1999-01-12 01:39:59 +03:00
|
|
|
/* $NetBSD: rstat_proc.c,v 1.27 1999/01/11 22:40:00 kleink Exp $ */
|
1996-08-31 00:15:06 +04:00
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
/*
|
|
|
|
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
|
|
|
* unrestricted use provided that this legend is included on all tape
|
|
|
|
* media and as a part of the software program in whole or part. Users
|
|
|
|
* may copy or modify Sun RPC without charge, but are not authorized
|
|
|
|
* to license or distribute it to anyone else except as part of a product or
|
|
|
|
* program developed by the user.
|
|
|
|
*
|
|
|
|
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
|
|
|
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
|
|
|
*
|
|
|
|
* Sun RPC is provided with no support and without any obligation on the
|
|
|
|
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
|
|
|
* modification or enhancement.
|
|
|
|
*
|
|
|
|
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
|
|
|
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
|
|
|
* OR ANY PART THEREOF.
|
|
|
|
*
|
|
|
|
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
|
|
|
* or profits or other special, indirect and consequential damages, even if
|
|
|
|
* Sun has been advised of the possibility of such damages.
|
|
|
|
*
|
|
|
|
* Sun Microsystems, Inc.
|
|
|
|
* 2550 Garcia Avenue
|
|
|
|
* Mountain View, California 94043
|
|
|
|
*/
|
1997-10-07 15:28:16 +04:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
1993-08-01 21:54:45 +04:00
|
|
|
#ifndef lint
|
1997-10-07 15:28:16 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";
|
|
|
|
static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";
|
|
|
|
#else
|
1999-01-12 01:39:59 +03:00
|
|
|
__RCSID("$NetBSD: rstat_proc.c,v 1.27 1999/01/11 22:40:00 kleink Exp $");
|
1997-10-07 15:28:16 +04:00
|
|
|
#endif
|
1993-08-01 21:54:45 +04:00
|
|
|
#endif
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rstat service: built with rstat.x and derived from rpc.rstatd.c
|
1993-08-01 21:54:45 +04:00
|
|
|
*
|
|
|
|
* Copyright (c) 1984 by Sun Microsystems, Inc.
|
1993-06-03 23:26:09 +04:00
|
|
|
*/
|
|
|
|
|
1998-02-07 15:04:37 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
1999-01-12 01:39:59 +03:00
|
|
|
#include <errno.h>
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <stdio.h>
|
1993-09-23 22:42:39 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
1994-05-25 23:40:40 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#ifdef BSD
|
1998-02-07 15:04:37 +03:00
|
|
|
#include <sys/sysctl.h>
|
1998-02-12 08:27:51 +03:00
|
|
|
#if defined(UVM)
|
1998-02-07 15:04:37 +03:00
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
#else
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <sys/vmmeter.h>
|
1998-02-07 15:04:37 +03:00
|
|
|
#endif
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <sys/dkstat.h>
|
1997-02-22 04:41:34 +03:00
|
|
|
#include "dkstats.h"
|
1993-06-03 23:26:09 +04:00
|
|
|
#else
|
|
|
|
#include <sys/dk.h>
|
|
|
|
#endif
|
1998-02-07 15:04:37 +03:00
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <net/if.h>
|
1993-09-23 22:42:39 +04:00
|
|
|
|
1998-02-07 15:04:37 +03:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
*
|
|
|
|
* this is a huge hack to stop `struct pmap' being
|
|
|
|
* defined twice!
|
|
|
|
*/
|
1998-02-11 20:27:37 +03:00
|
|
|
#define _RPC_PMAP_PROT_H_
|
1998-02-07 15:04:37 +03:00
|
|
|
#include <rpc/rpc.h>
|
|
|
|
|
1993-09-23 22:42:39 +04:00
|
|
|
#undef FSHIFT /* Use protocol's shift and scale values */
|
|
|
|
#undef FSCALE
|
1993-12-07 12:09:12 +03:00
|
|
|
#undef DK_NDRIVE
|
1994-05-15 02:12:06 +04:00
|
|
|
#undef CPUSTATES
|
|
|
|
#undef if_ipackets
|
|
|
|
#undef if_ierrors
|
|
|
|
#undef if_opackets
|
|
|
|
#undef if_oerrors
|
|
|
|
#undef if_collisions
|
1993-06-03 23:26:09 +04:00
|
|
|
#include <rpcsvc/rstat.h>
|
|
|
|
|
1994-05-25 23:40:40 +04:00
|
|
|
#ifdef BSD
|
|
|
|
#define BSD_CPUSTATES 5 /* Use protocol's idea of CPU states */
|
|
|
|
int cp_xlat[CPUSTATES] = { CP_USER, CP_NICE, CP_SYS, CP_IDLE };
|
|
|
|
#endif
|
|
|
|
|
1993-06-03 23:26:09 +04:00
|
|
|
struct nlist nl[] = {
|
1998-02-07 15:04:37 +03:00
|
|
|
#define X_IFNET 0
|
1993-06-03 23:26:09 +04:00
|
|
|
{ "_ifnet" },
|
1998-02-07 15:04:37 +03:00
|
|
|
#if !defined(UVM)
|
1998-02-12 08:27:51 +03:00
|
|
|
#define X_CNT 1
|
1998-02-07 15:04:37 +03:00
|
|
|
{ "_cnt" },
|
|
|
|
#endif
|
1996-10-01 08:01:52 +04:00
|
|
|
{ NULL },
|
1993-06-03 23:26:09 +04:00
|
|
|
};
|
1997-02-22 04:41:34 +03:00
|
|
|
|
|
|
|
extern int dk_ndrive; /* From dkstats.c */
|
|
|
|
extern struct _disk cur, last;
|
|
|
|
int hz;
|
|
|
|
char *memf = NULL, *nlistf = NULL;
|
|
|
|
|
1995-06-20 01:59:31 +04:00
|
|
|
struct ifnet_head ifnetq; /* chain of ethernet interfaces */
|
1994-12-23 17:29:31 +03:00
|
|
|
int numintfs;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
extern int from_inetd;
|
|
|
|
int sincelastreq = 0; /* number of alarms since last request */
|
|
|
|
extern int closedown;
|
1994-05-25 23:40:40 +04:00
|
|
|
kvm_t *kfd;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
union {
|
1995-01-13 22:37:52 +03:00
|
|
|
struct stats s1;
|
|
|
|
struct statsswtch s2;
|
|
|
|
struct statstime s3;
|
1993-06-03 23:26:09 +04:00
|
|
|
} stats_all;
|
|
|
|
|
1997-10-07 15:28:16 +04:00
|
|
|
extern void dkreadstats __P((void));
|
1998-07-19 21:48:15 +04:00
|
|
|
extern int dkinit __P((int, gid_t));
|
1997-10-07 15:28:16 +04:00
|
|
|
|
|
|
|
void updatestat __P((int));
|
|
|
|
void setup __P((void));
|
|
|
|
void stat_init __P((void));
|
|
|
|
int havedisk __P((void));
|
|
|
|
void rstat_service __P((struct svc_req *, SVCXPRT *));
|
|
|
|
|
1998-03-30 05:53:45 +04:00
|
|
|
static int stat_is_init = 0;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
#ifndef FSCALE
|
|
|
|
#define FSCALE (1 << 8)
|
|
|
|
#endif
|
|
|
|
|
1997-10-07 15:28:16 +04:00
|
|
|
void
|
1993-06-03 23:26:09 +04:00
|
|
|
stat_init()
|
|
|
|
{
|
1995-01-13 22:37:52 +03:00
|
|
|
stat_is_init = 1;
|
|
|
|
setup();
|
1997-10-07 15:28:16 +04:00
|
|
|
updatestat(0);
|
1995-01-13 22:37:52 +03:00
|
|
|
(void) signal(SIGALRM, updatestat);
|
|
|
|
alarm(1);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
statstime *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_stats_3_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:37:52 +03:00
|
|
|
if (!stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
|
|
|
return (&stats_all.s3);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
statsswtch *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_stats_2_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:37:52 +03:00
|
|
|
if (!stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s2.if_opackets = stats_all.s3.if_opackets;
|
1995-01-13 22:37:52 +03:00
|
|
|
return (&stats_all.s2);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
stats *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_stats_1_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:37:52 +03:00
|
|
|
if (!stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s1.if_opackets = stats_all.s3.if_opackets;
|
1995-01-13 22:37:52 +03:00
|
|
|
return (&stats_all.s1);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_havedisk_3_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-01-13 22:37:52 +03:00
|
|
|
static u_int have;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
1995-01-13 22:37:52 +03:00
|
|
|
if (!stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
|
|
|
have = havedisk();
|
|
|
|
return (&have);
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_havedisk_2_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-06-24 19:57:18 +04:00
|
|
|
return (rstatproc_havedisk_3_svc(arg, rqstp));
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
1995-06-24 19:57:18 +04:00
|
|
|
rstatproc_havedisk_1_svc(arg, rqstp)
|
|
|
|
void *arg;
|
|
|
|
struct svc_req *rqstp;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1995-06-24 19:57:18 +04:00
|
|
|
return (rstatproc_havedisk_3_svc(arg, rqstp));
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-10-07 15:28:16 +04:00
|
|
|
updatestat(dummy)
|
|
|
|
int dummy;
|
1993-06-03 23:26:09 +04:00
|
|
|
{
|
1994-12-23 17:29:31 +03:00
|
|
|
long off;
|
1997-02-22 04:41:34 +03:00
|
|
|
int i;
|
1998-02-07 15:04:37 +03:00
|
|
|
size_t len;
|
|
|
|
int mib[2];
|
1998-02-12 08:27:51 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
struct uvmexp uvmexp;
|
1998-02-07 15:04:37 +03:00
|
|
|
#else
|
1994-04-15 07:21:24 +04:00
|
|
|
struct vmmeter cnt;
|
1998-02-07 15:04:37 +03:00
|
|
|
#endif
|
1993-06-03 23:26:09 +04:00
|
|
|
struct ifnet ifnet;
|
|
|
|
double avrun[3];
|
|
|
|
struct timeval tm, btm;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_DEBUG, "entering updatestat");
|
1993-06-03 23:26:09 +04:00
|
|
|
#endif
|
|
|
|
if (sincelastreq >= closedown) {
|
|
|
|
#ifdef DEBUG
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_DEBUG, "about to closedown");
|
1993-06-03 23:26:09 +04:00
|
|
|
#endif
|
|
|
|
if (from_inetd)
|
|
|
|
exit(0);
|
|
|
|
else {
|
|
|
|
stat_is_init = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sincelastreq++;
|
|
|
|
|
1997-02-22 04:41:34 +03:00
|
|
|
/*
|
|
|
|
* dkreadstats reads in the "disk_count" as well as the "disklist"
|
|
|
|
* statistics. It also retrieves "hz" and the "cp_time" array.
|
|
|
|
*/
|
|
|
|
dkreadstats();
|
1997-07-20 00:25:44 +04:00
|
|
|
memset(stats_all.s3.dk_xfer, 0, sizeof(stats_all.s3.dk_xfer));
|
1997-02-22 04:41:34 +03:00
|
|
|
for (i = 0; i < dk_ndrive && i < DK_NDRIVE; i++)
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.dk_xfer[i] = cur.dk_xfer[i];
|
1997-02-22 04:41:34 +03:00
|
|
|
|
1994-05-25 23:40:40 +04:00
|
|
|
#ifdef BSD
|
|
|
|
for (i = 0; i < CPUSTATES; i++)
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.cp_time[i] = cur.cp_time[cp_xlat[i]];
|
1994-05-25 23:40:40 +04:00
|
|
|
#else
|
|
|
|
if (kvm_read(kfd, (long)nl[X_CPTIME].n_value,
|
1997-07-20 00:25:44 +04:00
|
|
|
(char *)stats_all.s3.cp_time,
|
|
|
|
sizeof (stats_all.s3.cp_time))
|
|
|
|
!= sizeof (stats_all.s3.cp_time)) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "can't read cp_time from kmem");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1994-05-25 23:40:40 +04:00
|
|
|
#endif
|
1993-06-03 23:26:09 +04:00
|
|
|
#ifdef BSD
|
|
|
|
(void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
|
|
|
|
#endif
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.avenrun[0] = avrun[0] * FSCALE;
|
|
|
|
stats_all.s3.avenrun[1] = avrun[1] * FSCALE;
|
|
|
|
stats_all.s3.avenrun[2] = avrun[2] * FSCALE;
|
1998-02-12 08:27:51 +03:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_BOOTTIME;
|
|
|
|
len = sizeof(btm);
|
|
|
|
if (sysctl(mib, 2, &btm, &len, NULL, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "can't sysctl kern.boottime");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.boottime.tv_sec = btm.tv_sec;
|
|
|
|
stats_all.s3.boottime.tv_usec = btm.tv_usec;
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1997-07-20 00:25:44 +04:00
|
|
|
syslog(LOG_DEBUG, "%d %d %d %d\n", stats_all.s3.cp_time[0],
|
|
|
|
stats_all.s3.cp_time[1], stats_all.s3.cp_time[2], stats_all.s3.cp_time[3]);
|
1993-06-03 23:26:09 +04:00
|
|
|
#endif
|
|
|
|
|
1998-02-07 15:04:37 +03:00
|
|
|
#if defined(UVM)
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_UVMEXP;
|
|
|
|
len = sizeof(uvmexp);
|
|
|
|
if (sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "can't sysctl vm.uvmexp");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
stats_all.s3.v_pgpgin = uvmexp.fltanget;
|
|
|
|
stats_all.s3.v_pgpgout = uvmexp.pdpageouts;
|
|
|
|
stats_all.s3.v_pswpin = uvmexp.swapins;
|
|
|
|
stats_all.s3.v_pswpout = uvmexp.swapouts;
|
|
|
|
stats_all.s3.v_intr = uvmexp.intrs;
|
|
|
|
stats_all.s3.v_swtch = uvmexp.swtch;
|
|
|
|
#else
|
1994-05-25 23:40:40 +04:00
|
|
|
if (kvm_read(kfd, (long)nl[X_CNT].n_value, (char *)&cnt, sizeof cnt) !=
|
|
|
|
sizeof cnt) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "can't read cnt from kmem");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.v_pgpgin = cnt.v_pgpgin;
|
|
|
|
stats_all.s3.v_pgpgout = cnt.v_pgpgout;
|
|
|
|
stats_all.s3.v_pswpin = cnt.v_pswpin;
|
|
|
|
stats_all.s3.v_pswpout = cnt.v_pswpout;
|
|
|
|
stats_all.s3.v_intr = cnt.v_intr;
|
1998-02-07 15:04:37 +03:00
|
|
|
stats_all.s3.v_swtch = cnt.v_swtch;
|
|
|
|
#endif
|
1993-06-03 23:26:09 +04:00
|
|
|
gettimeofday(&tm, (struct timezone *) 0);
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.v_intr -= hz*(tm.tv_sec - btm.tv_sec) +
|
1993-06-03 23:26:09 +04:00
|
|
|
hz*(tm.tv_usec - btm.tv_usec)/1000000;
|
1997-02-22 04:41:34 +03:00
|
|
|
|
1997-07-20 00:25:44 +04:00
|
|
|
stats_all.s3.if_ipackets = 0;
|
|
|
|
stats_all.s3.if_opackets = 0;
|
|
|
|
stats_all.s3.if_ierrors = 0;
|
|
|
|
stats_all.s3.if_oerrors = 0;
|
|
|
|
stats_all.s3.if_collisions = 0;
|
1995-06-20 01:59:31 +04:00
|
|
|
for (off = (long)ifnetq.tqh_first, i = 0; off && i < numintfs; i++) {
|
1994-05-25 23:40:40 +04:00
|
|
|
if (kvm_read(kfd, off, (char *)&ifnet, sizeof ifnet) !=
|
|
|
|
sizeof ifnet) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "can't read ifnet from kmem");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-07-20 00:25:44 +04:00
|
|
|
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;
|
1995-06-20 01:59:31 +04:00
|
|
|
off = (long)ifnet.if_list.tqe_next;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
gettimeofday((struct timeval *)&stats_all.s3.curtime,
|
|
|
|
(struct timezone *) 0);
|
|
|
|
alarm(1);
|
|
|
|
}
|
|
|
|
|
1997-10-07 15:28:16 +04:00
|
|
|
void
|
1993-06-03 23:26:09 +04:00
|
|
|
setup()
|
|
|
|
{
|
|
|
|
struct ifnet ifnet;
|
1994-12-23 17:29:31 +03:00
|
|
|
long off;
|
1994-05-25 23:40:40 +04:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
|
|
|
|
|
|
|
kfd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
|
|
|
|
if (kfd == NULL) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "%s", errbuf);
|
1994-05-25 23:40:40 +04:00
|
|
|
exit (1);
|
|
|
|
}
|
1993-06-03 23:26:09 +04:00
|
|
|
|
1994-05-25 23:40:40 +04:00
|
|
|
if (kvm_nlist(kfd, nl) != 0) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "can't get namelist");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
1995-06-20 01:59:31 +04:00
|
|
|
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");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
numintfs = 0;
|
1995-06-20 01:59:31 +04:00
|
|
|
for (off = (long)ifnetq.tqh_first; off;) {
|
1994-05-25 23:40:40 +04:00
|
|
|
if (kvm_read(kfd, off, (char *)&ifnet, sizeof ifnet) !=
|
|
|
|
sizeof ifnet) {
|
1995-01-13 22:37:52 +03:00
|
|
|
syslog(LOG_ERR, "can't read ifnet from kmem");
|
1993-06-03 23:26:09 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
numintfs++;
|
1995-06-20 01:59:31 +04:00
|
|
|
off = (long)ifnet.if_list.tqe_next;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
1998-07-19 21:48:15 +04:00
|
|
|
dkinit(0, getgid());
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns true if have a disk
|
|
|
|
*/
|
1994-05-25 23:40:40 +04:00
|
|
|
int
|
1993-06-03 23:26:09 +04:00
|
|
|
havedisk()
|
|
|
|
{
|
1997-02-22 04:41:34 +03:00
|
|
|
return dk_ndrive != 0;
|
1993-06-03 23:26:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rstat_service(rqstp, transp)
|
|
|
|
struct svc_req *rqstp;
|
|
|
|
SVCXPRT *transp;
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
int fill;
|
|
|
|
} argument;
|
|
|
|
char *result;
|
1995-07-09 04:30:11 +04:00
|
|
|
xdrproc_t xdr_argument, xdr_result;
|
1995-06-24 19:57:18 +04:00
|
|
|
char *(*local) __P((void *, struct svc_req *));
|
1993-06-03 23:26:09 +04:00
|
|
|
|
|
|
|
switch (rqstp->rq_proc) {
|
|
|
|
case NULLPROC:
|
|
|
|
(void)svc_sendreply(transp, xdr_void, (char *)NULL);
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
case RSTATPROC_STATS:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_argument = (xdrproc_t)xdr_void;
|
|
|
|
xdr_result = (xdrproc_t)xdr_statstime;
|
1993-06-03 23:26:09 +04:00
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RSTATVERS_ORIG:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_stats_1_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
case RSTATVERS_SWTCH:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_stats_2_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
case RSTATVERS_TIME:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_stats_3_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
default:
|
1993-06-09 23:54:03 +04:00
|
|
|
svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
|
1993-06-03 23:26:09 +04:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RSTATPROC_HAVEDISK:
|
1995-07-09 04:30:11 +04:00
|
|
|
xdr_argument = (xdrproc_t)xdr_void;
|
|
|
|
xdr_result = (xdrproc_t)xdr_u_int;
|
1993-06-03 23:26:09 +04:00
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RSTATVERS_ORIG:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_havedisk_1_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
case RSTATVERS_SWTCH:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_havedisk_2_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
case RSTATVERS_TIME:
|
1995-06-24 19:57:18 +04:00
|
|
|
local = (char *(*) __P((void *, struct svc_req *)))
|
|
|
|
rstatproc_havedisk_3_svc;
|
1993-06-03 23:26:09 +04:00
|
|
|
break;
|
|
|
|
default:
|
1993-06-09 23:54:03 +04:00
|
|
|
svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
|
1993-06-03 23:26:09 +04:00
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_noproc(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
1998-08-10 06:57:23 +04:00
|
|
|
memset((char *)&argument, 0, sizeof(argument));
|
1994-12-23 17:29:31 +03:00
|
|
|
if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
|
1993-06-03 23:26:09 +04:00
|
|
|
svcerr_decode(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
result = (*local)(&argument, rqstp);
|
|
|
|
if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
|
|
|
|
svcerr_systemerr(transp);
|
|
|
|
}
|
1994-12-23 17:29:31 +03:00
|
|
|
if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
|
1993-06-03 23:26:09 +04:00
|
|
|
(void)fprintf(stderr, "unable to free arguments\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
leave:
|
|
|
|
if (from_inetd)
|
|
|
|
exit(0);
|
|
|
|
}
|