mirror of
https://github.com/NixOS/nix
synced 2025-06-27 00:11:17 +02:00
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.
This commit is contained in:
parent
48c19c4633
commit
ea89df2b76
6 changed files with 51 additions and 22 deletions
|
@ -760,8 +760,8 @@ Pid::operator pid_t()
|
|||
|
||||
void Pid::kill()
|
||||
{
|
||||
if (pid == -1) return;
|
||||
|
||||
if (pid == -1 || pid == 0) return;
|
||||
|
||||
printMsg(lvlError, format("killing process %1%") % pid);
|
||||
|
||||
/* Send the requested signal to the child. If it has its own
|
||||
|
@ -883,7 +883,8 @@ string runProgram(Path program, bool searchPath, const Strings & args)
|
|||
|
||||
/* Fork. */
|
||||
Pid pid;
|
||||
pid = fork();
|
||||
pid = maybeVfork();
|
||||
|
||||
switch (pid) {
|
||||
|
||||
case -1:
|
||||
|
@ -955,6 +956,13 @@ void setuidCleanup()
|
|||
}
|
||||
|
||||
|
||||
#if HAVE_VFORK
|
||||
pid_t (*maybeVfork)() = vfork;
|
||||
#else
|
||||
pid_t (*maybeVfork)() = fork;
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue