From: Lennart Poettering Date: Tue, 21 Apr 2015 00:17:01 +0000 (+0200) Subject: service: make kill operation mapping explicit X-Git-Tag: v220~388 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4940c0b0b621c0d5a4a3c1f3bc281ecba6151c58;p=thirdparty%2Fsystemd.git service: make kill operation mapping explicit --- diff --git a/src/core/service.c b/src/core/service.c index fa818fc871c..3b241fd0a4a 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1367,6 +1367,25 @@ fail: service_enter_signal(s, SERVICE_FINAL_SIGTERM, SERVICE_FAILURE_RESOURCES); } +static int state_to_kill_operation(ServiceState state) { + switch (state) { + + case SERVICE_STOP_SIGABRT: + return KILL_ABORT; + + case SERVICE_STOP_SIGTERM: + case SERVICE_FINAL_SIGTERM: + return KILL_TERMINATE; + + case SERVICE_STOP_SIGKILL: + case SERVICE_FINAL_SIGKILL: + return KILL_KILL; + + default: + return _KILL_OPERATION_INVALID; + } +} + static void service_enter_signal(Service *s, ServiceState state, ServiceResult f) { int r; @@ -1380,8 +1399,7 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f r = unit_kill_context( UNIT(s), &s->kill_context, - (state != SERVICE_STOP_SIGTERM && state != SERVICE_FINAL_SIGTERM && state != SERVICE_STOP_SIGABRT) ? - KILL_KILL : (state == SERVICE_STOP_SIGABRT ? KILL_ABORT : KILL_TERMINATE), + state_to_kill_operation(state), s->main_pid, s->control_pid, s->main_pid_alien); diff --git a/src/core/unit.h b/src/core/unit.h index 11242c2a001..260dc451c7b 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -52,6 +52,8 @@ typedef enum KillOperation { KILL_TERMINATE, KILL_KILL, KILL_ABORT, + _KILL_OPERATION_MAX, + _KILL_OPERATION_INVALID = -1 } KillOperation; static inline bool UNIT_IS_ACTIVE_OR_RELOADING(UnitActiveState t) {