Subject: [PATCH RFC3.5.1 05/12] send-email: Improve readability and error-handling in send_message's sendmail code

From: Michael Witten <[email-masked]>
Date: Sun, 19 Apr 2009 08:49:35 -0500

Signed-off-by: Michael Witten <[email-masked]>
---
 git-send-email.perl |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 559e17b..3a140cd 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -967,15 +967,22 @@ X-Mailer: git-send-email $gitversion
 	}
 
 	if ($dry_run) {
+
 		# We don't want to send the email.
+
 	} elsif ($smtp_server_is_a_command) {
-		my $pid = open my $sm, '|-';
-		defined $pid or die $!;
-		if (!$pid) {
-			exec($smtp_server, @sendmail_parameters) or die $!;
-		}
-		print $sm "$header\n$message";
-		close $sm or die $?;
+
+		defined (my $pid = open my $pipe, '|-')
+			or die "Could not fork to run '$smtp_server': $!\n";
+
+		$pid or exec($smtp_server, @sendmail_parameters)
+			or die "Could not run '$smtp_server': $!\n";
+
+		local $SIG{PIPE} = 'IGNORE';
+
+		print $pipe "$header\n$message";
+		close $pipe or die "'$smtp_server' exited with status $?: $!\n";
+
 	} else {
 
 		if (!defined $smtp_server) {
-- 
1.6.2.2.479.g2aec