summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/manager.c16
-rw-r--r--src/core/manager.h10
-rw-r--r--src/core/unit-printf.c2
3 files changed, 23 insertions, 5 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;
}
diff --git a/src/core/manager.h b/src/core/manager.h
index 19fb0a901d..d3971f1684 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 62599d0813..97135db551 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -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"