Re: How is pivot_root intended to be used?

From: Steven Stewart-Gallus
Date: Thu Sep 04 2014 - 03:35:15 EST


Thank you, I think I will change the code to be like:

int old_root = open("/", O_DIRECTORY);
if (-1 == old_root) {
perror("open");
return EXIT_FAILURE;
}

if (-1 == syscall(__NR_pivot_root, ".", ".")) {
perror("pivot_root");
return EXIT_FAILURE;
}

if (-1 == fchdir(old_root)) {
perror("fchdir");
return EXIT_FAILURE;
}

if (-1 == umount2(".", MNT_DETACH)) {
perror("umount");
return EXIT_FAILURE;
}

if (-1 == close(old_root)) {
perror("close");
return EXIT_FAILURE;
}

if (-1 == chdir("/")) {
perror("chdir");
return EXIT_FAILURE;
}

This seems more understandable to me and less likely to have bugs later on.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/