Skip to content

Commit

Permalink
Merge pull request #10364 from obsidiansystems/split-out-unix
Browse files Browse the repository at this point in the history
Start factoring out Unix-assuming code
  • Loading branch information
Ericson2314 authored Apr 2, 2024
2 parents 290be6c + 02fa206 commit 478c053
Show file tree
Hide file tree
Showing 43 changed files with 402 additions and 302 deletions.
5 changes: 5 additions & 0 deletions local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ ERROR_SWITCH_ENUM = -Werror=switch-enum
$(foreach i, config.h $(wildcard src/lib*/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix, 0644)))

ifdef HOST_UNIX
$(foreach i, $(wildcard src/lib*/unix/*.hh), \
$(eval $(call install-file-in, $(i), $(includedir)/nix, 0644)))
endif

$(GCH): src/libutil/util.hh config.h

GCH_CXXFLAGS = $(INCLUDE_libutil)
2 changes: 1 addition & 1 deletion src/libcmd/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ libcmd_DIR := $(d)

libcmd_SOURCES := $(wildcard $(d)/*.cc)

libcmd_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers) $(INCLUDE_libexpr) -I src/libmain
libcmd_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers) $(INCLUDE_libexpr) $(INCLUDE_libmain)

libcmd_LDFLAGS = $(EDITLINE_LIBS) $(LOWDOWN_LIBS) $(THREAD_LDFLAGS)

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libexpr_SOURCES := \

INCLUDE_libexpr := -I $(d)

libexpr_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers) -I src/libmain $(INCLUDE_libexpr)
libexpr_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers) $(INCLUDE_libmain) $(INCLUDE_libexpr)

libexpr_LIBS = libutil libstore libfetchers

Expand Down
6 changes: 6 additions & 0 deletions src/libfetchers/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ libfetchers_NAME = libnixfetchers
libfetchers_DIR := $(d)

libfetchers_SOURCES := $(wildcard $(d)/*.cc)
ifdef HOST_UNIX
libfetchers_SOURCES += $(wildcard $(d)/unix/*.cc)
endif

# Not just for this library itself, but also for downstream libraries using this library

INCLUDE_libfetchers := -I $(d)
ifdef HOST_UNIX
INCLUDE_libfetchers += -I $(d)/unix
endif

libfetchers_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libfetchers)

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion src/libmain/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ libmain_NAME = libnixmain
libmain_DIR := $(d)

libmain_SOURCES := $(wildcard $(d)/*.cc)
ifdef HOST_UNIX
libmain_SOURCES += $(wildcard $(d)/unix/*.cc)
endif

libmain_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore)
INCLUDE_libmain := -I $(d)

libmain_CXXFLAGS += $(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libmain)

libmain_LDFLAGS += $(OPENSSL_LIBS)

Expand Down
26 changes: 13 additions & 13 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "cgroup.hh"
#include "personality.hh"
#include "current-process.hh"
#include "namespaces.hh"
#include "child.hh"
#include "unix-domain-socket.hh"
#include "posix-fs-canonicalise.hh"
Expand All @@ -40,18 +39,19 @@

/* Includes required for chroot support. */
#if __linux__
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/ip.h>
#include <sys/mman.h>
#include <sched.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#if HAVE_SECCOMP
#include <seccomp.h>
#endif
#define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old))
# include <sys/ioctl.h>
# include <net/if.h>
# include <netinet/ip.h>
# include <sys/mman.h>
# include <sched.h>
# include <sys/param.h>
# include <sys/mount.h>
# include <sys/syscall.h>
# include "namespaces.hh"
# if HAVE_SECCOMP
# include <seccomp.h>
# endif
# define pivot_root(new_root, put_old) (syscall(SYS_pivot_root, new_root, put_old))
#endif

#if __APPLE__
Expand Down
7 changes: 6 additions & 1 deletion src/libstore/filetransfer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "filetransfer.hh"
#include "namespaces.hh"
#include "globals.hh"
#include "store-api.hh"
#include "s3.hh"
Expand All @@ -12,6 +11,10 @@
#include <aws/core/client/ClientConfiguration.h>
#endif

#if __linux__
# include "namespaces.hh"
#endif

#include <unistd.h>
#include <fcntl.h>

Expand Down Expand Up @@ -568,7 +571,9 @@ struct curlFileTransfer : public FileTransfer
stopWorkerThread();
});

#if __linux__
unshareFilesystem();
#endif

std::map<CURL *, std::shared_ptr<TransferItem>> items;

Expand Down
6 changes: 6 additions & 0 deletions src/libstore/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ libstore_NAME = libnixstore
libstore_DIR := $(d)

libstore_SOURCES := $(wildcard $(d)/*.cc $(d)/builtins/*.cc $(d)/build/*.cc)
ifdef HOST_UNIX
libstore_SOURCES += $(wildcard $(d)/unix/*.cc)
endif

libstore_LIBS = libutil

Expand All @@ -30,6 +33,9 @@ endif
# Not just for this library itself, but also for downstream libraries using this library

INCLUDE_libstore := -I $(d) -I $(d)/build
ifdef HOST_UNIX
INCLUDE_libstore += -I $(d)/unix
endif

libstore_CXXFLAGS += \
$(INCLUDE_libutil) $(INCLUDE_libstore) $(INCLUDE_libstore) \
Expand Down
4 changes: 3 additions & 1 deletion src/libutil/current-process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cstring>

#include "current-process.hh"
#include "namespaces.hh"
#include "util.hh"
#include "finally.hh"
#include "file-system.hh"
Expand All @@ -17,6 +16,7 @@
# include <mutex>
# include <sys/resource.h>
# include "cgroup.hh"
# include "namespaces.hh"
#endif

#include <sys/mount.h>
Expand Down Expand Up @@ -84,7 +84,9 @@ void restoreProcessContext(bool restoreMounts)
{
restoreSignals();
if (restoreMounts) {
#if __linux__
restoreMountNamespace();
#endif
}

if (savedStackSize) {
Expand Down
14 changes: 0 additions & 14 deletions src/libutil/environment-variables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,4 @@ std::map<std::string, std::string> getEnv()
return env;
}


void clearEnv()
{
for (auto & name : getEnv())
unsetenv(name.first.c_str());
}

void replaceEnv(const std::map<std::string, std::string> & newEnv)
{
clearEnv();
for (auto & newEnvVar : newEnv)
setenv(newEnvVar.first.c_str(), newEnvVar.second.c_str(), 1);
}

}
Loading

0 comments on commit 478c053

Please sign in to comment.