]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
units: allow io.systemd.Hostname to be available earlier
authorMichael Vogt <michael@amutable.com>
Thu, 19 Mar 2026 15:05:52 +0000 (16:05 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 20 Mar 2026 09:04:26 +0000 (10:04 +0100)
Currently the varlink interface for hostname is only available
after sysinit. This means it is not available until systemd-firstboot
is finished. But there is information like the boot-id in there that
is useful to get early.

My use-case is to query the system early via the varlink-http-bridge
and currently I can't get data from io.systemd.Hostname until
systemd-firstboot is completed which is a bit limiting.

So to fix it this commit sets DefaultDependencies=no on both the socket
and service units.

It also changes hostnamed.c to use
bus_open_system_watch_bind_with_description() which means we will
reconnect once dbus is available. This mimics what resolved-bus.c
is doing (and which was originally introduced in d7afd945b).

Thanks to Lennart for pointing this out.

src/hostname/hostnamed.c
units/systemd-hostnamed.service.in
units/systemd-hostnamed.socket

index ce7187161834f4eb52de4b071a696ce2bca18439..dcd1264534970040bcc89e89ab009288c9fe9b4a 100644 (file)
@@ -1964,7 +1964,7 @@ static int connect_bus(Context *c) {
         assert(c->event);
         assert(!c->bus);
 
-        r = sd_bus_default_system(&c->bus);
+        r = bus_open_system_watch_bind_with_description(&c->bus, "bus-api-hostname");
         if (r < 0)
                 return log_error_errno(r, "Failed to get system bus connection: %m");
 
index ab00c24b53b27554ef23c95b643fbf1989e29f39..9bc58f4c13437b9536d09b049126e7f9c0d62554 100644 (file)
@@ -13,6 +13,9 @@ Documentation=man:systemd-hostnamed.service(8)
 Documentation=man:hostname(5)
 Documentation=man:machine-info(5)
 Documentation=man:org.freedesktop.hostname1(5)
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=shutdown.target
 
 [Service]
 Type=notify
index 288e736b47134d2946d79bd54ac2a87b9cb3e5fe..f84853ade8af26b294508e98610f5341e5990fda 100644 (file)
@@ -12,6 +12,9 @@ Description=Hostname Service Socket
 Documentation=man:systemd-hostnamed.service(8)
 Documentation=man:hostname(5)
 Documentation=man:machine-info(5)
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=shutdown.target sockets.target
 
 [Socket]
 ListenStream=/run/systemd/io.systemd.Hostname