You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by ColinB <cb...@yahoo.com> on 2003/07/29 13:10:12 UTC

Working directory of script is "/" !

I'm steadily making progress with getting a collection of mod_perl 1
compatibale scripts working with mod_perl 2 using the backward
compatibility mode.

However, I find that the working directory of all scripts is "/". This
occurs for both ModPerl::Registry and Apache::Registry. This causes
many scripts to fail because they call open() using a relative
pathname.

Surely the working directory of a script should be the directory in
which it resides?

It does not seem to matter what directory I am in when I invoke httpd;
the script's current directory is always "/".

I am mystified.

Here is the output from a simple "printenv" cgi script (with some of
the env variables snipped for brevity), which also prints the working
directory using getcwd (and invokes "ld -al" to list the contents of
the current directory):

Content-type: text/plain

DOCUMENT_ROOT="/dir1/dir2/httpd/htdocs"
EXITSERVERLOC="http://localhost/cgi-bin/index.cgi"
GATEWAY_INTERFACE="CGI-Perl/1.1"
HOME="/mps/home/cdi"
HTTP_ACCEPT="image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/msword, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/x-shockwave-flash, */*"
HTTP_ACCEPT_ENCODING="gzip, deflate"
HTTP_ACCEPT_LANGUAGE="en-gb"
HTTP_CONNECTION="Keep-Alive"
HTTP_USER_AGENT="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)"
MOD_PERL="mod_perl/1.99_09"
QUERY_STRING=""
REQUEST_METHOD="GET"
REQUEST_URI="/cgi-bin/printenv"
SCRIPT_FILENAME="/dir1/dir2/httpd/cgi-bin/printenv"
SCRIPT_NAME="/cgi-bin/printenv"
SERVER_PORT="8000"
SERVER_PROTOCOL="HTTP/1.1"
SERVER_SIGNATURE="<address>Apache/2.0.46 (Unix) mod_perl/1.99_09
Perl/v5.8.0 Server at homer Port 8000</address>\n"
SERVER_SOFTWARE="Apache/2.0.46 (Unix) mod_perl/1.99_09 Perl/v5.8.0"
TZ="GB"

Working directory is /
total 329

drwxr-xr-x  36 root     root        1024 Jul 16 09:50 .
drwxr-xr-x  36 root     root        1024 Jul 16 09:50 ..
lrwxrwxrwx   1 root     root           9 Jun 19 09:59 bin -> ./usr/bin
drwxr-xr-x   2 root     root         512 Jun 27 14:42 cdrom
drwxr-xr-x  16 root     sys         4608 Jun 27 15:44 dev
drwxr-xr-x   4 root     sys          512 Jun 19 10:28 devices
drwxr-xr-x  51 root     sys         3584 Jul 18 14:04 etc
drwxr-xr-x   3 root     sys          512 Jun 19 09:57 export

and so on...


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
Ed Grimm wrote:
> On Wed, 30 Jul 2003, Stas Bekman wrote:
> 
> 
>>Perrin Harkins wrote:
>>
>>>On Tue, 2003-07-29 at 07:23, Stas Bekman wrote:
>>>
>>>
>>>>That's correct. This is because $r->chdir_file in compat doesn't do
>>>>anything.  The reason is that under threaded mpm, chdir() affects all
>>>>threads. Of course we could check whether the mpm is prefork and do
>>>>things the old way, but that means that the same code won't work the
>>>>same under threaded and non-threaded mpms. Hence the limbo. Still
>>>>waiting for Arthur to finish porting safecwd package, which should
>>>>resolve this problem.
>>>
>>>When he does finish it, won't we make the threaded MPM work just like
>>>this?  It seems like it would be reasonable to get prefork working
>>>properly, even if the threaded MPM isn't ready yet. 
>>
>>It's a tricky thing. If we do have a complete implementation then it's
>>cool.  If not then we have a problem with people testing their code on
>>prefork mpm and then users getting the code malfunctioning on the
>>threaded mpms.
>>
>>I think we could have a temporary subclass of the registry (e.g.:
>>ModPerl::RegistryPrefork) which will be removed once the issue is
>>resolved. At least it'll remind the developers that their code won't
>>work on the threaded mpm setups. However if they make their code
>>working without relying on chdir then they can use Modperl::Registry
>>and the code will work everywhere.
> 
> 
> What's wrong with having the chdir code check for the threaded mpm, and,
> if it detects it, generate a warning that describes the situation?
> 
> Admittedly, I have a difficult time understanding someone who tests
> under one mpm, and then releases under another mpm without testing.  I
> realize there are people who do this sort of thing; I'm merely stating
> that I have difficulty understanding them.

