1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
switch_root: check if mount point to move even exists
--- a/sys-utils/switch_root.c
+++ b/sys-utils/switch_root.c
@@ -131,7 +131,12 @@ static int switchroot(const char *newroot)
int i;
int cfd;
pid_t pid;
- struct stat newroot_stat, sb;
+ struct stat newroot_stat, oldroot_stat, sb;
+
+ if (stat("/", &oldroot_stat) != 0) {
+ warn(_("stat of %s failed"), "/");
+ return -1;
+ }
if (stat(newroot, &newroot_stat) != 0) {
warn(_("stat of %s failed"), newroot);
@@ -143,6 +148,11 @@ static int switchroot(const char *newroot)
snprintf(newmount, sizeof(newmount), "%s%s", newroot, umounts[i]);
+ if ((stat(umounts[i], &sb) == 0) && sb.st_dev == oldroot_stat.st_dev) {
+ /* mount point to move seems to be a normal directory or stat failed */
+ continue;
+ }
+
if ((stat(newmount, &sb) != 0) || (sb.st_dev != newroot_stat.st_dev)) {
/* mount point seems to be mounted already or stat failed */
umount2(umounts[i], MNT_DETACH);
|