1 /* Pseudo implementation of waitid.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #include <sys/types.h>
31 waitid (idtype
, id
, infop
, options
)
48 if (id
< 0 || id
== 1)
61 /* Technically we're supposed to return EFAULT if infop is bogus,
62 but that would involve mucking with signals, which is
63 too much hassle. User will have to deal with SIGSEGV/SIGBUS.
64 We just check for a null pointer. */
72 child
= __waitpid (pid
, &status
, options
);
75 /* `waitpid' set `errno' for us. */
80 /* The WHOHANG bit in OPTIONS is set and there are children available
81 but none has a status for us. The XPG docs do not mention this
82 case so we clear the `siginfo_t' struct and return successfully. */
88 /* Decode the status field and set infop members... */
89 infop
->si_signo
= SIGCHLD
;
90 infop
->si_pid
= child
;
93 if (WIFEXITED (status
))
95 infop
->si_code
= CLD_EXITED
;
96 infop
->si_status
= WEXITSTATUS (status
);
98 else if (WIFSIGNALED (status
))
100 infop
->si_code
= WCOREDUMP (status
) ? CLD_DUMPED
: CLD_KILLED
;
101 infop
->si_status
= WTERMSIG (status
);
103 else if (WIFSTOPPED (status
))
105 infop
->si_code
= CLD_STOPPED
;
106 infop
->si_status
= WSTOPSIG (status
);
109 else if (WIFCONTINUED (status
))
111 infop
->si_code
= CLD_CONTINUED
;
112 infop
->si_status
= SIGCONT
;