Here is an example: let's say that you are stuck with windows, so you can test 
only with 'winnt'.

In any case, a simple subclass of the registry does the trick for those 
running with prefork mpm and wanting the mp1 behavior. So there is no problem, 
other than communicating the solution to those who need it.


__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by Ed Grimm <ja...@tgape.org>.
On Wed, 30 Jul 2003, Stas Bekman wrote:

> Perrin Harkins wrote:
>> On Tue, 2003-07-29 at 07:23, Stas Bekman wrote:
>> 
>>>That's correct. This is because $r->chdir_file in compat doesn't do
>>>anything.  The reason is that under threaded mpm, chdir() affects all
>>>threads. Of course we could check whether the mpm is prefork and do
>>>things the old way, but that means that the same code won't work the
>>>same under threaded and non-threaded mpms. Hence the limbo. Still
>>>waiting for Arthur to finish porting safecwd package, which should
>>>resolve this problem.
>> 
>> When he does finish it, won't we make the threaded MPM work just like
>> this?  It seems like it would be reasonable to get prefork working
>> properly, even if the threaded MPM isn't ready yet. 
> 
> It's a tricky thing. If we do have a complete implementation then it's
> cool.  If not then we have a problem with people testing their code on
> prefork mpm and then users getting the code malfunctioning on the
> threaded mpms.
> 
> I think we could have a temporary subclass of the registry (e.g.:
> ModPerl::RegistryPrefork) which will be removed once the issue is
> resolved. At least it'll remind the developers that their code won't
> work on the threaded mpm setups. However if they make their code
> working without relying on chdir then they can use Modperl::Registry
> and the code will work everywhere.

What's wrong with having the chdir code check for the threaded mpm, and,
if it detects it, generate a warning that describes the situation?

Admittedly, I have a difficult time understanding someone who tests
under one mpm, and then releases under another mpm without testing.  I
realize there are people who do this sort of thing; I'm merely stating
that I have difficulty understanding them.

Ed



Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> On Tue, 2003-07-29 at 07:23, Stas Bekman wrote:
> 
>>That's correct. This is because $r->chdir_file in compat doesn't do anything.
>>The reason is that under threaded mpm, chdir() affects all threads. Of course 
>>we could check whether the mpm is prefork and do things the old way, but that 
>>means that the same code won't work the same under threaded and non-threaded 
>>mpms. Hence the limbo. Still waiting for Arthur to finish porting safecwd 
>>package, which should resolve this problem.
> 
> 
> When he does finish it, won't we make the threaded MPM work just like
> this?  It seems like it would be reasonable to get prefork working
> properly, even if the threaded MPM isn't ready yet. 

It's a tricky thing. If we do have a complete implementation then it's cool. 
If not then we have a problem with people testing their code on prefork mpm 
and then users getting the code malfunctioning on the threaded mpms.

I think we could have a temporary subclass of the registry (e.g.: 
ModPerl::RegistryPrefork) which will be removed once the issue is resolved. At 
least it'll remind the developers that their code won't work on the threaded 
mpm setups. However if they make their code working without relying on chdir 
then they can use Modperl::Registry and the code will work everywhere.

__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-07-29 at 07:23, Stas Bekman wrote:
> That's correct. This is because $r->chdir_file in compat doesn't do anything.
> The reason is that under threaded mpm, chdir() affects all threads. Of course 
> we could check whether the mpm is prefork and do things the old way, but that 
> means that the same code won't work the same under threaded and non-threaded 
> mpms. Hence the limbo. Still waiting for Arthur to finish porting safecwd 
> package, which should resolve this problem.

When he does finish it, won't we make the threaded MPM work just like
this?  It seems like it would be reasonable to get prefork working
properly, even if the threaded MPM isn't ready yet. 

- Perrin

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
ColinB wrote:

> http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache__Registry___C_Apache__PerlRun__and_Friends
> 
> I'm a little confused about the changes you've made here. You still
> mention using Apache::Registry, and then you added the text that
> describes ModPerl::RegistryPrefork but then use it via
> 
>     PerlResponseHandler Apache::RegistryPrefork

Oops, please try again. Should be OK now.

