[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] [SV 63307] Reset SIGPIPE in spawned children
From: |
Andreas Schwab |
Subject: |
[PATCH] [SV 63307] Reset SIGPIPE in spawned children |
Date: |
Wed, 02 Nov 2022 17:02:43 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
* configure.ac: Check for posix_spawnattr_setsigdefault.
* src/job.c (child_execute_job): Reset SIGPIPE in the child
process.
* src/job.h (sigpipe_ignored): Declare.
* src/main.c (main): Remember if SIGPIPE was inherited as ignored.
---
configure.ac | 2 +-
src/job.c | 24 ++++++++++++++++++++++++
src/job.h | 2 ++
src/main.c | 2 +-
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9f688971..30eb2d55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,7 +134,7 @@ AC_CHECK_FUNCS([strtoll strdup strndup stpcpy memrchr
mempcpy umask mkstemp \
getgroups seteuid setegid setlinebuf setreuid setregid \
mkfifo getrlimit setrlimit setvbuf pipe strerror strsignal \
lstat readlink atexit isatty ttyname pselect posix_spawn \
- posix_spawnattr_setsigmask])
+ posix_spawnattr_setsigmask posix_spawnattr_setsigdefault])
# We need to check declarations, not just existence, because on Tru64 this
# function is not declared without special flags, which themselves cause
diff --git a/src/job.c b/src/job.c
index b78f279c..4f32f0f7 100644
--- a/src/job.c
+++ b/src/job.c
@@ -261,6 +261,10 @@ unsigned long job_counter = 0;
/* Number of jobserver tokens this instance is currently using. */
unsigned int jobserver_tokens = 0;
+
+/* Whether SIGPIPE was ignored on entry. */
+
+int sigpipe_ignored;
#ifdef WINDOWS32
@@ -2305,6 +2309,12 @@ child_execute_job (struct childbase *child, int
good_stdin, char **argv)
/* We are the child. */
unblock_all_sigs ();
+ /* Unignore SIPIPE. */
+#ifdef SIGPIPE
+ if (!sigpipe_ignored)
+ bsd_signal (SIGPIPE, SIG_DFL);
+#endif
+
#ifdef SET_STACK_SIZE
/* Reset limits, if necessary. */
if (stack_limit.rlim_cur)
@@ -2347,6 +2357,20 @@ child_execute_job (struct childbase *child, int
good_stdin, char **argv)
}
#endif /* have posix_spawnattr_setsigmask() */
+ /* Unignore SIGPIPE. */
+#ifdef HAVE_POSIX_SPAWNATTR_SETSIGDEFAULT
+ if (!sigpipe_ignored)
+ {
+ sigset_t mask;
+ sigemptyset (&mask);
+ sigaddset (&mask, SIGPIPE);
+ r = posix_spawnattr_setsigdefault (&attr, &mask);
+ if (r != 0)
+ goto cleanup;
+ flags |= POSIX_SPAWN_SETSIGDEF;
+ }
+#endif
+
/* USEVFORK can give significant speedup on systems where it's available. */
#ifdef POSIX_SPAWN_USEVFORK
flags |= POSIX_SPAWN_USEVFORK;
diff --git a/src/job.h b/src/job.h
index 14a9984d..b0352bd7 100644
--- a/src/job.h
+++ b/src/job.h
@@ -88,5 +88,7 @@ pid_t exec_command (char **argv, char **envp);
void unblock_all_sigs (void);
+extern int sigpipe_ignored;
+
extern unsigned int job_slots_used;
extern unsigned int jobserver_tokens;
diff --git a/src/main.c b/src/main.c
index eec93656..3b39e9fe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1184,7 +1184,7 @@ main (int argc, char **argv, char **envp)
/* Don't die if our stdout sends us SIGPIPE. */
#ifdef SIGPIPE
- bsd_signal (SIGPIPE, SIG_IGN);
+ sigpipe_ignored = bsd_signal (SIGPIPE, SIG_IGN) == SIG_IGN;
#endif
#ifdef HAVE_ATEXIT
--
2.38.1
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] [SV 63307] Reset SIGPIPE in spawned children,
Andreas Schwab <=