From patchwork Thu Dec 3 10:19:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 25547 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5FAB127BBFC; Thu, 3 Dec 2020 10:20:12 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D353127BBFB for ; Thu, 3 Dec 2020 10:20:11 +0000 (GMT) Received: from localhost ([::1]:52414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kklid-0004Px-1E for patchwork@mira.cbaines.net; Thu, 03 Dec 2020 05:20:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkliU-0004PV-Iq for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:55169) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kkliU-0006Qv-B2 for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kkliU-0000FV-6E for guix-patches@gnu.org; Thu, 03 Dec 2020 05:20:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45018] [PATCH 1/6] daemon: 'Agent' constructor takes a list of environment variables. References: <20201203101314.10842-1-ludo@gnu.org> In-Reply-To: <20201203101314.10842-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 03 Dec 2020 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45018 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45018@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 45018-submit@debbugs.gnu.org id=B45018.1606990793870 (code B ref 45018); Thu, 03 Dec 2020 10:20:02 +0000 Received: (at 45018) by debbugs.gnu.org; 3 Dec 2020 10:19:53 +0000 Received: from localhost ([127.0.0.1]:38467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliK-0000Dy-LD for submit@debbugs.gnu.org; Thu, 03 Dec 2020 05:19:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47550) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkliI-0000Dh-G1 for 45018@debbugs.gnu.org; Thu, 03 Dec 2020 05:19:50 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40700) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkliC-0006Gl-N0; Thu, 03 Dec 2020 05:19:44 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=49238 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kkli6-0007oh-AD; Thu, 03 Dec 2020 05:19:43 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 3 Dec 2020 11:19:25 +0100 Message-Id: <20201203101930.11210-1-ludo@gnu.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * nix/libutil/util.hh (struct Agent)[Agent]: Add 'env' parameter. * nix/libutil/util.cc (Agent::Agent): Honor it. --- nix/libutil/util.cc | 6 +++++- nix/libutil/util.hh | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 59a2981359..69f1c634a9 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc @@ -1173,7 +1173,7 @@ void commonChildInit(Pipe & logPipe) ////////////////////////////////////////////////////////////////////// -Agent::Agent(const string &command, const Strings &args) +Agent::Agent(const string &command, const Strings &args, const std::map &env) { debug(format("starting agent '%1%'") % command); @@ -1191,6 +1191,10 @@ Agent::Agent(const string &command, const Strings &args) commonChildInit(fromAgent); + for (auto pair: env) { + setenv(pair.first.c_str(), pair.second.c_str(), 1); + } + if (chdir("/") == -1) throw SysError("changing into `/"); /* Dup the communication pipes. */ diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 13cff44316..880b0e93b2 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -281,8 +282,10 @@ struct Agent /* The process ID of the agent. */ Pid pid; - /* The command and arguments passed to the agent. */ - Agent(const string &command, const Strings &args); + /* The command and arguments passed to the agent along with a list of + environment variable name/value pairs. */ + Agent(const string &command, const Strings &args, + const std::map &env = std::map()); ~Agent(); };