mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-06 03:59:31 +01:00
pbot-vm: improve exit-code handling
This commit is contained in:
parent
164ecc45a7
commit
3e2204a6b0
@ -441,8 +441,6 @@ sub cmd_print_last_statement($context, $args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub handle_program_exit($context, $data) {
|
sub handle_program_exit($context, $data) {
|
||||||
my $reason = $data->{reason};
|
|
||||||
|
|
||||||
if (not -s OUTPUT_FILENAME) { # -s gets size of file
|
if (not -s OUTPUT_FILENAME) { # -s gets size of file
|
||||||
my $locals = locals_to_string($context->{locals_end});
|
my $locals = locals_to_string($context->{locals_end});
|
||||||
|
|
||||||
@ -451,6 +449,10 @@ sub handle_program_exit($context, $data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (exists $data->{'exit-code'} && $data->{'exit-code'} != 0) {
|
||||||
|
$context->{'exit-code'} = oct $data->{'exit-code'};
|
||||||
|
}
|
||||||
|
|
||||||
_exit($context);
|
_exit($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +543,7 @@ sub handle_exec_async_output($context, $output) {
|
|||||||
if ($reason eq 'breakpoint-hit') {
|
if ($reason eq 'breakpoint-hit') {
|
||||||
handle_breakpoint_hit($context, $output);
|
handle_breakpoint_hit($context, $output);
|
||||||
}
|
}
|
||||||
elsif ($reason eq 'exited-normally') {
|
elsif ($reason eq 'exited-normally' || $reason eq 'exited') {
|
||||||
handle_program_exit($context, $output);
|
handle_program_exit($context, $output);
|
||||||
}
|
}
|
||||||
elsif ($reason eq 'signal-received') {
|
elsif ($reason eq 'signal-received') {
|
||||||
@ -592,9 +594,9 @@ sub _exit($context) {
|
|||||||
my $output = do { local $/; <$fh> };
|
my $output = do { local $/; <$fh> };
|
||||||
close $fh;
|
close $fh;
|
||||||
|
|
||||||
print STDOUT "$output\n";
|
print STDOUT "$output";
|
||||||
|
|
||||||
exit;
|
exit ($context->{'exit-code'} // 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
# send text to OUTPUT_FILENAME file
|
# send text to OUTPUT_FILENAME file
|
||||||
|
@ -150,9 +150,11 @@ sub run_command($command, $mod) {
|
|||||||
if (not $mod->{error}) {
|
if (not $mod->{error}) {
|
||||||
$mod->{output} .= "Success (no output).\n";
|
$mod->{output} .= "Success (no output).\n";
|
||||||
} else {
|
} else {
|
||||||
$mod->{output} .= "Exit code $mod->{error}.\n";
|
$mod->{output} .= "Exit $mod->{error}.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elsif ($mod->{error}) {
|
||||||
|
$mod->{output} .= " [Exit $mod->{error}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $mod->{output};
|
return $mod->{output};
|
||||||
|
@ -68,7 +68,7 @@ sub postprocess {
|
|||||||
$self->SUPER::postprocess;
|
$self->SUPER::postprocess;
|
||||||
|
|
||||||
# no errors compiling, but if output contains something, it must be diagnostic messages
|
# no errors compiling, but if output contains something, it must be diagnostic messages
|
||||||
if(length $self->{output}) {
|
if (length $self->{output}) {
|
||||||
$self->{output} =~ s/^\s+//;
|
$self->{output} =~ s/^\s+//;
|
||||||
$self->{output} =~ s/\s+$//;
|
$self->{output} =~ s/\s+$//;
|
||||||
$self->{output} = "[$self->{output}]\n";
|
$self->{output} = "[$self->{output}]\n";
|
||||||
@ -97,6 +97,8 @@ sub postprocess {
|
|||||||
($exitval, $stdout, $stderr) = $self->execute(60, $input, '/bin/sh');
|
($exitval, $stdout, $stderr) = $self->execute(60, $input, '/bin/sh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->{error} = $exitval;
|
||||||
|
|
||||||
my $result = $stderr;
|
my $result = $stderr;
|
||||||
$result .= ' ' if length $result;
|
$result .= ' ' if length $result;
|
||||||
$result .= $stdout;
|
$result .= $stdout;
|
||||||
|
Loading…
Reference in New Issue
Block a user