sdingare has asked for the wisdom of the Perl Monks concerning the following question:

Hi there

I'm dealing with some very odd behaviour as I migrate a process of mine from perl 5.8.8 to perl 5.12.1

I have created a small script (pasted below) that reproduces the problem; what seems to be happening is that the require statement of the module Vip.pm, which contains:

use Net::DNS; my $resolver = new Net::DNS::Resolver();

causes the SIG{CHLD} handler to be reset in some way when running on perl 5.12.1, which results in an error.

But on 5.8.8 the SIG{CHLD} handler is unchanged after the require statement.

If I add "use Net::DNS::Resolver;" at the top of the mytest.pl script (but leave the require as-is), then the output of the script on perl v 5.12.1 becomes the same as 5.8.8 (the signal handler remains unchanged)

Also, if I change Vip.pm to require another module (e.g. Digest::MD5), I don't get this behaviour, the output of the script on perl v5.12.1 and 5.8.8 is again the same (signal handler remains unchanged)

Finally, the error (when running on perl 5.12.1) appears as below in my reproducer script, but when running in my actual process appears as:

"Signal SIGCHLD received, but no signal handler set."

I'm running on Red Hat Enterprise Linux Server release 5.11

Here's the output of my program on perl v5.8.8
-----------------------------------------------

Before setting SIG{CHLD} its value is...<br/> $VAR1 = undef;<br/> After setting SIG{CHLD} its value is...<br/> $VAR1 = sub { "DUMMY" };<br/> After require statement SIG{CHLD} value is...<br/> $VAR1 = sub { "DUMMY" };<br/> Calling ping now...<br/> I AM A SIG{CHLD} handler<br/> Reading ping stream...<br/> Reading ping stream...<br/> Reading ping stream...<br/> Reading ping stream...<br/> Reading ping stream...<br/> Reading ping stream...<br/> DONE

Here's the output of my program on perl v5.12.1
---------------------------------------------

Before setting SIG{CHLD} its value is...<br/> $VAR1 = undef;<br/> After setting SIG{CHLD} its value is...<br/> $VAR1 = sub { "DUMMY" };<br/> After require statement SIG{CHLD} value is...<br/> $VAR1 = undef;<br/> Calling ping now...<br/> Reading ping stream...<br/> Use of uninitialized value in iteration finalizer at mytest.pl line 21 +, <PING> line 1.<br/> Unable to create sub named "" at mytest.pl line 21, <PING> line 1.</p>

Here is the code in my test script:
------------------------------------

use strict; use warnings; use Data::Dumper; use POSIX; print "Before setting SIG{CHLD} its value is...\n"; print Dumper($SIG{CHLD}); $SIG{CHLD}= \&REAPER; print "After setting SIG{CHLD} its value is...\n"; print Dumper($SIG{CHLD}); require Error::Vip; print "After require statement SIG{CHLD} value is...\n"; print Dumper($SIG{CHLD}); print "Calling ping now...\n"; my @cmd = ('ping', '-c', 1, '-n', '-A', '-W', 1, "164.55.89.62"); open (PING, '-|', @cmd) or confess("Can't ping -- $!"); while (my $ping = <PING>) { print "Reading ping stream...\n"; } close PING; print "DONE\n"; sub REAPER { print "I AM A SIG{CHLD} handler\n" }

Here's the code in Error/Vip.pm
-------------------------------

package Error::Test; use strict; use warnings; use Net::DNS; my $resolver = new Net::DNS::Resolver(); 1;

Replies are listed 'Best First'.
Re: SIG{CHLD} altered by require statement on Perl 5.12.1
by Corion (Patriarch) on Apr 13, 2015 at 16:15 UTC

    Maybe the versions of the Net::DNS module are different and the module now behaves differently?

