ruptime reports 0 users

Mark Plotnick mp at allegra.UUCP
Mon Nov 25 15:11:19 AEST 1985


ruptime may claim that a machine with lots of users on it has 0 users.
This is because it reads only the first 1K bytes of a whod file into a
buffer, and assumes that it can read an array of structures backwards
from the end of the buffer.  What it gets, if the whod file is big enough,
is a bunch of garbled structures.
Here are the minimum changes necessary to stop it from getting
confused; a cleaner fix would involve rewriting it to look more like
rwho.c.

*** ruptime.1.1	Sun Nov 24 16:58:43 1985
--- ruptime.1.2	Sun Nov 24 16:58:44 1985
***************
*** 36,38
  	int f, i, t;
! 	char buf[BUFSIZ]; int cc;
  	register struct hs *hsp = hs;

--- 36,38 -----
  	int f, i, t;
! 	char buf[sizeof (struct whod)]; int cc;
  	register struct hs *hsp = hs;
***************
*** 86,88
  		if (f > 0) {
! 			cc = read(f, buf, BUFSIZ);
  			if (cc >= WHDRSIZE) {

--- 86,88 -----
  		if (f > 0) {
! 			cc = read(f, buf, sizeof buf);
  			if (cc >= WHDRSIZE) {
***************
*** 88,89
  			if (cc >= WHDRSIZE) {
  				hsp->hs_wd = (struct whod *)malloc(WHDRSIZE);

--- 88,91 -----
  			if (cc >= WHDRSIZE) {
+ 				/* first, chop off any incomplete entry */
+ 				cc -= (cc - WHDRSIZE) % sizeof (struct whoent);
  				hsp->hs_wd = (struct whod *)malloc(WHDRSIZE);

	Mark Plotnick
	Department of remote control
	allegra!mp



More information about the Comp.bugs.4bsd.ucb-fixes mailing list