1

When looking at some examples for implementing a FastCGI client I ran into some curious code.

#include <fcgi_stdio.h>
#include <stdlib.h>
int main(void) {
    while(FCGI_Accept() >= 0)
        printf("Content-type: text/html\r\n\r\n"
               "Got a <i>%s</i> request\n",
               getenv("REQUEST_METHOD"));
    return 0;
}

To me that looks like the process would always get the same value for getenv(...), but it seems like the intent is to read data from the parent process.

Can the parent process update the child environment while the child process is running?

  • No. Why would the server name change? – Kusalananda Dec 6 '17 at 10:28
  • Just looks like less than ideal programming where instead the SERVER_NAME value should be stored statically/globally or some such. – B Layer Dec 6 '17 at 10:36
  • I saw a couple of other examples as well, but the SERVER_NAME variant was to shortest. Updated to better show that the intent was to read data from parent. – Kotte Dec 6 '17 at 12:13
3

No.

But the FCGI_Accept() function can update (the C library's copy of) the current process' environment every time that it is called, which of course is what it does.

Indeed, not retaining the result of calling getenv() is specifically called out in the doco of that function. So you can count how many people on this page read the doco. (-:

Further reading

  • FCGI_Accept. FCGI Manual. Open Market, Inc.. 1996. Archived at opensource.apple.com.
  • The edited version of the question provides significantly more incentive to read the documentation than the original ;-). – Stephen Kitt Dec 6 '17 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.