diff options
| author | joerg <joerg@NetBSD.org> | 2014-06-02 18:17:51 +0000 |
|---|---|---|
| committer | joerg <joerg@NetBSD.org> | 2014-06-02 18:17:51 +0000 |
| commit | 31a5065d22f2d08e2e562db55563eda2fd03a149 (patch) | |
| tree | 7357abaf390fe37f0ee8d7a64a3e9d051ec61d63 /libexec | |
| parent | 9d03c09b1a2375ca8fa226cf8b0135af8e586cd5 (diff) | |
Remove majority of KVM usage.
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/rpc.rstatd/rstat_proc.c | 107 |
1 files changed, 28 insertions, 79 deletions
diff --git a/libexec/rpc.rstatd/rstat_proc.c b/libexec/rpc.rstatd/rstat_proc.c index 171fcbd8e69..ea7e158b152 100644 --- a/libexec/rpc.rstatd/rstat_proc.c +++ b/libexec/rpc.rstatd/rstat_proc.c @@ -1,4 +1,4 @@ -/* $NetBSD: rstat_proc.c,v 1.48 2014/06/02 17:40:05 joerg Exp $ */ +/* $NetBSD: rstat_proc.c,v 1.49 2014/06/02 18:17:51 joerg Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: rstat_proc.c,v 1.48 2014/06/02 17:40:05 joerg Exp $"); +__RCSID("$NetBSD: rstat_proc.c,v 1.49 2014/06/02 18:17:51 joerg Exp $"); /* * rstat service: built with rstat.x and derived from rpc.rstatd.c @@ -41,6 +41,7 @@ __RCSID("$NetBSD: rstat_proc.c,v 1.48 2014/06/02 17:40:05 joerg Exp $"); #include <sys/param.h> #include <sys/sched.h> #include <sys/socket.h> +#include <sys/ioctl.h> #include <errno.h> #include <stdio.h> @@ -48,7 +49,6 @@ __RCSID("$NetBSD: rstat_proc.c,v 1.48 2014/06/02 17:40:05 joerg Exp $"); #include <string.h> #include <signal.h> #include <fcntl.h> -#include <kvm.h> #include <limits.h> #include <nlist.h> #include <syslog.h> @@ -89,13 +89,9 @@ struct nlist nl[] = { int hz; char *memf = NULL, *nlistf = NULL; -struct ifnet_head ifnetq; /* chain of ethernet interfaces */ -unsigned int numintfs; - extern int from_inetd; int sincelastreq = 0; /* number of alarms since last request */ extern int closedown; -kvm_t *kfd; union { struct stats s1; @@ -104,8 +100,6 @@ union { } stats_all; void updatestat(int); -void setup(void); -void setup_kd_once(void); void stat_init(void); int havedisk(void); void rstat_service(struct svc_req *, SVCXPRT *); @@ -120,7 +114,7 @@ void stat_init(void) { stat_is_init = 1; - setup(); + drvinit(0); updatestat(0); (void) signal(SIGALRM, updatestat); alarm(1); @@ -182,12 +176,11 @@ rstatproc_havedisk_1_svc(void *arg, struct svc_req *rqstp) void updatestat(int dummy) { - long off; - unsigned int i; - size_t len; - int mib[2]; + struct if_nameindex *ifps; + struct ifdatareq ifdr; + size_t i, len; + int mib[2], s; struct uvmexp_sysctl uvmexp; - struct ifnet ifnet; double avrun[3]; struct timeval tm, btm; @@ -261,76 +254,32 @@ updatestat(int dummy) stats_all.s3.if_ierrors = 0; stats_all.s3.if_oerrors = 0; stats_all.s3.if_collisions = 0; - for (off = (long)ifnetq.tqh_first, i = 0; off && i < numintfs; i++) { - if (kvm_read(kfd, off, (char *)&ifnet, sizeof ifnet) != - sizeof ifnet) { - syslog(LOG_ERR, "can't read ifnet from kmem"); - exit(1); - } - stats_all.s3.if_ipackets += ifnet.if_data.ifi_ipackets; - stats_all.s3.if_opackets += ifnet.if_data.ifi_opackets; - stats_all.s3.if_ierrors += ifnet.if_data.ifi_ierrors; - stats_all.s3.if_oerrors += ifnet.if_data.ifi_oerrors; - stats_all.s3.if_collisions += ifnet.if_data.ifi_collisions; - off = (long)ifnet.if_list.tqe_next; + + ifps = if_nameindex(); + if (ifps == NULL) { + syslog(LOG_ERR, "can't read interface list from kernel"); + exit(1); + } + s = socket(AF_INET, SOCK_DGRAM, 0); + for (i = 0; s != -1 && ifps[i].if_name != NULL; ++i) { + strncpy(ifdr.ifdr_name, ifps[i].if_name, sizeof(ifdr.ifdr_name)); + if (ioctl(s, SIOCGIFDATA, &ifdr) != 0) + continue; + stats_all.s3.if_ipackets += ifdr.ifdr_data.ifi_ipackets; + stats_all.s3.if_opackets += ifdr.ifdr_data.ifi_opackets; + stats_all.s3.if_ierrors += ifdr.ifdr_data.ifi_ierrors; + stats_all.s3.if_oerrors += ifdr.ifdr_data.ifi_oerrors; + stats_all.s3.if_collisions += ifdr.ifdr_data.ifi_collisions; } + if (s != -1) + close(s); + if_freenameindex(ifps); + stats_all.s3.curtime.tv_sec = tm.tv_sec; stats_all.s3.curtime.tv_usec = tm.tv_usec; alarm(1); } -void -setup_kd_once(void) -{ - char errbuf[_POSIX2_LINE_MAX]; - kfd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); - if (kfd == NULL) { - syslog(LOG_ERR, "%s", errbuf); - exit (1); - } -} - -void -setup(void) -{ - struct ifnet ifnet; - long off; - static int is_kfd_setup = 0; - - /* setup() is called after each dormant->active - * transition. Since we never close the kvm files - * (there's no reason), make sure we don't open them - * each time, as that can lead to exhaustion of all open - * files! */ - if (!is_kfd_setup) { - setup_kd_once(); - is_kfd_setup = 1; - } - - if (kvm_nlist(kfd, nl) != 0) { - syslog(LOG_ERR, "can't get namelist"); - exit (1); - } - - if (kvm_read(kfd, (long)nl[X_IFNET].n_value, &ifnetq, - sizeof ifnetq) != sizeof ifnetq) { - syslog(LOG_ERR, "can't read ifnet queue head from kmem"); - exit(1); - } - - numintfs = 0; - for (off = (long)ifnetq.tqh_first; off;) { - if (kvm_read(kfd, off, (char *)&ifnet, sizeof ifnet) != - sizeof ifnet) { - syslog(LOG_ERR, "can't read ifnet from kmem"); - exit(1); - } - numintfs++; - off = (long)ifnet.if_list.tqe_next; - } - drvinit(0); -} - /* * returns true if have a disk */ |
