about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2022-09-10 16:00:18 +0200
committeraszlig <aszlig@nix.build>2022-09-10 16:00:18 +0200
commit6ce46c651f56858e035d4fd784eeb428c48cf411 (patch)
treec577e0c8db3f88795fada933d529e1b511c6bd3b /pkgs
parent4f40b9c0dd898ec0460b47e727dbb1e0360a2bf9 (diff)
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 <aszlig@nix.build>
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/build-sandbox/src/setup.c15
1 files changed, 11 insertions, 4 deletions
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, ":");