Current working directory always "/"

Current working directory always "/"

am 21.05.2008 10:04:41 von Keenlearner

Hello,
It took me hours just to notice that my current working directory of
mod_perl2 always appear as "/"

Alias /modperl/ /var/www/modperl/

SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
Order allow,deny
Allow from all



But either I place my script at /var/www/modperl/test.pl OR
/var/www/modperl/directory/test.pl
use CGI qw(:standard);
print header;

use Cwd;
print getcwd();


These always print out "/". I have some modules living in my working
directory how can I have the directory working as like no using the
mod_perl2 before ? Thanks

Re: Current working directory always "/"

am 21.05.2008 10:29:12 von Fred Moyer

william wrote:
> Hello,
> It took me hours just to notice that my current working directory of
> mod_perl2 always appear as "/"

See slide 77 and on:

http://gozer.ectoplasm.org/Talks/mod_perl-2.0-from-cgi-fast. pdf

Specifically slide 81 looks like it addresses this issue.

Try adding:

require “/var/www/modperl/directory/test.pl";

to your cgi script.

Hope that helps.

>
> Alias /modperl/ /var/www/modperl/
>
> SetHandler perl-script
> PerlResponseHandler ModPerl::Registry
> PerlOptions +ParseHeaders
> Options +ExecCGI
> Order allow,deny
> Allow from all
>

>
>
> But either I place my script at /var/www/modperl/test.pl OR
> /var/www/modperl/directory/test.pl
> use CGI qw(:standard);
> print header;
>
> use Cwd;
> print getcwd();
>
>
> These always print out "/". I have some modules living in my working
> directory how can I have the directory working as like no using the
> mod_perl2 before ? Thanks


--
Red Hot Penguin Consulting LLC
mod_perl/PostgreSQL consulting and implementation
http://www.redhotpenguin.com/

Re: Current working directory always "/"

am 21.05.2008 11:22:34 von Keenlearner

On Wed, May 21, 2008 at 4:29 PM, Fred Moyer wrote:
> william wrote:
>>
>> Hello,
>> It took me hours just to notice that my current working directory of
>> mod_perl2 always appear as "/"
>
> See slide 77 and on:
>
> http://gozer.ectoplasm.org/Talks/mod_perl-2.0-from-cgi-fast. pdf
>
> Specifically slide 81 looks like it addresses this issue.
>
> Try adding:
>
> require "/var/www/modperl/directory/test.pl";
>
> to your cgi script.
>
> Hope that helps.
>
>>
>> Alias /modperl/ /var/www/modperl/
>>
>> SetHandler perl-script
>> PerlResponseHandler ModPerl::Registry
>> PerlOptions +ParseHeaders
>> Options +ExecCGI
>> Order allow,deny
>> Allow from all
>>

>>
>>
>> But either I place my script at /var/www/modperl/test.pl OR
>> /var/www/modperl/directory/test.pl
>> use CGI qw(:standard);
>> print header;
>>
>> use Cwd;
>> print getcwd();
>>
>>
>> These always print out "/". I have some modules living in my working
>> directory how can I have the directory working as like no using the
>> mod_perl2 before ? Thanks
>
>
> --
> Red Hot Penguin Consulting LLC
> mod_perl/PostgreSQL consulting and implementation
> http://www.redhotpenguin.com/
>

Thanks, I also found the same and better solution using ModPerl::RegistryPrefork
http://perl.apache.org/docs/2.0/api/ModPerl/RegistryPrefork. html

I don't know why they don't just recommend using
ModPerl::RegistryPrefork instead of ModPerl::Registry , that could
save a lot of other people's trouble. But there must be a reason that
I don't know.
Thanks.

Re: Current working directory always "/"

am 21.05.2008 11:26:27 von torsten.foertsch

On Wed 21 May 2008, william wrote:
> I don't know why they don't just recommend using
> ModPerl::RegistryPrefork instead of ModPerl::Registry , that could
> save a lot of other people's trouble. But there must be a reason that
> I don't know.

because it won't work with a threaded MPM.

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: Current working directory always "/"

am 21.05.2008 13:52:40 von Keenlearner

On Wed, May 21, 2008 at 5:26 PM, Torsten Foertsch
wrote:
> On Wed 21 May 2008, william wrote:
>> I don't know why they don't just recommend using
>> ModPerl::RegistryPrefork instead of ModPerl::Registry , that could
>> save a lot of other people's trouble. But there must be a reason that
>> I don't know.
>
> because it won't work with a threaded MPM.
>
> Torsten
>
> --
> Need professional mod_perl support?
> Just hire me: torsten.foertsch@gmx.net
>

Sigh...Even ModPerl::RegistryPrefork does not work as what I want, why
do they say "Run unaltered CGI scripts under mod_perl" when it is
working differently with CGI ?

/var/www/modperl/Dir/Test.pm
package Dir::Test;

use Cwd;
use Storable;

sub mygetcwd()
{
open(FILE, 'textfile') || die "$!"; #No such file or directory at
/var/www/modperl//Dir/Test.pm line 8.\n
print ;
print cwd; #The result is "/var/www/modperl"
}

