aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorjade <lix@jade.fyi>2024-05-30 02:33:05 +0000
committerGerrit Code Review <gerrit@lix-systems>2024-05-30 02:33:05 +0000
commit562ff516ab27b8e98490646dd30ac96e7e2c36bb (patch)
tree1798a20b33da0101bd91acf7da26c891f0cda620 /src/libstore
parentc71f21da3ac4d95ef9a42a26416ccee71639dbd6 (diff)
parenta39ba22ff7112cd3984bbf28d8610d84dd525a0f (diff)
Merge changes from topic "libutil-split" into main
* changes: util.hh: Delete remaining file and clean up headers util.hh: Move nativeSystem to local-derivation-goal.cc util.hh: Move stuff to types.hh util.cc: Delete remaining file util.{hh,cc}: Move ignoreException to error.{hh,cc} util.{hh,cc}: Split out namespaces.{hh,cc} util.{hh,cc}: Split out users.{hh,cc} util.{hh,cc}: Split out strings.{hh,cc} util.{hh,cc}: Split out unix-domain-socket.{hh,cc} util.{hh,cc}: Split out child.{hh,cc} util.{hh,cc}: Split out current-process.{hh,cc} util.{hh,cc}: Split out processes.{hh,cc} util.{hh,cc}: Split out file-descriptor.{hh,cc} util.{hh,cc}: Split out file-system.{hh,cc} util.{hh,cc}: Split out terminal.{hh,cc} util.{hh,cc}: Split out environment-variables.{hh,cc}
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/build/child.cc33
-rw-r--r--src/libstore/build/child.hh11
-rw-r--r--src/libstore/build/derivation-goal.cc1
-rw-r--r--src/libstore/build/hook-instance.cc2
-rw-r--r--src/libstore/build/hook-instance.hh1
-rw-r--r--src/libstore/build/local-derivation-goal.cc8
-rw-r--r--src/libstore/build/local-derivation-goal.hh1
-rw-r--r--src/libstore/common-protocol.cc3
-rw-r--r--src/libstore/crypto.cc3
-rw-r--r--src/libstore/crypto.hh2
-rw-r--r--src/libstore/derivations.cc1
-rw-r--r--src/libstore/derived-path.hh2
-rw-r--r--src/libstore/filetransfer.cc3
-rw-r--r--src/libstore/filetransfer.hh3
-rw-r--r--src/libstore/gc.cc8
-rw-r--r--src/libstore/globals.cc10
-rw-r--r--src/libstore/globals.hh2
-rw-r--r--src/libstore/local-store.hh2
-rw-r--r--src/libstore/lock.cc2
-rw-r--r--src/libstore/machines.cc2
-rw-r--r--src/libstore/meson.build2
-rw-r--r--src/libstore/names.cc2
-rw-r--r--src/libstore/nar-info-disk-cache.cc2
-rw-r--r--src/libstore/optimise-store.cc1
-rw-r--r--src/libstore/outputs-spec.cc2
-rw-r--r--src/libstore/path-references.cc4
-rw-r--r--src/libstore/pathlocks.cc4
-rw-r--r--src/libstore/pathlocks.hh2
-rw-r--r--src/libstore/profiles.cc2
-rw-r--r--src/libstore/remote-store.cc1
-rw-r--r--src/libstore/serve-protocol.cc2
-rw-r--r--src/libstore/sqlite.cc3
-rw-r--r--src/libstore/ssh.cc4
-rw-r--r--src/libstore/ssh.hh3
-rw-r--r--src/libstore/store-api.cc3
-rw-r--r--src/libstore/store-api.hh1
-rw-r--r--src/libstore/uds-remote-store.cc1
-rw-r--r--src/libstore/worker-protocol.cc1
38 files changed, 95 insertions, 45 deletions
diff --git a/src/libstore/build/child.cc b/src/libstore/build/child.cc
new file mode 100644
index 000000000..a82a5eec9
--- /dev/null
+++ b/src/libstore/build/child.cc
@@ -0,0 +1,33 @@
+#include "current-process.hh"
+#include "logging.hh"
+
+namespace nix {
+
+void commonChildInit()
+{
+ logger = makeSimpleLogger();
+
+ const static std::string pathNullDevice = "/dev/null";
+ restoreProcessContext(false);
+
+ /* Put the child in a separate session (and thus a separate
+ process group) so that it has no controlling terminal (meaning
+ that e.g. ssh cannot open /dev/tty) and it doesn't receive
+ terminal signals. */
+ if (setsid() == -1)
+ throw SysError("creating a new session");
+
+ /* Dup stderr to stdout. */
+ if (dup2(STDERR_FILENO, STDOUT_FILENO) == -1)
+ throw SysError("cannot dup stderr into stdout");
+
+ /* Reroute stdin to /dev/null. */
+ int fdDevNull = open(pathNullDevice.c_str(), O_RDWR);
+ if (fdDevNull == -1)
+ throw SysError("cannot open '%1%'", pathNullDevice);
+ if (dup2(fdDevNull, STDIN_FILENO) == -1)
+ throw SysError("cannot dup null device into stdin");
+ close(fdDevNull);
+}
+
+}
diff --git a/src/libstore/build/child.hh b/src/libstore/build/child.hh
new file mode 100644
index 000000000..3dfc552b9
--- /dev/null
+++ b/src/libstore/build/child.hh
@@ -0,0 +1,11 @@
+#pragma once
+///@file
+
+namespace nix {
+
+/**
+ * Common initialisation performed in child processes.
+ */
+void commonChildInit();
+
+}
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc
index 5fa5deb7c..97ba994ad 100644
--- a/src/libstore/build/derivation-goal.cc
+++ b/src/libstore/build/derivation-goal.cc
@@ -5,7 +5,6 @@
#include "builtins/buildenv.hh"
#include "references.hh"
#include "finally.hh"
-#include "util.hh"
#include "archive.hh"
#include "compression.hh"
#include "common-protocol.hh"
diff --git a/src/libstore/build/hook-instance.cc b/src/libstore/build/hook-instance.cc
index ea4c2e508..86f72486e 100644
--- a/src/libstore/build/hook-instance.cc
+++ b/src/libstore/build/hook-instance.cc
@@ -1,3 +1,5 @@
+#include "child.hh"
+#include "file-system.hh"
#include "globals.hh"
#include "hook-instance.hh"
diff --git a/src/libstore/build/hook-instance.hh b/src/libstore/build/hook-instance.hh
index d84f62877..481158296 100644
--- a/src/libstore/build/hook-instance.hh
+++ b/src/libstore/build/hook-instance.hh
@@ -2,6 +2,7 @@
///@file
#include "logging.hh"
+#include "processes.hh"
#include "serialise.hh"
namespace nix {
diff --git a/src/libstore/build/local-derivation-goal.cc b/src/libstore/build/local-derivation-goal.cc
index 9be780212..479b4ffeb 100644
--- a/src/libstore/build/local-derivation-goal.cc
+++ b/src/libstore/build/local-derivation-goal.cc
@@ -6,7 +6,6 @@
#include "builtins/buildenv.hh"
#include "path-references.hh"
#include "finally.hh"
-#include "util.hh"
#include "archive.hh"
#include "compression.hh"
#include "daemon.hh"
@@ -15,6 +14,8 @@
#include "cgroup.hh"
#include "personality.hh"
#include "namespaces.hh"
+#include "child.hh"
+#include "unix-domain-socket.hh"
#include <regex>
#include <queue>
@@ -63,6 +64,11 @@ extern "C" int sandbox_init_with_parameters(const char *profile, uint64_t flags,
namespace nix {
+/**
+ * The system for which Nix is compiled.
+ */
+constexpr std::string_view nativeSystem = SYSTEM;
+
void handleDiffHook(
uid_t uid, uid_t gid,
const Path & tryA, const Path & tryB,
diff --git a/src/libstore/build/local-derivation-goal.hh b/src/libstore/build/local-derivation-goal.hh
index b7f317fb6..f3a83d42f 100644
--- a/src/libstore/build/local-derivation-goal.hh
+++ b/src/libstore/build/local-derivation-goal.hh
@@ -3,6 +3,7 @@
#include "derivation-goal.hh"
#include "local-store.hh"
+#include "processes.hh"
namespace nix {
diff --git a/src/libstore/common-protocol.cc b/src/libstore/common-protocol.cc
index f906814bc..456ad2b1f 100644
--- a/src/libstore/common-protocol.cc
+++ b/src/libstore/common-protocol.cc
@@ -1,11 +1,8 @@
#include "serialise.hh"
-#include "util.hh"
#include "path-with-outputs.hh"
#include "store-api.hh"
-#include "build-result.hh"
#include "common-protocol.hh"
#include "common-protocol-impl.hh"
-#include "archive.hh"
#include "derivations.hh"
#include <nlohmann/json.hpp>
diff --git a/src/libstore/crypto.cc b/src/libstore/crypto.cc
index 1027469c9..2e0fd8ca5 100644
--- a/src/libstore/crypto.cc
+++ b/src/libstore/crypto.cc
@@ -1,6 +1,7 @@
#include "crypto.hh"
-#include "util.hh"
+#include "file-system.hh"
#include "globals.hh"
+#include "strings.hh"
#include <sodium.h>
diff --git a/src/libstore/crypto.hh b/src/libstore/crypto.hh
index 35216d470..22588cf97 100644
--- a/src/libstore/crypto.hh
+++ b/src/libstore/crypto.hh
@@ -1,9 +1,9 @@
#pragma once
///@file
-#include "types.hh"
#include <map>
+#include <string>
namespace nix {
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index fef680421..4e70804e5 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -3,7 +3,6 @@
#include "store-api.hh"
#include "globals.hh"
#include "types.hh"
-#include "util.hh"
#include "split.hh"
#include "common-protocol.hh"
#include "common-protocol-impl.hh"
diff --git a/src/libstore/derived-path.hh b/src/libstore/derived-path.hh
index 4d7033df2..c87cf2004 100644
--- a/src/libstore/derived-path.hh
+++ b/src/libstore/derived-path.hh
@@ -1,7 +1,7 @@
#pragma once
///@file
-#include "util.hh"
+#include "config.hh"
#include "path.hh"
#include "outputs-spec.hh"
#include "comparator.hh"
diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc
index 076a5ca56..76da8e415 100644
--- a/src/libstore/filetransfer.cc
+++ b/src/libstore/filetransfer.cc
@@ -1,5 +1,5 @@
#include "filetransfer.hh"
-#include "util.hh"
+#include "namespaces.hh"
#include "globals.hh"
#include "store-api.hh"
#include "s3.hh"
@@ -19,7 +19,6 @@
#include <algorithm>
#include <cmath>
#include <cstring>
-#include <iostream>
#include <queue>
#include <random>
#include <thread>
diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh
index 3f55995ef..c692f1485 100644
--- a/src/libstore/filetransfer.hh
+++ b/src/libstore/filetransfer.hh
@@ -1,8 +1,9 @@
#pragma once
///@file
+#include "logging.hh"
+#include "serialise.hh"
#include "types.hh"
-#include "hash.hh"
#include "config.hh"
#include <string>
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 6b37f0af3..d58e3c8eb 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -1,16 +1,14 @@
-#include "derivations.hh"
#include "globals.hh"
#include "local-store.hh"
+#include "pathlocks.hh"
+#include "processes.hh"
#include "signals.hh"
#include "finally.hh"
+#include "unix-domain-socket.hh"
-#include <functional>
#include <queue>
-#include <algorithm>
#include <regex>
-#include <random>
-#include <climits>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 3308cad1f..993a8cfa5 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -1,12 +1,15 @@
+#include "environment-variables.hh"
#include "globals.hh"
-#include "util.hh"
-#include "archive.hh"
+#include "file-system.hh"
+#include "logging.hh"
+#include "strings.hh"
+#include "users.hh"
#include "args.hh"
#include "abstract-setting-to-json.hh"
#include "compute-levels.hh"
+#include "current-process.hh"
#include <algorithm>
-#include <map>
#include <mutex>
#include <thread>
#include <dlfcn.h>
@@ -25,6 +28,7 @@
#include "config-impl.hh"
#ifdef __APPLE__
+#include "processes.hh"
#include <curl/curl.h>
#include <sys/sysctl.h>
#endif
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 85789f6b5..581de7ff6 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -1,9 +1,9 @@
#pragma once
///@file
+#include "environment-variables.hh"
#include "types.hh"
#include "config.hh"
-#include "util.hh"
#include <map>
#include <limits>
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index 14f024ca9..808fdc202 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -3,11 +3,9 @@
#include "sqlite.hh"
-#include "pathlocks.hh"
#include "store-api.hh"
#include "indirect-root-store.hh"
#include "sync.hh"
-#include "util.hh"
#include <chrono>
#include <future>
diff --git a/src/libstore/lock.cc b/src/libstore/lock.cc
index 80c75eaa5..05296757d 100644
--- a/src/libstore/lock.cc
+++ b/src/libstore/lock.cc
@@ -1,4 +1,6 @@
#include "lock.hh"
+#include "logging.hh"
+#include "file-system.hh"
#include "globals.hh"
#include "pathlocks.hh"
diff --git a/src/libstore/machines.cc b/src/libstore/machines.cc
index 700c9b3dd..cdd1e1c2c 100644
--- a/src/libstore/machines.cc
+++ b/src/libstore/machines.cc
@@ -1,7 +1,7 @@
#include "machines.hh"
-#include "util.hh"
#include "globals.hh"
#include "store-api.hh"
+#include "strings.hh"
#include <algorithm>
diff --git a/src/libstore/meson.build b/src/libstore/meson.build
index 98549f6d9..f776e9621 100644
--- a/src/libstore/meson.build
+++ b/src/libstore/meson.build
@@ -79,6 +79,7 @@ libstore_sources = files(
'store-api.cc',
'uds-remote-store.cc',
'worker-protocol.cc',
+ 'build/child.cc',
'build/derivation-goal.cc',
'build/drv-output-substitution-goal.cc',
'build/entry-points.cc',
@@ -96,6 +97,7 @@ libstore_sources = files(
libstore_headers = files(
'binary-cache-store.hh',
+ 'build/child.hh',
'build/derivation-goal.hh',
'build/drv-output-substitution-goal.hh',
'build/goal.hh',
diff --git a/src/libstore/names.cc b/src/libstore/names.cc
index 277aabf0f..b903a99f0 100644
--- a/src/libstore/names.cc
+++ b/src/libstore/names.cc
@@ -1,5 +1,5 @@
#include "names.hh"
-#include "util.hh"
+#include "strings.hh"
#include <regex>
diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc
index c7176d30f..169b63819 100644
--- a/src/libstore/nar-info-disk-cache.cc
+++ b/src/libstore/nar-info-disk-cache.cc
@@ -1,7 +1,9 @@
#include "nar-info-disk-cache.hh"
+#include "logging.hh"
#include "sync.hh"
#include "sqlite.hh"
#include "globals.hh"
+#include "users.hh"
#include <sqlite3.h>
#include <nlohmann/json.hpp>
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index e09072e90..4f02296c3 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -1,4 +1,3 @@
-#include "util.hh"
#include "local-store.hh"
#include "globals.hh"
#include "signals.hh"
diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc
index 21c069223..0d740c324 100644
--- a/src/libstore/outputs-spec.cc
+++ b/src/libstore/outputs-spec.cc
@@ -1,10 +1,10 @@
#include <regex>
#include <nlohmann/json.hpp>
-#include "util.hh"
#include "regex-combinators.hh"
#include "outputs-spec.hh"
#include "path-regex.hh"
+#include "strings.hh"
namespace nix {
diff --git a/src/libstore/path-references.cc b/src/libstore/path-references.cc
index 33cf66ce3..8a02e9006 100644
--- a/src/libstore/path-references.cc
+++ b/src/libstore/path-references.cc
@@ -1,12 +1,8 @@
#include "path-references.hh"
#include "hash.hh"
-#include "util.hh"
#include "archive.hh"
#include <map>
-#include <cstdlib>
-#include <mutex>
-#include <algorithm>
namespace nix {
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc
index 3e654c1c9..ced0f30bb 100644
--- a/src/libstore/pathlocks.cc
+++ b/src/libstore/pathlocks.cc
@@ -1,10 +1,8 @@
#include "pathlocks.hh"
-#include "util.hh"
+#include "logging.hh"
#include "signals.hh"
-#include "sync.hh"
#include <cerrno>
-#include <cstdlib>
#include <fcntl.h>
#include <sys/types.h>
diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh
index 4921df352..7fcfa2e40 100644
--- a/src/libstore/pathlocks.hh
+++ b/src/libstore/pathlocks.hh
@@ -1,7 +1,7 @@
#pragma once
///@file
-#include "util.hh"
+#include "file-descriptor.hh"
namespace nix {
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index 239047dd6..e8b88693d 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -1,7 +1,7 @@
#include "profiles.hh"
#include "store-api.hh"
#include "local-fs-store.hh"
-#include "util.hh"
+#include "users.hh"
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 22d87b027..93b1afabd 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -1,5 +1,4 @@
#include "serialise.hh"
-#include "util.hh"
#include "signals.hh"
#include "path-with-outputs.hh"
#include "gc-store.hh"
diff --git a/src/libstore/serve-protocol.cc b/src/libstore/serve-protocol.cc
index 2e15d28d5..603137c81 100644
--- a/src/libstore/serve-protocol.cc
+++ b/src/libstore/serve-protocol.cc
@@ -1,11 +1,9 @@
#include "serialise.hh"
-#include "util.hh"
#include "path-with-outputs.hh"
#include "store-api.hh"
#include "build-result.hh"
#include "serve-protocol.hh"
#include "serve-protocol-impl.hh"
-#include "archive.hh"
#include "path-info.hh"
#include <nlohmann/json.hpp>
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index 4bd425b46..f40217734 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -1,12 +1,11 @@
#include "sqlite.hh"
#include "globals.hh"
-#include "util.hh"
+#include "logging.hh"
#include "signals.hh"
#include "url.hh"
#include <sqlite3.h>
-#include <atomic>
namespace nix {
diff --git a/src/libstore/ssh.cc b/src/libstore/ssh.cc
index 87414fe9c..932ebaa52 100644
--- a/src/libstore/ssh.cc
+++ b/src/libstore/ssh.cc
@@ -1,5 +1,9 @@
+#include "current-process.hh"
+#include "environment-variables.hh"
#include "ssh.hh"
#include "finally.hh"
+#include "logging.hh"
+#include "strings.hh"
namespace nix {
diff --git a/src/libstore/ssh.hh b/src/libstore/ssh.hh
index 94b952af9..f9c532caa 100644
--- a/src/libstore/ssh.hh
+++ b/src/libstore/ssh.hh
@@ -1,7 +1,8 @@
#pragma once
///@file
-#include "util.hh"
+#include "file-system.hh"
+#include "processes.hh"
#include "sync.hh"
namespace nix {
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index ed3566f5e..eb9b5c3ef 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -1,9 +1,7 @@
-#include "crypto.hh"
#include "fs-accessor.hh"
#include "globals.hh"
#include "derivations.hh"
#include "store-api.hh"
-#include "util.hh"
#include "nar-info-disk-cache.hh"
#include "thread-pool.hh"
#include "url.hh"
@@ -14,6 +12,7 @@
// FIXME this should not be here, see TODO below on
// `addMultipleToStore`.
#include "worker-protocol.hh"
+#include "users.hh"
#include <nlohmann/json.hpp>
#include <regex>
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 745fce594..397ebe759 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -1,6 +1,7 @@
#pragma once
///@file
+#include "logging.hh"
#include "nar-info.hh"
#include "realisation.hh"
#include "path.hh"
diff --git a/src/libstore/uds-remote-store.cc b/src/libstore/uds-remote-store.cc
index 99589f8b2..226cdf717 100644
--- a/src/libstore/uds-remote-store.cc
+++ b/src/libstore/uds-remote-store.cc
@@ -1,4 +1,5 @@
#include "uds-remote-store.hh"
+#include "unix-domain-socket.hh"
#include "worker-protocol.hh"
#include <sys/types.h>
diff --git a/src/libstore/worker-protocol.cc b/src/libstore/worker-protocol.cc
index ad94c79ee..d76a8d2b8 100644
--- a/src/libstore/worker-protocol.cc
+++ b/src/libstore/worker-protocol.cc
@@ -1,5 +1,4 @@
#include "serialise.hh"
-#include "util.hh"
#include "path-with-outputs.hh"
#include "store-api.hh"
#include "build-result.hh"