X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Fhost.c;h=6298db2d8b5e581dddefc9648a849e97db473918;hb=3b54533821614d17afc61f1cd3b87d3a06fbf4da;hp=4a32d463973862739942190cae7cadccb5aa5739;hpb=13bc7e5d95ddbcfcce29080eb2ca2b6eb17d7433;p=pspp diff --git a/src/language/utilities/host.c b/src/language/utilities/host.c index 4a32d46397..6298db2d8b 100644 --- a/src/language/utilities/host.c +++ b/src/language/utilities/host.c @@ -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 (); }