From 095b9154e08b68cc218b8b3d98bba20dff93eccb Mon Sep 17 00:00:00 2001 From: "roberto@oneiric64" Date: Mon, 23 Jan 2012 12:33:57 +0100 Subject: [PATCH] fixed signal handling in gateways --- gateway.c | 8 ++++++ plugins/fastrouter/fastrouter.c | 51 +++++++++++++++++++++++++++++++-- plugins/http/http.c | 3 +- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/gateway.c b/gateway.c index a47578e5..8570dd4d 100644 --- a/gateway.c +++ b/gateway.c @@ -59,6 +59,14 @@ void gateway_respawn(int id) { } #endif uwsgi.mypid = getpid(); + signal(SIGALRM, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, end_me); + signal(SIGTERM, end_me); + signal(SIGUSR1, SIG_IGN); + signal(SIGUSR2, SIG_IGN); + signal(SIGPIPE, SIG_IGN); + ug->loop(id); // never here !!! (i hope) exit(1); diff --git a/plugins/fastrouter/fastrouter.c b/plugins/fastrouter/fastrouter.c index a8ae5f42..2ce4e050 100644 --- a/plugins/fastrouter/fastrouter.c +++ b/plugins/fastrouter/fastrouter.c @@ -343,7 +343,8 @@ void fastrouter_loop(int id) { ugs = ugs->next; } - event_queue_add_fd_read(ufr.queue, uwsgi.gateways[id].internal_subscription_pipe[1]); + if (ufr.has_subscription_sockets) + event_queue_add_fd_read(ufr.queue, uwsgi.gateways[id].internal_subscription_pipe[1]); if (!ufr.socket_timeout) @@ -551,7 +552,50 @@ void fastrouter_loop(int id) { continue; } - if (interesting_fd == ufr.fr_stats_server) { + if (interesting_fd == uwsgi.gateways[id].internal_subscription_pipe[1]) { + len = recv(interesting_fd, bbuf, 4096, 0); +#ifdef UWSGI_EVENT_USE_PORT + event_queue_add_fd_read(ufr.queue, interesting_fd); +#endif + if (len > 0) { + memset(&usr, 0, sizeof(struct uwsgi_subscribe_req)); + uwsgi_hooked_parse(bbuf + 4, len - 4, fastrouter_manage_subscription, &usr); + + // subscribe request ? + if (bbuf[3] == 0) { + if (uwsgi_add_subscribe_node(&ufr.subscriptions, &usr, ufr.subscription_regexp) && ufr.i_am_cheap) { + struct uwsgi_gateway_socket *ugs = uwsgi.gateway_sockets; + while (ugs) { + if (!strcmp(ugs->owner, "uWSGI fastrouter") && !ugs->subscription) { + event_queue_add_fd_read(ufr.queue, ugs->fd); + } + ugs = ugs->next; + } + ufr.i_am_cheap = 0; + uwsgi_log("[uwsgi-fastrouter] leaving cheap mode...\n"); + } + } + //unsubscribe + else { + struct uwsgi_subscribe_node *node = uwsgi_get_subscribe_node_by_name(&ufr.subscriptions, usr.key, usr.keylen, usr.address, usr.address_len, ufr.subscription_regexp); + if (node && node->len) { + if (node->death_mark == 0) + uwsgi_log("[uwsgi-fastrouter] %.*s => marking %.*s as failed\n", (int) usr.keylen, usr.key, (int) usr.address_len, usr.address); + node->failcnt++; + node->death_mark = 1; + // check if i can remove the node + if (node->reference == 0) { + uwsgi_remove_subscribe_node(&ufr.subscriptions, node); + } + if (ufr.subscriptions == NULL && ufr.cheap && !ufr.i_am_cheap) { + fastrouter_go_cheap(); + } + } + } + } + + } + else if (interesting_fd == ufr.fr_stats_server) { fastrouter_send_stats(ufr.fr_stats_server); } else { @@ -1018,6 +1062,9 @@ int fastrouter_opt(int i, char *optarg) { ufr.socket_num = atoi(optarg); } return 1; + case LONG_ARGS_FASTROUTER_PROCESSES: + ufr.processes = atoi(optarg); + return 1; case LONG_ARGS_FASTROUTER_USE_CODE_STRING: cs = uwsgi_str(optarg); cs_code = strchr(cs, ':'); diff --git a/plugins/http/http.c b/plugins/http/http.c index 88762dc0..f0096e23 100644 --- a/plugins/http/http.c +++ b/plugins/http/http.c @@ -498,7 +498,8 @@ void http_loop(int id) { ugs = ugs->next; } - event_queue_add_fd_read(uhttp_queue, uwsgi.gateways[id].internal_subscription_pipe[1]); + if (uhttp.has_subscription_sockets) + event_queue_add_fd_read(uhttp_queue, uwsgi.gateways[id].internal_subscription_pipe[1]); if (uhttp.pattern) { init_magic_table(magic_table);