You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by ob...@arcor.de on 2016/03/17 20:38:33 UTC
[users@httpd] Environment variable set by "apr_env_set()" not accesible by C
function "getenv()" within CGI program
Hi,
I have an Apache modul where I set an environment variable:
apr_env_set("FOO", "BAR", ...);
This variable is accesible by PHP:
<?php
print(getenv("FOO")); // --> BAR
?>
but not by a simple CGI program written in C:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
printf("Content-Type: text/html;charset=utf-8\n\n");
printf("%s", getenv("FOO")); /* --> NULL */
return 0;
}
Other (standard) server variables like SERVER_NAME are accesible.
Apache Version 2.2.
Many thanks in advance.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Environment variable set by "apr_env_set()" not
accesible by C function "getenv()" within CGI program
Posted by ob...@arcor.de.
On Thu, Mar 17, 2016 at 8:47 PM, Eric Covener wrote:
> On Thu, Mar 17, 2016 at 3:38 PM, <ob...@arcor.de> wrote:
>> Hi,
>>
>> I have an Apache modul where I set an environment variable:
>>
>> apr_env_set("FOO", "BAR", ...);
>>
>> This variable is accesible by PHP:
>>
>> <?php
>> print(getenv("FOO")); // --> BAR
>> ?>
>>
>> but not by a simple CGI program written in C:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>
> The environment used for a CGI is not the environment of httpd. You
> can modify it by adding entries to r->subprocess_env.
>
> Only some very specific vars are copied from httpds environment to the
> CGI, + the subprocess_env entries.
> --
> Eric Covener
> covener@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
Hi,
many thanks.
apr_table_setn(r->subprocess_env, "FOO", "BAR")
works perfectly.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Environment variable set by "apr_env_set()" not
accesible by C function "getenv()" within CGI program
Posted by Eric Covener <co...@gmail.com>.
On Thu, Mar 17, 2016 at 3:38 PM, <ob...@arcor.de> wrote:
> Hi,
>
> I have an Apache modul where I set an environment variable:
>
> apr_env_set("FOO", "BAR", ...);
>
> This variable is accesible by PHP:
>
> <?php
> print(getenv("FOO")); // --> BAR
> ?>
>
> but not by a simple CGI program written in C:
>
> #include <stdio.h>
> #include <stdlib.h>
The environment used for a CGI is not the environment of httpd. You
can modify it by adding entries to r->subprocess_env.
Only some very specific vars are copied from httpds environment to the
CGI, + the subprocess_env entries.
--
Eric Covener
covener@gmail.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org