Index: tools/scan-build/ccc-analyzer =================================================================== --- tools/scan-build/ccc-analyzer +++ tools/scan-build/ccc-analyzer @@ -158,28 +158,18 @@ my $mode = shift; my $Args = shift; - pipe (FROM_CHILD, TO_PARENT); - my $pid = fork(); - if ($pid == 0) { - close FROM_CHILD; - open(STDOUT,">&", \*TO_PARENT); - open(STDERR,">&", \*TO_PARENT); - exec $Clang, "-###", $mode, @$Args; - } - close(TO_PARENT); - my $line; - while () { + my $ClangLine; + my $ExecLine = join(' ', qq/"$Clang"/, "-###", $mode, @$Args, "2>&1", "|"); + open(PS, $ExecLine); + while ( ) { next if (!/\s"?-cc1"?\s/); - $line = $_; + $ClangLine = $_; } - waitpid($pid,0); - close(FROM_CHILD); - - die "could not find clang line\n" if (!defined $line); + die "could not find clang line\n" if (!defined $ClangLine); # Strip leading and trailing whitespace characters. - $line =~ s/^\s+|\s+$//g; - my @items = quotewords('\s+', 0, $line); + $ClangLine =~ s/^\s+|\s+$//g; + my @items = quotewords('\s+', 0, $ClangLine); my $cmd = shift @items; die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/)); return \@items; @@ -259,27 +249,16 @@ # Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR. # We save the output file in the 'crashes' directory if clang encounters # any problems with the file. - pipe (FROM_CHILD, TO_PARENT); - my $pid = fork(); - if ($pid == 0) { - close FROM_CHILD; - open(STDOUT,">&", \*TO_PARENT); - open(STDERR,">&", \*TO_PARENT); - exec $Cmd, @CmdArgs; - } - - close TO_PARENT; my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir); - - while () { + my $ExecLine = join(' ', qq/"$Cmd"/, @CmdArgs, "2>&1", "|"); + open(PS, $ExecLine); + while ( ) { print $ofh $_; print STDERR $_; } - close $ofh; - - waitpid($pid,0); - close(FROM_CHILD); + close PS; my $Result = $?; + close $ofh; # Did the command die because of a signal? if ($ReportFailures) { Index: tools/scan-build/scan-build =================================================================== --- tools/scan-build/scan-build +++ tools/scan-build/scan-build @@ -1232,16 +1232,9 @@ } my %EnabledCheckers; foreach my $lang ("c", "objective-c", "objective-c++", "c++") { - pipe(FROM_CHILD, TO_PARENT); - my $pid = fork(); - if ($pid == 0) { - close FROM_CHILD; - open(STDOUT,">&", \*TO_PARENT); - open(STDERR,">&", \*TO_PARENT); - exec $Clang, ( @PluginLoadCommandline_xclang, '--analyze', '-x', $lang, '-', '-###'); - } - close(TO_PARENT); - while() { + my $ExecLine = join(' ', qq/"$Clang"/, @PluginLoadCommandline_xclang, '--analyze', '-x', "$lang", '-', '-###', '2>&1', '|'); + open(PS, $ExecLine); + while () { foreach my $val (split /\s+/) { $val =~ s/\"//g; if ($val =~ /-analyzer-checker\=([^\s]+)/) { @@ -1249,23 +1242,14 @@ } } } - waitpid($pid,0); - close(FROM_CHILD); } # Query clang for complete list of checkers. if (defined $Clang && -x $Clang) { - pipe(FROM_CHILD, TO_PARENT); - my $pid = fork(); - if ($pid == 0) { - close FROM_CHILD; - open(STDOUT,">&", \*TO_PARENT); - open(STDERR,">&", \*TO_PARENT); - exec $Clang, ('-cc1', @PluginsToLoad , '-analyzer-checker-help'); - } - close(TO_PARENT); + my $ExecLine = join(' ', qq/"$Clang"/, '-cc1', @PluginsToLoad, '-analyzer-checker-help', '2>&1', '|'); + open(PS, $ExecLine); my $foundCheckers = 0; - while() { + while () { if (/CHECKERS:/) { $foundCheckers = 1; last; @@ -1277,7 +1261,7 @@ else { print("\nAVAILABLE CHECKERS:\n\n"); my $skip = 0; - while() { + while() { if (/experimental/) { $skip = 1; next; @@ -1314,10 +1298,8 @@ } print $_; } - print "\nNOTE: \"+\" indicates that an analysis is enabled by default.\n" + print "\nNOTE: \"+\" indicates that an analysis is enabled by default.\n"; } - waitpid($pid,0); - close(FROM_CHILD); } print <