* 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
* 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.
* Mountain View, California 94043
/*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";*/
static char rcsid
[] = "$Id: rstat_proc.c,v 1.4 1993/09/23 18:42:39 jtc Exp $";
* rstat service: built with rstat.x and derived from rpc.rstatd.c
* Copyright (c) 1984 by Sun Microsystems, Inc.
#undef FSHIFT /* Use protocol's shift and scale values */
#include <rpcsvc/rstat.h>
int firstifnet
, numintfs
; /* chain of ethernet interfaces */
int sincelastreq
= 0; /* number of alarms since last request */
* BSD has the kvm facility for getting info from the
* kernel. If you aren't on BSD, this surfices.
kvm_read(off
, addr
, size
)
if (lseek(kmem
, (long)off
, 0) == -1)
return(read(kmem
, addr
, size
));
int n
= nlist("/vmunix", nl
);
if ((kmem
= open("/dev/kmem", 0)) < 0)
(void) signal(SIGALRM
, updatestat
);
return(rstatproc_havedisk_3());
return(rstatproc_havedisk_3());
fprintf(stderr
, "entering updatestat\n");
if (sincelastreq
>= closedown
) {
fprintf(stderr
, "about to closedown\n");
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");
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");
if (kvm_read((long)nl
[X_AVENRUN
].n_value
, (char *)avrun
, sizeof (avrun
)) != sizeof (avrun
)) {
syslog(LOG_ERR
, "rstat: can't read avenrun from kmem\n");
(void)getloadavg(avrun
, sizeof(avrun
) / sizeof(avrun
[0]));
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");
stats_all
.s2
.boottime
.tv_sec
= btm
.tv_sec
;
stats_all
.s2
.boottime
.tv_usec
= btm
.tv_usec
;
fprintf(stderr
, "%d %d %d %d\n", stats_all
.s1
.cp_time
[0],
stats_all
.s1
.cp_time
[1], stats_all
.s1
.cp_time
[2], stats_all
.s1
.cp_time
[3]);
if (kvm_read((long)nl
[X_SUM
].n_value
, (char *)&sum
, sizeof sum
) != sizeof sum
) {
syslog(LOG_ERR
, "rstat: can't read sum from kmem\n");
stats_all
.s1
.v_pgpgin
= sum
.v_pgpgin
;
stats_all
.s1
.v_pgpgout
= sum
.v_pgpgout
;
stats_all
.s1
.v_pswpin
= sum
.v_pswpin
;
stats_all
.s1
.v_pswpout
= sum
.v_pswpout
;
stats_all
.s1
.v_intr
= sum
.v_intr
;
gettimeofday(&tm
, (struct timezone
*) 0);
stats_all
.s1
.v_intr
-= hz
*(tm
.tv_sec
- btm
.tv_sec
) +
hz
*(tm
.tv_usec
- btm
.tv_usec
)/1000000;
stats_all
.s2
.v_swtch
= sum
.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");
stats_all
.s1
.if_ipackets
= 0;
stats_all
.s1
.if_opackets
= 0;
stats_all
.s1
.if_ierrors
= 0;
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");
stats_all
.s1
.if_ipackets
+= ifnet
.if_ipackets
;
stats_all
.s1
.if_opackets
+= ifnet
.if_opackets
;
stats_all
.s1
.if_ierrors
+= ifnet
.if_ierrors
;
stats_all
.s1
.if_oerrors
+= ifnet
.if_oerrors
;
stats_all
.s1
.if_collisions
+= ifnet
.if_collisions
;
off
= (int) ifnet
.if_next
;
gettimeofday((struct timeval
*)&stats_all
.s3
.curtime
,
if (kvm_nlist(nl
) != 0) {
syslog(LOG_ERR
, "rstatd: Can't get namelist.");
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");
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");
off
= (int) ifnet
.if_next
;
* returns true if have a disk
if (kvm_nlist(nl
) != 0) {
syslog(LOG_ERR
, "rstatd: Can't get namelist.");
if (kvm_read((long)nl
[X_DKXFER
].n_value
, (char *)xfer
, sizeof xfer
)!= sizeof xfer
) {
syslog(LOG_ERR
, "rstat: can't read kmem\n");
for (i
=0; i
< DK_NDRIVE
; i
++)
rstat_service(rqstp
, transp
)
bool_t (*xdr_argument
)(), (*xdr_result
)();
switch (rqstp
->rq_proc
) {
(void)svc_sendreply(transp
, xdr_void
, (char *)NULL
);
xdr_result
= xdr_statstime
;
switch (rqstp
->rq_vers
) {
local
= (char *(*)()) rstatproc_stats_1
;
local
= (char *(*)()) rstatproc_stats_2
;
local
= (char *(*)()) rstatproc_stats_3
;
svcerr_progvers(transp
, RSTATVERS_ORIG
, RSTATVERS_TIME
);
switch (rqstp
->rq_vers
) {
local
= (char *(*)()) rstatproc_havedisk_1
;
local
= (char *(*)()) rstatproc_havedisk_2
;
local
= (char *(*)()) rstatproc_havedisk_3
;
svcerr_progvers(transp
, RSTATVERS_ORIG
, RSTATVERS_TIME
);
bzero((char *)&argument
, sizeof(argument
));
if (!svc_getargs(transp
, xdr_argument
, &argument
)) {
result
= (*local
)(&argument
, rqstp
);
if (result
!= NULL
&& !svc_sendreply(transp
, xdr_result
, result
)) {
svcerr_systemerr(transp
);
if (!svc_freeargs(transp
, xdr_argument
, &argument
)) {
(void)fprintf(stderr
, "unable to free arguments\n");