Skip to content

Commit ba085e9

Browse files
Fix daemon processes logging to wrong virtual host error log.
In daemon mode, output to wsgi.errors, sys.stdout and sys.stderr could be written to the main server ErrorLog instead of the ErrorLog of the VirtualHost handling the request. The daemon maps each proxied request back to the correct server using listener address details sent by the Apache child worker, but that code was guarded by MOD_WSGI_WITH_DAEMONS, which the 6.0.0 code restructuring left undefined in wsgi_environ.c by moving its definition into the daemon specific wsgi_daemon.h. The guarded code was silently compiled out and no listener details were sent. Move the MOD_WSGI_WITH_DAEMONS definition into the common wsgi_apache.h so it is visible to every translation unit.
1 parent 9569091 commit ba085e9

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

docs/release-notes/version-6.0.1.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ Bugs Fixed
3535
that variable is only declared when daemon mode is available, which is
3636
never the case on Windows. The reference is now protected by the
3737
appropriate conditional.
38+
39+
* When using daemon mode, output written to ``wsgi.errors`` (and anything
40+
sent to ``sys.stdout`` or ``sys.stderr``) could be written to the main
41+
server ``ErrorLog`` instead of the ``ErrorLog`` of the ``VirtualHost``
42+
actually handling the request. The daemon process maps each proxied
43+
request back to the correct server using listener address details
44+
supplied by the Apache child worker, but the code which populated those
45+
details was guarded by ``MOD_WSGI_WITH_DAEMONS``, and that symbol was not
46+
defined in the relevant source file, so the guarded code was silently
47+
compiled out and no listener details were sent. This was introduced by
48+
the 6.0.0 code restructuring, which moved the definition of
49+
``MOD_WSGI_WITH_DAEMONS`` into a daemon specific header that the affected
50+
source file did not include. The definition has been moved to a common
51+
header visible to all source files.

src/server/wsgi_apache.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup, (apr_pool_t *, server_rec *, con
7676
#include "util_md5.h"
7777
#include "scoreboard.h"
7878

79+
/* ------------------------------------------------------------------------- */
80+
81+
/*
82+
* Whether mod_wsgi is built with support for separate daemon processes
83+
* (WSGIDaemonProcess). This requires fork() and APR other-child support
84+
* and is never available on Windows.
85+
*
86+
* Defined here in the common Apache header, rather than in the daemon
87+
* specific wsgi_daemon.h, so that every translation unit which
88+
* conditionally compiles daemon mode code sees a consistent value
89+
* without having to include the daemon API header. When this is not
90+
* visible the guarded code is silently compiled out rather than failing
91+
* to build.
92+
*/
93+
94+
#ifndef WIN32
95+
#if APR_HAS_OTHER_CHILD && APR_HAS_FORK
96+
#define MOD_WSGI_WITH_DAEMONS 1
97+
#endif
98+
#endif
99+
79100
APLOG_USE_MODULE(wsgi);
80101

81102
#if defined(WIN32) && defined(APR_HAS_UNICODE_FS)

src/server/wsgi_daemon.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929

3030
extern char *wsgi_shutdown_reason;
3131

32-
#ifndef WIN32
33-
#if APR_HAS_OTHER_CHILD && APR_HAS_FORK
34-
#define MOD_WSGI_WITH_DAEMONS 1
35-
#endif
36-
#endif
37-
3832
/*
3933
* Apache 2.X and UNIX specific definitions related to
4034
* distinct daemon processes.

0 commit comments

Comments
 (0)