You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pradeep kumar <pr...@gmail.com> on 2005/08/29 13:28:15 UTC

Directive changes the command nam

Hi All,

Has anyone come across the command name changing when the Perl
directive is introduced in the configuration file.

When,

<Perl>
</Perl>

 is used then ps -ef gives the proper command name namely httpd. 

When
<Perl>

</Perl>

is used(This time with a blank line) then ps -ef does not give httpd
as the command name, instead gievs -e as the command name. This occurs
even when a directive is used inside the section but the directive is
parsed though.  Is there any buffer overflow that may be happening.

Regards,
Pradeep

Re: [mp2] Directive changes the command nam

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> Philip M. Gollucci wrote:
> 
>>pradeep kumar wrote:
>>        save_scalar(gv); /* local $0 */
Mainly for my sanity and the archives:

  $PROGRAM_NAME
        $0      Contains the name of the program being executed.

                On some (read: not all) operating systems assigning to $0 modi-
                fies the argument area that the "ps" program sees.  On some
                platforms you may have to use special "ps" options or a differ-
                ent "ps" to see the changes.  Modifying the $0 is more useful
                as a way of indicating the current program state than it is for
                hiding the program you're running.  (Mnemonic: same as sh and
                ksh.)

                Note that there are platform specific limitations on the the
                maximum length of $0.  In the most extreme case it may be lim-
                ited to the space occupied by the original $0.

                In some platforms there may be arbitrary amount of padding, for
                example space characters, after the modified name as shown by
                "ps".  In some platforms this padding may extend all the way to
                the original length of the argument area, no matter what you do
                (this is the case for example with Linux 2.2).

                Note for BSD users: setting $0 does not completely remove
                "perl" from the ps(1) output.  For example, setting $0 to "foo-
                bar" may result in "perl: foobar (perl)" (whether both the
                "perl: " prefix and the " (perl)" suffix are shown depends on
                your exact BSD variant and version).  This is an operating sys-
                tem feature, Perl cannot help it.

                In multithreaded scripts Perl coordinates the threads so that
                any thread may modify its copy of the $0 and the change becomes
                visible to ps(1) (assuming the operating system plays along).
                Note that the the view of $0 the other threads have will not
                change since they have their own copies of it.

-- 
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

Re: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
I want to know how i can get the position of the "-k start" as it can be at
any location. So assuming some position of it and hard coding it does not
help. Also I tried using 5.8.0 perl without the fix. It somehow did not
reproduce the problem. How is this happening. Since apache was not giving
the "-k start" to mod_perl how did 5.8.0 give the whole command line.

On 11/15/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
>
> pradeep kumar wrote:
> > #diff src/modules/perl/modperl_config.c
> > src/modules/perl/modperl_config.c.org
> > 175c175
> > < modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p, server_rec
> *s)
> > ---
> >> modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p)
>
> In the future, diff -u is much more preferred (being more human readable)
>
> > > [...]
> > This however is not giving me the "-k start". How can I get that.
>
> You would have to add it yourself, as -k arguments are used by apache to
> start
> (or restart/shutdown) a running apache, so it will start an actual httpd
> process
> _without_ that command line argument.
>
>
> --------------------------------------------------------------------------------
> 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: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pradeep kumar wrote:
> #diff src/modules/perl/modperl_config.c
> src/modules/perl/modperl_config.c.org
> 175c175
> < modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p, server_rec *s)
> ---
>> modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p)

In the future, diff -u is much more preferred (being more human readable)

> > [...]
> This however is not giving me the "-k start". How can I get that.

You would have to add it yourself, as -k arguments are used by apache to start
(or restart/shutdown) a running apache, so it will start an actual httpd process
_without_ that command line argument.

--------------------------------------------------------------------------------
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
#diff src/modules/perl/modperl_config.c
src/modules/perl/modperl_config.c.org
175c175
< modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p, server_rec *s)
---
> modperl_config_srv_t *modperl_config_srv_new(apr_pool_t *p)
177,178d176
< int i=0,len=0;
< char *str1=NULL;
202,203c200,211
< /* make sure httpd's argv[0] is the first argument so $0 is
< * correctly connected to the real thing */
---
> /* must copy ap_server_argv0, because otherwise any read/write of
> * $0 corrupts process' argv[0] (visible with 'ps -ef' on most
> * unices). This is due to the logic of calculating PL_origalen in
> * perl_parse, which is later used in set_mg.c:Perl_magic_set() to
> * truncate the argv[0] setting. remember that argv[0] passed to
> * perl_parse() != process's real argv[0].
> *
> * as a copying side-effect, changing $0 now doesn't affect the
> * way the process is seen from the outside.
> */
> modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
> strlen(ap_server_argv0)));
205,217d212
< for(i=0;i<s->process->argc;i++)
< {
< len+=strlen(s->process->argv[i]);
< len++;
< }
< str1=(char *)malloc(len);
< for(i=0;i<s->process->argc;i++)
< {
< strcat(str1,s->process->argv[i]);
< strcat(str1," ");
< }
< modperl_config_srv_argv_push(str1);
266c261
< modperl_config_srv_t *scfg = modperl_config_srv_new(p, s);
---
> modperl_config_srv_t *scfg = modperl_config_srv_new(p);
317c312
< *mrg = modperl_config_srv_new(p, add->server);
---
> *mrg = modperl_config_srv_new(p);

Somehow the "-k start" which is given at the command line is not getting
reflected in argv. This goes missing from argv. So when I start apache as
#/app/apache/bin/httpd -d /app/apache -k start
#ps -eaf | grep www
www 20734 20724 0 12:59:55 ? 0:00 /app/apache/bin/httpd -d /app/apache
www 20733 20724 0 12:59:55 ? 0:00 /app/apache/bin/httpd -d /app/apache
root 20724 1 0 12:59:53 ? 0:01 /app/apache/bin/httpd -d /app/apache
www 20729 20724 0 12:59:54 ? 0:00 /app/apache/bin/httpd -d /app/apache
#/app/apache/bin/httpd -d /app/apache -k startssl
#ps -eaf | grep www
www 20734 20724 0 12:59:55 ? 0:00 /app/apache/bin/httpd -d /app/apache -D
SSL
www 20733 20724 0 12:59:55 ? 0:00 /app/apache/bin/httpd -d /app/apache -D
SSL
root 20724 1 0 12:59:53 ? 0:01 /app/apache/bin/httpd -d /app/apache -D SSL
www 20729 20724 0 12:59:54 ? 0:00 /app/apache/bin/httpd -d /app/apache -D
SSL

