about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-04-25T17·10+0200
committerEelco Dolstra <edolstra@gmail.com>2017-04-25T17·10+0200
commit23aa1619daace5db30233a53183911adb42322d9 (patch)
treeec3bb88bf6b75d805f6055d16d451f4cbfc49556
parent4c95ef3768f8415579d9dd8bda69407021b72017 (diff)
Minor cleanup
-rw-r--r--src/nix/repl.cc17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 964bb85eb6f4..ae30502641a4 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -289,18 +289,15 @@ void NixRepl::completePrefix(string prefix)
 
 static int runProgram(const string & program, const Strings & args)
 {
-    std::vector<const char *> cargs; /* careful with c_str()! */
-    cargs.push_back(program.c_str());
-    for (Strings::const_iterator i = args.begin(); i != args.end(); ++i)
-        cargs.push_back(i->c_str());
-    cargs.push_back(0);
+    Strings args2(args);
+    args2.push_front(program);
 
     Pid pid;
     pid = fork();
     if (pid == -1) throw SysError("forking");
     if (pid == 0) {
         restoreAffinity();
-        execvp(program.c_str(), (char * *) &cargs[0]);
+        execvp(program.c_str(), stringsToCharPtrs(args2).data());
         _exit(1);
     }
 
@@ -394,7 +391,7 @@ bool NixRepl::processLine(string line)
         state.callFunction(f, v, result, Pos());
 
         Path drvPath = getDerivationPath(result);
-        runProgram("nix-shell", Strings{drvPath});
+        runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPath});
     }
 
     else if (command == ":b" || command == ":i" || command == ":s") {
@@ -406,16 +403,16 @@ bool NixRepl::processLine(string line)
             /* We could do the build in this process using buildPaths(),
                but doing it in a child makes it easier to recover from
                problems / SIGINT. */
-            if (runProgram("nix-store", Strings{"-r", drvPath}) == 0) {
+            if (runProgram(settings.nixBinDir + "/nix-store", Strings{"-r", drvPath}) == 0) {
                 Derivation drv = readDerivation(drvPath);
                 std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
                 for (auto & i : drv.outputs)
                     std::cout << format("  %1% -> %2%") % i.first % i.second.path << std::endl;
             }
         } else if (command == ":i") {
-            runProgram("nix-env", Strings{"-i", drvPath});
+            runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPath});
         } else {
-            runProgram("nix-shell", Strings{drvPath});
+            runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPath});
         }
     }