Loading ...
Sorry, an error occurred while loading the content.

66156Re: Working directory: CGI vs. mod_perl

Expand Messages
  • Tom Schindl
    Aug 1, 2005
    • 0 Attachment
      Hash: SHA1

      In Apache 1.3 this has been done by mp automatically when executing
      under PerlRun or Registry but because of the oulined problems this is
      not possible any more at least when supporting all mpms.

      If you are running on prefork and your cgi must be able to run as
      Apache::Registry and CGI you could register e.g. a TransHandler which
      looks like the following:

      - ----------------------------8<----------------------------
      package Util::FixUpDirectory;

      use Apache2::RequestUtil();
      use Apache2::Const();
      use Apache2::MPM ();

      sub handler {
      my $r = shift;

      if( ! Apache2::MPM->is_threaded ) {
      chdir $r->document_root();
      } else {
      print STDERR "Could not change to doc-root because you are
      running in a threaded mpm";

      return Apache2::Const::OK;
      - ----------------------------8<----------------------------

      - ----------------------------8<----------------------------

      <Directory /perl>
      SetHandler perl-script
      PerlTransHandler Util::FixUpDirectory
      PerlResponseHandler ModPerl::Registry
      Options +ExecCGI
      - ----------------------------8<----------------------------

      I'm uncertain if one should also write a clean-up handler which sets the
      directory back to "/" or does Apache starts every request at "/"?


      Jan Eden schrieb:
      > Hi Tom,
      > Tom Schindl wrote on 01.08.2005:
      >>-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
      >>If you are running mp2 that's true simply because of the fact that
      >>chdir in perl is not thread-safe :-(
      >>If you are running in prefork(which is only available on *nix) you
      >>could chdir yourself at the top of your handler.
      > That's what I feared: There is really no way to determine the working directory in the mod_perl 2 configuration phase.
      > Thanks,
      > Jan

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.0 (GNU/Linux)
      Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

      -----END PGP SIGNATURE-----
    • Show all 8 messages in this topic