This however is not giving me the "-k start". How can I get that.

On 11/10/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
>
> pradeep kumar wrote:
> > I tried to read the whole of argv and push it in
> > modperl_config_srv_argv_push(). But what I can get only upto
> > "/app/apache/bin/httpd -d /app/apache" and not the whole of
> > "/app/apache/bin/httpd -d /app/apache -k start". I tried to print
> > argv[3] which just gave me null. How can I get the rest of the
> arguments.
>
> Not sure I follow exactly what you are saying, but please, post whatever
> code you have, it's usually much better than trying to explain code (a
> diff
> would be great)
>
> But once again, like I said, we are being bitten by too much magic here,
> and
> especially on HP-UX, it might not even be possible to reset the process
> full
> command name + command arguments at all.
>
> --------------------------------------------------------------------------------
> 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: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pradeep kumar wrote:
> I tried to read the whole of  argv and push it in
> modperl_config_srv_argv_push(). But what I can get only upto
> "/app/apache/bin/httpd -d /app/apache" and not the whole of
> "/app/apache/bin/httpd  -d /app/apache -k start". I tried to print
> argv[3] which just gave me null. How can I get the rest of the arguments.

Not sure I follow exactly what you are saying, but please, post whatever
code you have, it's usually much better than trying to explain code (a diff
would be great)

But once again, like I said, we are being bitten by too much magic here, and
especially on HP-UX, it might not even be possible to reset the process full
command name + command arguments at all.
--------------------------------------------------------------------------------
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
I tried to read the whole of argv and push it in
modperl_config_srv_argv_push(). But what I can get only upto
"/app/apache/bin/httpd -d /app/apache" and not the whole of
"/app/apache/bin/httpd -d /app/apache -k start". I tried to print argv[3]
which just gave me null. How can I get the rest of the arguments.

On 10/12/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
>
> pradeep kumar wrote:
> > Hi,
> >
> > I got the fix from http://svn.apache.org/viewcvs.cgi?view=rev&rev=291193
> > <http://svn.apache.org/viewcvs.cgi?view=rev&rev=291193>. This solves the
> > problem partially. I used that fix. But this gives only the command name
> > instead of the whole of the command line.
>
> Yes, that an unfortunate side effect of how perl_parse functions.
>
> The typical embedder's method of calling perl_parse() like this:
> perl_parse(my_perl, NULL, 3, {"", "-e","0" }, NULL);
>
> Causes a side effect of setting $0 to '-e', which in turn, on HPUX
> will call pstat(PSTAT_SETCMD, [...]); Causing the original problem.
>
> The _only_ solution I can currently think of is what I implemented.
> Reset $0 to argv[0]. And that's why you see only the name of the binary.
>
> I am not sure if this could be somehow fixed by resetting $0 not only
> to argv[0], but to a concatenation of argv[0..argc].
>
> I am starting to think perl_parse() should be somewhat less magical...
>
> > #ps -eaf | grep httpd
> >
> > I normally get something like:
> > root 3634 1 0 20:31 ? 00:00:00 /app/apache/bin/httpd -k start
> > [...]
> >
> > But the fix gives only
> >
> > #ps -eaf | grep httpd
> >
> > root 3634 1 0 20:31 ? 00:00:00 /app/apache/bin/httpd
> > [...]
> >
> > without the arguments passed.
>
>
> --
> 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: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pradeep kumar wrote:
> Hi,
> 
> I got the fix from http://svn.apache.org/viewcvs.cgi?view=rev&rev=291193
> <http://svn.apache.org/viewcvs.cgi?view=rev&rev=291193>. This solves the
> problem partially. I used that fix. But this gives only the command name
> instead of the whole of the command line.

Yes, that an unfortunate side effect of how perl_parse functions.

The typical embedder's method of calling perl_parse() like this:
perl_parse(my_perl, NULL, 3, {"", "-e","0" }, NULL);

Causes a side effect of setting $0 to '-e', which in turn, on HPUX
will call pstat(PSTAT_SETCMD, [...]); Causing the original problem.

The _only_ solution I can currently think of is what I implemented.
Reset $0 to argv[0]. And that's why you see only the name of the binary.

I am not sure if this could be somehow fixed by resetting $0 not only
to argv[0], but to a concatenation of argv[0..argc].

I am starting to think perl_parse() should be somewhat less magical...

> #ps -eaf | grep httpd
> 
> I normally get something like:
> root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> [...]
>
> But the fix gives only
> 
> #ps -eaf | grep httpd
> 
> root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd
> [...]
> 
> without the arguments passed.


-- 
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
Hi,

I got the fix from http://svn.apache.org/viewcvs.cgi?view=rev&rev=291193.
This solves the problem partially. I used that fix. But this gives only the
command name instead of the whole of the command line.

#ps -eaf | grep httpd

I normally get something like:
root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3635  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3636  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3637  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3638  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3639  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start


But the fix gives only

#ps -eaf | grep httpd

root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd
nobody 3635  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd
nobody 3636  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd
nobody 3637  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd
nobody 3638  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd
nobody 3639  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd


