httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject Re: [PATCH] log stderr output from cgi's in 2.0
Date Fri, 19 May 2000 11:48:32 GMT
> Sender: greg@raleigh.ibm.com
> Date: Thu, 18 May 2000 16:27:34 -0400
> From: Greg Ames <gregames@raleigh.ibm.com>

> I didn't follow how this worked in 1.3 .   It behaves as if the cgi
> child's stderr was just inherited from the parent, but I do see similar
> pipe creation and dup2 stuff which should replace the inherited file.
> In any case, the raw stderr output appears in the 1.3 log without any
> formatting.  With this patch, we get the formatting added by
> ap_log_rerror (and some extra blank lines?!?) in addition to the raw
> stderror output:

The extra blank lines come because ap_log_rerror() (actually
log_error_core() which it calls) adds a '\n'.  If we keep the
ap_log_rerror() approach, then we can trim the '\n' before calling
ap_log_rerror().

> 
> [Thu May 18 15:55:00 2000] [error] [client 127.0.0.1] Premature end of
> script headers: /two/cgi-bin/junk-cgi
> [Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
> /two/cgi-bin/junk-cgi: junk: command not found
> 
> [Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
> /two/cgi-bin/junk-cgi: morejunk: command not found
> 
> [Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
> /two/cgi-bin/junk-cgi: yetmorejunk: command not found
> 
> Another approach would be to just let the cgi child inherit the parent's
> stderr and not bother with the pipe.

That would be cool too as in 1.3, but

1) different code than Win32 (maybe that is goodness?)
2) we lose the helpful prefix on the message (date/time, client info)
3) even though it is slower, we shouldn't care because this isn't
   mainline path

My only confusion at this point is why doesn't the code already remove
a trailing '\n'...  I guess it was a bug...

> 
> Greg Ames
> Index: apache-2.0/src/modules/standard/mod_cgi.c
> ===================================================================
> RCS file: /cvs/apache/apache-2.0/src/modules/standard/mod_cgi.c,v
> retrieving revision 1.37
> diff -u -d -b -w -r1.37 mod_cgi.c
> --- mod_cgi.c	2000/05/16 20:19:29	1.37
> +++ mod_cgi.c	2000/05/18 19:48:12
> @@ -221,19 +221,12 @@
>  	/* 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().
> -         */
> +
> +        /* Soak up stderr and redirect it to the error log. */
>          while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) {

----->         const char *newline = strchr(argsbuffer, '\n');

----->         if (newline) {
----->             *newline = '\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
>  	return ret;
>      }
>  
 -=- MIME -=- 
This is a multi-part message in MIME format.
--------------A4301FECB5FC1E43956905A0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The stderr output from cgi's isn't being logged on Unix in 2.0.  After
we fork, we use dup2 to replace the stderr inherited from the parent
with a pipe.  Back in run_cgi_child in mod_cgi.c, we read from the
parent's end of the stderr pipe but don't do anything with the output.
This patch uses the same logic as Windows to log the stderr output.

I didn't follow how this worked in 1.3 .   It behaves as if the cgi
child's stderr was just inherited from the parent, but I do see similar
pipe creation and dup2 stuff which should replace the inherited file.
In any case, the raw stderr output appears in the 1.3 log without any
formatting.  With this patch, we get the formatting added by
ap_log_rerror (and some extra blank lines?!?) in addition to the raw
stderror output:

[Thu May 18 15:55:00 2000] [error] [client 127.0.0.1] Premature end of
script headers: /two/cgi-bin/junk-cgi
[Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
/two/cgi-bin/junk-cgi: junk: command not found

[Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
/two/cgi-bin/junk-cgi: morejunk: command not found

[Thu May 18 15:55:00 2000] [error] [client 127.0.0.1]
/two/cgi-bin/junk-cgi: yetmorejunk: command not found

Another approach would be to just let the cgi child inherit the parent's
stderr and not bother with the pipe.

Greg Ames

--------------A4301FECB5FC1E43956905A0
Content-Type: text/plain; charset=us-ascii;
 name="script_err.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="script_err.patch"

Index: apache-2.0/src/modules/standard/mod_cgi.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/modules/standard/mod_cgi.c,v
retrieving revision 1.37
diff -u -d -b -w -r1.37 mod_cgi.c
--- mod_cgi.c	2000/05/16 20:19:29	1.37
+++ mod_cgi.c	2000/05/18 19:48:12
@@ -221,19 +221,12 @@
 	/* 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().
-         */
+
+        /* Soak up stderr and redirect it to the error log. */
         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
 	return ret;
     }
 

--------------A4301FECB5FC1E43956905A0--




-- 
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