split: return success even if a --filter exits
authorPádraig Brady <P@draigBrady.com>
Thu, 19 May 2011 22:23:23 +0000 (23:23 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 25 May 2011 23:10:32 +0000 (00:10 +0100)
src/split.c (main): Don't unblock SIGPIPE before cleanup,
as then any pending signals will be sent and cause
the main split process to exit with a non zero status (141).
* test/split/filter: Add a test for this case.

src/split.c
tests/split/filter

index 6c75080..3f92538 100644 (file)
@@ -1230,15 +1230,15 @@ main (int argc, char **argv)
 
   /* When filtering, closure of one pipe must not terminate the process,
      as there may still be other streams expecting input from us.  */
-  sigemptyset (&newblocked);
   if (filter_command)
     {
       struct sigaction act;
+      sigemptyset (&newblocked);
       sigaction (SIGPIPE, NULL, &act);
       if (act.sa_handler != SIG_IGN)
         sigaddset (&newblocked, SIGPIPE);
+      sigprocmask (SIG_BLOCK, &newblocked, &oldblocked);
     }
-  sigprocmask (SIG_BLOCK, &newblocked, &oldblocked);
 
   switch (split_type)
     {
@@ -1276,8 +1276,6 @@ main (int argc, char **argv)
       abort ();
     }
 
-  sigprocmask (SIG_SETMASK, &oldblocked, NULL);
-
   if (close (STDIN_FILENO) != 0)
     error (EXIT_FAILURE, errno, "%s", infile);
   closeout (NULL, output_desc, filter_pid, outfile);
index 4c25c5f..0614841 100755 (executable)
@@ -43,4 +43,8 @@ done
 split -e -n 10 --filter='xz > $FILE.xz' /dev/null || fail=1
 stat x?? 2>/dev/null && fail=1
 
+# Ensure SIGPIPEs sent by the children don't propagate back
+# where they would result in a non zero exit from split.
+yes | head -n200K | split -b1G --filter='head -c1 >/dev/null' || fail=1
+
 Exit $fail