Skip to contentSkip to conversation

kexec-tools: find sysfs smarter

PATCH In review Josef Bacik 2 participants 2 messages Jun 1, 2016 – Jun 2, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec-tools: find sysfs smarter

Some systems may not have /etc/mtab, so fall back to using /proc/mounts if we fail to open /etc/mtab. Also if a user does

mount -t sysfs none /sys

we won't find the sysfs directory. We need to check mnt->mnt_type, not mnt->mnt_fsname.

---
 kexec/arch/i386/x86-linux-setup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kexec/arch/i386/x86-linux-setup.c +6 -3
index c75adaa..c24abaa 100644
@@ -425,10 +425,13 @@ char *find_mnt_by_fsname(char *fsname)
 	char *mntdir;
 
 	mtab = setmntent("/etc/mtab", "r");
-	if (!mtab)
-		return NULL;
+	if (!mtab) {
+		mtab = setmntent("/proc/mounts", "r");
+		if (!mtab)
+			return NULL;
+	}
 	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
-		if (strcmp(mnt->mnt_fsname, fsname) == 0)
+		if (strcmp(mnt->mnt_type, fsname) == 0)
 			break;
 	}
 	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
Signature · 7 lines
2.5.0


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Josef Bacik

Some systems may not have /etc/mtab, so fall back to using /proc/mounts if we fail to open /etc/mtab. Also if a user does

mount -t sysfs none /sys

we won't find the sysfs directory. We need to check mnt->mnt_type, not mnt->mnt_fsname.

yes, mnt_fsname is actually "device for filesystem" and mnt_type is "type of filesystem". Therefore, checking mnt->mnt_type is appropriate.

Quoted 2 lines
Quoted 33 lines
---
 kexec/arch/i386/x86-linux-setup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kexec/arch/i386/x86-linux-setup.c +6 -3
index c75adaa..c24abaa 100644
@@ -425,10 +425,13 @@ char *find_mnt_by_fsname(char *fsname)
 	char *mntdir;
 
 	mtab = setmntent("/etc/mtab", "r");
-	if (!mtab)
-		return NULL;
+	if (!mtab) {
+		mtab = setmntent("/proc/mounts", "r");
+		if (!mtab)
+			return NULL;
+	}
 	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
-		if (strcmp(mnt->mnt_fsname, fsname) == 0)
+		if (strcmp(mnt->mnt_type, fsname) == 0)
 			break;
 	}
 	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
Signature · 7 lines
2.5.0


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec