libstore: inline commonExecveingChildInit into single user
Change-Id: Ia389ec8c5e375b8386949c5fb031a52f27e76d37
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
#include "lix/libutil/c-calls.hh"
|
||||
#include "lix/libutil/current-process.hh"
|
||||
#include "lix/libutil/logging.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
void commonExecveingChildInit()
|
||||
{
|
||||
logger = makeSimpleLogger();
|
||||
|
||||
const static std::string pathNullDevice = "/dev/null";
|
||||
restoreProcessContext(false);
|
||||
|
||||
/* Put the child in a separate session (and thus a separate
|
||||
process group) so that it has no controlling terminal (meaning
|
||||
that e.g. ssh cannot open /dev/tty) and it doesn't receive
|
||||
terminal signals. */
|
||||
if (setsid() == -1)
|
||||
throw SysError("creating a new session");
|
||||
|
||||
/* Dup stderr to stdout. */
|
||||
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
|
||||
throw SysError("cannot dup stderr into stdout");
|
||||
|
||||
/* Reroute stdin to /dev/null. */
|
||||
auto fdDevNull = sys::open(pathNullDevice, O_RDWR);
|
||||
if (!fdDevNull) {
|
||||
throw SysError("cannot open '%1%'", pathNullDevice);
|
||||
}
|
||||
if (dup2(fdDevNull.get(), STDIN_FILENO) == -1) {
|
||||
throw SysError("cannot dup null device into stdin");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
///@file
|
||||
|
||||
namespace nix {
|
||||
|
||||
/**
|
||||
* Common initialisation performed in child processes that are just going to
|
||||
* execve.
|
||||
*
|
||||
* These processes may not use ReceiveInterrupts as they do not have an
|
||||
* interrupt receiving thread.
|
||||
*/
|
||||
void commonExecveingChildInit();
|
||||
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "lix/libstore/build/child.hh"
|
||||
#include "lix/libutil/c-calls.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include "lix/libutil/file-descriptor.hh"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "derivation-goal.hh"
|
||||
#include "lix/libutil/async-io.hh"
|
||||
#include "lix/libutil/async.hh"
|
||||
#include "lix/libutil/current-process.hh"
|
||||
#include "lix/libutil/error.hh"
|
||||
#include "lix/libstore/indirect-root-store.hh"
|
||||
#include "lix/libstore/machines.hh"
|
||||
@@ -25,7 +26,6 @@
|
||||
#include "lix/libutil/json.hh"
|
||||
#include "lix/libstore/build/personality.hh"
|
||||
#include "lix/libutil/namespaces.hh"
|
||||
#include "lix/libstore/build/child.hh"
|
||||
#include "lix/libutil/types.hh"
|
||||
#include "lix/libutil/unix-domain-socket.hh"
|
||||
#include "lix/libutil/mount.hh"
|
||||
@@ -1208,7 +1208,31 @@ void LocalDerivationGoal::runChild(const Path & builder, const Strings & envStrs
|
||||
|
||||
try { /* child */
|
||||
|
||||
commonExecveingChildInit();
|
||||
logger = makeSimpleLogger();
|
||||
|
||||
restoreProcessContext(false);
|
||||
|
||||
/* Put the child in a separate session (and thus a separate
|
||||
process group) so that it has no controlling terminal (meaning
|
||||
that e.g. ssh cannot open /dev/tty) and it doesn't receive
|
||||
terminal signals. */
|
||||
if (setsid() == -1) {
|
||||
throw SysError("creating a new session");
|
||||
}
|
||||
|
||||
/* Dup stderr to stdout. */
|
||||
if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1) {
|
||||
throw SysError("cannot dup stderr into stdout");
|
||||
}
|
||||
|
||||
/* Reroute stdin to /dev/null. */
|
||||
AutoCloseFD fdDevNull{open("/dev/null", O_RDWR)};
|
||||
if (!fdDevNull) {
|
||||
throw SysError("cannot open '%1%'", "/dev/null");
|
||||
}
|
||||
if (dup2(fdDevNull.get(), STDIN_FILENO) == -1) {
|
||||
throw SysError("cannot dup null device into stdin");
|
||||
}
|
||||
|
||||
const bool setUser = prepareChildSetup();
|
||||
|
||||
|
||||
@@ -174,7 +174,6 @@ liblix_sources += files(
|
||||
# keep-sorted start
|
||||
'binary-cache-store.cc',
|
||||
'build-result.cc',
|
||||
'build/child.cc',
|
||||
'build/derivation-goal.cc',
|
||||
'build/entry-points.cc',
|
||||
'build/goal.cc',
|
||||
@@ -242,7 +241,6 @@ libstore_headers = files(
|
||||
# keep-sorted start
|
||||
'binary-cache-store.hh',
|
||||
'build-result.hh',
|
||||
'build/child.hh',
|
||||
'build/derivation-goal.hh',
|
||||
'build/goal.hh',
|
||||
'build/hook-instance.hh',
|
||||
|
||||
Reference in New Issue
Block a user