1;

/var/www/modperl/Dir/textfile
Hello world

/var/www/modperl/test.pl
use CGI qw(:standard);
print header;

use Dir::Test;
Dir::Test::mygetcwd();


Because the working directory is always the directory of the start of
execution file /var/www/modperl .So why can't I use the relative
directory , it only works if I use open(FILE, 'Dir/textfile');

Thanks.

Re: Current working directory always "/"

am 21.05.2008 14:22:51 von Perrin Harkins

On Wed, May 21, 2008 at 7:52 AM, william wrote:
> Sigh...Even ModPerl::RegistryPrefork does not work as what I want, why
> do they say "Run unaltered CGI scripts under mod_perl" when it is
> working differently with CGI ?
>
> /var/www/modperl/Dir/Test.pm
> package Dir::Test;

Under normal CGI, the cwd will be the directory that the script was
found in, not the directory of the currently executing module. This
is the same behavior.

- Perrin

Re: Current working directory always "/"

am 21.05.2008 16:28:00 von Philip Gollucci

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

william wrote:
| /var/www/modperl/Dir/Test.pm
| package Dir::Test;
|
| use Cwd;
| use Storable;
|
| sub mygetcwd()
| {
| open(FILE, 'textfile') || die "$!"; #No such file or directory at
| /var/www/modperl//Dir/Test.pm line 8.\n
| print ;
| print cwd; #The result is "/var/www/modperl"
| }
|
| 1;
You should almost always use full paths to files, think of threads.


- --
- ------------------------------------------------------------ ------------
Philip M. Gollucci (philip@ridecharge.com)
o:703.549.2050x206
Senior System Admin - Riderway, Inc.
http://riderway.com / http://ridecharge.com
1024D/DB9B8C1C B90B FBC3 A3A1 C71A 8E70 3F8C 75B8 8FFB DB9B 8C1C

Work like you don't need the money,
love like you'll never get hurt,
and dance like nobody's watching.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.8 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFINDFwdbiP+9ubjBwRArraAJ4gIWKyxD17Yiqjn71FRF4jOGicPACd Fd6F
kZWFcNaE/JkhSjcldojVrQY=
=XfnH
-----END PGP SIGNATURE-----

Re: Current working directory always "/"

am 21.05.2008 17:16:10 von Perrin Harkins

On Wed, May 21, 2008 at 10:28 AM, Philip M. Gollucci
wrote:
> You should almost always use full paths to files, think of threads.

This is true in a module you plan to distribute on CPAN, but for local
use you typically don't need to think of threads because most people
will not use them. There are arguments you could make that full paths
increase security though.

- Perrin

Re: Current working directory always "/"

am 22.05.2008 11:50:42 von Keenlearner

On 5/21/08, Perrin Harkins wrote:
> On Wed, May 21, 2008 at 10:28 AM, Philip M. Gollucci
> wrote:
> > You should almost always use full paths to files, think of threads.
>
>
> This is true in a module you plan to distribute on CPAN, but for local
> use you typically don't need to think of threads because most people
> will not use them. There are arguments you could make that full paths
> increase security though.
>
>
> - Perrin
>


Btw, could you tell me how does full paths increase security ? Thanks

Re: Current working directory always "/"

am 22.05.2008 21:39:49 von Perrin Harkins

On Thu, May 22, 2008 at 5:50 AM, william wrote:
> Btw, could you tell me how does full paths increase security ?

It prevents some attacks based on tricking your application into
working on different files. If you don't assume a certain working
directory, you won't be compromised if someone finds a way to change
it.

Using absolute paths is pretty common advice, e.g.:
http://advosys.ca/papers/web-security.html#absolute

- Perrin

Re: Current working directory always "/"

am 23.05.2008 05:37:23 von Foo JH

Hello Perrin,

I would think that threads are more important to Win32 Perlies than
their Linux counterparts. To me, I use threads as often as I can to
maximise performance and scalability. To conclude, I can't agree with
your statement that people don't use threads.


william wrote:
> On 5/21/08, Perrin Harkins wrote:
>
>> On Wed, May 21, 2008 at 10:28 AM, Philip M. Gollucci
>> wrote:
>> > You should almost always use full paths to files, think of threads.
>>
>>
>> This is true in a module you plan to distribute on CPAN, but for local
>> use you typically don't need to think of threads because most people
>> will not use them. There are arguments you could make that full paths
>> increase security though.
>>
>>
>> - Perrin
>>
>>
>
>
> Btw, could you tell me how does full paths increase security ? Thanks
>

Re: Current working directory always "/"

am 23.05.2008 13:34:46 von Perrin Harkins

On Thu, May 22, 2008 at 11:37 PM, Foo JH wrote:
> To conclude, I can't agree with your statement
> that people don't use threads.

I disagree with that statement too. What I actually said was that
most people don't use threads (since they are on Linux) and that
people who don't use threads don't need to worry about them when
writing internal code they don't plan to distribute. Of course Win32
users will run threads and will need to write all of their code with
threads in mind.

- Perrin