From 24ecd6ee16660651881a7ff218dc5293b95d7a26 Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Mon, 18 Jul 2022 16:04:09 +0200
Subject: [PATCH] Fix waitpid deadlock.

---
 src/platform/redox/clone.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/platform/redox/clone.rs b/src/platform/redox/clone.rs
index a01e8c63..62e2385d 100644
--- a/src/platform/redox/clone.rs
+++ b/src/platform/redox/clone.rs
@@ -228,6 +228,12 @@ fn fork_inner(initial_rsp: *mut usize) -> Result<usize> {
     // Unblock context.
     syscall::kill(new_pid, SIGCONT)?;
 
+    // XXX: Killing with SIGCONT will put (pid, 65536) at key (pid, pgid) into the waitpid of this
+    // context. This means that if pgid is changed (as it is in ion for example), the pgid message
+    // in syscall::exit() will not be inserted as the key comparator thinks they're equal as their
+    // PIDs are. So, we have to call this to clear the waitpid queue to prevent deadlocks.
+    let _ = syscall::waitpid(new_pid, &mut 0, syscall::WUNTRACED | syscall::WCONTINUED);
+
     Ok(new_pid)
 }
 #[no_mangle]
-- 
GitLab