render: Add comment.
[pspp] / src / language / utilities / host.c
index 4a32d463973862739942190cae7cadccb5aa5739..6298db2d8b5e581dddefc9648a849e97db473918 100644 (file)
@@ -40,6 +40,7 @@
 #include "libpspp/temp-file.h"
 #include "output/text-item.h"
 
+#include "gl/error.h"
 #include "gl/intprops.h"
 #include "gl/localcharset.h"
 #include "gl/read-file.h"
@@ -121,6 +122,11 @@ run_command (const char *command, struct timespec timeout)
     {
       /* Running in the child. */
 
+#if __GNU__
+      /* Hurd doesn't support inheriting process timers in a way that works. */
+      if (setpgid (0, 0) < 0)
+        error (1, errno, _("Failed to set process group."));
+#else
       /* Set up timeout. */
       if (timeout.tv_sec < TYPE_MAXIMUM (time_t))
         {
@@ -136,8 +142,10 @@ run_command (const char *command, struct timespec timeout)
               .tv_usec = left.tv_nsec / 1000
             }
           };
-          setitimer (ITIMER_REAL, &it, NULL);
+          if (setitimer (ITIMER_REAL, &it, NULL) < 0)
+            error (1, errno, _("Failed to set timeout."));
         }
+#endif
 
       /* Set up file descriptors:
          - /dev/null for stdin
@@ -172,7 +180,15 @@ run_command (const char *command, struct timespec timeout)
   int error = 0;
   for (;;)
     {
-      pid_t retval = waitpid (pid, &status, 0);
+#if __GNU__
+      if (timespec_cmp (current_timespec (), timeout) >= 0)
+        kill (-pid, SIGALRM);
+
+      int flags = WNOHANG;
+#else
+      int flags = 0;
+#endif
+      pid_t retval = waitpid (pid, &status, flags);
       if (retval == pid)
         break;
       else if (retval < 0)
@@ -183,6 +199,10 @@ run_command (const char *command, struct timespec timeout)
               break;
             }
         }
+#if __GNU__
+      else if (retval == 0)
+        sleep (1);
+#endif
       else
         NOT_REACHED ();
     }