libstore: make privateNetwork a function of LinuxLocalDerivationGoal
it's only used there, and this avoids using it uninitialized. Change-Id: I6bd84e3c441dc6750e8ab07822f896136586cd66
This commit is contained in:
@@ -71,11 +71,6 @@ struct LocalDerivationGoal : public DerivationGoal
|
||||
*/
|
||||
std::shared_ptr<AutoDelete> autoDelChroot;
|
||||
|
||||
/**
|
||||
* Whether to run the build in a private network namespace.
|
||||
*/
|
||||
bool privateNetwork = false;
|
||||
|
||||
/**
|
||||
* Stuff we need to pass to initChild().
|
||||
*/
|
||||
|
||||
@@ -932,7 +932,7 @@ bool LinuxLocalDerivationGoal::prepareChildSetup()
|
||||
|
||||
userNamespaceSync.readSide.reset();
|
||||
|
||||
if (privateNetwork) {
|
||||
if (privateNetwork()) {
|
||||
|
||||
/* Initialise the loopback interface. */
|
||||
AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));
|
||||
@@ -1299,12 +1299,9 @@ Pid LinuxLocalDerivationGoal::startChild(
|
||||
us.
|
||||
*/
|
||||
|
||||
if (derivationType->isSandboxed())
|
||||
privateNetwork = true;
|
||||
|
||||
// don't launch pasta unless we have a tun device. in a build sandbox we
|
||||
// commonly do not, and trying to run pasta anyway naturally won't work.
|
||||
runPasta = !privateNetwork && settings.pastaPath != "" && pathExists("/dev/net/tun");
|
||||
runPasta = !privateNetwork() && settings.pastaPath != "" && pathExists("/dev/net/tun");
|
||||
|
||||
userNamespaceSync.create();
|
||||
|
||||
@@ -1334,8 +1331,9 @@ Pid LinuxLocalDerivationGoal::startChild(
|
||||
options.cloneFlags = CLONE_NEWPID | CLONE_NEWNS | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_PARENT | SIGCHLD;
|
||||
// we always want to create a new network namespace for pasta, even when
|
||||
// we can't actually run it. not doing so hides bugs and impairs purity.
|
||||
if (settings.pastaPath != "" || privateNetwork)
|
||||
if (settings.pastaPath != "" || privateNetwork()) {
|
||||
options.cloneFlags |= CLONE_NEWNET;
|
||||
}
|
||||
if (worker.namespaces.user) {
|
||||
options.cloneFlags |= CLONE_NEWUSER;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,13 @@ private:
|
||||
* Pipe for synchronising updates to the builder namespaces.
|
||||
*/
|
||||
Pipe userNamespaceSync;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether to run the build in a private network namespace.
|
||||
*/
|
||||
bool privateNetwork() const
|
||||
{
|
||||
return derivationType.value().isSandboxed();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user