From: Lennart Poettering Date: Tue, 26 Sep 2017 21:35:58 +0000 (+0200) Subject: core: log unit failure with type-specific result code X-Git-Tag: v235~50^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ed77d407d3766e78f96c848aed04da50a0ac7d42;p=thirdparty%2Fsystemd.git core: log unit failure with type-specific result code This slightly changes how we log about failures. Previously, service_enter_dead() would log that a service unit failed along with its result code, and unit_notify() would do this again but without the result code. For other unit types only the latter would take effect. This cleans this up: we keep the message in unit_notify() only for debug purposes, and add type-specific log lines to all our unit types that can fail, and always place them before unit_notify() is invoked. Or in other words: the duplicate log message for service units is removed, and all other unit types get a more useful line with the precise result code. --- diff --git a/src/core/automount.c b/src/core/automount.c index 5ee0937fa79..0c926165754 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -325,6 +325,9 @@ static void automount_enter_dead(Automount *a, AutomountResult f) { if (a->result == AUTOMOUNT_SUCCESS) a->result = f; + if (a->result != AUTOMOUNT_SUCCESS) + log_unit_warning(UNIT(a), "Failed with result '%s'.", automount_result_to_string(a->result)); + automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD); } diff --git a/src/core/mount.c b/src/core/mount.c index 22b3608a2f7..903b3a9c1b3 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -796,6 +796,9 @@ static void mount_enter_dead(Mount *m, MountResult f) { if (m->result == MOUNT_SUCCESS) m->result = f; + if (m->result != MOUNT_SUCCESS) + log_unit_warning(UNIT(m), "Failed with result '%s'.", mount_result_to_string(m->result)); + mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD); exec_runtime_destroy(m->exec_runtime); diff --git a/src/core/path.c b/src/core/path.c index 83f794be89e..7092ed13bac 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -457,6 +457,9 @@ static void path_enter_dead(Path *p, PathResult f) { if (p->result == PATH_SUCCESS) p->result = f; + if (p->result != PATH_SUCCESS) + log_unit_warning(UNIT(p), "Failed with result '%s'.", path_result_to_string(p->result)); + path_set_state(p, p->result != PATH_SUCCESS ? PATH_FAILED : PATH_DEAD); } diff --git a/src/core/scope.c b/src/core/scope.c index 8f9df3b9b7f..96702286948 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -253,6 +253,9 @@ static void scope_enter_dead(Scope *s, ScopeResult f) { if (s->result == SCOPE_SUCCESS) s->result = f; + if (s->result != SCOPE_SUCCESS) + log_unit_warning(UNIT(s), "Failed with result '%s'.", scope_result_to_string(s->result)); + scope_set_state(s, s->result != SCOPE_SUCCESS ? SCOPE_FAILED : SCOPE_DEAD); } diff --git a/src/core/service.c b/src/core/service.c index 47fecfb34f8..1a4455bd228 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1512,12 +1512,13 @@ 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) + log_unit_warning(UNIT(s), "Failed with result '%s'.", service_result_to_string(s->result)); + service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD); - if (s->result != SERVICE_SUCCESS) { - log_unit_warning(UNIT(s), "Failed with result '%s'.", service_result_to_string(s->result)); + if (s->result != SERVICE_SUCCESS) emergency_action(UNIT(s)->manager, s->emergency_action, UNIT(s)->reboot_arg, "service failed"); - } if (allow_restart && service_shall_restart(s)) { diff --git a/src/core/socket.c b/src/core/socket.c index 3b84ffa2a79..fa93101e52a 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1983,6 +1983,9 @@ static void socket_enter_dead(Socket *s, SocketResult f) { if (s->result == SOCKET_SUCCESS) s->result = f; + if (s->result != SOCKET_SUCCESS) + log_unit_warning(UNIT(s), "Failed with result '%s'.", socket_result_to_string(s->result)); + socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD); exec_runtime_destroy(s->exec_runtime); diff --git a/src/core/swap.c b/src/core/swap.c index 6db1c0df69e..f4757555726 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -665,6 +665,9 @@ static void swap_enter_dead(Swap *s, SwapResult f) { if (s->result == SWAP_SUCCESS) s->result = f; + if (s->result != SWAP_SUCCESS) + log_unit_warning(UNIT(s), "Failed with result '%s'.", swap_result_to_string(s->result)); + swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD); exec_runtime_destroy(s->exec_runtime); diff --git a/src/core/timer.c b/src/core/timer.c index 3032a237b17..a34bc7b14eb 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -296,6 +296,9 @@ static void timer_enter_dead(Timer *t, TimerResult f) { if (t->result == TIMER_SUCCESS) t->result = f; + if (t->result != TIMER_SUCCESS) + log_unit_warning(UNIT(t), "Failed with result '%s'.", timer_result_to_string(t->result)); + timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD); } diff --git a/src/core/unit.c b/src/core/unit.c index c31ddd771e7..60cf30ea3a4 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2272,7 +2272,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su check_unneeded_dependencies(u); if (ns != os && ns == UNIT_FAILED) { - log_unit_notice(u, "Unit entered failed state."); + log_unit_debug(u, "Unit entered failed state."); unit_start_on_failure(u); } }