[PATCH mp2] sections setting $0

2003-11-14 Thread Philippe M. Chiasson
in mp 1.x land,  sections used to set $0 to the name of the
configuration file it was in.

Following patches does just that for 2.x

Index: Changes
===
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.250
diff -u -I$Id: -r1.250 Changes
--- Changes 13 Nov 2003 21:03:46 -  1.250
+++ Changes 14 Nov 2003 17:40:29 -
@@ -12,6 +12,9 @@
 
 =item 1.99_12-dev
 
+ sections now proprely set $0 to the name of the configuration
+file they are in. [Philippe M. Chiasson]
+
  sections now proprely set filename and line number information,
 making error messages report the correct location. [Philippe M. Chiasson]
 
Index: src/modules/perl/modperl_cmd.c
===
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.50
diff -u -I$Id: -r1.50 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c  13 Nov 2003 21:03:46 -  1.50
+++ src/modules/perl/modperl_cmd.c  14 Nov 2003 17:40:29 -
@@ -409,6 +409,8 @@
   arg, NULL);
 }
 
+sv_setpv(get_sv("0", TRUE), parms->directive->filename);
+
 eval_pv(arg, FALSE);
 
 if (SvTRUE(ERRSV)) {
Index: t/conf/extra.last.conf.in
===
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.8
diff -u -I$Id: -r1.8 extra.last.conf.in
--- t/conf/extra.last.conf.in   13 Nov 2003 21:03:46 -  1.8
+++ t/conf/extra.last.conf.in   14 Nov 2003 17:40:29 -
@@ -24,6 +24,7 @@
 
 $Apache::Server::SaveConfig = 1;
 $TestDirective::perl::filename = __FILE__;
+$TestDirective::perl::dollar_zero = $0;
 $TestDirective::perl::line =  __LINE__;
 
 
Index: t/response/TestDirective/perldo.pm
===
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
retrieving revision 1.4
diff -u -I$Id: -r1.4 perldo.pm
--- t/response/TestDirective/perldo.pm  13 Nov 2003 21:03:47 -  1.4
+++ t/response/TestDirective/perldo.pm  14 Nov 2003 17:40:29 -
@@ -10,7 +10,7 @@
 sub handler {
 my $r = shift;
 
-plan $r, tests => 7;
+plan $r, tests => 8;
 
 ok t_cmp('yes', $TestDirective::perl::worked);
 
@@ -21,6 +21,8 @@
 ok t_cmp('PerlSection', 
$Apache::ReadConfig::Location{'/perl_sections_saved'}{'AuthName'});
 
 ok t_cmp('yes', $TestDirective::perl::comments);
+
+ok t_cmp(qr/extra.last.conf/, $TestDirective::perl::dollar_zero, '$0');
 
 ok t_cmp(qr/extra.last.conf/, $TestDirective::perl::filename, '__FILE__');
 

-- 

Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'


signature.asc
Description: This is a digitally signed message part


Re: [PATCH mp2] sections setting $0

2003-11-14 Thread Stas Bekman
Philippe M. Chiasson wrote:
in mp 1.x land,  sections used to set $0 to the name of the
configuration file it was in.
Following patches does just that for 2.x
there is one problem with it. You need to restore it to its original value 
after Perl sections are over, no? How did it work in mp1?

Index: src/modules/perl/modperl_cmd.c
===
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.50
diff -u -I$Id: -r1.50 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c	13 Nov 2003 21:03:46 -	1.50
+++ src/modules/perl/modperl_cmd.c	14 Nov 2003 17:40:29 -
@@ -409,6 +409,8 @@
   arg, NULL);
 }
 
+sv_setpv(get_sv("0", TRUE), parms->directive->filename);
+
__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: [PATCH mp2] sections setting $0

2003-11-14 Thread Philippe M. Chiasson
On Fri, 2003-11-14 at 10:12, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > in mp 1.x land,  sections used to set $0 to the name of the
> > configuration file it was in.
> >
> > Following patches does just that for 2.x
> 
> there is one problem with it. You need to restore it to its original value 
> after Perl sections are over, no? How did it work in mp1?

Absolutely right! 

In mp1, it does that exact same thing, so it's also broken and doesn't
restore it to its original value

