Re: $r->document_root

[prev] [thread] [next] [Date index for 2005/02/19]

From: Stas Bekman
Subject: Re: $r->document_root
Date: 01:48 on 19 Feb 2005
Cahill, Earl wrote:
[...]
> Second, I couldn't get this
> 
> $r->document_root(hostname2docroot($r->hostname));
> 
> To set the docroot.  However, each of the following worked
> 
> my $new_docroot = hostname2docroot($r->hostname);
> $r->document_root($new_docroot);
> 
> And 
> 
> $r->document_root("" . hostname2docroot($r->hostname));
> 
> And 
> 
> $r->document_root($_ = hostname2docroot($r->hostname));
> 
> How very strange.

It's a bug. This patch which will go in shortly fixes it:

Index: xs/Apache/RequestUtil/Apache__RequestUtil.h
===================================================================
--- xs/Apache/RequestUtil/Apache__RequestUtil.h (revision 154310)
+++ xs/Apache/RequestUtil/Apache__RequestUtil.h (working copy)
@@ -320,7 +320,7 @@
          MP_CROAK_IF_THREADS_STARTED("setting $r->document_root");
          conf = ap_get_module_config(r->server->module_config,
                                      &core_module);
-        conf->ap_document_root = SvPV_nolen(new_root);
+        conf->ap_document_root = apr_pstrdup(r->pool, SvPV_nolen(new_root));
      }

      return retval;

before it just happened to work in certain situation. Since the value 
wasn't copied, if you have changed the scalar after assigning it, it'd 
affect the doc root in an unpredictable way. You've detected it since 
you've passed a value returned by another function. In that case it 
returns a TMP scalar which is special, as perl reuses it whenever the 
function is re-invoked. That's why you weren't getting it to work. This 
patch does a proper copying of that string.

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(message missing)

$r->document_root
Cahill, Earl 23:14 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:21 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:26 on 14 Feb 2005

RE: $r->document_root
Cahill, Earl 20:43 on 15 Feb 2005

Re: $r->document_root
Geoffrey Young 21:10 on 15 Feb 2005

Re: $r->document_root
Stas Bekman 01:48 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 02:02 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 13:54 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 17:21 on 19 Feb 2005

Re: $r->document_root
Joe Schaefer 14:12 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 05:26 on 20 Feb 2005

Re: $r->document_root
Stas Bekman 01:29 on 21 Feb 2005

Re: $r->document_root
Joe Schaefer 02:38 on 21 Feb 2005

Re: $r->document_root
Stas Bekman 02:43 on 21 Feb 2005

Generated at 12:48 on 22 Feb 2005 by mariachi v0.52