aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2000-08-09 11:03:07 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2000-08-09 11:03:07 +0000
commitfc2a80a97829537355a889ed4bf564ca5b6a9c75 (patch)
tree88f2e6628127bfd6570c90a5cf134e0bc19d733b
parent1645d61018c24013525f3953613aaea56714bab4 (diff)
downloadlcd4linux-fc2a80a97829537355a889ed4bf564ca5b6a9c75.tar.gz
[lcd4linux @ 2000-08-09 11:03:07 by reinelt]
fixed a bug in system.c where the format of /proc/net/dev was not correctly detected and parsed with different kernels git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@62 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--system.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/system.c b/system.c
index 97ea6ec..e063543 100644
--- a/system.c
+++ b/system.c
@@ -1,4 +1,4 @@
-/* $Id: system.c,v 1.14 2000/08/09 09:50:29 reinelt Exp $
+/* $Id: system.c,v 1.15 2000/08/09 11:03:07 reinelt Exp $
*
* system status retreivement
*
@@ -20,6 +20,11 @@
*
*
* $Log: system.c,v $
+ * Revision 1.15 2000/08/09 11:03:07 reinelt
+ *
+ * fixed a bug in system.c where the format of /proc/net/dev was not correctly
+ * detected and parsed with different kernels
+ *
* Revision 1.14 2000/08/09 09:50:29 reinelt
*
* opened 0.98 development
@@ -548,6 +553,8 @@ int Disk (int *r, int *w)
int Net (int *rx, int *tx, int *bytes)
{
char buffer[4096], *p, *s;
+ static char *proc_net_dev_fmt=NULL;
+ static int proc_net_dev_bytes=0;
static int fd=-2;
unsigned long pkg_rx, pkg_tx;
@@ -558,6 +565,22 @@ int Net (int *rx, int *tx, int *bytes)
if (fd==-1) return -1;
if (fd==-2) {
+ struct utsname ubuf;
+ if (uname(&ubuf)==-1) {
+ perror ("uname() failed");
+ fd=-1;
+ return -1;
+ }
+ if (strncmp(ubuf.release,"2.0.",4)==0) {
+ debug ("using old /proc/net/dev format\n");
+ proc_net_dev_fmt=" eth%*d: %ld %*d %*d %*d %*d %ld";
+ proc_net_dev_bytes=0;
+ } else {
+ debug ("using new /proc/net/dev format\n");
+ proc_net_dev_fmt=" eth%*d: %ld %*d %*d %*d %*d %*d %*d %*d %ld";
+ proc_net_dev_bytes=1;
+ }
+
fd = open("/proc/net/dev", O_RDONLY | O_NDELAY);
if (fd==-1) {
perror ("open(/proc/net/dev) failed");
@@ -583,24 +606,16 @@ int Net (int *rx, int *tx, int *bytes)
p=buffer;
while ((s=strsep(&p, "\n"))) {
unsigned long r, t;
-
- if (sscanf (s, " eth%*d:%ld %*d %*d %*d %*d %*d %*d %*d %ld %*d %*d %*d %*d %*d %*d %*d", &r, &t)==2) {
+ if (sscanf (s, proc_net_dev_fmt, &r, &t)==2) {
pkg_rx+=r;
pkg_tx+=t;
- *bytes=1;
- } else {
- if (sscanf (s, " eth%*d:%*d: %ld %*d %*d %*d %*d %ld %*d %*d %*d %*d %*d", &r, &t)==2 ||
- sscanf (s, " eth%*d:%ld %*d %*d %*d %*d %ld %*d %*d %*d %*d %*d", &r, &t)==2) {
- pkg_rx+=r;
- pkg_tx+=t;
- *bytes=0;
- }
}
}
-
+
*rx=smooth("net_rx", 500, pkg_rx);
*tx=smooth("net_tx", 500, pkg_tx);
-
+ *bytes=proc_net_dev_bytes;
+
return 0;
}