From 734818c995578ee7b504dde27e642b272b40da29 Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Wed, 14 Mar 2012 08:28:25 +0100 Subject: [PATCH] fixed shared sockets --- gateway.c | 1 + lib/corerouter.h | 1 + master_utils.c | 5 ++++- uwsgi.c | 2 +- uwsgi.h | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gateway.c b/gateway.c index df577957..f6cbd296 100644 --- a/gateway.c +++ b/gateway.c @@ -107,6 +107,7 @@ struct uwsgi_gateway_socket *uwsgi_new_gateway_socket(char *name, char *owner) { memset(uwsgi_sock, 0, sizeof(struct uwsgi_gateway_socket)); uwsgi_sock->fd = -1; + uwsgi_sock->shared = 0; uwsgi_sock->name = name; uwsgi_sock->owner = owner; diff --git a/lib/corerouter.h b/lib/corerouter.h index 0ae99e91..2a84c66a 100644 --- a/lib/corerouter.h +++ b/lib/corerouter.h @@ -17,6 +17,7 @@ static void uwsgi_corerouter_setup_sockets(char *gw_id) { int shared_socket = atoi(ugs->name+1); if (shared_socket >= 0) { ugs->fd = uwsgi_get_shared_socket_fd_by_num(shared_socket); + ugs->shared = 1; if (ugs->fd == -1) { uwsgi_log("unable to use shared socket %d\n", shared_socket); exit(1); diff --git a/master_utils.c b/master_utils.c index 232b578b..248c5baf 100644 --- a/master_utils.c +++ b/master_utils.c @@ -371,7 +371,10 @@ void uwsgi_fixup_fds(int wid, int muleid, struct uwsgi_gateway *ug) { ugs = ugs->next; continue; } - close(ugs->fd); + // do not close shared sockets !!! + if (!ugs->shared) { + close(ugs->fd); + } ugs = ugs->next; } // fix the communication pipe diff --git a/uwsgi.c b/uwsgi.c index c7e2c69f..51d0a601 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1670,7 +1670,7 @@ int main(int argc, char *argv[], char *envp[]) { uwsgi_sock->fd = shared_sock->fd; uwsgi_sock->family = shared_sock->family; uwsgi_sock->name = shared_sock->name; - uwsgi_log("uwsgi socket %d mapped to shared socket %d (%s)\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_get_shared_socket_num(shared_sock), shared_sock->name); + uwsgi_log("uwsgi socket %d mapped to shared socket %d (%s) fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_get_shared_socket_num(shared_sock), shared_sock->name, uwsgi_sock->fd); } uwsgi_sock = uwsgi_sock->next; diff --git a/uwsgi.h b/uwsgi.h index 41003858..6dfd44c6 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -394,6 +394,7 @@ struct uwsgi_gateway_socket { // this requires SCTP int sctp; #endif + int shared; char *owner; struct uwsgi_gateway *gateway;