core: output unit status output strings to console, only if we actually are changing unit state

Unit _start() and _stop() implementations can fail with -EAGAIN to delay
execution temporarily. Thus, we should not output status messages before
invoking these calls, but after, and only when we know that the
invocation actually made a change.
This commit is contained in:
Lennart Poettering
2015-01-28 15:07:13 +01:00
parent 3ad85e3775
commit 82a2b6bb5e
13 changed files with 49 additions and 35 deletions
+2 -2
View File
@@ -603,7 +603,7 @@ static int automount_start(Unit *u) {
a->result = AUTOMOUNT_SUCCESS;
automount_enter_waiting(a);
return 0;
return 1;
}
static int automount_stop(Unit *u) {
@@ -613,7 +613,7 @@ static int automount_stop(Unit *u) {
assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
automount_enter_dead(a, AUTOMOUNT_SUCCESS);
return 0;
return 1;
}
static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -615,7 +615,7 @@ static int busname_start(Unit *u) {
n->result = BUSNAME_SUCCESS;
busname_enter_making(n);
return 0;
return 1;
}
static int busname_stop(Unit *u) {
@@ -638,7 +638,7 @@ static int busname_stop(Unit *u) {
assert(IN_SET(n->state, BUSNAME_REGISTERED, BUSNAME_LISTENING, BUSNAME_RUNNING));
busname_enter_dead(n, BUSNAME_SUCCESS);
return 0;
return 1;
}
static int busname_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -1037,7 +1037,7 @@ static int mount_start(Unit *u) {
m->reload_result = MOUNT_SUCCESS;
mount_enter_mounting(m);
return 0;
return 1;
}
static int mount_stop(Unit *u) {
@@ -1061,7 +1061,7 @@ static int mount_stop(Unit *u) {
m->state == MOUNT_REMOUNTING_SIGKILL);
mount_enter_unmounting(m);
return 0;
return 1;
}
static int mount_reload(Unit *u) {
+2 -2
View File
@@ -572,7 +572,7 @@ static int path_start(Unit *u) {
p->result = PATH_SUCCESS;
path_enter_waiting(p, true, true);
return 0;
return 1;
}
static int path_stop(Unit *u) {
@@ -582,7 +582,7 @@ static int path_stop(Unit *u) {
assert(p->state == PATH_WAITING || p->state == PATH_RUNNING);
path_enter_dead(p, PATH_SUCCESS);
return 0;
return 1;
}
static int path_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -295,7 +295,7 @@ static int scope_start(Unit *u) {
s->result = SCOPE_SUCCESS;
scope_set_state(s, SCOPE_RUNNING);
return 0;
return 1;
}
static int scope_stop(Unit *u) {
@@ -311,7 +311,7 @@ static int scope_stop(Unit *u) {
s->state == SCOPE_ABANDONED);
scope_enter_signal(s, SCOPE_STOP_SIGTERM, SCOPE_SUCCESS);
return 0;
return 1;
}
static void scope_reset_failed(Unit *u) {
+2 -2
View File
@@ -1837,7 +1837,7 @@ static int service_start(Unit *u) {
s->notify_state = NOTIFY_UNKNOWN;
service_enter_start_pre(s);
return 0;
return 1;
}
static int service_stop(Unit *u) {
@@ -1878,7 +1878,7 @@ static int service_stop(Unit *u) {
s->state == SERVICE_EXITED);
service_enter_stop(s, SERVICE_SUCCESS);
return 0;
return 1;
}
static int service_reload(Unit *u) {
+2 -2
View File
@@ -187,7 +187,7 @@ static int slice_start(Unit *u) {
unit_realize_cgroup(u);
slice_set_state(t, SLICE_ACTIVE);
return 0;
return 1;
}
static int slice_stop(Unit *u) {
@@ -200,7 +200,7 @@ static int slice_stop(Unit *u) {
* unit_notify() will do that for us anyway. */
slice_set_state(t, SLICE_DEAD);
return 0;
return 1;
}
static int slice_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) {
+2 -2
View File
@@ -111,7 +111,7 @@ static int snapshot_start(Unit *u) {
if (s->cleanup)
unit_add_to_cleanup_queue(u);
return 0;
return 1;
}
static int snapshot_stop(Unit *u) {
@@ -121,7 +121,7 @@ static int snapshot_stop(Unit *u) {
assert(s->state == SNAPSHOT_ACTIVE);
snapshot_set_state(s, SNAPSHOT_DEAD);
return 0;
return 1;
}
static int snapshot_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -1954,7 +1954,7 @@ static int socket_start(Unit *u) {
s->result = SOCKET_SUCCESS;
socket_enter_start_pre(s);
return 0;
return 1;
}
static int socket_stop(Unit *u) {
@@ -1985,7 +1985,7 @@ static int socket_stop(Unit *u) {
assert(s->state == SOCKET_LISTENING || s->state == SOCKET_RUNNING);
socket_enter_stop_pre(s, SOCKET_SUCCESS);
return 0;
return 1;
}
static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -837,7 +837,7 @@ static int swap_start(Unit *u) {
s->result = SWAP_SUCCESS;
swap_enter_activating(s);
return 0;
return 1;
}
static int swap_stop(Unit *u) {
@@ -860,7 +860,7 @@ static int swap_stop(Unit *u) {
return -EPERM;
swap_enter_deactivating(s);
return 0;
return 1;
}
static int swap_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -137,7 +137,7 @@ static int target_start(Unit *u) {
assert(t->state == TARGET_DEAD);
target_set_state(t, TARGET_ACTIVE);
return 0;
return 1;
}
static int target_stop(Unit *u) {
@@ -147,7 +147,7 @@ static int target_stop(Unit *u) {
assert(t->state == TARGET_ACTIVE);
target_set_state(t, TARGET_DEAD);
return 0;
return 1;
}
static int target_serialize(Unit *u, FILE *f, FDSet *fds) {
+2 -2
View File
@@ -548,7 +548,7 @@ static int timer_start(Unit *u) {
t->result = TIMER_SUCCESS;
timer_enter_waiting(t, true);
return 0;
return 1;
}
static int timer_stop(Unit *u) {
@@ -558,7 +558,7 @@ static int timer_stop(Unit *u) {
assert(t->state == TIMER_WAITING || t->state == TIMER_RUNNING || t->state == TIMER_ELAPSED);
timer_enter_dead(t, TIMER_SUCCESS);
return 0;
return 1;
}
static int timer_serialize(Unit *u, FILE *f, FDSet *fds) {
+25 -11
View File
@@ -1423,6 +1423,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
int unit_start(Unit *u) {
UnitActiveState state;
Unit *following;
int r;
assert(u);
@@ -1461,9 +1462,6 @@ int unit_start(Unit *u) {
return unit_start(following);
}
unit_status_log_starting_stopping_reloading(u, JOB_START);
unit_status_print_starting_stopping(u, JOB_START);
if (UNIT_VTABLE(u)->supported && !UNIT_VTABLE(u)->supported(u->manager))
return -ENOTSUP;
@@ -1479,7 +1477,14 @@ int unit_start(Unit *u) {
unit_add_to_dbus_queue(u);
return UNIT_VTABLE(u)->start(u);
r = UNIT_VTABLE(u)->start(u);
if (r <= 0)
return r;
/* Log if the start function actually did something */
unit_status_log_starting_stopping_reloading(u, JOB_START);
unit_status_print_starting_stopping(u, JOB_START);
return r;
}
bool unit_can_start(Unit *u) {
@@ -1503,6 +1508,7 @@ bool unit_can_isolate(Unit *u) {
int unit_stop(Unit *u) {
UnitActiveState state;
Unit *following;
int r;
assert(u);
@@ -1516,15 +1522,18 @@ int unit_stop(Unit *u) {
return unit_stop(following);
}
unit_status_log_starting_stopping_reloading(u, JOB_STOP);
unit_status_print_starting_stopping(u, JOB_STOP);
if (!UNIT_VTABLE(u)->stop)
return -EBADR;
unit_add_to_dbus_queue(u);
return UNIT_VTABLE(u)->stop(u);
r = UNIT_VTABLE(u)->stop(u);
if (r <= 0)
return r;
unit_status_log_starting_stopping_reloading(u, JOB_STOP);
unit_status_print_starting_stopping(u, JOB_STOP);
return r;
}
/* Errors:
@@ -1535,6 +1544,7 @@ int unit_stop(Unit *u) {
int unit_reload(Unit *u) {
UnitActiveState state;
Unit *following;
int r;
assert(u);
@@ -1559,10 +1569,14 @@ int unit_reload(Unit *u) {
return unit_reload(following);
}
unit_status_log_starting_stopping_reloading(u, JOB_RELOAD);
unit_add_to_dbus_queue(u);
return UNIT_VTABLE(u)->reload(u);
r = UNIT_VTABLE(u)->reload(u);
if (r <= 0)
return r;
unit_status_log_starting_stopping_reloading(u, JOB_RELOAD);
return r;
}
bool unit_can_reload(Unit *u) {