Bug 14090

Summary: mod_cgid always writes to main server error log
Product: Apache httpd-2 Reporter: Sergey Polyakov <alexei>
Component: mod_cgidAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED LATER    
Severity: major CC: dhgutteridge, golden_moon_rising, matrix, pedietz, rob
Priority: P3    
Version: 2.0.43   
Target Milestone: ---   
Hardware: Other   
OS: Linux   

Description Sergey Polyakov 2002-10-30 14:04:44 UTC
I'm in the process of upgrading from Apache 1.3.27 to Apache 2.0.43 
with 'worker' scheme.  I've
noticed that if I specify a virtual host ErrorLog location, STDERR from my
Perl CGI programs is still directed to the default server error log file.
The key parts of my httpd.conf appear as follows:

ServerRoot "/opt/apache2"

ErrorLog logs/error_log

NameVirtualHost *

<VirtualHost *>
DocumentRoot /local/httpd/mmitest/htdocs
ServerName mmitest.mmi.frco.com
ServerAlias mmitest
ErrorLog /local/httpd/mmitest/logs/error_log
TransferLog /local/httpd/mmitest/logs/access_log
ScriptAlias /cgi-bin/ /local/httpd/mmitest/cgi-bin/
</VirtualHost>

If I access a cgi program on this virtual host that writes to STDERR, it
writes to the server default ErrorLog location
(/opt/apache2/logs/error_log), not the ErrorLog location specified in the
virtual host (/local/httpd/mmitest/logs/error_log).
Comment 1 Jeff Trawick 2003-02-12 19:09:28 UTC
Can you verify that you're using mod_cgid instead of mod_cgi?

It works for me with mod_cgi, fails as you describe for me with mod_cgid.

Thanks,

Jeff
Comment 2 Jeff Trawick 2003-10-10 13:10:34 UTC
*** Bug 22672 has been marked as a duplicate of this bug. ***
Comment 3 Neo 2003-11-17 07:53:08 UTC
Bug still exist in 2.4.08
Comment 4 Neo 2003-11-17 07:54:17 UTC
Typo earlier on 2.0.48
Comment 5 Paul Querna 2004-09-17 04:08:41 UTC
*** Bug 15926 has been marked as a duplicate of this bug. ***
Comment 6 Phil Dietz 2004-09-17 06:28:19 UTC
What ??

I dont know how my bug report got lumped into this one.

My report is about the contents of the ScriptLog....

If a cgi app emits to stderr....
aka 


puts stderr "hello world"


Mod_cgi's ScriptLog will catch that informations....
while mod_cgisd's ScriptLog will not!!!!

Please fix!
Comment 7 Paul Querna 2004-09-17 06:39:57 UTC
To fix, they would both involve a refactoring of how mod_cgid does its loging.
That is why I marked them as a duplicate.
Comment 8 Jeff Trawick 2005-07-12 21:44:23 UTC
*** Bug 35708 has been marked as a duplicate of this bug. ***
Comment 9 Ruediger Pluem 2006-02-28 21:15:33 UTC
*** Bug 38398 has been marked as a duplicate of this bug. ***
Comment 10 David H. Gutteridge 2006-03-01 19:42:22 UTC
Since comments #6 and #7 indicate general mod_cgid logging issues are being
recorded here, I have another one to add.  When writing to stderr and mod_cgi is
used, the error log includes the usual information specified for the output
format (e.g. time stamp, client IP address) before the output from the script,
but when doing the same through mod_cgid, it does not seem to include this
information, meaning the CGI stderr output is without a specific identifying
context.  (This is with 2.0.55 on NetBSD 3.0/i386, mod_cgi with the prefork MPM
and mod_cgid with the worker MPM.)

So with mod_cgi, we get (first row included for visual context):

[Tue Feb 28 05:34:28 2006] [error] [client 192.168.1.5] mod_mime_magic: can't
read `/usr/pkg/libexec/cgi-bin/errtest.cgi'
[Tue Feb 28 05:34:28 2006] [error] [client 192.168.1.5] This should be going to
the Apache error log.

And with mod_cgid, we get:

[Tue Feb 28 06:09:36 2006] [error] [client 192.168.1.5] mod_mime_magic: can't
read `/usr/pkg/libexec/cgi-bin/errtest.cgi'
This should be going to the Apache error log.

