Greetings,
Have written a program in C that takes input from stdin, and puts an answer on stdout. Program is intended to be called by apache webserver, from a RewriteMap;
RewriteMap prog prg:/usr/local/bin/prog
In apache, when RewriteRule condition is matched, the program defined in the RewriteMap is passed a string terminated by "\n". Apache expects the answer to be returned as a string or NULL, terminated by "\n".
When I test my program from command line, it functions as expected. Feed it a properly terminated string, and get an answer back. Feed it bogus string, get NULL back. Feed it an unterminated string, it sits there until enter is pressed. To my eye, it works as intended.
When apache starts, my program is started. I see it in the process list. When the RewriteMap feeds the string to my program, the browser hangs, waiting for response from apache. No further log output comes from apache, even though logging is jacked way up -
Loglevel debug rewrite:trace8 .
I shutdown apache, and I see it say "child process still did not exit, sending SIGTERM". Now I have a clue. My program has no notion of being a child process, so I will go figure out how to add capability for listening to SIG* signals from a parent process.
There are a couple of known gotchas regarding this RewriteMap technique.
Gotcha#1 says that buffering must be disabled, otherwise, apache will hang.. Sounds like behavior I see. In attempt to fix, I changed
printf("NULL\n");
to
fprintf(stdout"NULL\n");
No difference.
Gotcha#2 says that when using this technique in apache, Mutex must be defined in apache conf specifically for rewrite-map use, allowing apache to invoke its own lockfile management *for the program defined in the RewriteMap*. Otherwise, results from webclientA may end up in webclientB's browser.. I believe I've handled this part correctly, in apache2.conf;
Mutex file:/var/lock rewrite-map
I know the apache conf is correct. I made a bash script that does same thing as my prog - script works fine, no hang, results are returned, no SIGTERM issues, apache logging continues..
Sorry for all the blah-blah but I thought background would be relevant.
My questions:
Should I be concerned with 'fork' at this moment?
My program is not a daemon (as is apache 'httpd'). It loops forever waiting for input, and exits when Ctrl-C is pressed.
Should my program be made aware of apache's mutex use?
Any comments are appreciated. Thanks in advance.