1 /* Copyright (C) 1993-2022 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17 
18 #include <sys/types.h>
19 #include <sys/wait.h>
20 #include <errno.h>
21 #include <hurd.h>
22 #include <hurd/port.h>
23 #include <not-cancel.h>
24 
25 pid_t
__wait4_nocancel(pid_t pid,int * stat_loc,int options,struct rusage * usage)26 __wait4_nocancel (pid_t pid, int *stat_loc, int options, struct rusage *usage)
27 {
28   pid_t dead;
29   error_t err;
30   struct rusage ignored;
31   int sigcode;
32   int dummy;
33 
34   err = __USEPORT (PROC, __proc_wait (port, pid, options,
35 				      stat_loc ?: &dummy, &sigcode,
36 				      usage ?: &ignored, &dead));
37   switch (err)
38     {
39     case 0:			/* Got a child.  */
40       return dead;
41     case EAGAIN:
42       /* The RPC returns this error when the WNOHANG flag is set and no
43 	 selected children are dead (but some are living).  In that
44 	 situation, our return value is zero.  (The RPC can't return zero
45 	 for DEAD without also returning some garbage for the other out
46 	 parameters, so an error return is much more natural here.  Hence
47 	 the difference between the RPC and the POSIX.1 interface.  */
48       return (pid_t) 0;
49     default:
50       return (pid_t) __hurd_fail (err);
51     }
52 }
53 
54 libc_hidden_def (__wait4_nocancel)
55