Skip to content

Commit

Permalink
Merge branch 'release/4.6.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Jun 7, 2019
2 parents 8f29230 + 34fbcae commit e2209cf
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 82 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# General information about the project.
project = u'mod_wsgi'
copyright = u'2007-2018, Graham Dumpleton'
copyright = u'2007-2019, Graham Dumpleton'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
6 changes: 3 additions & 3 deletions docs/configuration-directives/WSGIDaemonProcess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ Options which can be supplied to the ``WSGIDaemonProcess`` directive are:
Note that the directory specified must exist and be writable by the
user that the daemon process run as.

**restart-interval=nnn**
Defines a time limit on how long a daemon process should run before
being restarted.
**restart-interval=sss**
Defines a time limit in seconds for how long a daemon process should
run before being restarted.

This might be use to periodically force restart the WSGI application
processes when you have issues related to Python object reference count
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release Notes
.. toctree::
:maxdepth: 2

release-notes/version-4.6.6
release-notes/version-4.6.5
release-notes/version-4.6.4
release-notes/version-4.6.3
Expand Down
28 changes: 28 additions & 0 deletions docs/release-notes/version-4.6.6.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
=============
Version 4.6.6
=============

Version 4.6.6 of mod_wsgi can be obtained from:

https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/4.6.6

Bugs Fixed
----------

* Fix compilation failures when using Python 3.8.

Features Changed
----------------

* When running ``mod_wsgi-express`` it will do a search for the location of
``bash`` and ``sh`` when defining the shell to use for the generated
``apachectl``. The shell used can be overridden using ``--shell-executable``
option. This is to get around issue with FreeBSD not having ``/bin/bash``.

New Features
------------

* The Apache request ID is accessible in request events as ``request_id``.

* The per request data dictionary accessible using ``mod_wsgi.request_data()``
is now also accessible in events as ``request_data``.
12 changes: 9 additions & 3 deletions src/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ def find_mimetypes():
for name in mimetypes.knownfiles:
if os.path.exists(name):
return name
break
else:
return '/dev/null'

SHELL = find_program(['bash', 'sh'], ['/usr/local/bin'])

APACHE_GENERAL_CONFIG = """
<IfModule !version_module>
LoadModule version_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_version.so'
Expand Down Expand Up @@ -1513,7 +1514,7 @@ def __init__(self, resources):
self.resources = {}

for extension, script in resources:
extension_name = re.sub('[^\w]{1}', '_', extension)
extension_name = re.sub(r'[^\w]{1}', '_', extension)
module_name = '__wsgi_resource%s__' % extension_name
module = imp.new_module(module_name)
module.__file__ = script
Expand Down Expand Up @@ -1758,7 +1759,7 @@ def generate_server_metrics_script(options):
print(SERVER_METRICS_SCRIPT % options, file=fp)

WSGI_CONTROL_SCRIPT = """
#!/bin/bash
#!%(shell_executable)s
# %(sys_argv)s
Expand Down Expand Up @@ -2465,6 +2466,11 @@ def check_percentage(option, opt_str, value, parser):
'unpacking of Python eggs. Defaults to a sub directory of '
'the server root directory.'),

optparse.make_option('--shell-executable', default=SHELL,
metavar='FILE-PATH', help='Override the path to the shell '
'used in the \'apachectl\' script. The \'bash\' shell will '
'be used if available.'),

optparse.make_option('--httpd-executable', default=apxs_config.HTTPD,
metavar='FILE-PATH', help='Override the path to the Apache web '
'server executable.'),
Expand Down
99 changes: 75 additions & 24 deletions src/server/mod_wsgi.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2063,8 +2063,6 @@ static PyObject *Adapter_start_response(AdapterObject *self, PyObject *args)
PyObject *status_line_as_bytes = NULL;
PyObject *headers_as_bytes = NULL;

PyObject *event = NULL;

