mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 08:56:15 +09:00
core: remember first unit failure, not last unit failure
Previously, the result value of a unit was overriden with each failure that took place, so that the result always reported the last failure that took place. With this commit this is changed, so that the first failure taking place is stored instead. This should normally not matter much as multiple failures are sufficiently uncommon. However, it improves one behaviour: if we send SIGABRT to a service due to a watchdog timeout, then this currently would be reported as "coredump" failure, rather than the "watchodg" failure it really is. Hence, in order to report information about the type of the failure, and not about the effect of it, let's change this from all unit type to store the first, not the last failure. This addresses the issue pointed out here: https://github.com/systemd/systemd/pull/3818#discussion_r73433520
This commit is contained in:
@@ -301,7 +301,7 @@ static void automount_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
static void automount_enter_dead(Automount *a, AutomountResult f) {
|
||||
assert(a);
|
||||
|
||||
if (f != AUTOMOUNT_SUCCESS)
|
||||
if (a->result == AUTOMOUNT_SUCCESS)
|
||||
a->result = f;
|
||||
|
||||
automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
|
||||
|
||||
@@ -442,7 +442,7 @@ fail:
|
||||
static void busname_enter_dead(BusName *n, BusNameResult f) {
|
||||
assert(n);
|
||||
|
||||
if (f != BUSNAME_SUCCESS)
|
||||
if (n->result == BUSNAME_SUCCESS)
|
||||
n->result = f;
|
||||
|
||||
busname_set_state(n, n->result != BUSNAME_SUCCESS ? BUSNAME_FAILED : BUSNAME_DEAD);
|
||||
@@ -454,7 +454,7 @@ static void busname_enter_signal(BusName *n, BusNameState state, BusNameResult f
|
||||
|
||||
assert(n);
|
||||
|
||||
if (f != BUSNAME_SUCCESS)
|
||||
if (n->result == BUSNAME_SUCCESS)
|
||||
n->result = f;
|
||||
|
||||
kill_context_init(&kill_context);
|
||||
@@ -882,7 +882,7 @@ static void busname_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
log_unit_full(u, f == BUSNAME_SUCCESS ? LOG_DEBUG : LOG_NOTICE, 0,
|
||||
"Control process exited, code=%s status=%i", sigchld_code_to_string(code), status);
|
||||
|
||||
if (f != BUSNAME_SUCCESS)
|
||||
if (n->result == BUSNAME_SUCCESS)
|
||||
n->result = f;
|
||||
|
||||
switch (n->state) {
|
||||
|
||||
@@ -759,7 +759,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
|
||||
static void mount_enter_dead(Mount *m, MountResult f) {
|
||||
assert(m);
|
||||
|
||||
if (f != MOUNT_SUCCESS)
|
||||
if (m->result == MOUNT_SUCCESS)
|
||||
m->result = f;
|
||||
|
||||
mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
|
||||
@@ -775,7 +775,7 @@ static void mount_enter_dead(Mount *m, MountResult f) {
|
||||
static void mount_enter_mounted(Mount *m, MountResult f) {
|
||||
assert(m);
|
||||
|
||||
if (f != MOUNT_SUCCESS)
|
||||
if (m->result == MOUNT_SUCCESS)
|
||||
m->result = f;
|
||||
|
||||
mount_set_state(m, MOUNT_MOUNTED);
|
||||
@@ -786,7 +786,7 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) {
|
||||
|
||||
assert(m);
|
||||
|
||||
if (f != MOUNT_SUCCESS)
|
||||
if (m->result == MOUNT_SUCCESS)
|
||||
m->result = f;
|
||||
|
||||
r = unit_kill_context(
|
||||
@@ -1158,7 +1158,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
else
|
||||
assert_not_reached("Unknown code");
|
||||
|
||||
if (f != MOUNT_SUCCESS)
|
||||
if (m->result == MOUNT_SUCCESS)
|
||||
m->result = f;
|
||||
|
||||
if (m->control_command) {
|
||||
|
||||
@@ -454,7 +454,7 @@ static int path_coldplug(Unit *u) {
|
||||
static void path_enter_dead(Path *p, PathResult f) {
|
||||
assert(p);
|
||||
|
||||
if (f != PATH_SUCCESS)
|
||||
if (p->result == PATH_SUCCESS)
|
||||
p->result = f;
|
||||
|
||||
path_set_state(p, p->result != PATH_SUCCESS ? PATH_FAILED : PATH_DEAD);
|
||||
|
||||
@@ -221,7 +221,7 @@ static void scope_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
static void scope_enter_dead(Scope *s, ScopeResult f) {
|
||||
assert(s);
|
||||
|
||||
if (f != SCOPE_SUCCESS)
|
||||
if (s->result == SCOPE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
scope_set_state(s, s->result != SCOPE_SUCCESS ? SCOPE_FAILED : SCOPE_DEAD);
|
||||
@@ -233,7 +233,7 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
|
||||
|
||||
assert(s);
|
||||
|
||||
if (f != SCOPE_SUCCESS)
|
||||
if (s->result == SCOPE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
unit_watch_all_pids(UNIT(s));
|
||||
|
||||
@@ -1423,7 +1423,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
|
||||
int r;
|
||||
assert(s);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
service_set_state(s, s->result != SERVICE_SUCCESS ? SERVICE_FAILED : SERVICE_DEAD);
|
||||
@@ -1472,7 +1472,7 @@ static void service_enter_stop_post(Service *s, ServiceResult f) {
|
||||
int r;
|
||||
assert(s);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
service_unwatch_control_pid(s);
|
||||
@@ -1525,7 +1525,7 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
|
||||
|
||||
assert(s);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
unit_watch_all_pids(UNIT(s));
|
||||
@@ -1583,7 +1583,7 @@ static void service_enter_stop(Service *s, ServiceResult f) {
|
||||
|
||||
assert(s);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
service_unwatch_control_pid(s);
|
||||
@@ -1635,7 +1635,7 @@ static bool service_good(Service *s) {
|
||||
static void service_enter_running(Service *s, ServiceResult f) {
|
||||
assert(s);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
service_unwatch_control_pid(s);
|
||||
@@ -2609,7 +2609,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
"EXIT_STATUS=%i", status,
|
||||
NULL);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
if (s->main_command &&
|
||||
@@ -2690,7 +2690,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
"Control process exited, code=%s status=%i",
|
||||
sigchld_code_to_string(code), status);
|
||||
|
||||
if (f != SERVICE_SUCCESS)
|
||||
if (s->result == SERVICE_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
/* Immediately get rid of the cgroup, so that the
|
||||
|
||||
@@ -1810,7 +1810,7 @@ fail:
|
||||
static void socket_enter_dead(Socket *s, SocketResult f) {
|
||||
assert(s);
|
||||
|
||||
if (f != SOCKET_SUCCESS)
|
||||
if (s->result == SOCKET_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD);
|
||||
@@ -1829,7 +1829,7 @@ static void socket_enter_stop_post(Socket *s, SocketResult f) {
|
||||
int r;
|
||||
assert(s);
|
||||
|
||||
if (f != SOCKET_SUCCESS)
|
||||
if (s->result == SOCKET_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
socket_unwatch_control_pid(s);
|
||||
@@ -1857,7 +1857,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
|
||||
|
||||
assert(s);
|
||||
|
||||
if (f != SOCKET_SUCCESS)
|
||||
if (s->result == SOCKET_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
r = unit_kill_context(
|
||||
@@ -1901,7 +1901,7 @@ static void socket_enter_stop_pre(Socket *s, SocketResult f) {
|
||||
int r;
|
||||
assert(s);
|
||||
|
||||
if (f != SOCKET_SUCCESS)
|
||||
if (s->result == SOCKET_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
socket_unwatch_control_pid(s);
|
||||
@@ -2822,7 +2822,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
"Control process exited, code=%s status=%i",
|
||||
sigchld_code_to_string(code), status);
|
||||
|
||||
if (f != SOCKET_SUCCESS)
|
||||
if (s->result == SOCKET_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
if (s->control_command &&
|
||||
|
||||
@@ -673,7 +673,7 @@ fail:
|
||||
static void swap_enter_dead(Swap *s, SwapResult f) {
|
||||
assert(s);
|
||||
|
||||
if (f != SWAP_SUCCESS)
|
||||
if (s->result == SWAP_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
|
||||
@@ -689,7 +689,7 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
|
||||
static void swap_enter_active(Swap *s, SwapResult f) {
|
||||
assert(s);
|
||||
|
||||
if (f != SWAP_SUCCESS)
|
||||
if (s->result == SWAP_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
swap_set_state(s, SWAP_ACTIVE);
|
||||
@@ -700,7 +700,7 @@ static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) {
|
||||
|
||||
assert(s);
|
||||
|
||||
if (f != SWAP_SUCCESS)
|
||||
if (s->result == SWAP_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
r = unit_kill_context(
|
||||
@@ -997,7 +997,7 @@ static void swap_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
else
|
||||
assert_not_reached("Unknown code");
|
||||
|
||||
if (f != SWAP_SUCCESS)
|
||||
if (s->result == SWAP_SUCCESS)
|
||||
s->result = f;
|
||||
|
||||
if (s->control_command) {
|
||||
|
||||
@@ -291,7 +291,7 @@ static int timer_coldplug(Unit *u) {
|
||||
static void timer_enter_dead(Timer *t, TimerResult f) {
|
||||
assert(t);
|
||||
|
||||
if (f != TIMER_SUCCESS)
|
||||
if (t->result == TIMER_SUCCESS)
|
||||
t->result = f;
|
||||
|
||||
timer_set_state(t, t->result != TIMER_SUCCESS ? TIMER_FAILED : TIMER_DEAD);
|
||||
|
||||
Reference in New Issue
Block a user