without the arguments passed.
On 9/14/05, pradeep kumar <pr...@gmail.com> wrote:
>
> I am using HP-UX. There is no setproctitle on it as far as I know. Is
> there any other way of doing this on HP-UX.. Also I found a similar query
> which was reported some time back which was changing the command name dated
> Wed, 11 Feb 2004. This has been rectified though. But in my case the entire
> command name is being changed instead of just httpd.
>  Earlier reported case:
> #ps -eaf | grep httpd
>
> I normally get something like:
> root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> nobody 3635  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> nobody 3636  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> nobody 3637  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> nobody 3638  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
> nobody 3639  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
>
>
> putting a single line between <Perl > and </Perl> (even if the line is
> empty)
> root 3738 1 2 20:34 ? 00:00:00 /app/apache/bin/-e -k start
> nobody 3739 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
> nobody 3740 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
> nobody 3741 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
> nobody 3742 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
> nobody 3743 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
>  In my case the output is something like this.
>  root 3738 1 2 20:34 ? 00:00:00 -e
> nobody 3739 3738 0 20:34 ? 00:00:00 -e
> nobody 3740 3738 0 20:34 ? 00:00:00 -e
> nobody 3741 3738 0 20:34 ? 00:00:00 -e
> nobody 3742 3738 0 20:34 ? 00:00:00 -e
> nobody 3743 3738 0 20:34 ? 00:00:00 -e
>  The fix for the first reported problem was given in the modperl_config.c
>
> modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
> strlen(ap_server_argv0)));
>
> Any idea why this is not working now.
>
>  On 9/14/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
> >
> > Philip M. Gollucci wrote:
> > > Philippe M. Chiasson wrote:
> > >
> > >> Still unable to reproduce this on my end.
> > >
> > > This help any ?
> >
> > Nope, but I've nailed the source of the problem.
> >
> > Turns out that on some BSDs (like FreeBSD) changes to argv[0]
> > do not affect the output of ps and such. Each process instead
> > has a slot somewhere for what's being displayed in ps output,
> > and there is an API to alter it (setproctitle()).
> >
> > So, Perl's $0 magic handling (in mg.c) does detect this correctly
> > and calls setproctitle() when necessary.
> >
> > We need to do the same, otherwise saving/copying ap_server_argv0
> > doesn't help.
> >
> > I've got a simple patch that fixed the problem I'd like you to test.
> >
> > That's probably not quite the right place to stick setproctitle(),
> > so this patch needs cleaning up some, but should at least work for
> > now.
> >
> > Index: src/modules/perl/modperl_config.c
> > ===================================================================
> > --- src/modules/perl/modperl_config.c (revision 280622)
> > +++ src/modules/perl/modperl_config.c (working copy)
> > @@ -183,6 +183,15 @@
> > * as a copying side-effect, changing $0 now doesn't affect the
> > * way the process is seen from the outside.
> > */
> > +
> > +#ifdef HAS_SETPROCTITLE
> > +# if __FreeBSD_version > 410001
> > + setproctitle("-%s", ap_server_argv0);
> > +# else
> > + setproctitle("%s", ap_server_argv0);
> > +# endif
> > +#endif
> > +
> > modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
> > strlen(ap_server_argv0)));
> >
> > --------------------------------------------------------------------------------
> >
> > 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

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

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
I am using HP-UX. There is no setproctitle on it as far as I know. Is there 
any other way of doing this on HP-UX.. Also I found a similar query which 
was reported some time back which was changing the command name dated Wed, 
11 Feb 2004. This has been rectified though. But in my case the entire 
command name is being changed instead of just httpd.
 Earlier reported case:
#ps -eaf | grep httpd

I normally get something like:
root   3634     1  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3635  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3636  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3637  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3638  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start
nobody 3639  3634  0 20:31 ?     00:00:00 /app/apache/bin/httpd -k start


putting a single line between <Perl > and </Perl> (even if the line is 
empty)
root 3738 1 2 20:34 ? 00:00:00 /app/apache/bin/-e -k start
nobody 3739 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
nobody 3740 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
nobody 3741 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
nobody 3742 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
nobody 3743 3738 0 20:34 ? 00:00:00 /app/apache/bin/-e -k start
 In my case the output is something like this.
 root 3738 1 2 20:34 ? 00:00:00 -e
nobody 3739 3738 0 20:34 ? 00:00:00 -e
nobody 3740 3738 0 20:34 ? 00:00:00 -e
nobody 3741 3738 0 20:34 ? 00:00:00 -e
nobody 3742 3738 0 20:34 ? 00:00:00 -e
nobody 3743 3738 0 20:34 ? 00:00:00 -e
 The fix for the first reported problem was given in the modperl_config.c

modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
strlen(ap_server_argv0)));

Any idea why this is not working now.

 On 9/14/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote: 
> 
> Philip M. Gollucci wrote:
> > Philippe M. Chiasson wrote:
> >
> >> Still unable to reproduce this on my end.
> >
> > This help any ?
> 
> Nope, but I've nailed the source of the problem.
> 
> Turns out that on some BSDs (like FreeBSD) changes to argv[0]
> do not affect the output of ps and such. Each process instead
> has a slot somewhere for what's being displayed in ps output,
> and there is an API to alter it (setproctitle()).
> 
> So, Perl's $0 magic handling (in mg.c) does detect this correctly
> and calls setproctitle() when necessary.
> 
> We need to do the same, otherwise saving/copying ap_server_argv0
> doesn't help.
> 
> I've got a simple patch that fixed the problem I'd like you to test.
> 
> That's probably not quite the right place to stick setproctitle(),
> so this patch needs cleaning up some, but should at least work for
> now.
> 
> Index: src/modules/perl/modperl_config.c
> ===================================================================
> --- src/modules/perl/modperl_config.c (revision 280622)
> +++ src/modules/perl/modperl_config.c (working copy)
> @@ -183,6 +183,15 @@
> * as a copying side-effect, changing $0 now doesn't affect the
> * way the process is seen from the outside.
> */
> +
> +#ifdef HAS_SETPROCTITLE
> +# if __FreeBSD_version > 410001
> + setproctitle("-%s", ap_server_argv0);
> +# else
> + setproctitle("%s", ap_server_argv0);
> +# endif
> +#endif
> +
> modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
> strlen(ap_server_argv0)));
> 
> 
> --------------------------------------------------------------------------------
> 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: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> Philippe M. Chiasson wrote:
> 
>> Still unable to reproduce this on my end.
> 
> This help any ?

Nope, but I've nailed the source of the problem.

Turns out that on some BSDs (like FreeBSD) changes to argv[0]
do not affect the output of ps and such. Each process instead
has a slot somewhere for what's being displayed in ps output,
and there is an API to alter it (setproctitle()).

So, Perl's $0 magic handling (in mg.c) does detect this correctly
and calls setproctitle() when necessary.

We need to do the same, otherwise saving/copying ap_server_argv0
doesn't help.

