From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id LZgXNXVOUWJ6aAEAgWs5BA (envelope-from ) for ; Sat, 09 Apr 2022 11:14:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id SL2MLHVOUWI1+QAAG6o9tA (envelope-from ) for ; Sat, 09 Apr 2022 11:14:29 +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 4BA248944 for ; Sat, 9 Apr 2022 11:14:29 +0200 (CEST) Received: from localhost ([::1]:42472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nd7Aq-0000Jf-Gk for larch@yhetil.org; Sat, 09 Apr 2022 05:14:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AR-0008Rp-HG for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AR-0003lc-8K for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nd7AR-0008OE-4G for guix-patches@gnu.org; Sat, 09 Apr 2022 05:14:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54811] [PATCH 3/3] daemon: Support systemd-style socket activation. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Apr 2022 09:14:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54811 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54811@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 54811-submit@debbugs.gnu.org id=B54811.164949563732210 (code B ref 54811); Sat, 09 Apr 2022 09:14:03 +0000 Received: (at 54811) by debbugs.gnu.org; 9 Apr 2022 09:13:57 +0000 Received: from localhost ([127.0.0.1]:36719 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AL-0008NR-Eu for submit@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60506) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nd7AJ-0008Mm-Ms for 54811@debbugs.gnu.org; Sat, 09 Apr 2022 05:13:56 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nd7AC-0003kN-Mv; Sat, 09 Apr 2022 05:13:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=aXuSOoUD9PFCYxpT6+JbDOPQcLH7omCCf5f8oHqBu1s=; b=j/BNaR5/P/EASeBJz0or jXIueR6NdAmbjp214A9ODRbBY2GzWZXS8EX5Fr/767LQo3toaYpzq4KWFbftTTky7tnVovcKu1e/T dxJXCFNC60zxSuqMEWr9ckbHzZF+tSmkMuvwD9YOV7jKRgRQLKNKgpW1O/IssUrGCtX8zbCQXNvw9 VTB5xRAvDvdg6aJeRs78QxB1P9VfLvKbAio61gTR3TW/gg9DVuoY9LOMVLAZJAs52ZZTh1bFho4LX N+ADNazKHTlUNb9jwDUfx/lVFMQ1v+OJqnstq9AxiJtHzvZAgXCPAHUzOG6xZ4xTn/EA7ZyDM4KCd g2R3saDgryIMsA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:58682 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nd7AC-00086k-AM; Sat, 09 Apr 2022 05:13:48 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sat, 9 Apr 2022 11:13:40 +0200 Message-Id: <20220409091340.7013-3-ludo@gnu.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409091340.7013-1-ludo@gnu.org> References: <20220409091340.7013-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" 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=1649495669; 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: content-transfer-encoding:content-transfer-encoding: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=/tmPpB6TlXACmS+CYhpOys8NqLke3zcFm6Z64rcKqx8=; b=XUninA4KoEqCkA1knEuST/8L0gDQKLv13Kh9yXHJMeA0Cn/0BZWOq3WhHp0I0klg6Ys1Yv qjKh3Atzeo8dymun8YonM0iTZgeEQNBPkBACxYvibQ2F9pgcaU9Z+d6HiuGfXd3Q89Vnwy iZ4QYq1dgj4SN+CQop3bHVG0926Q6IrYT6lEZOEMFKiPcvCMd7SuORRBZXwiSQ1gktHVFb zU4hqpy5Ca+Pyy9Rh2lH5MhbA+IwB8YyB1IA0mXBIOY+G8L1QAw4lIkEyoA8LukclNg1Mb fGhtqummy6PQY0pEPq66AoSBU3nXEPfhcwVJoz2aUCja9P0Fy7zruCjsVV2R8g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649495669; a=rsa-sha256; cv=none; b=UTartUoiivI+Co+S/6TRzlooA1liK5E89q7VraO/K3uaJY3ZUV0MIga+5u0U5dZ2wfAdGV dKdu1jK5hxeeRIz3DjIYjVbOVkupMjEUiyk+RrybbXv4FLIiZUuTelk7tWu8ENxcOSu13Y MZihZVJi5hE7NyEtychZ09vzviAKlvxnXjhDayEpXX9+t8ls5xHGoLotskfwwPraMMiKvi FAr/mwFnZhPOhIUYmiyXSVWSHlE7rCsxJ/DEZP0hRSwvVlPLu3Yw1bcj/L601L1u9suSPG ey21sFGjcBHO+sk970lQT4s3wkxxFqrbaeyj/D67IXgsq4E60YPvmqzfZogx4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="j/BNaR5/"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.77 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b="j/BNaR5/"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 4BA248944 X-Spam-Score: -3.77 X-Migadu-Scanner: scn0.migadu.com X-TUID: VjbhGj2uHW5Q * nix/nix-daemon/guix-daemon.cc (SD_LISTEN_FDS_START): New macro. (systemd_activation_sockets): New function. (main): Use it. Remove obsolete 'printMsg' call. * doc/guix.texi (Invoking guix-daemon): Document socket activation. --- doc/guix.texi | 6 ++++- nix/nix-daemon/guix-daemon.cc | 42 ++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 16bd858a3b..81fec35eb7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -1554,7 +1554,11 @@ is normally run as @code{root} like this: # guix-daemon --build-users-group=guixbuild @end example -@noindent +@cindex socket activation, for @command{guix-daemon} +This daemon can also be started following the systemd ``socket +activation'' protocol (@pxref{Service De- and Constructors, +@code{make-systemd-constructor},, shepherd, The GNU Shepherd Manual}). + For details on how to set it up, @pxref{Setting Up the Daemon}. @cindex chroot diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc index 36a06a3fae..d7ab9c5e64 100644 --- a/nix/nix-daemon/guix-daemon.cc +++ b/nix/nix-daemon/guix-daemon.cc @@ -1,5 +1,5 @@ /* GNU Guix --- Functional package management for GNU - Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Ludovic Courtès + Copyright (C) 2012-2019, 2021-2022 Ludovic Courtès Copyright (C) 2006, 2010, 2012, 2014 Eelco Dolstra This file is part of GNU Guix. @@ -434,6 +434,31 @@ listening_sockets (const std::list &options) return result; } +/* First file descriptor provided at startup using systemd-style socket + activation. */ +#define SD_LISTEN_FDS_START 3 + +/* Return a list of file descriptors of listening sockets provided following + the systemd "socket activation" protocol. Return the empty list if we are + not being socket-activated. */ +static std::vector +systemd_activation_sockets () +{ + std::vector result; + + if (getEnv ("LISTEN_PID") == std::to_string (getpid ())) + { + unsigned int fdCount; + if (string2Int (getEnv ("LISTEN_FDS"), fdCount)) + { + for (unsigned int i = 0; i < fdCount; i++) + result.push_back (SD_LISTEN_FDS_START + i); + } + } + + return result; +} + int main (int argc, char *argv[]) @@ -494,7 +519,17 @@ main (int argc, char *argv[]) argp_parse (&argp, argc, argv, 0, 0, 0); - auto sockets = listening_sockets (listen_options); + auto sockets = systemd_activation_sockets (); + if (sockets.empty ()) + /* We were not "socket-activated" so open the sockets specified by + LISTEN_OPTIONS. */ + sockets = listening_sockets (listen_options); + else + printMsg (lvlInfo, + format (ngettext ("socket-activated with %1% socket", + "socket-activated with %1% sockets", + sockets.size ())) + % sockets.size ()); /* Effect all the changes made via 'settings.set'. */ settings.update (); @@ -531,9 +566,6 @@ using `--build-users-group' is highly recommended\n")); format ("automatic deduplication set to %1%") % settings.autoOptimiseStore); - printMsg (lvlDebug, - format ("listening on `%1%'") % settings.nixDaemonSocketFile); - run (sockets); } catch (std::exception &e) -- 2.35.1