summaryrefslogtreecommitdiff
path: root/src/timeout.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeout.c')
-rw-r--r--src/timeout.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/timeout.c b/src/timeout.c
index 2ffd2b11..68baa23c 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -1,5 +1,5 @@
/* timeout -- run a command with bounded time
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Copyright (C) 2008-2014 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -118,7 +118,7 @@ unblock_signal (int sig)
as that's more useful in practice than reporting an error.
'0' means don't timeout. */
static void
-settimeout (double duration)
+settimeout (double duration, bool warn)
{
/* We configure timers below so that SIGALRM is sent on expiry.
@@ -142,11 +142,12 @@ settimeout (double duration)
return;
else
{
- error (0, errno, _("warning: timer_settime"));
+ if (warn)
+ error (0, errno, _("warning: timer_settime"));
timer_delete (timerid);
}
}
- else if (errno != ENOSYS)
+ else if (warn && errno != ENOSYS)
error (0, errno, _("warning: timer_create"));
#endif
@@ -190,10 +191,12 @@ cleanup (int sig)
{
if (kill_after)
{
+ int saved_errno = errno; /* settimeout may reset. */
/* Start a new timeout after which we'll send SIGKILL. */
term_signal = SIGKILL;
- settimeout (kill_after);
+ settimeout (kill_after, false);
kill_after = 0; /* Don't let later signals reset kill alarm. */
+ errno = saved_errno;
}
/* Send the signal directly to the monitored child,
@@ -235,18 +238,18 @@ Start COMMAND, and kill it if still running after DURATION.\n\
fputs (_("\
--preserve-status\n\
exit with the same status as COMMAND, even when the\n\
- command times out\n\
+ command times out\n\
--foreground\n\
- When not running timeout directly from a shell prompt,\n\
- allow COMMAND to read from the TTY and receive TTY signals.\n\
- In this mode, children of COMMAND will not be timed out.\n\
+ when not running timeout directly from a shell prompt,\n\
+ allow COMMAND to read from the TTY and get TTY signals;\n\
+ in this mode, children of COMMAND will not be timed out\n\
-k, --kill-after=DURATION\n\
also send a KILL signal if COMMAND is still running\n\
- this long after the initial signal was sent.\n\
+ this long after the initial signal was sent\n\
-s, --signal=SIGNAL\n\
- specify the signal to be sent on timeout.\n\
- SIGNAL may be a name like 'HUP' or a number.\n\
- See 'kill -l' for a list of signals\n"), stdout);
+ specify the signal to be sent on timeout;\n\
+ SIGNAL may be a name like 'HUP' or a number;\n\
+ see 'kill -l' for a list of signals\n"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -437,7 +440,7 @@ main (int argc, char **argv)
if (monitored_pid == -1)
{
error (0, errno, _("fork system call failed"));
- return EXIT_CANCELED;
+ exit (EXIT_CANCELED);
}
else if (monitored_pid == 0)
{ /* child */
@@ -452,14 +455,14 @@ main (int argc, char **argv)
/* exit like sh, env, nohup, ... */
exit_status = (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE);
error (0, errno, _("failed to run command %s"), quote (argv[0]));
- return exit_status;
+ exit (exit_status);
}
else
{
pid_t wait_result;
int status;
- settimeout (timeout);
+ settimeout (timeout, true);
while ((wait_result = waitpid (monitored_pid, &status, 0)) < 0
&& errno == EINTR)
@@ -497,8 +500,8 @@ main (int argc, char **argv)
}
if (timed_out && !preserve_status)
- return EXIT_TIMEDOUT;
+ exit (EXIT_TIMEDOUT);
else
- return status;
+ exit (status);
}
}