From owner-cvs-lib Sun May 18 06:18:02 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id GAA27822 for cvs-lib-outgoing; Sun, 18 May 1997 06:18:02 -0700 (PDT) Received: from spinner.DIALix.COM (spinner.dialix.com [192.203.228.67]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id GAA27802; Sun, 18 May 1997 06:17:38 -0700 (PDT) Received: from spinner.DIALix.COM (localhost.dialix.com.au [127.0.0.1]) by spinner.DIALix.COM with ESMTP id VAA07838; Sun, 18 May 1997 21:14:28 +0800 (WST) Message-Id: <199705181314.VAA07838@spinner.DIALix.COM> X-Mailer: exmh version 2.0gamma 1/27/96 To: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= cc: Bruce Evans , 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 In-reply-to: Your message of "Sun, 18 May 1997 15:07:12 +0400." Date: Sun, 18 May 1997 21:14:26 +0800 From: Peter Wemm Sender: owner-cvs-lib@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk =?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 > > http://www.nagual.pp.ru/~ache/ Cheers, -Peter