]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: split out send_ready and basic.target checking into functions of their own
authorLennart Poettering <lennart@poettering.net>
Tue, 23 Jan 2018 15:32:06 +0000 (16:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 23 Jan 2018 15:39:12 +0000 (16:39 +0100)
Let's shorten manager_check_finished() a bit by splitting out checking
of basic.target and the two things we do when we reach it.

This should not change behaviour, except for one thing: we now check
basic.target's actual state for figuring out whether it is up, instead
of generically checking whether it has any job queued. This is arguably
more correct, and is what other code does too for similar purposes, for
example manager_state()

src/core/manager.c

index a6037c335da4fa5e3fa7fe92d9cef0dbe6df8cf7..0a326dc58a3477d3287a8deb4e9adac3921a7b48 100644 (file)
@@ -3170,7 +3170,7 @@ static void manager_notify_finished(Manager *m) {
                                    NULL);
                 }
         } else {
-                /* The container case */
+                /* The container and --user case */
                 firmware_usec = loader_usec = initrd_usec = kernel_usec = 0;
                 total_usec = userspace_usec = m->timestamps[MANAGER_TIMESTAMP_FINISH].monotonic - m->timestamps[MANAGER_TIMESTAMP_USERSPACE].monotonic;
 
@@ -3194,6 +3194,40 @@ static void manager_notify_finished(Manager *m) {
         log_taint_string(m);
 }
 
+static void manager_send_ready(Manager *m) {
+        assert(m);
+
+        /* We send READY=1 on reaching basic.target only when running in --user mode. */
+        if (!MANAGER_IS_USER(m) || m->ready_sent)
+                return;
+
+        m->ready_sent = true;
+
+        sd_notifyf(false,
+                   "READY=1\n"
+                   "STATUS=Reached " SPECIAL_BASIC_TARGET ".");
+}
+
+static void manager_check_basic_target(Manager *m) {
+        Unit *u;
+
+        assert(m);
+
+        /* Small shortcut */
+        if (m->ready_sent && m->taint_logged)
+                return;
+
+        u = manager_get_unit(m, SPECIAL_BASIC_TARGET);
+        if (!u || !UNIT_IS_ACTIVE_OR_RELOADING(unit_active_state(u)))
+                return;
+
+        /* For user managers, send out READY=1 as soon as we reach basic.target */
+        manager_send_ready(m);
+
+        /* Log the taint string as soon as we reach basic.target */
+        log_taint_string(m);
+}
+
 void manager_check_finished(Manager *m) {
         assert(m);
 
@@ -3206,24 +3240,7 @@ void manager_check_finished(Manager *m) {
         if (m->exit_code != MANAGER_OK)
                 return;
 
-        if (!m->ready_sent || !m->taint_logged) {
-                Unit *u;
-
-                u = manager_get_unit(m, SPECIAL_BASIC_TARGET);
-                if (u && !u->job) {
-                        /* Log the taint string as soon as we reach basic.target */
-                        log_taint_string(m);
-
-                        /* For user managers, send out READY=1 as soon as we reach basic.target */
-                        if (MANAGER_IS_USER(m) && !m->ready_sent) {
-                                sd_notifyf(false,
-                                           "READY=1\n"
-                                           "STATUS=Reached " SPECIAL_BASIC_TARGET ".");
-
-                                m->ready_sent = true;
-                        }
-                }
-        }
+        manager_check_basic_target(m);
 
         if (hashmap_size(m->jobs) > 0) {
                 if (m->jobs_in_progress_event_source)