diff options
author | Ian Moffett <ian@osmora.org> | 2025-07-17 00:25:52 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-07-17 00:31:19 -0400 |
commit | 3a486d207fc948bf1d146b6071480a6ecdae41b7 (patch) | |
tree | aa8b9e29488756bbed30c6b1ccfe78920814b1ae /sys/kern/kern_spawn.c | |
parent | 24b850e55e1dd8c36a4b2e946b941422db17abb5 (diff) |
kernel: spawn: Add waitpid()
Add waitpid() in preparation of deprecating SPAWN_WAIT.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_spawn.c')
-rw-r--r-- | sys/kern/kern_spawn.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sys/kern/kern_spawn.c b/sys/kern/kern_spawn.c index 930c3d2..c1c0029 100644 --- a/sys/kern/kern_spawn.c +++ b/sys/kern/kern_spawn.c @@ -28,6 +28,7 @@ */ #include <sys/spawn.h> +#include <sys/wait.h> #include <sys/proc.h> #include <sys/exec.h> #include <sys/mman.h> @@ -96,6 +97,35 @@ spawn_thunk(void) __builtin_unreachable(); } +pid_t +waitpid(pid_t pid, int *wstatus, int options) +{ + struct proc *child, *td; + pid_t ret; + + td = this_td(); + child = get_child(td, pid); + + if (child == NULL) { + return -1; + } + + /* Wait for it to be done */ + while (!ISSET(child->flags, PROC_ZOMB)) { + sched_yield(); + } + + + /* Give back the status */ + if (wstatus != NULL) { + copyout(&child->exit_status, wstatus, sizeof(*wstatus)); + } + + ret = child->pid; + proc_reap(child); + return ret; +} + /* * Spawn a new process * @@ -220,6 +250,27 @@ get_child(struct proc *cur, pid_t pid) } /* + * arg0: PID + * arg1: wstatus + * arg2: options + * + * Returns PID of terminated child, returns + * -1 on failure. + */ +scret_t +sys_waitpid(struct syscall_args *scargs) +{ + pid_t pid; + int *u_wstatus; + int options; + + pid = scargs->arg0; + u_wstatus = (void *)scargs->arg1; + options = scargs->arg2; + return waitpid(pid, u_wstatus, options); +} + +/* * arg0: The file /path/to/executable * arg1: Argv * arg2: Envp (TODO) |