sleep 2; # to avoid dup signals
}
-=head2 Deferred Signals (Safe signals)
+=head2 Deferred Signals (Safe Signals)
In Perls before Perl 5.7.3 by installing Perl code to deal with
signals, you were exposing yourself to danger from two things. First,
you can try using the POSIX sigaction() function, which bypasses the
Perl safe signals (note that this means subjecting yourself to
possible memory corruption, as described above). Instead of setting
-C<$SIG{ALRM}> try something like the following:
+C<$SIG{ALRM}>:
- use POSIX;
- sigaction SIGALRM, new POSIX::SigAction sub { die "alarm\n" }
- or die "Error setting SIGALRM handler: $!\n";
+ local $SIG{ALRM} = sub { die "alarm" };
+
+try something like the following:
+
+ use POSIX qw(SIGALRM);
+ POSIX::sigaction(SIGALRM,
+ POSIX::SigAction->new(sub { die "alarm" }))
+ or die "Error setting SIGALRM handler: $!\n";
=item Restartable system calls
"loop". In future Perl's signal mechanism may be changed to avoid this
- perhaps by simply disallowing %SIG handlers on signals of that
type. Until then the work-round is not to set a %SIG handler on those
-signals. (Which signals they are is operating system dependant.)
+signals. (Which signals they are is operating system dependent.)
=item Signals triggered by operating system state
forks the ps(1) command (without spawning a shell, as there are more than
three arguments to open()), and reads its standard output via the
-C<KID_PS> filehandle. The corresponding syntax to read from command
+C<KID_PS> filehandle. The corresponding syntax to write to command
pipes (with C<"|-"> in place of C<"-|">) is also implemented.
Note that these operations are full Unix forks, which means they may not be
use strict;
my ($rendezvous, $line);
- $rendezvous = shift || '/tmp/catsock';
+ $rendezvous = shift || 'catsock';
socket(SOCK, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
connect(SOCK, sockaddr_un($rendezvous)) || die "connect: $!";
while (defined($line = <SOCK>)) {
sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }
- my $NAME = '/tmp/catsock';
+ my $NAME = 'catsock';
my $uaddr = sockaddr_un($NAME);
my $proto = getprotobyname('tcp');
my $id = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
my $sent = "message";
- my $type = 1234;
+ my $type_sent = 1234;
my $rcvd;
my $type_rcvd;
try to pass open file descriptors over a local UDP datagram socket if you
want your code to stand a chance of being portable.
-As mentioned in the signals section, because few vendors provide C
-libraries that are safely re-entrant, the prudent programmer will do
-little else within a handler beyond setting a numeric variable that
-already exists; or, if locked into a slow (restarting) system call,
-using die() to raise an exception and longjmp(3) out. In fact, even
-these may in some cases cause a core dump. It's probably best to avoid
-signals except where they are absolutely inevitable. This
-will be addressed in a future release of Perl.
-
=head1 AUTHOR
Tom Christiansen, with occasional vestiges of Larry Wall's original