diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-09 18:00:33 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2012-11-09 18:00:33 +0100 |
commit | ea89df2b76811505239b508a570ac9c0ea591038 (patch) | |
tree | 7b11ea7186ad2b73bf12ebb2e51e7238a052db85 /src/libstore/build.cc | |
parent | 48c19c4633b1443015531ee3032b16b29b0a92f9 (diff) |
Use vfork() instead of fork() if available
Hopefully this reduces the chance of hitting ‘unable to fork: Cannot
allocate memory’ errors. vfork() is used for everything except
starting builders.
Diffstat (limited to 'src/libstore/build.cc')
-rw-r--r-- | src/libstore/build.cc | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 6def0c1c5..3e67e55d4 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -665,7 +665,7 @@ HookInstance::HookInstance() builderOut.create(); /* Fork the hook. */ - pid = fork(); + pid = maybeVfork(); switch (pid) { case -1: @@ -2662,8 +2662,19 @@ void SubstitutionGoal::tryToRun() if (pathExists(destPath)) deletePathWrapped(destPath); + worker.store.setSubstituterEnv(); + + /* Fill in the arguments. */ + Strings args; + args.push_back(baseNameOf(sub)); + args.push_back("--substitute"); + args.push_back(storePath); + args.push_back(destPath); + const char * * argArr = strings2CharPtrs(args); + /* Fork the substitute program. */ - pid = fork(); + pid = maybeVfork(); + switch (pid) { case -1: @@ -2677,18 +2688,6 @@ void SubstitutionGoal::tryToRun() if (dup2(outPipe.writeSide, STDOUT_FILENO) == -1) throw SysError("cannot dup output pipe into stdout"); - /* Pass configuration options (including those overriden - with --option) to the substituter. */ - setenv("_NIX_OPTIONS", settings.pack().c_str(), 1); - - /* Fill in the arguments. */ - Strings args; - args.push_back(baseNameOf(sub)); - args.push_back("--substitute"); - args.push_back(storePath); - args.push_back(destPath); - const char * * argArr = strings2CharPtrs(args); - execv(sub.c_str(), (char * *) argArr); throw SysError(format("executing `%1%'") % sub); |