1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2007 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7 
8 #include <features.h>
9 
10 #if defined __USE_SVID || defined __USE_XOPEN
11 
12 #include <sys/syscall.h>
13 #include <sys/wait.h>
14 #include <cancel.h>
15 #ifndef __NR_waitid
16 # include <string.h>
17 #endif
18 
__NC(waitid)19 static int __NC(waitid)(idtype_t idtype, id_t id, siginfo_t *infop, int options)
20 {
21 #ifdef __NR_waitid
22 	return INLINE_SYSCALL(waitid, 5, idtype, id, infop, options, NULL);
23 #else
24 	switch (idtype) {
25 		case P_PID:
26 			if (id <= 0)
27 				goto invalid;
28 			break;
29 		case P_PGID:
30 			if (id < 0 || id == 1)
31 				goto invalid;
32 			id = -id;
33 			break;
34 		case P_ALL:
35 			id = -1;
36 			break;
37 		default:
38 		invalid:
39 			__set_errno(EINVAL);
40 			return -1;
41 	}
42 
43 	memset(infop, 0, sizeof *infop);
44 	infop->si_pid = __NC(waitpid)(id, &infop->si_status, options
45 # ifdef WEXITED
46 					   &~ WEXITED
47 # endif
48 					  );
49 	if (infop->si_pid < 0)
50 		return infop->si_pid;
51 	return 0;
52 #endif
53 }
54 CANCELLABLE_SYSCALL(int, waitid, (idtype_t idtype, id_t id, siginfo_t *infop, int options),
55 		    (idtype, id, infop, options))
56 
57 #endif
58