Skip Menu |

This queue is for tickets about the Perl-Unsafe-Signals CPAN distribution.

Report information
The Basics
Id: 106841
Status: resolved
Priority: 0/
Queue: Perl-Unsafe-Signals

People
Owner: Nobody in particular
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.02
Fixed in: (no value)



Subject: Does not restore flags if code within UNSAFE_SIGNALS fails
The attached perl script demonstrates that PL_signals is not restored if the code block within UNSAFE_SIGNALS throws an exception. What's expected: the script should hang, because the final endless() call is not within a UNSAFE_SIGNALS block. What's happening: the alarm handler is functional.
Subject: unsafe_signals.pl
#!/usr/bin/perl use strict; use warnings; use Inline C => 'DATA'; use Perl::Unsafe::Signals; my $impl = shift || 'c'; $SIG{ALRM} = sub { die "Alarm!"; }; alarm(1); eval { UNSAFE_SIGNALS { fails(); #does_not_fail(); }; }; if ($@) { warn "as expected, fails() fails: $@"; } endless(); # no UNSAFE_SIGNALS, so it's supposed to hang __END__ __C__ void endless() { while(1) { sleep(1); } } void fails() { croak("This fails"); } void does_not_fail() { }
On 2015-09-03 07:31:49, SREZIC wrote: Show quoted text
> The attached perl script demonstrates that PL_signals is not restored > if the code block within UNSAFE_SIGNALS throws an exception. > > What's expected: the script should hang, because the final endless() > call is not within a UNSAFE_SIGNALS block. > What's happening: the alarm handler is functional.
Attached a proposal how to fix this problem by using a small helper class with a DESTROY method. Sorry, no test for it, but probably my first sample script could be rebuilt with an outer fork(). I can do it if you are fine to accept the patch.
Subject: 0001-restore-PL_signals-using-DESTROY.patch
From 6f534a319b8ce3813449da848b1cd0fc58c412e6 Mon Sep 17 00:00:00 2001 From: Slaven Rezic <slaven.rezic@idealo.de> Date: Thu, 3 Sep 2015 13:37:31 +0200 Subject: [PATCH] restore PL_signals using DESTROY --- Signals.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Signals.pm b/Signals.pm index 0866f47..f5594e2 100644 --- a/Signals.pm +++ b/Signals.pm @@ -14,9 +14,23 @@ sub import { sub UNSAFE_SIGNALS (&) { my $code = shift; - my $oldflags = push_unsafe_flag(); + my $restore = Perl::Unsafe::Signals::Restore->new; $code->(); - pop_unsafe_flag( $oldflags ); +} + +{ + package # helper class, hide from PAUSE indexer + Perl::Unsafe::Signals::Restore; + sub new { + my($class) = @_; + my $oldflags = Perl::Unsafe::Signals::push_unsafe_flag(); + bless \$oldflags, $class; + } + sub DESTROY { + my $self = shift; + my $oldflags = $$self; + Perl::Unsafe::Signals::pop_unsafe_flag($oldflags); + } } 1; -- 1.7.9.5
Thanks, applied and released as version 0.03.