From 36c4dc089e21e731e7ff5519aa6c636dd55e30e5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Mar 2019 13:20:54 +0100 Subject: [PATCH] core: change emergency_action() to return void The function so far always returned -ECANCELLED, which is ignored in all cases the function is invoked, except one: in unit_test_start_limit() where -ECANCELLED is returned when the start limit is hit, which is part of unit_start()'s protocol of return values. Since the emergency_action() logic should be relatively generic and is used in many places, let's drop the return value from it, since it's constant anyway, and in alll cases useless. Instead, let's return it in unit_test_start_limit(), where it's part of the protocol. No change in behaviour. --- src/core/emergency-action.c | 8 +++----- src/core/emergency-action.h | 6 +++--- src/core/unit.c | 12 +++++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index f98b0de792..9731aef5c4 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -20,7 +20,7 @@ static void log_and_status(Manager *m, bool warn, const char *message, const cha "%s: %s", message, reason); } -int emergency_action( +void emergency_action( Manager *m, EmergencyAction action, EmergencyActionFlags options, @@ -33,11 +33,11 @@ int emergency_action( assert(action < _EMERGENCY_ACTION_MAX); if (action == EMERGENCY_ACTION_NONE) - return -ECANCELED; + return; if (FLAGS_SET(options, EMERGENCY_ACTION_IS_WATCHDOG) && !m->service_watchdogs) { log_warning("Watchdog disabled! Not acting on: %s", reason); - return -ECANCELED; + return; } bool warn = FLAGS_SET(options, EMERGENCY_ACTION_WARN); @@ -125,8 +125,6 @@ int emergency_action( default: assert_not_reached("Unknown emergency action"); } - - return -ECANCELED; } static const char* const emergency_action_table[_EMERGENCY_ACTION_MAX] = { diff --git a/src/core/emergency-action.h b/src/core/emergency-action.h index 6e6c69ddfc..706c38a7d7 100644 --- a/src/core/emergency-action.h +++ b/src/core/emergency-action.h @@ -24,9 +24,9 @@ typedef enum EmergencyActionFlags { #include "macro.h" #include "manager.h" -int emergency_action(Manager *m, - EmergencyAction action, EmergencyActionFlags options, - const char *reboot_arg, int exit_status, const char *reason); +void emergency_action(Manager *m, + EmergencyAction action, EmergencyActionFlags options, + const char *reboot_arg, int exit_status, 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/unit.c b/src/core/unit.c index 96b520f3d1..1ce7ceb3e1 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1682,9 +1682,11 @@ int unit_test_start_limit(Unit *u) { reason = strjoina("unit ", u->id, " failed"); - return emergency_action(u->manager, u->start_limit_action, - EMERGENCY_ACTION_IS_WATCHDOG|EMERGENCY_ACTION_WARN, - u->reboot_arg, -1, reason); + emergency_action(u->manager, u->start_limit_action, + EMERGENCY_ACTION_IS_WATCHDOG|EMERGENCY_ACTION_WARN, + u->reboot_arg, -1, reason); + + return -ECANCELED; } bool unit_shall_confirm_spawn(Unit *u) { @@ -2511,10 +2513,10 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag if (os != UNIT_FAILED && ns == UNIT_FAILED) { reason = strjoina("unit ", u->id, " failed"); - (void) emergency_action(m, u->failure_action, 0, u->reboot_arg, unit_failure_action_exit_status(u), reason); + emergency_action(m, u->failure_action, 0, u->reboot_arg, unit_failure_action_exit_status(u), reason); } else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && ns == UNIT_INACTIVE) { reason = strjoina("unit ", u->id, " succeeded"); - (void) emergency_action(m, u->success_action, 0, u->reboot_arg, unit_success_action_exit_status(u), reason); + emergency_action(m, u->success_action, 0, u->reboot_arg, unit_success_action_exit_status(u), reason); } } -- 2.25.1