diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-05-27 19:32:18 -0400 |
---|---|---|
committer | Austin Foxley <austinf@cetoncorp.com> | 2009-06-05 12:20:30 -0700 |
commit | a282a3fb19fa952a4222a1df9cadbbe553d7169a (patch) | |
tree | 8f558c0a5bbfecedd595c0dcb612bb368678ae72 /libc/sysdeps/linux/common | |
parent | aa0ac197ef8ad8274b78aad39513a37a20d37471 (diff) | |
download | uClibc-alpine-a282a3fb19fa952a4222a1df9cadbbe553d7169a.tar.bz2 uClibc-alpine-a282a3fb19fa952a4222a1df9cadbbe553d7169a.tar.xz |
waitid: linux ABI takes 5 args, not 4
The POSIX waitid() takes 4 args, but the Linux one takes 5 args, so make
sure we stuff the 5th arg with a NULL. Otherwise garbage gets randomly
passed up and considering this is a pointer, that's baaaad.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'libc/sysdeps/linux/common')
-rw-r--r-- | libc/sysdeps/linux/common/waitid.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/libc/sysdeps/linux/common/waitid.c b/libc/sysdeps/linux/common/waitid.c index 237056516..b7930a02d 100644 --- a/libc/sysdeps/linux/common/waitid.c +++ b/libc/sysdeps/linux/common/waitid.c @@ -5,12 +5,59 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ -#include <sys/syscall.h> +#include <features.h> #if defined __USE_SVID || defined __USE_XOPEN -#include <unistd.h> -#include <sys/types.h> -#include <sys/wait.h> +# include <string.h> +# include <sys/types.h> +# include <sys/wait.h> +# include <sys/syscall.h> + +# ifdef __NR_waitid +/* The waitid() POSIX interface takes 4 arguments, but the kernel function + * actually takes 5. The fifth is a pointer to struct rusage. Make sure + * we pass NULL rather than letting whatever was in the register bleed up. + */ +#define __NR_waitid5 __NR_waitid +static _syscall5(int, waitid5, idtype_t, idtype, id_t, id, siginfo_t*, infop, + int, options, struct rusage*, ru) +# endif + +/* libc_hidden_proto(waitpid) */ +int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) +{ +# ifdef __NR_waitid + return waitid5(idtype, id, infop, options, NULL); +# else + switch (idtype) { + case P_PID: + if (id <= 0) + goto invalid; + break; + case P_PGID: + if (id < 0 || id == 1) + goto invalid; + id = -id; + break; + case P_ALL: + id = -1; + break; + default: + invalid: + __set_errno(EINVAL); + return -1; + } + + memset(infop, 0, sizeof *infop); + infop->si_pid = waitpid(id, &infop->si_status, options +# ifdef WEXITED + &~ WEXITED +# endif + ); + if (infop->si_pid < 0) + return infop->si_pid; + return 0; +# endif +} -_syscall4(int, waitid, idtype_t, idtype, id_t, id, siginfo_t*, infop, int, options) #endif |