On Friday 29 October 2004 22:13, Stas Bekman wrote:
> Torsten Förtsch wrote:
> > On Friday 29 October 2004 20:17, Stas Bekman wrote:
> >>>perl allows to modify $0. Then top, ps & co would display the new
> >>> process title. Can the process title of a mod_perl modified apache be
> >>> set this way?
> >>
...
> >>Take a look at this commit, which might be of some relevance:
> >>http://marc.theaimsgroup.com/?l=apache-modperl-cvs&m=107672268012042&w=2
> >
> > But I see, it is not supported.
>
> Due to internal Apache corruptions, no.

I have just uploaded Sys::Proctitle that modifies the process title at C 
level. It works only on linux. I have tried it with 2.0.52+mp2-RC1.

To the internal Apache corruptions: my first attempt was simply to make a copy 
of __environ via malloc() and strdup(). With pure perl that worked but with 
apache/mod_perl it gave segfaults or double free messages from glibc 
depending on the require'ing or use'ing of the module. Some poking on 
putenv/getenv/setenv source code revealed big magic and led me to the 
following approach of copying the environment:

    clearenv();
    for( i=0; envp[i]; i++ ) {
      char *cp=strchr( envp[i], '=' );
      if( cp ) {
        *cp++='\0';
        setenv( envp[i], cp, 1 );
      }
    }

clearenv() simply sets __environ=NULL. setenv() then builds a new environment.

I don't know anything about how mp2 and apache interact regarding the 
environment. But maybe it helps to let $0 be assigned to in mod_perl.

Again, the module is very linux specific.

As an example of using Sys::Proctitle I have uploaded Apache::ShowStatus. It 
provides a PerlInitHandler that places a Sys::Proctitle object in $r->pnotes 
changing the command line to "httpd: ".$r->the_request. When the request is 
deleted the object is destroyed and the command line is changed back. 
Obviously this makes sense only with prefork mpm.

Torsten

Attachment: pgpB8CBmxeZMK.pgp
Description: PGP signature

Reply via email to