[comp.windows.x] xrload - another bug fix

csnjr@its63b.ed.ac.uk (Nick Rothwell) (08/20/87)

Another problem with the recently posted xrload program - it gets confused
if hosts are down, since it always reads a complete line of information
from ruptime, and there isn't one there if "down". This fix, to get-stats.c,
cuts short the read if necessary. Perhaps fscanf works differently on other
systems (stopping on '\n' for example), in which case this fix isn't
necessary.

38,43c38,48
< 	    nf = fscanf (pfile, "%s %s %s %d %s load %f, %f, %f",
< 			 stats[nh].sys_name, hstatus, stats[nh].how_long,
< 			 &stats[nh].users, junk,
< 			 &stats[nh].load_average[0],
< 			 &stats[nh].load_average[1],
< 			 &stats[nh].load_average[2]);
---
>            /* Read first part of line: */
> 	    nf = fscanf (pfile, "%s %s %s",
>                          stats[nh].sys_name, hstatus, stats[nh].how_long);
>            /* only read second part if "up" */
>             if (!strcmp(hstatus, "up"))
>                nf += fscanf (pfile, " %d %s load %f, %f, %f",
> 			     &stats[nh].users, junk,
> 			     &stats[nh].load_average[0],
> 			     &stats[nh].load_average[1],
> 		             &stats[nh].load_average[2]);
> 

-- 
Nick Rothwell,	Laboratory for Foundations of Computer Science, Edinburgh.
		nick%lfcs.ed.ac.uk@cs.ucl.ac.uk
		<Atlantic Ocean>!mcvax!ukc!lfcs!nick
~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
"Nothing's forgotten. Nothing is ever forgotten."   - Herne