I've got a simple patch that fixed the problem I'd like you to test.

That's probably not quite the right place to stick setproctitle(),
so this patch needs cleaning up some, but should at least work for
now.

Index: src/modules/perl/modperl_config.c
===================================================================
--- src/modules/perl/modperl_config.c   (revision 280622)
+++ src/modules/perl/modperl_config.c   (working copy)
@@ -183,6 +183,15 @@
      * as a copying side-effect, changing $0 now doesn't affect the
      * way the process is seen from the outside.
      */
+
+#ifdef HAS_SETPROCTITLE
+#   if __FreeBSD_version > 410001
+            setproctitle("-%s", ap_server_argv0);
+#   else
+            setproctitle("%s", ap_server_argv0);
+#   endif
+#endif
+
     modperl_config_srv_argv_push(apr_pstrmemdup(p, ap_server_argv0,
                                                 strlen(ap_server_argv0)));

--------------------------------------------------------------------------------
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
I tried to print out the scfg in the modperl_config.c file. This prints 0 : 
httpd and 1 : -e;0. This is the only place where I see a "-e" being written. 


char **modperl_config_srv_argv_init(modperl_config_srv_t *scfg, int *argc)
{
modperl_config_srv_argv_push("-e;0");

*argc = scfg->argv->nelts;

MP_TRACE_g_do(dump_argv(scfg));

return (char **)scfg->argv->elts;
}

 Does scfg have more than these 2 params? Is this what could be corrupting 
the ps output?
 Thanks and Regards,
Pradeep

 On 9/13/05, pradeep kumar <pr...@gmail.com> wrote: 
> 
> 
> By commenting out the 2 lines 
> save_scalar(gv); /* local $0 */
> sv_setpv_mg(GvSV(gv), directive->filename);
>  in modperl_cmd.c I have been able to see the proper arguments in the ps 
> output instead of the -e which was seen before. I wasn't sure of exactly 
> what these 2 lines are doing. I however see that the perl directives that 
> have been added inside the Perl block are being parsed. 
>  Diff
> 
> {
> SV *code = newSVpv(arg, 0);
> GV *gv = gv_fetchpv("0", TRUE, SVt_PV);
> ENTER;SAVETMPS;
> - save_scalar(gv); /* local $0 */
> - sv_setpv_mg(GvSV(gv), directive->filename); 
> eval_sv(code, G_SCALAR|G_KEEPERR);
> SvREFCNT_dec(code);
> modperl_env_sync_srv_env_hash2table(aTHX_ p, scfg);
> modperl_env_sync_dir_env_hash2table(aTHX_ p, dcfg);
> FREETMPS;LEAVE; 
> }
> Thanks and Regards,
> Pradeep
>  On 10/13/05, Philip M. Gollucci <pg...@p6m7g8.com> wrote: 
> > 
> > Philippe M. Chiasson wrote:
> > > Still unable to reproduce this on my end.
> > This help any ?
> > 
> > gdb httpd (wd: ~/dev/apps/httpd- 2.3.0/prefork/bin)
> > b modperl_cmd.c:559
> > [snip]
> > 
> > bt full
> > #0 modperl_cmd_perldo (parms=0xbfbfe9e0, mconfig=0x81056d0,
> > arg=0x8133798 "package
> > Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78;\n#line 
> > 
> > 78 /usr/home/pgollucci/dev/apps/httpd-2.3.0/prefork/conf/mod_perl.conf\n\n") 
> > at
> > modperl_cmd.c:560
> > code = (SV *) 0x8138c2c
> > gv = (GV *) 0x8138908
> > p = (apr_pool_t *) 0x80bc018
> > s = (server_rec *) 0x80c1988
> > dcfg = (modperl_config_dir_t *) 0x81056d0
> > options = (apr_table_t *) 0x8125018
> > handler = (modperl_handler_t *) 0x81335d8
> > pkg_name = 0x8133660 
> > 
> > "Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78"
> > directive = (ap_directive_t *) 0x8125158
> > scfg = (modperl_config_srv_t *) 0x8105100 
> > #1 0x08077ce3 in invoke_cmd (cmd=0x283a1420, parms=0xbfbfe9e0,
> > mconfig=0x81056d0, args=0x8125150 "\n") at config.c:735
> > w = 0x8078ce8 "\203Ä \211Eð\213Eø\213@\b\211Eü\213Eü\213@\f%"
> > w2 = 0xbfbfe988 "¸é¿¿¬\215\a\bXQ\022\bàé¿¿Hç\016\b4-da11-9dca-0002e33b"
> > w3 = 0x81056d0 ""
> > errmsg = 0x0
> > #2 0x08078d1c in ap_walk_config_sub (current=0x8125158, 
> > parms=0xbfbfe9e0, 
> > section_vector=0x80ee748) at config.c:1141
> > dir_config = (void *) 0x81056d0
> > retval = 0x0
> > cmd = (const command_rec *) 0x283a1420
> > ml = (ap_mod_list *) 0x8103458
> > dir = 0x8133418 "perl" 
> > #3 0x08078dac in ap_walk_config (current=0x8125158, parms=0xbfbfe9e0,
> > section_vector=0x80ee748) at config.c:1174
> > errmsg = 0x0
> > oldconfig = (ap_conf_vector_t *) 0x0
> > #4 0x08079c05 in ap_process_config_tree (s=0x80c1988, 
> > conftree=0x80efcb8, 
> > p=0x80bc018, ptemp=0x80ec018) at config.c:1743
> > errmsg = 0x0
> > parms = {info = 0x0, override = 150, limited = -1, limited_xmethods =
> > 0x0, xlimited = 0x0, config_file = 0x0, directive = 0x8125158, pool = 
> > 0x80bc018, 
> > temp_pool = 0x80ec018, server = 0x80c1988,
> > path = 0x0, cmd = 0x283a1420, context = 0x80ee748, err_directive = 0x0,
> > override_opts = 239}
> > #5 0x08061dc7 in main (argc=4, argv=0xbfbfeb04) at main.c:616
> > c = 100 'd' 
> > configtestonly = 0
> > confname = 0x80954cd "conf/httpd.conf"
> > def_server_root = 0xbfbfec59 ".."
> > temp_error_log = 0x0
> > error = 0x0
> > process = (process_rec *) 0x80ba098 
> > server_conf = (server_rec *) 0x80c1988
> > pglobal = (apr_pool_t *) 0x80ba018
> > pconf = (apr_pool_t *) 0x80bc018
> > plog = (apr_pool_t *) 0x80ea018
> > ptemp = (apr_pool_t *) 0x80ec018 
> > pcommands = (apr_pool_t *) 0x80be018
> > opt = (apr_getopt_t *) 0x80be0b0
> > rv = 70014
> > mod = (module **) 0x280a6261
> > optarg = 0xbfbfec59 ".."
> > signal_server = (apr_OFN_ap_signal_server_t *) 0x2824fe40 
> > <__isthreaded+28> 
> > (gdb) x directive->filename
> > 0x8121200: 0x7273752f
> > (gdb) p directive->filename
> > $3 = 0x8121200 "/usr/home/pgollucci/dev/apps/httpd-2.3.0
> > /prefork/conf/mod_perl.conf"
> > (gdb)
> > 
> > FYI, mod_perl.conf contains my 
> > <Perl>
> > 
> > </Perl>
> > 
> > section
> > 
> > at this point,
> > ps -aux | grep httpd
> > 111:pgollucci 53023 0.0 15.8 81684 81056 p6 T 1:42AM 0:01.54 gdb httpd
> > 112:pgollucci 53044 0.0 2.0 11148 10300 p6 TX 1:42AM 0: 00.39 (httpd)
> > 114:pgollucci 53259 0.0 0.0 348 208 p6 R+ 1:47AM 0:00.00 grep -nR httpd
> > 
> > If I let gbd continue, I end up with
> > ps -aux | grep httpd
> > 111:pgollucci 53023 0.0 15.8 81684 81056 p6 T 1:42AM 0: 01.54 gdb httpd
> > 112:pgollucci 53044 0.0 2.0 11148 10300 p6 TX 1:42AM 0:00.39 -e (httpd)
> > 114:pgollucci 53270 0.0 0.0 348 208 p6 R+ 1:48AM 0:00.00 grep -nR httpd
> > 
> > --
> > 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 
> > 
> 
>

