Skip to content

Commit bcbca82

Browse files
committed
networkd: don't hard depend on system bus
We may not have a dbus daemon in the initrd (until we can rely on kdbus). In this case, simply ignore any attempts at using the bus. There is only one user for now, but surely more to come. In order to work reliably in the real root without kdbus, but at the same time don't delay boot when kdbus is in use, order ourselves after dbus.service.
1 parent b2ad8a1 commit bcbca82

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/network/networkd-link.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,15 @@ static int set_hostname(sd_bus *bus, const char *hostname) {
325325
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
326326
int r = 0;
327327

328-
assert(bus);
329328
assert(hostname);
330329

331330
log_debug("Setting transient hostname: '%s'", hostname);
332331

332+
if (!bus) { /* TODO: replace by assert when we can rely on kdbus */
333+
log_info("Not connected to system bus, ignoring transient hostname.");
334+
return 0;
335+
}
336+
333337
r = sd_bus_message_new_method_call(
334338
bus,
335339
"org.freedesktop.hostname1",

src/network/networkd-manager.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int manager_new(Manager **ret) {
5555
return r;
5656

5757
r = sd_bus_default_system(&m->bus);
58-
if (r < 0)
58+
if (r < 0 && r != -ENOENT) /* TODO: drop when we can rely on kdbus */
5959
return r;
6060

6161
m->udev = udev_new();
@@ -288,6 +288,11 @@ int manager_rtnl_listen(Manager *m) {
288288
int manager_bus_listen(Manager *m) {
289289
int r;
290290

291+
assert(m->event);
292+
293+
if (!m->bus) /* TODO: drop when we can rely on kdbus */
294+
return 0;
295+
291296
r = sd_bus_attach_event(m->bus, m->event, 0);
292297
if (r < 0)
293298
return r;

units/systemd-networkd.service.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Description=Network Service
1010
Documentation=man:systemd-networkd.service(8)
1111
DefaultDependencies=no
12-
After=dbus.socket
12+
After=dbus.service
1313
Before=network.target
1414
Wants=network.target
1515
ConditionCapability=CAP_NET_ADMIN

0 commit comments

Comments
 (0)