From c91c8a5e6954a764d96322ccc8db3e7a77d4d824 Mon Sep 17 00:00:00 2001 From: Andrew Vagin Date: Wed, 15 Jun 2016 19:57:00 +0300 Subject: [PATCH] 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: Andrew Vagin Signed-off-by: Pavel Emelyanov --- criu/files.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/criu/files.c b/criu/files.c index b3953781e..e8fbdb218 100644 --- a/criu/files.c +++ b/criu/files.c @@ -1150,26 +1150,18 @@ out: static int fchroot(int fd) { - char fd_path[PSFDS]; - int proc; - /* * There's no such thing in syscalls. We can emulate - * it using the /proc/self/fd/ :) - * - * But since there might be no /proc mount in our mount - * namespace, we will have to ... workaround it. + * it using fchdir() */ - proc = get_service_fd(PROC_FD_OFF); - if (fchdir(proc) < 0) { + if (fchdir(fd) < 0) { pr_perror("Can't chdir to proc"); return -1; } - sprintf(fd_path, "./self/fd/%d", fd); - pr_debug("Going to chroot into %s\n", fd_path); - return chroot(fd_path); + pr_debug("Going to chroot into /proc/self/fd/%d\n", fd); + return chroot("."); } 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 - * calls chdir into proc service descriptor so - * we'd need to fix chdir after it anyway. + * Now do chroot/chdir. Chroot goes first as it calls chdir into + * dd_root so we'd need to fix chdir after it anyway. */ ret = fchroot(dd_root);