]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(dbus-daemon): introducing the dbus-daemon module
authorJóhann B. Guðmundsson <johannbg@gmail.com>
Wed, 3 Feb 2021 16:00:33 +0000 (16:00 +0000)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 8 Feb 2021 19:18:25 +0000 (20:18 +0100)
Introdusing dbus-daemon which is based on but superseeds
the previous 06dbus implementation with various enhancements and fixes.

fix: adding new modules to rpm spec file

fix: missed an echo

dracut.spec
modules.d/00dbus/module-setup.sh
modules.d/06dbus-daemon/module-setup.sh [new file with mode: 0755]
modules.d/06dbus/module-setup.sh [deleted file]

index 4548f6b1aac7ea3b2aec35c5de5184066a91d1c2..595da452e3a778bc6f2a4844f448003617889f35 100644 (file)
@@ -325,6 +325,7 @@ echo 'dracut_rescue_image="yes"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/
 %if %{undefined _unitdir}
 %endif
 %{dracutlibdir}/modules.d/00bash
+%{dracutlibdir}/modules.d/00dbus
 %{dracutlibdir}/modules.d/00systemd
 %ifnarch s390 s390x
 %{dracutlibdir}/modules.d/00warpclock
@@ -340,7 +341,8 @@ echo 'dracut_rescue_image="yes"' > $RPM_BUILD_ROOT%{dracutlibdir}/dracut.conf.d/
 %{dracutlibdir}/modules.d/04watchdog
 %{dracutlibdir}/modules.d/04watchdog-modules
 %{dracutlibdir}/modules.d/05busybox
-%{dracutlibdir}/modules.d/06dbus
+%{dracutlibdir}/modules.d/06dbus-broker
+%{dracutlibdir}/modules.d/06dbus-daemon
 %{dracutlibdir}/modules.d/06rngd
 %{dracutlibdir}/modules.d/10i18n
 %{dracutlibdir}/modules.d/30convertfs
index d8acd1938e66914677e38d8f5616dcbe58c1ada1..9c60a464ab15908ab3ac27a06b89ea4fac79957f 100755 (executable)
@@ -4,7 +4,7 @@
 
 # Prerequisite check(s) for module.
 check() {
-    # We only want to return 255 since this is a bus meta module.
+    # We only want to return 255 since this is a meta module.
     return 255
 }
 
@@ -17,4 +17,7 @@ depends() {
             break
         fi
     done;
+
+    echo "$dbus"
+    return 0
 }
