Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83 SMI; site sun.uucp
Path: utzoo!watmath!clyde!floyd!harpo!decvax!decwrl!sun!shannon
From: shannon@sun.uucp (Bill Shannon)
Newsgroups: net.bugs.4bsd
Subject: alarm return value is wrong in 4.2bsd
Message-ID: <667@sun.uucp>
Date: Wed, 21-Mar-84 19:59:08 EST
Article-I.D.: sun.667
Posted: Wed Mar 21 19:59:08 1984
Date-Received: Fri, 23-Mar-84 07:15:03 EST
Organization: Sun Microsystems, Inc.
Lines: 40

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.