Following patch achieves that correctly, also taking care of untainting
$0 (didn't even know $0 was tainted) which is required to prevent
"unsafe dependency in eval" errors from hapenning (not 100% certain why
that is the case)


? t/core.12386
? t/core.13747
? t/core.2207
? t/core.31221
? t/core.31900
? t/core.5627
? t/core.6511
? t/core.7185
Index: Changes
===
RCS file: /home/cvs/modperl-2.0/Changes,v
retrieving revision 1.250
diff -u -I$Id: -r1.250 Changes
--- Changes 13 Nov 2003 21:03:46 -  1.250
+++ Changes 15 Nov 2003 01:31:17 -
@@ -12,6 +12,9 @@
 
 =item 1.99_12-dev
 
+ sections now proprely set $0 to the name of the configuration
+file they are in. [Philippe M. Chiasson]
+
  sections now proprely set filename and line number information,
 making error messages report the correct location. [Philippe M. Chiasson]
 
Index: src/modules/perl/modperl_cmd.c
===
RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_cmd.c,v
retrieving revision 1.50
diff -u -I$Id: -r1.50 modperl_cmd.c
--- src/modules/perl/modperl_cmd.c  13 Nov 2003 21:03:46 -  1.50
+++ src/modules/perl/modperl_cmd.c  15 Nov 2003 01:31:17 -
@@ -365,6 +365,8 @@
 const char *line_header = NULL;
 int status = OK;
 AV *args = Nullav;
+SV *dollar_zero = Nullsv;
+int dollar_zero_tainted;
 #ifdef USE_ITHREADS
 MP_dSCFG(s);
 pTHX;
@@ -409,7 +411,23 @@
   arg, NULL);
 }
 
+/* Set $0 to the current configuration file */
+dollar_zero = get_sv("0", TRUE);
+dollar_zero_tainted = SvTAINTED(dollar_zero);
+
+if (dollar_zero_tainted) {
+SvTAINTED_off(dollar_zero); 
+}
+
+ENTER;
+save_item(dollar_zero);
+sv_setpv(dollar_zero, parms->directive->filename);
 eval_pv(arg, FALSE);
+LEAVE;
+
+if (dollar_zero_tainted) {
+SvTAINTED_on(dollar_zero);
+}
 
 if (SvTRUE(ERRSV)) {
 SV *strict;
Index: t/conf/extra.last.conf.in
===
RCS file: /home/cvs/modperl-2.0/t/conf/extra.last.conf.in,v
retrieving revision 1.8
diff -u -I$Id: -r1.8 extra.last.conf.in
--- t/conf/extra.last.conf.in   13 Nov 2003 21:03:46 -  1.8
+++ t/conf/extra.last.conf.in   15 Nov 2003 01:31:17 -
@@ -24,6 +24,7 @@
 
 $Apache::Server::SaveConfig = 1;
 $TestDirective::perl::filename = __FILE__;
+$TestDirective::perl::dollar_zero = $0;
 $TestDirective::perl::line =  __LINE__;
 
 
Index: t/response/TestDirective/perldo.pm
===
RCS file: /home/cvs/modperl-2.0/t/response/TestDirective/perldo.pm,v
retrieving revision 1.4
diff -u -I$Id: -r1.4 perldo.pm
--- t/response/TestDirective/perldo.pm  13 Nov 2003 21:03:47 -  1.4
+++ t/response/TestDirective/perldo.pm  15 Nov 2003 01:31:17 -
@@ -10,7 +10,7 @@
 sub handler {
 my $r = shift;
 
-plan $r, tests => 7;
+plan $r, tests => 9;
 
 ok t_cmp('yes', $TestDirective::perl::worked);
 
@@ -22,12 +22,15 @@
 
 ok t_cmp('yes', $TestDirective::perl::comments);
 
+ok t_cmp(qr/extra.last.conf/, $TestDirective::perl::dollar_zero, '$0');
+
 ok t_cmp(qr/extra.last.conf/, $TestDirective::perl::filename, '__FILE__');
 
 # 3 would mean we are still counting lines from the context of the eval
 ok $TestDirective::perl::line > 3;
 
+ok t_cmp("-e", $0, '$0');
+
 Apache::OK;
 }
-
 1;


> __
> Stas BekmanJAm_pH --> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
-- 

Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5 (122FF51B/C634E37B)
http://gozer.ectoplasm.org/F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so ingenious.
perl -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'


signature.asc
Description: This is a digitally signed message part


Re: [PATCH mp2] sections setting $0

2003-11-14 Thread Stas Bekman
Philippe M. Chiasson wrote:
On Fri, 2003-11-14 at 10:12, Stas Bekman wrote:

Philippe M. Chiasson wrote:

in mp 1.x land,  sections used to set $0 to the name of the
configuration file it was in.
Following patches does just that for 2.x
there is one problem with it. You need to restore it to its original value 
after Perl sections are over, no? How did it work in mp1?


Absolutely right! 

In mp1, it does that exact same thing, so it's also broken and doesn't
restore it to its original value
I vaguely remember some discussions about $0 being set to httpd vs. perl in 
mp1. It probably should be set to the location of httpd, since that's the 
running program, but -e works just fine for me. In mp1 PerlRunXS sets $0 to 
the current script name.

Following patch achieves that correctly, also taking care of untainting
$0 (didn't even know $0 was tainted) which is required to prevent
"unsafe dependency in eval" errors from hapenning (not 100% certain why
that is the case)
very cool. +1.

? t/core.12386
? t/core.13747
? t/core.2207
? t/core.31221
? t/core.31900
? t/core.5627
? t/core.6511
? t/core.7185
Hey, stop sending subliminal messages ;)

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]