You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mark James <mr...@bigpond.net.au> on 2003/02/28 19:05:47 UTC

mp2 runs scripts as root?

Some of my scripts break when running under mp2 (cvs) because the UID
is set as root rather than the Apache user (which for me is "web").
The problem manifests with RCS file locking. Is there some switch
to set so that I can run scripts as "web"?


Re: mp2 runs scripts as root?

Posted by Mark James <mr...@bigpond.net.au>.
Stas Bekman wrote:

> ...
> Well, actually this is not the case. It behaves exactly the same as in 
> modperl 1.0. You can use Env::C module (available from CPAN) to easily 
> debug this:
> ...
> In any case you probably want to rely on getpwuid($<), rather than 
> $ENV{USER} if applicable.

Unfortunately ci (RCS) uses the USER variable to determine lock
permissions for edits.

But using your Env::C::setenv to set USER instead of assigning to
$ENV{'USER'} allowed me to remove the ENV assigments from start-up.pl.
This'll make my package more turn-key.

Thanks again -- Mark



Re: mp2 runs scripts as root?

Posted by Stas Bekman <st...@stason.org>.
Mark James wrote:
> Stas Bekman wrote:
> 
>> Mark James wrote:
>>
>>> Some of my scripts break when running under mp2 (cvs) because the UID
>>> is set as root rather than the Apache user (which for me is "web").
>>> The problem manifests with RCS file locking. Is there some switch
>>> to set so that I can run scripts as "web"?
>>
>>
>> Eh? Are you talking about 'make test' or installed mod_perl? If the 
>> former, use the latest cvs where this should work if the latter, 
>> modify httpd.conf.
> 
> 
> The latter.  Turned out to be a caused by the perl ENV not being
> propogated to forked programs:
> http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code 

Well, actually this is not the case. It behaves exactly the same as in modperl 
1.0. You can use Env::C module (available from CPAN) to easily debug this:

The following snippet prints the same under mp1 and mp2 (assuming that they 
are started under the same username)
print map { "Perl: $ENV{$_} C: " . Env::C::getenv($_) . "\n"}  qw(USER);
print "$< ", scalar getpwuid($<), "\n";

> Fixed by adding:
> 
> $ENV{'USER'} = 'web';
> $ENV{'LOGNAME'} = 'web';
> 
> to the start-up script.

Indeed. The point is that ENV is not passed from shell, you have to explicitly 
do that and this is an Apache thing. So you can do:

SetEnv USER web

or as you did, in perl.

In any case you probably want to rely on getpwuid($<), rather than $ENV{USER} 
if applicable.

__________________________________________________________________
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: mp2 runs scripts as root?

Posted by Mark James <mr...@bigpond.net.au>.
Stas Bekman wrote:
> Mark James wrote:
> 
>> Some of my scripts break when running under mp2 (cvs) because the UID
>> is set as root rather than the Apache user (which for me is "web").
>> The problem manifests with RCS file locking. Is there some switch
>> to set so that I can run scripts as "web"?
> 
> Eh? Are you talking about 'make test' or installed mod_perl? If the 
> former, use the latest cvs where this should work if the latter, modify 
> httpd.conf.

The latter.  Turned out to be a caused by the perl ENV not being
propogated to forked programs:
http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code

Fixed by adding:

$ENV{'USER'} = 'web';
$ENV{'LOGNAME'} = 'web';

to the start-up script.

Thanks for the reply -- Mark


Re: mp2 runs scripts as root?

Posted by Stas Bekman <st...@stason.org>.
Mark James wrote:
> Some of my scripts break when running under mp2 (cvs) because the UID
> is set as root rather than the Apache user (which for me is "web").
> The problem manifests with RCS file locking. Is there some switch
> to set so that I can run scripts as "web"?

Eh? Are you talking about 'make test' or installed mod_perl? If the former, 
use the latest cvs where this should work if the latter, modify httpd.conf.

__________________________________________________________________
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