From: Pádraig Brady
Date: Sat, 27 Dec 2025 15:48:42 +0000 (+0000) Subject: sort: fix SIGPIPE handling X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6382388da8268b964eb27845c50969c7ac03e4de;p=thirdparty%2Fcoreutils.git sort: fix SIGPIPE handling * src/sort.c (main): Don't override handler for SIGPIPE (which we did since commit v9.9-34-ge63131b32), since we've explicit handling for SIGPIPE. Also move ignoring of SIGPIPE until after --help and --version are processed. --- diff --git a/src/sort.c b/src/sort.c index 26afc97ec5..1fdec81fd8 100644 --- a/src/sort.c +++ b/src/sort.c @@ -4440,6 +4440,8 @@ main (int argc, char **argv) sigemptyset (&caught_signals); for (size_t i = 0; i < nsigs; i++) { + if (term_sig[i] == SIGPIPE) + continue; /* Handled below. */ sigaction (term_sig[i], nullptr, &act); if (act.sa_handler != SIG_IGN) sigaddset (&caught_signals, term_sig[i]); @@ -4450,16 +4452,15 @@ main (int argc, char **argv) act.sa_flags = 0; for (size_t i = 0; i < nsigs; i++) - if (sigismember (&caught_signals, term_sig[i])) - sigaction (term_sig[i], &act, nullptr); + { + if (term_sig[i] == SIGPIPE) + continue; /* Handled below. */ + if (sigismember (&caught_signals, term_sig[i])) + sigaction (term_sig[i], &act, nullptr); + } } signal (SIGCHLD, SIG_DFL); /* Don't inherit CHLD handling from parent. */ - /* Ignore SIGPIPE so write failures are reported via EPIPE errno. - For stdout, sort_die() will reraise SIGPIPE if it was originally SIG_DFL. - For compression pipes, sort_die() will exit with SORT_FAILURE. */ - default_SIGPIPE = (signal (SIGPIPE, SIG_IGN) == SIG_DFL); - /* The signal mask is known, so it is safe to invoke exit_cleanup. */ atexit (exit_cleanup); @@ -4742,6 +4743,11 @@ main (int argc, char **argv) } } + /* Ignore SIGPIPE so write failures are reported via EPIPE errno. + For stdout, sort_die() will reraise SIGPIPE if it was originally SIG_DFL. + For compression pipes, sort_die() will exit with SORT_FAILURE. */ + default_SIGPIPE = (signal (SIGPIPE, SIG_IGN) == SIG_DFL); + if (files_from) { /* When using --files0-from=F, you may not specify any files