Geoffrey Young wrote:
Can you please remind me what was the mp1 behavior on that? We need to
match it. Things are complicated in mp2, because the C environ struct is
detached from perl's %ENV, so there is a lot of extra work to do to
think %ENV and $r->subprocess_env


as I said in another response, IIRC in mp1 %ENV was not tied to the
subprocess_env table - you could populate $r->subprocess_env all day, but it
wouldn't make it to %ENV until ap_add_cgi_vars was called.  and
ap_add_cgi_vars was only called 1) once per-request, or 2) if
$r->subprocess_env was called in a void context.

the once per-request appears to happen on the first entry into a directory

    if(r->per_dir_config)
        perl_per_request_init(r);

which is different than mp2:

      case MP_HANDLER_TYPE_PER_DIR:
      case MP_HANDLER_TYPE_PER_SRV:
...

        /* only happens once per-request */
        if (MpDirSETUP_ENV(dcfg)) {
            modperl_env_request_populate(aTHX_ r);
        }


{
if (GIMME_V == G_VOID) {
+ MP_dRCFG;
+ MpReqSETUP_ENV_Off(rcfg); modperl_env_request_populate(aTHX_ r);
}


this is rquired to maintain mp1 compat, if we're intersted in that.

Yes and no, Geoff.


But, let's forget for a moment mp1. What's the most intuitive way to handle:

$r->subprocess_env(foo => $bar)

won't you sort of expect that %ENV will get that entry too? may be we should adjust subprocess_env to set %ENV as well. %ENV gets reset at the end of the request.

Hmm, I wonder what happens if you use an interpreter scope == handler and get a different interpreter for different phases. Looks like that %ENV setting won't be seen by the other interpreter.

Your above patch is fine Geoff, but it just looks like a big waste to me, if someone just wants to add a single pair to %ENV. Otherwise it's not needed, I think (it should be enough to call it once per request). May be we need a different API, like I suggest below, just for that purpose?

+    # make sure that registry scripts can see all of subprocess_env
in %ENV
+    $r->subprocess_env;
+


This is ain't right, as it ignores the user's setting of whether to load
env vars or not via:

PerlOptions [+-]SetupEnv and SetHandler (modperl|perl-script)


yes, you're right.

not sure what to do about this, then.  looks like both mp1 and mp2 suffer
from the same problem - add to $r->subprocess_env after the call to
ap_add_cgi_vars and Registry doesn't see stuff in %ENV.  it's just that the
call is happening at different times between the two.

Enrico, with the first half of Geoff's patch (minus registry), you will be able to achieve what you want, by adding an explicit call to $r->subprocess_env(), but it's horribly inefficient, especially if you call it more than once. Of course that 'horrible' part could be just fine, if you aren't after msecs.


Until we figure it out, I think your best bet is to write a wrapper that does what you need:

sub Apache::RequestRec::enrico_set_env {
  $r->subprocess_env(@_);
  $ENV{$_[0]} = $_[1];
}

and now you can call:

$r->enrico_set_env(foo => $bar);

This will affect only request handlers and work as long as you don't set perl interpreter scope to 'handler'.
http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlInterpScope_


__________________________________________________________________
Stas Bekman            JAm_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]



Reply via email to