From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IG7uD4DcdGIxxQAAbAwnHQ (envelope-from ) for ; Fri, 06 May 2022 10:29:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id oLTDD4DcdGK7UAAAauVa8A (envelope-from ) for ; Fri, 06 May 2022 10:29:52 +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 AABEF9790 for ; Fri, 6 May 2022 10:29:51 +0200 (CEST) Received: from localhost ([::1]:50256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmt0a-0007HD-AP for larch@yhetil.org; Fri, 06 May 2022 04:08:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmszx-0007Gl-D8 for guix-devel@gnu.org; Fri, 06 May 2022 04:07:37 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:33793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmszu-00069Z-S0; Fri, 06 May 2022 04:07:36 -0400 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id BBBCEC0004; Fri, 6 May 2022 08:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1651824450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XohZ85l58GLkd4aLRMejHGPnao+srWlW3waBwru1xko=; b=W7iqRgt3fI5xTHEpzJ7UqmCHESCS4Y142LWy/ZPLoiiPYVMU3p+bucwXsl0thkbfby3Ba4 LpVNmyGswhc5kdswDdDjSzf4x8Denj9CIIhvpbnH8mG5o/SbvG+cGNgnFgLjqozsrAwnqc 44E6vmkIcNzOewz0Oucqjaoa/7q55E5L9JAUK/0K8jtu6xbv/6vDzfihTBksKySbrC5RnG foppHEaDkrekQ8ZWD6x9fd5Oj99OLS5FpUVNLcyw+uOYhhqgW2dvzfXwkF9MarlF5EwB3D XkzBaz6DkHUFJcl5Cj8OR2tY8CZV+XaMqdvX+gkRQS6xXeGgFL4pV1Mf6i1gRA== From: Andrew Tropin To: Kevin Boulain , guix-devel@gnu.org Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , Carlo Zancanaro , Leo Famulari Subject: Re: Should Guix Home daemonize Shepherd? In-Reply-To: References: Date: Fri, 06 May 2022 11:07:25 +0300 Message-ID: <87bkwbm6de.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Received-SPF: pass client-ip=217.70.183.198; envelope-from=andrew@trop.in; helo=relay6-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" 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=1651825791; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=XohZ85l58GLkd4aLRMejHGPnao+srWlW3waBwru1xko=; b=VOGuamVVTz4j3b/5J6nI05qwhAWxz40dVo5G91XiCoiLNknDA9wCJGL+l5gDAJIUBQFct+ Z3AaVPhKgQbj1oJ3LX7x2cLrLicoE08OCYAuPh52sEhh+ptsbOffdH6kJqNwUunR/lMqci KRxzKcvanHFn/Hr+JQjomD+qax8bkNKVoA1tQdsfvdnwqpk/vslUxrlro70D/GGHZR6k72 aHjPpPw83EQKEOj1AfoU+7C8ilcmkYY5niZ/Wug/fBYznN7pXST2gDA3tD2K1YBGTVBiS7 WmJA+jigqoEGiHJvQ7bOXhwmVMQOBpmIupU4ajZJHSwok0HC8faY0zU4hZUkXQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651825791; a=rsa-sha256; cv=none; b=ImD7kVD/7k/Txlq7XeW8ySz9FIjwnMvp+Z08crMCBQqLIzTU0piJ4rHpnETOhgXq6BzjKA GxgRub7x0zrZIpISfRcUuLmuSzDAe1HugjVxz4kpjQQcl2+yaAdp56RY/iO+0nSLmoOopS +iVnflzNsz6uV41M1HNVxMUcvFgtyuMEmHUg/YeEZp1fjbJtbzHkRHC1zQq8JOm+0Hxgk8 v6xapHmy0d55EtAdzzodi2C8bDsYT2SARcp7Yqq6gzk8nE8DAKmaQJllwIoyeFFLtuPWI2 O2+DYCCAT/TPw/pHSfM2mWia7l2cRUnFrAPK4LCta1zG7ppJeQ+xX3JkB32bDQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=trop.in header.s=gm1 header.b=W7iqRgt3; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.20 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=trop.in header.s=gm1 header.b=W7iqRgt3; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: AABEF9790 X-Spam-Score: -4.20 X-Migadu-Scanner: scn1.migadu.com X-TUID: +JUr7asmudCR --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On 2022-03-12 18:49, Kevin Boulain wrote: > So, I've done some digging and I'm coming back with two findings :) > > First, Guix Home correctly tells the user Shepherd to daemonize itself > via an 'action' > (https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/home/services/shephe= rd.scm#n64) > but, from my understanding, the daemonization process is missing at > least a setsid call > (https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/ser= vice.scm#n1421), > see the attached 'shepherd-setsid.patch'. This fixes the Shepherd > dying when exiting the SSH session or the Shepherd catching the ^C. > I guess it should also close std{in,out,err} like it's done for the > regular services > (https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/ser= vice.scm#n806) > but this answers a part of my initial post. CCed Leo, Ludovic and Carlo. > > Second, elogind (it's required by Guix Home to get the XDG_* > environment variables and also part of %desktop-services) will remove > /run/user/$uid when the session ends.=20 Actually, XDG_RUNTIME_DIR can be provided not only by elogind, but also by pam_rundir or something similar, however in general it's true, runtime dir will be removed when session ends. > It's standard, but the problem is that Guix Home's > 'on-first-login-executed' is located there, alongside > 'shepherd/socket' and probably the other user daemon's sockets. This > easily results in duplicate services being rerun when the old ones > haven't been killed because 'KillUserProcesses' is set to 'no' by > default > (https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/desktop.scm= #n937). > I don't think it's a bad idea to set KillUserProcesses=3Dno (I remember > that when this was first introduced a lot of users complained, see for > example https://github.com/tmux/tmux/issues/428) but now we're in an > awkward position unless Guix Home users move everything out of > XDG_RUNTIME_DIR (for example, tmux's socket is in /tmp). > > Thoughts? I must admit, I'm not sure how to address the elogind issue, > XDG_RUNTIME_DIR is ingrained in a lot of places (even in the Shepherd > https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/supp= ort.scm#n284) > and asking users to override socket flags (and others) for all the > services they run (if at all possible) sounds a bit counterintuitive. This is a tough question, faced it when only started to work on Guix Home. One idea I had back in the days is to have a possibility to get lingering user shepherd, which starts on boot, the implementation doesn't seem trivial so I decided to postpone experiments in this direction for a better times. Not sure if it's any perfect, but at least is something to think about. > Or am I missing something obvious? > Detach from the controlling terminal when daemonizing > > https://lists.gnu.org/archive/html/guix-devel/2022-03/msg00040.html > > diff --git c/modules/shepherd/service.scm w/modules/shepherd/service.scm > index ad8608b..62f97bc 100644 > --- c/modules/shepherd/service.scm > +++ w/modules/shepherd/service.scm > @@ -1420,8 +1420,12 @@ we want to receive these signals." > (else > (if (zero? (primitive-fork)) > (begin > - (catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1)) > - #t) > + (setsid) > + (if (zero? (primitive-fork)) > + (begin > + (catch-system-error (prctl PR_SET_CHILD_SUBREAPER= 1)) > + #t) > + (primitive-exit 0))) > (primitive-exit 0)))))) > (persistency > "Save the current state of running and non-running services. =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmJ01z0PHGFuZHJld0B0 cm9wLmluAAoJECII0glYwd6wfKoP/0UL7C3JLVmKrNoDGR58LLePL9E25MkYvu59 82523VVN0zuMxdEMGLt0NcV9paM0KotL6/Ne+65u9zBQ2hruTippJzVV+0XEQBW5 aL+fQogAvFEz3z76q2xDmYUhqSIz/69q2ZbvPXeQ40SyQEnauTVxEAvrQS7kH++v oORqPyz3HJFVRlG/n29Lu49WtJRXFZ6VtPX2UKisE6sQJCb2QbECmlwMNaRXlrDg KL+vz8kSVfa/lNeN2NEbfyVrF5Rwd+xr6qveWVSFOaPsI5J49hqoJdJssOBFmsl2 ZBqS4qB3U94YZ9xIMrBJM30JCbGK0hr0YDVcXGmy+PtBVtQchOdCLoRiAArZYFLd 3r9MYxawHrlLSY/cu6ctYBK+oRCyVXO1FBbZXyd887WlB4xYX/KHS5LiqQlqoF4w bGIYpSnZxbJ1hmeL8UaJiHhUPWyk0WJKIHe1GHRk06HBbj4Hp1VcrO4XEc00DHNm 75zzh+Zkuz6G7N9sgWU/4NBYsQZ4jr0Y5oQJ9bK6nTuOf6x4/jiWSAG342CrkH+0 X1mFZNgqXGhJCnbmzrNFAG6vHGJrvtXYcgEu7cvUmdHVq4/hmtwbHWMmMfgrwKMR ipxFveQ6mScc/v0TDPj34xTCRMNKRvv2Sd9anKOygNl++qlKnVyemU9dM+7MNWsz rxJ5tdk9 =ncRs -----END PGP SIGNATURE----- --=-=-=--