summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bits/waitflags.h8
-rw-r--r--conform/data/sys/wait.h-data12
-rw-r--r--sysdeps/mach/hurd/waitid.c40
3 files changed, 43 insertions, 17 deletions
diff --git a/bits/waitflags.h b/bits/waitflags.h
index a2f9646b22..82abdf7d50 100644
--- a/bits/waitflags.h
+++ b/bits/waitflags.h
@@ -24,3 +24,11 @@
 /* Bits in the third argument to `waitpid'.  */
 #define	WNOHANG		1	/* Don't block waiting.  */
 #define	WUNTRACED	2	/* Report status of stopped children.  */
+
+/* Bits in the fourth argument to `waitid'.  */
+#if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
+# define WSTOPPED	WUNTRACED	/* Report stopped child. */
+# define WCONTINUED	4		/* Report continued child.  */
+# define WNOWAIT	8		/* Don't reap, just poll status.  */
+# define WEXITED	16		/* Report dead child.  */
+#endif
diff --git a/conform/data/sys/wait.h-data b/conform/data/sys/wait.h-data
index c0761424da..a6713461ea 100644
--- a/conform/data/sys/wait.h-data
+++ b/conform/data/sys/wait.h-data
@@ -8,8 +8,7 @@ constant WUNTRACED
 
 macro WEXITSTATUS
 # if !defined XPG4 && !defined POSIX && !defined POSIX2008
-// Bug 23091: hurd: missing waitid support.
-xfail[i386-gnu]-macro WIFCONTINUED
+macro WIFCONTINUED
 # endif
 macro WIFEXITED
 macro WIFSIGNALED
@@ -17,15 +16,14 @@ macro WIFSTOPPED
 macro WSTOPSIG
 macro WTERMSIG
 
-// Bug 23091: hurd: missing waitid support.
 # if !defined XPG4 && !defined POSIX
-xfail[i386-gnu]-constant WEXITED
-xfail[i386-gnu]-constant WSTOPPED
+constant WEXITED
+constant WSTOPPED
 #  ifndef POSIX2008
-xfail[i386-gnu]-constant WCONTINUED
+constant WCONTINUED
 #  endif
 constant WNOHANG
-xfail[i386-gnu]-constant WNOWAIT
+constant WNOWAIT
 # endif
 
 #if !defined XPG4 && !defined POSIX
diff --git a/sysdeps/mach/hurd/waitid.c b/sysdeps/mach/hurd/waitid.c
index 044a1dd8e3..eb5141e351 100644
--- a/sysdeps/mach/hurd/waitid.c
+++ b/sysdeps/mach/hurd/waitid.c
@@ -1,4 +1,4 @@
-/* Pseudo implementation of waitid.
+/* Implementation of waitid.  Hurd version.
    Copyright (C) 1997-2020 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1997.
@@ -18,14 +18,23 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <sys/types.h>
 #include <sys/wait.h>
 #include <stddef.h>
+#include <hurd.h>
+#include <hurd/port.h>
+#include <hurd/version.h>
+#include <sysdep-cancel.h>
 
 int
 __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 {
+  struct rusage ignored;
+  error_t err;
   pid_t pid, child;
+  int sigcode;
   int status;
+  int cancel_oldtype;
 
   switch (idtype)
     {
@@ -59,16 +68,19 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
       return -1;
     }
 
-  /* Note the waitid() is a cancellation point.  But since we call
-     waitpid() which itself is a cancellation point we do not have
-     to do anything here.  */
-  child = __waitpid (pid, &status, options);
+  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);
 
-  if (child == -1)
-    /* `waitpid' set `errno' for us.  */
-    return -1;
-
-  if (child == 0)
+  if (err == EAGAIN)
     {
       /* POSIX.1-2008, Technical Corrigendum 1 XSH/TC1-2008/0713 [153] states
 	 that if waitid returns because WNOHANG was specified and status is
@@ -80,6 +92,9 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
       return 0;
     }
 
+  if (err != 0)
+    return __hurd_fail (err);
+
   /* Decode the status field and set infop members... */
   infop->si_signo = SIGCHLD;
   infop->si_pid = child;
@@ -100,6 +115,11 @@ __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
       infop->si_code = CLD_STOPPED;
       infop->si_status = WSTOPSIG (status);
     }
+  else if (WIFCONTINUED (status))
+    {
+      infop->si_code = CLD_CONTINUED;
+      infop->si_status = SIGCONT;
+    }
 
   return 0;
 }