mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-03 08:11:08 +00:00
79937577d1
2004-09-13 Ulrich Drepper <drepper@redhat.com> * misc/sys/cdefs.h: Restore old definition of __P. * csu/munch.awk: Remove uses of __P and __PMT. * gmon/gmon.c: Likewise. * hesiod/hesiod.h: Likewise. * include/stdio.h: Likewise. * io/fts.c: Likewise. * libio/genops.c: Likewise. * libio/libioP.h: Likewise. * libio/fileops.c: Likewise. * libio/iolibio.h: Likewise. * libio/libio.h: Likewise. * libio/memstream.c: Likewise. * libio/oldfileops.c: Likewise. * libio/oldstdfiles.c: Likewise. * libio/iopopen.c: Likewise. * libio/vsnprintf.c: Likewise. * libio/vswprintf.c: Likewise. * libio/wgenops.c: Likewise. * libio/oldiopopen.c: Likewise. * locale/programs/xmalloc.c: Likewise. * locale/programs/xstrdup.c: Likewise. * malloc/mtrace.c: Likewise. * misc/getttyent.c: Likewise. * misc/getusershell.c: Likewise. * nis/rpcsvc/ypupd.h: Likewise. * posix/fnmatch.h: Likewise. * posix/glob.h: Likewise. * resolv/arpa/nameser.h: Likewise. * resolv/gethnamaddr.c: Likewise. * resolv/resolv.h: Likewise. * resolv/inet_net_ntop.c: Likewise. * resolv/inet_net_pton.c: Likewise. * resolv/res_init.c: Likewise. * resolv/nss_dns/dns-network.c: Likewise. * stdio-common/vfprintf.c: Likewise. * stdio-common/reg-printf.c: Likewise. * sysdeps/generic/chflags.c: Likewise. * sysdeps/generic/fchflags.c: Likewise. * sysdeps/generic/glob.c: Likewise. * sysdeps/generic/printf_fphex.c: Likewise. * sysdeps/generic/memcmp.c: Likewise. * sysdeps/generic/memcopy.h: Likewise. * sysdeps/generic/morecore.c: Likewise. * sysdeps/generic/sstk.c: Likewise. * sysdeps/posix/sigvec.c: Likewise. * sysdeps/posix/ttyname_r.c: Likewise. * sysdeps/standalone/arm/bits/errno.h: Likewise. * sysdeps/standalone/standalone.h: Likewise. * sysdeps/standalone/i386/force_cpu386/brdinit.c: Likewise. * sysdeps/standalone/i386/force_cpu386/_exit.c: Likewise. * sysdeps/unix/arm/start.c: Likewise. * sysdeps/unix/bsd/sigaction.c: Likewise. * sysdeps/unix/bsd/sun/m68k/sigtramp.c: Likewise. * sysdeps/unix/bsd/sun/sparc/sigtramp.c: Likewise. * sysdeps/unix/bsd/sun/sunos4/wait4.c: Likewise. * sysdeps/unix/bsd/ultrix4/mips/sigvec.c: Likewise. * sysdeps/unix/bsd/ultrix4/sysconf.c: Likewise. * sysdeps/unix/sparc/start.c: Likewise. * sysdeps/unix/sysv/getdents.c: Likewise. * sysdeps/unix/sysv/irix4/fpathconf.c: Likewise. * sysdeps/unix/sysv/irix4/getgroups.c: Likewise. * sysdeps/unix/sysv/irix4/getpriority.c: Likewise. * sysdeps/unix/sysv/irix4/getrusage.c: Likewise. * sysdeps/unix/sysv/irix4/pathconf.c: Likewise. * sysdeps/unix/sysv/irix4/setgroups.c: Likewise. * sysdeps/unix/sysv/irix4/sigtramp.c: Likewise. * sysdeps/unix/sysv/irix4/start.c: Likewise. * sysdeps/unix/sysv/irix4/sysconf.c: Likewise. * sysdeps/unix/sysv/sco3.2.4/__setpgid.c: Likewise. * sysdeps/unix/sysv/sco3.2.4/getgroups.c: Likewise. * sysdeps/unix/sysv/sysv4/__getpgid.c: Likewise. * sysdeps/unix/sysv/sysv4/__setpgid.c: Likewise. * sysdeps/unix/sysv/sysv4/getpgid.c: Likewise. * sysdeps/unix/sysv/sysv4/setpgid.c: Likewise. * sysdeps/unix/sysv/sysv4/sethostname.c: Likewise. * sysdeps/unix/sysv/sysv4/setsid.c: Likewise. * sysdeps/unix/sysv/sysv4/sysconf.c: Likewise. * sysdeps/unix/sysv/sysv4/waitpid.c: Likewise. * sysdeps/unix/sysv/sysv4/solaris2/getdents.c: Likewise. * time/tzset.c: Likewise. * time/strftime_l.c: Likewise. * time/strptime_l.c: Likewise. * crypt/md5.h: Likewise.
121 lines
3.6 KiB
C
121 lines
3.6 KiB
C
/* Copyright (C) 1993,94,95,96,97,2002,2004 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Brendan Kehoe (brendan@zen.org).
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
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.
|
|
|
|
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
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
02111-1307 USA. */
|
|
|
|
#include <errno.h>
|
|
#include <sys/wait.h>
|
|
#include <sys/types.h>
|
|
#include <stddef.h>
|
|
#include "siginfo.h"
|
|
|
|
typedef enum __idtype
|
|
{
|
|
/* Look for processes based upon a given PID. */
|
|
P_PID,
|
|
|
|
/* Look for processes based upon a given process-group ID. */
|
|
P_PGID = 2,
|
|
|
|
/* Look for any process. */
|
|
P_ALL = 7,
|
|
} __idtype_t;
|
|
|
|
extern __pid_t __getpgid (__pid_t pid);
|
|
extern int __waitid (__idtype_t idtype, __pid_t id,
|
|
__siginfo_t *infop, int options);
|
|
|
|
/* Wait for a child matching PID to die.
|
|
If PID is greater than 0, match any process whose process ID is PID.
|
|
If PID is (pid_t) -1, match any process.
|
|
If PID is (pid_t) 0, match any process with the
|
|
same process group as the current process.
|
|
If PID is less than -1, match any process whose
|
|
process group is the absolute value of PID.
|
|
If the WNOHANG bit is set in OPTIONS, and that child
|
|
is not already dead, return (pid_t) 0. If successful,
|
|
return PID and store the dead child's status in STAT_LOC.
|
|
Return (pid_t) -1 for errors. If the WUNTRACED bit is set in OPTIONS,
|
|
return status for stopped children; otherwise don't. */
|
|
|
|
__pid_t
|
|
__libc_waitpid (__pid_t pid, int *stat_loc, int options)
|
|
{
|
|
__idtype_t idtype;
|
|
__pid_t tmp_pid = pid;
|
|
__siginfo_t infop;
|
|
|
|
if (pid <= WAIT_MYPGRP)
|
|
{
|
|
if (pid == WAIT_ANY)
|
|
{
|
|
/* Request the status for any child. */
|
|
idtype = P_ALL;
|
|
}
|
|
else if (pid == WAIT_MYPGRP)
|
|
{
|
|
/* Request the status for any child process that has
|
|
a pgid that's equal to that of our parent. */
|
|
tmp_pid = __getpgid (0);
|
|
idtype = P_PGID;
|
|
}
|
|
else /* PID < -1 */
|
|
{
|
|
/* Request the status for any child whose pgid is equal
|
|
to the absolute value of PID. */
|
|
tmp_pid = pid & ~0; /* XXX not pseudo-insn */
|
|
idtype = P_PGID;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* Request the status for the child whose pid is PID. */
|
|
idtype = P_PID;
|
|
}
|
|
|
|
if (__waitid (idtype, tmp_pid, &infop, options | WEXITED | WTRAPPED) < 0)
|
|
return -1;
|
|
|
|
switch (infop.__code)
|
|
{
|
|
case EXITED:
|
|
*stat_loc = W_EXITCODE (infop.__status, 0);
|
|
break;
|
|
case STOPPED:
|
|
case TRAPPED:
|
|
*stat_loc = W_STOPCODE (infop.__status);
|
|
break;
|
|
case KILLED:
|
|
/* Don't know what to do with continue, since it isn't documented.
|
|
Putting it here seemed the right place though. */
|
|
case CONTINUED:
|
|
*stat_loc = infop.__status;
|
|
/* FALLTHROUGH */
|
|
case CORED:
|
|
*stat_loc |= WCOREFLAG;
|
|
break;
|
|
}
|
|
|
|
/* Return the PID out of the INFOP structure instead of the one we were
|
|
called with, to account for cases of being called with -1 to signify
|
|
any PID. */
|
|
return infop.__pid;
|
|
}
|
|
weak_alias (__libc_waitpid, __waitpid)
|
|
weak_alias (__libc_waitpid, waitpid)
|
|
libc_hidden_weak (__waitpid)
|