Subject: Possible problem with sleep(3).
To: None <>
From: Greg Cronau <>
List: current-users
Date: 05/25/1994 15:39:58
I am currently porting some production code that was originally designed
in a SysVr3 environment. I just ran into a minor problem with the sleep()
library function. I am not sure whether this is an actual bug in the
implementation, or if the BSD semantics of sleep() is different from
SysV. Sleep returns an int. Under SysV sleep is supposed to return the
"unslept" time if it is interupted. NetBSD appears to restart function
calls as the default, but this can be changed with the sigaction() or
siginterrupt() calls. However, sleep() apparently ignores the value of
siginterrupt() and does not appear to be capable of being interrupted.
Notice the following piece of code from the end of .../lib/libc/gen/sleep.c:
	setvec(vec, sleephandler);
	(void) sigvec(SIGALRM, &vec, &ovec);
	omask = sigblock(sigmask(SIGALRM));
	ringring = 0;
	(void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0);
	while (!ringring)
		sigpause(omask &~ sigmask(SIGALRM));
	(void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
	(void) sigsetmask(omask);
	(void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0);
	return 0;

static void
	ringring = 1;

This code will just keep calling sigpause() everytime it is interupted until
the real SIGALRM arrives. I need the ability to interupt the sleep() call.
I see 3 solutions here:
1.) This is the correct symantics for BSD and I'm just going to have to
    write my own sleep() function.
2.) This is a bug and I should fix sleep() and post fixes.
3.) If this isn't a bug, would there be interest in code for an isleep()
    function to be added to libc that would be an interuptable sleep() ?