summaryrefslogtreecommitdiffstats
path: root/core/modules/dbus
diff options
context:
space:
mode:
authorJonathan Bauer2019-06-14 15:52:45 +0200
committerJonathan Bauer2019-06-14 15:52:45 +0200
commit6c69d527ab4dca33a0d48ebda9ce678f69e93fa8 (patch)
tree85bdbd3dfb43d25687e92528def5f0df5848bc14 /core/modules/dbus
parent[hardware-stats] Use slx-tools to determine free /tmp (diff)
downloadmltk-6c69d527ab4dca33a0d48ebda9ce678f69e93fa8.tar.gz
mltk-6c69d527ab4dca33a0d48ebda9ce678f69e93fa8.tar.xz
mltk-6c69d527ab4dca33a0d48ebda9ce678f69e93fa8.zip
[dbus] use system's service/socket
or generate as a fallback
Diffstat (limited to 'core/modules/dbus')
-rw-r--r--core/modules/dbus/module.build92
-rw-r--r--core/modules/dbus/templates/dbus.service3
-rw-r--r--core/modules/dbus/templates/dbus.socket (renamed from core/modules/dbus/data/etc/systemd/system/dbus.socket)0
3 files changed, 49 insertions, 46 deletions
diff --git a/core/modules/dbus/module.build b/core/modules/dbus/module.build
index 71f6f783..3d18d90c 100644
--- a/core/modules/dbus/module.build
+++ b/core/modules/dbus/module.build
@@ -12,54 +12,58 @@ build() {
tarcopy "$(cat "${COPYLIST}" | sort -u)" "${MODULE_BUILD_DIR}"
# Generate systemd files
- mkdir -p "$MODULE_BUILD_DIR/etc/systemd/system"
- # This is ugly, as the command line arguments changed over time. Try to do the right thing (whatever that is)
- # Need to run dbus-uuidgen first?
- local UUIDGEN="# This line intentionally left blank"
- if files_contain "ExecStartPre.*uuidgen" "/lib/systemd/system/dbus.service" "/usr/lib/systemd/system/dbus.service"; then
- UUIDGEN=$(find "$MODULE_BUILD_DIR" -name dbus-uuidgen -executable | head -n 1)
- [ -z "$UUIDGEN" ] && perror "Could not determine dbus-uuidgen location"
- UUIDGEN="ExecStartPre=/${UUIDGEN#$MODULE_BUILD_DIR} --ensure"
- fi
- # Figure out daemon location
- local DAEMON=$(find "$MODULE_BUILD_DIR" -name dbus-daemon -executable | head -n 1)
- [ -z "$DAEMON" ] && perror "Could not determine dbus-daemon location"
- DAEMON="/${DAEMON#$MODULE_BUILD_DIR}"
- local DAEMON_ARGS=""
- # Daemon arguments
- if files_contain "dbus-daemon.*nopidfile" "/lib/systemd/system/dbus.service" "/usr/lib/systemd/system/dbus.service"; then
- DAEMON_ARGS+=" --nopidfile"
- fi
- if files_contain "dbus-daemon.*activation=systemd" "/lib/systemd/system/dbus.service" "/usr/lib/systemd/system/dbus.service"; then
- DAEMON_ARGS+=" --activation=systemd"
- fi
- if files_contain "dbus-daemon.*systemd-activation" "/lib/systemd/system/dbus.service" "/usr/lib/systemd/system/dbus.service"; then
- DAEMON_ARGS+=" --systemd-activation"
- fi
- # dbus-send location
- local SEND=$(find "$MODULE_BUILD_DIR" -name dbus-send -executable | head -n 1)
- [ -z "$SEND" ] && perror "Could not determine dbus-send location"
- SEND="/${SEND#$MODULE_BUILD_DIR}"
- sed "s,%UUIDGEN%,$UUIDGEN,g;s,%DAEMON%,$DAEMON,g;s,%SEND%,$SEND,g;s,%DAEMON_ARGS%,$DAEMON_ARGS,g" "${MODULE_DIR}/templates/dbus.service" \
- > "$MODULE_BUILD_DIR/etc/systemd/system/dbus.service" \
- || perror "Could not generate $MODULE_BUILD_DIR/etc/systemd/system/dbus.service"
+ mkdir -p "$MODULE_BUILD_DIR/etc/systemd/system/dbus.service.d"
+
# This is REQUIRED, otherwise the session daemon won't start (can be empty, but has to exist...)
mkdir -p "${MODULE_BUILD_DIR}/etc/dbus-1/session.d"
-}
-post_copy() {
- :
-}
+ # We will either find the service file or generate it,
+ # thus we can already create the drop-in for uuidgen
+ UUIDGEN=$(find "$MODULE_BUILD_DIR" -name dbus-uuidgen -executable | head -n 1)
+ [ -z "$UUIDGEN" ] && perror "Could not determine dbus-uuidgen location"
+ cat <<-EOF > "$MODULE_BUILD_DIR/etc/systemd/system/dbus.service.d/uuidgen.conf"
+ [Service]
+ ExecStartPre=/${UUIDGEN#$MODULE_BUILD_DIR} --ensure
+ EOF
-files_contain () {
- [ $# -lt 2 ] && perror "files_contain needs at least 2 arguments (pattern, file)"
- local PATTERN="$1"
- shift
- local FILE
- for FILE in $@; do
- [ -e "$FILE" ] || continue
- grep -q "$PATTERN" "$FILE" && return 0 # Found
+ # First check if there is a system dbus file and copy it if so
+ declare -A found
+ for unit_type in service socket; do
+ for candidate in {,/usr}"/lib/systemd/system/dbus.${unit_type}"; do
+ if [ -e "$candidate" ]; then
+ cp -a "$candidate" "${MODULE_BUILD_DIR}/etc/systemd/system" \
+ || perror "Failed to copy '$found' to '$MODULE_BUILD_DIR'."
+ found["$unit_type"]=oui
+ fi
+ done
done
- return 1
+
+ # If not found, generate service file from the template
+ if [ -z "${found["service"]}" ]; then
+ # This is ugly, as the command line arguments changed over time. Try to do the right thing (whatever that is)
+ # Find path for: dbus-daemon
+ local DAEMON=$(find "$MODULE_BUILD_DIR" -name dbus-daemon -executable | head -n 1)
+ [ -z "$DAEMON" ] && perror "Could not determine dbus-daemon location"
+ DAEMON="/${DAEMON#$MODULE_BUILD_DIR}"
+
+ # Find path for: dbus-send
+ local SEND=$(find "$MODULE_BUILD_DIR" -name dbus-send -executable | head -n 1)
+ [ -z "$SEND" ] && perror "Could not determine dbus-send location"
+ SEND="/${SEND#$MODULE_BUILD_DIR}"
+
+ # Fill in the template
+ sed "s,%DAEMON%,$DAEMON,g;s,%SEND%,$SEND,g" "${MODULE_DIR}/templates/dbus.service" \
+ > "$MODULE_BUILD_DIR/etc/systemd/system/dbus.service" \
+ || perror "Could not generate $MODULE_BUILD_DIR/etc/systemd/system/dbus.service"
+ fi
+
+ # Same for socket file
+ if [ -z "${found["socket"]}" ]; then
+ cp "${MODULE_DIR}/templates/dbus.socket" "$MODULE_BUILD_DIR/etc/systemd/system" \
+ || perror "Could not copy templates/dbus.socket to build dir."
+ fi
}
+post_copy() {
+ :
+}
diff --git a/core/modules/dbus/templates/dbus.service b/core/modules/dbus/templates/dbus.service
index c9f747b0..ef9ee71d 100644
--- a/core/modules/dbus/templates/dbus.service
+++ b/core/modules/dbus/templates/dbus.service
@@ -5,9 +5,8 @@ Requires=dbus.socket
After=syslog.target
[Service]
-%UUIDGEN%
ExecStartPre=-/opt/openslx/bin/rm -f /var/run/dbus/pid
-ExecStart=%DAEMON% --system --address=systemd: --nofork %DAEMON_ARGS%
+ExecStart=%DAEMON% --system --address=systemd: --nofork
ExecReload=%SEND% --print-reply --system --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
OOMScoreAdjust=-900
diff --git a/core/modules/dbus/data/etc/systemd/system/dbus.socket b/core/modules/dbus/templates/dbus.socket
index 5c373cf4..5c373cf4 100644
--- a/core/modules/dbus/data/etc/systemd/system/dbus.socket
+++ b/core/modules/dbus/templates/dbus.socket