From ce39a751d9e102f5b773cdaa42ca41d004b54136 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sun, 19 May 2013 12:00:12 +0200 Subject: [PATCH] improved uwsgi_get_app_id --- core/utils.c | 5 ----- plugins/mono/mono_plugin.c | 2 +- plugins/psgi/psgi_plugin.c | 31 +++++++++++++++++++++---------- plugins/python/wsgi_handlers.c | 10 +++++++++- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/core/utils.c b/core/utils.c index 4478115a..a7f0fdb6 100644 --- a/core/utils.c +++ b/core/utils.c @@ -1208,11 +1208,6 @@ int uwsgi_get_app_id(struct wsgi_request *wsgi_req, char *key, uint16_t key_len, } } - if (!uwsgi.no_default_app) { - if (free_appname) free(app_name); - return uwsgi.default_app; - } - return -1; } diff --git a/plugins/mono/mono_plugin.c b/plugins/mono/mono_plugin.c index 26ff42fb..4f8d42e6 100644 --- a/plugins/mono/mono_plugin.c +++ b/plugins/mono/mono_plugin.c @@ -547,7 +547,7 @@ static int uwsgi_mono_request(struct wsgi_request *wsgi_req) { pthread_mutex_lock(&umono.lock_loader); } - // check if the mean time, something changed + // check if in the mean time, something changed wsgi_req->app_id = uwsgi_get_app_id(NULL, key, key_len, mono_plugin.modifier1); if (wsgi_req->app_id == -1) { diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index a64a3ebf..987ada01 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -394,33 +394,44 @@ int uwsgi_perl_request(struct wsgi_request *wsgi_req) { return -1; } + if (wsgi_req->dynamic) { + if (uwsgi.threads > 1) { + pthread_mutex_lock(&uperl.lock_loader); + } + } + wsgi_req->app_id = uwsgi_get_app_id(wsgi_req, wsgi_req->appid, wsgi_req->appid_len, psgi_plugin.modifier1); // if it is -1, try to load a dynamic app if (wsgi_req->app_id == -1) { if (wsgi_req->dynamic) { - if (uwsgi.threads > 1) { - pthread_mutex_lock(&uperl.lock_loader); - } - if (wsgi_req->script_len > 0) { wsgi_req->app_id = init_psgi_app(wsgi_req, wsgi_req->script, wsgi_req->script_len, NULL); } else if (wsgi_req->file_len > 0) { wsgi_req->app_id = init_psgi_app(wsgi_req, wsgi_req->file, wsgi_req->file_len, NULL); } - - if (uwsgi.threads > 1) { - pthread_mutex_unlock(&uperl.lock_loader); - } } + if (wsgi_req->app_id == -1 && !uwsgi.no_default_app && uwsgi.default_app > -1) { + if (uwsgi_apps[uwsgi.default_app].modifier1 == psgi_plugin.modifier1) { + wsgi_req->app_id = uwsgi.default_app; + } + } + + } + + if (wsgi_req->dynamic) { + if (uwsgi.threads > 1) { + pthread_mutex_unlock(&uperl.lock_loader); + } + } + if (wsgi_req->app_id == -1) { uwsgi_500(wsgi_req); uwsgi_log("--- unable to find perl application ---\n"); // nothing to clear/free return UWSGI_OK; } - } struct uwsgi_app *wi = &uwsgi_apps[wsgi_req->app_id]; wi->requests++; @@ -712,7 +723,7 @@ static uint16_t uwsgi_perl_rpc(void *func, uint8_t argc, char **argv, uint16_t a STRLEN rlen; SV *response = POPs; char *value = SvPV(response, rlen ); - ret = UMIN(UMAX16, rlen); + ret = UMIN(UMAX16-1, rlen); memcpy(buffer, value, ret); } diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 92be2a38..42dd213e 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -2,6 +2,7 @@ extern struct uwsgi_server uwsgi; extern struct uwsgi_python up; +extern struct uwsgi_plugin python_plugin; PyObject *uwsgi_Input_iter(PyObject *self) { @@ -339,7 +340,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } } - if ( (wsgi_req->app_id = uwsgi_get_app_id(wsgi_req, wsgi_req->appid, wsgi_req->appid_len, 0)) == -1) { + if ( (wsgi_req->app_id = uwsgi_get_app_id(wsgi_req, wsgi_req->appid, wsgi_req->appid_len, python_plugin.modifier1)) == -1) { if (wsgi_req->dynamic) { UWSGI_GET_GIL if (uwsgi.single_interpreter) { @@ -350,6 +351,12 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } UWSGI_RELEASE_GIL } + + if (wsgi_req->app_id == -1 && !uwsgi.no_default_app && uwsgi.default_app > -1) { + if (uwsgi_apps[uwsgi.default_app].modifier1 == python_plugin.modifier1) { + wsgi_req->app_id = uwsgi.default_app; + } + } } if (wsgi_req->dynamic) { @@ -358,6 +365,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { } } + if (wsgi_req->app_id == -1) { uwsgi_500(wsgi_req); uwsgi_log("--- no python application found, check your startup logs for errors ---\n");