We also need help to finish off the porting of the registry manpages, they are 
linked from the above url, but need work. Anybody wants to help?

__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
--- Stas Bekman <st...@stason.org> wrote:
> 
> > This seems to work OK. Hopefully I should now be able to remove the
> > mod_perl 1's Registry.pm file.
> > 
> > Thanks everyone.
> 
> Perfect. I've replaced the suggestion to use mp1's Apache::Registry
> with this 
> better solution, which doesn't require mp1:
> 
>
http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache__Registry___C_Apache__PerlRun__and_Friends

I'm a little confused about the changes you've made here. You still
mention using Apache::Registry, and then you added the text that
describes ModPerl::RegistryPrefork but then use it via

    PerlResponseHandler Apache::RegistryPrefork




__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
> This seems to work OK. Hopefully I should now be able to remove the
> mod_perl 1's Registry.pm file.
> 
> Thanks everyone.

Perfect. I've replaced the suggestion to use mp1's Apache::Registry with this 
better solution, which doesn't require mp1:

http://perl.apache.org/docs/2.0/user/porting/compat.html#C_Apache__Registry___C_Apache__PerlRun__and_Friends

__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
> Don't mess with the cooker, try using a subclass, e.g.:
> 
> # ModPerl/RegistryPrefork.pm
> 
> package ModPerl::RegistryPrefork;
> 
> use strict;
> use warnings FATAL => 'all';
> 
> our $VERSION = '0.01';
> 
> use base qw(ModPerl::Registry);
> 
> use File::Basename ();
> 
> sub handler : method {
>      my $class = (@_ >= 2) ? shift : __PACKAGE__;
>      my $r = shift;
>      return $class->new($r)->default_handler();
> }
> 
> sub chdir_file {
>      use File::Basename();
>      my $file = @_ == 2 ? $_[1] : $_[0]->{FILENAME};
>      my $dir = File::Basename::dirname($file);
>      chdir $dir or die "Can't chdir to $dir: $!";
> }
> 
> 1;

I copied this into a new file "RegistryPrefork.pm" in the same
directory as the ModPerl Registry.pm in the perl tree, and changed the

   PerlResponseHandler ModPerl::Registry

line in startup.pl to

   PerlResponseHandler ModPerl::RegistryPrefork

and restored the RegistryCooker.pm file to its original contents. I
also removed the Apache::RequestRec::chdir_file definition in my
startup.pl

This seems to work OK. Hopefully I should now be able to remove the
mod_perl 1's Registry.pm file.

Thanks everyone.

Colin


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
Randy Kobes wrote:
> On Tue, 29 Jul 2003, ColinB wrote:
> 
> 
>>Well I commented out the following line in
>>perl/lib/site_perl/5.8.0/sun4-solaris/Apache2/ModPerl/RegistryCooker.pm
>>like this:
>>
>>#*chdir_file = \&NOP;
>>
>>and added an identical definition to the above in my startup.pl file
>>like this:
>>
>>sub ModPerl::RegistryCooker::chdir_file {
>>    use File::Basename();
>>    my $file = @_ == 2 ? $_[1] : $_[0]->filename;
>>    my $dir = File::Basename::dirname($file);
>>    chdir $dir or die "Can't chdir to $dir: $!";
>>}
>>
>>and then in my httpd.conf I replaced
>>   PerlResponseHandler Apache::Registry
>>with
>>   PerlResponseHandler ModPerl::Registry
>>and then re-started the server.
>>
>>But the printenv script just displays the working directory as "/".
> 
> 
> Try the following, instead of ModPerl::RegistryCooker::chdir_file
> above:
> 
>  sub chdir_file_normal {
>      use File::Basename();
>      my $file = @_ == 2 ? $_[1] : $_[0]->{FILENAME};
>      my $dir = File::Basename::dirname($file);
>      chdir $dir or die "Can't chdir to $dir: $!";
>  }


Don't mess with the cooker, try using a subclass, e.g.:

# ModPerl/RegistryPrefork.pm

package ModPerl::RegistryPrefork;

use strict;
use warnings FATAL => 'all';

our $VERSION = '0.01';

use base qw(ModPerl::Registry);

use File::Basename ();

sub handler : method {
     my $class = (@_ >= 2) ? shift : __PACKAGE__;
     my $r = shift;
     return $class->new($r)->default_handler();
}

