From 9a34ec5fbb4b55413dc9d610b636fe760d34ecd7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 22 May 2010 01:46:08 +0200 Subject: [PATCH] execute: only reset those signals to the default we really need to reset to the default --- fixme | 4 ---- src/execute.c | 6 +++++- src/execute.h | 4 ++++ src/main.c | 10 ++-------- src/util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- src/util.h | 5 ++++- 6 files changed, 62 insertions(+), 16 deletions(-) diff --git a/fixme b/fixme index d15e0db6..513c32b6 100644 --- a/fixme +++ b/fixme @@ -23,8 +23,6 @@ * reinvestigate random seed, hwclock -* introduce serialized mode - * "disabled" load state? * uid are 32bit @@ -63,8 +61,6 @@ * Add code to systemctl to wait for an operation to finish -* update to new libudev/tags - Regularly: * look for close() vs. close_nointr() vs. close_nointr_nofail() diff --git a/src/execute.c b/src/execute.c index 06eb1521..ead6c0fa 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 d42e0ba9..045d4620 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 95d21152..5c2af042 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 5c1e16ab..47b1b443 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 84dd2bc8..93d67081 100644 --- a/src/util.h +++ b/src/util.h @@ -28,6 +28,7 @@ #include #include #include +#include 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[]); -- 2.39.5