diff --git a/lock.c b/lock.c index 579148cc..8d1b52bb 100644 --- a/lock.c +++ b/lock.c @@ -64,7 +64,7 @@ pid_t uwsgi_lock_check(void *lock) { pthread_mutex_unlock((pthread_mutex_t *) lock + sizeof(pthread_mutexattr_t)); return 0; } - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; return *pid; } @@ -77,7 +77,7 @@ pid_t uwsgi_rwlock_check(void *lock) { pthread_rwlock_unlock((pthread_rwlock_t *) lock + sizeof(pthread_mutexattr_t)); return 0; } - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; return *pid; #endif } @@ -95,7 +95,7 @@ void uwsgi_wlock(void *lock) { uwsgi_lock(lock); #else pthread_rwlock_wrlock((pthread_rwlock_t *) lock + sizeof(pthread_rwlockattr_t)); - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; *pid = uwsgi.mypid; #endif } @@ -105,7 +105,7 @@ void uwsgi_rwunlock(void *lock) { uwsgi_unlock(lock); #else pthread_rwlock_unlock((pthread_rwlock_t *) lock + sizeof(pthread_rwlockattr_t)); - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; *pid = 0; #endif } @@ -113,14 +113,14 @@ void uwsgi_rwunlock(void *lock) { void uwsgi_lock(void *lock) { pthread_mutex_lock((pthread_mutex_t *) lock + sizeof(pthread_mutexattr_t)); - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; *pid = uwsgi.mypid; } void uwsgi_unlock(void *lock) { pthread_mutex_unlock((pthread_mutex_t *) lock + sizeof(pthread_mutexattr_t)); - pid_t *pid = (pid_t *) lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t) ; + pid_t *pid = (pid_t *) (lock + sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t)) ; *pid = 0; } @@ -197,14 +197,14 @@ void uwsgi_lock_init(void *lock) { void uwsgi_lock(void *lock) { OSSpinLockLock((OSSpinLock *) lock); - pid_t *pid = (pid_t *) lock + sizeof(OSSpinLock); + pid_t *pid = (pid_t *) (lock + sizeof(OSSpinLock)); *pid = uwsgi.mypid; } void uwsgi_unlock(void *lock) { OSSpinLockUnlock((OSSpinLock *) lock); - pid_t *pid = (pid_t *) lock + sizeof(OSSpinLock); + pid_t *pid = (pid_t *) (lock + sizeof(OSSpinLock)); *pid = 0; } @@ -213,7 +213,7 @@ pid_t uwsgi_lock_check(void *lock) { OSSpinLockUnlock((OSSpinLock *) lock); return 0; } - pid_t *pid = (pid_t *) lock + sizeof(OSSpinLock); + pid_t *pid = (pid_t *) (lock + sizeof(OSSpinLock)); return *pid; } diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 943280bd..f53698d7 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -9,6 +9,21 @@ extern struct http_status_codes hsc[]; extern PyTypeObject uwsgi_InputType; +void uwsgi_opt_pythonpath(char *opt, char *value, void *foobar) { + + int i; + glob_t g; + + if (glob(value, GLOB_MARK, NULL, &g)) { + uwsgi_string_new_list(&up.python_path, value); + } + else { + for (i = 0; i < (int) g.gl_pathc; i++) { + uwsgi_string_new_list(&up.python_path, g.gl_pathv[i]); + } + } +} + struct uwsgi_option uwsgi_python_options[] = { {"wsgi-file", required_argument, 0, "load .wsgi file", uwsgi_opt_set_str, &up.file_config, 0}, {"file", required_argument, 0, "load .wsgi file", uwsgi_opt_set_str, &up.file_config, 0}, @@ -22,26 +37,27 @@ struct uwsgi_option uwsgi_python_options[] = { {"venv", required_argument, 'H', "set PYTHONHOME/virtualenv", uwsgi_opt_set_str, &up.home, 0}, {"pyhome", required_argument, 'H', "set PYTHONHOME/virtualenv", uwsgi_opt_set_str, &up.home, 0}, -/* - {"pythonpath", required_argument, 0, LONG_ARGS_PYTHONPATH}, - {"python-path", required_argument, 0, LONG_ARGS_PYTHONPATH}, - {"pp", required_argument, 0, LONG_ARGS_PYTHONPATH}, - {"pymodule-alias", required_argument, 0, LONG_ARGS_PYMODULE_ALIAS}, + {"pythonpath", required_argument, 0, "add directory (or glob) to pythonpath", 0, uwsgi_opt_pythonpath, 0}, + {"python-path", required_argument, 0, "add directory (or glob) to pythonpath", 0, uwsgi_opt_pythonpath, 0}, + {"pp", required_argument, 0, "add directory (or glob) to pythonpath", 0, uwsgi_opt_pythonpath, 0}, - {"post-pymodule-alias", required_argument, 0, LONG_ARGS_POST_PYMODULE_ALIAS}, - {"import", required_argument, 0, LONG_ARGS_PYIMPORT}, - {"pyimport", required_argument, 0, LONG_ARGS_PYIMPORT}, - {"py-import", required_argument, 0, LONG_ARGS_PYIMPORT}, - {"python-import", required_argument, 0, LONG_ARGS_PYIMPORT}, - {"shared-import", required_argument, 0, LONG_ARGS_SHARED_PYIMPORT}, - {"shared-pyimport", required_argument, 0, LONG_ARGS_SHARED_PYIMPORT}, - {"shared-py-import", required_argument, 0, LONG_ARGS_SHARED_PYIMPORT}, - {"shared-python-import", required_argument, 0, LONG_ARGS_SHARED_PYIMPORT}, - {"spooler-import", required_argument, 0, LONG_ARGS_SPOOLER_PYIMPORT}, - {"spooler-pyimport", required_argument, 0, LONG_ARGS_SPOOLER_PYIMPORT}, - {"spooler-py-import", required_argument, 0, LONG_ARGS_SPOOLER_PYIMPORT}, - {"spooler-python-import", required_argument, 0, LONG_ARGS_SPOOLER_PYIMPORT}, -*/ + {"pymodule-alias", required_argument, 0, "add a python alias module", uwsgi_opt_add_string_list, &up.pymodule_alias, 0}, + {"post-pymodule-alias", required_argument, 0, "add a python module alias after uwsgi module initialization", uwsgi_opt_add_string_list, &up.post_pymodule_alias, 0}, + + {"import", required_argument, 0, "import a python module", uwsgi_opt_add_string_list, &up.import_list, 0}, + {"pyimport", required_argument, 0, "import a python module", uwsgi_opt_add_string_list, &up.import_list, 0}, + {"py-import", required_argument, 0, "import a python module", uwsgi_opt_add_string_list, &up.import_list, 0}, + {"python-import", required_argument, 0, "import a python module", uwsgi_opt_add_string_list, &up.import_list, 0}, + + {"shared-import", required_argument, 0, "import a python module in all of the processes", uwsgi_opt_add_string_list, &up.shared_import_list, 0}, + {"shared-pyimport", required_argument, 0, "import a python module in all of the processes", uwsgi_opt_add_string_list, &up.shared_import_list, 0}, + {"shared-py-import", required_argument, 0, "import a python module in all of the processes", uwsgi_opt_add_string_list, &up.shared_import_list, 0}, + {"shared-python-import", required_argument, 0, "import a python module in all of the processes", uwsgi_opt_add_string_list, &up.shared_import_list, 0}, + + {"spooler-import", required_argument, 0, "import a python module in the spooler", uwsgi_opt_add_string_list, &up.spooler_import_list}, + {"spooler-pyimport", required_argument, 0, "import a python module in the spooler", uwsgi_opt_add_string_list, &up.spooler_import_list}, + {"spooler-py-import", required_argument, 0, "import a python module in the spooler", uwsgi_opt_add_string_list, &up.spooler_import_list}, + {"spooler-python-import", required_argument, 0, "import a python module in the spooler", uwsgi_opt_add_string_list, &up.spooler_import_list}, {"pyargv", required_argument, 0, "manually set sys.argv", uwsgi_opt_set_str, &up.argv, 0}, {"optimize", required_argument, 'O', "set python optimization level", uwsgi_opt_set_int, &up.optimize, 0}, @@ -58,13 +74,12 @@ struct uwsgi_option uwsgi_python_options[] = { //{"ini-paste", required_argument, 0, LONG_ARGS_INI_PASTE}, #endif {"catch-exceptions", no_argument, 0, "report exception has http output (discouraged)", uwsgi_opt_true, &up.catch_exceptions, 0}, -/* - {"ignore-script-name", no_argument, &up.ignore_script_name, 1}, - {"pep3333-input", no_argument, &up.pep3333_input, 1}, - {"reload-os-env", no_argument, &up.reload_os_env, 1}, + {"ignore-script-name", no_argument, 0, "ignore SCRIPT_NAME", uwsgi_opt_true, &up.ignore_script_name, 0}, + {"reload-os-env", no_argument, 0, "force reload of os.environ at each request", uwsgi_opt_true, &up.reload_os_env, 0}, #ifndef UWSGI_PYPY - {"no-site", no_argument, &Py_NoSiteFlag, 1}, + {"no-site", no_argument, 0, "do not import site module", uwsgi_opt_true, &Py_NoSiteFlag, 0}, #endif +/* {"pyshell", no_argument, 0, LONG_ARGS_PYSHELL}, {"pyshell-oneshot", no_argument, 0, LONG_ARGS_PYSHELL_ONESHOT}, {"python", required_argument, 0, LONG_ARGS_PYTHON_RUN}, @@ -186,6 +201,10 @@ void uwsgi_python_atexit() { if (uwsgi.workers[uwsgi.mywid].hijacked) return; + // if busy do not run atexit hooks + if (uwsgi.workers[uwsgi.mywid].busy) + return; + // this time we use this higher level function // as this code can be executed in a signal handler @@ -328,7 +347,6 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) { void init_uwsgi_vars() { - int i; PyObject *pysys, *pysys_dict, *pypath; PyObject *modules = PyImport_GetModuleDict(); @@ -372,9 +390,10 @@ void init_uwsgi_vars() { uppp = uppp->next; } - for (i = 0; i < up.pymodule_alias_cnt; i++) { + struct uwsgi_string_list *uppma = up.pymodule_alias; + while(uppma) { // split key=value - char *value = strchr(up.pymodule_alias[i], '='); + char *value = strchr(uppma->value, '='); if (!value) { uwsgi_log("invalid pymodule-alias syntax\n"); continue; @@ -388,19 +407,21 @@ void init_uwsgi_vars() { exit(1); } - PyDict_SetItemString(modules, up.pymodule_alias[i], tmp_module); + PyDict_SetItemString(modules, uppma->value, tmp_module); } else { // this is a filepath that need to be mapped - tmp_module = uwsgi_pyimport_by_filename(up.pymodule_alias[i], value + 1); + tmp_module = uwsgi_pyimport_by_filename(uppma->value, value + 1); if (!tmp_module) { PyErr_Print(); exit(1); } } - uwsgi_log("mapped virtual pymodule \"%s\" to real pymodule \"%s\"\n", up.pymodule_alias[i], value + 1); + uwsgi_log("mapped virtual pymodule \"%s\" to real pymodule \"%s\"\n", uppma->value, value + 1); // reset original value value[0] = '='; + + uppma = uppma->next; } } diff --git a/plugins/python/pyutils.c b/plugins/python/pyutils.c index b1b05160..f75d621c 100644 --- a/plugins/python/pyutils.c +++ b/plugins/python/pyutils.c @@ -67,21 +67,36 @@ void init_pyargv() { #ifdef PYTHREE wchar_t pname[6]; mbstowcs(pname, "uwsgi", 6); - up.py_argv[0] = pname; #else - up.py_argv[0] = "uwsgi"; + char *pname = "uwsgi"; #endif up.argc = 1; +#ifdef __sun__ + // FIX THIS !!! + ap = strtok(up.argv, " "); + while ((ap = strtok(NULL, " ")) != NULL) { +#else + while ((ap = strsep(&up.argv, " \t")) != NULL) { +#endif + if (*ap != '\0') { + up.argc++; + } + } + +#ifdef PYTHREE + up.py_argv = uwsgi_calloc(sizeof(wchar_t *) * up.argc+1); +#else + up.py_argv = uwsgi_calloc(sizeof(char *) * up.argc+1); +#endif + + up.py_argv[0] = pname; if (up.argv != NULL) { + + up.argc = 1; #ifdef PYTHREE - wchar_t *wcargv = malloc( sizeof( wchar_t ) * (strlen(up.argv)+1)); - if (!wcargv) { - uwsgi_error("malloc()"); - exit(1); - } - memset(wcargv, 0, sizeof( wchar_t ) * (strlen(up.argv)+1)); + wchar_t *wcargv = uwsgi_calloc( sizeof( wchar_t ) * (strlen(up.argv)+1)); #endif #ifdef __sun__ @@ -89,7 +104,7 @@ void init_pyargv() { ap = strtok(up.argv, " "); while ((ap = strtok(NULL, " ")) != NULL) { #else - while ((ap = strsep(&up.argv, " \t")) != NULL) { + while ((ap = strsep(&up.argv, " \t")) != NULL) { #endif if (*ap != '\0') { #ifdef PYTHREE @@ -100,8 +115,6 @@ void init_pyargv() { #endif up.argc++; } - if (up.argc + 1 > MAX_PYARGV) - break; } } diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index 96131216..01964405 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -3,9 +3,6 @@ #include -#define MAX_PYMODULE_ALIAS 64 -#define MAX_PYARGV 10 - #define PYTHON_APP_TYPE_WSGI 0 #define PYTHON_APP_TYPE_WEB3 1 #define PYTHON_APP_TYPE_WSGI2 2 @@ -101,9 +98,9 @@ struct uwsgi_python { int argc; #ifdef PYTHREE - wchar_t *py_argv[MAX_PYARGV]; + wchar_t **py_argv; #else - char *py_argv[MAX_PYARGV]; + char **py_argv; #endif PyObject *wsgi_spitout; @@ -121,6 +118,7 @@ struct uwsgi_python { struct uwsgi_string_list *shared_import_list; struct uwsgi_string_list *spooler_import_list; struct uwsgi_string_list *post_pymodule_alias; + struct uwsgi_string_list *pymodule_alias; PyObject *loader_dict; PyObject* (*loaders[LOADER_MAX]) (void *); @@ -160,8 +158,6 @@ struct uwsgi_python { PyObject *embedded_dict; PyObject *embedded_args; - char *pymodule_alias[MAX_PYMODULE_ALIAS]; - int pymodule_alias_cnt; int pep3333_input; diff --git a/psgi.py b/psgi.py deleted file mode 100644 index 9eb7f9d0..00000000 --- a/psgi.py +++ /dev/null @@ -1,8 +0,0 @@ -import uwsgi -import sys - -if uwsgi.load_plugin(0, "plugins/psgi/psgi_plugin.so", "mojoapp.pl"): - print "PSGI plugin loaded" -else: - print "unable to load PSGI plugin" - sys.exit(1)