diff mbox series

[bug#45018,v2,1/6] daemon: 'Agent' constructor takes a list of environment variables.

Message ID 20201206220415.23279-2-ludo@gnu.org
State Accepted
Headers show
Series Process and connection reuse for substitutions | expand

Checks

Context Check Description
cbaines/submitting builds success
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Ludovic Courtès Dec. 6, 2020, 10:04 p.m. UTC
* 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 mbox series

Patch

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<string, string> &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 <dirent.h>
 #include <unistd.h>
 #include <signal.h>
+#include <map>
 #include <functional>
 
 #include <cstdio>
@@ -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<string, string> &env = std::map<string, string>());
 
     ~Agent();
 };