You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Philippe M. Chiasson" <go...@ectoplasm.org> on 2005/09/22 01:35:33 UTC

[patch mp2] Fixes to $0 handling [Was: Directive changes the command name]

I've finally had time to dig deeper in the troubling $0 and process display
problems that seem to exist at least on *BSDs and HP-UX.

On linux, modifications to the original argv[0] will directy modify the process
information. On some other OSes, some special API is needed.

Perl's $0 magic handling correctly handles these OS differences and just does
the right thing.

So, simply passing Perl a _copy_ of argv[0] does disable $0 magic on Linux, but
not on the other OSes where it just calls the correct API (setproctitle() on BSDs)

On top of that, calling perl_parse() as is commonly done for embedders with
an argument of -e0, results in an initial $0 of '-e'. And that's what
is hapenning to pradeep.

But that's not all ;-) ap_server_argv0 _is_ _not_ httpd' argv[0], it's argv[0]
skipped forward to remove path components and leave only the binary's name
(httpd). The correct way to get at the real argv[0] is in server->proc->argv

All this combined has led to a more than troubling bug.

The correct solution (see patch) is:

 - Reset $0 to the _real_ argv[0] after calling perl_parse()
    /* Also need to fix PL_origalen */
    PL_origalen = strlen(argv[0])+1;
    /* argv[0] = '/usr/bin/httpd' */
    sv_setpv_mg(get_sv("0",0), argv[0]);

 - Use the real argv[0] (s->process->argv) and not a copy

-- 
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [patch mp2] Fixes to $0 handling [Was: Directive changes the command name]

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> 
>> I've finally had time to dig deeper in the troubling $0 and process
>> display
>> problems that seem to exist at least on *BSDs and HP-UX.
>>
>> [...]
>>
>> The correct solution (see patch) is:
>>
>>  - Reset $0 to the _real_ argv[0] after calling perl_parse()
>>     /* Also need to fix PL_origalen */
>>     PL_origalen = strlen(argv[0])+1;
>>     /* argv[0] = '/usr/bin/httpd' */
>>     sv_setpv_mg(get_sv("0",0), argv[0]);
>>
>>  - Use the real argv[0] (s->process->argv) and not a copy
> 
> Dear God!
> 
> +1
> 
> The test suite passes 100% with this applied and manual inspection of ps
> looks good.

Great, checked in as change r291193

> That on FreeBSD... hopefully I'll have some Open/Net BSD in the near
> future too.

-- 
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [patch mp2] Fixes to $0 handling [Was: Directive changes the command name]

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> 
>> I've finally had time to dig deeper in the troubling $0 and process
>> display
>> problems that seem to exist at least on *BSDs and HP-UX.
>>
>> [...]
>>
>> The correct solution (see patch) is:
>>
>>  - Reset $0 to the _real_ argv[0] after calling perl_parse()
>>     /* Also need to fix PL_origalen */
>>     PL_origalen = strlen(argv[0])+1;
>>     /* argv[0] = '/usr/bin/httpd' */
>>     sv_setpv_mg(get_sv("0",0), argv[0]);
>>
>>  - Use the real argv[0] (s->process->argv) and not a copy
> 
> Dear God!
> 
> +1
> 
> The test suite passes 100% with this applied and manual inspection of ps
> looks good.

Great, checked in as change r291193

> That on FreeBSD... hopefully I'll have some Open/Net BSD in the near
> future too.

-- 
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [patch mp2] Fixes to $0 handling [Was: Directive changes the command name]

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> I've finally had time to dig deeper in the troubling $0 and process display
> problems that seem to exist at least on *BSDs and HP-UX.
> 
> On linux, modifications to the original argv[0] will directy modify the process
> information. On some other OSes, some special API is needed.
> 
> Perl's $0 magic handling correctly handles these OS differences and just does
> the right thing.
> 
> So, simply passing Perl a _copy_ of argv[0] does disable $0 magic on Linux, but
> not on the other OSes where it just calls the correct API (setproctitle() on BSDs)
> 
> On top of that, calling perl_parse() as is commonly done for embedders with
> an argument of -e0, results in an initial $0 of '-e'. And that's what
> is hapenning to pradeep.
> 
> But that's not all ;-) ap_server_argv0 _is_ _not_ httpd' argv[0], it's argv[0]
> skipped forward to remove path components and leave only the binary's name
> (httpd). The correct way to get at the real argv[0] is in server->proc->argv
> 
> All this combined has led to a more than troubling bug.
> 
> The correct solution (see patch) is:
> 
>  - Reset $0 to the _real_ argv[0] after calling perl_parse()
>     /* Also need to fix PL_origalen */
>     PL_origalen = strlen(argv[0])+1;
>     /* argv[0] = '/usr/bin/httpd' */
>     sv_setpv_mg(get_sv("0",0), argv[0]);
> 
>  - Use the real argv[0] (s->process->argv) and not a copy

Dear God!

+1

The test suite passes 100% with this applied and manual inspection of ps looks 
good.

That on FreeBSD... hopefully I'll have some Open/Net BSD in the near future too.


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com