]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: fix failure if sort's parent has ignored SIGCHLD
authorPádraig Brady <P@draigBrady.com>
Tue, 8 Dec 2009 08:48:34 +0000 (08:48 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 8 Dec 2009 15:29:27 +0000 (15:29 +0000)
* src/sort.c (main): Reset the SIGCHLD handler to the default
as otherwise wait() could return an error.
* tests/misc/sort-compress: Set the CHLD handler in a subshell
to SIG_IGN to ensure the sort command resets it to SIG_DFL.
* NEWS: Mention the fix.

NEWS
src/sort.c
tests/misc/sort-compress

diff --git a/NEWS b/NEWS
index 469865a6d829d03fcd3167cf3f7db34fb8138980..e30e7e5fd6b48f49fbe131639781d94b30c73ce2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   the presence of the empty string argument.
   [bug introduced in coreutils-8.0]
 
+  sort is now immune to the signal handling of its parent.
+  Specifically sort now doesn't exit with an error message
+  if it uses helper processes for compression and its parent
+  ignores CHLD signals. [bug introduced in coreutils-6.9]
+
   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]
index 8709e53704f31c43629f705529935b6c88aa7b15..70e0bbbaeb59781eabcd4e67cecc9991000e485c 100644 (file)
@@ -3254,6 +3254,7 @@ main (int argc, char **argv)
         }
 #endif
   }
+  signal (SIGCHLD, SIG_DFL); /* Don't inherit CHLD handling from parent.  */
 
   /* The signal mask is known, so it is safe to invoke exit_cleanup.  */
   atexit (exit_cleanup);
index 7e4278e51e3bb3ceaa2e9755f064685c9ec171be..2711833b3358c55567478b707b2bb42286a7b1bf 100755 (executable)
@@ -30,7 +30,6 @@ SORT="$abs_top_builddir/src/sort"
 # Ensure that $TMPDIR is valid.
 TMPDIR=.; export TMPDIR
 
-
 # This should force the use of temp files
 sort -S 1k in > out || fail=1
 compare exp out || fail=1
@@ -44,6 +43,16 @@ EOF
 
 chmod +x gzip
 
+# Ensure `sort` is immune to parent's SIGCHLD handler
+# Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh.
+(
+  # ash doesn't support "trap '' CHLD"; it knows only signal numbers.
+  sig=`"$abs_top_builddir/src/kill" -l CHLD 2>/dev/null` && trap '' $sig
+
+  # This should force the use of child processes for "compression"
+  PATH=.:$PATH exec sort -S 1k --compress-program=gzip in > /dev/null
+) || fail=1
+
 # This will find our new gzip in PATH
 PATH=.:$PATH sort -S 1k --compress-program=gzip in > out || fail=1
 compare exp out || fail=1