Re: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
By commenting out the 2 lines 
save_scalar(gv); /* local $0 */
sv_setpv_mg(GvSV(gv), directive->filename);
 in modperl_cmd.c I have been able to see the proper arguments in the ps 
output instead of the -e which was seen before. I wasn't sure of exactly 
what these 2 lines are doing. I however see that the perl directives that 
have been added inside the Perl block are being parsed. 
 Diff

{
SV *code = newSVpv(arg, 0);
GV *gv = gv_fetchpv("0", TRUE, SVt_PV);
ENTER;SAVETMPS;
- save_scalar(gv); /* local $0 */
- sv_setpv_mg(GvSV(gv), directive->filename);
eval_sv(code, G_SCALAR|G_KEEPERR);
SvREFCNT_dec(code);
modperl_env_sync_srv_env_hash2table(aTHX_ p, scfg);
modperl_env_sync_dir_env_hash2table(aTHX_ p, dcfg);
FREETMPS;LEAVE;
}
Thanks and Regards,
Pradeep
 On 10/13/05, Philip M. Gollucci <pg...@p6m7g8.com> wrote: 
> 
> Philippe M. Chiasson wrote:
> > Still unable to reproduce this on my end.
> This help any ?
> 
> gdb httpd (wd: ~/dev/apps/httpd-2.3.0/prefork/bin)
> b modperl_cmd.c:559
> [snip]
> 
> bt full
> #0 modperl_cmd_perldo (parms=0xbfbfe9e0, mconfig=0x81056d0,
> arg=0x8133798 "package
> 
> Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78;\n#line
> 78 /usr/home/pgollucci/dev/apps/httpd-2.3.0/prefork/conf/mod_perl.conf\n\n") 
> at
> modperl_cmd.c:560
> code = (SV *) 0x8138c2c
> gv = (GV *) 0x8138908
> p = (apr_pool_t *) 0x80bc018
> s = (server_rec *) 0x80c1988
> dcfg = (modperl_config_dir_t *) 0x81056d0
> options = (apr_table_t *) 0x8125018
> handler = (modperl_handler_t *) 0x81335d8
> pkg_name = 0x8133660
> 
> "Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78"
> directive = (ap_directive_t *) 0x8125158
> scfg = (modperl_config_srv_t *) 0x8105100
> #1 0x08077ce3 in invoke_cmd (cmd=0x283a1420, parms=0xbfbfe9e0,
> mconfig=0x81056d0, args=0x8125150 "\n") at config.c:735
> w = 0x8078ce8 "\203Ä \211Eð\213Eø\213@\b\211Eü\213Eü\213@\f%"
> w2 = 0xbfbfe988 "¸é¿¿¬\215\a\bXQ\022\bàé¿¿Hç\016\b4-da11-9dca-0002e33b"
> w3 = 0x81056d0 ""
> errmsg = 0x0
> #2 0x08078d1c in ap_walk_config_sub (current=0x8125158, parms=0xbfbfe9e0,
> section_vector=0x80ee748) at config.c:1141
> dir_config = (void *) 0x81056d0
> retval = 0x0
> cmd = (const command_rec *) 0x283a1420
> ml = (ap_mod_list *) 0x8103458
> dir = 0x8133418 "perl"
> #3 0x08078dac in ap_walk_config (current=0x8125158, parms=0xbfbfe9e0,
> section_vector=0x80ee748) at config.c:1174
> errmsg = 0x0
> oldconfig = (ap_conf_vector_t *) 0x0
> #4 0x08079c05 in ap_process_config_tree (s=0x80c1988, conftree=0x80efcb8,
> p=0x80bc018, ptemp=0x80ec018) at config.c:1743
> errmsg = 0x0
> parms = {info = 0x0, override = 150, limited = -1, limited_xmethods =
> 0x0, xlimited = 0x0, config_file = 0x0, directive = 0x8125158, pool = 
> 0x80bc018,
> temp_pool = 0x80ec018, server = 0x80c1988,
> path = 0x0, cmd = 0x283a1420, context = 0x80ee748, err_directive = 0x0,
> override_opts = 239}
> #5 0x08061dc7 in main (argc=4, argv=0xbfbfeb04) at main.c:616
> c = 100 'd'
> configtestonly = 0
> confname = 0x80954cd "conf/httpd.conf"
> def_server_root = 0xbfbfec59 ".."
> temp_error_log = 0x0
> error = 0x0
> process = (process_rec *) 0x80ba098
> server_conf = (server_rec *) 0x80c1988
> pglobal = (apr_pool_t *) 0x80ba018
> pconf = (apr_pool_t *) 0x80bc018
> plog = (apr_pool_t *) 0x80ea018
> ptemp = (apr_pool_t *) 0x80ec018
> pcommands = (apr_pool_t *) 0x80be018
> opt = (apr_getopt_t *) 0x80be0b0
> rv = 70014
> mod = (module **) 0x280a6261
> optarg = 0xbfbfec59 ".."
> signal_server = (apr_OFN_ap_signal_server_t *) 0x2824fe40 
> <__isthreaded+28>
> (gdb) x directive->filename
> 0x8121200: 0x7273752f
> (gdb) p directive->filename
> $3 = 0x8121200 "/usr/home/pgollucci/dev/apps/httpd-2.3.0
> /prefork/conf/mod_perl.conf"
> (gdb)
> 
> FYI, mod_perl.conf contains my
> <Perl>
> 
> </Perl>
> 
> section
> 
> at this point,
> ps -aux | grep httpd
> 111:pgollucci 53023 0.0 15.8 81684 81056 p6 T 1:42AM 0:01.54 gdb httpd
> 112:pgollucci 53044 0.0 2.0 11148 10300 p6 TX 1:42AM 0:00.39 (httpd)
> 114:pgollucci 53259 0.0 0.0 348 208 p6 R+ 1:47AM 0:00.00 grep -nR httpd
> 
> If I let gbd continue, I end up with
> ps -aux | grep httpd
> 111:pgollucci 53023 0.0 15.8 81684 81056 p6 T 1:42AM 0:01.54 gdb httpd
> 112:pgollucci 53044 0.0 2.0 11148 10300 p6 TX 1:42AM 0:00.39 -e (httpd)
> 114:pgollucci 53270 0.0 0.0 348 208 p6 R+ 1:48AM 0:00.00 grep -nR httpd
> 
> --
> 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
>

