mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
new 0.9.7 codebase for app loading is complete
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
@@ -265,7 +267,7 @@ int async_del(int queuefd, int fd, int etype) {
|
||||
|
||||
#endif
|
||||
|
||||
inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
inline struct wsgi_request *next_wsgi_req(struct wsgi_request *wsgi_req) {
|
||||
|
||||
uint8_t *ptr = (uint8_t *) wsgi_req ;
|
||||
|
||||
@@ -274,17 +276,17 @@ inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *uwsgi, struct wsg
|
||||
return (struct wsgi_request *) ptr ;
|
||||
}
|
||||
|
||||
int async_get_timeout(struct uwsgi_server *uwsgi) {
|
||||
int async_get_timeout() {
|
||||
|
||||
|
||||
struct wsgi_request* wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request* wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i ;
|
||||
time_t curtime, tdelta = 0 ;
|
||||
int ret = 0 ;
|
||||
|
||||
if (!uwsgi->async_running) return 0;
|
||||
if (!uwsgi.async_running) return 0;
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_AGAIN) {
|
||||
if (wsgi_req->async_timeout_expired) {
|
||||
return 0;
|
||||
@@ -295,7 +297,7 @@ int async_get_timeout(struct uwsgi_server *uwsgi) {
|
||||
}
|
||||
}
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
|
||||
curtime = time(NULL);
|
||||
@@ -308,67 +310,67 @@ int async_get_timeout(struct uwsgi_server *uwsgi) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void async_expire_timeouts(struct uwsgi_server *uwsgi) {
|
||||
void async_expire_timeouts() {
|
||||
|
||||
struct wsgi_request* wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request* wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i ;
|
||||
time_t deadline = time(NULL);
|
||||
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_AGAIN && wsgi_req->async_timeout > 0) {
|
||||
if (wsgi_req->async_timeout <= deadline) {
|
||||
wsgi_req->async_timeout = 0 ;
|
||||
wsgi_req->async_timeout_expired = 1 ;
|
||||
}
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
}
|
||||
|
||||
struct wsgi_request *find_first_available_wsgi_req(struct uwsgi_server *uwsgi) {
|
||||
struct wsgi_request *find_first_available_wsgi_req() {
|
||||
|
||||
struct wsgi_request* wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request* wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i ;
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_OK) {
|
||||
return wsgi_req ;
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
|
||||
return NULL ;
|
||||
}
|
||||
|
||||
struct wsgi_request *find_wsgi_req_by_id(struct uwsgi_server *uwsgi, int async_id) {
|
||||
struct wsgi_request *find_wsgi_req_by_id(int async_id) {
|
||||
|
||||
uint8_t *ptr = (uint8_t *) uwsgi->wsgi_requests ;
|
||||
uint8_t *ptr = (uint8_t *) uwsgi.wsgi_requests ;
|
||||
|
||||
ptr += sizeof(struct wsgi_request) * async_id ;
|
||||
|
||||
return (struct wsgi_request *) ptr ;
|
||||
}
|
||||
|
||||
struct wsgi_request *find_wsgi_req_by_fd(struct uwsgi_server *uwsgi, int fd, int etype) {
|
||||
struct wsgi_request *find_wsgi_req_by_fd(int fd, int etype) {
|
||||
|
||||
struct wsgi_request* wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request* wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i ;
|
||||
|
||||
if (etype != -1) {
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_waiting_fd == fd && wsgi_req->async_waiting_fd_type == etype) {
|
||||
return wsgi_req ;
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_waiting_fd == fd) {
|
||||
return wsgi_req ;
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,13 +386,13 @@ void async_set_timeout(struct wsgi_request *wsgi_req, time_t timeout) {
|
||||
|
||||
}
|
||||
|
||||
void async_write_all(struct uwsgi_server *uwsgi, char *data, size_t len) {
|
||||
void async_write_all(char *data, size_t len) {
|
||||
|
||||
struct wsgi_request *wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request *wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i;
|
||||
ssize_t rlen ;
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_PAUSED) {
|
||||
rlen = write(wsgi_req->poll.fd, data, len);
|
||||
if (rlen < 0) {
|
||||
@@ -403,32 +405,32 @@ void async_write_all(struct uwsgi_server *uwsgi, char *data, size_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
void async_unpause_all(struct uwsgi_server *uwsgi) {
|
||||
void async_unpause_all() {
|
||||
|
||||
struct wsgi_request *wsgi_req = uwsgi->wsgi_requests ;
|
||||
struct wsgi_request *wsgi_req = uwsgi.wsgi_requests ;
|
||||
int i;
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_PAUSED) {
|
||||
wsgi_req->async_status = UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct wsgi_request * async_loop(struct uwsgi_server *uwsgi) {
|
||||
struct wsgi_request * async_loop() {
|
||||
|
||||
struct wsgi_request *wsgi_req ;
|
||||
int i ;
|
||||
|
||||
uwsgi->async_running = -1 ;
|
||||
wsgi_req = uwsgi->wsgi_requests ;
|
||||
uwsgi.async_running = -1 ;
|
||||
wsgi_req = uwsgi.wsgi_requests ;
|
||||
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
if (wsgi_req->async_status == UWSGI_AGAIN) {
|
||||
if (wsgi_req->async_waiting_fd != -1 && !wsgi_req->async_waiting_fd_monitored) {
|
||||
// add fd to monitoring
|
||||
if (async_add(uwsgi->async_queue, wsgi_req->async_waiting_fd, wsgi_req->async_waiting_fd_type)) {
|
||||
if (async_add(uwsgi.async_queue, wsgi_req->async_waiting_fd, wsgi_req->async_waiting_fd_type)) {
|
||||
// error adding fd to the async queue, better to close it...
|
||||
close(wsgi_req->async_waiting_fd);
|
||||
wsgi_req->async_status = UWSGI_OK ;
|
||||
@@ -438,10 +440,10 @@ struct wsgi_request * async_loop(struct uwsgi_server *uwsgi) {
|
||||
wsgi_req->async_status = UWSGI_AGAIN;
|
||||
}
|
||||
else if (wsgi_req->async_waiting_fd == -1 && wsgi_req->async_timeout <= 0) {
|
||||
uwsgi->async_running = 0 ;
|
||||
uwsgi.async_running = 0 ;
|
||||
// st global wsgi_req for python functions
|
||||
uwsgi->wsgi_req = wsgi_req ;
|
||||
wsgi_req->async_status = (*uwsgi->shared->hooks[wsgi_req->uh.modifier1]) (uwsgi, wsgi_req);
|
||||
uwsgi.wsgi_req = wsgi_req ;
|
||||
wsgi_req->async_status = (*uwsgi.shared->hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
|
||||
wsgi_req->async_switches++;
|
||||
|
||||
@@ -450,7 +452,7 @@ struct wsgi_request * async_loop(struct uwsgi_server *uwsgi) {
|
||||
}
|
||||
}
|
||||
}
|
||||
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
|
||||
wsgi_req = next_wsgi_req(wsgi_req) ;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -90,7 +90,7 @@ static char *add_uwsgi_var(char *up, char *key, uint16_t keylen, char *val, uint
|
||||
|
||||
static void *http_request(void *);
|
||||
|
||||
void http_loop(struct uwsgi_server * uwsgi)
|
||||
void http_loop()
|
||||
{
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ void http_loop(struct uwsgi_server * uwsgi)
|
||||
|
||||
// ignore broken pipes;
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
if (!uwsgi->http_only) {
|
||||
if (!uwsgi.http_only) {
|
||||
signal(SIGCHLD, &http_end);
|
||||
signal(SIGINT, &http_wait_end);
|
||||
}
|
||||
@@ -121,22 +121,22 @@ void http_loop(struct uwsgi_server * uwsgi)
|
||||
signal(SIGINT, &http_end);
|
||||
}
|
||||
|
||||
uwsgi->http_server_name = malloc(256);
|
||||
if (!uwsgi->http_server_name) {
|
||||
uwsgi.http_server_name = malloc(256);
|
||||
if (!uwsgi.http_server_name) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memset(uwsgi->http_server_name, 0, 256);
|
||||
if (gethostname(uwsgi->http_server_name, 255)) {
|
||||
memset(uwsgi.http_server_name, 0, 256);
|
||||
if (gethostname(uwsgi.http_server_name, 255)) {
|
||||
uwsgi_error("gethostname()");
|
||||
memcpy(uwsgi->http_server_name, "localhost", 9);
|
||||
memcpy(uwsgi.http_server_name, "localhost", 9);
|
||||
}
|
||||
|
||||
uwsgi_log("starting HTTP loop on %s (pid: %d)\n", uwsgi->http_server_name, (int) getpid());
|
||||
uwsgi_log("starting HTTP loop on %s (pid: %d)\n", uwsgi.http_server_name, (int) getpid());
|
||||
for(;;) {
|
||||
|
||||
if (!uwsgi->http_only) {
|
||||
if (!uwsgi.http_only) {
|
||||
if (waitpid(-1, &stat_loc, WNOHANG) != 0) {
|
||||
http_end();
|
||||
}
|
||||
@@ -148,7 +148,7 @@ void http_loop(struct uwsgi_server * uwsgi)
|
||||
continue;
|
||||
}
|
||||
ur->c_len = sizeof(struct sockaddr_in) ;
|
||||
ur->fd = accept(uwsgi->http_fd, (struct sockaddr *) &ur->c_addr, &ur->c_len);
|
||||
ur->fd = accept(uwsgi.http_fd, (struct sockaddr *) &ur->c_addr, &ur->c_len);
|
||||
|
||||
if (ur->fd < 0) {
|
||||
uwsgi_error("accept()");
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#include <ldap.h>
|
||||
|
||||
void ldap2uwsgi(char *ldapname, char *uwsginame) {
|
||||
@@ -219,7 +221,7 @@ next2:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void uwsgi_ldap_config(struct uwsgi_server *uwsgi, struct option *long_options) {
|
||||
void uwsgi_ldap_config(struct option *long_options) {
|
||||
|
||||
LDAP *ldp;
|
||||
LDAPMessage *results, *entry;
|
||||
@@ -238,8 +240,8 @@ void uwsgi_ldap_config(struct uwsgi_server *uwsgi, struct option *long_options)
|
||||
|
||||
LDAPURLDesc *ldap_url;
|
||||
|
||||
if (uwsgi->ldap) {
|
||||
url = uwsgi->ldap;
|
||||
if (uwsgi.ldap) {
|
||||
url = uwsgi.ldap;
|
||||
}
|
||||
|
||||
if (!ldap_is_ldap_url(url)) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#ifdef __linux__
|
||||
void get_linux_tcp_info(int fd) {
|
||||
struct tcp_info ti;
|
||||
@@ -14,7 +16,7 @@ void get_linux_tcp_info(int fd) {
|
||||
#endif
|
||||
|
||||
|
||||
void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
void master_loop(char **argv, char **environ) {
|
||||
|
||||
uint64_t master_cycles = 0;
|
||||
|
||||
@@ -58,10 +60,10 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
|
||||
signal(SIGUSR1, (void *) &stats);
|
||||
|
||||
uwsgi->wsgi_req->buffer = uwsgi->async_buf[0];
|
||||
uwsgi.wsgi_req->buffer = uwsgi.async_buf[0];
|
||||
#ifdef UWSGI_UDP
|
||||
if (uwsgi->udp_socket) {
|
||||
uwsgi_poll.fd = bind_to_udp(uwsgi->udp_socket);
|
||||
if (uwsgi.udp_socket) {
|
||||
uwsgi_poll.fd = bind_to_udp(uwsgi.udp_socket);
|
||||
if (uwsgi_poll.fd < 0) {
|
||||
uwsgi_log( "unable to bind to udp socket. SNMP and cluster management services will be disabled.\n");
|
||||
}
|
||||
@@ -73,20 +75,20 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_SNMP
|
||||
if (uwsgi->snmp) {
|
||||
if (uwsgi->snmp_community) {
|
||||
if (strlen(uwsgi->snmp_community) > 72) {
|
||||
if (uwsgi.snmp) {
|
||||
if (uwsgi.snmp_community) {
|
||||
if (strlen(uwsgi.snmp_community) > 72) {
|
||||
uwsgi_log( "*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
|
||||
memcpy(uwsgi->shared->snmp_community, uwsgi->snmp_community, 72);
|
||||
memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 72);
|
||||
}
|
||||
else {
|
||||
memcpy(uwsgi->shared->snmp_community, uwsgi->snmp_community, strlen(uwsgi->snmp_community) + 1);
|
||||
memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, strlen(uwsgi.snmp_community) + 1);
|
||||
}
|
||||
}
|
||||
uwsgi_log( "filling SNMP table...");
|
||||
|
||||
uwsgi->shared->snmp_gvalue[0].type = SNMP_COUNTER64;
|
||||
uwsgi->shared->snmp_gvalue[0].val = &uwsgi->workers[0].requests;
|
||||
uwsgi.shared->snmp_gvalue[0].type = SNMP_COUNTER64;
|
||||
uwsgi.shared->snmp_gvalue[0].val = &uwsgi.workers[0].requests;
|
||||
|
||||
uwsgi_log( "done\n");
|
||||
|
||||
@@ -94,50 +96,50 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
udp_callable = PyDict_GetItemString(uwsgi->embedded_dict, "udp_callable");
|
||||
udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable");
|
||||
if (udp_callable) {
|
||||
udp_callable_args = PyTuple_New(3);
|
||||
}
|
||||
#endif
|
||||
for (;;) {
|
||||
if (ready_to_die >= uwsgi->numproc && uwsgi->to_hell) {
|
||||
if (ready_to_die >= uwsgi.numproc && uwsgi.to_hell) {
|
||||
#ifdef UWSGI_SPOOLER
|
||||
if (uwsgi->spool_dir && uwsgi->shared->spooler_pid > 0) {
|
||||
kill(uwsgi->shared->spooler_pid, SIGKILL);
|
||||
uwsgi_log( "killed the spooler with pid %d\n", uwsgi->shared->spooler_pid);
|
||||
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
|
||||
kill(uwsgi.shared->spooler_pid, SIGKILL);
|
||||
uwsgi_log( "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_PROXY
|
||||
if (uwsgi->proxy_socket_name && uwsgi->shared->proxy_pid > 0) {
|
||||
kill(uwsgi->shared->proxy_pid, SIGKILL);
|
||||
uwsgi_log( "killed proxy with pid %d\n", uwsgi->shared->proxy_pid);
|
||||
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
|
||||
kill(uwsgi.shared->proxy_pid, SIGKILL);
|
||||
uwsgi_log( "killed proxy with pid %d\n", uwsgi.shared->proxy_pid);
|
||||
}
|
||||
#endif
|
||||
uwsgi_log( "goodbye to uWSGI.\n");
|
||||
exit(0);
|
||||
}
|
||||
if (ready_to_reload >= uwsgi->numproc && uwsgi->to_heaven) {
|
||||
if (ready_to_reload >= uwsgi.numproc && uwsgi.to_heaven) {
|
||||
#ifdef UWSGI_SPOOLER
|
||||
if (uwsgi->spool_dir && uwsgi->shared->spooler_pid > 0) {
|
||||
kill(uwsgi->shared->spooler_pid, SIGKILL);
|
||||
uwsgi_log( "wait4() the spooler with pid %d...", uwsgi->shared->spooler_pid);
|
||||
diedpid = waitpid(uwsgi->shared->spooler_pid, &waitpid_status, 0);
|
||||
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
|
||||
kill(uwsgi.shared->spooler_pid, SIGKILL);
|
||||
uwsgi_log( "wait4() the spooler with pid %d...", uwsgi.shared->spooler_pid);
|
||||
diedpid = waitpid(uwsgi.shared->spooler_pid, &waitpid_status, 0);
|
||||
uwsgi_log( "done.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_PROXY
|
||||
if (uwsgi->proxy_socket_name && uwsgi->shared->proxy_pid > 0) {
|
||||
kill(uwsgi->shared->proxy_pid, SIGKILL);
|
||||
uwsgi_log( "wait4() the proxy with pid %d...", uwsgi->shared->proxy_pid);
|
||||
diedpid = waitpid(uwsgi->shared->proxy_pid, &waitpid_status, 0);
|
||||
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
|
||||
kill(uwsgi.shared->proxy_pid, SIGKILL);
|
||||
uwsgi_log( "wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid);
|
||||
diedpid = waitpid(uwsgi.shared->proxy_pid, &waitpid_status, 0);
|
||||
uwsgi_log( "done.");
|
||||
}
|
||||
#endif
|
||||
uwsgi_log( "binary reloading uWSGI...\n");
|
||||
if (chdir(uwsgi->cwd)) {
|
||||
if (chdir(uwsgi.cwd)) {
|
||||
uwsgi_error("chdir()");
|
||||
exit(1);
|
||||
}
|
||||
@@ -145,8 +147,8 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
uwsgi_log( "closing all non-uwsgi socket fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf(_SC_OPEN_MAX));
|
||||
for (i = 3; i < sysconf(_SC_OPEN_MAX); i++) {
|
||||
int found = 0;
|
||||
for(j=0;j<uwsgi->sockets_cnt;j++) {
|
||||
if (i == uwsgi->sockets[j].fd) {
|
||||
for(j=0;j<uwsgi.sockets_cnt;j++) {
|
||||
if (i == uwsgi.sockets[j].fd) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
@@ -154,10 +156,10 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
if (!found) close(i);
|
||||
}
|
||||
|
||||
uwsgi_log( "running %s\n", uwsgi->binary_path);
|
||||
argv[0] = uwsgi->binary_path;
|
||||
//strcpy (argv[0], uwsgi->binary_path);
|
||||
execve(uwsgi->binary_path, argv, environ);
|
||||
uwsgi_log( "running %s\n", uwsgi.binary_path);
|
||||
argv[0] = uwsgi.binary_path;
|
||||
//strcpy (argv[0], uwsgi.binary_path);
|
||||
execve(uwsgi.binary_path, argv, environ);
|
||||
uwsgi_error("execve()");
|
||||
// never here
|
||||
exit(1);
|
||||
@@ -165,16 +167,16 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
|
||||
|
||||
|
||||
if (uwsgi->numproc > 0 ) {
|
||||
if (uwsgi.numproc > 0 ) {
|
||||
master_has_children = 1;
|
||||
}
|
||||
#ifdef UWSGI_SPOOLER
|
||||
if (uwsgi->spool_dir && uwsgi->shared->spooler_pid > 0) {
|
||||
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
|
||||
master_has_children = 1;
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_PROXY
|
||||
if (uwsgi->proxy_socket_name && uwsgi->shared->proxy_pid > 0) {
|
||||
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
|
||||
master_has_children = 1;
|
||||
}
|
||||
#endif
|
||||
@@ -198,43 +200,43 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
we support this for hyperultramegagodprogrammer and systems
|
||||
*/
|
||||
#ifdef UWSGI_THREADING
|
||||
if (uwsgi->has_threads && uwsgi->shared->options[UWSGI_OPTION_THREADS] == 1) {
|
||||
uwsgi->_save = PyEval_SaveThread();
|
||||
uwsgi->workers[uwsgi->mywid].i_have_gil = 0;
|
||||
if (uwsgi.has_threads && uwsgi.shared->options[UWSGI_OPTION_THREADS] == 1) {
|
||||
uwsgi._save = PyEval_SaveThread();
|
||||
uwsgi.workers[uwsgi.mywid].i_have_gil = 0;
|
||||
}
|
||||
#endif
|
||||
/* all processes ok, doing status scan after N seconds */
|
||||
check_interval.tv_sec = uwsgi->shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval.tv_sec = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
if (!check_interval.tv_sec)
|
||||
check_interval.tv_sec = 1;
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
if (uwsgi->udp_socket && uwsgi_poll.fd >= 0) {
|
||||
if (uwsgi.udp_socket && uwsgi_poll.fd >= 0) {
|
||||
rlen = poll(&uwsgi_poll, 1, check_interval.tv_sec * 1000);
|
||||
if (rlen < 0) {
|
||||
uwsgi_error("poll()");
|
||||
}
|
||||
else if (rlen > 0) {
|
||||
udp_len = sizeof(udp_client);
|
||||
rlen = recvfrom(uwsgi_poll.fd, uwsgi->wsgi_req->buffer, uwsgi->buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len);
|
||||
rlen = recvfrom(uwsgi_poll.fd, uwsgi.wsgi_req->buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len);
|
||||
if (rlen < 0) {
|
||||
uwsgi_error("recvfrom()");
|
||||
}
|
||||
else if (rlen > 0) {
|
||||
memset(udp_client_addr, 0, 16);
|
||||
if (inet_ntop(AF_INET, &udp_client.sin_addr.s_addr, udp_client_addr, 16)) {
|
||||
if (uwsgi->wsgi_req->buffer[0] == UWSGI_MODIFIER_MULTICAST_ANNOUNCE) {
|
||||
if (uwsgi.wsgi_req->buffer[0] == UWSGI_MODIFIER_MULTICAST_ANNOUNCE) {
|
||||
}
|
||||
#ifdef UWSGI_SNMP
|
||||
else if (uwsgi->wsgi_req->buffer[0] == 0x30 && uwsgi->snmp) {
|
||||
manage_snmp(uwsgi_poll.fd, (uint8_t *) uwsgi->wsgi_req->buffer, rlen, &udp_client);
|
||||
else if (uwsgi.wsgi_req->buffer[0] == 0x30 && uwsgi.snmp) {
|
||||
manage_snmp(uwsgi_poll.fd, (uint8_t *) uwsgi.wsgi_req->buffer, rlen, &udp_client);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
if (udp_callable && udp_callable_args) {
|
||||
PyTuple_SetItem(udp_callable_args, 0, PyString_FromString(udp_client_addr));
|
||||
PyTuple_SetItem(udp_callable_args, 1, PyInt_FromLong(ntohs(udp_client.sin_port)));
|
||||
PyTuple_SetItem(udp_callable_args, 2, PyString_FromStringAndSize(uwsgi->wsgi_req->buffer, rlen));
|
||||
PyTuple_SetItem(udp_callable_args, 2, PyString_FromStringAndSize(uwsgi.wsgi_req->buffer, rlen));
|
||||
udp_response = python_call(udp_callable, udp_callable_args, 0);
|
||||
if (udp_response) {
|
||||
Py_DECREF(udp_response);
|
||||
@@ -244,7 +246,7 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
}
|
||||
else {
|
||||
// a simple udp logger
|
||||
uwsgi_log( "[udp:%s:%d] %.*s", udp_client_addr, ntohs(udp_client.sin_port), rlen, uwsgi->wsgi_req->buffer);
|
||||
uwsgi_log( "[udp:%s:%d] %.*s", udp_client_addr, ntohs(udp_client.sin_port), rlen, uwsgi.wsgi_req->buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,65 +264,65 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
#endif
|
||||
|
||||
// checking logsize
|
||||
if (uwsgi->logfile) {
|
||||
uwsgi->shared->logsize = lseek(2, 0, SEEK_CUR);
|
||||
if (uwsgi.logfile) {
|
||||
uwsgi.shared->logsize = lseek(2, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
master_cycles++;
|
||||
working_workers = 0;
|
||||
blocking_workers = 0;
|
||||
#ifdef UWSGI_THREADING
|
||||
if (uwsgi->has_threads && !uwsgi->workers[uwsgi->mywid].i_have_gil) {
|
||||
PyEval_RestoreThread(uwsgi->_save);
|
||||
uwsgi->workers[uwsgi->mywid].i_have_gil = 1;
|
||||
if (uwsgi.has_threads && !uwsgi.workers[uwsgi.mywid].i_have_gil) {
|
||||
PyEval_RestoreThread(uwsgi._save);
|
||||
uwsgi.workers[uwsgi.mywid].i_have_gil = 1;
|
||||
}
|
||||
#endif
|
||||
check_interval.tv_sec = uwsgi->shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval.tv_sec = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
if (!check_interval.tv_sec)
|
||||
check_interval.tv_sec = 1;
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
for(i=0;i<uwsgi->sockets_cnt;i++) {
|
||||
if (uwsgi->sockets[i].family != AF_INET) continue;
|
||||
get_linux_tcp_info(uwsgi->sockets[i].fd);
|
||||
for(i=0;i<uwsgi.sockets_cnt;i++) {
|
||||
if (uwsgi.sockets[i].family != AF_INET) continue;
|
||||
get_linux_tcp_info(uwsgi.sockets[i].fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 1; i <= uwsgi->numproc; i++) {
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
/* first check for harakiri */
|
||||
if (uwsgi->workers[i].harakiri > 0) {
|
||||
if (uwsgi->workers[i].harakiri < time(NULL)) {
|
||||
if (uwsgi.workers[i].harakiri > 0) {
|
||||
if (uwsgi.workers[i].harakiri < time(NULL)) {
|
||||
/* first try to invoke the harakiri() custom handler */
|
||||
/* TODO */
|
||||
/* then brutally kill the worker */
|
||||
uwsgi_log("*** HARAKIRI ON WORKER %d (pid: %d) ***\n", i, uwsgi->workers[i].pid);
|
||||
kill(uwsgi->workers[i].pid, SIGUSR2);
|
||||
uwsgi_log("*** HARAKIRI ON WORKER %d (pid: %d) ***\n", i, uwsgi.workers[i].pid);
|
||||
kill(uwsgi.workers[i].pid, SIGUSR2);
|
||||
// allow SIGUSR2 to be delivered
|
||||
sleep(1);
|
||||
kill(uwsgi->workers[i].pid, SIGKILL);
|
||||
kill(uwsgi.workers[i].pid, SIGKILL);
|
||||
// to avoid races
|
||||
uwsgi->workers[i].harakiri = 0;
|
||||
uwsgi.workers[i].harakiri = 0;
|
||||
}
|
||||
}
|
||||
/* load counters */
|
||||
if (uwsgi->workers[i].status & UWSGI_STATUS_IN_REQUEST)
|
||||
if (uwsgi.workers[i].status & UWSGI_STATUS_IN_REQUEST)
|
||||
working_workers++;
|
||||
|
||||
if (uwsgi->workers[i].status & UWSGI_STATUS_BLOCKING)
|
||||
if (uwsgi.workers[i].status & UWSGI_STATUS_BLOCKING)
|
||||
blocking_workers++;
|
||||
|
||||
uwsgi->workers[i].last_running_time = uwsgi->workers[i].running_time;
|
||||
uwsgi.workers[i].last_running_time = uwsgi.workers[i].running_time;
|
||||
}
|
||||
|
||||
// check for cluster nodes
|
||||
for (i = 0; i < MAX_CLUSTER_NODES; i++) {
|
||||
struct uwsgi_cluster_node *ucn = &uwsgi->shared->nodes[i];
|
||||
struct uwsgi_cluster_node *ucn = &uwsgi.shared->nodes[i];
|
||||
|
||||
if (ucn->name[0] != 0 && ucn->status == UWSGI_NODE_FAILED) {
|
||||
// should i retry ?
|
||||
if (master_cycles % ucn->errors == 0) {
|
||||
if (!uwsgi_ping_node(i, uwsgi->wsgi_req)) {
|
||||
if (!uwsgi_ping_node(i, uwsgi.wsgi_req)) {
|
||||
ucn->status = UWSGI_NODE_OK;
|
||||
uwsgi_log( "re-enabled cluster node %d/%s\n", i, ucn->name);
|
||||
}
|
||||
@@ -336,10 +338,10 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
}
|
||||
#ifdef UWSGI_SPOOLER
|
||||
/* reload the spooler */
|
||||
if (uwsgi->spool_dir && uwsgi->shared->spooler_pid > 0) {
|
||||
if (diedpid == uwsgi->shared->spooler_pid) {
|
||||
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
|
||||
if (diedpid == uwsgi.shared->spooler_pid) {
|
||||
uwsgi_log( "OOOPS the spooler is no more...trying respawn...\n");
|
||||
uwsgi->shared->spooler_pid = spooler_start(uwsgi, uwsgi->embedded_dict);
|
||||
uwsgi.shared->spooler_pid = spooler_start(uwsgi.embedded_dict);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -347,12 +349,12 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
|
||||
#ifdef UWSGI_PROXY
|
||||
/* reload the proxy (can be the only process running) */
|
||||
if (uwsgi->proxy_socket_name && uwsgi->shared->proxy_pid > 0) {
|
||||
if (diedpid == uwsgi->shared->proxy_pid) {
|
||||
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
|
||||
if (diedpid == uwsgi.shared->proxy_pid) {
|
||||
if (WIFEXITED(waitpid_status)) {
|
||||
if (WEXITSTATUS(waitpid_status) != UWSGI_END_CODE) {
|
||||
uwsgi_log( "OOOPS the proxy is no more...trying respawn...\n");
|
||||
uwsgi->shared->spooler_pid = proxy_start(1);
|
||||
uwsgi.shared->spooler_pid = proxy_start(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -364,11 +366,11 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
#ifdef __sun__
|
||||
/* horrible hack... what the FU*K is doing Solaris ??? */
|
||||
if (WIFSIGNALED(waitpid_status)) {
|
||||
if (uwsgi->to_heaven) {
|
||||
if (uwsgi.to_heaven) {
|
||||
ready_to_reload++;
|
||||
continue;
|
||||
}
|
||||
else if (uwsgi->to_hell) {
|
||||
else if (uwsgi.to_hell) {
|
||||
ready_to_die++;
|
||||
continue;
|
||||
}
|
||||
@@ -376,19 +378,19 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
#endif
|
||||
/* check for reloading */
|
||||
if (WIFEXITED(waitpid_status)) {
|
||||
if (WEXITSTATUS(waitpid_status) == UWSGI_RELOAD_CODE && uwsgi->to_heaven) {
|
||||
if (WEXITSTATUS(waitpid_status) == UWSGI_RELOAD_CODE && uwsgi.to_heaven) {
|
||||
ready_to_reload++;
|
||||
continue;
|
||||
}
|
||||
else if (WEXITSTATUS(waitpid_status) == UWSGI_END_CODE && uwsgi->to_hell) {
|
||||
else if (WEXITSTATUS(waitpid_status) == UWSGI_END_CODE && uwsgi.to_hell) {
|
||||
ready_to_die++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uwsgi->mywid = find_worker_id(diedpid);
|
||||
if (uwsgi->mywid <= 0) {
|
||||
uwsgi.mywid = find_worker_id(diedpid);
|
||||
if (uwsgi.mywid <= 0) {
|
||||
if (WIFEXITED(waitpid_status)) {
|
||||
uwsgi_log("subprocess %d exited with code %d\n", (int) diedpid, WEXITSTATUS(waitpid_status));
|
||||
}
|
||||
@@ -403,24 +405,24 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
|
||||
uwsgi_log( "DAMN ! process %d died :( trying respawn ...\n", diedpid);
|
||||
gettimeofday(&last_respawn, NULL);
|
||||
if (last_respawn.tv_sec == uwsgi->respawn_delta) {
|
||||
if (last_respawn.tv_sec == uwsgi.respawn_delta) {
|
||||
uwsgi_log( "worker respawning too fast !!! i have to sleep a bit...\n");
|
||||
/* TODO, user configurable fork throttler */
|
||||
sleep(2);
|
||||
}
|
||||
gettimeofday(&last_respawn, NULL);
|
||||
uwsgi->respawn_delta = last_respawn.tv_sec;
|
||||
uwsgi.respawn_delta = last_respawn.tv_sec;
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
uwsgi->mypid = getpid();
|
||||
uwsgi->workers[uwsgi->mywid].pid = uwsgi->mypid;
|
||||
uwsgi->workers[uwsgi->mywid].harakiri = 0;
|
||||
uwsgi->workers[uwsgi->mywid].requests = 0;
|
||||
uwsgi->workers[uwsgi->mywid].failed_requests = 0;
|
||||
uwsgi->workers[uwsgi->mywid].respawn_count++;
|
||||
uwsgi->workers[uwsgi->mywid].last_spawn = time(NULL);
|
||||
uwsgi->workers[uwsgi->mywid].manage_next_request = 1;
|
||||
uwsgi->workers[uwsgi->mywid].i_have_gil = 1;
|
||||
uwsgi.mypid = getpid();
|
||||
uwsgi.workers[uwsgi.mywid].pid = uwsgi.mypid;
|
||||
uwsgi.workers[uwsgi.mywid].harakiri = 0;
|
||||
uwsgi.workers[uwsgi.mywid].requests = 0;
|
||||
uwsgi.workers[uwsgi.mywid].failed_requests = 0;
|
||||
uwsgi.workers[uwsgi.mywid].respawn_count++;
|
||||
uwsgi.workers[uwsgi.mywid].last_spawn = time(NULL);
|
||||
uwsgi.workers[uwsgi.mywid].manage_next_request = 1;
|
||||
uwsgi.workers[uwsgi.mywid].i_have_gil = 1;
|
||||
break;
|
||||
}
|
||||
else if (pid < 1) {
|
||||
@@ -429,13 +431,13 @@ void master_loop(struct uwsgi_server *uwsgi, char **argv, char **environ) {
|
||||
else {
|
||||
uwsgi_log( "Respawned uWSGI worker (new pid: %d)\n", pid);
|
||||
#ifdef UWSGI_SPOOLER
|
||||
if (uwsgi->mywid <= 0 && diedpid != uwsgi->shared->spooler_pid) {
|
||||
if (uwsgi.mywid <= 0 && diedpid != uwsgi.shared->spooler_pid) {
|
||||
#else
|
||||
if (uwsgi->mywid <= 0) {
|
||||
if (uwsgi.mywid <= 0) {
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_PROXY
|
||||
if (diedpid != uwsgi->shared->proxy_pid) {
|
||||
if (diedpid != uwsgi.shared->proxy_pid) {
|
||||
#endif
|
||||
uwsgi_log( "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n");
|
||||
#ifdef UWSGI_PROXY
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
[uwsgi]
|
||||
socket = :3031
|
||||
socket = :3032
|
||||
socket = :3033
|
||||
socket = :3034
|
||||
vacuum = true
|
||||
socket = pippo1.sock
|
||||
socket = pippo2.sock
|
||||
socket = 127.0.0.1:1717
|
||||
module = multiapp
|
||||
memory-report = true
|
||||
master = true
|
||||
processes = 10
|
||||
disable-logging = true
|
||||
mount = /app1=werkzeug.testapp:test_app
|
||||
mount = /app2=config:/Users/roberta/uwsgi/my.ini
|
||||
mount = /app3=pinaxsite/deploy/pinax.wsgi
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
void nagios(struct uwsgi_server *uwsgi) {
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void nagios() {
|
||||
|
||||
char *tcp_port;
|
||||
struct pollfd nagios_poll;
|
||||
// connect and send
|
||||
if (uwsgi->sockets[0].name == NULL) {
|
||||
if (uwsgi.sockets[0].name == NULL) {
|
||||
fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n");
|
||||
exit(3);
|
||||
}
|
||||
tcp_port = strchr(uwsgi->sockets[0].name, ':');
|
||||
tcp_port = strchr(uwsgi.sockets[0].name, ':');
|
||||
if (tcp_port == NULL) {
|
||||
fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n");
|
||||
exit(3);
|
||||
@@ -17,27 +19,27 @@ void nagios(struct uwsgi_server *uwsgi) {
|
||||
|
||||
tcp_port[0] = 0;
|
||||
|
||||
nagios_poll.fd = connect_to_tcp(uwsgi->sockets[0].name, atoi(tcp_port + 1), uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
nagios_poll.fd = connect_to_tcp(uwsgi.sockets[0].name, atoi(tcp_port + 1), uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (nagios_poll.fd < 0) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: could not connect() to workers\n");
|
||||
exit(2);
|
||||
}
|
||||
uwsgi->wsgi_req->uh.modifier1 = UWSGI_MODIFIER_PING;
|
||||
uwsgi->wsgi_req->uh.pktsize = 0;
|
||||
uwsgi->wsgi_req->uh.modifier2 = 0;
|
||||
if (write(nagios_poll.fd, uwsgi->wsgi_req, 4) != 4) {
|
||||
uwsgi.wsgi_req->uh.modifier1 = UWSGI_MODIFIER_PING;
|
||||
uwsgi.wsgi_req->uh.pktsize = 0;
|
||||
uwsgi.wsgi_req->uh.modifier2 = 0;
|
||||
if (write(nagios_poll.fd, uwsgi.wsgi_req, 4) != 4) {
|
||||
uwsgi_error("write()");
|
||||
fprintf(stdout, "UWSGI CRITICAL: could not send ping packet to workers\n");
|
||||
exit(2);
|
||||
}
|
||||
nagios_poll.events = POLLIN;
|
||||
if (!uwsgi_parse_response(&nagios_poll, uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) uwsgi->wsgi_req, uwsgi->wsgi_req->buffer)) {
|
||||
if (!uwsgi_parse_response(&nagios_poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) uwsgi.wsgi_req, uwsgi.wsgi_req->buffer)) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n");
|
||||
exit(2);
|
||||
}
|
||||
else {
|
||||
if (uwsgi->wsgi_req->uh.pktsize > 0) {
|
||||
fprintf(stdout, "UWSGI WARNING: %.*s\n", uwsgi->wsgi_req->uh.pktsize, uwsgi->wsgi_req->buffer);
|
||||
if (uwsgi.wsgi_req->uh.pktsize > 0) {
|
||||
fprintf(stdout, "UWSGI WARNING: %.*s\n", uwsgi.wsgi_req->uh.pktsize, uwsgi.wsgi_req->buffer);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
void embed_plugins(struct uwsgi_server *uwsgi) {
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void embed_plugins() {
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_PSGI
|
||||
if (uwsgi->plugin_arg_psgi)
|
||||
ret = uwsgi_load_plugin(uwsgi, 5, "psgi_plugin.so", uwsgi->plugin_arg_psgi, 0);
|
||||
if (uwsgi.plugin_arg_psgi)
|
||||
ret = uwsgi_load_plugin(uwsgi, 5, "psgi_plugin.so", uwsgi.plugin_arg_psgi, 0);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_LUA
|
||||
if (uwsgi->plugin_arg_lua)
|
||||
ret = uwsgi_load_plugin(uwsgi, 6, "lua_plugin.so", uwsgi->plugin_arg_lua, 0);
|
||||
if (uwsgi.plugin_arg_lua)
|
||||
ret = uwsgi_load_plugin(uwsgi, 6, "lua_plugin.so", uwsgi.plugin_arg_lua, 0);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGIN_RACK
|
||||
if (uwsgi->plugin_arg_rack)
|
||||
ret = uwsgi_load_plugin(uwsgi, 7, "rack_plugin.so", uwsgi->plugin_arg_rack, 0);
|
||||
if (uwsgi.plugin_arg_rack)
|
||||
ret = uwsgi_load_plugin(uwsgi, 7, "rack_plugin.so", uwsgi.plugin_arg_rack, 0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int uwsgi_load_plugin(struct uwsgi_server *uwsgi, int modifier, char *plugin, char *pargs, int absolute) {
|
||||
int uwsgi_load_plugin(int modifier, char *plugin, char *pargs, int absolute) {
|
||||
|
||||
char *plugin_name ;
|
||||
|
||||
void *plugin_handle;
|
||||
int (*plugin_init) (struct uwsgi_server *, char *);
|
||||
int (*plugin_request) (struct uwsgi_server *, struct wsgi_request *);
|
||||
void (*plugin_after_request) (struct uwsgi_server *, struct wsgi_request *);
|
||||
int (*plugin_init) (char *);
|
||||
int (*plugin_request) (struct wsgi_request *);
|
||||
void (*plugin_after_request) (struct wsgi_request *);
|
||||
|
||||
if (absolute) {
|
||||
plugin_name = malloc(strlen(plugin) + 1);
|
||||
@@ -51,7 +53,7 @@ int uwsgi_load_plugin(struct uwsgi_server *uwsgi, int modifier, char *plugin, ch
|
||||
else {
|
||||
plugin_init = dlsym(plugin_handle, "uwsgi_init");
|
||||
if (plugin_init) {
|
||||
if ((*plugin_init) (uwsgi, pargs)) {
|
||||
if ((*plugin_init) (pargs)) {
|
||||
uwsgi_log( "plugin initialization returned error\n");
|
||||
if (dlclose(plugin_handle)) {
|
||||
uwsgi_log( "unable to unload plugin\n");
|
||||
@@ -63,10 +65,10 @@ int uwsgi_load_plugin(struct uwsgi_server *uwsgi, int modifier, char *plugin, ch
|
||||
|
||||
plugin_request = dlsym(plugin_handle, "uwsgi_request");
|
||||
if (plugin_request) {
|
||||
uwsgi->shared->hooks[modifier] = plugin_request;
|
||||
uwsgi.shared->hooks[modifier] = plugin_request;
|
||||
plugin_after_request = dlsym(plugin_handle, "uwsgi_after_request");
|
||||
if (plugin_after_request) {
|
||||
uwsgi->shared->after_hooks[modifier] = plugin_after_request;
|
||||
uwsgi.shared->after_hooks[modifier] = plugin_after_request;
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
+3
-3
@@ -308,7 +308,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_parse_vars(struct wsgi_request *wsgi_req) {
|
||||
|
||||
char *buffer = wsgi_req->buffer;
|
||||
|
||||
@@ -426,7 +426,7 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
|
||||
wsgi_req->post_cl = get_content_length(ptrbuf, strsize);
|
||||
}
|
||||
|
||||
if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) {
|
||||
if (wsgi_req->var_cnt < uwsgi.vec_size - (4 + 1)) {
|
||||
wsgi_req->var_cnt++;
|
||||
}
|
||||
else {
|
||||
@@ -437,7 +437,7 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
|
||||
wsgi_req->hvec[wsgi_req->var_cnt].iov_base = ptrbuf;
|
||||
wsgi_req->hvec[wsgi_req->var_cnt].iov_len = strsize;
|
||||
//uwsgi_log("%.*s = %.*s\n", wsgi_req->hvec[wsgi_req->var_cnt-1].iov_len, wsgi_req->hvec[wsgi_req->var_cnt-1].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len, wsgi_req->hvec[wsgi_req->var_cnt].iov_base);
|
||||
if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) {
|
||||
if (wsgi_req->var_cnt < uwsgi.vec_size - (4 + 1)) {
|
||||
wsgi_req->var_cnt++;
|
||||
}
|
||||
else {
|
||||
|
||||
+41
-22
@@ -20,11 +20,11 @@ PyMethodDef uwsgi_eventfd_read_method[] = { {"uwsgi_eventfd_read", py_eventfd_re
|
||||
PyMethodDef uwsgi_eventfd_write_method[] = { {"uwsgi_eventfd_write", py_eventfd_write, METH_VARARGS, ""}};
|
||||
#endif
|
||||
|
||||
int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_interpreter) {
|
||||
int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, int new_interpreter) {
|
||||
|
||||
PyObject *zero;
|
||||
|
||||
int id = uwsgi->apps_cnt;
|
||||
int id = uwsgi.apps_cnt;
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
int i;
|
||||
@@ -33,33 +33,32 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
char *mountpoint;
|
||||
|
||||
struct uwsgi_app *wi;
|
||||
struct wsgi_request *wsgi_req = uwsgi->wsgi_req;
|
||||
|
||||
if (wsgi_req->script_name_len == 0) {
|
||||
wsgi_req->script_name = "";
|
||||
if (!uwsgi->vhost) id = 0;
|
||||
if (!uwsgi.vhost) id = 0;
|
||||
}
|
||||
else if (wsgi_req->script_name_len == 1) {
|
||||
if (wsgi_req->script_name[0] == '/') {
|
||||
if (!uwsgi->vhost) id = 0;
|
||||
if (!uwsgi.vhost) id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi->vhost && wsgi_req->host_len > 0) {
|
||||
if (uwsgi.vhost && wsgi_req->host_len > 0) {
|
||||
mountpoint = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|", 1, wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
}
|
||||
else {
|
||||
mountpoint = uwsgi_strncopy(wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
}
|
||||
|
||||
if (uwsgi_get_app_id(uwsgi, mountpoint, strlen(mountpoint)) != -1) {
|
||||
if (uwsgi_get_app_id(mountpoint, strlen(mountpoint)) != -1) {
|
||||
uwsgi_log( "mountpoint %.*s already configured. skip.\n", strlen(mountpoint), mountpoint);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
wi = &uwsgi->apps[id];
|
||||
wi = &uwsgi.apps[id];
|
||||
|
||||
memset(wi, 0, sizeof(struct uwsgi_app));
|
||||
wi->mountpoint = mountpoint;
|
||||
@@ -85,7 +84,7 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
exit(1);
|
||||
}
|
||||
PyThreadState_Swap(wi->interpreter);
|
||||
init_pyargv(uwsgi);
|
||||
init_pyargv();
|
||||
|
||||
#ifdef UWSGI_EMBEDDED
|
||||
// we need to inizialize an embedded module for every interpreter
|
||||
@@ -94,11 +93,11 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
init_uwsgi_vars();
|
||||
}
|
||||
else {
|
||||
wi->interpreter = uwsgi->main_thread;
|
||||
wi->interpreter = uwsgi.main_thread;
|
||||
}
|
||||
|
||||
|
||||
wi->wsgi_callable = uwsgi->loaders[loader](arg1);
|
||||
wi->wsgi_callable = uwsgi.loaders[loader](arg1);
|
||||
|
||||
if (!wi->wsgi_callable) {
|
||||
uwsgi_log("unable to load app SCRIPT_NAME=%s\n", mountpoint);
|
||||
@@ -106,13 +105,13 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wi->wsgi_environ = malloc(sizeof(PyObject*)*uwsgi->async);
|
||||
wi->wsgi_environ = malloc(sizeof(PyObject*)*uwsgi.async);
|
||||
if (!wi->wsgi_environ) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
wi->wsgi_environ[i] = PyDict_New();
|
||||
if (!wi->wsgi_environ[i]) {
|
||||
uwsgi_log("unable to allocate new env dictionary for app\n");
|
||||
@@ -172,13 +171,13 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
wi->wsgi_args = malloc(sizeof(PyObject*)*uwsgi->async);
|
||||
wi->wsgi_args = malloc(sizeof(PyObject*)*uwsgi.async);
|
||||
if (!wi->wsgi_args) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for(i=0;i<uwsgi->async;i++) {
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
wi->wsgi_args[i] = PyTuple_New(wi->argc);
|
||||
if (!wi->wsgi_args[i]) {
|
||||
uwsgi_log("unable to allocate new tuple for app args\n");
|
||||
@@ -187,7 +186,7 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
|
||||
// add start_response on WSGI app
|
||||
if (wi->argc == 2) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args[i], 1, uwsgi->wsgi_spitout)) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args[i], 1, uwsgi.wsgi_spitout)) {
|
||||
uwsgi_log("unable to set start_response in args tuple\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -197,7 +196,7 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
|
||||
wi->wsgi_args = PyTuple_New(wi->argc);
|
||||
if (wi->argc == 2) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args, 1, uwsgi->wsgi_spitout)) {
|
||||
if (PyTuple_SetItem(wi->wsgi_args, 1, uwsgi.wsgi_spitout)) {
|
||||
uwsgi_log("unable to set start_response in args tuple\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -217,7 +216,7 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
}
|
||||
|
||||
if (new_interpreter && id) {
|
||||
PyThreadState_Swap(uwsgi->main_thread);
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
|
||||
if (wi->argc == 1) {
|
||||
@@ -229,11 +228,11 @@ int init_uwsgi_app(int loader, void *arg1, struct uwsgi_server *uwsgi, int new_i
|
||||
|
||||
if (id == 0) {
|
||||
uwsgi_log(" (default app)");
|
||||
uwsgi->default_app = 0;
|
||||
if (uwsgi->vhost) uwsgi->apps_cnt++;
|
||||
uwsgi.default_app = 0;
|
||||
if (uwsgi.vhost) uwsgi.apps_cnt++;
|
||||
}
|
||||
else {
|
||||
uwsgi->apps_cnt++;
|
||||
uwsgi.apps_cnt++;
|
||||
}
|
||||
|
||||
uwsgi_log("\n");
|
||||
@@ -244,7 +243,7 @@ doh:
|
||||
PyErr_Print();
|
||||
if (new_interpreter && id) {
|
||||
Py_EndInterpreter(wi->interpreter);
|
||||
PyThreadState_Swap(uwsgi->main_thread);
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -318,6 +317,26 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) {
|
||||
|
||||
}
|
||||
|
||||
/* this is the mount loader, it loads app on mountpoint automagically */
|
||||
PyObject *uwsgi_mount_loader(void *arg1) {
|
||||
|
||||
PyObject *callable = NULL ;
|
||||
char *what = (char *) arg1;
|
||||
|
||||
if ( !strcmp(what+strlen(what)-3, ".py") || !strcmp(what+strlen(what)-3, ".wsgi")) {
|
||||
callable = uwsgi_file_loader((void *)what);
|
||||
}
|
||||
#ifdef UWSGI_PASTE
|
||||
else if (!strcmp(what+strlen(what)-4, ".ini")) {
|
||||
callable = uwsgi_paste_loader((void *)what);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
callable = uwsgi_uwsgi_loader((void *)what);
|
||||
}
|
||||
|
||||
return callable;
|
||||
}
|
||||
|
||||
|
||||
/* this is the dynamic loader, it loads app ireading nformation from a wsgi_request */
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
int manage_python_response(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int manage_python_response(struct wsgi_request *wsgi_req) {
|
||||
// use standard WSGI response parse
|
||||
return uwsgi_response_subhandler_wsgi(uwsgi, wsgi_req);
|
||||
return uwsgi_response_subhandler_wsgi(wsgi_req);
|
||||
}
|
||||
|
||||
PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
|
||||
@@ -29,14 +30,14 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
|
||||
|
||||
|
||||
|
||||
int uwsgi_python_call(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, PyObject *callable, PyObject *args) {
|
||||
int uwsgi_python_call(struct wsgi_request *wsgi_req, PyObject *callable, PyObject *args) {
|
||||
|
||||
wsgi_req->async_result = python_call(callable, args, 0);
|
||||
|
||||
if (wsgi_req->async_result) {
|
||||
while ( manage_python_response(uwsgi, wsgi_req) != UWSGI_OK) {
|
||||
while ( manage_python_response(wsgi_req) != UWSGI_OK) {
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
@@ -46,49 +47,49 @@ int uwsgi_python_call(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req,
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
void init_pyargv(struct uwsgi_server *uwsgi) {
|
||||
void init_pyargv() {
|
||||
|
||||
char *ap;
|
||||
|
||||
#ifdef PYTHREE
|
||||
wchar_t pname[6];
|
||||
mbstowcs(pname, "uwsgi", 6);
|
||||
uwsgi->py_argv[0] = pname;
|
||||
uwsgi.py_argv[0] = pname;
|
||||
#else
|
||||
uwsgi->py_argv[0] = "uwsgi";
|
||||
uwsgi.py_argv[0] = "uwsgi";
|
||||
#endif
|
||||
|
||||
if (uwsgi->pyargv != NULL && !uwsgi->pyargc) {
|
||||
uwsgi->pyargc++;
|
||||
if (uwsgi.pyargv != NULL && !uwsgi.pyargc) {
|
||||
uwsgi.pyargc++;
|
||||
#ifdef PYTHREE
|
||||
wchar_t *wcargv = malloc( sizeof( wchar_t ) * (strlen(uwsgi->pyargv)+1));
|
||||
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));
|
||||
memset(wcargv, 0, sizeof( wchar_t ) * (strlen(uwsgi.pyargv)+1));
|
||||
#endif
|
||||
|
||||
#ifdef __sun__
|
||||
// FIX THIS !!!
|
||||
ap = strtok(uwsgi->pyargv, " ");
|
||||
ap = strtok(uwsgi.pyargv, " ");
|
||||
while ((ap = strtok(NULL, " ")) != NULL) {
|
||||
#else
|
||||
while ((ap = strsep(&uwsgi->pyargv, " \t")) != NULL) {
|
||||
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);
|
||||
uwsgi.py_argv[uwsgi.pyargc] = wcargv + strlen(ap);
|
||||
#else
|
||||
uwsgi->py_argv[uwsgi->pyargc] = ap;
|
||||
uwsgi.py_argv[uwsgi.pyargc] = ap;
|
||||
#endif
|
||||
uwsgi->pyargc++;
|
||||
uwsgi.pyargc++;
|
||||
}
|
||||
if (uwsgi->pyargc + 1 > MAX_PYARGV)
|
||||
if (uwsgi.pyargc + 1 > MAX_PYARGV)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PySys_SetArgv(uwsgi->pyargc, uwsgi->py_argv);
|
||||
PySys_SetArgv(uwsgi.pyargc, uwsgi.py_argv);
|
||||
}
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ extern struct uwsgi_server uwsgi;
|
||||
|
||||
PyObject *py_uwsgi_sendfile(PyObject * self, PyObject * args) {
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|i:uwsgi_sendfile", &wsgi_req->async_sendfile, &wsgi_req->sendfile_fd_chunk)) {
|
||||
return NULL;
|
||||
@@ -29,7 +29,7 @@ PyObject *py_uwsgi_sendfile(PyObject * self, PyObject * args) {
|
||||
return (PyObject *) wsgi_req->sendfile_obj;
|
||||
}
|
||||
|
||||
ssize_t uwsgi_sendfile(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int fd = wsgi_req->sendfile_fd ;
|
||||
int sockfd = wsgi_req->poll.fd ;
|
||||
@@ -50,7 +50,7 @@ ssize_t uwsgi_sendfile(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
if (!wsgi_req->sendfile_fd_chunk) wsgi_req->sendfile_fd_chunk = 4096 ;
|
||||
|
||||
return uwsgi_do_sendfile(sockfd, wsgi_req->sendfile_fd, wsgi_req->sendfile_fd_size, wsgi_req->sendfile_fd_chunk, &wsgi_req->sendfile_fd_pos, uwsgi->async);
|
||||
return uwsgi_do_sendfile(sockfd, wsgi_req->sendfile_fd, wsgi_req->sendfile_fd_size, wsgi_req->sendfile_fd_chunk, &wsgi_req->sendfile_fd_pos, uwsgi.async);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifdef UWSGI_SPOOLER
|
||||
#include "uwsgi.h"
|
||||
|
||||
pid_t spooler_start(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
pid_t spooler_start() {
|
||||
int i;
|
||||
pid_t pid;
|
||||
|
||||
@@ -11,20 +13,20 @@ pid_t spooler_start(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
exit(1);
|
||||
}
|
||||
else if (pid == 0) {
|
||||
for(i=0;i<uwsgi->sockets_cnt;i++) {
|
||||
close(uwsgi->sockets[i].fd);
|
||||
for(i=0;i<uwsgi.sockets_cnt;i++) {
|
||||
close(uwsgi.sockets[i].fd);
|
||||
}
|
||||
spooler(uwsgi, uwsgi_module_dict);
|
||||
spooler(uwsgi.embedded_dict);
|
||||
}
|
||||
else if (pid > 0) {
|
||||
uwsgi_log( "spawned the uWSGI spooler on dir %s with pid %d\n", uwsgi->spool_dir, pid);
|
||||
uwsgi_log( "spawned the uWSGI spooler on dir %s with pid %d\n", uwsgi.spool_dir, pid);
|
||||
}
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buffer, int size) {
|
||||
int spool_request(char *filename, int rn, char *buffer, int size) {
|
||||
|
||||
char hostname[256 + 1];
|
||||
struct timeval tv;
|
||||
@@ -40,7 +42,7 @@ int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buff
|
||||
|
||||
hostname[256] = 0;
|
||||
|
||||
if (snprintf(filename, 1024, "%s/uwsgi_spoolfile_on_%s_%d_%d_%llu_%llu", uwsgi->spool_dir, hostname, (int) getpid(), rn, (unsigned long long) tv.tv_sec, (unsigned long long) tv.tv_usec) <= 0) {
|
||||
if (snprintf(filename, 1024, "%s/uwsgi_spoolfile_on_%s_%d_%d_%llu_%llu", uwsgi.spool_dir, hostname, (int) getpid(), rn, (unsigned long long) tv.tv_sec, (unsigned long long) tv.tv_usec) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -91,7 +93,7 @@ int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buff
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
void spooler() {
|
||||
DIR *sdir;
|
||||
struct dirent *dp;
|
||||
PyObject *spooler_callable, *spool_result, *spool_tuple, *spool_env;
|
||||
@@ -127,7 +129,7 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (chdir(uwsgi->spool_dir)) {
|
||||
if (chdir(uwsgi.spool_dir)) {
|
||||
uwsgi_error("chdir()");
|
||||
exit(1);
|
||||
}
|
||||
@@ -155,9 +157,9 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
|
||||
for (;;) {
|
||||
|
||||
sleep(uwsgi->shared->spooler_frequency);
|
||||
sleep(uwsgi.shared->spooler_frequency);
|
||||
|
||||
sdir = opendir(uwsgi->spool_dir);
|
||||
sdir = opendir(uwsgi.spool_dir);
|
||||
if (sdir) {
|
||||
while ((dp = readdir(sdir)) != NULL) {
|
||||
if (!strncmp("uwsgi_spoolfile_on_", dp->d_name, 19)) {
|
||||
@@ -171,7 +173,7 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
if (!access(dp->d_name, R_OK | W_OK)) {
|
||||
uwsgi_log( "managing spool request %s ...\n", dp->d_name);
|
||||
|
||||
spooler_callable = PyDict_GetItemString(uwsgi_module_dict, "spooler");
|
||||
spooler_callable = PyDict_GetItemString(uwsgi.embedded_dict, "spooler");
|
||||
if (!spooler_callable) {
|
||||
uwsgi_log( "you have to define uwsgi.spooler to use the spooler !!!\n");
|
||||
continue;
|
||||
@@ -313,12 +315,12 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
|
||||
}
|
||||
}
|
||||
|
||||
int uwsgi_request_spooler(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_spooler(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int i;
|
||||
char spool_filename[1024];
|
||||
|
||||
if (uwsgi->spool_dir == NULL) {
|
||||
if (uwsgi.spool_dir == NULL) {
|
||||
uwsgi_log( "the spooler is inactive !!!...skip\n");
|
||||
wsgi_req->uh.modifier1 = 255;
|
||||
wsgi_req->uh.pktsize = 0;
|
||||
@@ -331,7 +333,7 @@ int uwsgi_request_spooler(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_
|
||||
}
|
||||
|
||||
uwsgi_log( "managing spool request...\n");
|
||||
i = spool_request(uwsgi, spool_filename, uwsgi->workers[0].requests + 1, wsgi_req->buffer, wsgi_req->uh.pktsize);
|
||||
i = spool_request(spool_filename, uwsgi.workers[0].requests + 1, wsgi_req->buffer, wsgi_req->uh.pktsize);
|
||||
wsgi_req->uh.modifier1 = 255;
|
||||
wsgi_req->uh.pktsize = 0;
|
||||
if (i > 0) {
|
||||
|
||||
@@ -324,16 +324,16 @@ void uwsgi_as_root() {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int waitpid_status ;
|
||||
|
||||
gettimeofday(&wsgi_req->end_of_request, NULL);
|
||||
uwsgi->workers[uwsgi->mywid].running_time += (double) (((double) (wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec) - (double) (wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec)) / (double) 1000.0);
|
||||
uwsgi.workers[uwsgi.mywid].running_time += (double) (((double) (wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec) - (double) (wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec)) / (double) 1000.0);
|
||||
|
||||
|
||||
// get memory usage
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1)
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1)
|
||||
get_memusage();
|
||||
|
||||
|
||||
@@ -342,26 +342,26 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
|
||||
// TODO find a way to discard pending data
|
||||
close(wsgi_req->poll.fd);
|
||||
}
|
||||
uwsgi->workers[0].requests++;
|
||||
uwsgi->workers[uwsgi->mywid].requests++;
|
||||
uwsgi.workers[0].requests++;
|
||||
uwsgi.workers[uwsgi.mywid].requests++;
|
||||
|
||||
|
||||
// after_request hook
|
||||
(*uwsgi->shared->after_hooks[wsgi_req->uh.modifier1]) (uwsgi, wsgi_req);
|
||||
(*uwsgi.shared->after_hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
|
||||
// leave harakiri mode
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(0);
|
||||
}
|
||||
|
||||
// defunct process reaper
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_REAPER] == 1 || uwsgi->grunt) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_REAPER] == 1 || uwsgi.grunt) {
|
||||
while( waitpid(WAIT_ANY, &waitpid_status, WNOHANG) > 0) ;
|
||||
}
|
||||
// reset request
|
||||
memset(wsgi_req, 0, sizeof(struct wsgi_request));
|
||||
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_MAX_REQUESTS] > 0 && uwsgi->workers[uwsgi->mywid].requests >= uwsgi->shared->options[UWSGI_OPTION_MAX_REQUESTS]) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS] > 0 && uwsgi.workers[uwsgi.mywid].requests >= uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS]) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
@@ -408,17 +408,17 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
}
|
||||
|
||||
wsgi_req->async_status = (*uwsgi.shared->hooks[wsgi_req->uh.modifier1]) (&uwsgi, wsgi_req);
|
||||
wsgi_req->async_status = (*uwsgi.shared->hooks[wsgi_req->uh.modifier1]) (wsgi_req);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wsgi_req_accept(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int wsgi_req_accept(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
ret = poll(uwsgi->sockets_poll, uwsgi->sockets_cnt, -1);
|
||||
ret = poll(uwsgi.sockets_poll, uwsgi.sockets_cnt, -1);
|
||||
|
||||
if (ret < 0) {
|
||||
uwsgi_error("poll()");
|
||||
@@ -426,10 +426,10 @@ int wsgi_req_accept(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
|
||||
for(i=0;i<uwsgi->sockets_cnt;i++) {
|
||||
for(i=0;i<uwsgi.sockets_cnt;i++) {
|
||||
|
||||
if (uwsgi->sockets_poll[i].revents & POLLIN) {
|
||||
wsgi_req->poll.fd = accept(uwsgi->sockets_poll[i].fd, (struct sockaddr *) &wsgi_req->c_addr, (socklen_t *) &wsgi_req->c_len);
|
||||
if (uwsgi.sockets_poll[i].revents & POLLIN) {
|
||||
wsgi_req->poll.fd = accept(uwsgi.sockets_poll[i].fd, (struct sockaddr *) &wsgi_req->c_addr, (socklen_t *) &wsgi_req->c_len);
|
||||
|
||||
if (wsgi_req->poll.fd < 0) {
|
||||
uwsgi_error("accept()");
|
||||
@@ -443,43 +443,43 @@ int wsgi_req_accept(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline struct wsgi_request *current_wsgi_req(struct uwsgi_server *uwsgi) {
|
||||
|
||||
struct wsgi_request *wsgi_req = uwsgi->wsgi_req;
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
if (uwsgi->stackless && uwsgi->async >1) {
|
||||
inline struct wsgi_request *current_wsgi_req() {
|
||||
|
||||
struct wsgi_request *wsgi_req = uwsgi.wsgi_req;
|
||||
|
||||
if (uwsgi.stackless && uwsgi.async >1) {
|
||||
PyThreadState *ts = PyThreadState_GET();
|
||||
wsgi_req = find_request_by_tasklet(ts->st.current);
|
||||
}
|
||||
#endif
|
||||
|
||||
return wsgi_req;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void sanitize_args(struct uwsgi_server *uwsgi) {
|
||||
void sanitize_args() {
|
||||
|
||||
#ifdef UWSGI_UGREEN
|
||||
#ifdef UWSGI_THREADING
|
||||
if (uwsgi->ugreen) {
|
||||
if (uwsgi->has_threads) {
|
||||
if (uwsgi.ugreen) {
|
||||
if (uwsgi.has_threads) {
|
||||
uwsgi_log("--- python threads will be disabled in uGreen mode ---\n");
|
||||
uwsgi->has_threads = 0;
|
||||
uwsgi.has_threads = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
if (!uwsgi->post_buffering) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UWSGI_HTTP
|
||||
if (uwsgi->http && !uwsgi->http_only) {
|
||||
uwsgi->vacuum = 1;
|
||||
if (uwsgi.http && !uwsgi.http_only) {
|
||||
uwsgi.vacuum = 1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -791,15 +791,15 @@ char *uwsgi_strncopy(char *s, int len) {
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_get_app_id(struct uwsgi_server *uwsgi, char *script_name, int script_name_len) {
|
||||
int uwsgi_get_app_id(char *script_name, int script_name_len) {
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<uwsgi->apps_cnt;i++) {
|
||||
if (!uwsgi->apps[i].mountpoint_len) {
|
||||
for(i=0;i<uwsgi.apps_cnt;i++) {
|
||||
if (!uwsgi.apps[i].mountpoint_len) {
|
||||
continue;
|
||||
}
|
||||
if (!uwsgi_strncmp(uwsgi->apps[i].mountpoint, uwsgi->apps[i].mountpoint_len, script_name, script_name_len)) {
|
||||
if (!uwsgi_strncmp(uwsgi.apps[i].mountpoint, uwsgi.apps[i].mountpoint_len, script_name, script_name_len)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,6 +151,7 @@ static struct option long_options[] = {
|
||||
{"log-big", required_argument, 0, LONG_ARGS_LOG_BIG},
|
||||
{"chdir", required_argument, 0, LONG_ARGS_CHDIR},
|
||||
{"chdir2", required_argument, 0, LONG_ARGS_CHDIR2},
|
||||
{"mount", required_argument, 0, LONG_ARGS_MOUNT},
|
||||
{"grunt", no_argument, &uwsgi.grunt, 1},
|
||||
{"no-site", no_argument, &Py_NoSiteFlag, 1},
|
||||
{"vhost", no_argument, &uwsgi.vhost, 1},
|
||||
@@ -177,15 +178,15 @@ static struct option long_options[] = {
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
void ping(struct uwsgi_server *uwsgi) {
|
||||
void ping() {
|
||||
|
||||
struct uwsgi_header uh;
|
||||
struct pollfd uwsgi_poll;
|
||||
|
||||
// use a 3 secs timeout by default
|
||||
if (!uwsgi->ping_timeout) uwsgi->ping_timeout = 3 ;
|
||||
if (!uwsgi.ping_timeout) uwsgi.ping_timeout = 3 ;
|
||||
|
||||
uwsgi_poll.fd = uwsgi_connect(uwsgi->ping, uwsgi->ping_timeout);
|
||||
uwsgi_poll.fd = uwsgi_connect(uwsgi.ping, uwsgi.ping_timeout);
|
||||
if (uwsgi_poll.fd < 0) {
|
||||
exit(1);
|
||||
}
|
||||
@@ -198,7 +199,7 @@ void ping(struct uwsgi_server *uwsgi) {
|
||||
exit(2);
|
||||
}
|
||||
uwsgi_poll.events = POLLIN;
|
||||
if (!uwsgi_parse_response(&uwsgi_poll, uwsgi->ping_timeout, &uh, NULL)) {
|
||||
if (!uwsgi_parse_response(&uwsgi_poll, uwsgi.ping_timeout, &uh, NULL)) {
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
@@ -230,7 +231,7 @@ PyMethodDef null_methods[] = {
|
||||
};
|
||||
|
||||
void warn_pipe() {
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi.async < 2 && wsgi_req->uri_len > 0) {
|
||||
uwsgi_log("SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request %.*s !!!\n", wsgi_req->uri_len, wsgi_req->uri );
|
||||
@@ -325,7 +326,7 @@ void stats() {
|
||||
|
||||
void what_i_am_doing() {
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi.async < 2 && wsgi_req->uri_len > 0) {
|
||||
|
||||
@@ -349,12 +350,12 @@ int waitpid_status;
|
||||
struct timeval last_respawn;
|
||||
|
||||
|
||||
int unconfigured_hook(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int unconfigured_hook(struct wsgi_request *wsgi_req) {
|
||||
uwsgi_log("-- unavailable modifier requested: %d --\n", wsgi_req->uh.modifier1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void unconfigured_after_hook(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
static void unconfigured_after_hook(struct wsgi_request *wsgi_req) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -559,6 +560,15 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
else if (!strcmp(lazy+strlen(lazy)-5, ".wsgi")) {
|
||||
uwsgi.file_config = lazy;
|
||||
}
|
||||
else if (lazy[0] == '/' && strchr(lazy,'=')) {
|
||||
if (uwsgi.mounts_cnt < MAX_MOUNTPOINTS) {
|
||||
uwsgi.mounts[uwsgi.mounts_cnt] = lazy ;
|
||||
uwsgi.mounts_cnt++;
|
||||
}
|
||||
else {
|
||||
uwsgi_log("unable to add more that %d mountpoints\n", MAX_MOUNTPOINTS);
|
||||
}
|
||||
}
|
||||
else {
|
||||
uwsgi.wsgi_config = lazy;
|
||||
}
|
||||
@@ -577,7 +587,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
#endif
|
||||
#ifdef UWSGI_LDAP
|
||||
if (uwsgi.ldap != NULL) {
|
||||
uwsgi_ldap_config(&uwsgi, long_options);
|
||||
uwsgi_ldap_config(long_options);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -684,7 +694,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sanitize_args(&uwsgi);
|
||||
sanitize_args();
|
||||
|
||||
#ifdef UWSGI_HTTP
|
||||
if (uwsgi.http && !uwsgi.is_a_reload) {
|
||||
@@ -722,7 +732,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
|
||||
if (uwsgi.http_only) {
|
||||
http_loop(&uwsgi);
|
||||
http_loop();
|
||||
// never here
|
||||
exit(1);
|
||||
}
|
||||
@@ -731,7 +741,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
if (http_pid > 0) {
|
||||
masterpid = http_pid;
|
||||
http_loop(&uwsgi);
|
||||
http_loop();
|
||||
// never here
|
||||
exit(1);
|
||||
}
|
||||
@@ -866,7 +876,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
Py_Initialize();
|
||||
|
||||
|
||||
init_pyargv(&uwsgi);
|
||||
init_pyargv();
|
||||
|
||||
if (uwsgi.vhost) {
|
||||
uwsgi_log("VirtualHosting mode enabled.\n");
|
||||
@@ -932,14 +942,14 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
#ifdef UWSGI_NAGIOS
|
||||
if (uwsgi.nagios) {
|
||||
nagios(&uwsgi);
|
||||
nagios();
|
||||
// never here
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_UGREEN
|
||||
if (uwsgi.ugreen) {
|
||||
u_green_init(&uwsgi);
|
||||
u_green_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1209,7 +1219,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
uwsgi_log( "done.\n");
|
||||
|
||||
#ifdef UWSGI_EMBED_PLUGINS
|
||||
embed_plugins(&uwsgi);
|
||||
embed_plugins();
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ERLANG
|
||||
@@ -1236,6 +1246,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
uwsgi.loaders[LOADER_PASTE] = uwsgi_paste_loader;
|
||||
#endif
|
||||
uwsgi.loaders[LOADER_EVAL] = uwsgi_eval_loader;
|
||||
uwsgi.loaders[LOADER_MOUNT] = uwsgi_mount_loader;
|
||||
uwsgi.loaders[LOADER_CALLABLE] = uwsgi_callable_loader;
|
||||
uwsgi.loaders[LOADER_STRING_CALLABLE] = uwsgi_string_callable_loader;
|
||||
|
||||
@@ -1245,18 +1256,19 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
// the command line app loaders will be loaded in the main interpreter
|
||||
// (for performance reason, as this will avoid context switch)
|
||||
if (uwsgi.wsgi_config != NULL) {
|
||||
init_uwsgi_app(LOADER_UWSGI, uwsgi.wsgi_config, &uwsgi, 0);
|
||||
init_uwsgi_app(LOADER_UWSGI, uwsgi.wsgi_config, uwsgi.wsgi_req, 0);
|
||||
}
|
||||
else if (uwsgi.file_config != NULL) {
|
||||
init_uwsgi_app(LOADER_FILE, uwsgi.file_config, &uwsgi, 0);
|
||||
|
||||
if (uwsgi.file_config != NULL) {
|
||||
init_uwsgi_app(LOADER_FILE, uwsgi.file_config, uwsgi.wsgi_req, 0);
|
||||
}
|
||||
#ifdef UWSGI_PASTE
|
||||
else if (uwsgi.paste != NULL) {
|
||||
init_uwsgi_app(LOADER_PASTE, uwsgi.paste, &uwsgi, 0);
|
||||
if (uwsgi.paste != NULL) {
|
||||
init_uwsgi_app(LOADER_PASTE, uwsgi.paste, uwsgi.wsgi_req, 0);
|
||||
}
|
||||
#endif
|
||||
else if (uwsgi.eval != NULL) {
|
||||
init_uwsgi_app(LOADER_EVAL, uwsgi.eval, &uwsgi, 0);
|
||||
if (uwsgi.eval != NULL) {
|
||||
init_uwsgi_app(LOADER_EVAL, uwsgi.eval, uwsgi.wsgi_req, 0);
|
||||
}
|
||||
|
||||
// parse xml for <app> tags
|
||||
@@ -1266,6 +1278,21 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
#endif
|
||||
|
||||
for(i=0;i<uwsgi.mounts_cnt;i++) {
|
||||
char *what = strchr(uwsgi.mounts[i], '=');
|
||||
if (what) {
|
||||
what[0] = 0;
|
||||
what++;
|
||||
uwsgi.wsgi_req->script_name = uwsgi.mounts[i];
|
||||
uwsgi.wsgi_req->script_name_len = strlen(uwsgi.mounts[i]);
|
||||
init_uwsgi_app(LOADER_MOUNT, what, uwsgi.wsgi_req, 0);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("invalid mountpoint: %s\n", uwsgi.mounts[i]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.test_module != NULL) {
|
||||
if (PyImport_ImportModule(uwsgi.test_module)) {
|
||||
@@ -1302,18 +1329,18 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
#ifdef UWSGI_SPOOLER
|
||||
if (uwsgi.spool_dir != NULL && uwsgi.numproc > 0) {
|
||||
uwsgi.shared->spooler_pid = spooler_start(&uwsgi, uwsgi.embedded_dict);
|
||||
uwsgi.shared->spooler_pid = spooler_start();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
if (uwsgi.stackless) {
|
||||
stackless_init(&uwsgi);
|
||||
stackless_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
routing_setup(&uwsgi);
|
||||
routing_setup();
|
||||
#endif
|
||||
|
||||
if (!uwsgi.master_process) {
|
||||
@@ -1370,7 +1397,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
|
||||
if (getpid() == masterpid && uwsgi.master_process == 1) {
|
||||
master_loop(&uwsgi, argv, environ);
|
||||
master_loop(argv, environ);
|
||||
// from now on the process is a real worker
|
||||
}
|
||||
|
||||
@@ -1479,14 +1506,14 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
#ifdef UWSGI_UGREEN
|
||||
if (uwsgi.ugreen) {
|
||||
u_green_loop(&uwsgi);
|
||||
u_green_loop();
|
||||
// never here
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
if (uwsgi.stackless) {
|
||||
stackless_loop(&uwsgi);
|
||||
stackless_loop();
|
||||
// never here
|
||||
}
|
||||
#endif
|
||||
@@ -1514,9 +1541,9 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
if (uwsgi.async > 1) {
|
||||
|
||||
current_async_timeout = async_get_timeout(&uwsgi) ;
|
||||
current_async_timeout = async_get_timeout() ;
|
||||
uwsgi.async_nevents = async_wait(uwsgi.async_queue, uwsgi.async_events, uwsgi.async, uwsgi.async_running, current_async_timeout);
|
||||
async_expire_timeouts(&uwsgi);
|
||||
async_expire_timeouts();
|
||||
|
||||
if (uwsgi.async_nevents < 0) {
|
||||
continue;
|
||||
@@ -1526,7 +1553,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
if ( (int) uwsgi.async_events[i].ASYNC_FD == uwsgi.sockets[0].fd) {
|
||||
|
||||
uwsgi.wsgi_req = find_first_available_wsgi_req(&uwsgi);
|
||||
uwsgi.wsgi_req = find_first_available_wsgi_req();
|
||||
if (uwsgi.wsgi_req == NULL) {
|
||||
// async system is full !!!
|
||||
goto cycle;
|
||||
@@ -1534,7 +1561,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
wsgi_req_setup(uwsgi.wsgi_req, ( (uint8_t *)uwsgi.wsgi_req - (uint8_t *)uwsgi.wsgi_requests)/sizeof(struct wsgi_request) );
|
||||
|
||||
if (wsgi_req_accept(&uwsgi, uwsgi.wsgi_req)) {
|
||||
if (wsgi_req_accept(uwsgi.wsgi_req)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1548,7 +1575,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
}
|
||||
else {
|
||||
uwsgi.wsgi_req = find_wsgi_req_by_fd(&uwsgi, uwsgi.async_events[i].ASYNC_FD, uwsgi.async_events[i].ASYNC_EV);
|
||||
uwsgi.wsgi_req = find_wsgi_req_by_fd(uwsgi.async_events[i].ASYNC_FD, uwsgi.async_events[i].ASYNC_EV);
|
||||
if (uwsgi.wsgi_req) {
|
||||
uwsgi.wsgi_req->async_status = UWSGI_AGAIN ;
|
||||
uwsgi.wsgi_req->async_waiting_fd = -1 ;
|
||||
@@ -1560,7 +1587,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
|
||||
cycle:
|
||||
uwsgi.wsgi_req = async_loop(&uwsgi);
|
||||
uwsgi.wsgi_req = async_loop();
|
||||
|
||||
if (uwsgi.wsgi_req == NULL)
|
||||
continue ;
|
||||
@@ -1571,7 +1598,7 @@ cycle:
|
||||
#endif
|
||||
wsgi_req_setup(uwsgi.wsgi_req, 0);
|
||||
|
||||
if (wsgi_req_accept(&uwsgi, uwsgi.wsgi_req)) {
|
||||
if (wsgi_req_accept(uwsgi.wsgi_req)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1585,7 +1612,7 @@ reqclear:
|
||||
#endif
|
||||
|
||||
|
||||
uwsgi_close_request(&uwsgi, uwsgi.wsgi_req);
|
||||
uwsgi_close_request(uwsgi.wsgi_req);
|
||||
}
|
||||
|
||||
if (uwsgi.workers[uwsgi.mywid].manage_next_request == 0) {
|
||||
@@ -1719,7 +1746,7 @@ void uwsgi_uwsgi_config(char *module) {
|
||||
if (!applications) {
|
||||
uwsgi_log( "applications dictionary is not defined, trying with the \"application\" callable.\n");
|
||||
quick_callable = uwsgi_concat3(module, ":", quick_callable);
|
||||
if (init_uwsgi_app(LOADER_UWSGI, (void *) quick_callable, &uwsgi, 0) < 0) {
|
||||
if (init_uwsgi_app(LOADER_UWSGI, (void *) quick_callable, uwsgi.wsgi_req, 0) < 0) {
|
||||
uwsgi_log( "...goodbye cruel world...\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1769,7 +1796,7 @@ void uwsgi_uwsgi_config(char *module) {
|
||||
#else
|
||||
if (PyString_Check(app_app)) {
|
||||
#endif
|
||||
if (init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) PyString_AsString(app_app), &uwsgi, 0) < 0) {
|
||||
if (init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) PyString_AsString(app_app), uwsgi.wsgi_req, 0) < 0) {
|
||||
uwsgi_log( "...goodbye cruel world...\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -1777,7 +1804,7 @@ void uwsgi_uwsgi_config(char *module) {
|
||||
|
||||
}
|
||||
else {
|
||||
if (init_uwsgi_app(LOADER_CALLABLE, (void *) app_app, &uwsgi, 0) < 0) {
|
||||
if (init_uwsgi_app(LOADER_CALLABLE, (void *) app_app, uwsgi.wsgi_req, 0) < 0) {
|
||||
uwsgi_log( "...goodbye cruel world...\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -2154,12 +2181,12 @@ void manage_opt(int i, char *optarg) {
|
||||
break;
|
||||
#endif
|
||||
case LONG_ARGS_PYTHONPATH:
|
||||
if (uwsgi.python_path_cnt < 63) {
|
||||
if (uwsgi.python_path_cnt < MAX_PYTHONPATH) {
|
||||
uwsgi.python_path[uwsgi.python_path_cnt] = optarg;
|
||||
uwsgi.python_path_cnt++;
|
||||
}
|
||||
else {
|
||||
uwsgi_log( "you can specify at most 64 --pythonpath options\n");
|
||||
uwsgi_log( "you can specify at most %d --pythonpath options\n", MAX_PYTHONPATH);
|
||||
}
|
||||
break;
|
||||
case LONG_ARGS_LIMIT_AS:
|
||||
@@ -2251,6 +2278,15 @@ void manage_opt(int i, char *optarg) {
|
||||
case LONG_ARGS_LOG_BIG:
|
||||
uwsgi.shared->options[UWSGI_OPTION_LOG_BIG] = atoi(optarg);
|
||||
break;
|
||||
case LONG_ARGS_MOUNT:
|
||||
if (uwsgi.mounts_cnt < MAX_MOUNTPOINTS) {
|
||||
uwsgi.mounts[uwsgi.mounts_cnt] = optarg;
|
||||
uwsgi.mounts_cnt++;
|
||||
}
|
||||
else {
|
||||
uwsgi_log( "you can specify at most %d --mount options\n", MAX_MOUNTPOINTS);
|
||||
}
|
||||
break;
|
||||
#ifdef UWSGI_SPOOLER
|
||||
case 'Q':
|
||||
uwsgi.spool_dir = malloc(PATH_MAX);
|
||||
@@ -2446,6 +2482,7 @@ void manage_opt(int i, char *optarg) {
|
||||
\t--stackless\t\t\tenable usage of tasklet (only on Stackless Python)\n\
|
||||
\t--no-site\t\t\tdo not import site.py on startup\n\
|
||||
\t--vhost\t\t\t\tenable virtual hosting\n\
|
||||
\t--mount MOUNTPOINT=app\t\tadda new app under MOUNTPOINT\n\
|
||||
\t--routing\t\t\tenable uWSGI advanced routing\n\
|
||||
\t--http <addr>\t\t\tstart embedded HTTP server on <addr>\n\
|
||||
\t--http-only\t\t\tstart only the embedded HTTP server\n\
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
#define wsgi_req_time ((wsgi_req->end_of_request.tv_sec * 1000000 + wsgi_req->end_of_request.tv_usec) - (wsgi_req->start_of_request.tv_sec * 1000000 + wsgi_req->start_of_request.tv_usec))/1000
|
||||
|
||||
#define MAX_APPS 64
|
||||
#define MAX_MOUNTPOINTS 64
|
||||
#define MAX_PYTHONPATH 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
@@ -197,6 +201,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
|
||||
#define LONG_ARGS_LOG_4xx 17050
|
||||
#define LONG_ARGS_LOG_5xx 17051
|
||||
#define LONG_ARGS_LOG_BIG 17052
|
||||
#define LONG_ARGS_MOUNT 17053
|
||||
|
||||
|
||||
|
||||
@@ -337,8 +342,8 @@ struct uwsgi_app {
|
||||
PyObject *wsgi_eventfd_write;
|
||||
#endif
|
||||
|
||||
void* (*request_subhandler)(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_app *);
|
||||
int (*response_subhandler)(struct uwsgi_server *, struct wsgi_request *);
|
||||
void* (*request_subhandler)(struct wsgi_request *, struct uwsgi_app *);
|
||||
int (*response_subhandler)(struct wsgi_request *);
|
||||
|
||||
int argc;
|
||||
int requests;
|
||||
@@ -367,7 +372,7 @@ struct uwsgi_route {
|
||||
void *callable_args;
|
||||
int args;
|
||||
|
||||
void (*action)(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_route *);
|
||||
void (*action)(struct wsgi_request *, struct uwsgi_route *);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -493,8 +498,9 @@ struct wsgi_request {
|
||||
#define LOADER_EVAL 4
|
||||
#define LOADER_CALLABLE 5
|
||||
#define LOADER_STRING_CALLABLE 6
|
||||
#define LOADER_MOUNT 7
|
||||
|
||||
#define LOADER_MAX 7
|
||||
#define LOADER_MAX 8
|
||||
|
||||
struct uwsgi_server {
|
||||
|
||||
@@ -653,7 +659,7 @@ struct uwsgi_server {
|
||||
|
||||
char *file_config;
|
||||
|
||||
char *python_path[64];
|
||||
char *python_path[MAX_PYTHONPATH];
|
||||
int python_path_cnt;
|
||||
char *pyargv;
|
||||
|
||||
@@ -704,7 +710,7 @@ struct uwsgi_server {
|
||||
|
||||
struct uwsgi_shared *shared;
|
||||
|
||||
struct uwsgi_app apps[64];
|
||||
struct uwsgi_app apps[MAX_APPS];
|
||||
|
||||
#ifdef UWSGI_ERLANG
|
||||
int erlang_nodes;
|
||||
@@ -773,6 +779,9 @@ struct uwsgi_server {
|
||||
PyObject *pyloader_dict;
|
||||
|
||||
PyObject* (*loaders[LOADER_MAX]) (void *);
|
||||
|
||||
char *mounts[MAX_MOUNTPOINTS];
|
||||
int mounts_cnt;
|
||||
};
|
||||
|
||||
struct uwsgi_cluster_node {
|
||||
@@ -805,8 +814,8 @@ struct uwsgi_shared {
|
||||
// vga 80x25 specific !
|
||||
char warning_message[81];
|
||||
|
||||
int (*hooks[256]) (struct uwsgi_server *, struct wsgi_request *);
|
||||
void (*after_hooks[256]) (struct uwsgi_server *, struct wsgi_request *);
|
||||
int (*hooks[256]) (struct wsgi_request *);
|
||||
void (*after_hooks[256]) (struct wsgi_request *);
|
||||
uint32_t options[256];
|
||||
|
||||
struct uwsgi_cluster_node nodes[MAX_CLUSTER_NODES];
|
||||
@@ -919,9 +928,9 @@ void snmp_init(void);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_SPOOLER
|
||||
int spool_request(struct uwsgi_server *, char *, int, char *, int);
|
||||
void spooler(struct uwsgi_server *, PyObject *);
|
||||
pid_t spooler_start(struct uwsgi_server *, PyObject *);
|
||||
int spool_request(char *, int, char *, int);
|
||||
void spooler();
|
||||
pid_t spooler_start();
|
||||
#endif
|
||||
|
||||
void set_harakiri(int);
|
||||
@@ -933,7 +942,7 @@ uint32_t uwsgi_swap32(uint32_t);
|
||||
uint64_t uwsgi_swap64(uint64_t);
|
||||
#endif
|
||||
|
||||
int init_uwsgi_app(int, void *, struct uwsgi_server *, int);
|
||||
int init_uwsgi_app(int, void *, struct wsgi_request *wsgi_req, int);
|
||||
|
||||
PyObject *uwsgi_send_message(const char *, int, uint8_t, uint8_t, char *, int, int);
|
||||
|
||||
@@ -942,22 +951,22 @@ ssize_t send_udp_message(uint8_t, char *, char *, uint16_t);
|
||||
#endif
|
||||
|
||||
int uwsgi_parse_response(struct pollfd *, int, struct uwsgi_header *, char *);
|
||||
int uwsgi_parse_vars(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_parse_vars(struct wsgi_request *);
|
||||
|
||||
int uwsgi_enqueue_message(char *, int, uint8_t, uint8_t, char *, int, int);
|
||||
|
||||
/* included HOOKS */
|
||||
int uwsgi_request_wsgi(struct uwsgi_server *, struct wsgi_request *);
|
||||
void uwsgi_after_request_wsgi(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_wsgi(struct wsgi_request *);
|
||||
void uwsgi_after_request_wsgi(struct wsgi_request *);
|
||||
|
||||
int uwsgi_request_admin(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_admin(struct wsgi_request *);
|
||||
#ifdef UWSGI_SPOOLER
|
||||
int uwsgi_request_spooler(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_spooler(struct wsgi_request *);
|
||||
#endif
|
||||
int uwsgi_request_eval(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_fastfunc(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_marshal(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_ping(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_eval(struct wsgi_request *);
|
||||
int uwsgi_request_fastfunc(struct wsgi_request *);
|
||||
int uwsgi_request_marshal(struct wsgi_request *);
|
||||
int uwsgi_request_ping(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_ERLANG
|
||||
|
||||
@@ -988,15 +997,15 @@ struct http_status_codes {
|
||||
};
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
struct wsgi_request *async_loop(struct uwsgi_server *);
|
||||
struct wsgi_request *find_first_available_wsgi_req(struct uwsgi_server *);
|
||||
struct wsgi_request *find_wsgi_req_by_fd(struct uwsgi_server *, int, int);
|
||||
struct wsgi_request *find_wsgi_req_by_id(struct uwsgi_server *, int);
|
||||
struct wsgi_request *async_loop(void);
|
||||
struct wsgi_request *find_first_available_wsgi_req(void);
|
||||
struct wsgi_request *find_wsgi_req_by_fd(int, int);
|
||||
struct wsgi_request *find_wsgi_req_by_id(int);
|
||||
|
||||
#ifdef __clang__
|
||||
struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
|
||||
struct wsgi_request *next_wsgi_req(struct wsgi_request *);
|
||||
#else
|
||||
inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
|
||||
inline struct wsgi_request *next_wsgi_req(struct wsgi_request *);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1006,11 +1015,11 @@ int async_wait(int, void *, int, int, int);
|
||||
int async_del(int, int , int) ;
|
||||
int async_queue_init(int);
|
||||
|
||||
int async_get_timeout(struct uwsgi_server *);
|
||||
int async_get_timeout(void);
|
||||
void async_set_timeout(struct wsgi_request *, time_t);
|
||||
void async_expire_timeouts(struct uwsgi_server *);
|
||||
void async_write_all(struct uwsgi_server *, char *, size_t);
|
||||
void async_unpause_all(struct uwsgi_server *);
|
||||
void async_expire_timeouts(void);
|
||||
void async_write_all(char *, size_t);
|
||||
void async_unpause_all(void);
|
||||
|
||||
#ifdef __linux__
|
||||
#define ASYNC_FD data.fd
|
||||
@@ -1045,13 +1054,13 @@ PyObject *py_eventfd_write(PyObject *, PyObject *) ;
|
||||
PyObject *py_uwsgi_stackless(PyObject *, PyObject *) ;
|
||||
#endif
|
||||
|
||||
int manage_python_response(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_python_call(struct uwsgi_server *, struct wsgi_request *, PyObject *, PyObject *);
|
||||
int manage_python_response(struct wsgi_request *);
|
||||
int uwsgi_python_call(struct wsgi_request *, PyObject *, PyObject *);
|
||||
PyObject *python_call(PyObject *, PyObject *, int);
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
PyObject *py_uwsgi_sendfile(PyObject *, PyObject *) ;
|
||||
ssize_t uwsgi_sendfile(struct uwsgi_server *, struct wsgi_request *);
|
||||
ssize_t uwsgi_sendfile(struct wsgi_request *);
|
||||
ssize_t uwsgi_do_sendfile(int, int, size_t, size_t, off_t*, int);
|
||||
#endif
|
||||
|
||||
@@ -1061,7 +1070,7 @@ PyObject *py_uwsgi_spit(PyObject *, PyObject *) ;
|
||||
void uwsgi_as_root(void);
|
||||
|
||||
#ifdef UWSGI_NAGIOS
|
||||
void nagios(struct uwsgi_server *);
|
||||
void nagios(void);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1073,28 +1082,32 @@ struct stackless_req {
|
||||
};
|
||||
struct wsgi_request *find_request_by_tasklet(PyTaskletObject *);
|
||||
|
||||
void stackless_init(struct uwsgi_server *);
|
||||
void stackless_loop(struct uwsgi_server *);
|
||||
void stackless_init(void);
|
||||
void stackless_loop(void);
|
||||
#endif
|
||||
|
||||
void uwsgi_close_request(struct uwsgi_server *, struct wsgi_request *) ;
|
||||
void uwsgi_close_request(struct wsgi_request *) ;
|
||||
|
||||
void wsgi_req_setup(struct wsgi_request *, int);
|
||||
int wsgi_req_recv(struct wsgi_request *);
|
||||
int wsgi_req_accept(struct uwsgi_server *, struct wsgi_request *);
|
||||
int wsgi_req_accept(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_UGREEN
|
||||
void u_green_init(struct uwsgi_server *);
|
||||
void u_green_loop(struct uwsgi_server *);
|
||||
void u_green_init(void);
|
||||
void u_green_loop(void);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
#ifdef __clang__
|
||||
struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
|
||||
struct wsgi_request *current_wsgi_req(void);
|
||||
#else
|
||||
inline struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
|
||||
inline struct wsgi_request *current_wsgi_req(void);
|
||||
#endif
|
||||
#else
|
||||
#define current_wsgi_req() uwsgi.wsgi_req
|
||||
#endif
|
||||
|
||||
void sanitize_args(struct uwsgi_server *);
|
||||
void sanitize_args(void);
|
||||
|
||||
void env_to_arg(char *, char *);
|
||||
void parse_sys_envs(char **, struct option *);
|
||||
@@ -1108,8 +1121,8 @@ void uwsgi_log_verbose(const char *, ...);
|
||||
#define EVDIS_TYPE_DNSSD
|
||||
#endif
|
||||
|
||||
int uwsgi_load_plugin(struct uwsgi_server *, int, char *, char *, int);
|
||||
void embed_plugins(struct uwsgi_server *);
|
||||
int uwsgi_load_plugin(int, char *, char *, int);
|
||||
void embed_plugins(void);
|
||||
|
||||
|
||||
// PLUGINS
|
||||
@@ -1167,17 +1180,17 @@ void embed_plugins(struct uwsgi_server *);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
void routing_setup(struct uwsgi_server *);
|
||||
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 *);
|
||||
void routing_setup(void);
|
||||
void check_route(struct wsgi_request *);
|
||||
void uwsgi_route_action_uwsgi(struct wsgi_request *, struct uwsgi_route *);
|
||||
void uwsgi_route_action_wsgi(struct wsgi_request *, struct uwsgi_route *);
|
||||
#endif
|
||||
|
||||
void init_pyargv(struct uwsgi_server *);
|
||||
void init_pyargv(void);
|
||||
|
||||
void http_loop(struct uwsgi_server *);
|
||||
void http_loop();
|
||||
|
||||
int unconfigured_hook(struct uwsgi_server *, struct wsgi_request *);
|
||||
int unconfigured_hook(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_INI
|
||||
void uwsgi_ini_config(char *, struct option*);
|
||||
@@ -1187,7 +1200,7 @@ void uwsgi_ini_config(char *, struct option*);
|
||||
#ifdef UWSGI_LDAP
|
||||
void uwsgi_ldap_schema_dump(struct option*);
|
||||
void uwsgi_ldap_schema_dump_ldif(struct option*);
|
||||
void uwsgi_ldap_config(struct uwsgi_server *, struct option*);
|
||||
void uwsgi_ldap_config(struct option*);
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
@@ -1204,22 +1217,22 @@ char *uwsgi_concat3(char *, char *, char *);
|
||||
char *uwsgi_concat3n(char *, int, char *, int, char *, int);
|
||||
|
||||
|
||||
void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_wsgi(struct uwsgi_server *, struct wsgi_request *);
|
||||
void *uwsgi_request_subhandler_wsgi(struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_wsgi(struct wsgi_request *);
|
||||
|
||||
#ifdef UWSGI_WEB3
|
||||
void *uwsgi_request_subhandler_web3(struct uwsgi_server *, struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_web3(struct uwsgi_server *, struct wsgi_request *);
|
||||
void *uwsgi_request_subhandler_web3(struct wsgi_request *, struct uwsgi_app *);
|
||||
int uwsgi_response_subhandler_web3(struct wsgi_request *);
|
||||
#endif
|
||||
|
||||
int uwsgi_get_app_id(struct uwsgi_server *, char *, int);
|
||||
int uwsgi_get_app_id(char *, int);
|
||||
char *uwsgi_strncopy(char *, int );
|
||||
|
||||
void master_loop(struct uwsgi_server *, char **, char **);
|
||||
void master_loop(char **, char **);
|
||||
|
||||
|
||||
int find_worker_id(pid_t);
|
||||
void init_uwsgi_py_interpreter(struct uwsgi_server *, struct wsgi_request *);
|
||||
void init_uwsgi_py_interpreter(struct wsgi_request *);
|
||||
|
||||
|
||||
|
||||
@@ -1230,6 +1243,7 @@ PyObject *uwsgi_eval_loader(void *);
|
||||
PyObject *uwsgi_paste_loader(void *);
|
||||
PyObject *uwsgi_callable_loader(void *);
|
||||
PyObject *uwsgi_string_callable_loader(void *);
|
||||
PyObject *uwsgi_mount_loader(void *);
|
||||
|
||||
char *get_uwsgi_pymodule(char *);
|
||||
PyObject *get_uwsgi_pydict(char *);
|
||||
|
||||
+17
-15
@@ -1,14 +1,16 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
/* uwsgi PING|100 */
|
||||
int uwsgi_request_ping(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_ping(struct wsgi_request *wsgi_req) {
|
||||
char len;
|
||||
|
||||
uwsgi_log( "PING\n");
|
||||
wsgi_req->uh.modifier2 = 1;
|
||||
wsgi_req->uh.pktsize = 0;
|
||||
|
||||
len = strlen(uwsgi->shared->warning_message);
|
||||
len = strlen(uwsgi.shared->warning_message);
|
||||
if (len > 0) {
|
||||
// TODO: check endianess ?
|
||||
wsgi_req->uh.pktsize = len;
|
||||
@@ -18,7 +20,7 @@ int uwsgi_request_ping(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
if (write(wsgi_req->poll.fd, uwsgi->shared->warning_message, len)
|
||||
if (write(wsgi_req->poll.fd, uwsgi.shared->warning_message, len)
|
||||
!= len) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
@@ -28,7 +30,7 @@ int uwsgi_request_ping(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
}
|
||||
|
||||
/* uwsgi ADMIN|10 */
|
||||
int uwsgi_request_admin(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_admin(struct wsgi_request *wsgi_req) {
|
||||
uint32_t opt_value = 0;
|
||||
int i;
|
||||
|
||||
@@ -38,7 +40,7 @@ int uwsgi_request_admin(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_re
|
||||
}
|
||||
|
||||
uwsgi_log( "setting internal option %d to %d\n", wsgi_req->uh.modifier2, opt_value);
|
||||
uwsgi->shared->options[wsgi_req->uh.modifier2] = opt_value;
|
||||
uwsgi.shared->options[wsgi_req->uh.modifier2] = opt_value;
|
||||
|
||||
// ACK
|
||||
wsgi_req->uh.modifier1 = 255;
|
||||
@@ -55,7 +57,7 @@ int uwsgi_request_admin(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_re
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
int uwsgi_request_eval(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_eval(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *code, *py_dict;
|
||||
|
||||
@@ -84,38 +86,38 @@ int uwsgi_request_eval(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
}
|
||||
|
||||
/* uwsgi FASTFUNC|26 */
|
||||
int uwsgi_request_fastfunc(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_fastfunc(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *ffunc;
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (wsgi_req->async_status == UWSGI_AGAIN) {
|
||||
return manage_python_response(uwsgi, wsgi_req);
|
||||
return manage_python_response(wsgi_req);
|
||||
}
|
||||
#endif
|
||||
|
||||
ffunc = PyList_GetItem(uwsgi->fastfuncslist, wsgi_req->uh.modifier2);
|
||||
ffunc = PyList_GetItem(uwsgi.fastfuncslist, wsgi_req->uh.modifier2);
|
||||
if (ffunc) {
|
||||
uwsgi_log( "managing fastfunc %d\n", wsgi_req->uh.modifier2);
|
||||
return uwsgi_python_call(uwsgi, wsgi_req, ffunc, NULL);
|
||||
return uwsgi_python_call(wsgi_req, ffunc, NULL);
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
/* uwsgi MARSHAL|33 */
|
||||
int uwsgi_request_marshal(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_marshal(struct wsgi_request *wsgi_req) {
|
||||
PyObject *func_result;
|
||||
|
||||
PyObject *umm = PyDict_GetItemString(uwsgi->embedded_dict,
|
||||
PyObject *umm = PyDict_GetItemString(uwsgi.embedded_dict,
|
||||
"message_manager_marshal");
|
||||
if (umm) {
|
||||
PyObject *ummo = PyMarshal_ReadObjectFromString(wsgi_req->buffer,
|
||||
wsgi_req->uh.pktsize);
|
||||
if (ummo) {
|
||||
if (!PyTuple_SetItem(uwsgi->embedded_args, 0, ummo)) {
|
||||
if (!PyTuple_SetItem(uwsgi->embedded_args, 1, PyInt_FromLong(wsgi_req->uh.modifier2))) {
|
||||
func_result = PyEval_CallObject(umm, uwsgi->embedded_args);
|
||||
if (!PyTuple_SetItem(uwsgi.embedded_args, 0, ummo)) {
|
||||
if (!PyTuple_SetItem(uwsgi.embedded_args, 1, PyInt_FromLong(wsgi_req->uh.modifier2))) {
|
||||
func_result = PyEval_CallObject(umm, uwsgi.embedded_args);
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
+4
-4
@@ -509,7 +509,7 @@ PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args) {
|
||||
}
|
||||
}
|
||||
|
||||
i = spool_request(&uwsgi, spool_filename, uwsgi.workers[0].requests + 1, spool_buffer, cur_buf - spool_buffer);
|
||||
i = spool_request(spool_filename, uwsgi.workers[0].requests + 1, spool_buffer, cur_buf - spool_buffer);
|
||||
if (i > 0) {
|
||||
return Py_True;
|
||||
}
|
||||
@@ -714,7 +714,7 @@ PyObject *py_uwsgi_load_plugin(PyObject * self, PyObject * args) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (uwsgi_load_plugin(&uwsgi, modifier, plugin_name, pargs, 1)) {
|
||||
if (uwsgi_load_plugin(modifier, plugin_name, pargs, 1)) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
@@ -972,7 +972,7 @@ PyObject *py_uwsgi_mem(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) {
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
uwsgi_log( "disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid);
|
||||
|
||||
@@ -1091,7 +1091,7 @@ PyObject *py_uwsgi_grunt(PyObject * self, PyObject * args) {
|
||||
|
||||
pid_t grunt_pid ;
|
||||
int i;
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi.grunt) {
|
||||
uwsgi_log( "spawning a grunt from worker %d (pid :%d)...\n", uwsgi.mywid, uwsgi.mypid);
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ ASYNC=True
|
||||
UGREEN=False
|
||||
HTTP=True
|
||||
EVDIS=False
|
||||
LDAP=False
|
||||
LDAP=True
|
||||
WEB3=True
|
||||
ROUTING=False
|
||||
STACKLESS=False
|
||||
|
||||
+9
-7
@@ -1,6 +1,8 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
void *uwsgi_request_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
|
||||
PyObject *zero, *wsgi_socket;
|
||||
|
||||
@@ -22,7 +24,7 @@ void *uwsgi_request_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.run_once", Py_False);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.multithread", Py_False);
|
||||
if (uwsgi->numproc == 1) {
|
||||
if (uwsgi.numproc == 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "web3.multiprocess", Py_False);
|
||||
}
|
||||
else {
|
||||
@@ -49,7 +51,7 @@ void *uwsgi_request_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
|
||||
wsgi_req->async_app = wi->wsgi_callable ;
|
||||
|
||||
PyDict_SetItemString(uwsgi->embedded_dict, "env", wsgi_req->async_environ);
|
||||
PyDict_SetItemString(uwsgi.embedded_dict, "env", wsgi_req->async_environ);
|
||||
|
||||
// TODO: fix this
|
||||
//PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", uwsgi_version);
|
||||
@@ -58,11 +60,11 @@ void *uwsgi_request_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
// call
|
||||
|
||||
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi->catch_exceptions);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_response_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *pychunk ;
|
||||
ssize_t wsize ;
|
||||
@@ -97,7 +99,7 @@ int uwsgi_response_subhandler_web3(struct uwsgi_server *uwsgi, struct wsgi_reque
|
||||
goto clear2;
|
||||
}
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +140,7 @@ clear:
|
||||
}
|
||||
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
|
||||
fclose(wsgi_req->async_post);
|
||||
if (!uwsgi->post_buffering || wsgi_req->post_cl <= (size_t) uwsgi->post_buffering) {
|
||||
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
+40
-40
@@ -7,7 +7,7 @@ PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
|
||||
char *content;
|
||||
int len;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
data = PyTuple_GetItem(args, 0);
|
||||
if (PyString_Check(data)) {
|
||||
@@ -35,7 +35,7 @@ PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
|
||||
PyObject *py_eventfd_read(PyObject * self, PyObject * args) {
|
||||
int fd, timeout;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i|i", &fd, &timeout)) {
|
||||
return NULL;
|
||||
@@ -54,7 +54,7 @@ PyObject *py_eventfd_read(PyObject * self, PyObject * args) {
|
||||
PyObject *py_eventfd_write(PyObject * self, PyObject * args) {
|
||||
int fd, timeout;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i|i", &fd, &timeout)) {
|
||||
return NULL;
|
||||
@@ -70,7 +70,7 @@ PyObject *py_eventfd_write(PyObject * self, PyObject * args) {
|
||||
}
|
||||
#endif
|
||||
|
||||
int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int i;
|
||||
|
||||
@@ -103,7 +103,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
else {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_None);
|
||||
}
|
||||
return manage_python_response(uwsgi, wsgi_req);
|
||||
return manage_python_response(wsgi_req);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -113,13 +113,13 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi_parse_vars(uwsgi, wsgi_req)) {
|
||||
if (uwsgi_parse_vars(wsgi_req)) {
|
||||
uwsgi_log("Invalid WSGI request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi->limit_post) {
|
||||
if (wsgi_req->post_cl > uwsgi->limit_post) {
|
||||
if (uwsgi.limit_post) {
|
||||
if (wsgi_req->post_cl > uwsgi.limit_post) {
|
||||
uwsgi_log("Invalid (too big) CONTENT_LENGTH. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -127,18 +127,18 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
if (uwsgi->has_threads && !uwsgi->workers[uwsgi->mywid].i_have_gil) {
|
||||
PyEval_RestoreThread(uwsgi->_save);
|
||||
uwsgi->workers[uwsgi->mywid].i_have_gil = 1;
|
||||
if (uwsgi.has_threads && !uwsgi.workers[uwsgi.mywid].i_have_gil) {
|
||||
PyEval_RestoreThread(uwsgi._save);
|
||||
uwsgi.workers[uwsgi.mywid].i_have_gil = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!uwsgi->ignore_script_name) {
|
||||
if (!uwsgi.ignore_script_name) {
|
||||
|
||||
if (!wsgi_req->script_name)
|
||||
wsgi_req->script_name = "";
|
||||
|
||||
if (uwsgi->vhost) {
|
||||
if (uwsgi.vhost) {
|
||||
what = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|",1, wsgi_req->script_name, wsgi_req->script_name_len);
|
||||
what_len = wsgi_req->host_len + 1 + wsgi_req->script_name_len ;
|
||||
#ifdef UWSGI_DEBUG
|
||||
@@ -151,8 +151,8 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
}
|
||||
|
||||
|
||||
if ( (wsgi_req->app_id = uwsgi_get_app_id(uwsgi, what, what_len)) == -1) {
|
||||
if (wsgi_req->script_name_len > 1 || uwsgi->default_app < 0 || uwsgi->vhost) {
|
||||
if ( (wsgi_req->app_id = uwsgi_get_app_id(what, what_len)) == -1) {
|
||||
if (wsgi_req->script_name_len > 1 || uwsgi.default_app < 0 || uwsgi.vhost) {
|
||||
/* unavailable app for this SCRIPT_NAME */
|
||||
wsgi_req->app_id = -1;
|
||||
if (wsgi_req->wsgi_script_len > 0
|
||||
@@ -163,7 +163,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
#endif
|
||||
) {
|
||||
// a bit of magic: 1-1 = 0 / 0-1 = -1
|
||||
wsgi_req->app_id = init_uwsgi_app(LOADER_DYN, (void *) wsgi_req, uwsgi, uwsgi->single_interpreter-1);
|
||||
wsgi_req->app_id = init_uwsgi_app(LOADER_DYN, (void *) wsgi_req, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,8 +176,8 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
if (wsgi_req->app_id == -1) {
|
||||
// use default app ?
|
||||
if (!uwsgi->no_default_app && uwsgi->default_app >= 0) {
|
||||
wsgi_req->app_id = uwsgi->default_app ;
|
||||
if (!uwsgi.no_default_app && uwsgi.default_app >= 0) {
|
||||
wsgi_req->app_id = uwsgi.default_app ;
|
||||
}
|
||||
else {
|
||||
internal_server_error(wsgi_req->poll.fd, "wsgi application not found");
|
||||
@@ -186,9 +186,9 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
}
|
||||
|
||||
wi = &uwsgi->apps[wsgi_req->app_id];
|
||||
wi = &uwsgi.apps[wsgi_req->app_id];
|
||||
|
||||
if (uwsgi->single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
if (uwsgi.single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
if (!wi->interpreter) {
|
||||
internal_server_error(wsgi_req->poll.fd, "wsgi application's %d interpreter not found");
|
||||
goto clear2;
|
||||
@@ -274,7 +274,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
// set wsgi vars
|
||||
|
||||
|
||||
if (uwsgi->post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi->post_buffering) {
|
||||
if (uwsgi.post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi.post_buffering) {
|
||||
wsgi_req->async_post = tmpfile();
|
||||
if (!wsgi_req->async_post) {
|
||||
uwsgi_error("tmpfile()");
|
||||
@@ -283,11 +283,11 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
|
||||
while(post_remains > 0) {
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
}
|
||||
if (post_remains > (size_t) uwsgi->post_buffering_bufsize) {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi->post_buffering_bufsize);
|
||||
if (post_remains > (size_t) uwsgi.post_buffering_bufsize) {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize);
|
||||
}
|
||||
else {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, post_remains);
|
||||
@@ -309,14 +309,14 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
}
|
||||
|
||||
|
||||
wsgi_req->async_result = (*wi->request_subhandler)(uwsgi, wsgi_req, wi);
|
||||
wsgi_req->async_result = (*wi->request_subhandler)(wsgi_req, wi);
|
||||
|
||||
if (wsgi_req->async_result) {
|
||||
|
||||
|
||||
while ( (*wi->response_subhandler)(uwsgi, wsgi_req) != UWSGI_OK) {
|
||||
while ( (*wi->response_subhandler)(wsgi_req) != UWSGI_OK) {
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
@@ -324,7 +324,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
|
||||
}
|
||||
else if (uwsgi->catch_exceptions) {
|
||||
else if (uwsgi.catch_exceptions) {
|
||||
|
||||
wsgi_req->response_size += write(wsgi_req->poll.fd, wsgi_req->protocol, wsgi_req->protocol_len);
|
||||
wsgi_req->response_size += write(wsgi_req->poll.fd, " 500 Internal Server Error\r\n", 28 );
|
||||
@@ -357,9 +357,9 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
clear:
|
||||
|
||||
if (uwsgi->single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
if (uwsgi.single_interpreter == 0 && wsgi_req->app_id > 0) {
|
||||
// restoring main interpreter
|
||||
PyThreadState_Swap(uwsgi->main_thread);
|
||||
PyThreadState_Swap(uwsgi.main_thread);
|
||||
}
|
||||
|
||||
clear2:
|
||||
@@ -369,26 +369,26 @@ clear2:
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_after_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
void uwsgi_after_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOGGING]) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOGGING]) {
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
else {
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOG_ZERO]) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_ZERO]) {
|
||||
if (wsgi_req->response_size == 0) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOG_SLOW]) {
|
||||
if ((uint32_t) wsgi_req_time >= uwsgi->shared->options[UWSGI_OPTION_LOG_SLOW]) { log_request(wsgi_req); return; }
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) {
|
||||
if ((uint32_t) wsgi_req_time >= uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOG_4xx]) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_4xx]) {
|
||||
if (wsgi_req->status >= 400 && wsgi_req->status <= 499) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOG_5xx]) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_5xx]) {
|
||||
if (wsgi_req->status >= 500 && wsgi_req->status <= 599) { log_request(wsgi_req); return; }
|
||||
}
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_LOG_BIG]) {
|
||||
if (wsgi_req->response_size >= uwsgi->shared->options[UWSGI_OPTION_LOG_BIG]) { log_request(wsgi_req); return; }
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_BIG]) {
|
||||
if (wsgi_req->response_size >= uwsgi.shared->options[UWSGI_OPTION_LOG_BIG]) { log_request(wsgi_req); return; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
|
||||
PyObject *h_key, *h_value;
|
||||
int i, j;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
int base = 0;
|
||||
int shift = 0;
|
||||
|
||||
+15
-13
@@ -1,6 +1,8 @@
|
||||
#include "uwsgi.h"
|
||||
|
||||
void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_app *wi) {
|
||||
|
||||
PyObject *wsgi_socket, *zero;
|
||||
|
||||
@@ -13,7 +15,7 @@ void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.readable", wi->wsgi_eventfd_read);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.writable", wi->wsgi_eventfd_write);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_None);
|
||||
@@ -33,7 +35,7 @@ void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.run_once", Py_False);
|
||||
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multithread", Py_False);
|
||||
if (uwsgi->numproc == 1) {
|
||||
if (uwsgi.numproc == 1) {
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.multiprocess", Py_False);
|
||||
}
|
||||
else {
|
||||
@@ -60,15 +62,15 @@ void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
|
||||
wsgi_req->async_app = wi->wsgi_callable ;
|
||||
|
||||
PyDict_SetItemString(uwsgi->embedded_dict, "env", wsgi_req->async_environ);
|
||||
PyDict_SetItemString(uwsgi.embedded_dict, "env", wsgi_req->async_environ);
|
||||
|
||||
// TODO: fix here
|
||||
//PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.uwsgi.version", uwsgi_version);
|
||||
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
uwsgi_log("routing %d routes %d\n", uwsgi->routing, uwsgi->nroutes);
|
||||
if (uwsgi->routing && uwsgi->nroutes > 0) {
|
||||
uwsgi_log("routing %d routes %d\n", uwsgi.routing, uwsgi.nroutes);
|
||||
if (uwsgi.routing && uwsgi.nroutes > 0) {
|
||||
check_route(uwsgi, wsgi_req);
|
||||
}
|
||||
#endif
|
||||
@@ -78,10 +80,10 @@ void *uwsgi_request_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_requ
|
||||
|
||||
|
||||
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi->catch_exceptions);
|
||||
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
|
||||
}
|
||||
|
||||
int uwsgi_response_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *pychunk ;
|
||||
ssize_t wsize ;
|
||||
@@ -101,11 +103,11 @@ int uwsgi_response_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_reque
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
if (wsgi_req->sendfile_obj == wsgi_req->async_result && wsgi_req->sendfile_fd != -1) {
|
||||
sf_len = uwsgi_sendfile(uwsgi, wsgi_req);
|
||||
sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len < 1) goto clear;
|
||||
wsgi_req->response_size += sf_len ;
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
if (wsgi_req->response_size < wsgi_req->sendfile_fd_size) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
@@ -122,7 +124,7 @@ int uwsgi_response_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_reque
|
||||
goto clear2;
|
||||
}
|
||||
#ifdef UWSGI_ASYNC
|
||||
if (uwsgi->async > 1) {
|
||||
if (uwsgi.async > 1) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
#endif
|
||||
@@ -150,7 +152,7 @@ int uwsgi_response_subhandler_wsgi(struct uwsgi_server *uwsgi, struct wsgi_reque
|
||||
|
||||
#ifdef UWSGI_SENDFILE
|
||||
else if (wsgi_req->sendfile_obj == pychunk && wsgi_req->sendfile_fd != -1) {
|
||||
sf_len = uwsgi_sendfile(uwsgi, wsgi_req);
|
||||
sf_len = uwsgi_sendfile(wsgi_req);
|
||||
if (sf_len < 1) goto clear;
|
||||
wsgi_req->response_size += sf_len ;
|
||||
}
|
||||
@@ -168,7 +170,7 @@ clear:
|
||||
}
|
||||
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
|
||||
fclose(wsgi_req->async_post);
|
||||
if (!uwsgi->post_buffering || wsgi_req->post_cl <= (size_t) uwsgi->post_buffering) {
|
||||
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) node2->children->content, &uwsgi, uwsgi.single_interpreter-1);
|
||||
init_uwsgi_app(LOADER_STRING_CALLABLE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "eval")) {
|
||||
if (!node2->children) {
|
||||
@@ -206,7 +206,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_EVAL, (void *) node2->children->content, &uwsgi, uwsgi.single_interpreter-1);
|
||||
init_uwsgi_app(LOADER_EVAL, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "file")) {
|
||||
@@ -219,7 +219,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_FILE, (void *) node2->children->content, &uwsgi, uwsgi.single_interpreter-1);
|
||||
init_uwsgi_app(LOADER_FILE, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "module")) {
|
||||
@@ -232,7 +232,7 @@ next:
|
||||
continue;
|
||||
}
|
||||
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, &uwsgi, uwsgi.single_interpreter-1);
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
else if (!strcmp((char *) node2->name, "script")) {
|
||||
if (!node2->children) {
|
||||
@@ -243,7 +243,7 @@ next:
|
||||
uwsgi_log( "no script defined. skip.\n");
|
||||
continue;
|
||||
}
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, &uwsgi, uwsgi.single_interpreter-1);
|
||||
init_uwsgi_app(LOADER_UWSGI, (void *) node2->children->content, wsgi_req, uwsgi.single_interpreter-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user