diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index e14a3aae17..3f0c11a3f2 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -21,6 +21,7 @@ static void log_and_status(Manager *m, const char *message, const char *reason) int emergency_action( Manager *m, EmergencyAction action, + EmergencyActionFlags options, const char *reboot_arg, const char *reason) { @@ -31,7 +32,7 @@ int emergency_action( if (action == EMERGENCY_ACTION_NONE) return -ECANCELED; - if (!m->service_watchdogs) { + if (FLAGS_SET(options, EMERGENCY_ACTION_IS_WATCHDOG) && !m->service_watchdogs) { log_warning("Watchdog disabled! Not acting on: %s", reason); return -ECANCELED; } diff --git a/src/core/emergency-action.h b/src/core/emergency-action.h index 3f6f6e0a03..453de0dbd2 100644 --- a/src/core/emergency-action.h +++ b/src/core/emergency-action.h @@ -16,10 +16,16 @@ typedef enum EmergencyAction { _EMERGENCY_ACTION_INVALID = -1 } EmergencyAction; +typedef enum EmergencyActionFlags { + EMERGENCY_ACTION_IS_WATCHDOG = 1 << 0, +} EmergencyActionFlags; + #include "macro.h" #include "manager.h" -int emergency_action(Manager *m, EmergencyAction action, const char *reboot_arg, const char *reason); +int emergency_action(Manager *m, + EmergencyAction action, EmergencyActionFlags options, + const char *reboot_arg, const char *reason); const char* emergency_action_to_string(EmergencyAction i) _const_; EmergencyAction emergency_action_from_string(const char *s) _pure_; diff --git a/src/core/job.c b/src/core/job.c index 6b17cc1d6f..23717d5e47 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -973,7 +973,8 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user u = j->unit; job_finish_and_invalidate(j, JOB_TIMEOUT, true, false); - emergency_action(u->manager, u->job_timeout_action, u->job_timeout_reboot_arg, "job timed out"); + emergency_action(u->manager, u->job_timeout_action, EMERGENCY_ACTION_IS_WATCHDOG, + u->job_timeout_reboot_arg, "job timed out"); return 0; } diff --git a/src/core/manager.c b/src/core/manager.c index af84a0a769..0c3109b34b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -2538,7 +2538,7 @@ static void manager_handle_ctrl_alt_del(Manager *m) { if (ratelimit_below(&m->ctrl_alt_del_ratelimit) || m->cad_burst_action == EMERGENCY_ACTION_NONE) manager_start_target(m, SPECIAL_CTRL_ALT_DEL_TARGET, JOB_REPLACE_IRREVERSIBLY); else - emergency_action(m, m->cad_burst_action, NULL, + emergency_action(m, m->cad_burst_action, 0, NULL, "Ctrl-Alt-Del was pressed more than 7 times within 2s"); } diff --git a/src/core/unit.c b/src/core/unit.c index d90456e03c..0806a50cce 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1724,7 +1724,8 @@ int unit_start_limit_test(Unit *u) { log_unit_warning(u, "Start request repeated too quickly."); u->start_limit_hit = true; - return emergency_action(u->manager, u->start_limit_action, u->reboot_arg, "unit failed"); + return emergency_action(u->manager, u->start_limit_action, EMERGENCY_ACTION_IS_WATCHDOG, + u->reboot_arg, "unit failed"); } bool unit_shall_confirm_spawn(Unit *u) { @@ -2498,9 +2499,11 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag unit_check_binds_to(u); if (os != UNIT_FAILED && ns == UNIT_FAILED) - (void) emergency_action(u->manager, u->failure_action, u->reboot_arg, "unit failed"); + (void) emergency_action(u->manager, u->failure_action, 0, + u->reboot_arg, "unit failed"); else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && ns == UNIT_INACTIVE) - (void) emergency_action(u->manager, u->success_action, u->reboot_arg, "unit succeeded"); + (void) emergency_action(u->manager, u->success_action, 0, + u->reboot_arg, "unit succeeded"); } unit_add_to_dbus_queue(u);