qualcommax: ipq807x: uboot-envtools: yuncore ax880
[openwrt/openwrt.git] / package / libs / sysfsutils / patches / 200-mnt_path_check.patch
1 --- a/lib/sysfs_utils.c
2 +++ b/lib/sysfs_utils.c
3 @@ -22,6 +22,7 @@
4 */
5 #include "libsysfs.h"
6 #include "sysfs.h"
7 +#include <mntent.h>
8
9 /**
10 * sysfs_remove_trailing_slash: Removes any trailing '/' in the given path
11 @@ -53,6 +54,9 @@ int sysfs_get_mnt_path(char *mnt_path, s
12 {
13 static char sysfs_path[SYSFS_PATH_MAX] = "";
14 const char *sysfs_path_env;
15 + FILE *mnt;
16 + struct mntent *mntent;
17 + int ret;
18
19 if (len == 0 || mnt_path == NULL)
20 return -1;
21 @@ -64,12 +68,31 @@ int sysfs_get_mnt_path(char *mnt_path, s
22 if (sysfs_path_env != NULL) {
23 safestrcpymax(mnt_path, sysfs_path_env, len);
24 sysfs_remove_trailing_slash(mnt_path);
25 - return 0;
26 + } else {
27 + safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
28 }
29 - safestrcpymax(mnt_path, SYSFS_MNT_PATH, len);
30 }
31
32 - return 0;
33 + /* check that mount point is indeed mounted */
34 + ret = -1;
35 + if ((mnt = setmntent(SYSFS_PROC_MNTS, "r")) == NULL) {
36 + dprintf("Error getting mount information\n");
37 + return -1;
38 + }
39 + while ((mntent = getmntent(mnt)) != NULL) {
40 + if (strcmp(mntent->mnt_type, SYSFS_FSTYPE_NAME) == 0 &&
41 + strcmp(mntent->mnt_dir, mnt_path) == 0) {
42 + ret = 0;
43 + break;
44 + }
45 + }
46 +
47 + endmntent(mnt);
48 +
49 + if (ret < 0)
50 + errno = ENOENT;
51 +
52 + return ret;
53 }
54
55 /**