sub chdir_file {
     use File::Basename();
     my $file = @_ == 2 ? $_[1] : $_[0]->{FILENAME};
     my $dir = File::Basename::dirname($file);
     chdir $dir or die "Can't chdir to $dir: $!";
}

1;
__END__

now configure it as before but use the package name ModPerl::RegistryPrefork;

__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 29 Jul 2003, ColinB wrote:

> Well I commented out the following line in
> perl/lib/site_perl/5.8.0/sun4-solaris/Apache2/ModPerl/RegistryCooker.pm
> like this:
>
> #*chdir_file = \&NOP;
>
> and added an identical definition to the above in my startup.pl file
> like this:
>
> sub ModPerl::RegistryCooker::chdir_file {
>     use File::Basename();
>     my $file = @_ == 2 ? $_[1] : $_[0]->filename;
>     my $dir = File::Basename::dirname($file);
>     chdir $dir or die "Can't chdir to $dir: $!";
> }
>
> and then in my httpd.conf I replaced
>    PerlResponseHandler Apache::Registry
> with
>    PerlResponseHandler ModPerl::Registry
> and then re-started the server.
>
> But the printenv script just displays the working directory as "/".

Try the following, instead of ModPerl::RegistryCooker::chdir_file
above:

 sub chdir_file_normal {
     use File::Basename();
     my $file = @_ == 2 ? $_[1] : $_[0]->{FILENAME};
     my $dir = File::Basename::dirname($file);
     chdir $dir or die "Can't chdir to $dir: $!";
 }

-- 
best regards,
randy kobes


Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
> Can you please post a working solution, so I'll add it
> to docs.

I added this to my startup.pl just after the
use Apache::compat();


sub Apache::RequestRec::chdir_file {
    use File::Basename();
    my $file = @_ == 2 ? $_[1] : $_[0]->filename;
    my $dir = File::Basename::dirname($file);
    chdir $dir or die "Can't chdir to $dir: $!";
}


> 
> BTW, perhaps we should enable the chdir_file call in
> ModPerl::RegistryCooker, 
> so people won't need to install mod_perl 1 just to have
> Apache::Registry... 
> can you please try with ModPerl::RegistryCooker?

Well I commented out the following line in 
perl/lib/site_perl/5.8.0/sun4-solaris/Apache2/ModPerl/RegistryCooker.pm
like this:

#*chdir_file = \&NOP;

and added an identical definition to the above in my startup.pl file
like this:

sub ModPerl::RegistryCooker::chdir_file {
    use File::Basename();
    my $file = @_ == 2 ? $_[1] : $_[0]->filename;
    my $dir = File::Basename::dirname($file);
    chdir $dir or die "Can't chdir to $dir: $!";
}

and then in my httpd.conf I replaced

   PerlResponseHandler Apache::Registry

with

   PerlResponseHandler ModPerl::Registry

and then re-started the server.

But the printenv script just displays the working directory as "/".

Perhaps I've done this wrong? I did notice a couple of lines in the
RegistryCooker.pm file that were already commented out, like this:

  #XXX: $self->chdir_file("$Apache::Server::CWD/");

I don't know if that's significant?


Colin



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
ColinB wrote:
> Thanks Stas that worked a treat, except that your call to
> 
>   File::Basename::basename
> 
> should be
> 
>   File::Basename::dirname
> 
> The strange reversion to "/" seems to have been cured too.

you are right. Can you please post a working solution, so I'll add it to docs.

BTW, perhaps we should enable the chdir_file call in ModPerl::RegistryCooker, 
so people won't need to install mod_perl 1 just to have Apache::Registry... 
can you please try with ModPerl::RegistryCooker?

Thanks.

__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
Thanks Stas that worked a treat, except that your call to

  File::Basename::basename

should be

  File::Basename::dirname

The strange reversion to "/" seems to have been cured too.

Colin


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
ColinB wrote:
> --- Stas Bekman <st...@stason.org> wrote:
> 
>>... I won't commit it yet, but you can override it in your
> 
> startup.pl,
> 
>>until the dust settles down:
>>
>>require Apache::compat;
>>sub Apache::RequestRec::chdir_file {
>>     my $dir = @_ == 2 ? $_[1] : $_[0]->filename;
>>     chdir $dir;
>>}
> 
> 
> Thanks Stas. However, this seems to set the working directory to the
> server root, not the cgi-bin directory where the script resides. 

