[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: signals and atomicity



In article <[🔎] Pine.LNX.3.96.980419122410.668B-100000@vulcain.yyydom> you wrote:
> On Sat, 18 Apr 1998, Herbert Xu wrote:
>> This should work:
>> 
>> static int wait_or_timeout_retval = -1;
>> 
>> static void alarm_handler(int sig) {
>> 	errno = ETIMEDOUT; 
>> }
>> 
>> int wait_or_timeout (int *status) {
>> 	struct sigaction act;
>> 
>> 	wait_or_timeout_retval = -1; 
>> 
>> 	sigaction(SIGALRM, 0, &act);
>> 	act.sa_handler = alarm_handler;
>> 	act.sa_flags &= ~SA_RESTART;
>> 	sigaction(SIGALRM, &act, 0);
>> 	alarm(1);
>> 	wait_or_timeout_retval = wait(status);
>> 	alarm(0); 
>> 	return wait_or_timeout_retval; 
>> }

> i do not think, this works.

> alarm() calls setitimer(). setitimer() modifies "errno".
> so, setting errno inside the signal handler does not work, i think.

That's easy to fix.  Just store ETIMEDOUT in some other variable that is
reset at the start of wait_or_timeout and store the result in errno if wait
fails with EINTR.

-- 
Debian GNU/Linux 1.3 is out! ( http://www.debian.org/ )
Email:  Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


--
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: