develooper Front page | perl.perl5.porters | Postings from September 2005

$^CHILD_ERROR_NATIVE issues

Thread Next
From:
Ken Hirsch
Date:
September 28, 2005 17:06
Subject:
$^CHILD_ERROR_NATIVE issues
Message ID:
51c4e47205092814383f294c2d@mail.gmail.com
Thanks to Steve Hay for pointing out the new ${^CHILD_ERROR_NATIVE}. I had
to modify mpeixish.h to include <sys/wait.h>, but now CHILD_ERROR_NATIVE
works on MPE. However, it does introduce a couple of new issues.

Those who were previously using WEXITSTATUS($?) now have to change their
code.
In the core distribution, that's just these two:
lib/Test/Harness/Straps.pm
lib/Test/Simple/t/exit.t

And there are a few tests which fail because of END blocks fiddling with $?
For example, running "t/pod/pod2usage2.t", when the child exits, there's an
END block in Test::Builder which does _my_exit($?), which sets $?.

Here is a small program which reproduces the result:
$ cat testend.pl
my $self = "Parent";
if (fork == 0) {
$self = "Child";
exit(5);
} else {
wait;
print "Child status = $?\n";
print "Child status>>8 = ", $?>>8, "\n";
}
sub my_exit {
$? = $_[0]
}
END {
if ($self eq "Child") {
print "$self END block\n";
print "before assign \$? = $?",
" \${^CHILD_ERROR_NATIVE} = ${^CHILD_ERROR_NATIVE}\n";
my_exit($?);
print "after assign \$? = $?",
" \${^CHILD_ERROR_NATIVE} = ${^CHILD_ERROR_NATIVE}\n";
}
}
__END__

$ ./perl testend.pl
Child END block
before assign $? = 1280 ${^CHILD_ERROR_NATIVE} = 5
after assign $? = 1280 ${^CHILD_ERROR_NATIVE} = 1280
Child status = 0
Child status>>8 = 0

============================================
Or, to summarize,

$? = 0 + $?

shifts the whole thing left 8 bits.

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