right, here is another try, again untested:

Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.86
diff -u -r1.86 compat.pm
--- lib/Apache/compat.pm        28 Jul 2003 10:33:58 -0000      1.86
+++ lib/Apache/compat.pm        29 Jul 2003 13:31:24 -0000
@@ -40,6 +40,8 @@
  use mod_perl ();
  use Symbol ();

+use File::Basename ();
+
  BEGIN {
      $INC{'Apache.pm'} = __FILE__;

@@ -335,6 +337,9 @@

  sub chdir_file {
      #XXX resolve '.' in @INC to basename $r->filename
+    my $file = @_ == 2 ? $_[1] : $_[0]->filename;
+    my $dir = File::Basename::basename($file);
+    chdir $dir or die "Can't chdir to $dir: $!";
  }

  sub finfo {


__________________________________________________________________
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


Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
--- Stas Bekman <st...@stason.org> wrote:
> ... I won't commit it yet, but you can override it in your
startup.pl,
> until the dust settles down:
> 
> require Apache::compat;
> sub Apache::RequestRec::chdir_file {
>      my $dir = @_ == 2 ? $_[1] : $_[0]->filename;
>      chdir $dir;
> }

Thanks Stas. However, this seems to set the working directory to the
server root, not the cgi-bin directory where the script resides. For
example, my printenv script now displays:

...
SCRIPT_FILENAME="/dir1/dir2/httpd/cgi-bin/printenv"
SCRIPT_NAME="/cgi-bin/printenv"
...
Working directory is /dir1/dir2/httpd
total 54

drwxrwxr-x  15 sxi_user other        512 Nov 28  2001 .
drwxrwxr-x   4 sxi_user sxi          512 Jul 29 10:58 ..
drwxrwxr-x   2 sxi_user sxi          512 Jul 18 15:57 bin
drwxrwxr-x   2 sxi_user sxi          512 Jul 18 15:57 build
drwxrwxr-x   9 sxi_user sxi         1024 Jul 29 11:38 cgi-bin
drwxrwxr-x   2 sxi_user sxi          512 Aug 16  2000 conf
...



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by ColinB <cb...@yahoo.com>.
... and even stranger, when I invoke the printenv cgi script for the
FIRST time it STILL displays "/" for the working directory, but if I
then click the IE browser's refresh (or CTRL-Refresh) button it changes
to the server root /dir1/dir2/httpd. Subsequent clicks of the refresh
button continue to show the server root.

Howvever, if I leave the browser inactive for about 30 secs or so and
then click refresh again, I get the working directory "/" again.
Sunsequent rereshes display the server root pathname again.

Very strange.

Colin


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: Working directory of script is "/" !

Posted by Stas Bekman <st...@stason.org>.
ColinB wrote:
> I'm steadily making progress with getting a collection of mod_perl 1
> compatibale scripts working with mod_perl 2 using the backward
> compatibility mode.
> 
> However, I find that the working directory of all scripts is "/". This
> occurs for both ModPerl::Registry and Apache::Registry. This causes
> many scripts to fail because they call open() using a relative
> pathname.
> 
> Surely the working directory of a script should be the directory in
> which it resides?
> 
> It does not seem to matter what directory I am in when I invoke httpd;
> the script's current directory is always "/".

That's correct. This is because $r->chdir_file in compat doesn't do anything.
The reason is that under threaded mpm, chdir() affects all threads. Of course 
we could check whether the mpm is prefork and do things the old way, but that 
means that the same code won't work the same under threaded and non-threaded 
mpms. Hence the limbo. Still waiting for Arthur to finish porting safecwd 
package, which should resolve this problem.

Meanwhile try this patch:

Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.86
diff -u -r1.86 compat.pm
--- lib/Apache/compat.pm        28 Jul 2003 10:33:58 -0000      1.86
+++ lib/Apache/compat.pm        29 Jul 2003 11:19:46 -0000
@@ -335,6 +335,8 @@

  sub chdir_file {
      #XXX resolve '.' in @INC to basename $r->filename
+    my $dir = @_ == 2 ? $_[1] : $_[0]->filename;
+    chdir $dir;
  }

  sub finfo {

I won't commit it yet, but you can override it in your startup.pl, until the 
dust settles down:

require Apache::compat;
sub Apache::RequestRec::chdir_file {
     my $dir = @_ == 2 ? $_[1] : $_[0]->filename;
     chdir $dir;
}


__________________________________________________________________
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