Re: [mp2] Directive changes the command nam

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> Still unable to reproduce this on my end.
This help any ?

gdb httpd (wd: ~/dev/apps/httpd-2.3.0/prefork/bin)
b modperl_cmd.c:559
[snip]

bt full
#0  modperl_cmd_perldo (parms=0xbfbfe9e0, mconfig=0x81056d0,
     arg=0x8133798 "package 
Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78;\n#line 
78 /usr/home/pgollucci/dev/apps/httpd-2.3.0/prefork/conf/mod_perl.conf\n\n") at 
modperl_cmd.c:560
         code = (SV *) 0x8138c2c
         gv = (GV *) 0x8138908
         p = (apr_pool_t *) 0x80bc018
         s = (server_rec *) 0x80c1988
         dcfg = (modperl_config_dir_t *) 0x81056d0
         options = (apr_table_t *) 0x8125018
         handler = (modperl_handler_t *) 0x81335d8
         pkg_name = 0x8133660 
"Apache2::ReadConfig::usr::home::pgollucci::dev::apps::httpd_2_3_0::prefork::conf::mod_perl_conf::line_78"
         directive = (ap_directive_t *) 0x8125158
         scfg = (modperl_config_srv_t *) 0x8105100
#1  0x08077ce3 in invoke_cmd (cmd=0x283a1420, parms=0xbfbfe9e0, 
mconfig=0x81056d0, args=0x8125150 "\n") at config.c:735
         w = 0x8078ce8 "\203Ä \211Eð\213Eø\213@\b\211Eü\213Eü\213@\f%"
         w2 = 0xbfbfe988 "¸é¿¿¬\215\a\bXQ\022\bàé¿¿Hç\016\b4-da11-9dca-0002e33b"
         w3 = 0x81056d0 ""
         errmsg = 0x0
#2  0x08078d1c in ap_walk_config_sub (current=0x8125158, parms=0xbfbfe9e0, 
section_vector=0x80ee748) at config.c:1141
         dir_config = (void *) 0x81056d0
         retval = 0x0
         cmd = (const command_rec *) 0x283a1420
         ml = (ap_mod_list *) 0x8103458
         dir = 0x8133418 "perl"
#3  0x08078dac in ap_walk_config (current=0x8125158, parms=0xbfbfe9e0, 
section_vector=0x80ee748) at config.c:1174
         errmsg = 0x0
         oldconfig = (ap_conf_vector_t *) 0x0
#4  0x08079c05 in ap_process_config_tree (s=0x80c1988, conftree=0x80efcb8, 
p=0x80bc018, ptemp=0x80ec018) at config.c:1743
         errmsg = 0x0
         parms = {info = 0x0, override = 150, limited = -1, limited_xmethods = 
0x0, xlimited = 0x0, config_file = 0x0, directive = 0x8125158, pool = 0x80bc018, 
temp_pool = 0x80ec018, server = 0x80c1988,
   path = 0x0, cmd = 0x283a1420, context = 0x80ee748, err_directive = 0x0, 
override_opts = 239}
#5  0x08061dc7 in main (argc=4, argv=0xbfbfeb04) at main.c:616
         c = 100 'd'
         configtestonly = 0
         confname = 0x80954cd "conf/httpd.conf"
         def_server_root = 0xbfbfec59 ".."
         temp_error_log = 0x0
         error = 0x0
         process = (process_rec *) 0x80ba098
         server_conf = (server_rec *) 0x80c1988
         pglobal = (apr_pool_t *) 0x80ba018
         pconf = (apr_pool_t *) 0x80bc018
         plog = (apr_pool_t *) 0x80ea018
         ptemp = (apr_pool_t *) 0x80ec018
         pcommands = (apr_pool_t *) 0x80be018
         opt = (apr_getopt_t *) 0x80be0b0
         rv = 70014
         mod = (module **) 0x280a6261
         optarg = 0xbfbfec59 ".."
         signal_server = (apr_OFN_ap_signal_server_t *) 0x2824fe40 <__isthreaded+28>
