mirror of
https://github.com/NixOS/nix
synced 2025-06-25 10:41:16 +02:00
Fix more -Wundef, in darwin context
This commit is contained in:
parent
bd2d5b7335
commit
615344fdf0
17 changed files with 56 additions and 56 deletions
|
@ -14,7 +14,7 @@ int main (int argc, char **argv) {
|
||||||
// Disable build hook. We won't be testing remote builds in these unit tests. If we do, fix the above build hook.
|
// Disable build hook. We won't be testing remote builds in these unit tests. If we do, fix the above build hook.
|
||||||
settings.buildHook = {};
|
settings.buildHook = {};
|
||||||
|
|
||||||
#if __linux__ // should match the conditional around sandboxBuildDir declaration.
|
#ifdef __linux__ // should match the conditional around sandboxBuildDir declaration.
|
||||||
|
|
||||||
// When building and testing nix within the host's Nix sandbox, our store dir will be located in the host's sandboxBuildDir, e.g.:
|
// When building and testing nix within the host's Nix sandbox, our store dir will be located in the host's sandboxBuildDir, e.g.:
|
||||||
// Host
|
// Host
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <aws/core/client/ClientConfiguration.h>
|
#include <aws/core/client/ClientConfiguration.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include "nix/util/namespaces.hh"
|
# include "nix/util/namespaces.hh"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -622,7 +622,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
try {
|
try {
|
||||||
tryUnshareFilesystem();
|
tryUnshareFilesystem();
|
||||||
} catch (nix::Error & e) {
|
} catch (nix::Error & e) {
|
||||||
|
|
|
@ -335,7 +335,7 @@ static std::string quoteRegexChars(const std::string & raw)
|
||||||
return std::regex_replace(raw, specialRegex, R"(\$&)");
|
return std::regex_replace(raw, specialRegex, R"(\$&)");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & roots)
|
static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & roots)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -427,7 +427,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
readFileRoots("/proc/sys/kernel/modprobe", unchecked);
|
readFileRoots("/proc/sys/kernel/modprobe", unchecked);
|
||||||
readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
|
readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
|
||||||
readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);
|
readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);
|
||||||
|
|
|
@ -181,11 +181,11 @@ StringSet Settings::getDefaultSystemFeatures()
|
||||||
actually require anything special on the machines. */
|
actually require anything special on the machines. */
|
||||||
StringSet features{"nixos-test", "benchmark", "big-parallel"};
|
StringSet features{"nixos-test", "benchmark", "big-parallel"};
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
features.insert("uid-range");
|
features.insert("uid-range");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (access("/dev/kvm", R_OK | W_OK) == 0)
|
if (access("/dev/kvm", R_OK | W_OK) == 0)
|
||||||
features.insert("kvm");
|
features.insert("kvm");
|
||||||
#endif
|
#endif
|
||||||
|
@ -205,7 +205,7 @@ StringSet Settings::getDefaultExtraPlatforms()
|
||||||
if (std::string{NIX_LOCAL_SYSTEM} == "x86_64-linux" && !isWSL1())
|
if (std::string{NIX_LOCAL_SYSTEM} == "x86_64-linux" && !isWSL1())
|
||||||
extraPlatforms.insert("i686-linux");
|
extraPlatforms.insert("i686-linux");
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
StringSet levels = computeLevels();
|
StringSet levels = computeLevels();
|
||||||
for (auto iter = levels.begin(); iter != levels.end(); ++iter)
|
for (auto iter = levels.begin(); iter != levels.end(); ++iter)
|
||||||
extraPlatforms.insert(*iter + "-linux");
|
extraPlatforms.insert(*iter + "-linux");
|
||||||
|
@ -224,7 +224,7 @@ StringSet Settings::getDefaultExtraPlatforms()
|
||||||
|
|
||||||
bool Settings::isWSL1()
|
bool Settings::isWSL1()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
struct utsname utsbuf;
|
struct utsname utsbuf;
|
||||||
uname(&utsbuf);
|
uname(&utsbuf);
|
||||||
// WSL1 uses -Microsoft suffix
|
// WSL1 uses -Microsoft suffix
|
||||||
|
|
|
@ -34,7 +34,7 @@ struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t maxIdsPerBuild =
|
const uint32_t maxIdsPerBuild =
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
1 << 16
|
1 << 16
|
||||||
#else
|
#else
|
||||||
1
|
1
|
||||||
|
@ -467,7 +467,7 @@ public:
|
||||||
)", {}, true, Xp::AutoAllocateUids};
|
)", {}, true, Xp::AutoAllocateUids};
|
||||||
|
|
||||||
Setting<uint32_t> startId{this,
|
Setting<uint32_t> startId{this,
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
0x34000000,
|
0x34000000,
|
||||||
#else
|
#else
|
||||||
56930,
|
56930,
|
||||||
|
@ -476,7 +476,7 @@ public:
|
||||||
"The first UID and GID to use for dynamic ID allocation."};
|
"The first UID and GID to use for dynamic ID allocation."};
|
||||||
|
|
||||||
Setting<uint32_t> uidCount{this,
|
Setting<uint32_t> uidCount{this,
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
maxIdsPerBuild * 128,
|
maxIdsPerBuild * 128,
|
||||||
#else
|
#else
|
||||||
128,
|
128,
|
||||||
|
@ -484,7 +484,7 @@ public:
|
||||||
"id-count",
|
"id-count",
|
||||||
"The number of UIDs/GIDs to use for dynamic ID allocation."};
|
"The number of UIDs/GIDs to use for dynamic ID allocation."};
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
Setting<bool> useCgroups{
|
Setting<bool> useCgroups{
|
||||||
this, false, "use-cgroups",
|
this, false, "use-cgroups",
|
||||||
R"(
|
R"(
|
||||||
|
@ -596,7 +596,7 @@ public:
|
||||||
|
|
||||||
Setting<SandboxMode> sandboxMode{
|
Setting<SandboxMode> sandboxMode{
|
||||||
this,
|
this,
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
smEnabled
|
smEnabled
|
||||||
#else
|
#else
|
||||||
smDisabled
|
smDisabled
|
||||||
|
@ -671,7 +671,7 @@ public:
|
||||||
)"};
|
)"};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
Setting<std::string> sandboxShmSize{
|
Setting<std::string> sandboxShmSize{
|
||||||
this, "50%", "sandbox-dev-shm-size",
|
this, "50%", "sandbox-dev-shm-size",
|
||||||
R"(
|
R"(
|
||||||
|
@ -1066,7 +1066,7 @@ public:
|
||||||
// Don't document the machine-specific default value
|
// Don't document the machine-specific default value
|
||||||
false};
|
false};
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
Setting<bool> filterSyscalls{
|
Setting<bool> filterSyscalls{
|
||||||
this, true, "filter-syscalls",
|
this, true, "filter-syscalls",
|
||||||
R"(
|
R"(
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
# include <grp.h>
|
# include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
# include <sys/statvfs.h>
|
# include <sys/statvfs.h>
|
||||||
# include <sys/mount.h>
|
# include <sys/mount.h>
|
||||||
|
@ -575,7 +575,7 @@ void LocalStore::upgradeDBSchema(State & state)
|
||||||
bind mount. So make the Nix store writable for this process. */
|
bind mount. So make the Nix store writable for this process. */
|
||||||
void LocalStore::makeStoreWritable()
|
void LocalStore::makeStoreWritable()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (!isRootUser()) return;
|
if (!isRootUser()) return;
|
||||||
/* Check if /nix/store is on a read-only mount. */
|
/* Check if /nix/store is on a read-only mount. */
|
||||||
struct statvfs stat;
|
struct statvfs stat;
|
||||||
|
|
|
@ -1300,7 +1300,7 @@ ref<Store> openStore(StoreReference && storeURI)
|
||||||
return std::make_shared<LocalStore>(params);
|
return std::make_shared<LocalStore>(params);
|
||||||
else if (pathExists(settings.nixDaemonSocketFile))
|
else if (pathExists(settings.nixDaemonSocketFile))
|
||||||
return std::make_shared<UDSRemoteStore>(params);
|
return std::make_shared<UDSRemoteStore>(params);
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
else if (!pathExists(stateDir)
|
else if (!pathExists(stateDir)
|
||||||
&& params.empty()
|
&& params.empty()
|
||||||
&& !isRootUser()
|
&& !isRootUser()
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes required for chroot support. */
|
/* Includes required for chroot support. */
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include "nix/store/fchmodat2-compat.hh"
|
# include "nix/store/fchmodat2-compat.hh"
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
# include <net/if.h>
|
# include <net/if.h>
|
||||||
|
@ -129,7 +129,7 @@ LocalDerivationGoal::~LocalDerivationGoal()
|
||||||
|
|
||||||
inline bool LocalDerivationGoal::needsHashRewrite()
|
inline bool LocalDerivationGoal::needsHashRewrite()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
return !useChroot;
|
return !useChroot;
|
||||||
#else
|
#else
|
||||||
/* Darwin requires hash rewriting even when sandboxing is enabled. */
|
/* Darwin requires hash rewriting even when sandboxing is enabled. */
|
||||||
|
@ -170,7 +170,7 @@ void LocalDerivationGoal::killChild()
|
||||||
void LocalDerivationGoal::killSandbox(bool getStats)
|
void LocalDerivationGoal::killSandbox(bool getStats)
|
||||||
{
|
{
|
||||||
if (cgroup) {
|
if (cgroup) {
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
auto stats = destroyCgroup(*cgroup);
|
auto stats = destroyCgroup(*cgroup);
|
||||||
if (getStats) {
|
if (getStats) {
|
||||||
buildResult.cpuUser = stats.cpuUser;
|
buildResult.cpuUser = stats.cpuUser;
|
||||||
|
@ -222,14 +222,14 @@ Goal::Co LocalDerivationGoal::tryLocalBuild()
|
||||||
|
|
||||||
auto & localStore = getLocalStore();
|
auto & localStore = getLocalStore();
|
||||||
if (localStore.storeDir != localStore.realStoreDir.get()) {
|
if (localStore.storeDir != localStore.realStoreDir.get()) {
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
useChroot = true;
|
useChroot = true;
|
||||||
#else
|
#else
|
||||||
throw Error("building using a diverted store is not supported on this platform");
|
throw Error("building using a diverted store is not supported on this platform");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (useChroot) {
|
if (useChroot) {
|
||||||
if (!mountAndPidNamespacesSupported()) {
|
if (!mountAndPidNamespacesSupported()) {
|
||||||
if (!settings.sandboxFallback)
|
if (!settings.sandboxFallback)
|
||||||
|
@ -405,7 +405,7 @@ void LocalDerivationGoal::cleanupPostOutputsRegisteredModeNonCheck()
|
||||||
cleanupPostOutputsRegisteredModeCheck();
|
cleanupPostOutputsRegisteredModeCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
static void doBind(const Path & source, const Path & target, bool optional = false) {
|
static void doBind(const Path & source, const Path & target, bool optional = false) {
|
||||||
debug("bind mounting '%1%' to '%2%'", source, target);
|
debug("bind mounting '%1%' to '%2%'", source, target);
|
||||||
|
|
||||||
|
@ -478,12 +478,12 @@ static void handleChildException(bool sendException)
|
||||||
void LocalDerivationGoal::startBuilder()
|
void LocalDerivationGoal::startBuilder()
|
||||||
{
|
{
|
||||||
if ((buildUser && buildUser->getUIDCount() != 1)
|
if ((buildUser && buildUser->getUIDCount() != 1)
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
|| settings.useCgroups
|
|| settings.useCgroups
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
experimentalFeatureSettings.require(Xp::Cgroups);
|
experimentalFeatureSettings.require(Xp::Cgroups);
|
||||||
|
|
||||||
/* If we're running from the daemon, then this will return the
|
/* If we're running from the daemon, then this will return the
|
||||||
|
@ -729,7 +729,7 @@ void LocalDerivationGoal::startBuilder()
|
||||||
pathsInChroot[i] = {i, true};
|
pathsInChroot[i] = {i, true};
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
/* Create a temporary directory in which we set up the chroot
|
/* Create a temporary directory in which we set up the chroot
|
||||||
environment using bind-mounts. We put it in the Nix store
|
environment using bind-mounts. We put it in the Nix store
|
||||||
so that the build outputs can be moved efficiently from the
|
so that the build outputs can be moved efficiently from the
|
||||||
|
@ -943,7 +943,7 @@ void LocalDerivationGoal::startBuilder()
|
||||||
|
|
||||||
/* Fork a child to build the package. */
|
/* Fork a child to build the package. */
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (useChroot) {
|
if (useChroot) {
|
||||||
/* Set up private namespaces for the build:
|
/* Set up private namespaces for the build:
|
||||||
|
|
||||||
|
@ -1143,7 +1143,7 @@ void LocalDerivationGoal::initTmpDir()
|
||||||
{
|
{
|
||||||
/* In a sandbox, for determinism, always use the same temporary
|
/* In a sandbox, for determinism, always use the same temporary
|
||||||
directory. */
|
directory. */
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
|
tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
|
||||||
#else
|
#else
|
||||||
tmpDirInSandbox = tmpDir;
|
tmpDirInSandbox = tmpDir;
|
||||||
|
@ -1646,7 +1646,7 @@ void LocalDerivationGoal::addDependency(const StorePath & path)
|
||||||
|
|
||||||
debug("materialising '%s' in the sandbox", worker.store.printStorePath(path));
|
debug("materialising '%s' in the sandbox", worker.store.printStorePath(path));
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
Path source = worker.store.Store::toRealPath(path);
|
Path source = worker.store.Store::toRealPath(path);
|
||||||
Path target = chrootRootDir + worker.store.printStorePath(path);
|
Path target = chrootRootDir + worker.store.printStorePath(path);
|
||||||
|
@ -1696,7 +1696,7 @@ void LocalDerivationGoal::chownToBuilder(const Path & path)
|
||||||
|
|
||||||
void setupSeccomp()
|
void setupSeccomp()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (!settings.filterSyscalls) return;
|
if (!settings.filterSyscalls) return;
|
||||||
#if HAVE_SECCOMP
|
#if HAVE_SECCOMP
|
||||||
scmp_filter_ctx ctx;
|
scmp_filter_ctx ctx;
|
||||||
|
@ -1816,7 +1816,7 @@ void LocalDerivationGoal::runChild()
|
||||||
} catch (SystemError &) { }
|
} catch (SystemError &) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (useChroot) {
|
if (useChroot) {
|
||||||
|
|
||||||
userNamespaceSync.writeSide = -1;
|
userNamespaceSync.writeSide = -1;
|
||||||
|
@ -2050,7 +2050,7 @@ void LocalDerivationGoal::runChild()
|
||||||
/* Close all other file descriptors. */
|
/* Close all other file descriptors. */
|
||||||
unix::closeExtraFDs();
|
unix::closeExtraFDs();
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
linux::setPersonality(drv->platform);
|
linux::setPersonality(drv->platform);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
static std::vector<gid_t> get_group_list(const char *username, gid_t group_id)
|
static std::vector<gid_t> get_group_list(const char *username, gid_t group_id)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ struct SimpleUserLock : UserLock
|
||||||
if (lock->uid == getuid() || lock->uid == geteuid())
|
if (lock->uid == getuid() || lock->uid == geteuid())
|
||||||
throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup);
|
throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup);
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
/* Get the list of supplementary groups of this user. This is
|
/* Get the list of supplementary groups of this user. This is
|
||||||
* usually either empty or contains a group such as "kvm". */
|
* usually either empty or contains a group such as "kvm". */
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds, bool useUserNamespace)
|
||||||
|
|
||||||
bool useBuildUsers()
|
bool useBuildUsers()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser();
|
static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser();
|
||||||
return b;
|
return b;
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
# include <mach-o/dyld.h>
|
# include <mach-o/dyld.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include <mutex>
|
# include <mutex>
|
||||||
# include "nix/util/cgroup.hh"
|
# include "nix/util/cgroup.hh"
|
||||||
# include "nix/util/namespaces.hh"
|
# include "nix/util/namespaces.hh"
|
||||||
|
@ -23,7 +23,7 @@ namespace nix {
|
||||||
|
|
||||||
unsigned int getMaxCPU()
|
unsigned int getMaxCPU()
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
try {
|
try {
|
||||||
auto cgroupFS = getCgroupFS();
|
auto cgroupFS = getCgroupFS();
|
||||||
if (!cgroupFS) return 0;
|
if (!cgroupFS) return 0;
|
||||||
|
@ -82,7 +82,7 @@ void restoreProcessContext(bool restoreMounts)
|
||||||
unix::restoreSignals();
|
unix::restoreSignals();
|
||||||
#endif
|
#endif
|
||||||
if (restoreMounts) {
|
if (restoreMounts) {
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
restoreMountNamespace();
|
restoreMountNamespace();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ std::optional<Path> getSelfExe()
|
||||||
{
|
{
|
||||||
static auto cached = []() -> std::optional<Path>
|
static auto cached = []() -> std::optional<Path>
|
||||||
{
|
{
|
||||||
#if __linux__ || __GNU__
|
#if defined(__linux__) || defined(__GNU__)
|
||||||
return readLink("/proc/self/exe");
|
return readLink("/proc/self/exe");
|
||||||
#elif __APPLE__
|
#elif __APPLE__
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
|
@ -113,7 +113,7 @@ void AutoCloseFD::fsync() const
|
||||||
|
|
||||||
void AutoCloseFD::startFsync() const
|
void AutoCloseFD::startFsync() const
|
||||||
{
|
{
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
/* Ignore failure, since fsync must be run later anyway. This is just a performance optimization. */
|
/* Ignore failure, since fsync must be run later anyway. This is just a performance optimization. */
|
||||||
::sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE);
|
::sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE);
|
||||||
|
|
|
@ -163,7 +163,7 @@ void Pipe::create()
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if __linux__ || __FreeBSD__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
static int unix_close_range(unsigned int first, unsigned int last, int flags)
|
static int unix_close_range(unsigned int first, unsigned int last, int flags)
|
||||||
{
|
{
|
||||||
#if !HAVE_CLOSE_RANGE
|
#if !HAVE_CLOSE_RANGE
|
||||||
|
@ -179,7 +179,7 @@ void unix::closeExtraFDs()
|
||||||
constexpr int MAX_KEPT_FD = 2;
|
constexpr int MAX_KEPT_FD = 2;
|
||||||
static_assert(std::max({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) == MAX_KEPT_FD);
|
static_assert(std::max({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) == MAX_KEPT_FD);
|
||||||
|
|
||||||
#if __linux__ || __FreeBSD__
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
// first try to close_range everything we don't care about. if this
|
// first try to close_range everything we don't care about. if this
|
||||||
// returns an error with these parameters we're running on a kernel
|
// returns an error with these parameters we're running on a kernel
|
||||||
// that does not implement close_range (i.e. pre 5.9) and fall back
|
// that does not implement close_range (i.e. pre 5.9) and fall back
|
||||||
|
@ -189,7 +189,7 @@ void unix::closeExtraFDs()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
try {
|
try {
|
||||||
for (auto & s : std::filesystem::directory_iterator{"/proc/self/fd"}) {
|
for (auto & s : std::filesystem::directory_iterator{"/proc/self/fd"}) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
|
@ -190,7 +190,7 @@ static pid_t doFork(bool allowVfork, ChildWrapperFunction & fun)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
static int childEntry(void * arg)
|
static int childEntry(void * arg)
|
||||||
{
|
{
|
||||||
auto & fun = *reinterpret_cast<ChildWrapperFunction*>(arg);
|
auto & fun = *reinterpret_cast<ChildWrapperFunction*>(arg);
|
||||||
|
@ -213,7 +213,7 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
|
||||||
logger = makeSimpleLogger();
|
logger = makeSimpleLogger();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
|
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
|
||||||
throw SysError("setting death signal");
|
throw SysError("setting death signal");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -105,7 +105,7 @@ void unix::setChildSignalMask(sigset_t * sigs)
|
||||||
{
|
{
|
||||||
assert(sigs); // C style function, but think of sigs as a reference
|
assert(sigs); // C style function, but think of sigs as a reference
|
||||||
|
|
||||||
#if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
|
#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE) || (defined(_POSIX_SOURCE) && _POSIX_SOURCE)
|
||||||
sigemptyset(&savedSignalMask);
|
sigemptyset(&savedSignalMask);
|
||||||
// There's no "assign" or "copy" function, so we rely on (math) idempotence
|
// There's no "assign" or "copy" function, so we rely on (math) idempotence
|
||||||
// of the or operator: a or a = a.
|
// of the or operator: a or a = a.
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
# include <netinet/in.h>
|
# include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include "nix/util/namespaces.hh"
|
# include "nix/util/namespaces.hh"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ void mainWrapped(int argc, char * * argv)
|
||||||
"__build-remote",
|
"__build-remote",
|
||||||
});
|
});
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (isRootUser()) {
|
if (isRootUser()) {
|
||||||
try {
|
try {
|
||||||
saveMountNamespace();
|
saveMountNamespace();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "nix/expr/eval.hh"
|
#include "nix/expr/eval.hh"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
# include <sys/mount.h>
|
# include <sys/mount.h>
|
||||||
# include "nix/store/personality.hh"
|
# include "nix/store/personality.hh"
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,7 +59,7 @@ void execProgramInStore(ref<Store> store,
|
||||||
throw SysError("could not execute chroot helper");
|
throw SysError("could not execute chroot helper");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (system)
|
if (system)
|
||||||
linux::setPersonality(*system);
|
linux::setPersonality(*system);
|
||||||
#endif
|
#endif
|
||||||
|
@ -153,7 +153,7 @@ void chrootHelper(int argc, char * * argv)
|
||||||
while (p < argc)
|
while (p < argc)
|
||||||
args.push_back(argv[p++]);
|
args.push_back(argv[p++]);
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
uid_t gid = getgid();
|
uid_t gid = getgid();
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ void chrootHelper(int argc, char * * argv)
|
||||||
writeFile(fs::path{"/proc/self/uid_map"}, fmt("%d %d %d", uid, uid, 1));
|
writeFile(fs::path{"/proc/self/uid_map"}, fmt("%d %d %d", uid, uid, 1));
|
||||||
writeFile(fs::path{"/proc/self/gid_map"}, fmt("%d %d %d", gid, gid, 1));
|
writeFile(fs::path{"/proc/self/gid_map"}, fmt("%d %d %d", gid, gid, 1));
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (system != "")
|
if (system != "")
|
||||||
linux::setPersonality(system);
|
linux::setPersonality(system);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
#include "nix/util/cgroup.hh"
|
#include "nix/util/cgroup.hh"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ static void daemonLoop(std::optional<TrustedFlag> forceTrustClientOpt)
|
||||||
// Get rid of children automatically; don't let them become zombies.
|
// Get rid of children automatically; don't let them become zombies.
|
||||||
setSigChldAction(true);
|
setSigChldAction(true);
|
||||||
|
|
||||||
#if __linux__
|
#ifdef __linux__
|
||||||
if (settings.useCgroups) {
|
if (settings.useCgroups) {
|
||||||
experimentalFeatureSettings.require(Xp::Cgroups);
|
experimentalFeatureSettings.require(Xp::Cgroups);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue