Skip to content

Commit

Permalink
Merge pull request #8920 from obsidiansystems/split-util-cchh
Browse files Browse the repository at this point in the history
Split up `util.{hh,cc}`
  • Loading branch information
roberth authored Nov 5, 2023
2 parents 8e222fb + ac89bb0 commit 1a14ce8
Show file tree
Hide file tree
Showing 138 changed files with 3,051 additions and 2,683 deletions.
1 change: 0 additions & 1 deletion perl/lib/Nix/Store.xs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "derivations.hh"
#include "globals.hh"
#include "store-api.hh"
#include "util.hh"
#include "crypto.hh"

#include <sodium.h>
Expand Down
3 changes: 3 additions & 0 deletions src/libcmd/built-path.hh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once
///@file

#include "derived-path.hh"
#include "realisation.hh"

Expand Down
1 change: 0 additions & 1 deletion src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "common-eval-args.hh"
#include "shared.hh"
#include "filetransfer.hh"
#include "util.hh"
#include "eval.hh"
#include "fetchers.hh"
#include "registry.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/editor-for.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "util.hh"
#include "editor-for.hh"
#include "environment-variables.hh"

namespace nix {

Expand Down
1 change: 0 additions & 1 deletion src/libcmd/installable-attr-path.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "globals.hh"
#include "installable-value.hh"
#include "outputs-spec.hh"
#include "util.hh"
#include "command.hh"
#include "attr-path.hh"
#include "common-eval-args.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "installable-attr-path.hh"
#include "installable-flake.hh"
#include "outputs-spec.hh"
#include "users.hh"
#include "util.hh"
#include "command.hh"
#include "attr-path.hh"
Expand Down
1 change: 0 additions & 1 deletion src/libcmd/installables.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
///@file

#include "util.hh"
#include "path.hh"
#include "outputs-spec.hh"
#include "derived-path.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libcmd/markdown.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "markdown.hh"
#include "util.hh"
#include "finally.hh"
#include "terminal.hh"

#include <sys/queue.h>
#include <lowdown.h>
Expand Down
3 changes: 3 additions & 0 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern "C" {
#include "repl.hh"

#include "ansicolor.hh"
#include "signals.hh"
#include "shared.hh"
#include "eval.hh"
#include "eval-cache.hh"
Expand All @@ -36,6 +37,8 @@ extern "C" {
#include "globals.hh"
#include "flake/flake.hh"
#include "flake/lockfile.hh"
#include "users.hh"
#include "terminal.hh"
#include "editor-for.hh"
#include "finally.hh"
#include "markdown.hh"
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/attr-path.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "attr-path.hh"
#include "eval-inline.hh"
#include "util.hh"


namespace nix {
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "users.hh"
#include "eval-cache.hh"
#include "sqlite.hh"
#include "eval.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "users.hh"
#include "globals.hh"
#include "profiles.hh"
#include "eval.hh"
Expand Down
2 changes: 2 additions & 0 deletions src/libexpr/eval-settings.hh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
///@file

#include "config.hh"

namespace nix {
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "print.hh"
#include "fs-input-accessor.hh"
#include "memory-input-accessor.hh"
#include "signals.hh"

#include <algorithm>
#include <chrono>
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/flake/config.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "flake.hh"
#include "users.hh"
#include "globals.hh"
#include "fetch-settings.hh"
#include "flake.hh"

#include <nlohmann/json.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "terminal.hh"
#include "flake.hh"
#include "eval.hh"
#include "eval-settings.hh"
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/get-drvs.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "get-drvs.hh"
#include "util.hh"
#include "eval-inline.hh"
#include "derivations.hh"
#include "store-api.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <variant>

#include "util.hh"
#include "users.hh"

#include "nixexpr.hh"
#include "eval.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "path-references.hh"
#include "store-api.hh"
#include "util.hh"
#include "processes.hh"
#include "value-to-json.hh"
#include "value-to-xml.hh"
#include "primops.hh"
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/search-path.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "search-path.hh"
#include "util.hh"

namespace nix {

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/value-to-json.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "value-to-json.hh"
#include "eval-inline.hh"
#include "util.hh"
#include "store-api.hh"
#include "signals.hh"

#include <cstdlib>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/value-to-xml.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "value-to-xml.hh"
#include "xml-writer.hh"
#include "eval-inline.hh"
#include "util.hh"
#include "signals.hh"

#include <cstdlib>

Expand Down
1 change: 1 addition & 0 deletions src/libexpr/value/context.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "util.hh"
#include "value/context.hh"

#include <optional>
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/value/context.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
///@file

#include "util.hh"
#include "comparator.hh"
#include "derived-path.hh"
#include "variant-wrapper.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.hh"
#include "users.hh"
#include "sqlite.hh"
#include "sync.hh"
#include "store-api.hh"
Expand Down
1 change: 0 additions & 1 deletion src/libfetchers/fetch-settings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "types.hh"
#include "config.hh"
#include "util.hh"

#include <map>
#include <limits>
Expand Down
3 changes: 2 additions & 1 deletion src/libfetchers/git.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "fetchers.hh"
#include "users.hh"
#include "cache.hh"
#include "globals.hh"
#include "tarfile.hh"
#include "store-api.hh"
#include "url-parts.hh"
#include "pathlocks.hh"
#include "util.hh"
#include "processes.hh"
#include "git.hh"

#include "fetch-settings.hh"
Expand Down
2 changes: 2 additions & 0 deletions src/libfetchers/input-accessor.hh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once
///@file

#include "source-accessor.hh"
#include "ref.hh"
#include "types.hh"
#include "file-system.hh"
#include "repair-flag.hh"
#include "content-address.hh"

Expand Down
2 changes: 2 additions & 0 deletions src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "fetchers.hh"
#include "processes.hh"
#include "users.hh"
#include "cache.hh"
#include "globals.hh"
#include "tarfile.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/registry.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "registry.hh"
#include "tarball.hh"
#include "util.hh"
#include "users.hh"
#include "globals.hh"
#include "store-api.hh"
#include "local-fs-store.hh"
Expand Down
2 changes: 2 additions & 0 deletions src/libmain/common-args.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "common-args.hh"
#include "args/root.hh"
#include "globals.hh"
#include "logging.hh"
#include "loggers.hh"
#include "util.hh"

namespace nix {

Expand Down
2 changes: 1 addition & 1 deletion src/libmain/loggers.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "loggers.hh"
#include "environment-variables.hh"
#include "progress-bar.hh"
#include "util.hh"

namespace nix {

Expand Down
2 changes: 1 addition & 1 deletion src/libmain/progress-bar.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "progress-bar.hh"
#include "util.hh"
#include "terminal.hh"
#include "sync.hh"
#include "store-api.hh"
#include "names.hh"
Expand Down
3 changes: 2 additions & 1 deletion src/libmain/shared.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "globals.hh"
#include "current-process.hh"
#include "shared.hh"
#include "store-api.hh"
#include "gc-store.hh"
#include "util.hh"
#include "loggers.hh"
#include "progress-bar.hh"
#include "signals.hh"

#include <algorithm>
#include <cctype>
Expand Down
2 changes: 1 addition & 1 deletion src/libmain/shared.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
///@file

#include "util.hh"
#include "processes.hh"
#include "args.hh"
#include "args/root.hh"
#include "common-args.hh"
Expand Down
1 change: 1 addition & 0 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "nar-accessor.hh"
#include "thread-pool.hh"
#include "callback.hh"
#include "signals.hh"

#include <chrono>
#include <future>
Expand Down
37 changes: 37 additions & 0 deletions src/libstore/build/child.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "child.hh"
#include "current-process.hh"
#include "logging.hh"

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

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);
}

}
11 changes: 11 additions & 0 deletions src/libstore/build/child.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
///@file

namespace nix {

/**
* Common initialisation performed in child processes.
*/
void commonChildInit();

}
2 changes: 2 additions & 0 deletions src/libstore/build/hook-instance.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "globals.hh"
#include "hook-instance.hh"
#include "file-system.hh"
#include "child.hh"

namespace nix {

Expand Down
1 change: 1 addition & 0 deletions src/libstore/build/hook-instance.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "logging.hh"
#include "serialise.hh"
#include "processes.hh"

namespace nix {

Expand Down
5 changes: 5 additions & 0 deletions src/libstore/build/local-derivation-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include "json-utils.hh"
#include "cgroup.hh"
#include "personality.hh"
#include "current-process.hh"
#include "namespaces.hh"
#include "child.hh"
#include "unix-domain-socket.hh"

#include <regex>
#include <queue>
Expand Down Expand Up @@ -1620,6 +1623,8 @@ void setupSeccomp()
seccomp_release(ctx);
});

constexpr std::string_view nativeSystem = SYSTEM;

if (nativeSystem == "x86_64-linux" &&
seccomp_arch_add(ctx, SCMP_ARCH_X86) != 0)
throw SysError("unable to add 32-bit seccomp architecture");
Expand Down
1 change: 1 addition & 0 deletions src/libstore/build/local-derivation-goal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "derivation-goal.hh"
#include "local-store.hh"
#include "processes.hh"

namespace nix {

Expand Down
1 change: 1 addition & 0 deletions src/libstore/build/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "drv-output-substitution-goal.hh"
#include "local-derivation-goal.hh"
#include "hook-instance.hh"
#include "signals.hh"

#include <poll.h>

Expand Down
Loading

0 comments on commit 1a14ce8

Please sign in to comment.