diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-28 18:24:20 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-28 21:34:23 +0200 |
commit | 597466f49752a52e85ea04051d020f97e8739f72 (patch) | |
tree | b8db897a9af2741644e4deafdc0b11094b95edb9 /src | |
parent | 68a01fb658c926b527bd58da94467903feb5d1d0 (diff) |
exit-status: introduce common exit_status_set_test() call for testing exit status set membership
Diffstat (limited to 'src')
-rw-r--r-- | src/core/service.c | 6 | ||||
-rw-r--r-- | src/shared/exit-status.c | 14 | ||||
-rw-r--r-- | src/shared/exit-status.h | 1 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/core/service.c b/src/core/service.c index 9104347f27..d004728671 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1290,10 +1290,8 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart) (s->restart == SERVICE_RESTART_ON_ABNORMAL && !IN_SET(s->result, SERVICE_SUCCESS, SERVICE_FAILURE_EXIT_CODE)) || (s->restart == SERVICE_RESTART_ON_WATCHDOG && s->result == SERVICE_FAILURE_WATCHDOG) || (s->restart == SERVICE_RESTART_ON_ABORT && IN_SET(s->result, SERVICE_FAILURE_SIGNAL, SERVICE_FAILURE_CORE_DUMP)) || - (s->main_exec_status.code == CLD_EXITED && set_contains(s->restart_force_status.status, INT_TO_PTR(s->main_exec_status.status))) || - (IN_SET(s->main_exec_status.code, CLD_KILLED, CLD_DUMPED) && set_contains(s->restart_force_status.signal, INT_TO_PTR(s->main_exec_status.status)))) && - (s->main_exec_status.code != CLD_EXITED || !set_contains(s->restart_prevent_status.status, INT_TO_PTR(s->main_exec_status.status))) && - (!IN_SET(s->main_exec_status.code, CLD_KILLED, CLD_DUMPED) || !set_contains(s->restart_prevent_status.signal, INT_TO_PTR(s->main_exec_status.status)))) { + exit_status_set_test(&s->restart_force_status, s->main_exec_status.code, s->main_exec_status.status)) && + !exit_status_set_test(&s->restart_prevent_status, s->main_exec_status.code, s->main_exec_status.status)) { r = service_arm_timer(s, s->restart_usec); if (r < 0) diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 9e14eb8bf5..c09efdd2cb 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -225,3 +225,17 @@ bool exit_status_set_is_empty(ExitStatusSet *x) { return set_isempty(x->status) && set_isempty(x->signal); } + +bool exit_status_set_test(ExitStatusSet *x, int code, int status) { + + if (exit_status_set_is_empty(x)) + return false; + + if (code == CLD_EXITED && set_contains(x->status, INT_TO_PTR(status))) + return true; + + if (IN_SET(code, CLD_KILLED, CLD_DUMPED) && set_contains(x->signal, INT_TO_PTR(status))) + return true; + + return false; +} diff --git a/src/shared/exit-status.h b/src/shared/exit-status.h index 1d774f25dc..7259cd1d18 100644 --- a/src/shared/exit-status.h +++ b/src/shared/exit-status.h @@ -100,3 +100,4 @@ bool is_clean_exit_lsb(int code, int status, ExitStatusSet *success_status); void exit_status_set_free(ExitStatusSet *x); bool exit_status_set_is_empty(ExitStatusSet *x); +bool exit_status_set_test(ExitStatusSet *x, int code, int status); |