(gdb) x directive->filename
0x8121200:      0x7273752f
(gdb) p directive->filename
$3 = 0x8121200 "/usr/home/pgollucci/dev/apps/httpd-2.3.0/prefork/conf/mod_perl.conf"
(gdb)

FYI, mod_perl.conf contains my
<Perl>

</Perl>

section

at this point,
ps -aux | grep httpd
111:pgollucci 53023  0.0 15.8 81684 81056  p6  T     1:42AM   0:01.54 gdb httpd
112:pgollucci 53044  0.0  2.0 11148 10300  p6  TX    1:42AM   0:00.39  (httpd)
114:pgollucci 53259  0.0  0.0   348   208  p6  R+    1:47AM   0:00.00 grep -nR httpd

If I let gbd continue, I end up with
ps -aux | grep httpd
111:pgollucci 53023  0.0 15.8 81684 81056  p6  T     1:42AM   0:01.54 gdb httpd
112:pgollucci 53044  0.0  2.0 11148 10300  p6  TX    1:42AM   0:00.39 -e (httpd)
114:pgollucci 53270  0.0  0.0   348   208  p6  R+    1:48AM   0:00.00 grep -nR httpd

-- 
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

Re: [mp2] Directive changes the command nam

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philippe M. Chiasson wrote:
> Still unable to reproduce this on my end.
FreeBSD i386 7.0-current
perl 5.8.7 w/out ithreads
httpd svn
apr svn not threaded
mod_perl svn

perl Makefile.PL \
  MP_APXS=/usr/home/pgollucci/dev/apps/httpd-2.3.0/prefork/bin/apxs \
  MP_MAINTAINER=1 \
  MP_DEBUG=1 \
  MP_TRACE=1 \

httpd.conf:
LoadModule perl_module modules/mod_perl.so
Include conf/mod_perl.conf

mod_perl.conf
PerlSwitchs -wT
PerlPostConfigRequire conf/startup.pl

<Perl>

</Perl>

startup.pl:
## CORE PERL Modules
use strict;
use warnings FATAL => 'all';
use Carp;

## Core MP2 Modules
use mod_perl2;
use ModPerl::MethodLookup ();

&ModPerl::MethodLookup::preload_all_modules();

## MP2 Extras
use Apache2::PerlSections ();
$Apache2::PerlSections::Save = 1; ## this has to come before Apache2::Status

use Apache2::Status();

-- 
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


Re: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Philip M. Gollucci wrote:
> pradeep kumar wrote:
> 
>> Hi Philppe,
>>  
>> I did try using mod_perl 2.0.1 and got the same "-e" in the ps output
>> instead of
>> "/PATH_TO_HTTPD -d /PATH_OF_APACHE -k start".
> 
> I'll confirm this in mp2 svn.

Still unable to reproduce this on my end.

> Here's the relevenant section in modperl_cmd.c:
> 
>     {
>         SV *code = newSVpv(arg, 0);
>         GV *gv = gv_fetchpv("0", TRUE, SVt_PV);
> 
>         ENTER;SAVETMPS;

This bit creates the equivalent of a {} block for scoping issues

>         save_scalar(gv); /* local $0 */

As the comment points out, this is just like local $0

> #if PERL_REVISION == 5 && PERL_VERSION >= 9
>         TAINT_NOT; /* XXX: temp workaround, see my p5p post */
> #endif
>         sv_setpv_mg(GvSV(gv), directive->filename);

This sets $0 to directive->filename (setpv_mg so that the magic that
changes argv[0] is performed)

>         eval_sv(code, G_SCALAR|G_KEEPERR);
>         SvREFCNT_dec(code);
>         modperl_env_sync_srv_env_hash2table(aTHX_ p, scfg);
>         modperl_env_sync_dir_env_hash2table(aTHX_ p, dcfg);
>         FREETMPS;LEAVE;

This closes the pseudo-{} block we just created, restoring $0

>     }
> 
> Okay, now, how do I go about figuring out this XS.  I've read most if
> not all of the perldoc things like guts and xs etc...

This is the simplest example I can think of to localize something:

    #define PRINT$0 eval_pv("print STDERR qq(Dollar 0 = $0\n)", 0)

    GV *gv = gv_fetchpv("0", TRUE, SVt_PV);
    PRINT$0;
    ENTER;SAVETMPS;
        PRINT$0;
        save_scalar(gv);
        PRINT$0;
        sv_setpv_mg(GvSV(gv), "Hello XS");
        PRINT$0;
    FREETMPS;LEAVE;
    PRINT$0;

And you'd get:

Dollar 0 = t/Test.t
Dollar 0 = t/Test.t
Dollar 0 =
Dollar 0 = Hello XS
Dollar 0 = t/Test.t

> Perl_gv_dump and Perl_sv_dump don't tell me too much that I can use.
> 
> Any pointers to your favorite documentation?
> 
> Me thinks that this needs to change ?
>         sv_setpv_mg(GvSV(gv), directive->filename);

Why? It's doing exactly what it's supposed to be doing ...

--------------------------------------------------------------------------------
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: [mp2] Directive changes the command nam

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
pradeep kumar wrote:
> Hi Philppe,
>  
> I did try using mod_perl 2.0.1 and got the same "-e" in the ps output 
> instead of
> "/PATH_TO_HTTPD -d /PATH_OF_APACHE -k start".
I'll confirm this in mp2 svn.

Here's the relevenant section in modperl_cmd.c:

     {
         SV *code = newSVpv(arg, 0);
         GV *gv = gv_fetchpv("0", TRUE, SVt_PV);

         ENTER;SAVETMPS;
         save_scalar(gv); /* local $0 */
#if PERL_REVISION == 5 && PERL_VERSION >= 9
         TAINT_NOT; /* XXX: temp workaround, see my p5p post */
#endif
         sv_setpv_mg(GvSV(gv), directive->filename);
         eval_sv(code, G_SCALAR|G_KEEPERR);
         SvREFCNT_dec(code);
         modperl_env_sync_srv_env_hash2table(aTHX_ p, scfg);
         modperl_env_sync_dir_env_hash2table(aTHX_ p, dcfg);
         FREETMPS;LEAVE;
     }

