Re: $0 ?

[prev] [thread] [next] [Date index for 2004/12/30]

From: Torsten Foertsch
Subject: Re: $0 ?
Date: 15:18 on 30 Dec 2004
--nextPart2651036.bakVOKTtNY
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

On Friday 29 October 2004 22:13, Stas Bekman wrote:
> Torsten F=F6rtsch 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?
> >>
=2E..
> >>Take a look at this commit, which might be of some relevance:
> >>http://marc.theaimsgroup.com/?l=3Dapache-modperl-cvs&m=3D10767226801204=
2&w=3D2
> >
> > 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=20
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 c=
opy=20
of __environ via malloc() and strdup(). With pure perl that worked but with=
=20
apache/mod_perl it gave segfaults or double free messages from glibc=20
depending on the require'ing or use'ing of the module. Some poking on=20
putenv/getenv/setenv source code revealed big magic and led me to the=20
following approach of copying the environment:

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

clearenv() simply sets __environ=3DNULL. setenv() then builds a new environ=
ment.

I don't know anything about how mp2 and apache interact regarding the=20
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. I=
t=20
provides a PerlInitHandler that places a Sys::Proctitle object in $r->pnote=
s=20
changing the command line to "httpd: ".$r->the_request. When the request is=
=20
deleted the object is destroyed and the command line is changed back.=20
Obviously this makes sense only with prefork mpm.

Torsten

--nextPart2651036.bakVOKTtNY
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQBB1Bw3wicyCTir8T4RAsmPAJwOs+kJBZJRjCIXi8gTovZpRzQDQgCfYZqx
LZoN4BOa+QaAg1w4qauWhco=
=shuG
-----END PGP SIGNATURE-----

--nextPart2651036.bakVOKTtNY--

(message missing)

$0 ?
Torsten =?iso-8859-1?q?F=F6rtsch?= 17:37 on 29 Oct 2004

Re: $0 ?
Stas Bekman 18:17 on 29 Oct 2004

Re: $0 ?
Torsten =?iso-8859-1?q?F=F6rtsch?= 18:40 on 29 Oct 2004

Re: $0 ?
Stas Bekman 20:13 on 29 Oct 2004

Re: $0 ?
Pratik 20:21 on 29 Oct 2004

Re: $0 ?
Torsten Foertsch 15:18 on 30 Dec 2004

Some tests failed: mod_perl-2.0.0-RC2-XMas on FC3
Patrick LeBoutillier 16:30 on 30 Dec 2004

Re: $0 ?
Stas Bekman 23:02 on 30 Dec 2004

Re: $0 ?
David Nicol 00:21 on 30 Oct 2004

Generated at 12:16 on 16 Jan 2005 by mariachi v0.52