diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-04 11:42:16 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-03-04 14:49:45 -0800 |
commit | 99fcde22ce8c6108781ca9d2bf7cd7286bdd1355 (patch) | |
tree | 26da64cd5dfd342cd5ef0b4dc3a1a7ff536a5868 | |
parent | aa266f1b3dc4e12acdc46cc0f562adc03c2c0b8f (diff) | |
download | coreutils-99fcde22ce8c6108781ca9d2bf7cd7286bdd1355.tar.gz |
split: simplify SIGPIPE handling
Ignore and default SIGPIPE, rather than blocking and unblocking it.
* src/split.c (default_SIGPIPE):
New static var, replacing oldblocked and newblocked.
(create): Use it.
(main): Set it.
-rw-r--r-- | src/split.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/split.c b/src/split.c index 424ca9fe0..c8d54576b 100644 --- a/src/split.c +++ b/src/split.c @@ -61,9 +61,8 @@ static int *open_pipes; static size_t open_pipes_alloc; static size_t n_open_pipes; -/* Blocked signals. */ -static sigset_t oldblocked; -static sigset_t newblocked; +/* Whether SIGPIPE has the default action, when --filter is used. */ +static bool default_SIGPIPE; /* Base name of output files. */ static char const *outbase; @@ -510,7 +509,8 @@ create (char const *name) if (close (fd_pair[0]) != 0) die (EXIT_FAILURE, errno, _("closing input pipe")); } - sigprocmask (SIG_SETMASK, &oldblocked, NULL); + if (default_SIGPIPE) + signal (SIGPIPE, SIG_DFL); execl (shell_prog, last_component (shell_prog), "-c", filter_command, (char *) NULL); die (EXIT_FAILURE, errno, _("failed to run command: \"%s -c %s\""), @@ -1609,14 +1609,7 @@ 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. */ 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); - } + default_SIGPIPE = signal (SIGPIPE, SIG_IGN) == SIG_DFL; switch (split_type) { |