Re: How is pivot_root intended to be used?

Steven Stewart-Gallus
2014-09-04T07:35:11Z

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.