Date: Sun, 18 May 1997 21:14:26 +0800 From: Peter Wemm <peter@spinner.DIALix.COM> To: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= <ache@nagual.pp.ru> Cc: Bruce Evans <bde@zeta.org.au>, peter@FreeBSD.ORG, cvs-all@FreeBSD.ORG, cvs-committers@FreeBSD.ORG, cvs-lib@FreeBSD.ORG Subject: Re: cvs commit: src/lib/libc/gen sleep.c Message-ID: <199705181314.VAA07838@spinner.DIALix.COM> In-Reply-To: Your message of "Sun, 18 May 1997 15:07:12 %2B0400." <Pine.BSF.3.96.970518150412.1533B-100000@nagual.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
=?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= wrote:
> On Sun, 18 May 1997, Peter Wemm wrote:
>
> > (void) sigvec(SIGALRM, &vec, &ovec);
> > if (setjmp(&jmpbuf) == 0) {
> > .. unmask SIGALRM ..
>
> I think here is a race place -->
No, because if a SIGALRM is taken before getting into nanosleep(), the
signal handler longjmp's out, and the nanosleep() isn't called. So, if we
recieve a sigalarm inside sleep(3), we don't sleep (as intended). However,
there are so many races here already it's not funny.. like, what happens if
we get a signal before masking SIGALRM in the first place?
> > nanosleep(&time_to_sleep, &time_remaining);
> > (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0);
>
> > ... but this has several problems..
> > 1: it's starting to get messy with lots of syscalls.
> > 2: it doesn't deal with an aborted nanosleep() due to SIGALRM. It'd have
> > to calculate the elapsed time itself by calling gettimeofday or
> > clock_gettime() before and after. It'd also suffer from time adjustments
> > and contribute to the mess.
>
> Yes.
Hmm.. or we could initialise time_remaining to the full value. If
nanosleep() never gets called, we can simply return the full value since
we never really slept.
> > On the other hand, perhaps we could change the nanosleep syscall so that
> > it takes a mask argument and handle the differences in the libc wrapper
> > and have sleep(3) do this:
> >
> >
> > sigprocmask(SIG_BLOCK, ..SIGALRM.., &oset);
> > ...
> > setsignal(SIGALRM, sleephandler);
> > ...
> > nanosleep_mask(&time, &remaining, &oset);
> > ...
> >
> and have nanosleep(ts1, ts2) be implemented as nanosleep_mask(ts1, ts2,
> > NULL);
>
> The second variant looks much better.
Bleah.. signanosleep()? wait for an unmasked signal (mask specified in
syscall) for up to the max time limit.
> --
> Andrey A. Chernov
> <ache@null.net>
> http://www.nagual.pp.ru/~ache/
Cheers,
-Peter
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199705181314.VAA07838>
