File: get_mnt_path_check.patch

package info (click to toggle)
sysfsutils 2.1.0+repack-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,120 kB
  • sloc: sh: 8,685; ansic: 8,035; makefile: 58
file content (57 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Index: sysfsutils-2.1.0+repack/lib/sysfs_utils.c
===================================================================
--- sysfsutils-2.1.0+repack.orig/lib/sysfs_utils.c	2006-08-07 07:08:01.000000000 +0200
+++ sysfsutils-2.1.0+repack/lib/sysfs_utils.c	2010-08-06 19:03:58.276747000 +0200
@@ -22,6 +22,7 @@
  */
 #include "libsysfs.h"
 #include "sysfs.h"
+#include <mntent.h>
 
 /**
  * sysfs_remove_trailing_slash: Removes any trailing '/' in the given path
@@ -53,6 +54,9 @@
 {
 	static char sysfs_path[SYSFS_PATH_MAX] = "";
 	const char *sysfs_path_env;
+	FILE *mnt;
+	struct mntent *mntent;
+	int ret;
 
 	if (len == 0 || mnt_path == NULL)
 		return -1;
@@ -64,12 +68,31 @@
 		if (sysfs_path_env != NULL) {
 			safestrcpymax(mnt_path, sysfs_path_env, len);
 			sysfs_remove_trailing_slash(mnt_path);
-			return 0;
+		} else {
+			safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
 		}
-		safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
 	}
 
-	return 0;
+	/* check that mount point is indeed mounted */
+	ret = -1;
+	if ((mnt = setmntent(SYSFS_PROC_MNTS, "r")) == NULL) {
+		dprintf("Error getting mount information\n");
+		return -1;
+	}
+	while ((mntent = getmntent(mnt)) != NULL) {
+		if (strcmp(mntent->mnt_type, SYSFS_FSTYPE_NAME) == 0 &&
+			strcmp(mntent->mnt_dir, mnt_path) == 0) {
+			ret = 0;
+			break;
+		}
+	}
+	
+	endmntent(mnt);
+
+	if (ret < 0)
+		errno = ENOENT;
+
+	return ret;
 }
 
 /**