Martin Michlmayr <[EMAIL PROTECTED]> writes:

> * Roger Leigh <[EMAIL PROTECTED]> [2007-02-04 23:00]:
>> While it would be possible to send all stderr output to /dev/null, I
>> don't feel that this is appropriate, because it will discard all error
>> reporting when running apt-cache.  One solution I am now looking at is
>> sending stderr to the package log (rather than the main log) for just
>> apt-cache invokations.  Errors and warnings will still be logged, but
>> they will then not get mailed to you separately.  Does that sound OK.
>
> Sounds good to me.

Please could you try the attached patch?

This should do the above, preventing apt-cache errors and warnings
From going to stderr; they go to the package log instead.


Thanks,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
Index: sbuild
===================================================================
--- sbuild	(revision 1082)
+++ sbuild	(working copy)
@@ -29,6 +29,7 @@
 use POSIX;
 use File::Basename qw(basename dirname);
 use IO::Handle;
+use IPC::Open3;
 use FileHandle;
 use Sbuild qw(binNMU_version version_compare);
 
@@ -51,6 +52,10 @@
 # in case the terminal disappears, the build should continue
 $SIG{'HUP'} = 'IGNORE';
 
+if (!open(main::DEVNULL, '+<', '/dev/null')) {
+	die "Cannot open /dev/null: $!\n";;
+}
+
 umask(022);
 
 $main::distribution = "unstable";
@@ -414,9 +419,10 @@
 
 		  retry:
 			print PLOG "Checking available source versions...\n";
-			my $command = get_apt_command("$conf::apt_cache", "-q showsrc $pkg 2>&1 </dev/null", $main::username, 0);
-			if (!open( PIPE, "$command |" )) {
-				print PLOG "Can't open pipe to apt-cache: $!\n";
+			my $command = get_apt_command("$conf::apt_cache", "-q showsrc $pkg", $main::username, 0);
+			my $pid = open3(\*main::DEVNULL, \*PIPE, '>&PLOG', "$command" );
+			if (!$pid) {
+				print PLOG "Can't open pipe to $conf::apt_cache: $!\n";
 				return ("ERROR");
 			}
 			{ local($/) = "";
@@ -430,12 +436,13 @@
 				  @{$entries{$ver}} = map { (split( /\s+/, $_ ))[3] }
 					  split( "\n", $tfile );
 			  } else {
-				  print PLOG "apt-cache returned no information about $pkg source\n";
+				  print PLOG "$conf::apt_cache returned no information about $pkg source\n";
 				  print PLOG "Are there any deb-src lines in your /etc/apt/sources.list?\n";
 				  return ("ERROR");
 			  }
 		  }
-			close( PIPE );
+			close(PIPE);
+			waitpid $pid, 0;
 			if ($?) {
 				print PLOG "$conf::apt_cache failed\n";
 				return ("ERROR");
@@ -1745,14 +1752,18 @@
 
 	my $command = get_apt_command("$conf::apt_cache", "policy @interest", $main::username, 0);
 
-	open(APTCACHE, "$command |" )
-		or die "Cannot start $conf::apt_cache $!\n";
+	my $pid = open3(\*main::DEVNULL, \*APTCACHE, '>&PLOG', "$command" );
+	if (!$pid) {
+		die "Cannot start $conf::apt_cache $!\n";
+	}
 	while(<APTCACHE>) {
 		$package=$1 if /^([0-9a-z+.-]+):$/;
 		$packages{$package}->{curversion}=$1 if /^ {2}Installed: ([0-9a-zA-Z-.:~+]*)$/;
 		$packages{$package}->{defversion}=$1 if /^ {2}Candidate: ([0-9a-zA-Z-.:~+]*)$/;
 		push @{$packages{$package}->{versions}}, "$2" if /^ (\*{3}| {3}) ([0-9a-zA-Z-.:~+]*) 0$/;
 	}
+	close(APTCACHE);
+	waitpid $pid, 0;
 	die "$conf::apt_cache exit status $?\n" if $?;
 
 	return %packages;
@@ -2252,9 +2263,11 @@
 	local(*PIPE);
 	my %deps;
 	
-	my $command = get_apt_command("$conf::apt_cache", "show @_ 2>&1", $main::username, 0);
-	open( PIPE, "$command |" )
-		or die "Cannot start $conf::apt_cache $!\n";
+	my $command = get_apt_command("$conf::apt_cache", "show @_", $main::username, 0);
+	my $pid = open3(\*main::DEVNULL, \*PIPE, '>&PLOG', "$command" );
+	if (!$pid) {
+		die "Cannot start $conf::apt_cache $!\n";
+	}
 	local($/) = "";
 	while( <PIPE> ) {
 		my ($name, $dep, $predep);
@@ -2267,6 +2280,7 @@
 		$deps{$name} = $dep;
 	}
 	close( PIPE );
+	waitpid $pid, 0;
 	die "$conf::apt_cache exit status $?\n" if $?;
 
 	return \%deps;
@@ -2275,9 +2289,11 @@
 sub get_virtuals {
 	local(*PIPE);
 
-	my $command = get_apt_command("$conf::apt_cache", "showpkg @_ 2>&1", $main::username, 0);
-	open( PIPE, "$command |" )
-		or die "Cannot start $conf::apt_cache: $!\n";
+	my $command = get_apt_command("$conf::apt_cache", "showpkg @_", $main::username, 0);
+	my $pid = open3(\*main::DEVNULL, \*PIPE, '>&PLOG', "$command" );
+	if (!$pid) {
+		die "Cannot start $conf::apt_cache $!\n";
+	}
 	my $name;
 	my $in_rprov = 0;
 	my %provided_by;
@@ -2296,6 +2312,7 @@
 		}
 	}
 	close( PIPE );
+	waitpid $pid, 0;
 	die "$conf::apt_cache exit status $?\n" if $?;
 
 	return \%provided_by;

Attachment: pgp4Ej6ZX2ge5.pgp
Description: PGP signature

Reply via email to