From 0003d1ab75f82dd6aa143582c5bd815b3b8f65e8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 14 Oct 2010 00:54:48 +0200 Subject: [PATCH] manager: hookup shutdown helper and signals --- src/manager.c | 33 +++++++++++++++++++++++++++------ src/service.c | 2 +- src/special.h | 3 ++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/manager.c b/src/manager.c index 1fe8936c..f2ec2b72 100644 --- a/src/manager.c +++ b/src/manager.c @@ -164,11 +164,16 @@ static int manager_setup_signals(Manager *m) { SIGWINCH, /* Kernel sends us this on kbrequest (alt-arrowup) */ SIGPWR, /* Some kernel drivers and upsd send us this on power failure */ SIGRTMIN+0, /* systemd: start default.target */ - SIGRTMIN+1, /* systemd: start rescue.target */ + SIGRTMIN+1, /* systemd: isolate rescue.target */ SIGRTMIN+2, /* systemd: isolate emergency.target */ SIGRTMIN+3, /* systemd: start halt.target */ SIGRTMIN+4, /* systemd: start poweroff.target */ SIGRTMIN+5, /* systemd: start reboot.target */ + SIGRTMIN+6, /* systemd: start kexec.target */ + SIGRTMIN+13, /* systemd: Immediate halt */ + SIGRTMIN+14, /* systemd: Immediate poweroff */ + SIGRTMIN+15, /* systemd: Immediate reboot */ + SIGRTMIN+16, /* systemd: Immediate kexec */ -1); assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0); @@ -1987,7 +1992,7 @@ static int manager_process_signal_fd(Manager *m) { } /* Run the exit target if there is one, if not, just exit. */ - if (manager_start_target(m, SPECIAL_EXIT_SERVICE, JOB_REPLACE) < 0) { + if (manager_start_target(m, SPECIAL_EXIT_TARGET, JOB_REPLACE) < 0) { m->exit_code = MANAGER_EXIT; return 0; } @@ -2058,22 +2063,38 @@ static int manager_process_signal_fd(Manager *m) { break; default: { - static const char * const table[] = { + /* Starting SIGRTMIN+0 */ + static const char * const target_table[] = { [0] = SPECIAL_DEFAULT_TARGET, [1] = SPECIAL_RESCUE_TARGET, [2] = SPECIAL_EMERGENCY_TARGET, [3] = SPECIAL_HALT_TARGET, [4] = SPECIAL_POWEROFF_TARGET, - [5] = SPECIAL_REBOOT_TARGET + [5] = SPECIAL_REBOOT_TARGET, + [6] = SPECIAL_KEXEC_TARGET + }; + + /* Starting SIGRTMIN+13, so that target halt and system halt are 10 apart */ + static const ManagerExitCode code_table[] = { + [0] = MANAGER_HALT, + [1] = MANAGER_POWEROFF, + [2] = MANAGER_REBOOT, + [3] = MANAGER_KEXEC }; if ((int) sfsi.ssi_signo >= SIGRTMIN+0 && - (int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(table)) { - manager_start_target(m, table[sfsi.ssi_signo - SIGRTMIN], + (int) sfsi.ssi_signo < SIGRTMIN+(int) ELEMENTSOF(target_table)) { + manager_start_target(m, target_table[sfsi.ssi_signo - SIGRTMIN], (sfsi.ssi_signo == 1 || sfsi.ssi_signo == 2) ? JOB_ISOLATE : JOB_REPLACE); break; } + if ((int) sfsi.ssi_signo >= SIGRTMIN+13 && + (int) sfsi.ssi_signo < SIGRTMIN+13+(int) ELEMENTSOF(code_table)) { + m->exit_code = code_table[sfsi.ssi_signo - SIGRTMIN - 13]; + break; + } + log_warning("Got unhandled signal <%s>.", strna(signal_to_string(sfsi.ssi_signo))); } } diff --git a/src/service.c b/src/service.c index 310aa28c..3ebe60e4 100644 --- a/src/service.c +++ b/src/service.c @@ -316,7 +316,7 @@ static int sysv_translate_facility(const char *name, const char *filename, char } /* If we don't know this name, fallback heuristics to figure - * out whether something is a target or an service alias. */ + * out whether something is a target or a service alias. */ if (*name == '$') /* Facilities starting with $ are most likely targets */ diff --git a/src/special.h b/src/special.h index ca241219..0b37353c 100644 --- a/src/special.h +++ b/src/special.h @@ -54,11 +54,12 @@ #define SPECIAL_SYSINIT_TARGET "sysinit.target" #define SPECIAL_FSCK_TARGET "fsck.target" #define SPECIAL_RESCUE_TARGET "rescue.target" -#define SPECIAL_EXIT_SERVICE "exit.service" +#define SPECIAL_EXIT_TARGET "exit.target" #define SPECIAL_EMERGENCY_TARGET "emergency.target" #define SPECIAL_HALT_TARGET "halt.target" #define SPECIAL_POWEROFF_TARGET "poweroff.target" #define SPECIAL_REBOOT_TARGET "reboot.target" +#define SPECIAL_KEXEC_TARGET "kexec.target" #define SPECIAL_DBUS_SERVICE "dbus.service" #define SPECIAL_DBUS_SOCKET "dbus.socket" #define SPECIAL_GETTY_TARGET "getty.target" -- 2.39.5