change exit behaviour for unix/windows exec

This commit is contained in:
Colin Gagnaire 2019-02-07 13:41:18 +01:00
parent 9d9eed9a01
commit d59da382d7
2 changed files with 15 additions and 25 deletions

View File

@ -51,19 +51,15 @@ sub windows_execute {
$| = 1; $| = 1;
pipe FROM_CHILD, TO_PARENT or do { pipe FROM_CHILD, TO_PARENT or do {
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => "Internal error: can't create pipe from child to parent: $!");
short_msg => "Internal error: can't create pipe from child to parent: $!"); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
}; };
my $job = Win32::Job->new; my $job = Win32::Job->new;
if (!($pid = $job->spawn(undef, $cmd, if (!($pid = $job->spawn(undef, $cmd,
{ stdout => \*TO_PARENT, { stdout => \*TO_PARENT,
stderr => \*TO_PARENT }))) { stderr => \*TO_PARENT }))) {
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => "Internal error: execution issue: $^E");
short_msg => "Internal error: execution issue: $^E"); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
} }
close TO_PARENT; close TO_PARENT;
@ -97,10 +93,8 @@ sub windows_execute {
close FROM_CHILD; close FROM_CHILD;
if ($ended == 0) { if ($ended == 0) {
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => "Command too long to execute (timeout)...");
short_msg => "Command too long to execute (timeout)..."); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
} }
chomp $stdout; chomp $stdout;
@ -110,10 +104,8 @@ sub windows_execute {
if ($result->{$pid}->{exitcode} != 0) { if ($result->{$pid}->{exitcode} != 0) {
$stdout =~ s/\n/ - /g; $stdout =~ s/\n/ - /g;
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => "Command error: $stdout");
short_msg => "Command error: $stdout"); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
} }
return ($stdout, $result->{$pid}->{exitcode}); return ($stdout, $result->{$pid}->{exitcode});
@ -190,10 +182,8 @@ sub unix_execute {
$stdout =~ s/\r//g; $stdout =~ s/\r//g;
if ($lerror <= -1000) { if ($lerror <= -1000) {
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => $stdout);
short_msg => $stdout); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
} }
if (defined($options{no_quit}) && $options{no_quit} == 1) { if (defined($options{no_quit}) && $options{no_quit} == 1) {
@ -202,10 +192,8 @@ sub unix_execute {
if ($exit_code != 0 && (!defined($options{no_errors}) || !defined($options{no_errors}->{$exit_code}))) { if ($exit_code != 0 && (!defined($options{no_errors}) || !defined($options{no_errors}->{$exit_code}))) {
$stdout =~ s/\n/ - /g; $stdout =~ s/\n/ - /g;
$options{output}->output_add(severity => 'UNKNOWN', $options{output}->add_option_msg(short_msg => "Command error: $stdout");
short_msg => "Command error: $stdout"); $options{output}->option_exit();
$options{output}->display();
$options{output}->exit();
} }
return $stdout; return $stdout;

View File

@ -1060,7 +1060,9 @@ Filter UOM that match the regexp.
=item B<--opt-exit> =item B<--opt-exit>
Exit code for an option error, usage (default: unknown). Optional exit code for an execution error (i.e. wrong option provided,
SSH connection refused, timeout, etc)
(Default: unknown).
=item B<--output-xml> =item B<--output-xml>