From 00815552f22c1b60c32a6c42f82b6a2ad6ec6952 Mon Sep 17 00:00:00 2001 From: eschnett Date: Fri, 16 Nov 2012 02:46:49 +0000 Subject: Do not buffer output from thorn configuration scripts Use a pipe when reading output from thorn configuration scripts, and display the output right away instead of buffering it. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4912 17b73243-c579-4c4c-a9d2-2d5706c11dac --- lib/sbin/ConfigScriptParser.pl | 224 +++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 134 deletions(-) (limited to 'lib') diff --git a/lib/sbin/ConfigScriptParser.pl b/lib/sbin/ConfigScriptParser.pl index 25e7d36b..80cb1a18 100644 --- a/lib/sbin/ConfigScriptParser.pl +++ b/lib/sbin/ConfigScriptParser.pl @@ -19,142 +19,98 @@ #@@*/ sub ParseConfigScript { - my($config_dir, $provides, $lang, $script, $thorn, $cfg)=@_; - my($line_number, $line, $temp); - my($exit_value, $signal_num, $dumped_core); - - my $start_dir = `pwd`; - chdir $config_dir; - - # Run the configuration script in the config_dir folder - if ($lang ne '' && $script ne '') - { - @data=`$lang $script`; - } - $exit_value = $? >> 8; - $signal_num = $? & 127; - $dumped_core = $? & 128; - - for($line_number = 0; $line_number < @data; $line_number++) - { - $line = $data[$line_number]; - - chomp $line; - next if (! $line); - - # Parse the line - if($line =~ m/^\s*BEGIN\s+DEFINE\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+DEFINE\s*/i) - { - $cfg->{"\U$thorn $provides\E DEFINE"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - - } - } - elsif($line =~ m/^\s*BEGIN\s+INCLUDE\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+INCLUDE\s*/i) - { - $cfg->{"\U$thorn $provides\E INCLUDE"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - - } - } - elsif($line =~ m/^\s*BEGIN\s+ERROR\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+ERROR\s*/i) - { - $cfg->{"\U$thorn $provides\E ERROR"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - } - } - elsif($line =~ m/^\s*BEGIN\s+MESSAGE\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+MESSAGE\s*/i) - { - $cfg->{"\U$thorn $provides\E MESSAGE"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - } + my ($config_dir, $provides, $lang, $script, $thorn, $cfg) = @_; + + return if $lang eq '' || $script eq ''; + + print "\n"; + print "********************************************************************************\n"; + print "Running configuration script for thorn $thorn:\n"; + + # Run the configuration script in the config_dir folder + chdir $config_dir; + open (my $lines, '-|', "$lang $script"); + + my $line_number = 0; + while (my $line = <$lines>) { + chomp $line; ++$line_number; + next if ! $line; + + # Parse the line + if ($line =~ m/^\s*BEGIN\s+DEFINE\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+DEFINE\s*/i) { + $cfg->{"\U$thorn $provides\E DEFINE"} .= "$line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*BEGIN\s+INCLUDE\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+INCLUDE\s*/i) { + $cfg->{"\U$thorn $provides\E INCLUDE"} .= "$line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*BEGIN\s+ERROR\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+ERROR\s*/i) { + $cfg->{"\U$thorn $provides\E ERROR"} .= "$line\n"; + print "ERROR: $line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*BEGIN\s+MESSAGE\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+MESSAGE\s*/i) { + $cfg->{"\U$thorn $provides\E MESSAGE"} .= "$line\n"; + print "$line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*BEGIN\s+MAKE_DEFINITION\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+MAKE_DEFINITION\s*/i) { + $cfg->{"\U$thorn $provides\E MAKE_DEFINITION"} .= "$line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*BEGIN\s+MAKE_DEPENDENCY\s*/i) { + $line = <$lines>; chomp $line; ++$line_number; + while ($line !~ m/^\s*END\s+MAKE_DEPENDENCY\s*/i) { + $cfg->{"\U$thorn $provides\E MAKE_DEPENDENCY"} .= "$line\n"; + $line = <$lines>; chomp $line; ++$line_number; + } + } elsif ($line =~ m/^\s*INCLUDE_DIRECTORY\s+(.*)$/i) { + $cfg->{"\U$thorn $provides\E INCLUDE_DIRECTORY"} .= " $1"; + } elsif ($line =~ m/^\s*LIBRARY_DIRECTORY\s+(.*)$/i) { + $cfg->{"\U$thorn $provides\E LIBRARY_DIRECTORY"} .= " $1"; + } elsif ($line =~ m/^\s*LIBRARY\s+(.*)$/i) { + $cfg->{"\U$thorn $provides\E LIBRARY"} .= " $1"; + } else { + &CST_error(0, "Unrecognised line $line_number '$line' produced by configuration script '$script'"); + } } - elsif($line =~ m/^\s*BEGIN\s+MAKE_DEFINITION\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+MAKE_DEFINITION\s*/i) - { - $cfg->{"\U$thorn $provides\E MAKE_DEFINITION"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - } + + close $lines; + my $exit_value = $? >> 8; + my $signal_num = $? & 127; + my $dumped_core = $? & 128; + + my $error_msg = $cfg->{"\U$thorn $provides\E ERROR"}; + chomp $error_msg; + if ($error_msg) { + $error_msg = " Error message: '$error_msg'"; + } else { + $error_msg = ' (no error message)'; } - elsif($line =~ m/^\s*BEGIN\s+MAKE_DEPENDENCY\s*/i) - { - $line_number++; - $line = $data[$line_number]; - chomp $line; - while($line !~ m/^\s*END\s+MAKE_DEPENDENCY\s*/i) - { - $cfg->{"\U$thorn $provides\E MAKE_DEPENDENCY"} .= $line . "\n"; - $line_number++; - $line = $data[$line_number]; - chomp $line; - } - } - elsif($line =~ m/^\s*INCLUDE_DIRECTORY\s+(.*)$/i) - { - $cfg->{"\U$thorn $provides\E INCLUDE_DIRECTORY"} .= ' ' . $1; - } - elsif($line =~ m/^\s*LIBRARY_DIRECTORY\s+(.*)$/i) - { - $cfg->{"\U$thorn $provides\E LIBRARY_DIRECTORY"} .= ' ' . $1; - } - elsif($line =~ m/^\s*LIBRARY\s+(.*)$/i) - { - $cfg->{"\U$thorn $provides\E LIBRARY"} .= ' ' . $1; - } - else - { - &CST_error (0, "Unrecognised line '$line' in configuration script '$script'"); - } - } - - chomp ($error_msg = $cfg->{"\U$thorn $provides\E ERROR"}); - $error_msg = $error_msg ? " Error message: '$error_msg'" : - ' (no error message)'; - - print $cfg->{"\U$thorn $provides\E MESSAGE"}; - - $msg = "Configuration script for thorn $thorn "; - &CST_error (0, $msg . "returned exit code $exit_value\n$error_msg") - if ($exit_value); - &CST_error (0, $msg . "received signal $signal_num\n$error_msg") - if ($signal_num); - &CST_error (0, $msg . "dumped core\n$error_msg") - if ($dumped_core); - + + my $msg = "Configuration script for thorn $thorn"; + &CST_error(0, "$msg returned exit code $exit_value\n$error_msg") + if $exit_value; + &CST_error(0, "$msg received signal $signal_num\n$error_msg") + if $signal_num; + &CST_error(0, "$msg dumped core\n$error_msg") + if $dumped_core; + + print "Finished running configuration script for thorn $thorn.\n"; + + # TODO: Should we abort if there was an error message, but the + # return code indicates that there was no error? } 1; -- cgit v1.2.3