various fixes from 0.9.5.2

This commit is contained in:
roberto@voldemort
2010-06-26 22:37:46 +02:00
parent 2877ba54de
commit b7edaa68c8
16 changed files with 168 additions and 89 deletions
+15 -1
View File
@@ -1,3 +1,17 @@
*** june 2010 ***
* 0.9.5.2 [20100626] *
- fixed a request parsing bug
- applied debian fixes
- fixed multiple interpreter sys.argv
- improved --chmod-socket
- fixed uid 0 SIGHUP
- updated nginx and apache modules
- updated PSGI, lua and example plugin
- fixed --pyargv with python 3.x
- improved plugin build system
*** may 2010 ***
* 0.9.5.1 [20100519] *
@@ -24,7 +38,7 @@
- logging via udp
- improved spooler for cron-like apps
- async support
- green thread platform (uGreen) on top of teh async mode
- green thread platform (uGreen) on top of the async mode
- transparent Erlang integration
- embedded snmp agent
- nagios mode
-6
View File
@@ -1,6 +0,0 @@
Package: uwsgi
Version: 0.9.5
Maintainer: Unbit
Description: Fast, developer-friendly wsgi server
Architecture: all
Depends: python, libxml2
+1 -1
View File
@@ -38,7 +38,7 @@
#ifdef __linux__
#include <endian.h>
#elif __sun__
#elif __apple__
#elif __APPLE__
#include <libkern/OSByteOrder.h>
#else
#include <machine/endian.h>
-1
View File
@@ -45,7 +45,6 @@ void log_request(struct wsgi_request *wsgi_req) {
app_req = wi->requests;
}
}
via = msg2;
if (wsgi_req->sendfile_fd > -1) {
via = msg1;
+3 -1
View File
@@ -35,7 +35,9 @@
#include <ngx_core.h>
#include <ngx_http.h>
#define NGX_HTTP_UWSGI_TEMP_PATH "uwsgi_temp"
#ifndef NGX_HTTP_UWSGI_TEMP_PATH
#define NGX_HTTP_UWSGI_TEMP_PATH "uwsgi_temp"
#endif
typedef struct {
ngx_http_upstream_conf_t upstream;
-2
View File
@@ -2,8 +2,6 @@
void embed_plugins(struct uwsgi_server *uwsgi) {
int ret ;
#ifdef UWSGI_EMBED_PLUGIN_PSGI
if (uwsgi->plugin_arg_psgi)
ret = uwsgi_load_plugin(uwsgi, 5, "psgi_plugin.so", uwsgi->plugin_arg_psgi, 0);
+1 -2
View File
@@ -104,8 +104,7 @@ int uwsgi_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
}
// put function in the stack
lua_pushvalue(ulua.L, -1);
lua_getfield(ulua.L, -1, "run");
lua_getfield(ulua.L, LUA_GLOBALSINDEX, "run");
// put cgi vars in the stack
lua_newtable(ulua.L);
+48 -1
View File
@@ -167,7 +167,9 @@ PyObject *python_call(PyObject *callable, PyObject *args) {
}
#ifdef UWSGI_DEBUG
uwsgi_debug("called %p %p %d\n", callable, args, pyret ? pyret->ob_refcnt : NULL);
if (pyret) {
uwsgi_debug("called %p %p %d\n", callable, args, pyret->ob_refcnt);
}
#endif
@@ -192,3 +194,48 @@ int uwsgi_python_call(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req,
return UWSGI_OK;
}
void init_pyargv(struct uwsgi_server *uwsgi) {
#ifdef PYTHREE
wchar_t pname[6];
mbstowcs(pname, "uwsgi", 6);
uwsgi->py_argv[0] = pname;
#else
uwsgi->py_argv[0] = "uwsgi";
#endif
if (uwsgi->pyargv != NULL && !uwsgi->pyargc) {
uwsgi->pyargc++;
#ifdef PYTHREE
wchar_t *wcargv = malloc( sizeof( wchar_t ) * (strlen(uwsgi->pyargv)+1));
if (!wcargv) {
uwsgi_error("malloc()");
exit(1);
}
memset(wcargv, 0, sizeof( wchar_t ) * (strlen(uwsgi->pyargv)+1));
#endif
char *ap;
#ifdef __sun__
// FIX THIS !!!
ap = strtok(uwsgi->pyargv, " ");
while ((ap = strtok(NULL, " ")) != NULL) {
#else
while ((ap = strsep(&uwsgi->pyargv, " \t")) != NULL) {
#endif
if (*ap != '\0') {
#ifdef PYTHREE
mbstowcs( wcargv + strlen(ap), ap, strlen(ap));
uwsgi->py_argv[uwsgi->pyargc] = wcargv + strlen(ap);
#else
uwsgi->py_argv[uwsgi->pyargc] = ap;
#endif
uwsgi->pyargc++;
}
if (uwsgi->pyargc + 1 > MAX_PYARGV)
break;
}
}
PySys_SetArgv(uwsgi->pyargc, uwsgi->py_argv);
}
+1 -1
View File
@@ -66,7 +66,7 @@ ssize_t uwsgi_sendfile(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
}
return sf_len;
#elif __APPLE__
#elif defined(__APPLE__)
off_t sf_len = wsgi_req->sendfile_fd_size ;
if (uwsgi->async > 1) {
+14 -5
View File
@@ -52,12 +52,21 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
// chmod unix socket for lazy users
if (chmod_socket == 1 && abstract_socket == 0) {
uwsgi_log( "chmod() socket to 666 for lazy and brave users\n");
if (chmod(socket_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != 0) {
uwsgi_error("chmod()");
if (uwsgi.chmod_socket_value) {
if (chmod(socket_name, uwsgi.chmod_socket_value) != 0) {
uwsgi_error("chmod()");
}
}
else {
uwsgi_log( "chmod() socket to 666 for lazy and brave users\n");
if (chmod(socket_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != 0) {
uwsgi_error("chmod()");
}
}
}
free(uws_addr);
return serverfd;
}
@@ -230,7 +239,6 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
int serverfd;
struct sockaddr_in uws_addr;
int reuse = 1;
int i, ret;
tcp_port[0] = 0;
memset(&uws_addr, 0, sizeof(struct sockaddr_in));
@@ -263,7 +271,8 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) {
uwsgi_error("setsockopt()");
}
#elif defined(__apple__) || defined(__freebsd__)
// OSX has no SO_ACCEPTFILTER !!!
#elif defined(__freebsd__)
struct accept_filter_arg afa;
strcpy(afa.af_name, "dataready");
afa.af_arg[0] = 0;
+3 -3
View File
@@ -255,15 +255,15 @@ void uwsgi_as_root() {
}
}
else {
if (uwsgi.chroot) {
if (uwsgi.chroot && !uwsgi.is_a_reload) {
uwsgi_log("cannot chroot() as non-root user\n");
exit(1);
}
if (uwsgi.gid) {
if (uwsgi.gid && getgid() != uwsgi.gid) {
uwsgi_log("cannot setgid() as non-root user\n");
exit(1);
}
if (uwsgi.uid) {
if (uwsgi.uid && getuid() != uwsgi.uid) {
uwsgi_log("cannot setuid() as non-root user\n");
exit(1);
}
+28 -49
View File
@@ -203,13 +203,6 @@ int main(int argc, char *argv[], char *envp[]) {
uint64_t master_cycles = 0;
struct timeval check_interval = {.tv_sec = 1,.tv_usec = 0 };
#ifdef PYTHREE
wchar_t *pyargv[MAX_PYARGV];
#else
char *pyargv[MAX_PYARGV];
#endif
int pyargc = 1;
int i;
int rlen;
@@ -305,7 +298,7 @@ int main(int argc, char *argv[], char *envp[]) {
{"memory-report", no_argument, 0, 'm'},
{"cgi-mode", no_argument, 0, 'c'},
{"abstract-socket", no_argument, 0, 'a'},
{"chmod-socket", no_argument, 0, 'C'},
{"chmod-socket", optional_argument , 0, 'C'},
#ifdef UWSGI_THREADING
{"enable-threads", no_argument, 0, 'T'},
#endif
@@ -656,47 +649,7 @@ int main(int argc, char *argv[], char *envp[]) {
Py_Initialize();
#ifdef PYTHREE
mbstowcs(pname, "uwsgi", 6);
pyargv[0] = pname;
#else
pyargv[0] = "uwsgi";
#endif
if (uwsgi.pyargv != NULL) {
#ifdef PYTHREE
wchar_t *wcargv = malloc( sizeof( wchar_t ) * strlen(uwsgi.pyargv));
if (!wcargv) {
uwsgi_error("malloc()");
exit(1);
}
wchar_t *wa;
#endif
char *ap;
#ifdef __sun__
// FIX THIS !!!
ap = strtok(uwsgi.pyargv, " ");
while ((ap = strtok(NULL, " ")) != NULL) {
#else
while ((ap = strsep(&uwsgi.pyargv, " \t")) != NULL) {
#endif
if (*ap != '\0') {
#ifdef PYTHREE
wa = (wchar_t *) ( (ap-uwsgi.pyargv) * sizeof(wchar_t) );
mbstowcs(wa, ap, strlen(ap));
pyargv[pyargc] = wa;
#else
pyargv[pyargc] = ap;
#endif
pyargc++;
}
if (pyargc + 1 > MAX_PYARGV)
break;
}
}
PySys_SetArgv(pyargc, pyargv);
init_pyargv(&uwsgi);
if (uwsgi.vhost) {
uwsgi_log("VirtualHosting mode enabled.\n");
@@ -1663,7 +1616,11 @@ void init_uwsgi_vars() {
if (snprintf(venv_version, 15, "/lib/python%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION) == -1) {
return ;
}
#ifdef PYTHREE
venv_path = PyString_Concat( venv_path, PyString_FromString(venv_version) );
#else
PyString_Concat( &venv_path, PyString_FromString(venv_version) );
#endif
if ( PyList_Insert(pypath, 0, venv_path) ) {
PyErr_Print();
@@ -1747,8 +1704,13 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (uwsgi.vhost) {
zero = PyString_FromStringAndSize(uwsgi.wsgi_req->host, uwsgi.wsgi_req->host_len);
#ifdef PYTHREE
zero = PyString_Concat(zero, PyString_FromString("|"));
zero = PyString_Concat(zero, PyString_FromStringAndSize(uwsgi.wsgi_req->script_name, uwsgi.wsgi_req->script_name_len));
#else
PyString_Concat(&zero, PyString_FromString("|"));
PyString_Concat(&zero, PyString_FromStringAndSize(uwsgi.wsgi_req->script_name, uwsgi.wsgi_req->script_name_len));
#endif
}
else {
zero = PyString_FromStringAndSize(uwsgi.wsgi_req->script_name, uwsgi.wsgi_req->script_name_len);
@@ -1776,6 +1738,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
exit(1);
}
PyThreadState_Swap(wi->interpreter);
init_pyargv(&uwsgi);
#ifdef UWSGI_EMBEDDED
// we need to inizialize an embedded module for every interpreter
@@ -2778,6 +2741,22 @@ void manage_opt(int i, char *optarg) {
break;
case 'C':
uwsgi.chmod_socket = 1;
if (optarg) {
if (strlen(optarg) != 3) {
uwsgi_log("invalid chmod value: %s\n", optarg);
exit(1);
}
for(i=0;i<3;i++) {
if (optarg[i] < '0' || optarg[i] > '7') {
uwsgi_log("invalid chmod value: %s\n", optarg);
exit(1);
}
}
uwsgi.chmod_socket_value = (uwsgi.chmod_socket_value << 3) + (optarg[0] - '0');
uwsgi.chmod_socket_value = (uwsgi.chmod_socket_value << 3) + (optarg[1] - '0');
uwsgi.chmod_socket_value = (uwsgi.chmod_socket_value << 3) + (optarg[2] - '0');
}
break;
#endif
case 'M':
+17 -2
View File
@@ -49,6 +49,10 @@
#include <sys/wait.h>
#ifdef __APPLE__
#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_4
#endif
#include <dlfcn.h>
#include <poll.h>
@@ -113,7 +117,7 @@
#endif
/* this value are taken from nginx */
#if defined(__apple__) || defined(__freebsd__)
#if defined(__APPLE__) || defined(__freebsd__)
#define UWSGI_LISTEN_QUEUE -1
#else
#define UWSGI_LISTEN_QUEUE 511
@@ -191,7 +195,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#ifdef _BIG_ENDIAN
#define __BIG_ENDIAN__ 1
#endif
#elif __apple__
#elif __APPLE__
#include <libkern/OSByteOrder.h>
#else
#include <machine/endian.h>
@@ -236,6 +240,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define PyString_FromFormat PyUnicode_FromFormat
#define PyString_FromString PyUnicode_FromString
#define PyString_Size PyUnicode_GET_DATA_SIZE
#define PyString_Concat PyUnicode_Concat
#define PyString_AsString (char *) PyUnicode_AS_UNICODE
#define PyFile_FromFile(A,B,C,D) PyFile_FromFd(fileno((A)), (B), (C), -1, NULL, NULL, NULL, 0)
#endif
@@ -553,6 +558,7 @@ struct uwsgi_server {
#ifndef UNBIT
int abstract_socket;
int chmod_socket;
mode_t chmod_socket_value;
int listen_queue;
#ifdef UWSGI_XML
@@ -564,6 +570,13 @@ struct uwsgi_server {
char *python_path[64];
int python_path_cnt;
char *pyargv;
int pyargc;
#ifdef PYTHREE
wchar_t *py_argv[MAX_PYARGV];
#else
char *py_argv[MAX_PYARGV];
#endif
#endif
#ifdef UWSGI_ROUTING
@@ -1011,3 +1024,5 @@ void check_route(struct uwsgi_server *, struct wsgi_request *);
void uwsgi_route_action_uwsgi(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_route *);
void uwsgi_route_action_wsgi(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_route *);
#endif
void init_pyargv(struct uwsgi_server *);
+20 -6
View File
@@ -19,7 +19,7 @@ ASYNC=True
UGREEN=True
EVDIS=True
WSGI2=True
ROUTING=True
ROUTING=False
STACKLESS=False
#PLUGINS = ['psgi']
PLUGINS = []
@@ -64,7 +64,7 @@ gcc_list = ['utils', 'pyutils', 'protocol', 'socket', 'logging', 'wsgi_handlers'
# large file support
try:
cflags = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
cflags = ['-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
except:
print("You need python headers to build uWSGI.")
sys.exit(1)
@@ -72,6 +72,9 @@ except:
cflags = cflags + ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
ldflags = os.environ.get("LDFLAGS", "").split()
libs = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
if sysconfig.get_config_var('LIBPL'):
libs.append('-L' + sysconfig.get_config_var('LIBPL'))
if USWALLOW:
cflags = cflags + sysconfig.get_config_var('LLVM_CXXFLAGS').split()
@@ -220,7 +223,20 @@ def parse_vars():
depends_on("ROUTING", ['WSGI2', 'XML'])
cflags.append("-DUWSGI_ROUTING")
gcc_list.append('routing')
libs.append('-lpcre')
pcreconf = spcall("pcre-config --cflags")
if pcreconf is None:
print ("*** Unable to locate pcre-config. The uWSGI build has been interrupted. You have to install pcre.")
sys.exit(1)
else:
cflags.append(pcreconf)
pcreconf = spcall("pcre-config --libs")
if pcreconf is None:
print ("*** Unable to locate pcre-config. The uWSGI build has been interrupted. You have to install pcre.")
sys.exit(1)
else:
libs.append(pcreconf)
if EVDIS:
cflags.append("-DUWSGI_EVDIS")
@@ -316,11 +332,9 @@ def build_plugin(path):
import uwsgiplugin as up
p_cflags = cflags[:]
p_libs = libs[:]
p_ldflags = ldflags[:]
p_cflags.append(up.CFLAGS)
p_libs.append(up.LDFLAGS)
p_cflags.insert(0, '-I.')
@@ -332,7 +346,7 @@ def build_plugin(path):
if uwsgi_os == 'Darwin':
shared_flag = '-dynamiclib -undefined dynamic_lookup'
gccline = "%s -fPIC %s -o %s.so %s %s %s.c %s" % (GCC, shared_flag, plugin_dest, ' '.join(p_cflags), ' '.join(p_ldflags), plugin_base, ' '.join(p_libs))
gccline = "%s -fPIC %s -o %s.so %s %s %s.c" % (GCC, shared_flag, plugin_dest, ' '.join(p_cflags), ' '.join(p_ldflags), plugin_base )
print(gccline)
ret = os.system(gccline)
+5
View File
@@ -126,8 +126,13 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
if (wsgi_req->script_name_len > 0) {
if (uwsgi->vhost) {
zero = PyString_FromStringAndSize(wsgi_req->host, wsgi_req->host_len);
#ifdef PYTHREE
zero = PyString_Concat(zero, PyString_FromString("|"));
zero = PyString_Concat(zero, PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len));
#else
PyString_Concat(&zero, PyString_FromString("|"));
PyString_Concat(&zero, PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len));
#endif
}
else {
zero = PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len);
+12 -8
View File
@@ -116,8 +116,8 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
}
#ifdef UWSGI_ROUTING
else if (!strcmp((char *) node->name, "routing")) {
char *default_route_mountpoint = NULL;
char *default_route_callbase = NULL ;
unsigned char *default_route_mountpoint = NULL;
unsigned char *default_route_callbase = NULL ;
xmlChar *tmp_val;
int default_route_modifier1 = 0;
int default_route_modifier2 = 0;
@@ -129,12 +129,12 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
tmp_val = xmlGetProp(node, (const xmlChar *) "modifier1");
if (tmp_val) {
default_route_modifier1 = atoi(tmp_val);
default_route_modifier1 = atoi( (char *)tmp_val);
}
tmp_val = xmlGetProp(node, (const xmlChar *) "modifier2");
if (tmp_val) {
default_route_modifier2 = atoi(tmp_val);
default_route_modifier2 = atoi( (char *) tmp_val);
}
@@ -145,13 +145,13 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
uwsgi_log( "no route callable defined. skip.\n");
continue;
}
uwsgi.routes[uwsgi.nroutes].mountpoint = default_route_mountpoint;
uwsgi.routes[uwsgi.nroutes].callbase = default_route_callbase;
uwsgi.routes[uwsgi.nroutes].mountpoint = (char *) default_route_mountpoint;
uwsgi.routes[uwsgi.nroutes].callbase = (char *) default_route_callbase;
uwsgi.routes[uwsgi.nroutes].modifier1 = default_route_modifier1;
uwsgi.routes[uwsgi.nroutes].modifier2 = default_route_modifier2;
// TODO check for action
uwsgi.routes[uwsgi.nroutes].action = NULL;
uwsgi.routes[uwsgi.nroutes].call = node2->children->content;
uwsgi.routes[uwsgi.nroutes].call = (char *) node2->children->content;
if (uwsgi.routes[uwsgi.nroutes].call == NULL) {
uwsgi_log( "no route callable defined. skip.\n");
continue;
@@ -163,7 +163,7 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
continue;
}
uwsgi.routes[uwsgi.nroutes].pattern = pcre_compile(tmp_val, 0, &errstr, &erroff, NULL);
uwsgi.routes[uwsgi.nroutes].pattern = pcre_compile( (char *) tmp_val, 0, &errstr, &erroff, NULL);
uwsgi.routes[uwsgi.nroutes].pattern_extra = pcre_study(uwsgi.routes[uwsgi.nroutes].pattern, 0, &errstr);
@@ -184,7 +184,11 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
}
/* We cannot free xml resources on the first round (and with routing enabled) as the string pointer must be valid for all the server lifecycle */
#ifdef UWSGI_ROUTING
if (!long_options && !uwsgi.routing) {
#else
if (!long_options) {
#endif
xmlFreeDoc (doc);
xmlCleanupParser ();
}