A common idiom, at least in my code, is to have the script itself set
$ENV{'PERL_SIGNALS'} = "unsafe", such as in BEGIN { }, so that I don't have
to pollute my environment with it ordinarily and the scripts that want this
can set it themselves. This works fine in 5.8, 5.10 and 5.12. It does not
work in 5.14; it requires that I already have the variable set before the
script is executed, or the value is not seen and "safe" signals are used.
Although the argument could be made that this was not designed to be set at
runtime, modules such as Perl::Unsafe::Signals are certainly doing that
already (just through XS and PL_signals):
http://cpansearch.perl.org/src/RGARCIA/Perl-Unsafe-Signals-0.02/Signals.xs
I have not evaluated this module specifically with 5.14, but its use does
not appear uncommon.
A quick scan through mg.c does not show anywhere that PL_signals is exposed,
unlike, say, $^H. Therefore there is no replacement in 5.14 for this lost
functionality.
I would like to request the old behaviour be reinstated for backward
compatibility.
Thanks for your consideration.
% perl514 -v
This is perl 5, version 14, subversion 0 (v5.14.0) built for darwin-2level
Copyright 1987-2011, Larry Wall
[...]
% perl514 -V
[...]
Summary of my perl5 (revision 5 version 14 subversion 0) configuration:
Platform:
osname=darwin, osvers=8.11.0, archname=darwin-2level
uname='darwin bruce.floodgap.com 8.11.0 darwin kernel version 8.11.0: wed oct 10 18:26:00 pdt 2007; root:xnu-792.24.17~1release_ppc power macintosh powerpc '
config_args=''
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include',
optimize='-O3',
cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include'
ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5370)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/local/lib -L/opt/local/lib'
libpth=/usr/local/lib /opt/local/lib /lib /usr/lib
libs=-lgdbm -ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV USE_LARGE_FILES USE_PERLIO
USE_PERL_ATOF
Built under darwin
Compiled at Jun 5 2011 07:10:59
%ENV:
PERL_SIGNALS="unsafe"
@INC:
./lib
/opt/perl514/lib/site_perl/5.14.0/darwin-2level
/opt/perl514/lib/site_perl/5.14.0
/opt/perl514/lib/5.14.0/darwin-2level
/opt/perl514/lib/5.14.0
.
--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Nasty habits/Here to stay! -- Oingo Boingo ---------------------------------
Exactly. I'd personally call this a fix, not a bug.
> modules such as Perl::Unsafe::Signals are certainly doing that
> already (just through XS and PL_signals):
Is there any reason you can't use Perl::Unsafe::Signals instead? For
that matter, is there any reason you really have to use unsafe
signals? Really? It's a dangerous thing to do, and enabling it for the
entire duration of the program is really a bad idea.
> I would like to request the old behaviour be reinstated for backward
> compatibility.
I'd prefer a different solution to this. You can trivially write a
module on top of PUS that disables safe signal handling if you really
want that, no need for the ugly hack you're using right now:
package Perl::Unsafe::Signals::Global;
use Perl::Unsafe::Signals;
Perl::Unsafe::Signals::push_unsafe_flag();
1;
Leon
I imagine you would not consider this a good reason, but I specifically
support scripts that can run in environments where the only thing available
is the Perl binary (embedded systems and small installs particularly
benefit), and I have users who depend specifically on that functionality.
The previous behaviour worked fine in minimal environments; using P::U::S
would add, at best, an inconvenient dependency. Currently for 5.14 we are
using a workaround of a shell script that sets the variable and calls Perl,
which works, but is kludgey.
Rather than explain the whole of why I use unsafe signals, let me simply
say I am well aware of why they are considered "unsafe," but I do not find
Perl "safe signals" real-time enough for my purposes. I suspect others do
as well, which is why something like Perl::Unsafe::Signals exists in the
first place.
--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Even cabbage more sense than you! -- Shampoo, "Ranma 1/2" ------------------
Another possibility that doesn't require non-core modules is using
POSIX's sigaction() instead of %SIG to set the signal handlers. This
sets unsafe signal handlers by default (though you can chose per
signal if they should be safe or not).
Leon
I agree that would indeed be fine if the Perl standard library were present.
However, I do specifically support the situation where only the Perl bare
binary is present (the truly most minimal install of all), which like I say
is very useful to embedded systems. If this is no longer a supported
configuration to run Perl in, then I imagine we'll make do with the shell
script workaround and facultatively use POSIX.pm if it is present, though as
I say this is suboptimal for this particular purpose.
--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Bowl angry. ----------------------------------------------------------------
If you're in control of the perl binary you could patch it to use
unsafe signals by default (see attachment), or you could try a
staticperl[1] approach to include POSIX.pm/Perl::Unsafe::Signals. If
not and POSIX is compiled in statically you can use it with a little
coercion.
Leon
I never received Leon's request. The difference in behaviour relates to
real-time signal handling; if a system call is running, it may not be
interrupted by a signal coming through. I could write up a script to bang
on a second process if you like to show the difference. The specific
application that went awry was TTYtter (and Texapp, its descendent) when
using a ReadLine driver; the ReadLine driver would send signals to TTYtter
to squelch it while the user was typing and only with 'unsafe' signals on
would the select() be reliably interrupted.
However, I suspect that there is no interest in restoring the prior
behaviour (as evidenced by this particular reply), so I've started requiring
users to either set this variable before starting the script, or have a full
installation with POSIX.pm. It's suboptimal, but it works.
I would be happy to try to fix this myself, if there is any interest in
accepting a patch.