[Rt-commit] r4398 - rt/branches/3.4-RELEASE/lib/RT/Action

ruz at bestpractical.com ruz at bestpractical.com
Wed Jan 18 16:28:41 EST 2006


Author: ruz
Date: Wed Jan 18 16:28:41 2006
New Revision: 4398

Modified:
   rt/branches/3.4-RELEASE/lib/RT/Action/SendEmail.pm

Log:
* handle SIGPIPE, could happen if sendmail closes pipe before
  we output all message
* handle SIGCHLD with default handler to get exit status from sendmail
* handle errors in 'close', system errors or sendmail exit with error
* only send warn on the error exit status


Modified: rt/branches/3.4-RELEASE/lib/RT/Action/SendEmail.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Action/SendEmail.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Action/SendEmail.pm	Wed Jan 18 16:28:41 2006
@@ -253,12 +253,28 @@
 
     if ( $RT::MailCommand eq 'sendmailpipe' ) {
         eval {
-            open( my $mail, "|$RT::SendmailPath $RT::SendmailArguments" ) || die $!;
+            # don't ignore CHLD signal to get proper exit code
+            local $SIG{'CHLD'} = 'DEFAULT';
+
+            my $mail;
+            unless( open $mail, "|$RT::SendmailPath $RT::SendmailArguments" ) {
+                die "Couldn't run $RT::SendmailPath: $!";
+            }
+
+            # if something wrong with $mail->print we will get PIPE signal, handle it
+            local $SIG{'PIPE'} = sub { die "$RT::SendmailPath closed pipe" };
             $MIMEObj->print($mail);
-            close($mail);
+
+            unless ( close $mail ) {
+                die "Close failed: $!" if $!; # system error
+                # sendmail exit statuses mostly errors with data not software
+                # TODO: status parsing: core dump, exit on signal or EX_*
+                $RT::Logger->warning( "$RT::SendmailPath exitted with status $?" );
+            }
         };
         if ($@) {
-            $RT::Logger->crit( $msgid . "Could not send mail. -" . $@ );
+            $RT::Logger->crit( $msgid . "Could not send mail: " . $@ );
+            return 0;
         }
     }
     else {


More information about the Rt-commit mailing list