Skip to content

Commit b948d56

Browse files
committed
systemd: ensure dbus is available for network services
Fix race condition where network services attempt to use D-Bus functionality before the D-Bus broker is fully initialized: 1. Add DefaultDependencies=no to dbus.socket to allow D-Bus to start earlier in the boot process 2. Make network-pre.target require dbus-broker.service to ensure D-Bus is ready before network services start 3. Disable PrivateTmp for dbus-broker.service to remove dependency on systemd-tmpfiles and local-fs.target Signed-off-by: Yutong Sun <[email protected]>
1 parent 40f228a commit b948d56

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

packages/dbus-broker/dbus-broker.service

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
Description=D-Bus System Message Bus
33
Documentation=https://github.com/bus1/dbus-broker
44
DefaultDependencies=false
5-
After=dbus.socket
5+
# Ensure the dbus user is created before starting dbus-broker
6+
After=dbus.socket systemd-sysusers.service
7+
Wants=dbus.socket systemd-sysusers.service
68
Before=basic.target shutdown.target
79
Requires=dbus.socket
810
Conflicts=shutdown.target
@@ -13,7 +15,9 @@ Sockets=dbus.socket
1315
OOMScoreAdjust=-900
1416
LimitNOFILE=16384
1517
ProtectSystem=full
16-
PrivateTmp=true
18+
# Disable private /tmp to avoid dependency on systemd-tmpfiles and consequently
19+
# local-fs.target, allowing dbus to start earlier in the boot
20+
PrivateTmp=no
1721
PrivateDevices=true
1822
ExecStart=/usr/bin/dbus-broker-launch --scope system
1923
ExecReload=/usr/bin/busctl call org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ReloadConfig

packages/dbus-broker/dbus.socket

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
[Unit]
22
Description=D-Bus System Message Bus Socket
3+
# Disable DefaultDependencies to allow D-Bus to be started earlier in the boot
4+
# so that it is available for other services
5+
DefaultDependencies=no
6+
Before=shutdown.target sockets.target
7+
Conflicts=shutdown.target
38

49
[Socket]
510
ListenStream=/run/dbus/system_bus_socket
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
# Ensure D-Bus is fully initialized before network services start
3+
# This prevents a race condition where network services could attempt
4+
# to use D-Bus functionality (like networkctl commands) before the D-Bus
5+
# broker service is fully ready to handle requests.
6+
DefaultDependencies=no
7+
After=dbus-broker.service
8+
Requires=dbus-broker.service
9+
Before=shutdown.target
10+
Conflicts=shutdown.target

packages/release/release.spec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Source1107: systemd-journald-compat.conf
110110
Source1108: systemd-sysusers-selinux.conf
111111
Source1109: modprobe-no-exit.conf
112112
Source1110: tmp-mount-noexec.conf
113+
Source1111: network-pre-target-dbus-dep.conf
113114

114115
# network link rules
115116
Source1200: 80-release.link
@@ -271,6 +272,10 @@ install -d %{buildroot}%{_cross_unitdir}/tmp.mount.d
271272
install -p -m 0644 %{S:1110} \
272273
%{buildroot}%{_cross_unitdir}/tmp.mount.d/10-no-exec.conf
273274

275+
install -d %{buildroot}%{_cross_unitdir}/network-pre.target.d
276+
install -p -m 0644 %{S:1111} \
277+
%{buildroot}%{_cross_unitdir}/network-pre.target.d/00-dbus-dep.conf
278+
274279
# Empty (but packaged) directory. The FIPS packages for kernels will add drop-ins to
275280
# this directory to arrange for the right modules to be loaded before the check runs.
276281
install -d %{buildroot}%{_cross_unitdir}/check-fips-modules.service.d
@@ -386,6 +391,8 @@ ln -s preconfigured.target %{buildroot}%{_cross_unitdir}/default.target
386391
%{_cross_unitdir}/mask-local-mnt.service
387392
%{_cross_unitdir}/mask-local-opt.service
388393
%{_cross_unitdir}/mask-local-var.service
394+
%dir %{_cross_unitdir}/network-pre.target.d
395+
%{_cross_unitdir}/network-pre.target.d/00-dbus-dep.conf
389396
%{_cross_unitdir}/root-.aws.mount
390397
%{_cross_unitdir}/repart-data-preferred.service
391398
%{_cross_unitdir}/repart-data-fallback.service

0 commit comments

Comments
 (0)