teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0274-util-reset-signals-when-we-fork-off-agents.patch

65878a
From 72be8870f1ab5d8753d966ee6c81f88734053a95 Mon Sep 17 00:00:00 2001
65878a
From: Lennart Poettering <lennart@poettering.net>
65878a
Date: Tue, 26 Aug 2014 21:04:21 +0200
65878a
Subject: [PATCH] util: reset signals when we fork off agents
65878a
65878a
If we invoke agents, we should make sure we actually can kill them
65878a
again. I mean, it's probably not our job to cleanup the signals if our
65878a
tools are invoked in weird contexts, but at least we should make sure,
65878a
that the subprocesses we invoke and intend to control work as intended.
65878a
65878a
Also see:
65878a
65878a
http://lists.freedesktop.org/archives/systemd-devel/2014-August/022460.html
65878a
65878a
(cherry picked from commit 8a7c93d858c342744adf481565d8bb03b9713dcf)
65878a
65878a
Resolves: #1134818
65878a
---
65878a
 src/shared/util.c | 18 ++++++++++++++++++
65878a
 src/shared/util.h |  1 +
65878a
 2 files changed, 19 insertions(+)
65878a
65878a
diff --git a/src/shared/util.c b/src/shared/util.c
65878a
index fc1f765..e4448ff 100644
65878a
--- a/src/shared/util.c
65878a
+++ b/src/shared/util.c
65878a
@@ -935,6 +935,18 @@ int reset_all_signal_handlers(void) {
65878a
         return 0;
65878a
 }
65878a
 
65878a
+int reset_signal_mask(void) {
65878a
+        sigset_t ss;
65878a
+
65878a
+        if (sigemptyset(&ss) < 0)
65878a
+                return -errno;
65878a
+
65878a
+        if (sigprocmask(SIG_SETMASK, &ss, NULL) < 0)
65878a
+                return -errno;
65878a
+
65878a
+        return 0;
65878a
+}
65878a
+
65878a
 char *strstrip(char *s) {
65878a
         char *e;
65878a
 
65878a
@@ -5028,6 +5040,12 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
65878a
         /* Don't leak fds to the agent */
65878a
         close_all_fds(except, n_except);
65878a
 
65878a
+        /* Make sure we actually can kill the agent, if we need to, in
65878a
+         * case somebody invoked us from a shell script that trapped
65878a
+         * SIGTERM or so... */
65878a
+        reset_all_signal_handlers();
65878a
+        reset_signal_mask();
65878a
+
65878a
         stdout_is_tty = isatty(STDOUT_FILENO);
65878a
         stderr_is_tty = isatty(STDERR_FILENO);
65878a
 
65878a
diff --git a/src/shared/util.h b/src/shared/util.h
65878a
index ec18d2c..5a9bc99 100644
65878a
--- a/src/shared/util.h
65878a
+++ b/src/shared/util.h
65878a
@@ -207,6 +207,7 @@ int readlink_and_make_absolute(const char *p, char **r);
65878a
 int readlink_and_canonicalize(const char *p, char **r);
65878a
 
65878a
 int reset_all_signal_handlers(void);
65878a
+int reset_signal_mask(void);
65878a
 
65878a
 char *strstrip(char *s);
65878a
 char *delete_chars(char *s, const char *bad);