]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
feat(systemd-coredump): introducing systemd-coredump module
authorJóhann B. Guðmundsson <johannbg@gmail.com>
Mon, 1 Feb 2021 11:27:52 +0000 (11:27 +0000)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Tue, 2 Feb 2021 18:01:06 +0000 (18:01 +0000)
This pull request introduces systemd-coredump as a seperated
module and adds the systemdutilconfdir global variable.

dracut.conf.d/fedora.conf.example
dracut.sh
modules.d/01systemd-coredump/module-setup.sh [new file with mode: 0755]

index c65f83acbabaa7a15e3ce613a247a4884de2af63..96ef5899d9f5a8e0a512dbe3153c2ec7e5f85bcd 100644 (file)
@@ -27,6 +27,7 @@ dbussystemservicesconfdir=/etc/dbus-1/system-services
 sysctld=/usr/lib/sysctl.d
 sysctldconfdir=/etc/sysctl.d
 systemdutildir=/usr/lib/systemd
+systemdutilconfdir=/etc/systemd
 systemdcatalog=/usr/lib/systemd/catalog
 systemdntpunits=/usr/lib/systemd/ntp-units.d
 systemdntpunitsconfdir=/etc/systemd/ntp-units.d
index 4685072a5adb73016a35c0294a82f4e9ba770cb2..056a4114c34c2537842cc8f8b4e870ede049d4e3 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -1109,6 +1109,10 @@ if ! [[ -d "$dracutsysrootdir$systemdutildir" ]]; then
     [[ -e $dracutsysrootdir/usr/lib/systemd/systemd-udevd ]] && systemdutildir=/usr/lib/systemd
 fi
 
+[[ -d $dracutsysrootdir$systemdutilconfdir ]] \
+    || systemdutilconfdir=$(pkg-config systemd --variable=systemdutilconfdir 2>/dev/null)
+
+[[ -d "$dracutsysrootdir$systemdutilconfdir" ]] || systemdutilconfdir=/etc/systemd
 
 if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
     if ! [[ -f $srcmods/modules.dep ]]; then
@@ -1600,8 +1604,8 @@ export initdir dracutbasedir \
     dbusservices dbusservicesconfdir dbussession dbussessionconfdir \
     dbussystem dbussystemconfdir dbussystemservices dbussystemservicesconfdir \
     environment environmentconfdir sysctl sysctlconfdir sysusers sysusersconfdir \
-    systemdutildir systemdcatalog systemdntpunits systemdntpunitsconfdir \
-    systemdsystemunitdir systemdsystemconfdir \
+    systemdutildir systemdutilconfdir systemdcatalog systemdntpunits \
+    systemdntpunitsconfdir systemdsystemunitdir systemdsystemconfdir \
     hostonly_cmdline loginstall \
     tmpfilesdir
 
diff --git a/modules.d/01systemd-coredump/module-setup.sh b/modules.d/01systemd-coredump/module-setup.sh
new file mode 100755 (executable)
index 0000000..bbf7eac
--- /dev/null
@@ -0,0 +1,76 @@
+#!/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 coredumpctl || return 1
+    require_binaries $systemdutildir/systemd-coredump || 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 "systemd-coredump needs systemd in the initramfs."
+        return 1
+    fi
+
+    if ! dracut_module_included "systemd-journald"; then
+         derror "systemd-coredump needs systemd-journald in the initramfs."
+         return 1
+    fi
+
+    if ! dracut_module_included "systemd-sysctl"; then
+        derror "systemd-coredump needs systemd-sysctl in the initramfs."
+        return 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 systemd-journald systemd-sysctl
+    # 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() {
+
+    # Install the required directories.
+    inst_dir   /var/lib/systemd/coredump
+    # Install the required file(s.
+    inst_multiple -o \
+        # Install the kernel configuration parameters for coredump.
+        $sysctld/50-coredump.conf \
+        # Install vendor configuration files.
+        $systemdutildir/coredump.conf \
+        # Install the systemd type service unit for coredump.
+        $systemdsystemunitdir/systemd-coredump \
+        $systemdsystemunitdir/systemd-coredump.socket \
+        $systemdsystemunitdir/systemd-coredump@.service\
+        $systemdsystemunitdir/sockets.target.wants/systemd-coredump.socket
+        # Install the binary executable(s) for sysusers.
+        coredumpctl
+
+    # Install the hosts local user configurations if enabled.
+    if [[ $hostonly ]]; then
+        inst_multiple -H -o \
+            $systemdutilconfdir/coredump.conf \
+            $systemdsystemconfdir/coredump.conf.d/*.conf \
+            $systemdsystemconfdir/systemd-coredump.socket \
+            $systemdsystemconfdir/systemd-coredump.socket.d/*.conf \
+            $systemdsystemconfdir/systemd-coredump@.service \
+            $systemdsystemconfdir/systemd-coredump@.service.d/*.conf \
+            $systemdsystemconfdir/sockets.target.wants/systemd-coredump.socket
+            ${NULL}
+    fi
+}