This way there's no race between unlinking the /newroot directory and
the MS_MOVE/chroot() to get away from it.
Signed-off-by: Peter Jones <pjones@redhat.com>
}
cfd = open("/", O_RDONLY);
- if (cfd >= 0) {
- pid = fork();
- if (pid <= 0) {
- recursiveRemove(cfd);
- if (pid == 0)
- exit(EXIT_SUCCESS);
- }
- close(cfd);
- }
if (mount(newroot, "/", NULL, MS_MOVE, NULL) < 0) {
warn("failed to mount moving %s to /", newroot);
warn("failed to change root");
return -1;
}
+
+ if (cfd >= 0) {
+ pid = fork();
+ if (pid <= 0) {
+ recursiveRemove(cfd);
+ if (pid == 0)
+ exit(EXIT_SUCCESS);
+ }
+ close(cfd);
+ }
return 0;
}