2020-12-28 22:37:04 +00:00
|
|
|
/* Implementation of waitid. Hurd version.
|
2023-01-06 21:08:04 +00:00
|
|
|
Copyright (C) 1997-2023 Free Software Foundation, Inc.
|
1997-12-14 22:24:57 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-12-14 22:24:57 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
1997-12-14 22:24:57 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1997-12-14 22:24:57 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
2020-12-28 22:37:04 +00:00
|
|
|
#include <sys/types.h>
|
1997-12-14 22:24:57 +00:00
|
|
|
#include <sys/wait.h>
|
2020-02-04 13:29:04 +00:00
|
|
|
#include <stddef.h>
|
2020-12-28 22:37:04 +00:00
|
|
|
#include <hurd.h>
|
|
|
|
#include <hurd/port.h>
|
|
|
|
#include <hurd/version.h>
|
|
|
|
#include <sysdep-cancel.h>
|
1997-12-14 22:24:57 +00:00
|
|
|
|
2019-11-19 21:34:19 +00:00
|
|
|
int
|
|
|
|
__waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
|
1997-12-14 22:24:57 +00:00
|
|
|
{
|
2020-12-28 22:37:04 +00:00
|
|
|
struct rusage ignored;
|
|
|
|
error_t err;
|
1997-12-14 22:24:57 +00:00
|
|
|
pid_t pid, child;
|
2020-12-28 22:37:04 +00:00
|
|
|
int sigcode;
|
1997-12-14 22:24:57 +00:00
|
|
|
int status;
|
2020-12-28 22:37:04 +00:00
|
|
|
int cancel_oldtype;
|
1997-12-14 22:24:57 +00:00
|
|
|
|
|
|
|
switch (idtype)
|
|
|
|
{
|
|
|
|
case P_PID:
|
2019-11-19 21:34:19 +00:00
|
|
|
if (id <= 0)
|
1997-12-14 22:24:57 +00:00
|
|
|
goto invalid;
|
|
|
|
pid = (pid_t) id;
|
|
|
|
break;
|
|
|
|
case P_PGID:
|
|
|
|
if (id < 0 || id == 1)
|
|
|
|
goto invalid;
|
|
|
|
pid = (pid_t) -id;
|
|
|
|
break;
|
|
|
|
case P_ALL:
|
|
|
|
pid = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
invalid:
|
2023-05-20 11:55:29 +00:00
|
|
|
return __hurd_fail (EINVAL);
|
1997-12-14 22:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Technically we're supposed to return EFAULT if infop is bogus,
|
|
|
|
but that would involve mucking with signals, which is
|
|
|
|
too much hassle. User will have to deal with SIGSEGV/SIGBUS.
|
|
|
|
We just check for a null pointer. */
|
|
|
|
|
|
|
|
if (infop == NULL)
|
2023-05-20 11:55:29 +00:00
|
|
|
return __hurd_fail (EFAULT);
|
1997-12-14 22:24:57 +00:00
|
|
|
|
2020-12-28 22:37:04 +00:00
|
|
|
cancel_oldtype = LIBC_CANCEL_ASYNC();
|
|
|
|
#if HURD_INTERFACE_VERSION >= 20201227
|
|
|
|
err = __USEPORT_CANCEL (PROC, __proc_waitid (port, pid, options,
|
|
|
|
&status, &sigcode,
|
|
|
|
&ignored, &child));
|
|
|
|
if (err == MIG_BAD_ID || err == EOPNOTSUPP)
|
|
|
|
#endif
|
|
|
|
err = __USEPORT_CANCEL (PROC, __proc_wait (port, pid, options,
|
|
|
|
&status, &sigcode,
|
|
|
|
&ignored, &child));
|
|
|
|
LIBC_CANCEL_RESET (cancel_oldtype);
|
1997-12-14 22:24:57 +00:00
|
|
|
|
2020-12-28 22:37:04 +00:00
|
|
|
if (err == EAGAIN)
|
1997-12-14 22:24:57 +00:00
|
|
|
{
|
2019-11-19 21:34:19 +00:00
|
|
|
/* POSIX.1-2008, Technical Corrigendum 1 XSH/TC1-2008/0713 [153] states
|
|
|
|
that if waitid returns because WNOHANG was specified and status is
|
|
|
|
not available for any process specified by idtype and id, then the
|
|
|
|
si_signo and si_pid members of the structure pointed to by infop
|
|
|
|
shall be set to zero. */
|
1997-12-14 22:24:57 +00:00
|
|
|
infop->si_signo = 0;
|
|
|
|
infop->si_code = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-28 22:37:04 +00:00
|
|
|
if (err != 0)
|
|
|
|
return __hurd_fail (err);
|
|
|
|
|
1997-12-14 22:24:57 +00:00
|
|
|
/* Decode the status field and set infop members... */
|
|
|
|
infop->si_signo = SIGCHLD;
|
|
|
|
infop->si_pid = child;
|
|
|
|
infop->si_errno = 0;
|
|
|
|
|
|
|
|
if (WIFEXITED (status))
|
|
|
|
{
|
|
|
|
infop->si_code = CLD_EXITED;
|
|
|
|
infop->si_status = WEXITSTATUS (status);
|
|
|
|
}
|
|
|
|
else if (WIFSIGNALED (status))
|
|
|
|
{
|
|
|
|
infop->si_code = WCOREDUMP (status) ? CLD_DUMPED : CLD_KILLED;
|
|
|
|
infop->si_status = WTERMSIG (status);
|
|
|
|
}
|
|
|
|
else if (WIFSTOPPED (status))
|
|
|
|
{
|
|
|
|
infop->si_code = CLD_STOPPED;
|
|
|
|
infop->si_status = WSTOPSIG (status);
|
|
|
|
}
|
2020-12-28 22:37:04 +00:00
|
|
|
else if (WIFCONTINUED (status))
|
|
|
|
{
|
|
|
|
infop->si_code = CLD_CONTINUED;
|
|
|
|
infop->si_status = SIGCONT;
|
|
|
|
}
|
1997-12-14 22:24:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-09 09:42:48 +00:00
|
|
|
weak_alias (__waitid, waitid)
|
2002-12-10 04:05:39 +00:00
|
|
|
strong_alias (__waitid, __libc_waitid)
|