From d39a66c351dee298676d59bdc5d0d468bfad1dc5 Mon Sep 17 00:00:00 2001
From: jD91mZM2 <me@krake.one>
Date: Tue, 7 Aug 2018 15:01:07 +0200
Subject: [PATCH] Fix waitpid -1 on redox

---
 src/platform/src/linux/mod.rs | 4 +++-
 src/platform/src/redox/mod.rs | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs
index 99b2d6e0..be108e8d 100644
--- a/src/platform/src/linux/mod.rs
+++ b/src/platform/src/linux/mod.rs
@@ -5,6 +5,8 @@ use types::*;
 
 const EINVAL: c_int = 22;
 
+const SIGCHLD: usize = 17;
+
 const TCGETS: c_ulong = 0x5401;
 const TCSETS: c_ulong = 0x5402;
 const TIOCGWINSZ: c_ulong = 0x5413;
@@ -106,7 +108,7 @@ pub fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
 }
 
 pub fn fork() -> pid_t {
-    e(unsafe { syscall!(CLONE, 17, 0) }) as pid_t
+    e(unsafe { syscall!(CLONE, SIGCHLD, 0) }) as pid_t
 }
 
 pub fn fsync(fildes: c_int) -> c_int {
diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs
index 14edf6ae..c9f815b9 100644
--- a/src/platform/src/redox/mod.rs
+++ b/src/platform/src/redox/mod.rs
@@ -1045,7 +1045,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 {
+pub fn waitpid(mut pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
+    if pid == !0 {
+        pid = 0;
+    }
     unsafe {
         let mut temp: usize = 0;
         let res = e(syscall::waitpid(pid as usize, &mut temp, options as usize));
-- 
GitLab