From ccb29cfa2cfefa067817bbff3af74f4e9383f3a7 Mon Sep 17 00:00:00 2001
From: Paul Sajna <paulsajna@gmail.com>
Date: Sun, 11 Mar 2018 16:50:46 -0700
Subject: [PATCH] wait and waitpid

---
 src/platform/src/linux/mod.rs | 4 ++++
 src/platform/src/redox/mod.rs | 4 ++++
 src/wait/src/lib.rs           | 4 ++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs
index 8915e6fea..3f0ef34ed 100644
--- a/src/platform/src/linux/mod.rs
+++ b/src/platform/src/linux/mod.rs
@@ -159,6 +159,10 @@ pub fn unlink(path: *const c_char) -> c_int {
     e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int
 }
 
+pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+    e(unsafe { syscall!(WAIT4, pid, stat_loc, options) }) as pid_t
+}
+
 pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
     e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
 }
diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs
index e663a1b2d..4d98965be 100644
--- a/src/platform/src/redox/mod.rs
+++ b/src/platform/src/redox/mod.rs
@@ -202,6 +202,10 @@ pub fn unlink(path: *const c_char) -> c_int {
     e(syscall::unlink(path)) as c_int
 }
 
+pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+    e(syscall::waitpid(pid as usize, stat_loc as &mut usize, options as usize))
+}
+
 pub fn write(fd: c_int, buf: &[u8]) -> ssize_t {
     e(syscall::write(fd as usize, buf)) as ssize_t
 }
diff --git a/src/wait/src/lib.rs b/src/wait/src/lib.rs
index 51fdd2856..c64108a58 100644
--- a/src/wait/src/lib.rs
+++ b/src/wait/src/lib.rs
@@ -11,7 +11,7 @@ use resource::rusage;
 
 #[no_mangle]
 pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t {
-    unimplemented!();
+    waitpid(-1, stat_loc, 0)
 }
 
 #[no_mangle]
@@ -39,5 +39,5 @@ pub unsafe extern "C" fn wait3(
 
 #[no_mangle]
 pub unsafe extern "C" fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
-    unimplemented!();
+    platform::waitpid(pid, stat_loc, options)
 }
-- 
GitLab