Skip to content

Commit 7b55963

Browse files
Merge branch 'release/4.5.4'
2 parents a8c8c73 + 24f320e commit 7b55963

14 files changed

+342
-8
lines changed

docs/installation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ For instructions on how to compile mod_wsgi from source code for UNIX like
1818
operating systems such as Linux and MacOS X see:
1919

2020
* :doc:`user-guides/quick-installation-guide`
21+
* :doc:`user-guides/installation-on-macosx`
2122

2223
If you are on Windows, you should instead use:
2324

docs/release-notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release Notes
55
.. toctree::
66
:maxdepth: 2
77

8+
release-notes/version-4.5.4
89
release-notes/version-4.5.3
910
release-notes/version-4.5.2
1011
release-notes/version-4.5.1

docs/release-notes/version-4.5.4.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=============
2+
Version 4.5.4
3+
=============
4+
5+
Version 4.5.4 of mod_wsgi can be obtained from:
6+
7+
https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/4.5.4
8+
9+
Bugs Fixed
10+
----------
11+
12+
1. When using Apache 2.4 and daemon mode, the connection and request log
13+
IDs from the Apache child worker processes were not being copied across
14+
to the daemon process so that log messages generated against the request
15+
would use the same ID in logs when using the ``%L`` format modifier.
16+
17+
2. When using Apache 2.4 and daemon mode, the remote client port
18+
information was not being cached such that log messages generated
19+
against the request would use the port in logs when using the ``%a``
20+
format modifier.
21+
22+
Features Changed
23+
----------------
24+
25+
1. If ``sys.stdout`` and ``sys.stderr`` are used in the context of the
26+
thread handling a request, calls against them to log messages will be
27+
routed back via ``wsgi.errors`` from the per request WSGI ``environ``
28+
dictionary. This avoids the danger of logged messages from different
29+
request handlers being intermixed as buffering will now be done on a per
30+
request basis. Such messages will also be logged with the correct
31+
connection and request log ID if the ``%L`` formatter is used in the
32+
error log format.
33+
34+
New Features
35+
------------
36+
37+
1. Added new option ``--error-log-format`` to ``mod_wsgi-express`` to allow
38+
the error log message format to be specified.
39+
40+
2. Pass through to the WSGI per request ``environ`` dictionary new values
41+
for ``mod_wsgi.connection_id`` and ``mod_wsgi.request_id``. These are
42+
the Apache log IDs for the connection and request that it uses in log
43+
messages when using the ``%L`` format modifier. This only applies to
44+
Apache 2.4 and later.

docs/user-guides.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ User Guides
66
:maxdepth: 1
77

