local-derivation-goal.cc: save global errno to the stack before performing tests which might clobber it

This commit is contained in:
Adam Joseph 2022-07-19 03:49:52 -07:00
parent a9e75eca00
commit 36e1383b6b

View file

@ -851,10 +851,11 @@ void LocalDerivationGoal::startBuilder()
flags &= ~CLONE_NEWUSER; flags &= ~CLONE_NEWUSER;
child = clone(childEntry, stack + stackSize, flags, this); child = clone(childEntry, stack + stackSize, flags, this);
} }
if (child == -1) if (child == -1) {
switch(errno) { switch(errno) {
case EPERM: case EPERM:
case EINVAL: { case EINVAL: {
int errno_ = errno;
if (!userNamespacesEnabled && errno==EPERM) if (!userNamespacesEnabled && errno==EPERM)
notice("user namespaces appear to be disabled; they are required for sandboxing; check /proc/sys/user/max_user_namespaces"); notice("user namespaces appear to be disabled; they are required for sandboxing; check /proc/sys/user/max_user_namespaces");
if (userNamespacesEnabled) { if (userNamespacesEnabled) {
@ -875,11 +876,12 @@ void LocalDerivationGoal::startBuilder()
/* Mention sandbox-fallback in the error message so the user /* Mention sandbox-fallback in the error message so the user
knows that having it disabled contributed to the knows that having it disabled contributed to the
unrecoverability of this failure */ unrecoverability of this failure */
throw SysError("creating sandboxed builder process using clone(), without sandbox-fallback"); throw SysError(errno_, "creating sandboxed builder process using clone(), without sandbox-fallback");
} }
default: default:
throw SysError("creating sandboxed builder process using clone()"); throw SysError("creating sandboxed builder process using clone()");
} }
}
writeFull(builderOut.writeSide.get(), writeFull(builderOut.writeSide.get(),
fmt("%d %d\n", usingUserNamespace, child)); fmt("%d %d\n", usingUserNamespace, child));
_exit(0); _exit(0);