feat(wait): wait/waitpid/waitid and status macros

This commit is contained in:
2026-09-05 16:39:58 -04:00
parent 98f4c3169c
commit 6eaacd4448
3 changed files with 646 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/wait.h>
#include "../internal/syscall.h"
/*
* wait/waitpid/waitid/wait3/wait4 — child-process status collection.
*
* All four are pass-throughs to the kernel: wait/waitpid/wait3/wait4 ride
* SYS_wait4 (the kernel does the pid selection, the option masking, and the
* status-word encoding), waitid rides SYS_waitid (which fills a full
* 128-byte siginfo with the si_pid/si_uid/si_status details and a CLD_*
* si_code). The raw result goes through syscall_ret(), so a child pid (or
* waitid's 0) is returned on success and -1 with errno set on error;
* WNOHANG-with-no-child returns 0 from the kernel untouched.
*
* No argument inspection is needed: the kernel interprets pid == -1 (any
* child), 0 (own process group) and pid < -1 (process group) for wait4, and
* the which/id pair for waitid, exactly as POSIX specifies. The options are
* the kernel-identical W* bits from <sys/wait.h>. rusage passes through
* verbatim for wait3/wait4 (NULL is legal and skips the fill).
*/
pid_t
wait(int *stat_loc)
{
return (pid_t)syscall_ret(__syscall4(SYS_wait4, -1, (long)stat_loc, 0, 0));
}
pid_t
waitpid(pid_t pid, int *stat_loc, int options)
{
return (pid_t)syscall_ret(__syscall4(SYS_wait4, pid, (long)stat_loc, options, 0));
}
int
waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
{
return syscall_ret(__syscall5(SYS_waitid, idtype, id, (long)infop, options, 0));
}
#if VLIBC_LEVEL_GE(2)
/* Level 2 (muslmimic): XSI wait3/wait4. */
pid_t
wait3(int *stat_loc, int options, struct rusage *rusage)
{
return (pid_t)syscall_ret(__syscall4(SYS_wait4, -1, (long)stat_loc, options, (long)rusage));
}
pid_t
wait4(pid_t pid, int *stat_loc, int options, struct rusage *rusage)
{
return (pid_t)syscall_ret(__syscall4(SYS_wait4, pid, (long)stat_loc, options, (long)rusage));
}
#endif /* VLIBC_LEVEL_GE(2) */