if (!self->r) {
PyErr_SetString(PyExc_RuntimeError, "request object has expired");
return NULL;
Expand Down Expand Up @@ -2110,17 +2108,31 @@ static PyObject *Adapter_start_response(AdapterObject *self, PyObject *args)
if (wsgi_event_subscribers()) {
WSGIThreadInfo *thread_info;

PyObject *event = NULL;
PyObject *value = NULL;

thread_info = wsgi_thread_info(0, 0);

event = PyDict_New();

#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
if (self->r->log_id) {
#if PY_MAJOR_VERSION >= 3
value = PyUnicode_DecodeLatin1(self->r->log_id,
strlen(self->r->log_id), NULL);
#else
value = PyString_FromString(self->r->log_id);
#endif
PyDict_SetItemString(event, "request_id", value);
Py_DECREF(value);
}
#endif

PyDict_SetItemString(event, "response_status", status_line);
PyDict_SetItemString(event, "response_headers", headers);
PyDict_SetItemString(event, "exception_info", exc_info);

#if 0
PyDict_SetItemString(event, "request_data", thread_info->request_data);
#endif

wsgi_publish_event("response_started", event);

Expand Down Expand Up @@ -3093,6 +3105,19 @@ static int Adapter_run(AdapterObject *self, PyObject *object)

event = PyDict_New();

#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
if (self->r->log_id) {
#if PY_MAJOR_VERSION >= 3
value = PyUnicode_DecodeLatin1(self->r->log_id,
strlen(self->r->log_id), NULL);
#else
value = PyString_FromString(self->r->log_id);
#endif
PyDict_SetItemString(event, "request_id", value);
Py_DECREF(value);
}
#endif

value = wsgi_PyInt_FromLong(thread_handle->thread_id);
PyDict_SetItemString(event, "thread_id", value);
Py_DECREF(value);
Expand Down Expand Up @@ -3128,9 +3153,7 @@ static int Adapter_run(AdapterObject *self, PyObject *object)
PyDict_SetItemString(event, "application_start", value);
Py_DECREF(value);

#if 0
PyDict_SetItemString(event, "request_data", thread_handle->request_data);
#endif

wsgi_publish_event("request_started", event);

Expand Down Expand Up @@ -3299,6 +3322,19 @@ static int Adapter_run(AdapterObject *self, PyObject *object)

event = PyDict_New();

#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
if (self->r->log_id) {
#if PY_MAJOR_VERSION >= 3
value = PyUnicode_DecodeLatin1(self->r->log_id,
strlen(self->r->log_id), NULL);
#else
value = PyString_FromString(self->r->log_id);
#endif
PyDict_SetItemString(event, "request_id", value);
Py_DECREF(value);
}
#endif

value = wsgi_PyInt_FromLongLong(self->input->reads);
PyDict_SetItemString(event, "input_reads", value);
Py_DECREF(value);
Expand Down Expand Up @@ -3378,9 +3414,7 @@ static int Adapter_run(AdapterObject *self, PyObject *object)
PyDict_SetItemString(event, "application_time", value);
Py_DECREF(value);

#if 0
PyDict_SetItemString(event, "request_data", thread_handle->request_data);
#endif

wsgi_publish_event("request_finished", event);

Expand Down Expand Up @@ -4345,8 +4379,13 @@ static void wsgi_python_child_init(apr_pool_t *p)
* do it if Python was initialised in parent process.
*/

if (wsgi_python_initialized && !wsgi_python_after_fork)
if (wsgi_python_initialized && !wsgi_python_after_fork) {
#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7)
PyOS_AfterFork_Child();
#else
PyOS_AfterFork();
#endif
}

/* Finalise any Python objects required by child process. */

Expand Down Expand Up @@ -6344,15 +6383,12 @@ static void wsgi_build_environment(request_rec *r)
apr_psprintf(r->pool, "%" APR_TIME_T_FMT, r->request_time));

#if AP_MODULE_MAGIC_AT_LEAST(20100923,2)
if (!r->log_id || !r->connection->log_id) {
if (!r->log_id) {
const char **id;

/* Need to cast const away. */

if (r)
id = &((request_rec *)r)->log_id;
else
id = &((conn_rec *)c)->log_id;
id = &((request_rec *)r)->log_id;

ap_run_generate_log_id(c, r, id);
}
Expand Down Expand Up @@ -8510,6 +8546,9 @@ static int wsgi_setup_socket(WSGIProcessGroup *process)
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, wsgi_server,
"mod_wsgi (pid=%d): Couldn't bind unix domain "
"socket '%s'.", getpid(), process->socket_path);

close(sockfd);

return -1;
}

