chiark / gitweb /
core: when the user hits Ctrl-Alt-Del more than 7x per 2s, reboot immediately
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 01:18:59 +0000 (02:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 01:18:59 +0000 (02:18 +0100)
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
src/core/manager.h
src/core/unit-printf.c

index e2df91196e58f2f4020f3f12408ff2f612c0af7e..336ec1ed78269a013f48c487e13edef52fb075d8 100644 (file)
@@ -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;
                         }
 
index 19fb0a901d849b90063a5823bd349a855c5b0e86..d3971f16845225fd860fac96a1e2f5df1c91fc63 100644 (file)
 #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);
index 62599d0813bd2478ace3c0a95f51cbff374f9a7d..97135db551aa2f1e7cc7f42c99f4562e2ac79a55 100644 (file)
@@ -19,7 +19,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include "systemd/sd-id128.h"
+#include "sd-id128.h"
 #include "unit.h"
 #include "specifier.h"
 #include "path-util.h"