use IO::Socket;
use POSIX qw(WNOHANG setsid);
sub daemonize {
$SIG{CHLD} = 'IGNORE'; # Configure to autoreap zombies
die "Can't fork" unless defined ( my $child = fork ); # FORK <<<<<<<<<<<<
CORE::exit(0) if $child; # Parent exits
setsid(); # Become session leader
open( STDIN, "/dev/null" ); # Detach STDOUT from shell
open( STDERR, ">&STDOUT" ); # Detach STDERR from shell
chdir '/tmp'; # Change working directory
umask(0); # Reset umask
$ENV{PATH} = '/bin:/sbin:/usr/sbin'; # Reset PATH
}
####
sub cmd_wrapper {
my $cmd = shift;
my @out;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 15;
## (CSV output logged) ##
@out = qx[$cmd]; #<<<<< Shell out
## (CSV output *NOT* logged) ##
alarm 0;
};
return $@ if $@ ne ""
return wantarray ? @out : join '', @out;
}
##
##
## Run the Curl command ##
my $restURL = $opt_ref->{restURL} . $opt_ref->{pagingURL};
say "DEBUG: \$restURL: \]$restURL\[" if $cfg{debug} or $cfg{test};
my $cmd = "$curlCommand -X $opt_ref->{method} $restURL";
my $results = cmd_wrapper( $cmd, $opt_ref, $info_ref, $cfh{csv_export}, \@rpt_hdr, 1 );
say 'DEBUG: $results: ', Dumper $results if $cfg{debug}; #or $cfg{test} > 1;
$info_ref->{name} = $?;
$info_ref->{primary} = $cmd;
$info_ref->{status_msg} = $results;
#=pod
# Uncommented I see results, Commented out cmd_wrapper seems to hang.
## CASE: Connection issue
if( $? == -1 ) { # WARN: Will this still work now that I'm calling cmd_wrapper()???
$info_ref->{entry_level} = 'DEBUG';
$info_ref->{status} = 'runCurl connection failed';
csv_log( $opt_ref, $info_ref, $cfh{csv_export}, \@rpt_hdr, 1 );
return; #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< RETURN
}
#=cut
##
##
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux
Red Hat Enterprise Linux Server release 5.11 (Tikanga)