mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
Restore affinity
This commit is contained in:
parent
0abdf4beaa
commit
c6f2b89c0e
2 changed files with 28 additions and 8 deletions
|
@ -4,7 +4,8 @@ runCommand "nix-repl"
|
||||||
{ buildInputs = [ readline nixUnstable boehmgc ]; }
|
{ buildInputs = [ readline nixUnstable boehmgc ]; }
|
||||||
''
|
''
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
g++ -O3 -Wall -o $out/bin/nix-repl ${./nix-repl.cc} \
|
g++ -O3 -Wall -std=c++0x \
|
||||||
|
-o $out/bin/nix-repl ${./nix-repl.cc} \
|
||||||
-I${nixUnstable}/include/nix -L${nixUnstable}/lib/nix \
|
-I${nixUnstable}/include/nix -L${nixUnstable}/lib/nix \
|
||||||
-lexpr -lmain -lreadline -lgc
|
-lexpr -lmain -lreadline -lgc
|
||||||
''
|
''
|
||||||
|
|
33
nix-repl.cc
33
nix-repl.cc
|
@ -13,6 +13,7 @@
|
||||||
#include "common-opts.hh"
|
#include "common-opts.hh"
|
||||||
#include "get-drvs.hh"
|
#include "get-drvs.hh"
|
||||||
#include "derivations.hh"
|
#include "derivations.hh"
|
||||||
|
#include "affinity.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
@ -187,6 +188,27 @@ 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);
|
||||||
|
|
||||||
|
Pid pid;
|
||||||
|
pid = fork();
|
||||||
|
if (pid == -1) throw SysError("forking");
|
||||||
|
if (pid == 0) {
|
||||||
|
restoreAffinity();
|
||||||
|
execvp(program.c_str(), (char * *) &cargs[0]);
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pid.wait(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NixRepl::processLine(string line)
|
void NixRepl::processLine(string line)
|
||||||
{
|
{
|
||||||
if (line == "") return;
|
if (line == "") return;
|
||||||
|
@ -224,16 +246,13 @@ void NixRepl::processLine(string line)
|
||||||
/* We could do the build in this process using buildPaths(),
|
/* We could do the build in this process using buildPaths(),
|
||||||
but doing it in a child makes it easier to recover from
|
but doing it in a child makes it easier to recover from
|
||||||
problems / SIGINT. */
|
problems / SIGINT. */
|
||||||
if (system(("nix-store -r " + drvPath + " > /dev/null").c_str()) == -1)
|
if (runProgram("nix-store", Strings{"-r", drvPath}) != 0) return;
|
||||||
throw SysError("starting nix-store");
|
|
||||||
Derivation drv = parseDerivation(readFile(drvPath));
|
Derivation drv = parseDerivation(readFile(drvPath));
|
||||||
std::cout << "this derivation produced the following outputs:" << std::endl;
|
std::cout << std::endl << "this derivation produced the following outputs:" << std::endl;
|
||||||
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl;
|
std::cout << format(" %1% -> %2%") % i->first % i->second.path << std::endl;
|
||||||
} else {
|
} else
|
||||||
if (system(("nix-shell " + drvPath).c_str()) == -1)
|
runProgram("nix-shell", Strings{drvPath});
|
||||||
throw SysError("starting nix-shell");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (string(line, 0, 1) == ":")
|
else if (string(line, 0, 1) == ":")
|
||||||
|
|
Loading…
Reference in a new issue