summaryrefslogtreecommitdiff
path: root/src/timeout.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2009-10-23 08:52:25 +0100
committerPádraig Brady <P@draigBrady.com>2009-10-25 23:28:38 +0000
commit69fbfd400c8000e7a7aeed399476c6d9c002a0bc (patch)
tree9b22bd760cbb452789a81253e28da984459aff44 /src/timeout.c
parent30e4b6e84b7e478121a645515ce891d29cc75105 (diff)
downloadcoreutils-69fbfd400c8000e7a7aeed399476c6d9c002a0bc.tar.xz
timeout: don't orphan monitored programs if they ignore specified signals
* src/timeout.c (install_signal_handlers): Handle any user specified signal, so that if it does not cause the child to exit then we don't exit and orphan the child. Previously this for example, would leave an orphan dd process running: timeout -sUSR1 1s dd if=/dev/zero of=/dev/null * NEWS: Mention the fix.
Diffstat (limited to 'src/timeout.c')
-rw-r--r--src/timeout.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/timeout.c b/src/timeout.c
index 7b0f1d7c5..3babb8c26 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -196,7 +196,7 @@ apply_time_suffix (unsigned long *x, char suffix_char)
}
static void
-install_signal_handlers (void)
+install_signal_handlers (int sigterm)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask); /* Allow concurrent calls to handler */
@@ -206,8 +206,9 @@ install_signal_handlers (void)
sigaction (SIGALRM, &sa, NULL); /* our timeout. */
sigaction (SIGINT, &sa, NULL); /* Ctrl-C at terminal for example. */
sigaction (SIGQUIT, &sa, NULL); /* Ctrl-\ at terminal for example. */
- sigaction (SIGTERM, &sa, NULL); /* if we're killed, stop monitored proc. */
sigaction (SIGHUP, &sa, NULL); /* terminal closed for example. */
+ sigaction (SIGTERM, &sa, NULL); /* if we're killed, stop monitored proc. */
+ sigaction (sigterm, &sa, NULL); /* user specified termination signal. */
}
int
@@ -271,7 +272,7 @@ main (int argc, char **argv)
/* Setup handlers before fork() so that we
handle any signals caused by child, without races. */
- install_signal_handlers ();
+ install_signal_handlers (term_signal);
signal (SIGTTIN, SIG_IGN); /* don't sTop if background child needs tty. */
signal (SIGTTOU, SIG_IGN); /* don't sTop if background child needs tty. */