Commit 87f7c908 authored by Guillaume Huard's avatar Guillaume Huard
Browse files

Handling of sigpipe and of non printable characters

parent 3a42544a
......@@ -83,50 +83,6 @@ sub get_value($$$) {
}
}
# Reads a file up to a given limit, -1 if no limit
# sub bounded_read_file($$) {
# my $name = shift;
# my $bound = shift;
# my $size = ($bound == -1) ? 1024 : $bound;
# open(my $fh, "<", $name) || error("Cannot read $name");
# my $data;
# my $offset = 0;
# while ((my $number = read($fh, $data, $size, $offset)) != 0) {
# if (defined($number)) {
# $size -= $number if $bound != -1;
# $offset += $number;
# } else {
# if (! $!{EINTR}) {
# error("Error $! when reading");
# }
# }
# }
# close($fh);
# return ($data, $size == 0);
# }
# Reads a file up to a given limit, -1 if no limit
# sub write_file($$) {
# my $name = shift;
# my $bound = shift;
# my $size = ($bound == -1) ? 1024 : $bound;
# open(my $fh, "<", $name) || error("Cannot read $name");
# my $data;
# my $offset = 0;
# while ((my $number = read($fh, $data, $size, $offset)) != 0) {
# if (defined($number)) {
# $size -= $number if $bound != -1;
# $offset += $number;
# } else {
# if (! $!{EINTR}) {
# error("Error $! when reading");
# }
# }
# }
# close($fh);
# return ($data, $size == 0);
# }
# Runs a command associated to a test with a given input, returns a hash that holds the content of standard output and error as well as exit code
# Looks at outputs_limit, timeout, debug, args and input in the test to find out how to run it (but they are not necessarily expected to exist)
sub run_command($$$$) {
......@@ -149,15 +105,19 @@ sub run_command($$$$) {
debug("Executing $command");
if ($has_limits) {
$timeout = get_value($test, 'timeout', 10);
unshift @arguments, '-s9', $timeout, $command;
$command = 'timeout';
if ($timeout > 0) {
unshift @arguments, '-s9', $timeout, $command;
$command = 'timeout';
}
}
# create the process with open3 in order to store its outputs/errors in memory
my $child = {};
# error has to exists otherwise open3 merge output and error into the same stream
$child->{error} = gensym;
$SIG{PIPE} = 'DEFAULT';
my $pid = open3($child->{input}, $child->{output}, $child->{error}, $command, @arguments) || error("Cannot exec $command, error $!\n");
$SIG{PIPE} = 'IGNORE';
my $remaining = {};
my $done = {};
......@@ -417,6 +377,7 @@ sub add_values($$) {
sub preformat($) {
my $line = shift;
$line =~ s/^/>/gm;
$line =~ s/[^[:print:]\s]/./g;
return $line;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment