]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
timeout: port to NonStop (Bug#9077)
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 16 Jul 2011 00:48:38 +0000 (17:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 16 Jul 2011 19:10:44 +0000 (12:10 -0700)
* src/timeout.c (SA_RESTART): Define to 0 if not defined.
(main): Don't assume signal handling uses SA_RESTART.

src/timeout.c

index ef660a717ada25a057671403ddc39cb7885ccfaa..895d72038fb682e4d0df83f970ad92fa41e4fc80 100644 (file)
 # include <sys/resource.h>
 #endif
 
+/* NonStop circa 2011 lacks both SA_RESTART and siginterrupt.  */
+#ifndef SA_RESTART
+# define SA_RESTART 0
+#endif
+
 #define PROGRAM_NAME "timeout"
 
 #define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
@@ -256,7 +261,8 @@ install_signal_handlers (int sigterm)
   struct sigaction sa;
   sigemptyset (&sa.sa_mask);  /* Allow concurrent calls to handler */
   sa.sa_handler = cleanup;
-  sa.sa_flags = SA_RESTART;  /* restart syscalls (like wait() below) */
+  sa.sa_flags = SA_RESTART;   /* Restart syscalls if possible, as that's
+                                 more likely to work cleanly.  */
 
   sigaction (SIGALRM, &sa, NULL); /* our timeout.  */
   sigaction (SIGINT, &sa, NULL);  /* Ctrl-C at terminal for example.  */
@@ -354,18 +360,15 @@ main (int argc, char **argv)
     }
   else
     {
+      pid_t wait_result;
       int status;
 
       alarm (timeout);
 
-      /* We're just waiting for a single process here, so wait() suffices.
-         Note the signal() calls above on GNU/Linux and BSD at least,
-         essentially call the lower level sigaction() with the SA_RESTART flag
-         set, which ensures the following wait call will only return if the
-         child exits, not on this process receiving a signal. Also we're not
-         passing WUNTRACED | WCONTINUED to a waitpid() call and so will not get
-         indication that the child has stopped or continued.  */
-      if (wait (&status) == -1)
+      while ((wait_result = wait (&status)) < 0 && errno == EINTR)
+        continue;
+
+      if (wait_result < 0)
         {
           /* shouldn't happen.  */
           error (0, errno, _("error waiting for command"));