switch_root: Add a sanity check
As switch_root basically does rm -Rf / we should make sure that / is really an initramfs. Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
parent
456857a49a
commit
07de470e43
|
@ -174,7 +174,13 @@ static int switchroot(const char *newroot)
|
|||
if (cfd >= 0) {
|
||||
pid = fork();
|
||||
if (pid <= 0) {
|
||||
recursiveRemove(cfd);
|
||||
if (fstat(cfd, &sb) == 0) {
|
||||
if (sb.st_dev == makedev(0, 1))
|
||||
recursiveRemove(cfd);
|
||||
else
|
||||
warn(_("old root filesystem is not an initramfs"));
|
||||
}
|
||||
|
||||
if (pid == 0)
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue