Merge pull request #10550 from obsidiansystems/less-cli-unix-only

Make a few commands that were Unix-only no longer
This commit is contained in:
John Ericson 2024-04-17 17:22:06 -04:00 committed by GitHub
commit c16fc2c1bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 21 additions and 13 deletions

View file

@ -1,18 +1,15 @@
#include "personality.hh" #include "personality.hh"
#include "globals.hh" #include "globals.hh"
#if __linux__
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/personality.h> #include <sys/personality.h>
#endif
#include <cstring> #include <cstring>
namespace nix { namespace nix::linux {
void setPersonality(std::string_view system) void setPersonality(std::string_view system)
{ {
#if __linux__
/* Change the personality to 32-bit if we're doing an /* Change the personality to 32-bit if we're doing an
i686-linux build on an x86_64-linux machine. */ i686-linux build on an x86_64-linux machine. */
struct utsname utsbuf; struct utsname utsbuf;
@ -39,7 +36,6 @@ void setPersonality(std::string_view system)
determinism. */ determinism. */
int cur = personality(0xffffffff); int cur = personality(0xffffffff);
if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE); if (cur != -1) personality(cur | ADDR_NO_RANDOMIZE);
#endif
} }
} }

View file

@ -3,7 +3,7 @@
#include <string> #include <string>
namespace nix { namespace nix::linux {
void setPersonality(std::string_view system); void setPersonality(std::string_view system);

View file

@ -8,6 +8,9 @@ libstore_SOURCES := $(wildcard $(d)/*.cc $(d)/builtins/*.cc)
ifdef HOST_UNIX ifdef HOST_UNIX
libstore_SOURCES += $(wildcard $(d)/unix/*.cc $(d)/unix/builtins/*.cc $(d)/unix/build/*.cc) libstore_SOURCES += $(wildcard $(d)/unix/*.cc $(d)/unix/builtins/*.cc $(d)/unix/build/*.cc)
endif endif
ifdef HOST_LINUX
libstore_SOURCES += $(wildcard $(d)/linux/*.cc)
endif
ifdef HOST_WINDOWS ifdef HOST_WINDOWS
libstore_SOURCES += $(wildcard $(d)/windows/*.cc) libstore_SOURCES += $(wildcard $(d)/windows/*.cc)
endif endif
@ -39,6 +42,9 @@ INCLUDE_libstore := -I $(d) -I $(d)/build
ifdef HOST_UNIX ifdef HOST_UNIX
INCLUDE_libstore += -I $(d)/unix INCLUDE_libstore += -I $(d)/unix
endif endif
ifdef HOST_LINUX
INCLUDE_libstore += -I $(d)/linux
endif
ifdef HOST_WINDOWS ifdef HOST_WINDOWS
INCLUDE_libstore += -I $(d)/windows INCLUDE_libstore += -I $(d)/windows
endif endif

View file

@ -14,7 +14,6 @@
#include "topo-sort.hh" #include "topo-sort.hh"
#include "callback.hh" #include "callback.hh"
#include "json-utils.hh" #include "json-utils.hh"
#include "personality.hh"
#include "current-process.hh" #include "current-process.hh"
#include "child.hh" #include "child.hh"
#include "unix-domain-socket.hh" #include "unix-domain-socket.hh"
@ -52,6 +51,7 @@
# endif # endif
# define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old)) # define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old))
# include "cgroup.hh" # include "cgroup.hh"
# include "personality.hh"
#endif #endif
#if __APPLE__ #if __APPLE__
@ -1957,7 +1957,9 @@ void LocalDerivationGoal::runChild()
/* Close all other file descriptors. */ /* Close all other file descriptors. */
closeMostFDs({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}); closeMostFDs({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO});
setPersonality(drv->platform); #if __linux__
linux::setPersonality(drv->platform);
#endif
/* Disable core dumps by default. */ /* Disable core dumps by default. */
struct rlimit limit = { 0, RLIM_INFINITY }; struct rlimit limit = { 0, RLIM_INFINITY };

View file

@ -5,15 +5,15 @@
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
#include "derivations.hh" #include "derivations.hh"
#include "local-store.hh" #include "local-fs-store.hh"
#include "finally.hh" #include "finally.hh"
#include "source-accessor.hh" #include "source-accessor.hh"
#include "progress-bar.hh" #include "progress-bar.hh"
#include "eval.hh" #include "eval.hh"
#include "build/personality.hh"
#if __linux__ #if __linux__
#include <sys/mount.h> # include <sys/mount.h>
# include "personality.hh"
#endif #endif
#include <queue> #include <queue>
@ -56,8 +56,10 @@ void runProgramInStore(ref<Store> store,
throw SysError("could not execute chroot helper"); throw SysError("could not execute chroot helper");
} }
#if __linux__
if (system) if (system)
setPersonality(*system); linux::setPersonality(*system);
#endif
if (useSearchPath == UseSearchPath::Use) if (useSearchPath == UseSearchPath::Use)
execvp(program.c_str(), stringsToCharPtrs(args).data()); 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/uid_map", fmt("%d %d %d", uid, uid, 1));
writeFile("/proc/self/gid_map", fmt("%d %d %d", gid, gid, 1)); writeFile("/proc/self/gid_map", fmt("%d %d %d", gid, gid, 1));
#if __linux__
if (system != "") if (system != "")
setPersonality(system); linux::setPersonality(system);
#endif
execvp(cmd.c_str(), stringsToCharPtrs(args).data()); execvp(cmd.c_str(), stringsToCharPtrs(args).data());