mirror of
https://github.com/systemd/systemd.git
synced 2024-10-27 18:55:40 +03:00
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.
This commit is contained in:
parent
a986501b90
commit
2e5c94b9aa
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user