]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firstboot: synchronously wait for systemd-vconsole-setup.service/restart job
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 25 May 2023 10:26:37 +0000 (12:26 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 May 2023 13:07:01 +0000 (15:07 +0200)
Requested in https://github.com/systemd/systemd/pull/27755#pullrequestreview-1443489520.

I dropped the info message about the job being requested, because we get
fairly verbose logs from starting the unit, and the additional message isn't
useful.

In the unit, the ordering before systemd-vconsole-setup.service is dropped,
because now it needs to happen in parallel, while systemd-firstboot.service
is running. This means that we may potentially execute vconsole-setup twice,
but it's fairly quick, so this doesn't matter much.

src/firstboot/firstboot.c
units/systemd-firstboot.service

index c423aff5dddbc196ff5e3d39de9cd8fcc35ec2cc..65859eaa9fc6ce7d0f2060f2ceeb7bbe506ea7d9 100644 (file)
@@ -13,6 +13,7 @@
 #include "bus-error.h"
 #include "bus-locator.h"
 #include "bus-util.h"
+#include "bus-wait-for-jobs.h"
 #include "chase.h"
 #include "copy.h"
 #include "creds-util.h"
@@ -1588,6 +1589,9 @@ static int reload_system_manager(sd_bus **bus) {
 
 static int reload_vconsole(sd_bus **bus) {
         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+        _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
+        const char *object;
         int r;
 
         assert(bus);
@@ -1598,10 +1602,22 @@ static int reload_vconsole(sd_bus **bus) {
                         return bus_log_connect_error(r, BUS_TRANSPORT_LOCAL);
         }
 
-        r = bus_call_method(*bus, bus_systemd_mgr, "RestartUnit", &error, NULL, "ss", "systemd-vconsole-setup.service", "replace");
+        r = bus_wait_for_jobs_new(*bus, &w);
+        if (r < 0)
+                return log_error_errno(r, "Could not watch jobs: %m");
+
+        r = bus_call_method(*bus, bus_systemd_mgr, "RestartUnit", &error, &reply,
+                            "ss", "systemd-vconsole-setup.service", "replace");
         if (r < 0)
                 return log_error_errno(r, "Failed to issue method call: %s", bus_error_message(&error, r));
-        log_info("Requested vconsole setup to apply key map configuration.");
+
+        r = sd_bus_message_read(reply, "o", &object);
+        if (r < 0)
+                return bus_log_parse_error(r);
+
+        r = bus_wait_for_jobs_one(w, object, false, NULL);
+        if (r < 0)
+                return log_error_errno(r, "Failed to wait for systemd-vconsole-setup.service/restart: %m");
         return 0;
 }
 
index 5fee85a2873b86a0eb989f798e328b6e52140cac..234e4e7572b9d044a2b0a024175bd408a89fce26 100644 (file)
@@ -15,9 +15,9 @@ ConditionPathIsReadWrite=/etc
 ConditionFirstBoot=yes
 
 DefaultDependencies=no
-After=systemd-remount-fs.service
-Before=systemd-vconsole-setup.service sysinit.target first-boot-complete.target
+After=systemd-remount-fs.service systemd-sysusers.service
 Wants=first-boot-complete.target
+Before=first-boot-complete.target sysinit.target
 Conflicts=shutdown.target
 Before=shutdown.target