From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gPRKO7E6kWLX/QAAbAwnHQ (envelope-from ) for ; Fri, 27 May 2022 22:55:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UCBFO7E6kWIEOwAA9RJhRA (envelope-from ) for ; Fri, 27 May 2022 22:55:13 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A00DF19B24 for ; Fri, 27 May 2022 22:55:13 +0200 (CEST) Received: from localhost ([::1]:57592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nugzI-0000XQ-44 for larch@yhetil.org; Fri, 27 May 2022 16:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nugz8-0000XF-Eo for bug-guix@gnu.org; Fri, 27 May 2022 16:55:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:41966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nugz8-0004A4-4K for bug-guix@gnu.org; Fri, 27 May 2022 16:55:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nugz8-0008EP-1E for bug-guix@gnu.org; Fri, 27 May 2022 16:55:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#55444: elogind startup race between shepherd and dbus-daemon Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 27 May 2022 20:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55444 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 55444@debbugs.gnu.org Received: via spool by 55444-submit@debbugs.gnu.org id=B55444.165368490031630 (code B ref 55444); Fri, 27 May 2022 20:55:01 +0000 Received: (at 55444) by debbugs.gnu.org; 27 May 2022 20:55:00 +0000 Received: from localhost ([127.0.0.1]:35863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nugz5-0008E6-QS for submit@debbugs.gnu.org; Fri, 27 May 2022 16:55:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51604) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nugz3-0008Ds-ND for 55444@debbugs.gnu.org; Fri, 27 May 2022 16:54:58 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:39562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nugyy-00048U-8m for 55444@debbugs.gnu.org; Fri, 27 May 2022 16:54:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=SXqEvI1r3wW6fjldWZZTlH6jgTZDXsl9yjw9gbm7LNY=; b=fqfg/IZ70nxDa6WISOd5 amoMR5eY8dNhroeQkmYUlS37UT4icP3yXgj9HpvHFWTcmlPk925VQ8pqB1XaUhUY1HsPkJLl8SyT+ kQUJZpZmDU29TITWm3YctfHj6OOavdVNf7wg+iRPZjHAbUv9wX1O3bLkXbr0CiHiUyhRIxOY86XFd dPlBqDKqfendhe4NZLlqnAe1c5mqTJpfkqURofdnToGrBRcjHEiTooLE4MjOpOT5cwE0RYqQ75xeE sIpBw3z+E0tXEyzFklm/RUCp92Ae6K/UK1M22ZpF6cGxKSJv1vFjjWFqonRO/2KUnMclwbbEOAhX3 k3fr+pML2hrVxw==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:58234 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nugyx-0008RU-Sr for 55444@debbugs.gnu.org; Fri, 27 May 2022 16:54:52 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <877d6lc28o.fsf@inria.fr> Date: Fri, 27 May 2022 22:54:49 +0200 In-Reply-To: <877d6lc28o.fsf@inria.fr> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Mon, 16 May 2022 10:26:15 +0200") Message-ID: <878rqmelwm.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653684913; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=SXqEvI1r3wW6fjldWZZTlH6jgTZDXsl9yjw9gbm7LNY=; b=frhcicg34SNNC8Fh2guZebG409iVwSVdjgSITudqKiA+Jord3bCUEbDj6JMq/+JR7SJO8C nwlsV4oYmGm3tvV68dBq+V2oVSOaX4uMGE1shShULbRnBr8bpDvzJ9McLX931VzQiQUCqK fmJvrAiWpYykqh/3WsSBFfKH3SJWm5zEf3qNSmjnO5IlRpM4PZ7hfpDC3z4ShgdxUtZAqe jKLYfBPMyv9kjyjlrru6eusG4+VEj3ZYB9Ewm//PupgDBltI0YfhaGg236cm6XBHyPH821 YdYqCTYq8g8TL8bis0boF0aLiAISNWwlWu8gvjCgSMrFtY+H6DOWo5EVZVj3kg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653684913; a=rsa-sha256; cv=none; b=e1Gttk3AHZUGhtf/VK6SAB4w1Sa8aTe13U8Hx4MCsoT1zSHNEfL0jNUgPSaE0evqqz6uw5 7QjmxhjpP1d9dNE/Xs9m2st2XRgTN5+rYLosOeILj1FCa+kR6jeSLmcavmR4KVLgRw7vLh rS8DitwetJ55VZXz18FSEustM5pvvP5sCFbOcJyweKrLIeccx7P737moO7AABzIyLtKcJA FjVngPEaRh+yORea6cQs+wFrmPatOcTiXZ44XMR1hPR5SqJILFna6eTglUzr49+/d7JArO RR4VVr9TofC1+IHZ2n+4WNx/xkEOjs1CN1rNhSBerMfVsg7fQ9REs4/FAJpjGg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="fqfg/IZ7"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.74 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="fqfg/IZ7"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: A00DF19B24 X-Spam-Score: -4.74 X-Migadu-Scanner: scn0.migadu.com X-TUID: eIWjNbwqTY/F --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hey there, Ludovic Court=C3=A8s skribis: > So it would seem that the solution to this is to prevent dbus-daemon > from starting elogind. We can do that by changing > org.freedesktop.login1.service so that it has =E2=80=9CExec=3Dtrue=E2=80= =9D instead of > =E2=80=9CExec=3Delogind --daemon=E2=80=9D. > > =E2=80=9CExec=3Dtrue=E2=80=9D is a bit crude because it doesn=E2=80=99t g= uarantee that elogind is > really started; if that isn=E2=80=99t good enough, we could instead wait = for the > PID file or something (as of Shepherd 0.9.0, invoking =E2=80=98herd start > elogind=E2=80=99 potentially leads shepherd to start a second instance if= the > first one is still being started, so we can=E2=80=99t really do that). The patch below address that: it changes the =E2=80=9CExec=3D=E2=80=9D line= of =E2=80=98org.freedesktop.login1=E2=80=99 to refer to a wrapper. That wrapp= er connects to shepherd and waits until =E2=80=98elogind=E2=80=99 is started. That way, if dbus-daemon comes first, it won=E2=80=99t actually launch anyt= hing and instead wait for the Shepherd =E2=80=98elogind=E2=80=99 service to be u= p. (And if it comes second, dbus-daemon won=E2=80=99t try to launch anything, so no spurious =E2=80=9Calready running=E2=80=9D messages.) I tested it in a =E2=80=98desktop.tmpl=E2=80=99 VM, quickly logging in on t= ty1. On /var/log/messages, you can see the =E2=80=9CActivating =E2=80=A6.login1=E2= =80=9D message from dbus-daemon, followed by =E2=80=9CService elogind started=E2=80=9D from she= pherd, followed by =E2=80=9CSuccessfully activated =E2=80=A6.login1=E2=80=9D from = dbus-daemon. The =E2=80=9Celogind=E2=80=9D system test passes too. Thoughts? Objections? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-services-elogind-When-started-by-dbus-daemon-wait-fo.patch Content-Description: the patch >From 7ef63d7426677961afd2bd937af19b08209c5b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 27 May 2022 22:41:55 +0200 Subject: [PATCH] services: elogind: When started by dbus-daemon, wait for the Shepherd service. Fixes . Previously shepherd and dbus-daemon would race to start elogind. In some cases (for instance if one logs in quickly enough on the tty), dbus-daemon would "win" and start elogind before shepherd has had a chance to do it. Consequently, shepherd would fail to start elogind and mark it as stopped and disabled, in turn preventing services that depend on it such as 'xorg-server' from starting. * gnu/services/desktop.scm (elogind-dbus-service): Rewrite to refer to a wrapper that waits for the 'elogind' Shepherd service. --- gnu/services/desktop.scm | 79 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/gnu/services/desktop.scm b/gnu/services/desktop.scm index 24fd43a207..318107a2ca 100644 --- a/gnu/services/desktop.scm +++ b/gnu/services/desktop.scm @@ -1075,10 +1075,81 @@ (define-syntax-rule (ini-file config file clause ...) ("HybridSleepMode" (sleep-list elogind-hybrid-sleep-mode)))) (define (elogind-dbus-service config) - (list (wrapped-dbus-service (elogind-package config) - "libexec/elogind/elogind" - `(("ELOGIND_CONF_FILE" - ,(elogind-configuration-file config)))))) + "Return a @file{org.freedesktop.login1.service} file that tells D-Bus how to +\"start\" elogind. In practice though, our elogind is started when booting by +shepherd. Thus, the @code{Exec} line of this @file{.service} file does not +explain how to start elogind; instead, it spawns a wrapper that waits for the +@code{elogind} shepherd service. This avoids a race condition where both +@command{shepherd} and @command{dbus-daemon} would attempt to start elogind." + ;; For more info on the elogind startup race, see + ;; . + + (define elogind + (elogind-package config)) + + (define wrapper + (program-file "elogind-dbus-shepherd-sync" + (with-imported-modules '((gnu services herd)) + #~(begin + (use-modules (gnu services herd) + (srfi srfi-1) + (ice-9 match)) + + (define (elogind-service? service) + (memq 'elogind (live-service-provision service))) + + (define max-attempts + ;; Number of attempts before assuming elogind failed + ;; to start. + 20) + + ;; Repeatedly check whether the 'elogind' shepherd + ;; service is up and running. (As of Shepherd 0.9.1, + ;; we cannot just call the 'start' method and wait for + ;; it: it would spawn an additional elogind process.) + (let loop ((attempts 0)) + (define services + (current-services)) + + (when (>= attempts max-attempts) + (format (current-error-port) + "elogind shepherd service not started~%") + (exit 2)) + + (match (find elogind-service? services) + (#f + (format (current-error-port) + "no elogind shepherd service~%") + (exit 1)) + (service + (unless (live-service-running service) + (sleep 1) + (loop (+ attempts 1)))))))))) + + (define build + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (ice-9 match)) + + (define service-directory + "/share/dbus-1/system-services") + + (mkdir-p (dirname (string-append #$output service-directory))) + (copy-recursively (string-append #$elogind service-directory) + (string-append #$output service-directory)) + (symlink (string-append #$elogind "/etc") ;for etc/dbus-1 + (string-append #$output "/etc")) + + ;; Replace the "Exec=" line of the 'org.freedesktop.login1.service' + ;; file with one that refers to WRAPPER instead of elogind. + (match (find-files #$output "\\.service$") + ((file) + (substitute* file + (("Exec[[:blank:]]*=.*" _) + (string-append "Exec=" #$wrapper "\n")))))))) + + (list (computed-file "elogind-dbus-service-wrapper" build))) (define (pam-extension-procedure config) "Return an extension for PAM-ROOT-SERVICE-TYPE that ensures that all the PAM -- 2.36.0 --=-=-=--