[net.bugs.4bsd] alarm return value is wrong in 4.2bsd

shannon@sun.uucp (Bill Shannon) (03/22/84)

Index:	lib/libc/gen/alarm.c 4.2BSD

Description:
	alarm (which is implemented using setitimer) can sometimes lie
	and return zero even when there is an alarm pending.  This
	screws up people who do:

		left = alarm(0);	/* turn alarm off */
		diddle, diddle, diddle...
		alarm(left);		/* turn it back on */
Repeat-By:
	See above.
Fix:
	The problem is that the interval timer has higher resolution
	than alarm and alarm truncates the value.  I fixed it to round
	up.  Diffs follow.

*** /tmp/d02314	Wed Mar 21 16:30:17 1984
--- alarm.c	Wed Mar 21 16:29:59 1984
***************
*** 18,22
  	itp->it_value.tv_usec = 0;
  	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
  		return (-1);
  	return (oitv.it_value.tv_sec);
  }

--- 18,24 -----
  	itp->it_value.tv_usec = 0;
  	if (setitimer(ITIMER_REAL, itp, &oitv) < 0)
  		return (-1);
+ 	if (oitv.it_value.tv_usec)
+ 		oitv.it_value.tv_sec++;
  	return (oitv.it_value.tv_sec);
  }


					Bill Shannon
					sun!shannon
					Sun Microsystems, Inc.