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:
Richard Weinberger 2013-02-09 19:22:50 +01:00 committed by Karel Zak
parent 456857a49a
commit 07de470e43
1 changed files with 7 additions and 1 deletions

View File

@ -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);
}