perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@ectoplasm.org>
Subject [patch mp2] Fixes to $0 handling [Was: <Perl> Directive changes the command name]
Date Wed, 21 Sep 2005 23:35:33 GMT
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

Mime
View raw message