aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-04-07 13:10:02 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-04-07 13:10:02 +0200
commit9b9e703df41d75949272059f9b8bc8b763e91fce (patch)
tree8ddcd01325ee08d8029e0a86f467390de23c7b39 /src/nix
parent8a29052cb2f52ef2c82c36fb3818fd0f66349729 (diff)
restoreSignals() + restoreAffinity() -> restoreProcessContext()
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/develop.cc3
-rw-r--r--src/nix/edit.cc3
-rw-r--r--src/nix/repl.cc30
-rw-r--r--src/nix/run.cc4
4 files changed, 11 insertions, 29 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index 7cc7b85be..498a7b45c 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -462,8 +462,7 @@ struct CmdDevelop : Common, MixEnvironment
auto args = phase || !command.empty() ? Strings{std::string(baseNameOf(shell)), rcFilePath}
: Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath};
- restoreAffinity();
- restoreSignals();
+ restoreProcessContext();
execvp(shell.c_str(), stringsToCharPtrs(args).data());
diff --git a/src/nix/edit.cc b/src/nix/edit.cc
index 6472dd27a..b26417b18 100644
--- a/src/nix/edit.cc
+++ b/src/nix/edit.cc
@@ -42,7 +42,8 @@ struct CmdEdit : InstallableCommand
auto args = editorFor(pos);
- restoreSignals();
+ restoreProcessContext();
+
execvp(args.front().c_str(), stringsToCharPtrs(args).data());
std::string command;
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index bce8d31dc..eed79c332 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -343,24 +343,6 @@ StringSet NixRepl::completePrefix(string prefix)
}
-static int runProgram(const string & program, const Strings & args)
-{
- 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(), stringsToCharPtrs(args2).data());
- _exit(1);
- }
-
- return pid.wait();
-}
-
-
bool isVarName(const string & s)
{
if (s.size() == 0) return false;
@@ -462,7 +444,7 @@ bool NixRepl::processLine(string line)
auto args = editorFor(pos);
auto editor = args.front();
args.pop_front();
- runProgram(editor, args);
+ runProgram(editor, true, args);
// Reload right after exiting the editor
state->resetFileCache();
@@ -481,7 +463,7 @@ bool NixRepl::processLine(string line)
state->callFunction(f, v, result, Pos());
StorePath drvPath = getDerivationPath(result);
- runProgram(settings.nixBinDir + "/nix-shell", Strings{state->store->printStorePath(drvPath)});
+ runProgram(settings.nixBinDir + "/nix-shell", true, {state->store->printStorePath(drvPath)});
}
else if (command == ":b" || command == ":i" || command == ":s") {
@@ -494,16 +476,18 @@ 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(settings.nixBinDir + "/nix", Strings{"build", "--no-link", drvPathRaw}) == 0) {
+ try {
+ runProgram(settings.nixBinDir + "/nix", true, {"build", "--no-link", drvPathRaw});
auto drv = state->store->readDerivation(drvPath);
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
for (auto & i : drv.outputsAndOptPaths(*state->store))
std::cout << fmt(" %s -> %s\n", i.first, state->store->printStorePath(*i.second.second));
+ } catch (ExecError &) {
}
} else if (command == ":i") {
- runProgram(settings.nixBinDir + "/nix-env", Strings{"-i", drvPathRaw});
+ runProgram(settings.nixBinDir + "/nix-env", true, {"-i", drvPathRaw});
} else {
- runProgram(settings.nixBinDir + "/nix-shell", Strings{drvPathRaw});
+ runProgram(settings.nixBinDir + "/nix-shell", true, {drvPathRaw});
}
}
diff --git a/src/nix/run.cc b/src/nix/run.cc
index ba60e57d8..b5d8ab38a 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -31,9 +31,7 @@ struct RunCommon : virtual Command
{
stopProgressBar();
- restoreSignals();
-
- restoreAffinity();
+ restoreProcessContext();
/* If this is a diverted store (i.e. its "logical" location
(typically /nix/store) differs from its "physical" location