diff --git a/modules.d/06dbus-daemon/module-setup.sh b/modules.d/06dbus-daemon/module-setup.sh
new file mode 100755 (executable)
index 0000000..91abdc5
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/sh
+# This file is part of dracut.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# Prerequisite check(s) for module.
+check() {
+
+    # If the binary(s) requirements are not fulfilled
+    # return 1 to not include the binary.
+    require_binaries busctl || return 1
+    require_binaries dbus-daemon || return 1
+    require_binaries dbus-send || return 1
+
+    # If the module dependency requirements are not fulfilled
+    # return 1 to not include the required module(s).
+    if ! dracut_module_included "systemd"; then
+        derror "dbus needs systemd in the initramfs."
+        return 1
+    fi
+
+    # dbus conflicts with dbus-broker.
+    if dracut_module_included "dbus-broker"; then
+        derror "dbus conflicts with dbus-broker in the initramfs."
+        exit 1
+    fi
+
+    # Return 255 to only include the module, if another module requires it.
+    return 255
+}
+
+# Module dependency requirements.
+depends() {
+
+    # This module has external dependency on the systemd module.
+    echo systemd
+    # Return 0 to include the dependent systemd module in the initramfs.
+    return 0
+}
+
+# Install the required file(s) for the module in the initramfs.
+install() {
+
+    # Create dbus related directories.
+    inst_dir $dbus
+    inst_dir $dbusinterfaces
+    inst_dir $dbusservices
+    inst_dir $dbussession
+    inst_dir $dbussystem
+    inst_dir $dbussystemservices
+    inst_dir $dbusconfdir
+    inst_dir $dbusinterfacesconfdir
+    inst_dir $dbusservicesconfdir
+    inst_dir $dbussessionconfdir
+    inst_dir $dbussystemconfdir
+    inst_dir $dbussystemservicesconfdir
+
+    inst_multiple -o \
+        # Install the dbus system configuration file.
+        $dbus/system.conf \
+        # The systemd module should be providing this and
+        # depend on the dbus module. Added here until it does.
+        $dbussystem/org.freedesktop.systemd1.conf \
+        $dbusservicesconfdir/org.freedesktop.systemd1.service \
+        $dbussystemservices/org.freedesktop.systemd1.service \
+        # Install the systemd type service unit for dbus.
+        $systemdsystemunitdir/dbus.service \
+        # Install the systemd type socket unit for dbus.
+        $systemdsystemunitdir/dbus.socket \
+        # Install the dbus target.
+        $systemdsystemunitdir/dbus.target.wants
+        # Install the binary executable(s) for dbus.
+        busctl dbus-send dbus-daemon
+
+    # Adjusting dependencies for initramfs in the dbus service unit.
+    sed -i -e \
+        '/^\[Unit\]/aDefaultDependencies=no\
+        Conflicts=shutdown.target\
+        Before=shutdown.target' \
+        "$initdir$systemdsystemunitdir/dbus.service"
+
+    # Adjusting dependencies for initramfs in the dbus socket unit.
+    sed -i -e \
+       '/^\[Unit\]/aDefaultDependencies=no\
+        Conflicts=shutdown.target\
+        Before=shutdown.target
+        /^\[Socket\]/aRemoveOnStop=yes' \
+        "$initdir$systemdsystemunitdir/dbus.socket"
+
+    # Adding the user and group for dbus
+    grep '^\(d\|message\)bus:' /etc/passwd >> "$initdir/etc/passwd"
+    grep '^\(d\|message\)bus:' /etc/group >> "$initdir/etc/group"
+
+    # Install the hosts local user configurations if enabled.
+    if [[ $hostonly ]]; then
+        inst_multiple -H -o \
+            $dbusconfdir/system.conf \
+            $systemdsystemconfdir/dbus.socket \
+            $systemdsystemconfdir/dbus.socket.d/*.conf \
+            $systemdsystemconfdir/dbus.service \
+            $systemdsystemconfdir/dbus.service.d/*.conf
+            ${NULL}
+     fi
+
+    # We need to make sure that systemd-tmpfiles-setup.service->dbus.socket
+    # will not wait for local-fs.target to start if swap is encrypted,
+    # this would make dbus wait the timeout for the swap before loading.
+    # This could delay sysinit services that are dependent on dbus.service.
+    sed -i -Ee \
+        '/^After/s/(After[[:space:]]*=.*)(local-fs.target[[:space:]]*)(.*)/\1-\.mount \3/' \
+        "$initdir$systemdsystemunitdir/systemd-tmpfiles-setup.service"
+}
diff --git a/modules.d/06dbus/module-setup.sh b/modules.d/06dbus/module-setup.sh
deleted file mode 100755 (executable)
index 9a5c812..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/bin/bash
-
-# called by dracut
-check() {
-  require_binaries dbus-daemon || return 1
-
-  return 255
-}
-
-depends() {
-  echo systemd
-  return 0
-}
-
-adjust_dependencies() {
-  sed -i -e \
-'/^\[Unit\]/aDefaultDependencies=no\
-Conflicts=shutdown.target\
-Before=shutdown.target' \
-    "$initdir"${1}
-
-}
-
-install() {
-
-  inst_multiple \
-    $systemdsystemunitdir/dbus.service \
-    $systemdsystemunitdir/dbus.socket \
-    dbus-send \
-    busctl
-  adjust_dependencies $systemdsystemunitdir/dbus.service
-
-  if type -P dbus-daemon >/dev/null; then
-    inst_multiple \
-      dbus-daemon
-  fi
-
-  if type -P dbus-broker >/dev/null; then
-    inst_multiple \
-      $systemdsystemunitdir/dbus-broker.service \
-      dbus-broker \
-      dbus-broker-launch
-    adjust_dependencies $systemdsystemunitdir/dbus-broker.service
-  fi
-
-  inst_dir      /etc/dbus-1/system.d
-  inst_dir      /usr/share/dbus-1/services
-  inst_dir      /usr/share/dbus-1/system-services
-  inst_multiple /etc/dbus-1/system.conf
-  inst_multiple /usr/share/dbus-1/system.conf \
-                /usr/share/dbus-1/services/org.freedesktop.systemd1.service
-  inst_multiple $(find /var/lib/dbus)
-
-  grep '^\(d\|message\)bus:' /etc/passwd >> "$initdir/etc/passwd"
-  grep '^\(d\|message\)bus:' /etc/group >> "$initdir/etc/group"
-
-  sed -i -e \
-'/^\[Unit\]/aDefaultDependencies=no\
-Conflicts=shutdown.target\
-Before=shutdown.target
-/^\[Socket\]/aRemoveOnStop=yes' \
-    "$initdir$systemdsystemunitdir/dbus.socket"
-
-  #We need to make sure that systemd-tmpfiles-setup.service->dbus.socket will not wait local-fs.target to start,
-  #If swap is encrypted, this would make dbus wait the timeout for the swap before loading. This could delay sysinit
-  #services that are dependent on dbus.service.
-  sed -i -Ee \
-    '/^After/s/(After[[:space:]]*=.*)(local-fs.target[[:space:]]*)(.*)/\1-\.mount \3/' \
-    "$initdir$systemdsystemunitdir/systemd-tmpfiles-setup.service"
-}