system-stats: Use getmntent_r() for thread-safety.
authorBen Pfaff <blp@nicira.com>
Thu, 25 Apr 2013 23:59:15 +0000 (16:59 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 3 May 2013 19:49:39 +0000 (12:49 -0700)
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 <blp@nicira.com>
configure.ac
vswitchd/system-stats.c

index 7af8afb..bbb6dea 100644 (file)
@@ -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 <sys/stat.h>]])
-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
index 2e18b1b..842bc20 100644 (file)
@@ -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 */
 }
 \f
 #define SYSTEM_STATS_INTERVAL (5 * 1000) /* In milliseconds. */