Permalink
Browse files

chdir to the given CGI script path. Fix #338

  • Loading branch information...
1 parent 7ca56c6 commit 14e06a5e3e711251d226b2f2ca91034b951fdbf2 @miyagawa miyagawa committed Feb 4, 2013
Showing with 4 additions and 0 deletions.
  1. +4 −0 lib/Plack/App/WrapCGI.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use parent qw(Plack::Component);
use Plack::Util::Accessor qw(script execute _app);
+use File::Spec;
use CGI::Emulate::PSGI;
use CGI::Compile;
use Carp;
@@ -13,6 +14,8 @@ sub prepare_app {
my $script = $self->script
or croak "'script' is not set";
+ $script = File::Spec->rel2abs($script);
+
if ($self->execute) {
my $app = sub {
my $env = shift;
@@ -41,6 +44,7 @@ sub prepare_app {
open( STDIN, "<&=" . fileno($stdinr) )
or Carp::croak "Cannot dup STDIN: $!";
+ chdir(File::Basename::dirname($script));
exec($script) or Carp::croak("cannot exec: $!");
exit(2);

0 comments on commit 14e06a5

Please sign in to comment.