More graceful fallback for chroots on Linux < 2.13

This commit is contained in:
Eelco Dolstra 2015-02-23 15:52:04 +01:00
parent 99897f6979
commit 885bebf13b

View file

@ -1997,12 +1997,11 @@ void DerivationGoal::startBuilder()
int flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD; int flags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD;
if (!fixedOutput) flags |= CLONE_NEWNET; if (!fixedOutput) flags |= CLONE_NEWNET;
pid_t child = clone(childEntry, stack + sizeof(stack) - 8, flags, this); pid_t child = clone(childEntry, stack + sizeof(stack) - 8, flags, this);
if (child == -1) { if (child == -1 && errno == EINVAL)
if (errno == EINVAL) /* Fallback for Linux < 2.13 where CLONE_NEWPID and
throw SysError("cloning builder process (Linux chroot builds require 3.13 or later)"); CLONE_PARENT are not allowed together. */
else child = clone(childEntry, stack + sizeof(stack) - 8, flags & ~CLONE_NEWPID, this);
throw SysError("cloning builder process"); if (child == -1) throw SysError("cloning builder process");
}
writeFull(builderOut.writeSide, int2String(child) + "\n"); writeFull(builderOut.writeSide, int2String(child) + "\n");
_exit(0); _exit(0);
}); });