chiark / gitweb /
core: output unit status output strings to console, only if we actually are changing...
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 14:07:13 +0000 (15:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 14:07:13 +0000 (15:07 +0100)
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.

13 files changed:
src/core/automount.c
src/core/busname.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/service.c
src/core/slice.c
src/core/snapshot.c
src/core/socket.c
src/core/swap.c
src/core/target.c
src/core/timer.c
src/core/unit.c

index 51f7373f77d13e3e7b85b1a5cc8badb262ed7c93..d47e6fa8dc3214b6a11bf29dfce8bcbd517096ea 100644 (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) {
index 00e56686e5d88dbbe42b9e37c5bac04c4e7fd8b1..ca9ceb8c3c32d0249af24b8e5c0c603095a44610 100644 (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) {
index f944c02e2bea7001bb922eebc4dc6c51d2a851a6..6bd6914509f8b290c82a10799739a8741988cf6b 100644 (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) {
index 0fdf48380b3f1b227217f37d7dfb8a4733494cbd..e5ea79fec7c9bf074c781a8e2fc3a55ebf843de9 100644 (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) {
index e0da6e4db7965739cd99ad5444b5816ebcc1599b..b41db7872c4ef5a2811aacc7ff2ffe2249f79911 100644 (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) {
index 120510c6c130f01dbe50c87cac36c3908c5fb11b..15a2ed7f7ebae315c63ad12946a72bbb85e57239 100644 (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) {
index a31e629370e0b68b98349537b8471c30b9520805..ae9819d015fefa8bbd1eec53e1cfd20da914d20f 100644 (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) {
index 068a077f15311c680be4f1b26683563ed8cd1f95..b70c3beb6023c1b75455c636bbaf8d8d9a0c0dc1 100644 (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) {
index b671fffc5963a6a0183d2f0e9f86cf137c3aae15..85f7f16e15360cbe4dcefc49948c9882652d1553 100644 (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) {
index 1ef672f7e9e7a3ce565b57ce9597bd7ff60d3ff3..4fbabda568d35b0a3a8c5a44cfa79b46bbf6cfff 100644 (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) {
index 68be22b38df3acf149afc52ab8f78e7550392fc9..33fb66bc3fe4800617d521d53bac86c55bde964d 100644 (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) {
index 309852aae6aeaa2e31509b399e58d8ff12978f08..45744c7de57f64ac685c8d9d7d5fecac6039bef4 100644 (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) {
index 7311c5804dacb7fd597558e4103eb44dedcb01d6..23ad7c10e0739733cb7d0bab479392f003aecaf3 100644 (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) {