From owner-freebsd-current Thu Jul 17 23:20:15 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id XAA02087 for current-outgoing; Thu, 17 Jul 1997 23:20:15 -0700 (PDT) Received: from nagual.pp.ru (ache.relcom.ru [194.58.229.133]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id XAA02082 for ; Thu, 17 Jul 1997 23:20:10 -0700 (PDT) Received: (from ache@localhost) by nagual.pp.ru (8.8.6/8.8.5) id KAA00269 for current@freebsd.org; Fri, 18 Jul 1997 10:20:00 +0400 (MSD) Date: Fri, 18 Jul 1997 10:19:57 +0400 (MSD) From: =?KOI8-R?B?4c7E0sXKIP7F0s7P1w==?= To: FreeBSD-current Subject: sleep.c fix for review Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Our current implementation do not enable ALARM handler, if it was disabled previously. Since such case is very rare, there is no real optimization occurse, but potential incompatibility: all other Unix sleep implementations including GNU one enable ALARM handler in _any_ case. This patch makes our sleep compatible with our previous code and the rest of the world sleep codes. *** sleep.c.bak Sun Jun 8 15:11:01 1997 --- sleep.c Tue Jul 15 00:57:59 1997 *************** *** 73,79 **** struct timespec time_remaining; struct sigaction act, oact; sigset_t mask, omask; - int alarm_blocked; if (seconds != 0) { time_to_sleep.tv_sec = seconds; --- 73,78 ---- *************** *** 84,101 **** sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &omask); ! /* Was SIGALRM blocked already? */ ! alarm_blocked = sigismember(&omask, SIGALRM); ! ! if (!alarm_blocked) { ! /* ! * Set up handler to interrupt signanosleep only if ! * SIGALRM was unblocked. (Save some syscalls) ! */ ! memset(&act, 0, sizeof(act)); ! act.sa_handler = sleephandler; ! sigaction(SIGALRM, &act, &oact); ! } /* * signanosleep() uses the given mask for the lifetime of --- 83,95 ---- sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &omask); ! /* ! * Set up handler to interrupt signanosleep only if ! * SIGALRM was unblocked. (Save some syscalls) ! */ ! memset(&act, 0, sizeof(act)); ! act.sa_handler = sleephandler; ! sigaction(SIGALRM, &act, &oact); /* * signanosleep() uses the given mask for the lifetime of *************** *** 107,117 **** */ signanosleep(&time_to_sleep, &time_remaining, &omask); ! if (!alarm_blocked) { ! /* Unwind */ ! sigaction(SIGALRM, &oact, (struct sigaction *)0); ! sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); ! } /* return how long is left */ seconds = time_remaining.tv_sec; --- 101,109 ---- */ signanosleep(&time_to_sleep, &time_remaining, &omask); ! /* Unwind */ ! sigaction(SIGALRM, &oact, (struct sigaction *)0); ! sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); /* return how long is left */ seconds = time_remaining.tv_sec; -- Andrey A. Chernov http://www.nagual.pp.ru/~ache/