summaryrefslogtreecommitdiff
path: root/src/core/manager.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-28 02:18:59 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-28 02:18:59 +0100
commit2e5c94b9aaefce46835b623e800cfc168995ea3f (patch)
treefd08747425942a062e225497aa850dfa0b3ecc9d /src/core/manager.c
parenta986501b9059b72e8deced262554fbdd1ab9da17 (diff)
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.
Diffstat (limited to 'src/core/manager.c')
-rw-r--r--src/core/manager.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index e2df91196e..336ec1ed78 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;
}