Blame sysdeps/mach/hurd/wait4.c

Packit 6c4009
/* Copyright (C) 1993-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <sys/wait.h>
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <hurd.h>
Packit 6c4009
#include <hurd/port.h>
Packit 6c4009
Packit 6c4009
pid_t
Packit 6c4009
__wait4 (pid_t pid, int *stat_loc, int options, struct rusage *usage)
Packit 6c4009
{
Packit 6c4009
  pid_t dead;
Packit 6c4009
  error_t err;
Packit 6c4009
  struct rusage ignored;
Packit 6c4009
  int sigcode;
Packit 6c4009
  int dummy;
Packit 6c4009
Packit 6c4009
  err = __USEPORT (PROC, __proc_wait (port, pid, options,
Packit 6c4009
				      stat_loc ?: &dummy, &sigcode,
Packit 6c4009
				      usage ?: &ignored, &dead));
Packit 6c4009
  switch (err)
Packit 6c4009
    {
Packit 6c4009
    case 0:			/* Got a child.  */
Packit 6c4009
      return dead;
Packit 6c4009
    case EAGAIN:
Packit 6c4009
      /* The RPC returns this error when the WNOHANG flag is set and no
Packit 6c4009
	 selected children are dead (but some are living).  In that
Packit 6c4009
	 situation, our return value is zero.  (The RPC can't return zero
Packit 6c4009
	 for DEAD without also returning some garbage for the other out
Packit 6c4009
	 parameters, so an error return is much more natural here.  Hence
Packit 6c4009
	 the difference between the RPC and the POSIX.1 interface.  */
Packit 6c4009
      return (pid_t) 0;
Packit 6c4009
    default:
Packit 6c4009
      return (pid_t) __hurd_fail (err);
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
weak_alias (__wait4, wait4)