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:
Leon Timmermans
Date:
January 11, 2011 04:55
Subject:
Re: [perl #82040] %SIG handlers BLOCK/UNBLOCK signals rather thanBLOCK+save / restore
Message ID:
AANLkTimnLDBtyQ3wTu0ZFdYG9cHX_MSA6w36mvPtR2jh@mail.gmail.com
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?

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.

Leon

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