88
user-guides/quick-installation-guide
9+
user-guides/installation-on-macosx
910
user-guides/quick-configuration-guide
1011
user-guides/configuration-guidelines
1112
user-guides/installation-issues
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
=======================
2+
Installation On MacOS X
3+
=======================
4+
5+
If you are using MacOS X, mod_wsgi can be compiled from source code
6+
against the standard versions of Python and Apache httpd server supplied
7+
with the operating system. To do this though you will first need to have
8+
installed the Xcode command line tools.
9+
10+
The Xcode command line tools package provides a C compiler, along with
11+
header files and support tools for the Apache httpd server. If you have
12+
already set up your system so as to be able to install additional Python
13+
packages which include C extensions, you likely will already have the
14+
Xcode command line tools.
15+
16+
Install Xcode command line tools
17+
--------------------------------
18+
19+
To install the Xcode command line tools you should run the command::
20+
21+
xcode-select --install
22+
23+
If this gives you back the error message::
24+
25+
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
26+
27+
then the tools have already been installed. As noted by the warning
28+
message, do make sure you have run a system software update to ensure
29+
that you have the latest versions of these tools.
30+
31+
If you do not already have the Xcode command line tools installed, running
32+
that ``xcode-select`` command should result in you being prompted to
33+
install them. This may ask you to provide the details of an administrator
34+
account along with the password for that account.
35+
36+
Note that it is not necessary to install the whole of the Xcode
37+
developer application from the MacOS X App Store, only the command line
38+
tools using ``xcode-select``. If you have installed the Xcode developer
39+
application, still ensure that the command line tools are installed and
40+
ensure you have run the system software update.
41+
42+
Configuring and building mod_wsgi
43+
---------------------------------
44+
45+
If you are using the Python and Apache httpd server packages provided with
46+
the operating system, all you need to do to configure the mod_wsgi source
47+
code before building it is to run in the mod_wsgi source code directory::
48+
49+
./configure
50+
51+
This should yield output similar to::
52+
53+
checking for apxs2... no
54+
checking for apxs... /usr/sbin/apxs
55+
checking for gcc... gcc
56+
checking whether the C compiler works... yes
57+
checking for C compiler default output file name... a.out
58+
checking for suffix of executables...
59+
checking whether we are cross compiling... no
60+
checking for suffix of object files... o
61+
checking whether we are using the GNU C compiler... yes
62+
checking whether gcc accepts -g... yes
63+
checking for gcc option to accept ISO C89... none needed
64+
checking for prctl... no
65+
checking Apache version... 2.4.18
66+
checking for python... /usr/bin/python
67+
configure: creating ./config.status
68+
config.status: creating Makefile
69+
70+
The ``configure`` script should show that it has detected ``apxs`` as being
71+
located at ``/usr/sbin/apxs`` and ``python`` as being at ``/usr/bin/python``.
72+
73+
If you get different values for ``apxs`` and ``python`` then it means
74+
that you likely have a separate installation of Python or the Apache
75+
httpd server installed on your system. If this is the case, to ensure that
76+
you use the versions of Python and Apache httpd server provided with the
77+
operating system instead use the command::
78+
79+
./configure --with-python=/usr/bin/python --with-apxs=/usr/sbin/apxs
80+
81+
Once you have configured the source code by running ``configure``, you
82+
can build mod_wsgi using the command::
83+
84+
make
85+
86+
This will compile the mod_wsgi source code and produce a single
87+
``mod_wsgi.so`` file which then needs to be installed into a common
88+
location so that the Apache httpd server can use it.
89+
90+
Installing the mod_wsgi module
91+
------------------------------
92+
93+
What you need to do to install the mod_wsgi module depends on which version
94+
of MacOS X you are using.
95+
96+
For the Apache httpd server provided by the operating system, the directory
97+
``/usr/libexec/apache2`` is used to store the compiled modules. Prior to
98+
MacOS X El Capitan (10.11) this directory was writable and the mod_wsgi
99+
module could be installed here along with all the default modules. With the
100+
introduction of the System Integrity Protection (SIP_) feature in MacOS X
101+
El Capitan this directory is not writable, not even to the root user.
102+
103+
Because of this, if you are using a version of MacOS X prior to MacOS X El
104+
Capitan (10.11) you can use the command::
105+
106+
sudo make install
107+
108+
to install the mod_wsgi module. As ``sudo`` is being run, you will be
109+
prompted for your password. The module will be installed into the
110+
directory ``/usr/libexec/apache2``. Within the Apache httpd server
111+
configuration file you can then use the standard ``LoadModule`` line
112+
of::
113+
114+
LoadModule wsgi_module libexec/apache2/mod_wsgi.so
115+
116+
If however you are using MacOS X El Capitan (10.11) or later, the mod_wsgi
117+
module will need to be installed into a different location. If you don't
118+
and try to run just ``sudo make install``, it will fail with the output::
119+
120+
./apxs -i -S LIBEXECDIR=/usr/libexec/apache2 -n 'mod_wsgi' src/server/mod_wsgi.la
121+
/usr/share/httpd/build/instdso.sh SH_LIBTOOL='./libtool' src/server/mod_wsgi.la /usr/libexec/apache2
122+
./libtool --mode=install install src/server/mod_wsgi.la /usr/libexec/apache2/
123+
libtool: install: install src/server/.libs/mod_wsgi.so /usr/libexec/apache2/mod_wsgi.so
124+
install: /usr/libexec/apache2/mod_wsgi.so: Operation not permitted
125+
apxs:Error: Command failed with rc=4653056
126+
.
127+
make: *** [install] Error 1
128+
129+
The directory you use to install the mod_wsgi module is up to you, but
130+
one suggested option is that you use the directory
131+
``/usr/local/httpd/modules``. Just ensure that this isn't already used
132+
by a separate installation of the Apache httpd server.
133+
134+
To install the mod_wsgi module into this directory use the command::
135+
136+
sudo make install LIBEXECDIR=/usr/local/httpd/modules
137+
138+
The output from the command will be similar to::
139+
140+
mkdir -p /usr/local/httpd/modules
141+
./apxs -i -S LIBEXECDIR=/usr/local/httpd/modules -n 'mod_wsgi' src/server/mod_wsgi.la
142+
/usr/share/httpd/build/instdso.sh SH_LIBTOOL='./libtool' src/server/mod_wsgi.la /usr/local/httpd/modules
143+
./libtool --mode=install install src/server/mod_wsgi.la /usr/local/httpd/modules/
144+
libtool: install: install src/server/.libs/mod_wsgi.so /usr/local/httpd/modules/mod_wsgi.so
145+
libtool: install: install src/server/.libs/mod_wsgi.lai /usr/local/httpd/modules/mod_wsgi.la
146+
libtool: install: install src/server/.libs/mod_wsgi.a /usr/local/httpd/modules/mod_wsgi.a
147+
libtool: install: chmod 644 /usr/local/httpd/modules/mod_wsgi.a
148+
libtool: install: ranlib /usr/local/httpd/modules/mod_wsgi.a
149+
libtool: install: warning: remember to run `libtool --finish /usr/libexec/apache2'
150+
chmod 755 /usr/local/httpd/modules/mod_wsgi.so
151+
152+
The warning about needing to run ``libtool --finish`` can be ignored as it
153+
is not required for everything to work.
154+
155+
With the mod_wsgi module installed in this location, the ``LoadModule`` line
156+
in the Apache httpd configuration file should be::
157+
158+
LoadModule wsgi_module /usr/local/httpd/modules/mod_wsgi.so
159+
160+
Normal steps to then configure the Apache httpd server and mod_wsgi for
161+
your specific WSGI application would then be followed.
162+
163+
.. _SIP: https://en.wikipedia.org/wiki/System_Integrity_Protection

src/server/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ def find_mimetypes():
394394
</IfDefine>
395395
LogLevel %(log_level)s
396396
397+
<IfDefine MOD_WSGI_ERROR_LOG_FORMAT>
398+
ErrorLogFormat "%(error_log_format)s"
399+
</IfDefine>
400+
397401
<IfDefine MOD_WSGI_ACCESS_LOG>
398402
<IfModule !log_config_module>
399403
LoadModule log_config_module ${MOD_WSGI_MODULES_DIRECTORY}/mod_log_config.so
@@ -2257,6 +2261,8 @@ def check_percentage(option, opt_str, value, parser):
22572261

22582262
optparse.make_option('--access-log-format', metavar='FORMAT',
22592263
help='Specify the format of the access log records.'),
2264+
optparse.make_option('--error-log-format', metavar='FORMAT',
2265+
help='Specify the format of the error log records.'),
22602266

22612267
optparse.make_option('--error-log-name', metavar='FILE-NAME',
22622268
default='error_log', help='Specify the name of the error '
@@ -2646,6 +2652,10 @@ def _cmd_setup_server(command, args, options):
26462652
options['access_log_format'] = options['access_log_format'].replace(
26472653
'\"', '\\"')
26482654

2655+
if options['error_log_format']:
2656+
options['error_log_format'] = options['error_log_format'].replace(
2657+
'\"', '\\"')
2658+
26492659
options['pid_file'] = ((options['pid_file'] and os.path.abspath(
26502660
options['pid_file'])) or os.path.join(options['server_root'],
26512661
'httpd.pid'))
@@ -3006,6 +3016,8 @@ def _cmd_setup_server(command, args, options):
30063016
options['httpd_arguments_list'].append('-DMOD_WSGI_DIRECTORY_INDEX')
30073017
if options['directory_listing']:
30083018
options['httpd_arguments_list'].append('-DMOD_WSGI_DIRECTORY_LISTING')
3019+
if options['error_log_format']:
3020+
options['httpd_arguments_list'].append('-DMOD_WSGI_ERROR_LOG_FORMAT')
30093021
if options['access_log']:
30103022
options['httpd_arguments_list'].append('-DMOD_WSGI_ACCESS_LOG')
30113023
if options['rotate_logs']:

src/server/mod_wsgi.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,6 +3749,8 @@ static int wsgi_execute_script(request_rec *r)
37493749

37503750
int status;
37513751

3752+
WSGIThreadInfo *thread_info = NULL;
3753+
37523754
/* Grab request configuration. */
37533755

37543756
config = (WSGIRequestConfig *)ap_get_module_config(r->request_config,
@@ -3958,7 +3960,7 @@ static int wsgi_execute_script(request_rec *r)
39583960

39593961
/* Setup metrics for start of request. */
39603962

3961-
wsgi_start_request();
3963+
thread_info = wsgi_start_request();
39623964

39633965
/* Load module if not already loaded. */
39643966

@@ -3995,6 +3997,9 @@ static int wsgi_execute_script(request_rec *r)
39953997
PyObject *method = NULL;
39963998
PyObject *args = NULL;
39973999

4000+
Py_INCREF(adapter->log);
4001+
thread_info->log = adapter->log;
4002+
39984003
Py_INCREF(object);
39994004
status = Adapter_run(adapter, object);
40004005
Py_DECREF(object);
@@ -4029,6 +4034,8 @@ static int wsgi_execute_script(request_rec *r)
40294034
Py_XDECREF(object);
40304035
Py_XDECREF(method);
40314036

4037+
Py_CLEAR(thread_info->log);
4038+
40324039
adapter->bb = NULL;
40334040
}
40344041

@@ -6053,6 +6060,27 @@ static void wsgi_build_environment(request_rec *r)
60536060

60546061
apr_table_setn(r->subprocess_env, "mod_wsgi.request_start",
60556062
apr_psprintf(r->pool, "%" APR_TIME_T_FMT, r->request_time));
6063+
6064+
#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
6065+
if (!r->log_id || !r->connection->log_id) {
6066+
const char **id;
6067+
6068+
/* Need to cast const away. */
6069+
6070+
if (r)
6071+
id = &((request_rec *)r)->log_id;
6072+
else
6073+
id = &((conn_rec *)c)->log_id;
6074+
6075+
ap_run_generate_log_id(c, r, id);
6076+
}
6077+
6078+
if (r->log_id)
6079+
apr_table_setn(r->subprocess_env, "mod_wsgi.request_id", r->log_id);
6080+
if (r->connection->log_id)
6081+
apr_table_setn(r->subprocess_env, "mod_wsgi.connection_id",
6082+
r->connection->log_id);
6083+
#endif
60566084
}
60576085

60586086
typedef struct {
@@ -12325,9 +12353,13 @@ static int wsgi_hook_daemon_handler(conn_rec *c)
1232512353
#if AP_MODULE_MAGIC_AT_LEAST(20111130,0)
1232612354
r->connection->client_ip = (char *)apr_table_get(r->subprocess_env,
1232712355
"REMOTE_ADDR");
12356+
r->connection->client_addr->port = atoi(apr_table_get(r->subprocess_env,
12357+
"REMOTE_PORT"));
1232812358
#else
1232912359
r->connection->remote_ip = (char *)apr_table_get(r->subprocess_env,
1233012360
"REMOTE_ADDR");
12361+
r->connection->remote_addr->port = atoi(apr_table_get(r->subprocess_env,
12362+
"REMOTE_PORT"));
1233112363
#endif
1233212364

1233312365
#if AP_MODULE_MAGIC_AT_LEAST(20111130,0)
@@ -12428,7 +12460,9 @@ static int wsgi_hook_daemon_handler(conn_rec *c)
1242812460
errno = 0;
1242912461
config->request_start = apr_strtoi64(item, (char **)&item, 10);
1243012462

12431-
if (!(!*item && errno != ERANGE))
12463+
if (!*item && errno != ERANGE)
12464+
r->request_time = config->request_start;
12465+
else
1243212466
config->request_start = 0.0;
1243312467
}
1243412468

@@ -12448,6 +12482,18 @@ static int wsgi_hook_daemon_handler(conn_rec *c)
1244812482
apr_psprintf(r->pool, "%" APR_TIME_T_FMT,
1244912483
config->daemon_start));
1245012484

12485+
#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
12486+
item = apr_table_get(r->subprocess_env, "mod_wsgi.request_id");
12487+
12488+
if (item)
12489+
r->log_id = item;
12490+
12491+
item = apr_table_get(r->subprocess_env, "mod_wsgi.connection_id");
12492+
12493+
if (item)
12494+
r->connection->log_id = item;
12495+
#endif
12496+
1245112497
/*
1245212498
* Install the standard HTTP input filter and set header for
1245312499
* chunked transfer encoding to force it to dechunk the input.

0 commit comments

Comments
 (0)