[Pgp-tools-commit] r781 - trunk/caff

Guilhem Moulin guilhem-guest at moszumanska.debian.org
Fri Feb 20 19:36:24 UTC 2015


Author: guilhem-guest
Date: 2015-02-20 19:36:24 +0000 (Fri, 20 Feb 2015)
New Revision: 781

Modified:
   trunk/caff/caff
Log:
caff: Properly close GnuPG::Handles.

Modified: trunk/caff/caff
===================================================================
--- trunk/caff/caff	2015-02-20 19:36:19 UTC (rev 780)
+++ trunk/caff/caff	2015-02-20 19:36:24 UTC (rev 781)
@@ -487,7 +487,7 @@
 		my $handles = mkGnuPG_fds ( stdout => undef, status => undef );
 		my $pid = $gpg->list_public_keys(handles => $handles, command_args => [ $gecos ]);
 		my ($stdout, $stderr, $status) = readwrite_gpg('', $handles);
-		waitpid $pid, 0;
+		done_gpg($pid, $handles);
 
 		if ($stdout eq '') {
 			mywarn "No data from gpg for list-key"; # There should be at least 'tru:' everywhere.
@@ -653,6 +653,16 @@
 	return $handles;
 };
 
+sub done_gpg($;$) {
+	my ($pid, $handles) = @_;
+	waitpid $pid, 0;
+	mywarn("$CONFIG{gpg} exited with value ".($? >> 8)) if $?;
+	return unless defined $handles;
+	foreach (GnuPG::Handles::HANDLES) {
+		next unless defined $handles->{$_} and $handles->{$_} !~ /^[<>]&/;
+		$handles->{$_}->close if $handles->{$_}->opened;
+	}
+}
 
 sub readwrite_gpg($$%) {
 	my ($in, $handles, %options) = @_;
@@ -843,8 +853,7 @@
 	} else {
 		my $stdout = $handles->{stdout};
 		my $asciikey = do { local $/; <$stdout> };
-		waitpid $pid, 0;
-		close $stdout;
+		done_gpg($pid, $handles);
 		return $asciikey;
 	}
 };
@@ -893,7 +902,7 @@
 		my $handles = mkGnuPG_fds( stdin => undef, stdout => undef, status => undef );
 		my $pid = $gpg->encrypt(handles => $handles);
 		my ($stdout, $status) = readwrite_gpg($message, $handles);
-		waitpid $pid, 0;
+		done_gpg($pid, $handles);
 		if ($stdout eq '') {
 			if (($status =~ /^\[GNUPG:\] INV_RECP ([0-9]+) ([0-9A-F]+)$/m) and
 			    (defined $CONFIG{'also-encrypt-to'})) {
@@ -1108,9 +1117,8 @@
 			delete @keyids{@keys};
 		}
 	}
-	waitpid $iPid, 0; # import done
-	waitpid $ePid, 0; # export done
-	close $handles->{$_} for qw/stdin status/;
+	done_gpg($iPid, $handles);	# import done
+	done_gpg($ePid);			# export done
 
 	if (wantarray) {
 		return (keys %keyids); # failed to import
@@ -1145,8 +1153,7 @@
 			$err = 0;
 		}
 	}
-	waitpid $pid, 0;
-	close $status;
+	done_gpg($pid, $handles);
 	return $err;
 }
 
@@ -1430,8 +1437,7 @@
 			notice ("Got unknown reply from gpg: ".$_);
 		}
 	};
-	waitpid $pid, 0;
-	close $status;
+	done_gpg($pid, $handles);
 
 	if (scalar %local_keyids) {
 		notice ("Import failed for: ". (join ' ', keys %local_keyids)."." . ($had_v3_keys ? " (Or maybe it's one of those ugly v3 keys?)" :  ""));
@@ -1500,8 +1506,7 @@
 			notice ("Got unknown reply from gpg: ".$_);
 		}
 	}
-	waitpid $pid, 0;
-	close $stdout;
+	done_gpg($pid, $handles);
 
 	unless (defined $KEYS{$keyid}) {
 		mywarn ("No public keys found with list-key $keyid (note that caff uses its own keyring in $GNUPGHOME).");
@@ -1625,8 +1630,7 @@
 
 
 		readwrite_gpg("save\n", $handles);
-		waitpid $pid, 0;
-		myerror(1, "Couldn't prune $keyid: $?.") if $?;
+		done_gpg($pid, $handles);
 
 		my $asciikey = export_keys($uiddir, [$keyid]);
 		undef $uiddir; # delete dir
@@ -1721,7 +1725,7 @@
 				}
 
 				readwrite_gpg("save\n", $handles);
-				waitpid $pid, 0;
+				done_gpg($pid, $handles);
 				myerror(1, "Couldn't auto lsign $keyid: $?.") if $?;
 			}
 		}




More information about the Pgp-tools-commit mailing list