--- netkit-rusers-0.15/rpc.rstatd/rstat_proc.c.jbj Wed Feb 10 17:01:01 1999 +++ netkit-rusers-0.15/rpc.rstatd/rstat_proc.c Fri Aug 27 13:00:06 1999 @@ -62,10 +62,10 @@ #define CP_USER 0 #define CP_NICE 1 #define CP_SYS 2 -#define CP_INTR 3 -#define CP_IDLE 4 +#define CP_IDLE 3 +#define CP_INTR 4 #define CPUSTATES 5 -static int cp_xlat[4] = { CP_USER, CP_NICE, CP_SYS, CP_IDLE }; +static int cp_xlat[CPUSTATES] = { CP_USER, CP_NICE, CP_SYS, CP_IDLE }; /* * System wide statistics counters. @@ -317,10 +317,13 @@ stat_init(void) { stat_is_init = 1; - setup(); + + /* Prime the pump */ updatestat(0); + (void) signal(SIGALRM, updatestat); alarm(1); + pause(); } statstime * @@ -361,8 +364,8 @@ (void)&arg; (void)&rqstp; if (!stat_is_init) stat_init(); - sincelastreq = 0; have = havedisk(); + sincelastreq = 0; return (&have); } @@ -391,7 +394,7 @@ }; static void -getstat(unsigned *cuse, unsigned *cice, unsigned *csys, unsigned long *cide, +getstat(unsigned long *cuse, unsigned long *cice, unsigned long *csys, unsigned long *cide, unsigned *pin, unsigned *pout, unsigned *sin, unsigned *sout, unsigned *itot, unsigned *i1, unsigned *ct, struct _ldisk *d) { @@ -407,7 +410,7 @@ *itot = 0; *i1 = 1; /* ensure assert below will fail if the sscanf bombs */ b = strstr(buff, "cpu "); - sscanf(b, "cpu %u %u %u %lu", cuse, cice, csys, cide); + sscanf(b, "cpu %lu %lu %lu %lu", cuse, cice, csys, cide); b = strstr(buff, "disk "); sscanf(b, "disk %u %u %u %u", d->xfer+0, d->xfer+1, d->xfer+2, d->xfer+3); b = strstr(buff, "disk_rio "); @@ -537,12 +540,17 @@ static int hz; static struct timeval tm, btm; static double avrun[3]; -static unsigned int cpu_use[2], cpu_nic[2], cpu_sys[2]; +static unsigned long cpu_use[2], cpu_nic[2], cpu_sys[2]; static unsigned long cpu_idl[2]; static struct _ldisk disk[2]; static unsigned int pgpgin[2], pgpgout[2], pswpin[2], pswpout[2]; static unsigned int inter[2], ticks[2], ctxt[2]; + +#ifdef NOTYET /* XXX noop to match solaris behavior */ #define _DELTA(_x, _i) ( (_x)[(_i)] - (_x)[!(_i)] ) +#else +#define _DELTA(_x, _i) ( (_x)[(_i)] ) +#endif extern int uptime(double *, double *); extern void loadavg(double *, double *, double *); @@ -568,7 +576,6 @@ getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog, pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog, inter+tog,ticks+tog,ctxt+tog, disk+tog); - tog = !tog; dk_ndrive = 0; for (i = 0; i < 4; i++) { @@ -578,11 +585,11 @@ dk_ndrive++; } - cur.cp_time[CP_USER] = _DELTA(cpu_use, tog); - cur.cp_time[CP_NICE] = _DELTA(cpu_nic, tog); - cur.cp_time[CP_SYS] = _DELTA(cpu_sys, tog); + cur.cp_time[CP_USER] = (_DELTA(cpu_use, tog)) % UINT_MAX; + cur.cp_time[CP_NICE] = (_DELTA(cpu_nic, tog)) % UINT_MAX; + cur.cp_time[CP_SYS] = (_DELTA(cpu_sys, tog)) % UINT_MAX; cur.cp_time[CP_INTR] = 0; - cur.cp_time[CP_SYS] = (_DELTA(cpu_idl, tog)) % UINT_MAX; + cur.cp_time[CP_IDLE] = (_DELTA(cpu_idl, tog)) % UINT_MAX; cnt.v_pgpgin = pgpgin[tog]; cnt.v_pgpgout = pgpgout[tog]; @@ -590,6 +597,7 @@ cnt.v_pswpout = pswpout[tog]; cnt.v_intr = inter[tog]; cnt.v_swtch = ctxt[tog]; + tog = !tog; } static void @@ -597,11 +605,10 @@ { int i, save_errno = errno; - (void)&signo; #ifdef DEBUG syslog(LOG_DEBUG, "entering updatestat"); #endif - if (sincelastreq >= closedown) { + if (signo != 0 && sincelastreq >= closedown) { #ifdef DEBUG syslog(LOG_DEBUG, "about to closedown"); #endif @@ -678,15 +685,6 @@ alarm(1); errno = save_errno; } - -static void -setup(void) -{ - /* Prime the pump */ - convert_stats(); - sleep(1); -} - /* * returns true if have a disk