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 <sysdep-cancel.h>
24
25pid_t
26__wait4 (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 int cancel_oldtype;
34
35 cancel_oldtype = LIBC_CANCEL_ASYNC();
36 err = __USEPORT_CANCEL (PROC, __proc_wait (port, pid, options,
37 stat_loc ?: &dummy, &sigcode,
38 usage ?: &ignored, &dead));
39 LIBC_CANCEL_RESET (cancel_oldtype);
40 switch (err)
41 {
42 case 0: /* Got a child. */
43 return dead;
44 case EAGAIN:
45 /* The RPC returns this error when the WNOHANG flag is set and no
46 selected children are dead (but some are living). In that
47 situation, our return value is zero. (The RPC can't return zero
48 for DEAD without also returning some garbage for the other out
49 parameters, so an error return is much more natural here. Hence
50 the difference between the RPC and the POSIX.1 interface. */
51 return (pid_t) 0;
52 default:
53 return (pid_t) __hurd_fail (err);
54 }
55}
56
57libc_hidden_def (__wait4)
58weak_alias (__wait4, wait4)
59

source code of glibc/sysdeps/mach/hurd/wait4.c