[comp.unix.sysv386] bug in /etc/dfspace

jimmy@tokyo07.info.com (Jim Gottlieb) (04/08/91)

I don't recall seeing this problem mentioned here, so I enclose a copy
of the letter I sent to Interactive (even though this code appears to
have come from AT&T, so the problem may exist in other systems if the
respective company did not catch it).



From: jimmy@tokyo07.info.com (Jim Gottlieb)
To: support@ism.isc.com
Subject: bug in /etc/dfspace

There is a bug in the /etc/dfspace script that causes incorrect
output when a filesystem has no space left.  A typical erroneous
output is...

/              :	 Disk space:  15.68 MB of  29.13 MB available (53.84%).
/usr           :	 Disk space:   8.38 MB of  38.84 MB available (21.58%).
/usr2          :	 Disk space:   8.38 MB of 222.62 MB available ( 0.00%).

Total Disk Space:        	      24.06 MB of 290.60 MB available ( 8.28%).



Note that it is reporting 8.38 MB available in /usr2 even though it
shows 0.00%.  The percentage is correct.  The MB value is merely the
same as reported for /usr.


The problem comes from the following line...

		if ( free != 0 )  f = (free * CONST) - .005;

The problem is that if f _is_ equal to 0, variable 'f' is not reset and
is left at the value it was set to for the previous filesystem.

If the above line is replaced with 


		if ( free != 0 ) {
			f = (free * CONST) - .005;
		}
		else {
			f = 0;
		}

the problem appears to be fixed.