summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-22 01:46:08 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-22 01:46:08 +0200
commit9a34ec5fbb4b55413dc9d610b636fe760d34ecd7 (patch)
tree75ca3c00d0954ad3c78dbb1c616d6fafd2b93ff0 /src
parente1ce2c2782015579f042d4d6963ed039333fb8c2 (diff)
execute: only reset those signals to the default we really need to reset to the default
Diffstat (limited to 'src')
-rw-r--r--src/execute.c6
-rw-r--r--src/execute.h4
-rw-r--r--src/main.c10
-rw-r--r--src/util.c49
-rw-r--r--src/util.h5
5 files changed, 62 insertions, 12 deletions
diff --git a/src/execute.c b/src/execute.c
index 06eb15215d..ead6c0fa42 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -783,7 +783,11 @@ int exec_spawn(ExecCommand *command,
/* child */
- reset_all_signal_handlers();
+ /* We reset exactly these two signals, since they are
+ * the only ones we set to SIG_IGN in the main
+ * daemon. All others */
+ default_signals(SIGNALS_CRASH_HANLDER,
+ SIGNALS_IGNORE, -1);
if (sigemptyset(&ss) < 0 ||
sigprocmask(SIG_SETMASK, &ss, NULL) < 0) {
diff --git a/src/execute.h b/src/execute.h
index d42e0ba9d9..045d4620d7 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -41,6 +41,10 @@ struct CGroupBonding;
/* Abstract namespace! */
#define LOGGER_SOCKET "/org/freedesktop/systemd1/logger"
+/* This doesn't really belong here, but I couldn't find a better place to put this. */
+#define SIGNALS_CRASH_HANLDER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
+#define SIGNALS_IGNORE SIGKILL,SIGPIPE
+
typedef enum ExecInput {
EXEC_INPUT_NULL,
EXEC_INPUT_TTY,
diff --git a/src/main.c b/src/main.c
index 95d2115230..5c2af042d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -165,12 +165,7 @@ static void install_crash_handler(void) {
sa.sa_handler = crash;
sa.sa_flags = SA_NODEFER;
- assert_se(sigaction(SIGSEGV, &sa, NULL) == 0);
- assert_se(sigaction(SIGILL, &sa, NULL) == 0);
- assert_se(sigaction(SIGFPE, &sa, NULL) == 0);
- assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
- assert_se(sigaction(SIGQUIT, &sa, NULL) == 0);
- assert_se(sigaction(SIGABRT, &sa, NULL) == 0);
+ sigaction_many(&sa, SIGNALS_CRASH_HANLDER, -1);
}
static int make_null_stdio(void) {
@@ -569,8 +564,7 @@ int main(int argc, char *argv[]) {
assert_se(reset_all_signal_handlers() == 0);
/* If we are init, we can block sigkill. Yay. */
- ignore_signal(SIGKILL);
- ignore_signal(SIGPIPE);
+ ignore_signals(SIGNALS_IGNORE, -1);
if (running_as != MANAGER_SESSION)
if (parse_proc_cmdline() < 0)
diff --git a/src/util.c b/src/util.c
index 5c1e16ab6e..47b1b443ff 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1735,14 +1735,59 @@ int release_terminal(void) {
return r;
}
-int ignore_signal(int sig) {
+int sigaction_many(const struct sigaction *sa, ...) {
+ va_list ap;
+ int r = 0, sig;
+
+ va_start(ap, sa);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
+}
+
+int ignore_signals(int sig, ...) {
struct sigaction sa;
+ va_list ap;
+ int r = 0;
zero(sa);
sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_RESTART;
- return sigaction(sig, &sa, NULL);
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+
+ va_start(ap, sig);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
+}
+
+int default_signals(int sig, ...) {
+ struct sigaction sa;
+ va_list ap;
+ int r = 0;
+
+ zero(sa);
+ sa.sa_handler = SIG_DFL;
+ sa.sa_flags = SA_RESTART;
+
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+
+ va_start(ap, sig);
+ while ((sig = va_arg(ap, int)) > 0)
+ if (sigaction(sig, &sa, NULL) < 0)
+ r = -errno;
+ va_end(ap);
+
+ return r;
}
int close_pipe(int p[]) {
diff --git a/src/util.h b/src/util.h
index 84dd2bc8d1..93d67081b7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -28,6 +28,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
+#include <signal.h>
typedef uint64_t usec_t;
@@ -223,7 +224,9 @@ int release_terminal(void);
int flush_fd(int fd);
-int ignore_signal(int sig);
+int ignore_signals(int sig, ...);
+int default_signals(int sig, ...);
+int sigaction_many(const struct sigaction *sa, ...);
int close_pipe(int p[]);