Re: Working directory of script is / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
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 / !
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 / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
--- Stas Bekman [EMAIL PROTECTED] 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 / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
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.pm28 Jul 2003 10:33:58 - 1.86 +++ lib/Apache/compat.pm29 Jul 2003 11:19:46 - @@ -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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
--- Stas Bekman [EMAIL PROTECTED] 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 other512 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 / !
... 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 / !
ColinB wrote: --- Stas Bekman [EMAIL PROTECTED] 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.pm28 Jul 2003 10:33:58 - 1.86 +++ lib/Apache/compat.pm29 Jul 2003 13:31:24 - @@ -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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
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 / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
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 / !
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 / !
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 / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Working directory of script is / !
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 BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com