2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de.
5 * Distributed under the terms of the MIT License.
13 #include <syscall_utils.h>
15 #include <errno_private.h>
17 #include <thread_defs.h>
23 return waitpid(-1, _status
, 0);
27 _waitpid(pid_t pid
, int* _status
, int options
, team_usage_info
*usage_info
)
31 pid_t child
= _kern_wait_for_child(pid
, options
, &info
, usage_info
);
36 // When not getting a child status when WNOHANG was specified, don't
38 if (child
== B_WOULD_BLOCK
&& (options
& WNOHANG
) != 0)
40 RETURN_AND_SET_ERRNO(child
);
44 if (_status
!= NULL
) {
46 switch (info
.si_code
) {
48 // fill in exit status for WIFEXITED() and WEXITSTATUS()
49 status
= info
.si_status
& 0xff;
54 // fill in signal for WIFSIGNALED() and WTERMSIG()
55 status
= (info
.si_status
<< 8) & 0xff00;
56 // if core dumped, set flag for WIFCORED()
57 if (info
.si_code
== CLD_DUMPED
)
62 // set flag for WIFCONTINUED()
67 // fill in signal for WIFSTOPPED() and WSTOPSIG()
68 status
= (info
.si_status
<< 16) & 0xff0000;
74 // should never get here -- assume exited
87 waitpid(pid_t pid
, int* _status
, int options
)
89 return _waitpid(pid
, _status
, options
, NULL
);
94 waitid(idtype_t idType
, id_t id
, siginfo_t
* info
, int options
)
96 // translate the idType, id pair to a waitpid() style ID
104 // the child with the given ID
106 RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL
);
110 // any child in the given process group
112 RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL
);
117 RETURN_AND_SET_ERRNO_TEST_CANCEL(EINVAL
);
120 pid_t child
= _kern_wait_for_child(id
, options
, info
, NULL
);
121 if (child
>= 0 || child
== B_WOULD_BLOCK
)
124 RETURN_AND_SET_ERRNO_TEST_CANCEL(child
);