diff --git a/core/offload.c b/core/offload.c index fadb1970..7690852a 100644 --- a/core/offload.c +++ b/core/offload.c @@ -107,7 +107,7 @@ error: return -1; } -static void uwsgi_offload_close(struct uwsgi_offload_request *uor) { +static void uwsgi_offload_close(struct uwsgi_thread *ut, struct uwsgi_offload_request *uor) { // close the socket and the file descriptor close(uor->s); close(uor->fd); @@ -115,12 +115,12 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) { struct uwsgi_offload_request *prev = uor->prev; struct uwsgi_offload_request *next = uor->next; - if (uor == uwsgi.offload_requests_head) { - uwsgi.offload_requests_head = next; + if (uor == ut->offload_requests_head) { + ut->offload_requests_head = next; } - if (uor == uwsgi.offload_requests_tail) { - uwsgi.offload_requests_tail = prev; + if (uor == ut->offload_requests_tail) { + ut->offload_requests_tail = prev; } if (prev) { @@ -142,22 +142,22 @@ static void uwsgi_offload_close(struct uwsgi_offload_request *uor) { free(uor); } -static void uwsgi_offload_append(struct uwsgi_offload_request *uor) { +static void uwsgi_offload_append(struct uwsgi_thread *ut, struct uwsgi_offload_request *uor) { - if (!uwsgi.offload_requests_head) { - uwsgi.offload_requests_head = uor; + if (!ut->offload_requests_head) { + ut->offload_requests_head = uor; } - if (uwsgi.offload_requests_tail) { - uwsgi.offload_requests_tail->next = uor; - uor->prev = uwsgi.offload_requests_tail; + if (ut->offload_requests_tail) { + ut->offload_requests_tail->next = uor; + uor->prev = ut->offload_requests_tail; } - uwsgi.offload_requests_tail = uor; + ut->offload_requests_tail = uor; } -static struct uwsgi_offload_request *uwsgi_offload_get_by_fd(int s) { - struct uwsgi_offload_request *uor = uwsgi.offload_requests_head; +static struct uwsgi_offload_request *uwsgi_offload_get_by_fd(struct uwsgi_thread *ut, int s) { + struct uwsgi_offload_request *uor = ut->offload_requests_head; while (uor) { if (uor->s == s || uor->fd == s) { return uor; @@ -187,20 +187,20 @@ static void uwsgi_offload_loop(struct uwsgi_thread *ut) { } // start monitoring socket for write if (uor->func(ut, uor, -1)) { - uwsgi_offload_close(uor); + uwsgi_offload_close(ut, uor); continue; } - uwsgi_offload_append(uor); + uwsgi_offload_append(ut, uor); continue; } // get the task from the interesting fd - struct uwsgi_offload_request *uor = uwsgi_offload_get_by_fd(interesting_fd); + struct uwsgi_offload_request *uor = uwsgi_offload_get_by_fd(ut, interesting_fd); if (!uor) continue; // run the hook if (uor->func(ut, uor, interesting_fd)) { - uwsgi_offload_close(uor); + uwsgi_offload_close(ut, uor); } } } diff --git a/core/protocol.c b/core/protocol.c index 1fe43206..f3d74d6f 100644 --- a/core/protocol.c +++ b/core/protocol.c @@ -1082,7 +1082,7 @@ nextcs: udd = uwsgi.static_maps; while (udd) { #ifdef UWSGI_DEBUG - uwsgi_log("checking for %.*s <-> %.*s\n", wsgi_req->path_info_len, wsgi_req->path_info, udd->keylen, udd->key); + uwsgi_log("checking for %.*s <-> %.*s %.*s\n", (int)wsgi_req->path_info_len, wsgi_req->path_info, (int)udd->keylen, udd->key, (int) udd->vallen, udd->value); #endif if (udd->status == 0) { #ifdef UWSGI_THREADING @@ -1092,6 +1092,7 @@ nextcs: char *real_docroot = uwsgi_malloc(PATH_MAX + 1); if (!realpath(udd->value, real_docroot)) { free(real_docroot); + real_docroot = NULL; udd->value = NULL; } #ifdef UWSGI_THREADING @@ -1128,6 +1129,7 @@ nextsm: char *real_docroot = uwsgi_malloc(PATH_MAX + 1); if (!realpath(udd->value, real_docroot)) { free(real_docroot); + real_docroot = NULL; udd->value = NULL; } #ifdef UWSGI_THREADING diff --git a/core/socket.c b/core/socket.c index bd4fcbde..de5c287d 100644 --- a/core/socket.c +++ b/core/socket.c @@ -718,7 +718,7 @@ int timed_connect(struct pollfd *fdpoll, const struct sockaddr *addr, int addr_s #if defined(__linux__) && defined(SOCK_NONBLOCK) && !defined(OBSOLETE_LINUX_KERNEL) - // hmm, nothing to do, as we are already non-blocking + uwsgi_socket_b(fdpoll->fd); #else /* re-set blocking socket */ arg &= (~O_NONBLOCK); diff --git a/core/utils.c b/core/utils.c index f9102582..f92c3c3b 100644 --- a/core/utils.c +++ b/core/utils.c @@ -4806,7 +4806,7 @@ static void *uwsgi_thread_run(void *arg) { struct uwsgi_thread *uwsgi_thread_new(void (*func) (struct uwsgi_thread *)) { - struct uwsgi_thread *ut = uwsgi_malloc(sizeof(struct uwsgi_thread)); + struct uwsgi_thread *ut = uwsgi_calloc(sizeof(struct uwsgi_thread)); #if defined(SOCK_SEQPACKET) && defined(__linux__) if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, ut->pipe)) { diff --git a/uwsgi.h b/uwsgi.h index ced945a8..4ccaad5a 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1529,10 +1529,6 @@ struct uwsgi_server { int check_static_docroot; - // linked list for offloaded requests - struct uwsgi_offload_request *offload_requests_head; - struct uwsgi_offload_request *offload_requests_tail; - char *daemonize; char *daemonize2; int do_not_change_umask; @@ -3409,6 +3405,9 @@ struct uwsgi_thread { uint64_t custom1; uint64_t custom2; uint64_t custom3; + // linked list for offloaded requests + struct uwsgi_offload_request *offload_requests_head; + struct uwsgi_offload_request *offload_requests_tail; void (*func)(struct uwsgi_thread *); }; struct uwsgi_thread *uwsgi_thread_new(void (*)(struct uwsgi_thread *));