httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject [PATCH] another take at logging stderr output from cgi scripts in 2.0
Date Thu, 25 May 2000 01:32:14 GMT
This is very similar to what Greg Ames and I chatted about on the list
last week, except that a couple of other paths are covered.

It seems to us that stderr from cgis (mod_cgi) never goes to the error
log on 2.0 without this change.  It also seems to us that in 1.3,
there was code to set up the pipe for stderr to do something similar
to the 2.0 code but due to reasons we don't yet understand the output
still went to the error log (i.e., FILENO_STDERR in the cgi child
process was the error log instead of the stderr pipe being soaked up by
Apache).

This patch is more true to the 1.3 behavior of stderr output going to
the log than to what looks like code that intends to discard stderr
output.

Comments?

Index: src/modules/standard/mod_cgi.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/modules/standard/mod_cgi.c,v
retrieving revision 1.40
diff -u -r1.40 mod_cgi.c
--- mod_cgi.c	2000/05/24 00:15:08	1.40
+++ mod_cgi.c	2000/05/25 01:29:15
@@ -202,6 +202,23 @@
     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)
 {
@@ -220,20 +237,9 @@
                   APR_APPEND, APR_OS_DEFAULT, r->pool) != APR_SUCCESS)) {
 	/* 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 @@
 	    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 @@
 	}
 	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);
     }
 


-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message