From af1c840c1cf7f471ea2097148bc0e15dd0c2813b Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 3 Oct 2017 23:13:48 +0200 Subject: pkgs/sandbox: Mount closure of /etc/static We already mount /etc, but it isn't quite enough, because it contains files symlinked to /etc/static, which in turn is a store path so we need to mount the closure of that path as well. Signed-off-by: aszlig --- .../build-support/build-sandbox/src/nix-query.cc | 8 +++-- pkgs/games/build-support/build-sandbox/src/setup.c | 42 ++++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) (limited to 'pkgs/games/build-support') diff --git a/pkgs/games/build-support/build-sandbox/src/nix-query.cc b/pkgs/games/build-support/build-sandbox/src/nix-query.cc index 128c376a..71208693 100644 --- a/pkgs/games/build-support/build-sandbox/src/nix-query.cc +++ b/pkgs/games/build-support/build-sandbox/src/nix-query.cc @@ -56,11 +56,12 @@ static Path get_ancestor(query_state *qs, Path path) } } - return path; + return get_store_path(qs, path); } extern "C" { - struct query_state *new_query(void) { + struct query_state *new_query(void) + { query_state *initial = new query_state(); #if NIX_VERSION >= 112 initial->store = openStore(); @@ -72,7 +73,8 @@ extern "C" { return initial; } - void free_query(query_state *qs) { + void free_query(query_state *qs) + { delete qs; } diff --git a/pkgs/games/build-support/build-sandbox/src/setup.c b/pkgs/games/build-support/build-sandbox/src/setup.c index b1f8cdcf..0b582e92 100644 --- a/pkgs/games/build-support/build-sandbox/src/setup.c +++ b/pkgs/games/build-support/build-sandbox/src/setup.c @@ -496,6 +496,17 @@ static bool setup_xauthority(void) return result; } +static bool is_dir(const char *path) +{ + struct stat sb; + if (stat(path, &sb) == -1) { + fprintf(stderr, "stat %s: %s\n", path, strerror(errno)); + // Default to directory for mounting + return true; + } + return S_ISDIR(sb.st_mode); +} + static bool mount_requisites(struct query_state *qs, const char *path) { const char *requisite; @@ -506,8 +517,13 @@ static bool mount_requisites(struct query_state *qs, const char *path) } while ((requisite = next_query_result(qs)) != NULL) { - if (!bind_mount(requisite, true, false)) - return false; + if (is_dir(requisite)) { + if (!bind_mount(requisite, true, false)) + return false; + } else { + if (!bind_file(requisite)) + return false; + } } return true; @@ -539,6 +555,23 @@ bool mount_from_path_var(struct query_state *qs, const char *name) return true; } +static bool setup_static_etc(struct query_state *qs) +{ + char dest[PATH_MAX]; + ssize_t destlen; + + if ((destlen = readlink("/etc/static", dest, PATH_MAX)) == -1) + return true; + + if (destlen >= PATH_MAX) { + fputs("readlink of /etc/static larger than PATH_MAX.\n", stderr); + return false; + } + + dest[destlen] = '\0'; + return mount_requisites(qs, dest); +} + static bool setup_runtime_paths(void) { struct query_state *qs; @@ -548,6 +581,11 @@ static bool setup_runtime_paths(void) return false; } + if (!setup_static_etc(qs)) { + free_query(qs); + return false; + } + if (!mount_runtime_path_vars(qs)) { free_query(qs); return false; -- cgit 1.4.1