Subject: bin/253: rpc.rstatd uses old kvm interface
To: None <gnats-admin>
From: None <root@mailhost.uni-koblenz.de>
List: netbsd-bugs
Date: 05/20/1994 06:35:03
>Number: 253
>Category: bin
>Synopsis: rpc.rstatd fails with signal
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: gnats-admin (Utility Bug People)
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri May 20 06:35:01 1994
>Originator: Charlie &
>Organization:
Uwe Arndt | arndt@uniko.uni-koblenz.de
Universitaet Koblenz, |
Rechenzentrum | Voice: +49 261 9119-642
Rheinau 1, D-56075 Koblenz, Germany | Fax: +49 261 9119-499
>Release:
>Environment:
System: NetBSD harvey.uni-koblenz.de NetBSD 0.9B NetBSD 0.9B (HARVEY) #4: Thu May 19 19:29:21 MET DST 1994 root@harvey.uni-koblenz.de:/usr/src/sys/arch/i386/compile/HARVEY i386
>Description:
rpc.rstatd fails when called from inetd with signal
>How-To-Repeat:
call rup with your own machines name
>Fix:
the following patch fixes the kvm access:
*** rstat_proc.c.orig Sun May 15 11:11:25 1994
--- rstat_proc.c Fri May 20 10:25:09 1994
***************
*** 42,47 ****
--- 42,49 ----
#include <stdlib.h>
#include <string.h>
#include <signal.h>
+ #include <fcntl.h>
+ #include <kvm.h>
#include <rpc/rpc.h>
#include <sys/socket.h>
#include <nlist.h>
***************
*** 205,210 ****
--- 207,215 ----
struct ifnet ifnet;
double avrun[3];
struct timeval tm, btm;
+ kvm_t *kvm;
+
+ kvm = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
#ifdef DEBUG
fprintf(stderr, "entering updatestat\n");
***************
*** 222,232 ****
}
sincelastreq++;
! if (kvm_read((long)nl[X_HZ].n_value, (char *)&hz, sizeof hz) != sizeof hz) {
syslog(LOG_ERR, "rstat: can't read hz from kmem\n");
exit(1);
}
! if (kvm_read((long)nl[X_CPTIME].n_value, (char *)stats_all.s1.cp_time, sizeof (stats_all.s1.cp_time))
!= sizeof (stats_all.s1.cp_time)) {
syslog(LOG_ERR, "rstat: can't read cp_time from kmem\n");
exit(1);
--- 227,237 ----
}
sincelastreq++;
! if (kvm_read(kvm, (long)nl[X_HZ].n_value, (char *)&hz, sizeof hz) != sizeof hz) {
syslog(LOG_ERR, "rstat: can't read hz from kmem\n");
exit(1);
}
! if (kvm_read(kvm, (long)nl[X_CPTIME].n_value, (char *)stats_all.s1.cp_time, sizeof (stats_all.s1.cp_time))
!= sizeof (stats_all.s1.cp_time)) {
syslog(LOG_ERR, "rstat: can't read cp_time from kmem\n");
exit(1);
***************
*** 243,249 ****
stats_all.s2.avenrun[0] = avrun[0] * FSCALE;
stats_all.s2.avenrun[1] = avrun[1] * FSCALE;
stats_all.s2.avenrun[2] = avrun[2] * FSCALE;
! if (kvm_read((long)nl[X_BOOTTIME].n_value, (char *)&btm, sizeof (stats_all.s2.boottime))
!= sizeof (stats_all.s2.boottime)) {
syslog(LOG_ERR, "rstat: can't read boottime from kmem\n");
exit(1);
--- 248,254 ----
stats_all.s2.avenrun[0] = avrun[0] * FSCALE;
stats_all.s2.avenrun[1] = avrun[1] * FSCALE;
stats_all.s2.avenrun[2] = avrun[2] * FSCALE;
! if (kvm_read(kvm, (long)nl[X_BOOTTIME].n_value, (char *)&btm, sizeof (stats_all.s2.boottime))
!= sizeof (stats_all.s2.boottime)) {
syslog(LOG_ERR, "rstat: can't read boottime from kmem\n");
exit(1);
***************
*** 257,263 ****
stats_all.s1.cp_time[1], stats_all.s1.cp_time[2], stats_all.s1.cp_time[3]);
#endif
! if (kvm_read((long)nl[X_CNT].n_value, (char *)&cnt, sizeof cnt) != sizeof cnt) {
syslog(LOG_ERR, "rstat: can't read cnt from kmem\n");
exit(1);
}
--- 262,268 ----
stats_all.s1.cp_time[1], stats_all.s1.cp_time[2], stats_all.s1.cp_time[3]);
#endif
! if (kvm_read(kvm, (long)nl[X_CNT].n_value, (char *)&cnt, sizeof cnt) != sizeof cnt) {
syslog(LOG_ERR, "rstat: can't read cnt from kmem\n");
exit(1);
}
***************
*** 271,277 ****
hz*(tm.tv_usec - btm.tv_usec)/1000000;
stats_all.s2.v_swtch = cnt.v_swtch;
! if (kvm_read((long)nl[X_DKXFER].n_value, (char *)stats_all.s1.dk_xfer, sizeof (stats_all.s1.dk_xfer))
!= sizeof (stats_all.s1.dk_xfer)) {
syslog(LOG_ERR, "rstat: can't read dk_xfer from kmem\n");
exit(1);
--- 276,282 ----
hz*(tm.tv_usec - btm.tv_usec)/1000000;
stats_all.s2.v_swtch = cnt.v_swtch;
! if (kvm_read(kvm, (long)nl[X_DKXFER].n_value, (char *)stats_all.s1.dk_xfer, sizeof (stats_all.s1.dk_xfer))
!= sizeof (stats_all.s1.dk_xfer)) {
syslog(LOG_ERR, "rstat: can't read dk_xfer from kmem\n");
exit(1);
***************
*** 283,289 ****
stats_all.s1.if_oerrors = 0;
stats_all.s1.if_collisions = 0;
for (off = firstifnet, i = 0; off && i < numintfs; i++) {
! if (kvm_read(off, (char *)&ifnet, sizeof ifnet) != sizeof ifnet) {
syslog(LOG_ERR, "rstat: can't read ifnet from kmem\n");
exit(1);
}
--- 288,294 ----
stats_all.s1.if_oerrors = 0;
stats_all.s1.if_collisions = 0;
for (off = firstifnet, i = 0; off && i < numintfs; i++) {
! if (kvm_read(kvm, off, (char *)&ifnet, sizeof ifnet) != sizeof ifnet) {
syslog(LOG_ERR, "rstat: can't read ifnet from kmem\n");
exit(1);
}
***************
*** 297,315 ****
gettimeofday((struct timeval *)&stats_all.s3.curtime,
(struct timezone *) 0);
alarm(1);
}
setup()
{
struct ifnet ifnet;
int off;
! if (kvm_nlist(nl) != 0) {
syslog(LOG_ERR, "rstatd: Can't get namelist.");
exit (1);
}
! if (kvm_read((long)nl[X_IFNET].n_value, &firstifnet,
sizeof(int)) != sizeof(int)) {
syslog(LOG_ERR, "rstat: can't read firstifnet from kmem\n");
exit(1);
--- 302,324 ----
gettimeofday((struct timeval *)&stats_all.s3.curtime,
(struct timezone *) 0);
alarm(1);
+ kvm_close(kvm);
}
setup()
{
struct ifnet ifnet;
int off;
+ kvm_t *kvm;
+
+ kvm = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
! if (kvm_nlist(kvm,nl) != 0) {
syslog(LOG_ERR, "rstatd: Can't get namelist.");
exit (1);
}
! if (kvm_read(kvm, (long)nl[X_IFNET].n_value, &firstifnet,
sizeof(int)) != sizeof(int)) {
syslog(LOG_ERR, "rstat: can't read firstifnet from kmem\n");
exit(1);
***************
*** 317,329 ****
numintfs = 0;
for (off = firstifnet; off;) {
! if (kvm_read(off, (char *)&ifnet, sizeof ifnet) != sizeof ifnet) {
syslog(LOG_ERR, "rstat: can't read ifnet from kmem\n");
exit(1);
}
numintfs++;
off = (int) ifnet.if_next;
}
}
/*
--- 326,339 ----
numintfs = 0;
for (off = firstifnet; off;) {
! if (kvm_read(kvm, off, (char *)&ifnet, sizeof ifnet) != sizeof ifnet) {
syslog(LOG_ERR, "rstat: can't read ifnet from kmem\n");
exit(1);
}
numintfs++;
off = (int) ifnet.if_next;
}
+ kvm_close(kvm);
}
/*
***************
*** 333,348 ****
{
int i, cnt;
long xfer[DK_NDRIVE];
! if (kvm_nlist(nl) != 0) {
syslog(LOG_ERR, "rstatd: Can't get namelist.");
exit (1);
}
! if (kvm_read((long)nl[X_DKXFER].n_value, (char *)xfer, sizeof xfer)!= sizeof xfer) {
syslog(LOG_ERR, "rstat: can't read kmem\n");
exit(1);
}
cnt = 0;
for (i=0; i < DK_NDRIVE; i++)
cnt += xfer[i];
--- 343,361 ----
{
int i, cnt;
long xfer[DK_NDRIVE];
+ kvm_t *kvm;
! kvm = kvm_open(NULL,NULL,NULL,O_RDONLY,"kvm_open");
! if (kvm_nlist(kvm,nl) != 0) {
syslog(LOG_ERR, "rstatd: Can't get namelist.");
exit (1);
}
! if (kvm_read(kvm, (long)nl[X_DKXFER].n_value, (char *)xfer, sizeof xfer)!= sizeof xfer) {
syslog(LOG_ERR, "rstat: can't read kmem\n");
exit(1);
}
+ kvm_close(kvm);
cnt = 0;
for (i=0; i < DK_NDRIVE; i++)
cnt += xfer[i];
>Audit-Trail:
>Unformatted:
------------------------------------------------------------------------------