From owner-freebsd-current Tue Mar 11 03:14:24 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id DAA15125 for current-outgoing; Tue, 11 Mar 1997 03:14:24 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id DAA15120 for ; Tue, 11 Mar 1997 03:14:21 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.3/8.6.9) id VAA09291; Tue, 11 Mar 1997 21:50:52 +1100 Date: Tue, 11 Mar 1997 21:50:52 +1100 From: Bruce Evans Message-Id: <199703111050.VAA09291@godzilla.zeta.org.au> To: ache@nagual.ru, brian@awfulhak.demon.co.uk Subject: Re: ppp Cc: brian@utell.co.uk, current@FreeBSD.org Sender: owner-current@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk >> Ok, so if I put (a fixed) sig.c back in there, could I ask you to do >> some testing ? I was thinking of: >> >> void handle_signals() { >> int sig; >> int had; >> >> had = caused; >> if (had) >> for (sig=0; sig<__MAXSIG; sig++) >> if (had&(1<> caused &= ~(1<> (*handler[sig])(sig+1); >> } >> } > >This way you lost _number_ of signals which may come. Since all signals >mapped to single bit in "caused" bitmask, here can be f.e. 10 or more >similar signals, but only one time signal handler will be executed. You >need to replace "caused" bitmask with "int caused[__MAXSIG];" and count >true number of signals come: caused[sig]++ (decrease it when handler was >executed: caused[sig]--). Generally you don't care and can't tell exactly how many signals occurred (the system doesn't count them). One exception might be if SIGALRM is pended and there is too large a latrency before unpending. Then counting could be used to tell how many SIGALRMs were mishandled :-). The main problems here are: 1. the code is non-portable. sigset_t might be larger than int, and not using sigset_t makes it hard to use sigprocmask(). 2. `caused &= ~(1<BTW, why you use own __MAXSIG when standard >NSIG is available from signal.h? NSIG is nonstandard. The only standard way to tell how many signals there are is to call sigisvalid() for all reasonable signal numbers, attempting to avoid bugs in sigisvalid() (see cvs/lib/sighandle.c). For a general signal catcher you can just use the maximum of all the signal numbers that you are catching. Bruce