aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1999-01-31 18:23:17 +0000
committerEric S. Raymond <esr@thyrsus.com>1999-01-31 18:23:17 +0000
commit1715ab1008073e39d9355e58fea0a6fa62f9ebd7 (patch)
tree7f20db02e04b95535c5a01ec6d4e94edceb73779
parentd460f445287037708d6962fff4082704164850e9 (diff)
downloadfetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.tar.gz
fetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.tar.bz2
fetchmail-1715ab1008073e39d9355e58fea0a6fa62f9ebd7.zip
Move /proc/net/dev derivation to runtime.
svn path=/trunk/; revision=2367
-rw-r--r--NEWS2
-rw-r--r--acconfig.h3
-rw-r--r--configure.in11
-rw-r--r--fetchmail.c4
-rw-r--r--fetchmail.h1
-rw-r--r--interface.c33
6 files changed, 32 insertions, 22 deletions
diff --git a/NEWS b/NEWS
index 8c38593c..349e2bf6 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@
fetchmail-4.7.7 ():
* Fixed off-by-one error in batchlimit logic (thanks to Brian Warner).
* Added MD5 checksums to web page.
+* Get kernel type (and derive /proc/net/dev format) at startup.
+* Fixes for fetchmailconf bugs reported by Gunther Leber.
There are 263 people on fetchmail-friends and 342 on fetchmail-announce.
diff --git a/acconfig.h b/acconfig.h
index 2f22e699..d0f1c611 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -112,9 +112,6 @@
/* Define if you want built-in SOCKS support */
#undef HAVE_SOCKS
-/* Define if it looks like we have new /proc/dev/net format under Linux */
-#undef HAVE_NEWPROCNETDEV
-
/* Define to the version of the distribution. */
#undef VERSION
diff --git a/configure.in b/configure.in
index d637ddd1..56098371 100644
--- a/configure.in
+++ b/configure.in
@@ -183,17 +183,6 @@ AC_TRY_LINK([#include <signal.h>
[AC_DEFINE(SYS_SIGLIST_DECLARED) AC_MSG_RESULT(yes)],
AC_MSG_RESULT(no))
-dnl Figure out whether we're using a 2.2 kernel (assuming this is Linux)
-AC_MSG_CHECKING(OS kernel major version)
-set -- `uname -r | tr '.' ' '`
-release="${1}.${2}"
-AC_MSG_RESULT($release)
-if expr "$release" '>=' '2.2' >/dev/null
-then
- AC_DEFINE(HAVE_NEWPROCNETDEV)
- AC_MSG_RESULT("assuming new /proc/dev/net format")
-fi
-
# Find the right directory to put the root-mode PID file in
for dir in "/var/run" "/etc"
do
diff --git a/fetchmail.c b/fetchmail.c
index 17d278f3..d2c31744 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -478,6 +478,10 @@ int main (int argc, char **argv)
signal(SIGHUP, SIG_IGN);
}
+#ifdef linux
+ interface_init();
+#endif /* linux */
+
/* beyond here we don't want more than one fetchmail running per user */
umask(0077);
signal(SIGABRT, termhook);
diff --git a/fetchmail.h b/fetchmail.h
index 243fd623..1e4e6c51 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -433,6 +433,7 @@ extern int MimeBodyType(unsigned char *hdrs, int WantDecode);
extern int UnMimeBodyline(unsigned char **buf, int collapsedoubledot);
/* interface.c */
+void interface_init(void);
void interface_parse(char *, struct hostdata *);
void interface_note_activity(struct hostdata *);
int interface_approve(struct hostdata *);
diff --git a/interface.c b/interface.c
index 05d34404..eeff225c 100644
--- a/interface.c
+++ b/interface.c
@@ -41,13 +41,30 @@ struct interface_pair_s {
struct in_addr interface_mask;
} *interface_pair;
-#ifdef HAVE_NEWPROCNETDEV
-/* Linux 2.2 /proc/net/dev format -- transmit packet count in 10th field */
-#define PROCNETDEV "%d %d %*d %*d %*d %d %*d %*d %*d %*d %d %*d %d"
-#else
-/* pre-linux-2.2 format -- transmit packet count in 8th field */
-#define PROCNETDEV "%d %d %*d %*d %*d %d %*d %d %*d %*d %*d %*d %d"
-#endif
+static char *netdevfmt;
+
+void interface_init(void)
+/* figure out which /roc/dev/net format to use */
+{
+ FILE *fp = fopen("/proc/sys/kernel/osrelease", "r");
+
+ /* 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";
+
+ if (!fp)
+ return;
+ else
+ {
+ int major, minor;
+
+ if (fscanf(fp, "%d.%d.%*d", &major, &minor) != 2)
+ return;
+
+ if (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";
+ }
+}
static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname,
ifinfo_t *ifinfo)
@@ -68,7 +85,7 @@ static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname,
if (!strncmp(cp, ifname, namelen) &&
cp[namelen] == ':') {
cp += namelen + 1;
- if (sscanf(cp, PROCNETDEV,
+ if (sscanf(cp, netdevfmt,
counts, counts+1, counts+2,
counts+3,&found)>4) { /* found = dummy */
/* newer kernel with byte counts */