From ee0e5d34a0ad5f52c547fdd7d270ab451eccab4a Mon Sep 17 00:00:00 2001 From: Maxim Cournoyer Date: Thu, 9 Dec 2021 23:53:12 -0500 Subject: [PATCH 5/5] services: dbus: Add synchronization primitives to dbus, elogind. This is an (unsuccessful) to fix https://issues.guix.gnu.org/52051. --- gnu/services/dbus.scm | 28 ++++++++++++++++++++-------- gnu/services/desktop.scm | 35 +++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/gnu/services/dbus.scm b/gnu/services/dbus.scm index da167f2e36..c285531663 100644 --- a/gnu/services/dbus.scm +++ b/gnu/services/dbus.scm @@ -194,14 +194,26 @@ (define dbus-shepherd-service (documentation "Run the D-Bus system daemon.") (provision '(dbus-system)) (requirement '(user-processes syslogd)) - (start #~(make-forkexec-constructor - (list (string-append #$dbus "/bin/dbus-daemon") - "--nofork" "--system" "--syslog-only") - #$@(if verbose? - '(#:environment-variables '("DBUS_VERBOSE=1") - #:log-file "/var/log/dbus-daemon.log") - '()) - #:pid-file "/var/run/dbus/pid")) + (modules `((gnu build dbus-service) + ,@%default-modules)) + (start + (with-imported-modules '((gnu build dbus-service)) + #~(lambda args + (define pid + ((make-forkexec-constructor + (list (string-append #$dbus "/bin/dbus-daemon") + "--nofork" "--system" "--syslog-only") + #$@(if verbose? + ;; Since the verbose output goes to the console, + ;; not syslog, add a log file to capture it. + '(#:environment-variables '("DBUS_VERBOSE=1") + #:log-file "/var/log/dbus-daemon.log") + '()) + #:pid-file "/var/run/dbus/pid"))) + ;; Ensure the system bus is ready to service requests + ;; before returning. + (wait-for-bus-readiness) + pid))) (stop #~(make-kill-destructor))))))) (define dbus-root-service-type diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm index 612d548eea..3208cb7aac 100644 --- a/gnu/services/desktop.scm +++ b/gnu/services/desktop.scm @@ -3,7 +3,7 @@ ;;; Copyright © 2015 Andy Wingo ;;; Copyright © 2015 Mark H Weaver ;;; Copyright © 2016 Sou Bunnbu -;;; Copyright © 2017, 2020 Maxim Cournoyer +;;; Copyright © 2017, 2020, 2021 Maxim Cournoyer ;;; Copyright © 2017 Nikita ;;; Copyright © 2018, 2020 Efraim Flashner ;;; Copyright © 2018 Ricardo Wurmus @@ -724,13 +724,32 @@ (define (elogind-shepherd-service config) (list (shepherd-service (requirement '(dbus-system)) (provision '(elogind)) - (start #~(make-forkexec-constructor - (list #$(file-append (elogind-package config) - "/libexec/elogind/elogind")) - #:environment-variables - (list (string-append "ELOGIND_CONF_FILE=" - #$(elogind-configuration-file - config))))) + (modules `((gnu build dbus-service) + ,@%default-modules)) + (start + (with-imported-modules '((gnu build dbus-service)) + #~(lambda args + (define pid + ((make-forkexec-constructor + (list #$(file-append strace "/bin/strace") "-f" + "-o/elogind.log" "-s700" + #$(file-append (elogind-package config) + "/libexec/elogind/elogind")) + #:environment-variables + (list (string-append "ELOGIND_CONF_FILE=" + #$(elogind-configuration-file + config)))))) + ;; Wait until the login1 service name has been acquired by + ;; D-Bus. This prevents potential races that would cause + ;; elogind to be auto started by D-Bus by other processes + ;; requiring it, causing problems. + (parameterize ((%send-dbus-bus (string-append "unix:path=" + %dbus-system-bus))) + (with-retries 25 1 + (pk 'available-dbus-services (dbus-available-services)) + (dbus-service-available? "org.freedesktop.login1"))) + + pid))) (stop #~(make-kill-destructor))))) (define elogind-service-type -- 2.34.0