]>
Commit | Line | Data |
---|---|---|
f6abd970 | 1 | /* Implementation of waitid. Hurd version. |
2b778ceb | 2 | Copyright (C) 1997-2021 Free Software Foundation, Inc. |
bd355af0 UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1997. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
bd355af0 UD |
10 | |
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 | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
bd355af0 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
bd355af0 UD |
19 | |
20 | #include <errno.h> | |
f6abd970 | 21 | #include <sys/types.h> |
bd355af0 | 22 | #include <sys/wait.h> |
01bd6251 | 23 | #include <stddef.h> |
f6abd970 ST |
24 | #include <hurd.h> |
25 | #include <hurd/port.h> | |
26 | #include <hurd/version.h> | |
27 | #include <sysdep-cancel.h> | |
bd355af0 | 28 | |
6437fecc AZ |
29 | int |
30 | __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options) | |
bd355af0 | 31 | { |
f6abd970 ST |
32 | struct rusage ignored; |
33 | error_t err; | |
bd355af0 | 34 | pid_t pid, child; |
f6abd970 | 35 | int sigcode; |
bd355af0 | 36 | int status; |
f6abd970 | 37 | int cancel_oldtype; |
bd355af0 UD |
38 | |
39 | switch (idtype) | |
40 | { | |
41 | case P_PID: | |
6437fecc | 42 | if (id <= 0) |
bd355af0 UD |
43 | goto invalid; |
44 | pid = (pid_t) id; | |
45 | break; | |
46 | case P_PGID: | |
47 | if (id < 0 || id == 1) | |
48 | goto invalid; | |
49 | pid = (pid_t) -id; | |
50 | break; | |
51 | case P_ALL: | |
52 | pid = -1; | |
53 | break; | |
54 | default: | |
55 | invalid: | |
56 | __set_errno (EINVAL); | |
57 | return -1; | |
58 | } | |
59 | ||
60 | /* Technically we're supposed to return EFAULT if infop is bogus, | |
61 | but that would involve mucking with signals, which is | |
62 | too much hassle. User will have to deal with SIGSEGV/SIGBUS. | |
63 | We just check for a null pointer. */ | |
64 | ||
65 | if (infop == NULL) | |
66 | { | |
67 | __set_errno (EFAULT); | |
68 | return -1; | |
69 | } | |
70 | ||
f6abd970 ST |
71 | cancel_oldtype = LIBC_CANCEL_ASYNC(); |
72 | #if HURD_INTERFACE_VERSION >= 20201227 | |
73 | err = __USEPORT_CANCEL (PROC, __proc_waitid (port, pid, options, | |
74 | &status, &sigcode, | |
75 | &ignored, &child)); | |
76 | if (err == MIG_BAD_ID || err == EOPNOTSUPP) | |
77 | #endif | |
78 | err = __USEPORT_CANCEL (PROC, __proc_wait (port, pid, options, | |
79 | &status, &sigcode, | |
80 | &ignored, &child)); | |
81 | LIBC_CANCEL_RESET (cancel_oldtype); | |
bd355af0 | 82 | |
f6abd970 | 83 | if (err == EAGAIN) |
bd355af0 | 84 | { |
6437fecc AZ |
85 | /* POSIX.1-2008, Technical Corrigendum 1 XSH/TC1-2008/0713 [153] states |
86 | that if waitid returns because WNOHANG was specified and status is | |
87 | not available for any process specified by idtype and id, then the | |
88 | si_signo and si_pid members of the structure pointed to by infop | |
89 | shall be set to zero. */ | |
bd355af0 UD |
90 | infop->si_signo = 0; |
91 | infop->si_code = 0; | |
92 | return 0; | |
93 | } | |
94 | ||
f6abd970 ST |
95 | if (err != 0) |
96 | return __hurd_fail (err); | |
97 | ||
bd355af0 UD |
98 | /* Decode the status field and set infop members... */ |
99 | infop->si_signo = SIGCHLD; | |
100 | infop->si_pid = child; | |
101 | infop->si_errno = 0; | |
102 | ||
103 | if (WIFEXITED (status)) | |
104 | { | |
105 | infop->si_code = CLD_EXITED; | |
106 | infop->si_status = WEXITSTATUS (status); | |
107 | } | |
108 | else if (WIFSIGNALED (status)) | |
109 | { | |
110 | infop->si_code = WCOREDUMP (status) ? CLD_DUMPED : CLD_KILLED; | |
111 | infop->si_status = WTERMSIG (status); | |
112 | } | |
113 | else if (WIFSTOPPED (status)) | |
114 | { | |
115 | infop->si_code = CLD_STOPPED; | |
116 | infop->si_status = WSTOPSIG (status); | |
117 | } | |
f6abd970 ST |
118 | else if (WIFCONTINUED (status)) |
119 | { | |
120 | infop->si_code = CLD_CONTINUED; | |
121 | infop->si_status = SIGCONT; | |
122 | } | |
bd355af0 UD |
123 | |
124 | return 0; | |
125 | } | |
6166815d | 126 | weak_alias (__waitid, waitid) |
e5e45b53 | 127 | strong_alias (__waitid, __libc_waitid) |