Comment 11 David H. Gutteridge 2006-03-06 21:31:31 UTC
(Addendum to comment #10:) I've looked at the code for mod_cgid and see that the
Apache developers are aware of this, mod_cgid apparently doesn't have the
requisite information available to it.
Comment 12 Artem Kuchin 2007-10-16 10:56:21 UTC
I have just tested it on 2.2.6 and this bug is still present. Why is it marked
as RESOLVED?


Comment 13 Franz-Josef Huecker 2015-05-10 08:03:36 UTC
(In reply to Artem Kuchin from comment #12)
> I have just tested it on 2.2.6 and this bug is still present. Why is it
> marked
> as RESOLVED?

I've just tested it with 2.4.7 and the bug is still present. 

But there are a simple way to fix it: disable mpm_event, enable cgi, enable mpm_event, and it works.
Comment 14 wick 2017-03-17 15:05:53 UTC
(In reply to Franz-Josef Huecker from comment #13)
> 
> I've just tested it with 2.4.7 and the bug is still present. 
> 
> But there are a simple way to fix it: disable mpm_event, enable cgi, enable
> mpm_event, and it works.

Sorry if this is a stupid question -- how exactly do you "disable mpm_event, enable cgi, enable mpm_event"?

I thought we could deal with the main error logging, but since the mod_cgid error logging does not including timestamps, on a very busy web server that hosts multiple domains, it's proven to be 99.9999% useless so far.
Comment 15 Eric Covener 2017-03-17 18:20:22 UTC
(In reply to wick from comment #14)
> (In reply to Franz-Josef Huecker from comment #13)
> > 
> > I've just tested it with 2.4.7 and the bug is still present. 
> > 
> > But there are a simple way to fix it: disable mpm_event, enable cgi, enable
> > mpm_event, and it works.
> 
> Sorry if this is a stupid question -- how exactly do you "disable mpm_event,
> enable cgi, enable mpm_event"?

I think this refers to some specific packaging loophole that would result in mod_cgi being used w/ event MPM,  instead of mod_cgid which is normally used with all threaded MPMs like event.
Comment 16 bna 2019-08-23 11:45:17 UTC
(In reply to Franz-Josef Huecker from comment #13)
> (In reply to Artem Kuchin from comment #12)
> > I have just tested it on 2.2.6 and this bug is still present. Why is it
> > marked
> > as RESOLVED?
> 
> I've just tested it with 2.4.7 and the bug is still present. 
> 
> But there are a simple way to fix it: disable mpm_event, enable cgi, enable
> mpm_event, and it works.

Thanks!

I spent several hours to understand what was going on until I could find this report.

Yes, I admit that I missed the line "Your MPM seems to be threaded. Selecting cgid instead of cgi."

I believe that in this case it is necessary to give an error message, and not enable another module (cgid instead cgi)

Is there an easy way in 2019 to write the error logs of each virtual host to the file specified in the virtual host configuration with mpm_event and cgid?

The not working way:
# a2dismod cgid
Module cgid disabled.

# a2enmod cgi
Your MPM seems to be threaded. Selecting cgid instead of cgi.
Enabling module cgid.


The working way:
# a2dismod mpm_event 
Module mpm_event disabled.

# a2dismod cgid
Module cgid disabled.

# a2enmod cgi
AH00534: apache2: Configuration error: No MPM loaded.
ERROR: Can't determine enabled MPMEnabling module cgi.
*Missing newline character in error message*

# a2enmod mpm_event 
Considering conflict mpm_worker for mpm_event:
Considering conflict mpm_prefork for mpm_event:
Enabling module mpm_event.

# apache2ctl -V
Server version: Apache/2.4.38 (Debian)
Server built:   2019-04-07T18:15:40
Server's Module Magic Number: 20120211:84
Server loaded:  APR 1.6.5, APR-UTIL 1.6.1
Compiled using: APR 1.6.5, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"
Comment 17 Rainer Jung 2019-08-23 18:11:34 UTC
Look here for a sugested patch by Joe Orton:

https://marc.info/?l=apache-httpd-dev&m=156337168604935&w=2

The patch is available for testing under

http://people.apache.org/~jorton/httpd-2.4.x-cgid-fdpassing.patch

but the mail thread contains more details.

If it works well for you please report back here or to the httpd dev mailing list.

Thanks and regards,

Rainer