From: Lennart Poettering Date: Wed, 28 Jan 2015 14:07:13 +0000 (+0100) Subject: core: output unit status output strings to console, only if we actually are changing... X-Git-Tag: v219~242 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=82a2b6bb5e4e5d294f09af778c48974a7857afb6;hp=3ad85e3775d018f32098a2957ce25e1f53440da1 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. --- diff --git a/src/core/automount.c b/src/core/automount.c index 51f7373f7..d47e6fa8d 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -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) { diff --git a/src/core/busname.c b/src/core/busname.c index 00e56686e..ca9ceb8c3 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -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) { diff --git a/src/core/mount.c b/src/core/mount.c index f944c02e2..6bd691450 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -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) { diff --git a/src/core/path.c b/src/core/path.c index 0fdf48380..e5ea79fec 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -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) { diff --git a/src/core/scope.c b/src/core/scope.c index e0da6e4db..b41db7872 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -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) { diff --git a/src/core/service.c b/src/core/service.c index 120510c6c..15a2ed7f7 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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) { diff --git a/src/core/slice.c b/src/core/slice.c index a31e62937..ae9819d01 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -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) { diff --git a/src/core/snapshot.c b/src/core/snapshot.c index 068a077f1..b70c3beb6 100644 --- a/src/core/snapshot.c +++ b/src/core/snapshot.c @@ -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) { diff --git a/src/core/socket.c b/src/core/socket.c index b671fffc5..85f7f16e1 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -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) { diff --git a/src/core/swap.c b/src/core/swap.c index 1ef672f7e..4fbabda56 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -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) { diff --git a/src/core/target.c b/src/core/target.c index 68be22b38..33fb66bc3 100644 --- a/src/core/target.c +++ b/src/core/target.c @@ -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) { diff --git a/src/core/timer.c b/src/core/timer.c index 309852aae..45744c7de 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -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) { diff --git a/src/core/unit.c b/src/core/unit.c index 7311c5804..23ad7c10e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -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) {