From 0ee7ba6aae66e96ce081e81fcf693c4208960eb8 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Fri, 13 Jul 2012 21:44:16 +0200 Subject: [PATCH] save mountpoint,chdir and touch-reload valies of dynamic apps in shared memory --- core/utils.c | 4 ++-- plugins/python/pyloader.c | 33 +++++++++++++-------------------- uwsgi.h | 7 ++++--- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/core/utils.c b/core/utils.c index 3451f693..7eac969b 100644 --- a/core/utils.c +++ b/core/utils.c @@ -4197,8 +4197,8 @@ struct uwsgi_app *uwsgi_add_app(int id, uint8_t modifier1, char *mountpoint, int memset(wi, 0, sizeof(struct uwsgi_app)); wi->modifier1 = modifier1; - wi->mountpoint = mountpoint; - wi->mountpoint_len = mountpoint_len; + wi->mountpoint_len = mountpoint_len < 0xff ? mountpoint_len : (0xff-1); + strncpy(wi->mountpoint, mountpoint, wi->mountpoint_len); wi->interpreter = interpreter; wi->callable = callable; diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index e2060e6e..88f7784d 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -82,30 +82,24 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre int i; - char *mountpoint; - struct uwsgi_app *wi; time_t now = uwsgi_now(); - mountpoint = uwsgi_strncopy(wsgi_req->appid, wsgi_req->appid_len); - - if (uwsgi_get_app_id(mountpoint, strlen(mountpoint), -1) != -1) { - uwsgi_log( "mountpoint %.*s already configured. skip.\n", strlen(mountpoint), mountpoint); - free(mountpoint); + if (uwsgi_get_app_id(wsgi_req->appid, wsgi_req->appid_len, -1) != -1) { + uwsgi_log( "mountpoint %.*s already configured. skip.\n", wsgi_req->appid_len, wsgi_req->appid); return -1; } - wi = &uwsgi_apps[id]; memset(wi, 0, sizeof(struct uwsgi_app)); - wi->mountpoint = mountpoint; - wi->mountpoint_len = strlen(mountpoint); + wi->mountpoint_len = wsgi_req->appid_len < 0xff ? wsgi_req->appid_len : (0xff-1); + strncpy(wi->mountpoint, wsgi_req->appid, wi->mountpoint_len); // dynamic chdir ? if (wsgi_req->chdir_len > 0) { - wi->chdir = uwsgi_strncopy(wsgi_req->chdir, wsgi_req->chdir_len); + strncpy(wi->chdir, wsgi_req->chdir, wsgi_req->chdir_len < 0xff ? wsgi_req->chdir_len : (0xff-1)); #ifdef UWSGI_DEBUG uwsgi_debug("chdir to %s\n", wi->chdir); #endif @@ -193,11 +187,10 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre wi->interpreter = up.main_thread; #endif - if (wsgi_req->touch_reload_len) { + if (wsgi_req->touch_reload_len > 0 && wsgi_req->touch_reload_len < 0xff) { struct stat trst; - char *touch_reload = uwsgi_strncopy(wsgi_req->touch_reload, wsgi_req->touch_reload_len); - if (!stat(touch_reload, &trst)) { - wi->touch_reload = touch_reload; + strncpy(wi->touch_reload, wsgi_req->touch_reload, wsgi_req->touch_reload_len); + if (!stat(wi->touch_reload, &trst)) { wi->touch_reload_mtime = trst.st_mtime; } } @@ -205,7 +198,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre wi->callable = up.loaders[loader](arg1); if (!wi->callable) { - uwsgi_log("unable to load app %d (mountpoint='%s') (callable not found or import error)\n", id, mountpoint); + uwsgi_log("unable to load app %d (mountpoint='%s') (callable not found or import error)\n", id, wi->mountpoint); goto doh; } @@ -227,8 +220,9 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre uwsgi_log("the app mountpoint must be a string\n"); goto doh; } - wi->mountpoint = PyString_AsString(app_mnt); - wi->mountpoint_len = strlen(wi->mountpoint); + char *tmp_mountpoint = PyString_AsString(app_mnt); + wi->mountpoint_len = strlen(wi->mountpoint) < 0xff ? strlen(wi->mountpoint) : (0xff-1); + strncpy(wi->mountpoint, tmp_mountpoint, wi->mountpoint_len); wsgi_req->appid = wi->mountpoint; wsgi_req->appid_len = wi->mountpoint_len; #ifdef UWSGI_DEBUG @@ -359,7 +353,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre //uwsgi_log("%p\n", uwsgi.core[i]->ts[id]); uwsgi.core[i]->ts[id] = PyThreadState_New( ((PyThreadState *)wi->interpreter)->interp); if (!uwsgi.core[i]->ts[id]) { - uwsgi_log("unable to allocate new PyThreadState structure for app %s", mountpoint); + uwsgi_log("unable to allocate new PyThreadState structure for app %s", wi->mountpoint); goto doh; } } @@ -424,7 +418,6 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre return id; doh: - free(mountpoint); if (PyErr_Occurred()) PyErr_Print(); #ifdef UWSGI_MINTERPRETERS diff --git a/uwsgi.h b/uwsgi.h index 72df3580..96127462 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -704,7 +704,7 @@ struct uwsgi_app { uint8_t modifier1; - char *mountpoint; + char mountpoint[0xff]; int mountpoint_len; #ifdef UWSGI_PCRE @@ -742,9 +742,10 @@ struct uwsgi_app { int argc; uint64_t requests; uint64_t exceptions; - char *chdir; - char *touch_reload; + char chdir[0xff]; + char touch_reload[0xff]; + time_t touch_reload_mtime; void *gateway_version;