Skip to content

Commit

Permalink
Item14205: Fixed STDIN issue when post data was lost.
Browse files Browse the repository at this point in the history
- 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 d079f79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions FastCGIEngineContrib/lib/Foswiki/Engine/FastCGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 23 additions & 1 deletion core/lib/Foswiki/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Engine/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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*(.*)/;
Expand Down

0 comments on commit d079f79

Please sign in to comment.