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

Re: signals and atomicity



In article <[🔎] Pine.LNX.3.96.980417092907.398C-100000@vulcain.yyydom> you wrote:

> if the signal occurs after the wait system call, but before the result of
> the system call is stored in "wait_or_timeout_retval", the fact, that
> the system call succeeded is lost.

> this is (1) a bug in apache and (2) a problem of me that i want to solve.
> i thought others would have solved it, but this is obviously not true :-(

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; 
}

-- 
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: