diff options
| author | Jakob Kaivo <jkk@ung.org> | 2020-08-14 20:19:37 -0400 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2020-08-14 20:19:37 -0400 |
| commit | 73a32f2e680f715c4e98dab7460f3e7269ce4085 (patch) | |
| tree | 1615dd386afe7208fce8c87c127223ea88d55730 /src/sys | |
| parent | 902687a68398963b18e5dbed78553c3c19408eeb (diff) | |
draft as wrapper to waitid()
Diffstat (limited to 'src/sys')
| -rw-r--r-- | src/sys/wait/waitpid.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/sys/wait/waitpid.c b/src/sys/wait/waitpid.c index ef196cc1..c3892ff0 100644 --- a/src/sys/wait/waitpid.c +++ b/src/sys/wait/waitpid.c @@ -1,11 +1,45 @@ #include "sys/types.h" #include <sys/wait.h> +#include "signal.h" +#include "unistd.h" +#include "_syscall.h" + +#ifndef P_PID +#include "signal/union_sigval.c" +#include "signal/siginfo_t.c" +#include "idtype_t.c" +#include "P_PID.c" +#include "P_PGID.c" +#include "P_ALL.c" +#define getpgid(_pid) __syscall(__syscall_lookup(getpgid), _pid, 0, 0, 0, 0, 0) +#define waitid(_type, _id, _si, _opt) __syscall(__syscall_lookup(waitid), _type, _id, _si, _opt, 0, 0) +#endif pid_t waitpid(pid_t pid, int *stat_loc, int options) { - (void)pid; (void)stat_loc; (void)options; - return 0; + /* TODO: handle WUNTRACED, is not recognized by waitid() */ + + siginfo_t si = { 0 }; + idtype_t idt = P_PID; + int ret = -1; + + if (pid == (pid_t)-1) { + idt = P_ALL; + } else if (pid == 0) { + idt = P_PGID; + pid = getpgid(0); + } else if (pid < (pid_t)-1) { + idt = P_PGID; + pid = -pid; + } + + ret = waitid(idt, pid, &si, options); + if (stat_loc) { + *stat_loc = si.si_status; + } + return ret; } + /* POSIX(1) */ |
