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/10/11 13:40:00 UTC

Re: [mp2] Directive changes the command nam

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