aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--test/nstool.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/nstool.c b/test/nstool.c
index c7f2b25..e6d7d37 100644
--- a/test/nstool.c
+++ b/test/nstool.c
@@ -420,6 +420,7 @@ static void cmd_exec(int argc, char *argv[])
const struct ns_type *nst;
int ctlfd, flags, opt, rc;
const char *const *xargs;
+ struct holder_info info;
bool keepcaps = false;
struct ucred peercred;
const char *exe;
@@ -444,7 +445,7 @@ static void cmd_exec(int argc, char *argv[])
sockpath = argv[optind];
- ctlfd = connect_ctl(sockpath, false, NULL, &peercred);
+ ctlfd = connect_ctl(sockpath, false, &info, &peercred);
flags = detect_namespaces(peercred.pid);
@@ -475,6 +476,15 @@ static void cmd_exec(int argc, char *argv[])
nst->name, strerror(errno));
}
+ /* If we've entered a mount ns, our cwd has changed to /.
+ * Switch to the cwd of the holder, which is probably less
+ * surprising. */
+ if (flags & CLONE_NEWNS) {
+ rc = chdir(info.cwd);
+ if (rc < 0)
+ die("chdir(\"%s\"): %s\n", info.cwd, strerror(errno));
+ }
+
/* Fork to properly enter PID namespace */
xpid = fork();
if (xpid < 0)