NetBSD Problem Report #253

From gnats  Fri May 20 01:27:43 1994
Received: from infko.uni-koblenz.de (mailhost.uni-koblenz.de [141.26.4.1]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id BAA00821 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Fri, 20 May 1994 01:27:18 -0700
Message-Id: <199405200827.KAA21551@infko.uni-koblenz.de>
Date: Fri, 20 May 1994 10:27:18 +0200
From: root@mailhost.uni-koblenz.de
Reply-To: arndt@mailhost.uni-koblenz.de
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: rpc.rstatd uses old kvm interface
X-Send-Pr-Version: 3.2

>Number:         253
>Category:       bin
>Synopsis:       rpc.rstatd fails with signal
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 20 06:35:01 +0000 1994
>Closed-Date:    Wed May 25 19:41:29 +0000 1994
>Last-Modified:  
>Originator:     Charlie &
>Release:        
>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
>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];
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: pk 
State-Changed-When: Wed May 25 12:41:29 PDT 1994 
State-Changed-Why:  
Solved along the lines suggested by using new libkvm interface. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.