curl-library
Re: Seldom SegFaults within getenv on x64 architecture
Date: Thu, 13 Mar 2008 17:52:44 +0100
Am Donnerstag, 13. März 2008 17:31:23 schrieb Ingo Krabbe:
> Ok, this is a problem. I detected and located the source of this error and
>
> ITS NO FAULT OF libcURL itself, though its a problem when using it as I do:
>
> (FCGI=fast CGI as supported by mod_fcgid)
>
> Again: I use it as an FCGI Application that is called by an apache httpd.
> What I actually Do is: I get a request from the web server that results in
> another request to another host, but I don't want the client to wait for
> the completion of the request but I will give him a unique id, so that he
> can reference later to the requested data and see if I'm ready processing
> it.
>
> Then in background the libcURL requests to the other servers are processed
> and the results are stored for later shipment.
>
> What happens is that: The apache httpd server builds an own process
> environment for each single request to the fcgi_application, the
> fcgi_application process itself stays in memory. The process environment
> is only valid between the FCGI_accept call and the shipment of the answer.
> But the cURL callbacks are handled in the idle time too, where no request
> from the apache httpd is active.
>
> So when libcURL tries to read the environment within this idle time, which
> it does, when a new request is scheduled on the base of the finished old
> one, the environment isn't valid anymore and getenv itself segfaults
> reading the environ pointer (internally).
>
> Next I will try to provide an idle time environment for the process.
>
This actually solves the problem. Thats funny:
extern char** environ;
static char** saved_environ = NULL; /* I don't know if this is really needed
*/
static char* idle_environ[] = { "NO=VALUE",NULL }; /* <--fill in saved values
here */
....
if ( saved_environ == NULL ) saved_environ = environ;
environ = saved_environ;
FCGI_Accept();
...
/* closing request at the end of the function */
environ = idle_environ;
Received on 2008-03-13