diff --git a/async.c b/async.c index 786d71e3..57f421b9 100644 --- a/async.c +++ b/async.c @@ -427,7 +427,7 @@ struct wsgi_request * async_loop() { uwsgi.async_running = 0; // st global wsgi_req for python functions uwsgi.wsgi_req = wsgi_req; - wsgi_req->async_status = (*uwsgi.shared->hook_request[wsgi_req->uh.modifier1]) (wsgi_req); + wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req); if (wsgi_req->async_status < UWSGI_AGAIN) { return wsgi_req; diff --git a/buildconf/default.ini b/buildconf/default.ini index 1d1a1f29..2c44f0eb 100644 --- a/buildconf/default.ini +++ b/buildconf/default.ini @@ -10,11 +10,9 @@ udp = true multicast = true threading = true sendfile = true -nagios = true proxy = true minterpreters = true async = true -ugreen = false http = true evdis = false ldap = false @@ -26,7 +24,7 @@ xml_implementation = libxml2 plugins = bin_name = uwsgi plugin_dir = . -embedded_plugins = python, ping +embedded_plugins = python, ping, nagios, rack [python] paste = true diff --git a/loop.c b/loop.c index 96ec4cff..770be62a 100644 --- a/loop.c +++ b/loop.c @@ -51,8 +51,8 @@ void *simple_loop(void *arg1) { sigfillset(&smask); pthread_sigmask(SIG_BLOCK, &smask, NULL); for(i=0;i<0xFF;i++) { - if (uwsgi.shared->hook_init_thread[i]) { - uwsgi.shared->hook_init_thread[i](); + if (uwsgi.p[i]->init_thread) { + uwsgi.p[i]->init_thread(); } } /* @@ -65,6 +65,7 @@ void *simple_loop(void *arg1) { while (uwsgi.workers[uwsgi.mywid].manage_next_request) { + #ifndef __linux__ if (uwsgi.no_orphans && uwsgi.master_process) { // am i a son of init ? diff --git a/master.c b/master.c index a4abe274..4c5f4f58 100644 --- a/master.c +++ b/master.c @@ -225,8 +225,8 @@ void master_loop(char **argv, char **environ) { // loop the various udp manager until one returns true udp_managed = 0; for(i=0;i<0xFF;i++) { - if (uwsgi.shared->hook_manage_udp[i]) { - if (uwsgi.shared->hook_manage_udp[i](udp_client_addr, udp_client.sin_port, uwsgi.wsgi_req->buffer, rlen)) { + if (uwsgi.p[i]->manage_udp) { + if (uwsgi.p[i]->manage_udp(udp_client_addr, udp_client.sin_port, uwsgi.wsgi_req->buffer, rlen)) { udp_managed = 1; break; } diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index e0a6e8d5..5f4dcc67 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -286,12 +286,11 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { wsgi_req->async_result = wi->request_subhandler(wsgi_req, wi); - if (wsgi_req->async_result) { UWSGI_RELEASE_GIL - while ( (*wi->response_subhandler)(wsgi_req) != UWSGI_OK) { + while ( wi->response_subhandler(wsgi_req) != UWSGI_OK) { wsgi_req->switches++; #ifdef UWSGI_ASYNC if (uwsgi.async > 1) { @@ -336,7 +335,6 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { close(tmp_stderr); } - clear: UWSGI_GET_GIL @@ -353,10 +351,9 @@ clear: UWSGI_RELEASE_GIL - clear2: +clear2: - - return UWSGI_OK; + return UWSGI_OK; } diff --git a/plugins/python/wsgi_headers.c b/plugins/python/wsgi_headers.c index 439a00e9..470ab184 100644 --- a/plugins/python/wsgi_headers.c +++ b/plugins/python/wsgi_headers.c @@ -149,6 +149,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { uwsgi_error("writev()"); } + //uwsgi_log("%d %p\n", wsgi_req->poll.fd, up.wsgi_writeout); Py_INCREF(up.wsgi_writeout); diff --git a/plugins/python/wsgi_subhandler.c b/plugins/python/wsgi_subhandler.c index fc0d98a4..60f744ff 100644 --- a/plugins/python/wsgi_subhandler.c +++ b/plugins/python/wsgi_subhandler.c @@ -110,15 +110,15 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { UWSGI_GET_GIL - // return or yield ? - if (PyString_Check((PyObject *)wsgi_req->async_result)) { - if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) { - uwsgi_error("write()"); - goto clear; - } - wsgi_req->response_size += wsize; + // return or yield ? + if (PyString_Check((PyObject *)wsgi_req->async_result)) { + if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) { + uwsgi_error("write()"); goto clear; } + wsgi_req->response_size += wsize; + goto clear; + } #ifdef UWSGI_SENDFILE if (wsgi_req->sendfile_obj == wsgi_req->async_result && wsgi_req->sendfile_fd != -1) { @@ -181,7 +181,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) { Py_DECREF(pychunk); UWSGI_RELEASE_GIL - return UWSGI_AGAIN; + return UWSGI_AGAIN; clear: if (wsgi_req->sendfile_fd != -1) { @@ -214,7 +214,7 @@ clear2: #endif UWSGI_RELEASE_GIL - return UWSGI_OK; + return UWSGI_OK; } diff --git a/utils.c b/utils.c index b9d8d35c..fa9cebe2 100644 --- a/utils.c +++ b/utils.c @@ -341,7 +341,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) { } // after_request hook - uwsgi.shared->hook_after_request[wsgi_req->uh.modifier1](wsgi_req); + uwsgi.p[wsgi_req->uh.modifier1]->after_request(wsgi_req); // leave harakiri mode if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { @@ -402,8 +402,7 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) { set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]); } - wsgi_req->async_status = uwsgi.shared->hook_request[wsgi_req->uh.modifier1] (wsgi_req); - + wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req); return 0; } @@ -468,17 +467,6 @@ void sanitize_args() { uwsgi.cores = uwsgi.threads; } -#ifdef UWSGI_UGREEN -#ifdef UWSGI_THREADING - if (uwsgi.ugreen) { - if (uwsgi.has_threads) { - uwsgi_log("--- python threads will be disabled in uGreen mode ---\n"); - uwsgi.has_threads = 0; - } - } -#endif -#endif - if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { if (!uwsgi.post_buffering) { uwsgi_log(" *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** \n"); diff --git a/uwsgi.c b/uwsgi.c index ec2b427e..7a389196 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -282,6 +282,13 @@ static void unconfigured_after_hook(struct wsgi_request * wsgi_req) return; } +struct uwsgi_plugin unconfigured_plugin = { + + .name = "unconfigured", + .request = unconfigured_hook, + .after_request = unconfigured_after_hook, +}; + static void vacuum(void) { @@ -391,8 +398,7 @@ int main(int argc, char *argv[], char *envp[]) #endif for (i = 0; i <= 0xFF; i++) { - uwsgi.shared->hook_request[i] = unconfigured_hook; - uwsgi.shared->hook_after_request[i] = unconfigured_after_hook; + uwsgi.p[i] = &unconfigured_plugin; } uwsgi.cores = 1; @@ -764,8 +770,8 @@ uwsgi.wsgi_config = lazy; } } for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_init[i]) { - (*uwsgi.shared->hook_init[i]) (); + if (uwsgi.p[i]->init) { + uwsgi.p[i]->init(); } } @@ -822,8 +828,8 @@ uwsgi.wsgi_config = lazy; if (uwsgi.has_threads) { uwsgi.current_wsgi_req = threaded_current_wsgi_req; for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_enable_threads[i]) - uwsgi.shared->hook_enable_threads[i] (); + if (uwsgi.p[i]->enable_threads) + uwsgi.p[i]->enable_threads(); } } #endif @@ -1128,8 +1134,8 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100 //init apps hook for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_init_apps[i]) { - uwsgi.shared->hook_init_apps[i] (); + if (uwsgi.p[i]->init_apps) { + uwsgi.p[i]->init_apps(); } } @@ -1231,8 +1237,8 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100 //from now on the process is a real worker } for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_post_fork[i]) { - uwsgi.shared->hook_post_fork[i] (); + if (uwsgi.p[i]->post_fork) { + uwsgi.p[i]->post_fork(); } } @@ -1890,8 +1896,8 @@ end: } for (j = 0; j < 0xFF; j++) { - if (uwsgi.shared->hook_manage_opt[j]) { - if (uwsgi.shared->hook_manage_opt[j] (i, optarg)) { + if (uwsgi.p[j]->manage_opt) { + if (uwsgi.p[j]->manage_opt(i, optarg)) { return; } } @@ -1960,8 +1966,8 @@ void build_options() { char *so_ptr; for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_short_options[i]) { - short_opt_size += strlen(uwsgi.shared->hook_short_options[i]); + if (uwsgi.p[i]->short_options) { + short_opt_size += strlen(uwsgi.p[i]->short_options); } } @@ -1983,9 +1989,9 @@ void build_options() { so_ptr = short_options + strlen(base_short_options); for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_short_options[i]) { - memcpy(so_ptr, uwsgi.shared->hook_short_options[i], strlen(uwsgi.shared->hook_short_options[i])); - so_ptr += strlen(uwsgi.shared->hook_short_options[i]); + if (uwsgi.p[i]->short_options) { + memcpy(so_ptr, uwsgi.p[i]->short_options, strlen(uwsgi.p[i]->short_options)); + so_ptr += strlen(uwsgi.p[i]->short_options); } } @@ -1999,8 +2005,8 @@ void build_options() { *so_ptr = 0; for (i = 0; i < 0xFF; i++) { - if (uwsgi.shared->hook_options[i]) { - opt_count += count_options(uwsgi.shared->hook_options[i]); + if (uwsgi.p[i]->options) { + opt_count += count_options(uwsgi.p[i]->options); } } @@ -2032,7 +2038,7 @@ void build_options() { } for (i = 0; i < 0xFF; i++) { - lopt = uwsgi.shared->hook_options[i]; + lopt = uwsgi.p[i]->options; if (!lopt) continue; diff --git a/uwsgi.h b/uwsgi.h index 915ffeb3..201adec8 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -24,47 +24,21 @@ #define ULEP(pname)\ if (pname##_plugin.request) {\ - uwsgi.shared->hook_init[pname##_plugin.modifier1] = pname##_plugin.init;\ - uwsgi.shared->hook_post_fork[pname##_plugin.modifier1] = pname##_plugin.post_fork;\ - uwsgi.shared->hook_options[pname##_plugin.modifier1] = pname##_plugin.options;\ - uwsgi.shared->hook_manage_opt[pname##_plugin.modifier1] = pname##_plugin.manage_opt;\ - uwsgi.shared->hook_short_options[pname##_plugin.modifier1] = pname##_plugin.short_options;\ - uwsgi.shared->hook_request[pname##_plugin.modifier1] = pname##_plugin.request;\ - uwsgi.shared->hook_after_request[pname##_plugin.modifier1] = pname##_plugin.after_request;\ - uwsgi.shared->hook_init_apps[pname##_plugin.modifier1] = pname##_plugin.init_apps;\ - uwsgi.shared->hook_enable_threads[pname##_plugin.modifier1] = pname##_plugin.enable_threads;\ - uwsgi.shared->hook_init_thread[pname##_plugin.modifier1] = pname##_plugin.init_thread;\ - uwsgi.shared->hook_manage_udp[pname##_plugin.modifier1] = pname##_plugin.manage_udp;\ - uwsgi.shared->hook_manage_xml[pname##_plugin.modifier1] = pname##_plugin.manage_xml;\ - uwsgi.shared->hook_suspend[pname##_plugin.modifier1] = pname##_plugin.suspend;\ - uwsgi.shared->hook_resume[pname##_plugin.modifier1] = pname##_plugin.resume;\ + uwsgi.p[pname##_plugin.modifier1] = &pname##_plugin;\ }\ else {\ if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\ - uwsgi_log("you have embedded to much generic plugins !!!\n");\ + uwsgi_log("you have embedded too much generic plugins !!!\n");\ exit(1);\ }\ - uwsgi.gp[uwsgi.gp_cnt] = pname##_plugin;\ + uwsgi.gp[uwsgi.gp_cnt] = &pname##_plugin;\ uwsgi.gp_cnt++;\ }\ #define fill_plugin_table(x, up)\ if (up->request) {\ - uwsgi.shared->hook_init[x] = up->init;\ - uwsgi.shared->hook_post_fork[x] = up->post_fork;\ - uwsgi.shared->hook_options[x] = up->options;\ - uwsgi.shared->hook_manage_opt[x] = up->manage_opt;\ - uwsgi.shared->hook_short_options[x] = up->short_options;\ - uwsgi.shared->hook_request[x] = up->request;\ - uwsgi.shared->hook_after_request[x] = up->after_request;\ - uwsgi.shared->hook_init_apps[x] = up->init_apps;\ - uwsgi.shared->hook_enable_threads[x] = up->enable_threads;\ - uwsgi.shared->hook_init_thread[x] = up->init_thread;\ - uwsgi.shared->hook_manage_udp[x] = up->manage_udp;\ - uwsgi.shared->hook_manage_xml[x] = up->manage_xml;\ - uwsgi.shared->hook_suspend[x] = up->suspend;\ - uwsgi.shared->hook_resume[x] = up->resume;\ + uwsgi.p[x] = up;\ }\ else {\ if (uwsgi.gp_cnt >= MAX_GENERIC_PLUGINS) {\ @@ -797,6 +771,7 @@ struct uwsgi_server { struct uwsgi_loop loops[MAX_LOOPS]; int loops_cnt; + struct uwsgi_plugin *p[0xFF]; struct uwsgi_plugin *gp[MAX_GENERIC_PLUGINS]; int gp_cnt; @@ -832,21 +807,7 @@ struct uwsgi_shared { //vga 80 x25 specific ! char warning_message[81]; - int (*hook_init[0xFF]) (void); - void (*hook_post_fork[0xFF]) (void); - void (*hook_enable_threads[0xFF]) (void); - int (*hook_request[0xFF]) (struct wsgi_request *); - void (*hook_after_request[0xFF]) (struct wsgi_request *); - void (*hook_init_thread[0xFF]) (void); - void (*hook_init_apps[0xFF]) (void); - struct option *hook_options[0xFF]; - const char *hook_short_options[0xFF]; - int (*hook_manage_opt[0xFF]) (int, char *); - int (*hook_manage_udp[0xFF]) (char *, int, char *, int); - int (*hook_manage_xml[0xFF]) (char *, char *); - void (*hook_suspend[0xFF]) (struct wsgi_request *); - void (*hook_resume[0xFF]) (struct wsgi_request *); - uint32_t options[256]; + uint32_t options[0xFF]; struct uwsgi_cluster_node nodes[MAX_CLUSTER_NODES]; diff --git a/xmlconf.c b/xmlconf.c index 09bbb2f2..e198f723 100644 --- a/xmlconf.c +++ b/xmlconf.c @@ -170,8 +170,8 @@ next: if (node2->children) { if (node2->children->content) { for(i=0;i<0xFF;i++) { - if (uwsgi.shared->hook_manage_xml[i]) { - if (uwsgi.shared->hook_manage_xml[i]( (char *)node2->name, (char *) node2->children->content)) break; + if (uwsgi.p[i]->manage_xml) { + if (uwsgi.p[i]->manage_xml( (char *)node2->name, (char *) node2->children->content)) break; } } }