summaryrefslogtreecommitdiffstats
path: root/sys-utils/switch_root.c
diff options
context:
space:
mode:
authorRichard Weinberger2013-02-09 19:22:50 +0100
committerKarel Zak2013-02-13 14:55:30 +0100
commit07de470e437f204e3d40b8b0a85f57c1978ff9ed (patch)
tree6cd85fe6dd4c3148843bf5af03e2503c0493cdc1 /sys-utils/switch_root.c
parentbuild-sys: add config-gen.d stuff for chsh-chfn (diff)
downloadkernel-qcow2-util-linux-07de470e437f204e3d40b8b0a85f57c1978ff9ed.tar.gz
kernel-qcow2-util-linux-07de470e437f204e3d40b8b0a85f57c1978ff9ed.tar.xz
kernel-qcow2-util-linux-07de470e437f204e3d40b8b0a85f57c1978ff9ed.zip
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>
Diffstat (limited to 'sys-utils/switch_root.c')
-rw-r--r--sys-utils/switch_root.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sys-utils/switch_root.c b/sys-utils/switch_root.c
index f0ef67745..f26f7dae4 100644
--- a/sys-utils/switch_root.c
+++ b/sys-utils/switch_root.c
@@ -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);
}