I've got some weird situation going on with a 3rd party perl script. To demonstrate:
my $rc = system("tar -C /app/src -xvf /app/package.tar.gz");
if ($rc != 0)
{
print "Return code: $rc";
}
Running tar -C /app/src -xvf /app/package.tar.gz
directly on the shell works just fine, echo $?
shows the exit status 0
. All good.
Also, when running this small perl snippet the return is always -1
. If I try something like:
my $rc = system("ls");
if ($rc != 0)
{
print "Return code: $rc";
}
...the return code will also be -1
.
I don't have much knowledge in perl, so I wonder what could possibly trigger this behaviour.
The documentation doesn't mention anything in particular regarding this (http://perldoc.perl.org/functions/system.html).
Solution:
Fetching $!
to get some more details about the error:
my $rc = system("tar -C /app/src -xvf /app/package.tar.gz");
if ($rc != 0)
{
print "Return code: $rc\n";
print "Reason: $!";
}
Returned:
Return code: -1
Reason: No child processes
Applying $SIG{'CHLD'} = 'DEFAULT';
fixed the issue:
$SIG{'CHLD'} = 'DEFAULT';
my $rc = system("tar -C /app/src -xvf /app/package.tar.gz");
if ($rc != 0)
{
print "Return code: $rc\n";
print "Reason: $!";
}
Some details from: What's the difference between various $SIG{CHLD} values?