diff --git a/lix/libstore/build/child.cc b/lix/libstore/build/child.cc deleted file mode 100644 index d0b11add0..000000000 --- a/lix/libstore/build/child.cc +++ /dev/null @@ -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"); - } -} - -} diff --git a/lix/libstore/build/child.hh b/lix/libstore/build/child.hh deleted file mode 100644 index 3464865e8..000000000 --- a/lix/libstore/build/child.hh +++ /dev/null @@ -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(); - -} diff --git a/lix/libstore/build/hook-instance.cc b/lix/libstore/build/hook-instance.cc index e95b2d411..742cf5518 100644 --- a/lix/libstore/build/hook-instance.cc +++ b/lix/libstore/build/hook-instance.cc @@ -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" diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index d4a553e05..7f6bebcfb 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -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(); diff --git a/lix/libstore/meson.build b/lix/libstore/meson.build index fc5ce38d5..94eadf66c 100644 --- a/lix/libstore/meson.build +++ b/lix/libstore/meson.build @@ -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',