You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mariano Absatz <ht...@lists.com.ar> on 2004/02/05 00:39:52 UTC
directive and ps -ef output
Hi,
I'm having a weird 'problem'... actually, it's just a nuisance, but I'd
like to know if
1) it can be solved
2) it's only a nuisance or it could be hidin' something else...
I'm using:
apache httpd 2.0.48 w/mod_perl 1.99.12 (under RedHat linux 7.2 w/stock
perl 5.6.1 installed from rpm) and I just started toying around with the
<Perl > directive (in order to get VirtualHost data from an LDAP
directory).
Everything is working OK, but whenever I use <Perl >, the output of "ps -
ef" changes.
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
However, as soon as I put a single line between <Perl > and </Perl> (even
if the line is empty), I get something like:
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
ps -e keeps working fine:
3738 ? 00:00:00 httpd
3739 ? 00:00:00 httpd
3740 ? 00:00:00 httpd
3741 ? 00:00:00 httpd
3742 ? 00:00:00 httpd
3743 ? 00:00:00 httpd
Is this a bug?
A feature?
An error on my part?
TIA.
--
Mariano Absatz
El Baby
----------------------------------------------------------
Quote me as saying I was misquoted.
-- Groucho Marx
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: directive and ps -ef output
Posted by Stas Bekman <st...@stason.org>.
Mariano Absatz wrote:
> Stas,
>
> thanx a lot... in fact, I'm a quite newbie user of mod_perl and only
> subscribed to the list to ask this, thinking I might be doing something
> wrong... in fact, as noone answered, and I had subscribed with the
> address I use for announce@httpd.apache.org, as the mod_perl messages
> were cluttering the folder, I just unsubscribed (so the copy of this mail
> to the list will probably bounce).
>
> 10 hours after I unsubscribed you sent your first answer, thankfully, you
> (and later Philippe) cc-ed me so I could stay in touch. I'm glad I was
> able to find a bug, and ever more glad that you were able to fix it.
>
> The point is that I'm in the middle of the migration of the service
> (mail/web hosting/dns) farm for a large ISP (from windows to linux) and I
> have no time at all to try the new cvs version.
>
> I've installed 1.99-12 in the web servers, and I'm in the process of
> final testing to go into production next week (we just missed tomorrow's
> deadline for going into production).
>
> Anyway, I'm only using mod_perl to automatically generate a little over a
> thousand virtual hosts whose data (servername, serveraliases, path, etc.)
> is stored in an LDAP directory... and I think I'll live with this version
> until final 2.0 is out there.
>
> If I'm able to find some spare time next weekend (not the one starting
> now), I'll try to check the cvs version.
>
> Once again, thanx a lot.
I think it should work fine. So it'll be in mod_perl 1.99_13, when it gets
released.
If having the 'httpd' name is significant you may want to apply this patch:
Index: src/modules/perl/modperl_config.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_config.c,v
retrieving revision 1.75
diff -u -r1.75 modperl_config.c
--- src/modules/perl/modperl_config.c 12 Feb 2004 02:05:28 -0000 1.75
+++ src/modules/perl/modperl_config.c 14 Feb 2004 01:37:09 -0000
@@ -178,8 +178,19 @@
#ifdef MP_USE_GTOP
scfg->gtop = modperl_gtop_new(p);
#endif
-
- modperl_config_srv_argv_push((char *)ap_server_argv0);
+
+ /* 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)));
MP_TRACE_d(MP_FUNC, "new scfg: 0x%lx\n", (unsigned long)scfg);
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: directive and ps -ef output
Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> On Wed, 2004-02-11 at 14:55 -0800, Stas Bekman wrote:
>
>>Mariano Absatz wrote:
>>[...]
>>I was trying to restore argv[0] to 'httpd', but it looks like perl does some
>>internal magic in main(), limiting the set_magic to PL_origalen which for some
>>reason is very short. so I get back things like 'htt' instead of 'httpd'.
>>
>>I can see the problem you have reported and still looking at possible solutions.
>
>
> 2 things worth looking at :
>
> ap_server_argv0 will hold the name of httpd (I hope)
>
> And in modperl_config.c :
>
> char **modperl_config_srv_argv_init(modperl_config_srv_t *scfg, int
> *argc)
> {
> modperl_config_srv_argv_push("-e;0");
>
> that's probably why PL_origalen is set to 4, so we might need to cheat
> and pad it a bit so it's at least strlen(ap_server_argv0) long...
I've found the root of the problem. $0 manipulations were corrupting process'
argv[0]. it's due to how perl propogates $0 settings to argv[0]. PL_origalen
set in perl_parse, which is later used in set_mg.c:Perl_magic_set() to
truncate the argv[0] setting, is set to the length of argv[0] passed to
perl_parse(), which is not a process's real argv[0].
I've changed the code to copy the real argv[0]. so now the process is always
seen from the outside with its real name (e.g. httpd), no matter what you
assign to $0. The original problem was happening even if you only read $0 w/o
setting it. It's truncate argv[0] to 'http' and later on to even 'htt'. My
earlier patch posted in this thread tried to workaround the problem by setting
PL_origalen to the original argv[0] length, but I think detaching $0 from
process' argv[0] is a goodness.
It's now committed, Marriano, please give a try to the cvs version which
includes this change.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: directive and ps -ef output
Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Wed, 2004-02-11 at 14:55 -0800, Stas Bekman wrote:
> Mariano Absatz wrote:
> [...]
> I was trying to restore argv[0] to 'httpd', but it looks like perl does some
> internal magic in main(), limiting the set_magic to PL_origalen which for some
> reason is very short. so I get back things like 'htt' instead of 'httpd'.
>
> I can see the problem you have reported and still looking at possible solutions.
2 things worth looking at :
ap_server_argv0 will hold the name of httpd (I hope)
And in modperl_config.c :
char **modperl_config_srv_argv_init(modperl_config_srv_t *scfg, int
*argc)
{
modperl_config_srv_argv_push("-e;0");
that's probably why PL_origalen is set to 4, so we might need to cheat
and pad it a bit so it's at least strlen(ap_server_argv0) long...
> _________________________
> Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org http://ticketmaster.com
>
> --
> Reporting bugs: http://perl.apache.org/bugs/
> Mail list info: http://perl.apache.org/maillist/modperl.html
> List etiquette: http://perl.apache.org/maillist/email-etiquette.html
>
Re: directive and ps -ef output
Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Mariano Absatz wrote:
>
>> Hi,
>>
>> I'm having a weird 'problem'... actually, it's just a nuisance, but
>> I'd like to know if
>> 1) it can be solved
>> 2) it's only a nuisance or it could be hidin' something else...
>>
>> I'm using:
>> apache httpd 2.0.48 w/mod_perl 1.99.12 (under RedHat linux 7.2 w/stock
>> perl 5.6.1 installed from rpm) and I just started toying around with
>> the <Perl > directive (in order to get VirtualHost data from an LDAP
>> directory).
>>
>> Everything is working OK, but whenever I use <Perl >, the output of "ps -
>> ef" changes.
>>
>> 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
>>
>> However, as soon as I put a single line between <Perl > and </Perl>
>> (even if the line is empty), I get something like:
>> root 3738 1 2 20:34 ? 00:00:00 /app/apache/bin/-e -k start
Please try this patch.
Index: src/modules/perl/mod_perl.c
===================================================================
RCS file: /home/cvs/modperl-2.0/src/modules/perl/mod_perl.c,v
retrieving revision 1.206
diff -u -r1.206 mod_perl.c
--- src/modules/perl/mod_perl.c 10 Jan 2004 05:01:04 -0000 1.206
+++ src/modules/perl/mod_perl.c 12 Feb 2004 01:07:55 -0000
@@ -1,5 +1,7 @@
#include "mod_perl.h"
+static char *MP_ap_server_argv0;
+
/* make sure that mod_perl won't try to start itself, while it's
* already starting. If the flag's value is 1 * it's still starting,
* when it's 2 it is running */
@@ -201,6 +203,17 @@
status = perl_parse(perl, modperl_xs_init, argc, argv, NULL);
MP_boot_data_set(NULL, NULL);
+ /* perl doesn't take into an account that it can be embedded and
+ * argv can be longer than the one passed to perl_parse. so we
+ * have to workaround the logic to calculate PL_origalen in
+ * perl_parse, which is later used in set_mg.c:Perl_magic_set() to
+ * truncate the argv[0] setting.
+ */
+ if (PL_origalen < (strlen(MP_ap_server_argv0)+1)) {
+ PL_origalen = strlen(MP_ap_server_argv0) + 1;
+ };
+ sv_setpv(get_sv("0", TRUE), MP_ap_server_argv0);
+
if (status) {
perror("perl_parse");
exit(1);
@@ -545,6 +558,11 @@
/* perl 5.8.1+ */
modperl_hash_seed_init(p);
+
+ /* it seems that Apache messes up with ap_server_argv0, so copy it
+ * away asap */
+ MP_ap_server_argv0 = apr_pstrmemdup(p, ap_server_argv0,
+ strlen(ap_server_argv0));
return OK;
}
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: directive and ps -ef output
Posted by Stas Bekman <st...@stason.org>.
Mariano Absatz wrote:
> Hi,
>
> I'm having a weird 'problem'... actually, it's just a nuisance, but I'd
> like to know if
> 1) it can be solved
> 2) it's only a nuisance or it could be hidin' something else...
>
> I'm using:
> apache httpd 2.0.48 w/mod_perl 1.99.12 (under RedHat linux 7.2 w/stock
> perl 5.6.1 installed from rpm) and I just started toying around with the
> <Perl > directive (in order to get VirtualHost data from an LDAP
> directory).
>
> Everything is working OK, but whenever I use <Perl >, the output of "ps -
> ef" changes.
>
> 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
>
> However, as soon as I put a single line between <Perl > and </Perl> (even
> if the line is empty), I get something like:
> 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
>
> ps -e keeps working fine:
> 3738 ? 00:00:00 httpd
> 3739 ? 00:00:00 httpd
> 3740 ? 00:00:00 httpd
> 3741 ? 00:00:00 httpd
> 3742 ? 00:00:00 httpd
> 3743 ? 00:00:00 httpd
>
> Is this a bug?
> A feature?
> An error on my part?
This is not an error on your part. <Perl> sections set $0 to the name of the
file they were originated from. That affects argv[0] (perl does that). For
example:
% perl -le '$0 = "foo"; sleep 20'
sets argv[0] to 'foo', so "ps -ef | grep foo" will show that process and not perl.
I was trying to restore argv[0] to 'httpd', but it looks like perl does some
internal magic in main(), limiting the set_magic to PL_origalen which for some
reason is very short. so I get back things like 'htt' instead of 'httpd'.
I can see the problem you have reported and still looking at possible solutions.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html