You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2002/05/22 19:44:22 UTC

$r->chdir_file for registry revistited

i'm working on the issue with chdir, which we cannot use in 2.0, because 
it's not thread-safe.

The issue of require() and friends when they use relative paths is 
easily resolved by pushing the script's dir as the first element of @INC.

The big issue is the open() call when it tries to open a file relative 
to the script's dir. We could override open() but its args are very 
complex which will require an expensive parser, so it's a no-no. A 
simpler solution is to tell the user to use full paths everywhere. This 
can be done in a portable way using this code

use File::Basename ();
my $cwd = File::Basename::dirname($0);

we could supply a wrapper  to shorten things and cache the value for 
registry scripts to speed things up, so the user will call:

ModPerl::Registry::cwd();

to make it back-compatible with 1.x we need to include this wrapper at 
least in 1.27 that's about to be released. PerlRun and other scripts can 
still use ModPerl::Registry::cwd();

or should we use some longer sub name and export it into the script's 
namespace?

In any case if the wrapper is used, the scripts won't work under 
mod_cgi. On the other hand if File::Basename::dirname() is used 
explicitly the script will still work with mod_cgi.

The worst thing about this workaround, no matter how we implement it, is 
that users will have to modify their code to make this work. So the cool 
idea of "run your scripts unaltered" doesn't work any more :(

May be we can still have a special mode in which chdir() is performed if 
running under non-threaded mpm? For those who need a transition period?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: $r->chdir_file for registry revistited

Posted by Per Einar Ellefsen <pe...@skynet.be>.
At 21:43 22.05.2002, Doug MacEachern wrote:
>On Thu, 23 May 2002, Stas Bekman wrote:
>
> > In any case if the wrapper is used, the scripts won't work under
> > mod_cgi. On the other hand if File::Basename::dirname() is used
> > explicitly the script will still work with mod_cgi.
>
>good point.  we should probably not bother providing something special in
>this case.  at least not something that is also added to 1.27.  2.0 can
>have something fast and clean that uses apr, which 1.x doesn't have.

We definitely shouldn't have something that makes mod_perl Registry scripts 
incompatible with CGI. In that case people might just re-start from scratch 
with handlers.

> > The worst thing about this workaround, no matter how we implement it, is
> > that users will have to modify their code to make this work. So the cool
> > idea of "run your scripts unaltered" doesn't work any more :(
>
>umm, sloppy cgi scripts have always required changes to run properly in
>1.x.  one might consider depending on '.' and chdir to be sloppy.
>and if that's the only change one has to make for a cgi script to also be
>thread-safe, that ain't too bad.

Hmm, I know I come with problems without much of a solution, but I would 
just like to express my concern as to this: the way I see it, opening files 
by depending on '.' is *really* common for CGI scripts, so I think we would 
need a solution. The way I know it, people won't remember about this (or 
not even read bout it), and have all kinds of problems with their scripts, 
then come to us asking why mod_perl can't run their CGI scripts, etc etc.

>the goal of 2.x is to have enough compat layer so code will _run_ in
>both 1.x and 2.x.  that doesn't mean changes won't be required such as
>this case or $r->connection->user changing to $r->user.  but once the
>change is made, the code will run with both 2.x and 1.x.  that is what's
>important.

IMO, $r->user is much less common than the above open() problem.

> > May be we can still have a special mode in which chdir() is performed if
> > running under non-threaded mpm? For those who need a transition period?
>
>we should probably have it die("chdir not supported in threaded MPMs");
>and warn("chdir ok in prefork MPM, will not work in threaded MPM");

If it can be made to work under prefork MPM, that is atleast a good step 
forward. But there will still be many people using threaded MPM in Apache 
2, because "it's the latest and greatest" everyone's talking about.


-- 
Per Einar Ellefsen
per.einar@skynet.be



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: $r->chdir_file for registry revistited

Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 23 May 2002, Stas Bekman wrote:
 
> In any case if the wrapper is used, the scripts won't work under 
> mod_cgi. On the other hand if File::Basename::dirname() is used 
> explicitly the script will still work with mod_cgi.

good point.  we should probably not bother providing something special in 
this case.  at least not something that is also added to 1.27.  2.0 can 
have something fast and clean that uses apr, which 1.x doesn't have.
 
> The worst thing about this workaround, no matter how we implement it, is 
> that users will have to modify their code to make this work. So the cool 
> idea of "run your scripts unaltered" doesn't work any more :(

umm, sloppy cgi scripts have always required changes to run properly in 
1.x.  one might consider depending on '.' and chdir to be sloppy.
and if that's the only change one has to make for a cgi script to also be 
thread-safe, that ain't too bad.

the goal of 2.x is to have enough compat layer so code will _run_ in 
both 1.x and 2.x.  that doesn't mean changes won't be required such as 
this case or $r->connection->user changing to $r->user.  but once the 
change is made, the code will run with both 2.x and 1.x.  that is what's 
important.
 
> May be we can still have a special mode in which chdir() is performed if 
> running under non-threaded mpm? For those who need a transition period?

we should probably have it die("chdir not supported in threaded MPMs");
and warn("chdir ok in prefork MPM, will not work in threaded MPM");


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org