]> Pileus Git - ~andy/fetchmail/commitdiff
Default to Linux 2.2 /proc/net/dev format, and use uname(2) to determine the kernel...
authorGraham Wilson <graham@mknod.org>
Sun, 14 Nov 2004 18:58:40 +0000 (18:58 -0000)
committerGraham Wilson <graham@mknod.org>
Sun, 14 Nov 2004 18:58:40 +0000 (18:58 -0000)
svn path=/trunk/; revision=4007

NEWS
interface.c

diff --git a/NEWS b/NEWS
index c521dc4dc030d86f9068656a3817e5efa82f1f68..95b36ae757eebc88892982e562a18d1b26e2cd41 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,8 @@
   snprintf or vsnprintf.
 * Clean up the horrible #ifdef HAVE_[V]SNPRINTF that made the code
   unreadable. Use Trio where [v]snprintf is/are missing. Matthias Andree.
+* Default to Linux 2.2 /proc/net/dev format, and use uname(2) to determine the
+  kernel version instead of calling uname(1). Thanks to Paul Slootman.
 
 fetchmail-6.2.5 (Wed Oct 15 18:39:22 EDT 2003), 23079 lines:
 
index 4c9dde32c6f1b75dd170164da59835aec430ca5e..c264f22b9ff1c9478901b8ddc8bb5cbb102d929b 100644 (file)
 #include <sys/types.h>
 #include <sys/param.h>
 
+#if defined(linux)
+#include <sys/utsname.h>
+#endif
+
 #if (defined(linux) && !defined(INET6_ENABLE)) || defined(__FreeBSD__)
 
 #include "config.h"
@@ -73,24 +77,23 @@ static char *netdevfmt;
 #if defined(linux)
 
 void interface_init(void)
-/* figure out which /proc/dev/net format to use */
+/* figure out which /proc/net/dev format to use */
 {
-    FILE *fp = popen("uname -r", "r"); /* still wins if /proc is out */
+    struct utsname utsname;
 
-    /* pre-linux-2.2 format -- transmit packet count in 8th field */
-    netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d";
+    /* Linux 2.2 -- transmit packet count in 10th field */
+    netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
 
-    if (!fp)
-       return;
+    if (uname(&utsname) < 0)
+        return;
     else
     {
        int major, minor;
 
-       if (fscanf(fp, "%d.%d.%*d", &major, &minor) >= 2
-                                       && major >= 2 && minor >= 2)
-           /* Linux 2.2 -- transmit packet count in 10th field */
-           netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
-       pclose(fp);
+       if (sscanf(utsname.release, "%d.%d.%*d", &major, &minor) >= 2
+                                       && !(major >= 2 && minor >= 2))
+           /* pre-linux-2.2 format -- transmit packet count in 8th field */
+           netdevfmt = "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d";
     }
 }