]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
timeout: don't orphan monitored programs if they ignore specified signals
authorPádraig Brady <P@draigBrady.com>
Fri, 23 Oct 2009 07:52:25 +0000 (08:52 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 25 Oct 2009 23:28:38 +0000 (23:28 +0000)
* 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.

NEWS
src/timeout.c

diff --git a/NEWS b/NEWS
index 1ed577f7f370cd7721c6f8c0b5bb9f5eebee3918..315ae5f6dee83a3a443ce19518017ec42f2996ce 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   were first renamed or unlinked or never modified.
   [The race was introduced in coreutils-7.5]
 
+  timeout now doesn't exit unless the command it is monitoring does,
+  for any specified signal. [bug introduced in coreutils-7.0].
+
 ** Changes in behavior
 
   chroot, env, nice, and su fail with status 125, rather than 1, on
index 7b0f1d7c56ae43fdf04cb7e01164b049753fce40..3babb8c260c191bd9645877349a89bd0b366e526 100644 (file)
@@ -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.  */