bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] timeout: fix failure if timeout's parent has ignored SIGCHLD


From: Pádraig Brady
Subject: [PATCH] timeout: fix failure if timeout's parent has ignored SIGCHLD
Date: Tue, 08 Dec 2009 00:55:25 +0000
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

attached
>From 4177a115a6d198b0a08f65623094cddeb90deb3a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <address@hidden>
Date: Mon, 7 Dec 2009 19:00:04 +0000
Subject: [PATCH] timeout: fix failure if timeout's parent has ignored SIGCHLD

* src/timeout.c (main): Reset the SIGCHLD handler to the default
as otherwise wait() could return -1 and set errno to ECHILD.
This condition was ignored until commit 0b1dcf33, on 31-08-2009,
"timeout: defensive handling of all wait() errors"
but subsequently timeout would run the command correctly
but then fail with an error message.
* tests/misc/timeout: Set the CHLD handler to SIG_IGN to ensure
the timeout command resets it to SIG_DFL.
* NEWS: mention the fix.
---
 NEWS               |    3 +++
 src/timeout.c      |    1 +
 tests/misc/timeout |    1 +
 3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/NEWS b/NEWS
index 19cca5b..469865a 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   the presence of the empty string argument.
   [bug introduced in coreutils-8.0]
 
+  timeout is now immune to the signal handling of its parent.
+  Specifically timeout now doesn't exit with an error message
+  if its parent ignores CHLD signals. [bug introduced in coreutils-7.6]
 
 * Noteworthy changes in release 8.1 (2009-11-18) [stable]
 
diff --git a/src/timeout.c b/src/timeout.c
index 3babb8c..c7753d4 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -275,6 +275,7 @@ main (int argc, char **argv)
   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.  
*/
+  signal (SIGCHLD, SIG_DFL);    /* Don't inherit CHLD handling from parent.   
*/
 
   monitored_pid = fork ();
   if (monitored_pid == -1)
diff --git a/tests/misc/timeout b/tests/misc/timeout
index 77a4205..ac34e27 100755
--- a/tests/misc/timeout
+++ b/tests/misc/timeout
@@ -23,6 +23,7 @@ fi
 
 . $srcdir/test-lib.sh
 
+trap '' CHLD # ensure `timeout` is immune to parent's SIGCHLD handler
 
 # no timeout
 timeout 1 true || fail=1
-- 
1.6.2.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]