From 6fa3656a3286d3e73a54277965a1b1ae8d34300d Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 17 Apr 2024 16:20:56 -0400 Subject: [PATCH] Make a few commands that were Unix-only no longer Also clean up some more linux-specific (`setPersonality`) code in alignment with recent best practices. --- src/libstore/{unix/build => linux}/personality.cc | 6 +----- src/libstore/{unix/build => linux}/personality.hh | 2 +- src/libstore/local.mk | 6 ++++++ src/libstore/unix/build/local-derivation-goal.cc | 6 ++++-- src/nix/{unix => }/fmt.cc | 0 src/nix/{unix => }/fmt.md | 0 src/nix/{unix => }/run.cc | 14 +++++++++----- src/nix/{unix => }/run.hh | 0 src/nix/{unix => }/run.md | 0 src/nix/{unix => }/upgrade-nix.cc | 0 src/nix/{unix => }/upgrade-nix.md | 0 11 files changed, 21 insertions(+), 13 deletions(-) rename src/libstore/{unix/build => linux}/personality.cc (95%) rename src/libstore/{unix/build => linux}/personality.hh (80%) rename src/nix/{unix => }/fmt.cc (100%) rename src/nix/{unix => }/fmt.md (100%) rename src/nix/{unix => }/run.cc (97%) rename src/nix/{unix => }/run.hh (100%) rename src/nix/{unix => }/run.md (100%) rename src/nix/{unix => }/upgrade-nix.cc (100%) rename src/nix/{unix => }/upgrade-nix.md (100%) diff --git a/src/libstore/unix/build/personality.cc b/src/libstore/linux/personality.cc similarity index 95% rename from src/libstore/unix/build/personality.cc rename to src/libstore/linux/personality.cc index 1a6201758..255d174a6 100644 --- a/src/libstore/unix/build/personality.cc +++ b/src/libstore/linux/personality.cc @@ -1,18 +1,15 @@ #include "personality.hh" #include "globals.hh" -#if __linux__ #include #include -#endif #include -namespace nix { +namespace nix::linux { void setPersonality(std::string_view system) { -#if __linux__ /* Change the personality to 32-bit if we're doing an i686-linux build on an x86_64-linux machine. */ struct utsname utsbuf; @@ -39,7 +36,6 @@ void setPersonality(std::string_view system) determinism. */ int cur = personality(0xffffffff); if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE); -#endif } } diff --git a/src/libstore/unix/build/personality.hh b/src/libstore/linux/personality.hh similarity index 80% rename from src/libstore/unix/build/personality.hh rename to src/libstore/linux/personality.hh index 91b730fab..6a6376f8f 100644 --- a/src/libstore/unix/build/personality.hh +++ b/src/libstore/linux/personality.hh @@ -3,7 +3,7 @@ #include -namespace nix { +namespace nix::linux { void setPersonality(std::string_view system); diff --git a/src/libstore/local.mk b/src/libstore/local.mk index 6be748581..2e118f6cb 100644 --- a/src/libstore/local.mk +++ b/src/libstore/local.mk @@ -8,6 +8,9 @@ libstore_SOURCES := $(wildcard $(d)/*.cc $(d)/builtins/*.cc) ifdef HOST_UNIX libstore_SOURCES += $(wildcard $(d)/unix/*.cc $(d)/unix/builtins/*.cc $(d)/unix/build/*.cc) endif +ifdef HOST_LINUX + libstore_SOURCES += $(wildcard $(d)/linux/*.cc) +endif ifdef HOST_WINDOWS libstore_SOURCES += $(wildcard $(d)/windows/*.cc) endif @@ -39,6 +42,9 @@ INCLUDE_libstore := -I $(d) -I $(d)/build ifdef HOST_UNIX INCLUDE_libstore += -I $(d)/unix endif +ifdef HOST_LINUX + INCLUDE_libstore += -I $(d)/linux +endif ifdef HOST_WINDOWS INCLUDE_libstore += -I $(d)/windows endif diff --git a/src/libstore/unix/build/local-derivation-goal.cc b/src/libstore/unix/build/local-derivation-goal.cc index 99a91a7f1..33208a622 100644 --- a/src/libstore/unix/build/local-derivation-goal.cc +++ b/src/libstore/unix/build/local-derivation-goal.cc @@ -14,7 +14,6 @@ #include "topo-sort.hh" #include "callback.hh" #include "json-utils.hh" -#include "personality.hh" #include "current-process.hh" #include "child.hh" #include "unix-domain-socket.hh" @@ -52,6 +51,7 @@ # endif # define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old)) # include "cgroup.hh" +# include "personality.hh" #endif #if __APPLE__ @@ -1957,7 +1957,9 @@ void LocalDerivationGoal::runChild() /* Close all other file descriptors. */ closeMostFDs({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}); - setPersonality(drv->platform); +#if __linux__ + linux::setPersonality(drv->platform); +#endif /* Disable core dumps by default. */ struct rlimit limit = { 0, RLIM_INFINITY }; diff --git a/src/nix/unix/fmt.cc b/src/nix/fmt.cc similarity index 100% rename from src/nix/unix/fmt.cc rename to src/nix/fmt.cc diff --git a/src/nix/unix/fmt.md b/src/nix/fmt.md similarity index 100% rename from src/nix/unix/fmt.md rename to src/nix/fmt.md diff --git a/src/nix/unix/run.cc b/src/nix/run.cc similarity index 97% rename from src/nix/unix/run.cc rename to src/nix/run.cc index dfd8b643c..c45683302 100644 --- a/src/nix/unix/run.cc +++ b/src/nix/run.cc @@ -5,15 +5,15 @@ #include "shared.hh" #include "store-api.hh" #include "derivations.hh" -#include "local-store.hh" +#include "local-fs-store.hh" #include "finally.hh" #include "source-accessor.hh" #include "progress-bar.hh" #include "eval.hh" -#include "build/personality.hh" #if __linux__ -#include +# include +# include "personality.hh" #endif #include @@ -56,8 +56,10 @@ void runProgramInStore(ref store, throw SysError("could not execute chroot helper"); } +#if __linux__ if (system) - setPersonality(*system); + linux::setPersonality(*system); +#endif if (useSearchPath == UseSearchPath::Use) execvp(program.c_str(), stringsToCharPtrs(args).data()); @@ -277,8 +279,10 @@ void chrootHelper(int argc, char * * argv) writeFile("/proc/self/uid_map", fmt("%d %d %d", uid, uid, 1)); writeFile("/proc/self/gid_map", fmt("%d %d %d", gid, gid, 1)); +#if __linux__ if (system != "") - setPersonality(system); + linux::setPersonality(system); +#endif execvp(cmd.c_str(), stringsToCharPtrs(args).data()); diff --git a/src/nix/unix/run.hh b/src/nix/run.hh similarity index 100% rename from src/nix/unix/run.hh rename to src/nix/run.hh diff --git a/src/nix/unix/run.md b/src/nix/run.md similarity index 100% rename from src/nix/unix/run.md rename to src/nix/run.md diff --git a/src/nix/unix/upgrade-nix.cc b/src/nix/upgrade-nix.cc similarity index 100% rename from src/nix/unix/upgrade-nix.cc rename to src/nix/upgrade-nix.cc diff --git a/src/nix/unix/upgrade-nix.md b/src/nix/upgrade-nix.md similarity index 100% rename from src/nix/unix/upgrade-nix.md rename to src/nix/upgrade-nix.md