From 6ce46c651f56858e035d4fd784eeb428c48cf411 Mon Sep 17 00:00:00 2001 From: aszlig Date: Sat, 10 Sep 2022 16:00:18 +0200 Subject: pkgs/sandbox: Create injected target directory When using NIX_SANDBOX_DEBUG_INJECT_FILES (which we now call NIX_SANDBOX_DEBUG_INJECT_DIRS, because it's more accurate), I usually used it to provide fake /dev or /sys directories. I turned out, that today I was trying to use this functionality again (who'd have known) and it also turned out that I forgot to create the target directory, which wasn't needed back then for /dev or /sys because they were already existing. Signed-off-by: aszlig --- pkgs/build-support/build-sandbox/src/setup.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'pkgs') diff --git a/pkgs/build-support/build-sandbox/src/setup.c b/pkgs/build-support/build-sandbox/src/setup.c index 63b72773..fff5a718 100644 --- a/pkgs/build-support/build-sandbox/src/setup.c +++ b/pkgs/build-support/build-sandbox/src/setup.c @@ -714,11 +714,11 @@ static bool setup_runtime_debug(void) { char *injected_files, *buf, *ptr, *equals, *target; - if ((injected_files = getenv("NIX_SANDBOX_DEBUG_INJECT_FILES")) == NULL) + if ((injected_files = getenv("NIX_SANDBOX_DEBUG_INJECT_DIRS")) == NULL) return true; if ((buf = strdup(injected_files)) == NULL) { - perror("strdup NIX_SANDBOX_DEBUG_INJECT_FILES"); + perror("strdup NIX_SANDBOX_DEBUG_INJECT_DIRS"); return false; } @@ -733,8 +733,14 @@ static bool setup_runtime_debug(void) return false; } + if (!makedirs(target, true)) { + free(target); + free(buf); + return false; + } + if (mount(ptr, target, "", MS_BIND, NULL) == -1) { - fprintf(stderr, "mount injected file %s to %s: %s\n", + fprintf(stderr, "mount injected directory %s to %s: %s\n", ptr, target, strerror(errno)); free(target); free(buf); @@ -742,7 +748,8 @@ static bool setup_runtime_debug(void) } free(target); - fprintf(stderr, "Injected file '%s' to '%s'.\n", ptr, equals + 1); + fprintf(stderr, "Injected directory '%s' to '%s'.\n", + ptr, equals + 1); } ptr = strtok(NULL, ":"); -- cgit 1.4.1