Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: [PATCH mp2] <Perl> sections setting $0: msg#00154

apache.mod-perl.devel

Subject: Re: [PATCH mp2] <Perl> sections setting $0

On Fri, 2003-11-14 at 10:12, Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> > in mp 1.x land, <Perl> 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 -0000 1.250
+++ Changes 15 Nov 2003 01:31:17 -0000
@@ -12,6 +12,9 @@

=item 1.99_12-dev

+<Perl> sections now proprely set $0 to the name of the configuration
+file they are in. [Philippe M. Chiasson]
+
<Perl> 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 -0000 1.50
+++ src/modules/perl/modperl_cmd.c 15 Nov 2003 01:31:17 -0000
@@ -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 -0000 1.8
+++ t/conf/extra.last.conf.in 15 Nov 2003 01:31:17 -0000
@@ -24,6 +24,7 @@
<Perl >
$Apache::Server::SaveConfig = 1;
$TestDirective::perl::filename = __FILE__;
+$TestDirective::perl::dollar_zero = $0;
$TestDirective::perl::line = __LINE__;
</Perl>

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 -0000 1.4
+++ t/response/TestDirective/perldo.pm 15 Nov 2003 01:31:17 -0000
@@ -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 Bekman JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/ mod_perl Guide ---> http://perl.apache.org
> mailto:stas@xxxxxxxxxx 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}'

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

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
solaris.opensol...    editors.vim/200...    web.turbogears....    jakarta.ant.dev...    mathematics.max...    text.unicode.ge...    lang.ruby.core/...    xfce.announce/2...    network.centeri...    php.cvs.pear/20...    user-groups.lin...    kde.devel.quant...    file-systems.ar...    redhat.fedora.t...    apple.fink.auto...    gnome.orbit.gen...    qplus.devel/200...    culture.transpo...    video.dri.user/...    operators.nanog...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation