core: introduce a helper function to wrap unit_log_{success,failure}

It's inline so that the compiler can easily optimize away the call to get
status string.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-16 10:09:45 +01:00
parent 14c4da2ffe
commit aac99f303a
8 changed files with 14 additions and 34 deletions

View File

@ -315,11 +315,7 @@ static void automount_enter_dead(Automount *a, AutomountResult f) {
if (a->result == AUTOMOUNT_SUCCESS)
a->result = f;
if (a->result == AUTOMOUNT_SUCCESS)
unit_log_success(UNIT(a));
else
unit_log_failure(UNIT(a), automount_result_to_string(a->result));
unit_log_result(UNIT(a), a->result == AUTOMOUNT_SUCCESS, automount_result_to_string(a->result));
automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
}

View File

@ -799,11 +799,7 @@ static void mount_enter_dead(Mount *m, MountResult f) {
if (m->result == MOUNT_SUCCESS)
m->result = f;
if (m->result == MOUNT_SUCCESS)
unit_log_success(UNIT(m));
else
unit_log_failure(UNIT(m), mount_result_to_string(m->result));
unit_log_result(UNIT(m), m->result == MOUNT_SUCCESS, mount_result_to_string(m->result));
mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
m->exec_runtime = exec_runtime_unref(m->exec_runtime, true);

View File

@ -449,11 +449,7 @@ static void path_enter_dead(Path *p, PathResult f) {
if (p->result == PATH_SUCCESS)
p->result = f;
if (p->result == PATH_SUCCESS)
unit_log_success(UNIT(p));
else
unit_log_failure(UNIT(p), path_result_to_string(p->result));
unit_log_result(UNIT(p), p->result == PATH_SUCCESS, path_result_to_string(p->result));
path_set_state(p, p->result != PATH_SUCCESS ? PATH_FAILED : PATH_DEAD);
}

View File

@ -240,11 +240,7 @@ static void scope_enter_dead(Scope *s, ScopeResult f) {
if (s->result == SCOPE_SUCCESS)
s->result = f;
if (s->result == SCOPE_SUCCESS)
unit_log_success(UNIT(s));
else
unit_log_failure(UNIT(s), scope_result_to_string(s->result));
unit_log_result(UNIT(s), s->result == SCOPE_SUCCESS, scope_result_to_string(s->result));
scope_set_state(s, s->result != SCOPE_SUCCESS ? SCOPE_FAILED : SCOPE_DEAD);
}

View File

@ -1699,10 +1699,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
if (s->result == SERVICE_SUCCESS)
s->result = f;
if (s->result == SERVICE_SUCCESS)
unit_log_success(UNIT(s));
else
unit_log_failure(UNIT(s), service_result_to_string(s->result));
unit_log_result(UNIT(s), s->result == SERVICE_SUCCESS, service_result_to_string(s->result));
if (allow_restart && service_shall_restart(s))
s->will_auto_restart = true;

View File

@ -653,11 +653,7 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
if (s->result == SWAP_SUCCESS)
s->result = f;
if (s->result == SWAP_SUCCESS)
unit_log_success(UNIT(s));
else
unit_log_failure(UNIT(s), swap_result_to_string(s->result));
unit_log_result(UNIT(s), s->result == SWAP_SUCCESS, swap_result_to_string(s->result));
swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
s->exec_runtime = exec_runtime_unref(s->exec_runtime, true);

View File

@ -288,11 +288,7 @@ static void timer_enter_dead(Timer *t, TimerResult f) {
if (t->result == TIMER_SUCCESS)
t->result = f;
if (t->result == TIMER_SUCCESS)
unit_log_success(UNIT(t));
else
unit_log_failure(UNIT(t), timer_result_to_string(t->result));
unit_log_result(UNIT(t), t->result == TIMER_SUCCESS, timer_result_to_string(t->result));
timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
}

View File

@ -808,6 +808,13 @@ int unit_pid_attachable(Unit *unit, pid_t pid, sd_bus_error *error);
void unit_log_success(Unit *u);
void unit_log_failure(Unit *u, const char *result);
static inline void unit_log_result(Unit *u, bool success, const char *result) {
if (success)
unit_log_success(u);
else
unit_log_failure(u, result);
}
void unit_log_process_exit(Unit *u, int level, const char *kind, const char *command, int code, int status);
/* Macros which append UNIT= or USER_UNIT= to the message */