Permalink
Browse files

Item14205: Fixed STDIN issue when post data was lost.

- Added fhIN, fhOUT, fhERR keys on $Foswiki::engine object to provide
standard file handles for the current environment.
  • Loading branch information...
vrurg committed Nov 9, 2016
1 parent ed6218f commit d079f79e1dff1b57d5808c628fafe0526e24438c
@@ -67,11 +67,11 @@ sub run {
$args ||= {};
# Prepare output handles for FastCGI.
- $this->{$_} = IO::Handle->new foreach qw(fhOUT fhERR);
+ $this->{$_} = IO::Handle->new foreach qw(fhIN fhOUT fhERR);
# This is a little trick to make all `print STDERR' clauses send their
- # output to the log file.
+ # output to the log file. May not work for spawned processes.
STDERR->fdopen($this->{fhERR}->fileno, "w");
- my $r = FCGI::Request( \*STDIN, $this->{fhOUT}, $this->{fhERR}, \%ENV, $sock,
+ my $r = FCGI::Request( $this->{fhIN}, $this->{fhOUT}, $this->{fhERR}, \%ENV, $sock,
&FCGI::FAIL_ACCEPT_ON_INTR );
my $manager;
View
@@ -34,12 +34,34 @@ BEGIN {
Constructs an engine object.
+The default object has three initialized keys on it: =fhIN=, =fhOUT=, =fhERR=.
+Those are filehandles used to communicate with HTTP server/environment and by
+default they're set to =STDIN=, =STDOUT=, and =STDERR= correspondingly. It is
+recommended to use =$engine->{fhERR}= instead of STDERR in order to get error
+messages always logged correctly:
+
+<verbatim>
+print $Foswiki::engine->{fhERR} "This is the error we wanna see in the log.\n";
+
+$SIG{__DIE__} = sub {
+ print $Foswiki::engine->{fhERR} @_;
+ exit 1;
+};
+</verbatim>
+
=cut
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
- my $this = {};
+ my $this = {
+
+ # Standard file handles to support engines/environments where
+ # communication is based on custom sockets.
+ fhIN => \*STDIN,
+ fhOUT => \*STDOUT,
+ fhERR => \*STDERR,
+ };
return bless $this, $class;
}
@@ -220,7 +220,7 @@ sub prepareBody {
# as breaking uploads (though cdot believes this is because of the
# deprecated dual nature of param delivering lightweight file handles,
# and it would probably work in Foswiki. Just not tried it)
- my $cgi = new CGI();
+ my $cgi = new CGI( $this->{fhIN} );
my $err = $cgi->cgi_error;
throw Foswiki::EngineException( $1, $2 )
if defined $err && $err =~ m/\s*(\d{3})\s*(.*)/;

0 comments on commit d079f79

Please sign in to comment.