From 55356a78219e5c55bd90d83813630c6dc422afee Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 19 Mar 2026 16:05:52 +0100 Subject: [PATCH] units: allow io.systemd.Hostname to be available earlier 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 | 2 +- units/systemd-hostnamed.service.in | 3 +++ units/systemd-hostnamed.socket | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index ce71871618..dcd1264534 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -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"); diff --git a/units/systemd-hostnamed.service.in b/units/systemd-hostnamed.service.in index ab00c24b53..9bc58f4c13 100644 --- a/units/systemd-hostnamed.service.in +++ b/units/systemd-hostnamed.service.in @@ -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 diff --git a/units/systemd-hostnamed.socket b/units/systemd-hostnamed.socket index 288e736b47..f84853ade8 100644 --- a/units/systemd-hostnamed.socket +++ b/units/systemd-hostnamed.socket @@ -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