Re: SIG{CHLD} altered by require statement on Perl 5.12.1
by afoken (Chancellor) on Apr 14, 2015 at 15:20 UTC

    A little bit more code than needed, and some information missing.

    What OS do you use? Which version? Module versions could also be interesting. I suggest to run the following script (use the download link) with both Perl versions and to post its output, wrapped in <code> tags:

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys=1; sub info { my $where=shift; print $where,": ",Dumper($SIG{'CHLD'}),"\n"; } info('start'); $SIG{'CHLD'}=sub { 'oh well, just a dummy' }; info('after set handler'); require Net::DNS; info('after require'); Net::DNS->import(); info('after import'); print "\n"; print "OS: $^O\n"; print "Versions:\n"; print "Perl $^V\n"; for my $fn (sort keys %INC) { my $mod=$fn; $mod=~s|/|::|g; $mod=~s|\.pm$|| or next; my $ver=do { no strict 'refs'; defined ${"$mod\::VERSION"} ? ${"$mod\::VERSION"} : 'n +one' }; print "$mod $ver\n"; }

    The first lines up to print "\n" are the real test code, everything following that collects information (OS, Perl version, Module versions).

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Hi there,

      Thanks for your suggestion (I think I already mentioned the OS in my first post but here it is again: Red Hat Enterprise Linux Server release 5.11; also perl -v says my perl was built for built for x86_64-linux-thread-multi)- I ran your script and here is the output I get:

      perl v5.8.8
      ---------------

      start: $VAR1 = undef; after set handler: $VAR1 = sub { "DUMMY" }; after require: $VAR1 = sub { "DUMMY" }; after import: $VAR1 = sub { "DUMMY" }; OS: linux Versions: Perl Carp 1.04 Config none Data::Dumper 2.121_08 Errno 1.0901 Exporter 5.58 Exporter::Heavy 5.58 IO 1.22 IO::Handle 1.25 IO::Select 1.17 IO::Socket 1.29 IO::Socket::INET 1.29 IO::Socket::UNIX 1.22 Net::DNS 0.66 Net::DNS::Header 704 Net::DNS::Packet 837 Net::DNS::Question 800 Net::DNS::RR 828 Net::DNS::RR::Unknown 388 Net::DNS::Resolver 830 Net::DNS::Resolver::Base 830 Net::DNS::Resolver::UNIX 482 Net::DNS::Update 517 SelectSaver 1.01 Socket 1.78 Symbol 1.06 XSLoader 0.06 bytes 1.02 constant 1.05 overload 1.04 strict 1.03 vars 1.01 warnings 1.05 warnings::register 1.01

      perl v 5.12.5
      -----------------

      start: $VAR1 = undef; after set handler: $VAR1 = sub { "DUMMY" }; after require: $VAR1 = undef; after import: $VAR1 = undef; OS: linux Versions: Perl v5.12.5 Carp 1.17 Config none Data::Dumper 2.131 Errno 1.11 Exporter 5.64_01 Exporter::Heavy 5.64_01 IO 1.25_02 IO::Handle 1.28 IO::Select 1.17 IO::Socket 1.31 IO::Socket::INET 1.31 IO::Socket::UNIX 1.23 Net::DNS 0.66 Net::DNS::Header 704 Net::DNS::Packet 837 Net::DNS::Question 800 Net::DNS::RR 828 Net::DNS::RR::Unknown 388 Net::DNS::Resolver 830 Net::DNS::Resolver::Base 830 Net::DNS::Resolver::UNIX 482 Net::DNS::Update 517 SelectSaver 1.02 Socket 1.87_01 Symbol 1.07 XSLoader 0.15 bytes 1.04 constant 1.20 overload 1.10 strict 1.04 vars 1.01 warnings 1.09 warnings::register 1.01

        Net::DNS 0.66 is really old, released before January 2012. I can't find the sources for Net::DNS 0.66 at CPAN. Consider upgrading it to the most recent version.

        As you can see from the script output, Net::DNS loads a lot of other modules, perhaps $SIG{CHLD} is deleted in one of the other modules. The following script should report where $SIG{CHLD} is modified. Run it on perl 5.12.1.

        #!/usr/bin/perl use v5.12; use strict; use warnings; package SpyHash { use Tie::Hash; # for Tie::StdHash use Carp qw( carp ); our @ISA=qw( Tie::StdHash ); sub STORE { my ($self,$key,$value)=@_; $key=~/^CH?LD$/ and carp "Assign to key $key"; return $self->SUPER::STORE($key,$value); } sub DELETE { my ($self,$key)=@_; $key=~/^CH?LD$/ and carp "Delete key $key"; return $self->SUPER::DELETE($key); } } tie %SIG,'SpyHash'; $SIG{'CHLD'}=sub { 'just a dummy' }; # this line should be reported require Net::DNS; # Any module messing with $SIG{'CHLD'} should be rep +orted from here Net::DNS->import(); # ... or here

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)