Commit 6e94eb5b authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

files: restore cwd after switching mntns

Cc: Stanislav Kinsbursky <skinsbursky@openvz.org>
Reported-by: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 9e96f138
...@@ -423,6 +423,7 @@ void try_clean_remaps(int ns_fd) ...@@ -423,6 +423,7 @@ void try_clean_remaps(int ns_fd)
{ {
struct remap_info *ri; struct remap_info *ri;
int old_ns = -1; int old_ns = -1;
int cwd_fd = -1;
if (list_empty(&remaps)) if (list_empty(&remaps))
goto out; goto out;
...@@ -436,6 +437,12 @@ void try_clean_remaps(int ns_fd) ...@@ -436,6 +437,12 @@ void try_clean_remaps(int ns_fd)
return; return;
} }
cwd_fd = open(".", O_DIRECTORY);
if (cwd_fd < 0) {
pr_perror("Unable to open cwd");
return;
}
if (setns(ns_fd, CLONE_NEWNS) < 0) { if (setns(ns_fd, CLONE_NEWNS) < 0) {
close(old_ns); close(old_ns);
pr_perror("`- Can't switch"); pr_perror("`- Can't switch");
...@@ -453,6 +460,15 @@ void try_clean_remaps(int ns_fd) ...@@ -453,6 +460,15 @@ void try_clean_remaps(int ns_fd)
close(old_ns); close(old_ns);
} }
if (cwd_fd >= 0) {
if (fchdir(cwd_fd)) {
pr_perror("Unable to restore cwd");
close(cwd_fd);
return;
}
close(cwd_fd);
}
out: out:
if (ns_fd >= 0) if (ns_fd >= 0)
close(ns_fd); close(ns_fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment