Commit c91c8a5e authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

files: simplify fchroot()

We can call fchdir into the taget directory and call chroot(".")

v2: fix one more comment speaking about proc
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 2fdef836
...@@ -1150,26 +1150,18 @@ out: ...@@ -1150,26 +1150,18 @@ out:
static int fchroot(int fd) static int fchroot(int fd)
{ {
char fd_path[PSFDS];
int proc;
/* /*
* There's no such thing in syscalls. We can emulate * There's no such thing in syscalls. We can emulate
* it using the /proc/self/fd/ :) * it using fchdir()
*
* But since there might be no /proc mount in our mount
* namespace, we will have to ... workaround it.
*/ */
proc = get_service_fd(PROC_FD_OFF); if (fchdir(fd) < 0) {
if (fchdir(proc) < 0) {
pr_perror("Can't chdir to proc"); pr_perror("Can't chdir to proc");
return -1; return -1;
} }
sprintf(fd_path, "./self/fd/%d", fd); pr_debug("Going to chroot into /proc/self/fd/%d\n", fd);
pr_debug("Going to chroot into %s\n", fd_path); return chroot(".");
return chroot(fd_path);
} }
int restore_fs(struct pstree_item *me) int restore_fs(struct pstree_item *me)
...@@ -1195,9 +1187,8 @@ int restore_fs(struct pstree_item *me) ...@@ -1195,9 +1187,8 @@ int restore_fs(struct pstree_item *me)
} }
/* /*
* Now do chroot/chdir. Chroot goes first as it * Now do chroot/chdir. Chroot goes first as it calls chdir into
* calls chdir into proc service descriptor so * dd_root so we'd need to fix chdir after it anyway.
* we'd need to fix chdir after it anyway.
*/ */
ret = fchroot(dd_root); ret = fchroot(dd_root);
......
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