From: Ben Pfaff Date: Thu, 25 Apr 2013 23:59:15 +0000 (-0700) Subject: system-stats: Use getmntent_r() for thread-safety. X-Git-Tag: sliver-openvswitch-1.10.90-3~17^2~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=ffb1cfd1445008a23fdc3276a6f8ecbeaac74279;p=sliver-openvswitch.git system-stats: Use getmntent_r() for thread-safety. getmntent_r() is a GNU extension so we test for its existence and just disable this feature of system stats if it is not present, because this feature is not very important. Signed-off-by: Ben Pfaff --- diff --git a/configure.ac b/configure.ac index 7af8afbc0..bbb6dea7f 100644 --- a/configure.ac +++ b/configure.ac @@ -60,7 +60,7 @@ OVS_CHECK_IF_DL OVS_CHECK_STRTOK_R AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec], [], [], [[#include ]]) -AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs setmntent]) +AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs getmntent_r]) AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h]) OVS_CHECK_PKIDIR diff --git a/vswitchd/system-stats.c b/vswitchd/system-stats.c index 2e18b1b6b..842bc204a 100644 --- a/vswitchd/system-stats.c +++ b/vswitchd/system-stats.c @@ -447,9 +447,11 @@ get_process_stats(struct smap *stats) static void get_filesys_stats(struct smap *stats OVS_UNUSED) { -#if HAVE_SETMNTENT && HAVE_STATVFS +#if HAVE_GETMNTENT_R && HAVE_STATVFS static const char file_name[] = "/etc/mtab"; + struct mntent mntent; struct mntent *me; + char buf[4096]; FILE *stream; struct ds s; @@ -460,7 +462,7 @@ get_filesys_stats(struct smap *stats OVS_UNUSED) } ds_init(&s); - while ((me = getmntent(stream)) != NULL) { + while ((me = getmntent_r(stream, &mntent, buf, sizeof buf)) != NULL) { unsigned long long int total, free; struct statvfs vfs; char *p; @@ -494,7 +496,7 @@ get_filesys_stats(struct smap *stats OVS_UNUSED) smap_add(stats, "file_systems", ds_cstr(&s)); } ds_destroy(&s); -#endif /* HAVE_SETMNTENT && HAVE_STATVFS */ +#endif /* HAVE_GETMNTENT_R && HAVE_STATVFS */ } #define SYSTEM_STATS_INTERVAL (5 * 1000) /* In milliseconds. */