diff options
author | Yabin Cui <yabinc@google.com> | 2015-01-06 18:17:41 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-01-06 18:17:41 +0000 |
commit | 28175b0221ae0b1e2e0997419051ba3d24bb0e1b (patch) | |
tree | 1c7c2cfb17e91fefb95bbb5bec2b2e4d6c93bf2b /libcutils | |
parent | e8f0971cc852ecf4220cdcde01167b8f4f384f17 (diff) | |
parent | fdb3da5953b70dc87a05d28c31cb0dc06b8181aa (diff) | |
download | system_core-28175b0221ae0b1e2e0997419051ba3d24bb0e1b.zip system_core-28175b0221ae0b1e2e0997419051ba3d24bb0e1b.tar.gz system_core-28175b0221ae0b1e2e0997419051ba3d24bb0e1b.tar.bz2 |
am fdb3da59: Merge "Use getmntent when accessing /proc/mounts."
* commit 'fdb3da5953b70dc87a05d28c31cb0dc06b8181aa':
Use getmntent when accessing /proc/mounts.
Diffstat (limited to 'libcutils')
-rw-r--r-- | libcutils/android_reboot.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c index 5d98295..aa86206 100644 --- a/libcutils/android_reboot.c +++ b/libcutils/android_reboot.c @@ -20,6 +20,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <mntent.h> #include <stdio.h> #include <string.h> @@ -33,37 +34,21 @@ */ static int remount_ro_done(void) { - FILE *f; - char mount_dev[256]; - char mount_dir[256]; - char mount_type[256]; - char mount_opts[256]; - int mount_freq; - int mount_passno; - int match; + FILE* fp; + struct mntent* mentry; int found_rw_fs = 0; - f = fopen("/proc/mounts", "r"); - if (! f) { - /* If we can't read /proc/mounts, just give up */ + if ((fp = setmntent("/proc/mounts", "r")) == NULL) { + /* If we can't read /proc/mounts, just give up. */ return 1; } - - do { - match = fscanf(f, "%255s %255s %255s %255s %d %d\n", - mount_dev, mount_dir, mount_type, - mount_opts, &mount_freq, &mount_passno); - mount_dev[255] = 0; - mount_dir[255] = 0; - mount_type[255] = 0; - mount_opts[255] = 0; - if ((match == 6) && !strncmp(mount_dev, "/dev/block", 10) && strstr(mount_opts, "rw,")) { + while ((mentry = getmntent(fp)) != NULL) { + if (!strncmp(mentry->mnt_fsname, "/dev/block", 10) && strstr(mentry->mnt_opts, "rw,")) { found_rw_fs = 1; break; } - } while (match != EOF); - - fclose(f); + } + endmntent(fp); return !found_rw_fs; } |