Okay, now, how do I go about figuring out this XS.  I've read most if not all of the perldoc things like guts and xs etc...

Perl_gv_dump and Perl_sv_dump don't tell me too much that I can use.

Any pointers to your favorite documentation?

Me thinks that this needs to change ?
         sv_setpv_mg(GvSV(gv), directive->filename);



-- 
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


Re: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
Hi Philppe,
 I did try using mod_perl 2.0.1 and got the same "-e" in the ps output 
instead of 
"/PATH_TO_HTTPD -d /PATH_OF_APACHE -k start". 
 Thanks and Regards,
Pradeep
 On 9/9/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote: 
> 
> pradeep kumar wrote:
> > Hi Philppe,
> >
> > I am using mp2. The version of mod_perl is 1.99_16. What is the
> > equivalent of this patch in mp2.
> 
> This should not be a problem in mod_perl 2.0, can you try and upgrade
> to mod_perl-2.0.1 and see if the problem still persists ?
> 
> If so, try and use the mp2bug tool to submit a complete bug report.
> 
> 
> --------------------------------------------------------------------------------
> 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: [mp2] Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pradeep kumar wrote:
> Hi Philppe,
>
> I am using mp2. The version of mod_perl is 1.99_16. What is the
> equivalent of this patch in mp2.

This should not be a problem in mod_perl 2.0, can you try and upgrade
to mod_perl-2.0.1 and see if the problem still persists ?

If so, try and use the mp2bug tool to submit a complete bug report.

--------------------------------------------------------------------------------
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: [mp2] Directive changes the command nam

Posted by pradeep kumar <pr...@gmail.com>.
Hi Philppe,
 I am using mp2. The version of mod_perl is 1.99_16. What is the equivalent 
of this patch in mp2.
 Thanks and Regards,
Pradeep

 On 8/30/05, Philippe M. Chiasson <go...@ectoplasm.org> wrote: 
> 
> pradeep kumar wrote:
> > Hi All,
> >
> > Has anyone come across the command name changing when the Perl
> > directive is introduced in the configuration file.
> >
> > When,
> >
> > <Perl>
> > </Perl>
> >
> > is used then ps -ef gives the proper command name namely httpd.
> >
> > When
> > <Perl>
> >
> > </Perl>
> >
> > is used(This time with a blank line) then ps -ef does not give httpd
> > as the command name, instead gievs -e as the command name. This occurs
> > even when a directive is used inside the section but the directive is
> > parsed though. Is there any buffer overflow that may be happening.
> 
> Can you please report a more complete bug report that includes at least 
> the
> version numbers of what you are running ?
> 
> mp1 bug reporting: 
> http://perl.apache.org/docs/1.0/guide/help.html#How_to_Report_Problems
> mp2 bug reporting: 
> http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems
> 
> But after having looked at mp1's code, I suspect you are running mp1 and 
> that there
> is a bug there. Can you try applying this patch ?
> 
> Index: src/modules/perl/perl_config.c
> ===================================================================
> --- src/modules/perl/perl_config.c (revision 190634)
> +++ src/modules/perl/perl_config.c (working copy)
> @@ -1764,12 +1766,13 @@
> perl_section_hash_init("FilesMatch", dotie);
> perl_section_hash_init("Limit", dotie);
> 
> - sv_setpv(perl_get_sv("0", TRUE), cmd_filename);
> -
> ENTER_SAFE(parms->server, parms->pool);
> MP_TRACE_g(mod_perl_dump_opmask());
> 
> {
> + SV *scriptname = perl_get_sv("0", TRUE);
> + save_item(scriptname);
> + sv_setpv_mg(scriptname, cmd_filename);
> SV *server_sv = perl_get_sv("Apache::__SERVER", FALSE);
> IV ptr = SvIVX(SvRV(server_sv));
> SvIVX(SvRV(server_sv)) = (IV)parms->server;
> 
> But one thing is for sure, in mp1, this is a bug, since it's setting $0 
> but
> failing to reset it back.
> 
> 
> --------------------------------------------------------------------------------
> 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: Directive changes the command nam

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pradeep kumar wrote:
> Hi All,
> 
> Has anyone come across the command name changing when the Perl
> directive is introduced in the configuration file.
> 
> When,
> 
> <Perl>
> </Perl>
> 
>  is used then ps -ef gives the proper command name namely httpd. 
> 
> When
> <Perl>
> 
> </Perl>
> 
> is used(This time with a blank line) then ps -ef does not give httpd
> as the command name, instead gievs -e as the command name. This occurs
> even when a directive is used inside the section but the directive is
> parsed though.  Is there any buffer overflow that may be happening.

Can you please report a more complete bug report that includes at least the
version numbers of what you are running ?

mp1 bug reporting: http://perl.apache.org/docs/1.0/guide/help.html#How_to_Report_Problems
mp2 bug reporting: http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems

But after having looked at mp1's code, I suspect you are running mp1 and that there
is a bug there. Can you try applying this patch ?

Index: src/modules/perl/perl_config.c
===================================================================
--- src/modules/perl/perl_config.c      (revision 190634)
+++ src/modules/perl/perl_config.c      (working copy)
@@ -1764,12 +1766,13 @@
     perl_section_hash_init("FilesMatch", dotie);
     perl_section_hash_init("Limit", dotie);

-    sv_setpv(perl_get_sv("0", TRUE), cmd_filename);
-
     ENTER_SAFE(parms->server, parms->pool);
     MP_TRACE_g(mod_perl_dump_opmask());

     {
+        SV *scriptname = perl_get_sv("0", TRUE);
+        save_item(scriptname);
+        sv_setpv_mg(scriptname, cmd_filename);
         SV *server_sv = perl_get_sv("Apache::__SERVER", FALSE);
         IV ptr = SvIVX(SvRV(server_sv));
         SvIVX(SvRV(server_sv)) = (IV)parms->server;

But one thing is for sure, in mp1, this is a bug, since it's setting $0 but
failing to reset it back.

--------------------------------------------------------------------------------
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