[Rt-commit] rt branch, protect_mod_perl_stdout, updated. rt-3.8.7-340-gb89a604

Ruslan Zakirov ruz at bestpractical.com
Thu Apr 8 17:28:02 EDT 2010


The branch, protect_mod_perl_stdout has been updated
       via  b89a604cd36c34995eb8bde1db587bdc86fb1642 (commit)
       via  7e1535c3b8cd0ddf2419a38275d4e47337bb38e6 (commit)
      from  ac867d76715986ff780c0800bfd66cd951b03625 (commit)

Summary of changes:
 bin/webmux.pl.in          |   16 ++++++++++++++++
 lib/RT/Interface/Email.pm |    3 ++-
 2 files changed, 18 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 7e1535c3b8cd0ddf2419a38275d4e47337bb38e6
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Apr 9 01:25:55 2010 +0400

    usually sendmail doesn't print anything to stdout

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index e0815fb..37013a0 100755
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -444,7 +444,8 @@ sub SendEmail {
             # don't ignore CHLD signal to get proper exit code
             local $SIG{'CHLD'} = 'DEFAULT';
 
-            open my $mail, "|$path $args" or die "couldn't execute program: $!";
+            open my $mail, "|$path $args >/dev/null"
+                or die "couldn't execute program: $!";
 
             # if something wrong with $mail->print we will get PIPE signal, handle it
             local $SIG{'PIPE'} = sub { die "program unexpectedly closed pipe" };

commit b89a604cd36c34995eb8bde1db587bdc86fb1642
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Apr 9 01:26:33 2010 +0400

    protect FD #1 under mod_perl 2

diff --git a/bin/webmux.pl.in b/bin/webmux.pl.in
index 50b959a..73db86d 100755
--- a/bin/webmux.pl.in
+++ b/bin/webmux.pl.in
@@ -55,9 +55,25 @@ package RT::Mason;
 
 our ($Nobody, $SystemUser, $Handler, $r);
 
+my $protect_fd;
+
 sub handler {
     ($r) = @_;
 
+    if ( !$protect_fd && $ENV{'MOD_PERL'} && exists $ENV{'MOD_PERL_API_VERSION'}
+        && $ENV{'MOD_PERL_API_VERSION'} >= 2 && fileno(STDOUT) != 1
+    ) {
+        # under mod_perl2, STDOUT gets closed and re-opened, however new STDOUT
+        # is not on FD #1. In this case next IO operation will occupy this FD
+        # and make all system() and open "|-" dangerouse, for example DBI
+        # can get this FD for DB connection and system() call will close
+        # by putting grabage into the socket
+        open $protect_fd, '>/dev/null' or die "Couldn't open /dev/null: $!";
+        unless ( fileno($protect_fd) == 1 ) {
+            warn "We opened /dev/null to protect FD #1, but descriptor #1 is already occupied";
+        }
+    }
+
     local $SIG{__WARN__};
     local $SIG{__DIE__};
     RT::InitSignalHandlers();

-----------------------------------------------------------------------


More information about the Rt-commit mailing list