From 31bd3fa6c451e54129a4fc5247a937979a016156 Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Fri, 17 Dec 2010 17:13:45 +0100 Subject: [PATCH] use uwsgi_signal framework for better/portable --no-orphans --- master.c | 1 + protocol.c | 12 +----- utils.c | 109 +++++++++++++++++------------------------------ uwsgi.c | 122 +++++++++++++---------------------------------------- uwsgi.h | 5 ++- 5 files changed, 75 insertions(+), 174 deletions(-) diff --git a/master.c b/master.c index f943d167..52c63d1e 100644 --- a/master.c +++ b/master.c @@ -440,6 +440,7 @@ void master_loop(char **argv, char **environ) { } else { uwsgi_log_verbose("lost connection with worker %d\n", i+1); + close(uwsgi_signal_poll[i].fd); } } } diff --git a/protocol.c b/protocol.c index 6c42a51b..2d4bda67 100644 --- a/protocol.c +++ b/protocol.c @@ -597,11 +597,7 @@ int uwsgi_get_dgram(int fd, struct wsgi_request *wsgi_req) { socklen_t sin_len = sizeof(struct sockaddr_in); if (!buffer) { - buffer = malloc(uwsgi.buffer_size + 4); - if (!buffer) { - uwsgi_error("malloc()"); - exit(1); - } + buffer = uwsgi_malloc(uwsgi.buffer_size + 4); } @@ -747,11 +743,7 @@ int uwsgi_string_sendto(int fd, uint8_t modifier1, uint8_t modifier2, struct soc ssize_t rlen ; struct uwsgi_header *uh; - char *upkt = malloc(len + 4); - if (!upkt) { - uwsgi_error("malloc()"); - exit(1); - } + char *upkt = uwsgi_malloc(len + 4); uh = (struct uwsgi_header *) upkt; diff --git a/utils.c b/utils.c index 6f76e7e3..067e424d 100644 --- a/utils.c +++ b/utils.c @@ -185,21 +185,13 @@ char *uwsgi_get_cwd() { int newsize = 256; char *cwd; - cwd = malloc(newsize); - if (cwd == NULL) { - uwsgi_error("malloc()"); - exit(1); - } + cwd = uwsgi_malloc(newsize); if (getcwd(cwd, newsize) == NULL) { newsize = errno; uwsgi_log("need a bigger buffer (%d bytes) for getcwd(). doing reallocation.\n", newsize); free(cwd); - cwd = malloc(newsize); - if (cwd == NULL) { - uwsgi_error("malloc()"); - exit(1); - } + cwd = uwsgi_malloc(newsize); if (getcwd(cwd, newsize) == NULL) { uwsgi_error("getcwd()"); exit(1); @@ -465,16 +457,27 @@ int wsgi_req_accept(struct wsgi_request *wsgi_req) { int i; int ret; + char uwsgi_signal; + if (wsgi_req->leave_open) return 0; - ret = poll(uwsgi.sockets_poll, uwsgi.sockets_cnt, -1); + ret = poll(uwsgi.sockets_poll, uwsgi.sockets_cnt+uwsgi.no_orphans, -1); if (ret < 0) { uwsgi_error("poll()"); return -1; } + if (uwsgi.sockets_poll[uwsgi.sockets_cnt].revents) { + if (read(uwsgi.sockets_poll[uwsgi.sockets_cnt].fd, &uwsgi_signal, 1) <= 0 && uwsgi.no_orphans) { + uwsgi_log_verbose("UAAAAAAH my master died, i will follow him...\n"); + end_me(); + } + else { + uwsgi_log_verbose("master sent signal %b to worker %d\n", uwsgi_signal, uwsgi.mywid); + } + } for(i=0;i