From: Jeff Trawick Date: Sun, 28 May 2000 11:48:24 +0000 (+0000) Subject: mod_cgi: Restore logging of stderr from child process when ScriptLog X-Git-Tag: APACHE_2_0_ALPHA_4~53 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=822f0dc1437dcbdb1258967923712dd2f14ce178;p=apache mod_cgi: Restore logging of stderr from child process when ScriptLog isn't used (as in 1.3), except that on Unix it is now logged via ap_log_rerror() instead of by the child having STDERR_FILENO refer to the error log. Submitted by: Greg Ames Reviewed by: Jeff Trawick git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85331 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index 4ab25957c3..e2297f876d 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -202,6 +202,23 @@ static int log_scripterror(request_rec *r, cgi_server_conf * conf, int ret, return ret; } +/* Soak up stderr from a script and redirect it to the error log. + */ +static void log_script_err(request_rec *r, BUFF *script_err) +{ + char argsbuffer[HUGE_STRING_LEN]; + char *newline; + + while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { + newline = strchr(argsbuffer, '\n'); + if (newline) { + *newline = '\0'; + } + ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, + "%s", argsbuffer); + } +} + static int log_script(request_rec *r, cgi_server_conf * conf, int ret, char *dbuf, const char *sbuf, BUFF *script_in, BUFF *script_err) { @@ -221,19 +238,8 @@ static int log_script(request_rec *r, cgi_server_conf * conf, int ret, /* Soak up script output */ while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0) continue; -#ifdef WIN32 - /* Soak up stderr and redirect it to the error log. - * Script output to stderr is already directed to the error log - * on Unix, thanks to the magic of fork(). - */ - while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { - ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, - "%s", argsbuffer); - } -#else - while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) - continue; -#endif + + log_script_err(r, script_err); return ret; } @@ -606,9 +612,7 @@ static int cgi_handler(request_rec *r) while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0) { continue; } - while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { - continue; - } + log_script_err(r, script_err); /* This redirect needs to be a GET no matter what the original * method was. */ @@ -637,9 +641,7 @@ static int cgi_handler(request_rec *r) } ap_bclose(script_in); - while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { - continue; - } + log_script_err(r, script_err); ap_bclose(script_err); }