From 2e5c94b9aaefce46835b623e800cfc168995ea3f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 28 Jan 2015 02:18:59 +0100 Subject: [PATCH 1/1] core: when the user hits Ctrl-Alt-Del more than 7x per 2s, reboot immediately This should be useful for cases where clean rebooting doesn't work, and the user wants to hurry up the reboot. --- src/core/manager.c | 16 +++++++++++++++- src/core/manager.h | 10 +++++++--- src/core/unit-printf.c | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/core/manager.c b/src/core/manager.c index e2df91196..336ec1ed7 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -549,6 +549,9 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) { m->test_run = test_run; + /* Reboot immediately if the user hits C-A-D more often than 7x per 2s */ + RATELIMIT_INIT(m->ctrl_alt_del_ratelimit, 2 * USEC_PER_SEC, 7); + r = manager_default_environment(m); if (r < 0) goto fail; @@ -1721,7 +1724,18 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t case SIGINT: if (m->running_as == SYSTEMD_SYSTEM) { - manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY); + + /* If the user presses C-A-D too more + * than 7 times within 2s, we reboot + * immediately. */ + + if (ratelimit_test(&m->ctrl_alt_del_ratelimit)) + manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY); + else { + log_notice("Ctrl-Alt-Del was pressed more than 7 times within 2s, rebooting immediately."); + m->exit_code = MANAGER_REBOOT; + } + break; } diff --git a/src/core/manager.h b/src/core/manager.h index 19fb0a901..d3971f168 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -29,6 +29,10 @@ #include "sd-event.h" #include "fdset.h" #include "cgroup-util.h" +#include "hashmap.h" +#include "list.h" +#include "set.h" +#include "ratelimit.h" /* Enforce upper limit how many names we allow */ #define MANAGER_MAX_NAMES 131072 /* 128K */ @@ -68,9 +72,6 @@ typedef enum StatusType { #include "unit.h" #include "job.h" -#include "hashmap.h" -#include "list.h" -#include "set.h" #include "path-lookup.h" #include "execute.h" #include "unit-name.h" @@ -295,6 +296,9 @@ struct Manager { /* Used for processing polkit authorization responses */ Hashmap *polkit_registry; + + /* When the user hits C-A-D more than 7 times per 2s, reboot immediately... */ + RateLimit ctrl_alt_del_ratelimit; }; int manager_new(SystemdRunningAs running_as, bool test_run, Manager **m); diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 62599d081..97135db55 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -19,7 +19,7 @@ along with systemd; If not, see . ***/ -#include "systemd/sd-id128.h" +#include "sd-id128.h" #include "unit.h" #include "specifier.h" #include "path-util.h" -- 2.30.2