Fall back to chroot() if setns() fails for mnt namespace

fixes #347
This commit is contained in:
Bob Lantz
2014-08-26 14:09:40 -07:00
parent 16a384ab4b
commit bfdbb7089a
+5 -4
View File
@@ -152,15 +152,16 @@ int main(int argc, char *argv[])
perror("setns");
return 1;
}
/* Plan A: call setns() to attach to mount namespace */
sprintf(path, "/proc/%d/ns/mnt", pid);
nsid = open(path, O_RDONLY);
if (nsid < 0) {
if (nsid < 0 || setns(nsid, 0) != 0) {
/* Plan B: chroot into pid's root file system */
sprintf(path, "/proc/%d/root", pid);
if (chroot(path) < 0) {
perror(path);
return 1;
}
if (setns(nsid, 0) != 0) {
perror("setns");
return 1;
}
break;
case 'g':