From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IKr8C5EOHmL6MQEAgWs5BA (envelope-from ) for ; Tue, 01 Mar 2022 13:16:17 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id KJgNBZEOHmJXEAEAG6o9tA (envelope-from ) for ; Tue, 01 Mar 2022 13:16:17 +0100 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 75C643FA64 for ; Tue, 1 Mar 2022 13:16:16 +0100 (CET) Received: from localhost ([::1]:34090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nP1QM-00024P-PB for larch@yhetil.org; Tue, 01 Mar 2022 07:16:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nP1Cd-0000Iy-AJ for guix-patches@gnu.org; Tue, 01 Mar 2022 07:02:05 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:41836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nP1Cc-0007a1-NH for guix-patches@gnu.org; Tue, 01 Mar 2022 07:02:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nP1Cc-0006MZ-Ga for guix-patches@gnu.org; Tue, 01 Mar 2022 07:02:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#54205] [PATCH v2] Factor out a public FORK-AND-CALL. Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 01 Mar 2022 12:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54205 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Attila Lendvai , 54205@debbugs.gnu.org Received: via spool by 54205-submit@debbugs.gnu.org id=B54205.164613612024451 (code B ref 54205); Tue, 01 Mar 2022 12:02:02 +0000 Received: (at 54205) by debbugs.gnu.org; 1 Mar 2022 12:02:00 +0000 Received: from localhost ([127.0.0.1]:35733 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nP1CZ-0006MI-UN for submit@debbugs.gnu.org; Tue, 01 Mar 2022 07:02:00 -0500 Received: from mailrelay.tugraz.at ([129.27.2.202]:30065) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nP1CW-0006M8-UD for 54205@debbugs.gnu.org; Tue, 01 Mar 2022 07:01:58 -0500 Received: from lprikler-laptop.ist.intra (gw.ist.tugraz.at [129.27.202.101]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4K7G7h743Kz1LZWn; Tue, 1 Mar 2022 13:01:52 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4K7G7h743Kz1LZWn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1646136113; bh=Z6AN3XJLM1vnvfiVNHrsns/EaKVXFrPOtZLNf5Jt/NE=; h=Subject:From:To:Date:In-Reply-To:References:From; b=ay8b5irE4B/KWZuNIah5FcUTO/POGAeL+Je8Kv58QkDY2WlInXt4T5RFoeUa9PrKS vvqRSPxBFQ8sutC+OFI+t++XwL6aOdRmtwJmWZXa7Ne/8v/Zgtp5gdadZrRjFoBqmg saV/iIJnHgpqoO8BiNKovcx/xuFNRiwmAol3oVU0= Message-ID: From: Liliana Marie Prikler Date: Tue, 01 Mar 2022 13:01:52 +0100 In-Reply-To: <20220301072927.26525-1-attila@lendvai.name> References: <20220301072927.26525-1-attila@lendvai.name> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUG-Backscatter-control: waObeELIUl4ypBWmcn/8wQ X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 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-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1646136976; 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: 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=Z6AN3XJLM1vnvfiVNHrsns/EaKVXFrPOtZLNf5Jt/NE=; b=HnUzA8SgbZvtW+Ue+njAF7Y/D6aQPXWbuq8yBj5fx1eV4EA0UfLbNMSEDwk5XDOZBXqDEy bjzM0Puwwn6nhhHSMHXwhUwiMzwF4rPc8Xz1WRp4b3KZV/WQfvAC+MrRngz0TUiN6eDKPo 9ZEiF+zq0MV6qz8bhmzi1hlvsaEA3APF239SckZtavgd2qRwPFeLKYnnNNHCa0LePncYKo 2cFDMsntOMJX7lLX4bIbkJhg6jLGnudX0lBWiJIcS6chISDR5tkbBylND0zovIwxwVy2Yr YW7uRSyNHAAGr/LnhdRoxpF9O/BLiOCmIlTDukdEnzYwmC6d9K/q6ee8hP/T+g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1646136976; a=rsa-sha256; cv=none; b=NAYwY4sU9lG4lhkGu934YoBAIFokKHu6ZMr2mVJm2PKkFNoivpCOEcLUNrAph0fxiEkNdj PwwDzgF/mT1cffUTRiFqD3PSQ6FmaVH+GZP4ad3PdRKLxdLKOtvGVisnvnL2zJqerpbnDZ ZWt23mSumUhhpZwkUnpSQMWj5it7qRdHORAKS6/UVyqc9jD5pIiNloNyuetd2PE7UfhON9 fr9qo8Sq5UpzIdA8ar7MQ6epTI02sde1vPwU73zeRfCTwfDZ3HxUDTmh/4Y0evA0Txlfjh xamhSDGv5agGThZIZNp2+FUAjqeX/ijNIRx8znpkUEEHoe/DxwvXeHzLR6jZvw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=ay8b5irE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=tugraz.at (policy=none); 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: 5.61 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=tugraz.at header.s=mailrelay header.b=ay8b5irE; dmarc=fail reason="SPF not aligned (relaxed)" header.from=tugraz.at (policy=none); 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: 75C643FA64 X-Spam-Score: 5.61 X-Migadu-Scanner: scn1.migadu.com X-TUID: jMGE94VhErnI Am Dienstag, dem 01.03.2022 um 08:29 +0100 schrieb Attila Lendvai: > This enables service implementations to easily inject code that is > run before their service is started.  One such example is calling > setrlimit from a start action to set NOFILE (the open files limit), > before the service is exec'ed and inherits this value from the parent > process, i.e. from Shepherd. In general, I think such capabilities should be added to exec-command, rather than resorting to a lambda. It takes a little while to realize that call-in-fork, fork-and-call or whatever you want to name it is in fact not pure evil; mainly because shepherd could in its stead already invoke any lambda you throw at it. That being said, one should always be aware that this child process runs with the full permissions of shepherd, which you normally don't want to do for a service. > [...] > +(define* (fork-and-call thunk) > +  "Call THUNK in a fork." >    ;; Install the SIGCHLD handler if this is the first fork+exec- > command call. This docstring, as well as the procedure name only describe what is done with thunk in the crudest terms. What's more, I don't think it makes too much sense to restrict ourselves to thunks if we already run arbitrary code anyway. In my opinion, it ought to be > +(define* (fork+apply proc . args) > + "Spawn a process that calls PROC with ARGS and return its PID." >    (unless %sigchld-handler-installed? >      (sigaction SIGCHLD handle-SIGCHLD SA_NOCLDSTOP) > @@ -916,17 +906,34 @@ its PID." >              ;; process. >              (unblock-signals %precious-signals) >   > -            (exec-command command > -                          #:user user > -                          #:group group > -                          #:supplementary-groups supplementary- > groups > -                          #:log-file log-file > -                          #:directory directory > -                          #:file-creation-mask file-creation-mask > -                          #:create-session? create-session? > -                          #:environment-variables environment- > variables)) > +            (apply proc args)) >            pid)))) WDYT?   > +(define* (fork+exec-command command > +                            #:key > +                            (user #f) > +                            (group #f) > +                            (supplementary-groups '()) > +                            (log-file #f) > +                            (directory (default-service-directory)) > +                            (file-creation-mask #f) > +                            (create-session? #t) > +                            (environment-variables > +                             (default-environment-variables))) > +  "Spawn a process that executed COMMAND as per 'exec-command', and > return > +its PID." This is just copypasta from a previous mistake, but s/executed/executes/. Cheers