Expand All @@ -8521,6 +8560,9 @@ static int wsgi_setup_socket(WSGIProcessGroup *process)
ap_log_error(APLOG_MARK, APLOG_ALERT, errno, wsgi_server,
"mod_wsgi (pid=%d): Couldn't listen on unix domain "
"socket.", getpid());

close(sockfd);

return -1;
}

Expand Down Expand Up @@ -8555,6 +8597,9 @@ static int wsgi_setup_socket(WSGIProcessGroup *process)
"mod_wsgi (pid=%d): Couldn't change owner of unix "
"domain socket '%s' to uid=%ld.", getpid(),
process->socket_path, (long)socket_uid);

close(sockfd);

return -1;
}
}
Expand Down Expand Up @@ -9441,8 +9486,8 @@ static void wsgi_log_stack_traces(void)
while (current) {
int lineno;

char *filename = NULL;
char *name = NULL;
const char *filename = NULL;
const char *name = NULL;

if (current->f_trace) {
lineno = current->f_lineno;
Expand Down Expand Up @@ -10422,6 +10467,12 @@ static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon)
wsgi_exit_daemon_process(0);
}

if (wsgi_python_initialized) {
#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7)
PyOS_AfterFork_Parent();
#endif
}

apr_pool_note_subprocess(p, &daemon->process, APR_KILL_AFTER_TIMEOUT);
apr_proc_other_child_register(&daemon->process, wsgi_manage_process,
daemon, NULL, p);
Expand Down Expand Up @@ -13338,8 +13389,10 @@ static void wsgi_hook_child_init(apr_pool_t *p, server_rec *s)
for (i = 0; i < wsgi_daemon_list->nelts; ++i) {
entry = &entries[i];

close(entry->listener_fd);
entry->listener_fd = -1;
if (entry->listener_fd != -1) {
close(entry->listener_fd);
entry->listener_fd = -1;
}
}
}
#endif
Expand Down Expand Up @@ -13751,8 +13804,8 @@ static void wsgi_process_proxy_headers(request_rec *r)

if (trusted_proxy) {
for (i=0; i<trusted_proxy_headers->nelts; i++) {
const char *name = NULL;
const char *value = NULL;
const char *name;
const char *value;

name = ((const char**)trusted_proxy_headers->elts)[i];
value = apr_table_get(r->subprocess_env, name);
Expand Down Expand Up @@ -13879,11 +13932,9 @@ static void wsgi_process_proxy_headers(request_rec *r)
*/

for (i=0; i<trusted_proxy_headers->nelts; i++) {
const char *name = NULL;
const char *value = NULL;
const char *name;

name = ((const char**)trusted_proxy_headers->elts)[i];
value = apr_table_get(r->subprocess_env, name);

if (!strcmp(name, "HTTP_X_FORWARDED_FOR") ||
!strcmp(name, "HTTP_X_REAL_IP")) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_apache.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_apache.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_buckets.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_convert.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/server/wsgi_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* ------------------------------------------------------------------------- */

/*
* Copyright 2007-2018 GRAHAM DUMPLETON
* Copyright 2007-2019 GRAHAM DUMPLETON
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit e2209cf

Please sign in to comment.