X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Futilities%2Fhost.c;h=6298db2d8b5e581dddefc9648a849e97db473918;hb=610b2ee0e31ce3e9ced7ea5e518d516033176734;hp=1ab7cc1d02eef6a530ddd7159a3dcf342ad159af;hpb=d7c2328e0a1902e9e090baa95c7a0b671e93d4ee;p=pspp diff --git a/src/language/utilities/host.c b/src/language/utilities/host.c index 1ab7cc1d02..6298db2d8b 100644 --- a/src/language/utilities/host.c +++ b/src/language/utilities/host.c @@ -122,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)) { @@ -140,6 +145,7 @@ run_command (const char *command, struct timespec timeout) if (setitimer (ITIMER_REAL, &it, NULL) < 0) error (1, errno, _("Failed to set timeout.")); } +#endif /* Set up file descriptors: - /dev/null for stdin @@ -174,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) @@ -185,6 +199,10 @@ run_command (const char *command, struct timespec timeout) break; } } +#if __GNU__ + else if (retval == 0) + sleep (1); +#endif else NOT_REACHED (); }