develooper Front page | perl.perl5.porters | Postings from January 2011

Re: [perl #82040] %SIG handlers BLOCK/UNBLOCK signals rather thanBLOCK+save / restore

Thread Previous | Thread Next
From:
Paul LeoNerd Evans
Date:
January 12, 2011 08:23
Subject:
Re: [perl #82040] %SIG handlers BLOCK/UNBLOCK signals rather thanBLOCK+save / restore
Message ID:
20110112162340.GA3518@cel.leo
On Tue, Jan 11, 2011 at 01:55:34PM +0100, Leon Timmermans wrote:
> On Tue, Jan 11, 2011 at 1:23 PM, Zefram <zefram@fysh.org> wrote:
> > Paul LeoNerd Evans wrote:
> > Restore the whole mask?  What if you want to change the blocking status
> > of a different signal, in the body of this signal handler?

Ah, an excellent point.

> How about this?
> 
> int was_blocked;
> sigset_t new, old;
> 
> sigemptyset(&new);
> sigaddset(&new, sig);
> 
> sigprocmask(SIG_BLOCK, &new, &old) = 0;
> was_blocked = sigismember(&old, signal);
>  ... { code body here }
> if (!was_blocked) {
>     sigprocmask(SIG_UNBLOCK, new, NULL);
> }
> 
> Signals can't block themselves that way, but they couldn't do that
> before either anyway.

That looks much better yes.

Is there a plan for fixing this? Does anyone want to have a stab at
fixing it (Leon's suggestion there looks good), or should I have a go?

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About