From c7358581ded0f95bfcbd1f969455d847191420d0 Mon Sep 17 00:00:00 2001 From: marschap Date: Thu, 20 Sep 2007 09:06:51 +0000 Subject: [PATCH] fixes for the lcpdroc client iface screen on *BSD (M.Dolze): 1. If an interface priviously been UP goes DOWN, the time when the interface changed would always show the current time. 2. If an active interface is removed from the system, the server would still show the old screens and the user will not get any notice. 3. The "first run" detection would not work if more than one interface is monitored. Now the "last_online" time is used, because this is an "per interface" value initialized to 0 at startup. 4. The TRUE/FALSE macros are used for the return values as in the other functions. --- ChangeLog | 1 + clients/lcdproc/machine_Darwin.c | 21 ++++++++++----------- clients/lcdproc/machine_FreeBSD.c | 20 ++++++++++---------- clients/lcdproc/machine_NetBSD.c | 18 +++++++++--------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc9f098..ad6fed1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,7 @@ v.0.5dev (ongoing development) + new driver shuttleVFD for USB-based Shuttle VFDs (Thien Vu) * enable building lcdproc client on FreeBSD AMD64 platform (M. Dolze) * Autoconf fixes for Net/FreeBSD (M. Dolze) + * fixes for the lcpdroc client iface screen on *BSD (M.Dolze) v.0.5.2 * fix switching on/off the Load screen in lcdproc client using the menu diff --git a/clients/lcdproc/machine_Darwin.c b/clients/lcdproc/machine_Darwin.c index 9ca08fb..c41cb24 100644 --- a/clients/lcdproc/machine_Darwin.c +++ b/clients/lcdproc/machine_Darwin.c @@ -479,7 +479,6 @@ static int swapmode(int *rettotal, int *retfree) /* Get network statistics */ int machine_get_iface_stats (IfaceInfo *interface) { - static int first_time = 1; /* is it first time we call this function? */ int rows; int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT}; size_t len; @@ -487,7 +486,6 @@ int machine_get_iface_stats (IfaceInfo *interface) len = sizeof(rows); /* get number of interfaces */ - //if (sysctlbyname("net.link.generic.system.ifcount", &rows, &len, NULL, 0) == 0) { if (sysctl(name, 5, &rows, &len, 0, 0) == 0) { interface->status = down; /* set status down by default */ @@ -506,31 +504,32 @@ int machine_get_iface_stats (IfaceInfo *interface) } /* check if its interface name matches */ if (strcmp(ifmd.ifmd_name, interface->name) == 0) { - interface->last_online = time(NULL); /* save actual time */ - - if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) - interface->status = up; /* is up */ interface->rc_byte = ifmd.ifmd_data.ifi_ibytes; interface->tr_byte = ifmd.ifmd_data.ifi_obytes; interface->rc_pkt = ifmd.ifmd_data.ifi_ipackets; interface->tr_pkt = ifmd.ifmd_data.ifi_opackets; - if (first_time) { + if (interface->last_online == 0) { interface->rc_byte_old = interface->rc_byte; interface->tr_byte_old = interface->tr_byte; interface->rc_pkt_old = interface->rc_pkt; interface->tr_pkt_old = interface->tr_pkt; - first_time = 0; /* now it isn't first time */ } - return 1; + + if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) { + interface->status = up; /* is up */ + interface->last_online = time(NULL); /* save actual time */ + } + + return (TRUE); } } /* if we are here there is no interface with the given name */ - return 0; + return (TRUE); } else { perror("read sysctl IFMIB_IFCOUNT"); - return 0; + return (FALSE); } } /* get_iface_stats() */ diff --git a/clients/lcdproc/machine_FreeBSD.c b/clients/lcdproc/machine_FreeBSD.c index 4ca6771..ce00792 100644 --- a/clients/lcdproc/machine_FreeBSD.c +++ b/clients/lcdproc/machine_FreeBSD.c @@ -439,7 +439,6 @@ static int swapmode(int *retavail, int *retfree) */ int machine_get_iface_stats (IfaceInfo *interface) { - static int first_time = 1; /* is it first time we call this function? */ int rows; int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, 0, IFDATA_GENERAL}; size_t len; @@ -461,31 +460,32 @@ int machine_get_iface_stats (IfaceInfo *interface) } /* check if its interface name matches */ if (strcmp(ifmd.ifmd_name, interface->name) == 0) { - interface->last_online = time(NULL); /* save actual time */ - - if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) - interface->status = up; /* is up */ interface->rc_byte = ifmd.ifmd_data.ifi_ibytes; interface->tr_byte = ifmd.ifmd_data.ifi_obytes; interface->rc_pkt = ifmd.ifmd_data.ifi_ipackets; interface->tr_pkt = ifmd.ifmd_data.ifi_opackets; - if (first_time) { + if (interface->last_online == 0) { interface->rc_byte_old = interface->rc_byte; interface->tr_byte_old = interface->tr_byte; interface->rc_pkt_old = interface->rc_pkt; interface->tr_pkt_old = interface->tr_pkt; - first_time = 0; /* now it isn't first time */ } - return 1; + + if ((ifmd.ifmd_flags & IFF_UP) == IFF_UP) { + interface->status = up; /* is up */ + interface->last_online = time(NULL); /* save actual time */ + } + + return (TRUE); } } /* if we are here there is no interface with the given name */ - return 0; + return (TRUE); } else { perror("read sysctlbyname"); - return 0; + return (FALSE); } } /* get_iface_stats() */ diff --git a/clients/lcdproc/machine_NetBSD.c b/clients/lcdproc/machine_NetBSD.c index 11abd72..5672fc9 100644 --- a/clients/lcdproc/machine_NetBSD.c +++ b/clients/lcdproc/machine_NetBSD.c @@ -380,7 +380,6 @@ int machine_get_uptime(double *up, double *idle) /* Get network statistics */ int machine_get_iface_stats (IfaceInfo *interface) { - static int first_time = 1; /* is it first time we call this function? */ struct ifaddrs *ifa, *ifa_ptr; struct if_data *ifd; @@ -397,30 +396,31 @@ int machine_get_iface_stats (IfaceInfo *interface) (ifa_ptr->ifa_addr->sa_family == AF_LINK)) { ifd = (struct if_data *)ifa_ptr->ifa_data; - interface->last_online = time(NULL); /* save actual time */ - - if ((ifa_ptr->ifa_flags & IFF_UP) == IFF_UP) - interface->status = up; /* is up */ interface->rc_byte = ifd->ifi_ibytes; interface->tr_byte = ifd->ifi_obytes; interface->rc_pkt = ifd->ifi_ipackets; interface->tr_pkt = ifd->ifi_opackets; - if (first_time) { + if (interface->last_online == 0) { interface->rc_byte_old = interface->rc_byte; interface->tr_byte_old = interface->tr_byte; interface->rc_pkt_old = interface->rc_pkt; interface->tr_pkt_old = interface->tr_pkt; - first_time = 0; /* now it isn't first time */ } - return 1; + + if ((ifa_ptr->ifa_flags & IFF_UP) == IFF_UP) { + interface->status = up; /* is up */ + interface->last_online = time(NULL); /* save actual time */ + } + + return (TRUE); } } freeifaddrs(ifa); /* if we are here there is no interface with the given name */ - return 0; + return (TRUE); } #endif /* __NetBSD__ */