diff --git a/Makefile b/Makefile index af806fbd..e727c738 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,6 @@ all: clean: python uwsgiconfig.py --clean + +check: + python uwsgiconfig.py --check diff --git a/core/cache.c b/core/cache.c index 411e880f..f6f75f12 100644 --- a/core/cache.c +++ b/core/cache.c @@ -3,7 +3,6 @@ extern struct uwsgi_server uwsgi; void uwsgi_init_cache() { - int i; if (!uwsgi.cache_blocksize) uwsgi.cache_blocksize = UMAX16; @@ -64,6 +63,7 @@ void uwsgi_init_cache() { } else { uwsgi.cache_items = (struct uwsgi_cache_item *) mmap(NULL, (sizeof(struct uwsgi_cache_item) * uwsgi.cache_max_items) + (uwsgi.cache_blocksize * uwsgi.cache_max_items), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); + int i; for (i = 0; i < (int) uwsgi.cache_max_items; i++) { memset(&uwsgi.cache_items[i], 0, sizeof(struct uwsgi_cache_item)); } @@ -243,7 +243,6 @@ int uwsgi_cache_set(char *key, uint16_t keylen, char *val, uint64_t vallen, uint struct uwsgi_cache_item *uci, *ucii; int ret = -1; - int slot; if (!keylen || !vallen) return -1; @@ -283,7 +282,7 @@ int uwsgi_cache_set(char *key, uint16_t keylen, char *val, uint64_t vallen, uint uci->keysize = keylen; ret = 0; // now put the value in the 16bit hashtable - slot = uci->djbhash % 0xffff; + int slot = uci->djbhash % 0xffff; // reset values uci->prev = 0; uci->next = 0; diff --git a/core/event.c b/core/event.c index b6297f75..490dc3ed 100644 --- a/core/event.c +++ b/core/event.c @@ -104,7 +104,6 @@ int event_queue_wait_multi(int eq, int timeout, void *events, int nevents) { int ret; uint_t nget = 1; timespec_t ts; - port_event_t *pe; if (timeout >= 0) { ts.tv_sec = timeout; @@ -123,8 +122,6 @@ int event_queue_wait_multi(int eq, int timeout, void *events, int nevents) { return 0; } - pe = (port_event_t *) events; - return nget; } diff --git a/core/init.c b/core/init.c index cfbd3e79..112f0b89 100644 --- a/core/init.c +++ b/core/init.c @@ -78,6 +78,11 @@ void uwsgi_init_default() { uwsgi.alarm_freq = 3; #endif + +#ifdef UWSGI_MULTICAST + uwsgi.multicast_ttl = 1; +#endif + } void uwsgi_setup_reload() { diff --git a/core/signal.c b/core/signal.c index d18f92d3..aa4ddc66 100644 --- a/core/signal.c +++ b/core/signal.c @@ -4,13 +4,13 @@ extern struct uwsgi_server uwsgi; int uwsgi_signal_handler(uint8_t sig) { - struct uwsgi_signal_entry *use = NULL; + struct uwsgi_signal_entry *use = NULL; use = &uwsgi.shared->signal_table[sig]; if (!uwsgi.p[use->modifier1]->signal_handler) { return -1; - } + } // check for COW if (uwsgi.master_process) { @@ -34,52 +34,52 @@ int uwsgi_signal_handler(uint8_t sig) { } } - // set harakiri here (if required and if i am a worker) - + // set harakiri here (if required and if i am a worker) + if (uwsgi.mywid > 0) { - uwsgi.workers[uwsgi.mywid].sig = 1; - uwsgi.workers[uwsgi.mywid].signum = sig; + uwsgi.workers[uwsgi.mywid].sig = 1; + uwsgi.workers[uwsgi.mywid].signum = sig; uwsgi.workers[uwsgi.mywid].signals++; - if(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { - set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]); + if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { + set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]); } - } + } else if (uwsgi.muleid > 0) { - uwsgi.mules[uwsgi.muleid-1].sig = 1; - uwsgi.mules[uwsgi.muleid-1].signum = sig; - uwsgi.mules[uwsgi.muleid-1].signals++; - if(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI] > 0) { - set_mule_harakiri(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI]); + uwsgi.mules[uwsgi.muleid - 1].sig = 1; + uwsgi.mules[uwsgi.muleid - 1].signum = sig; + uwsgi.mules[uwsgi.muleid - 1].signals++; + if (uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI] > 0) { + set_mule_harakiri(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI]); } } #ifdef UWSGI_SPOOLER - else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) { - if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { - set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]); - } - } + else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) { + if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]); + } + } #endif int ret = uwsgi.p[use->modifier1]->signal_handler(sig, use->handler); if (uwsgi.mywid > 0) { - uwsgi.workers[uwsgi.mywid].sig = 0; - if(uwsgi.workers[uwsgi.mywid].harakiri > 0) { - set_harakiri(0); + uwsgi.workers[uwsgi.mywid].sig = 0; + if (uwsgi.workers[uwsgi.mywid].harakiri > 0) { + set_harakiri(0); } - } + } else if (uwsgi.muleid > 0) { - uwsgi.mules[uwsgi.muleid-1].sig = 0; - if(uwsgi.mules[uwsgi.muleid-1].harakiri > 0) { - set_mule_harakiri(0); + uwsgi.mules[uwsgi.muleid - 1].sig = 0; + if (uwsgi.mules[uwsgi.muleid - 1].harakiri > 0) { + set_mule_harakiri(0); } - } + } #ifdef UWSGI_SPOOLER else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) { - if(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { - set_spooler_harakiri(0); - } - } + if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) { + set_spooler_harakiri(0); + } + } #endif return ret; @@ -97,7 +97,8 @@ int uwsgi_register_signal(uint8_t sig, char *receiver, void *handler, uint8_t mo struct uwsgi_signal_entry *use = NULL; - if (strlen(receiver) > 63) return -1; + if (strlen(receiver) > 63) + return -1; uwsgi_lock(uwsgi.signal_table_lock); @@ -109,7 +110,7 @@ int uwsgi_register_signal(uint8_t sig, char *receiver, void *handler, uint8_t mo return -1; } - strncpy(use->receiver, receiver, strlen(receiver)+1); + strncpy(use->receiver, receiver, strlen(receiver) + 1); use->handler = handler; use->modifier1 = modifier1; use->wid = uwsgi.mywid; @@ -129,7 +130,7 @@ int uwsgi_register_signal(uint8_t sig, char *receiver, void *handler, uint8_t mo int uwsgi_add_file_monitor(uint8_t sig, char *filename) { - if (strlen(filename) > (0xff-1)) { + if (strlen(filename) > (0xff - 1)) { uwsgi_log("uwsgi_add_file_monitor: invalid filename length\n"); return -1; } @@ -140,9 +141,9 @@ int uwsgi_add_file_monitor(uint8_t sig, char *filename) { // fill the fmon table, the master will use it to add items to the event queue memcpy(ushared->files_monitored[ushared->files_monitored_cnt].filename, filename, strlen(filename)); - ushared->files_monitored[ushared->files_monitored_cnt].registered = 0; + ushared->files_monitored[ushared->files_monitored_cnt].registered = 0; ushared->files_monitored[ushared->files_monitored_cnt].sig = sig; - + ushared->files_monitored_cnt++; } else { @@ -157,31 +158,31 @@ int uwsgi_add_file_monitor(uint8_t sig, char *filename) { } -struct uwsgi_probe *uwsgi_probe_register(struct uwsgi_probe **up, char *name, int (*func)(int, struct uwsgi_signal_probe *)) { +struct uwsgi_probe *uwsgi_probe_register(struct uwsgi_probe **up, char *name, int (*func) (int, struct uwsgi_signal_probe *)) { - struct uwsgi_probe *uwsgi_up = *up, *old_up; + struct uwsgi_probe *uwsgi_up = *up, *old_up; - if (!uwsgi_up) { - *up = uwsgi_malloc(sizeof(struct uwsgi_probe)); - uwsgi_up = *up; - } - else { - while(uwsgi_up) { - old_up = uwsgi_up; - uwsgi_up = uwsgi_up->next; - } + if (!uwsgi_up) { + *up = uwsgi_malloc(sizeof(struct uwsgi_probe)); + uwsgi_up = *up; + } + else { + while (uwsgi_up) { + old_up = uwsgi_up; + uwsgi_up = uwsgi_up->next; + } - uwsgi_up = uwsgi_malloc(sizeof(struct uwsgi_probe)); - old_up->next = uwsgi_up; - } + uwsgi_up = uwsgi_malloc(sizeof(struct uwsgi_probe)); + old_up->next = uwsgi_up; + } - uwsgi_up->name = name; - uwsgi_up->func = func; - uwsgi_up->next = NULL; + uwsgi_up->name = name; + uwsgi_up->func = func; + uwsgi_up->next = NULL; uwsgi_log("registered new probe \"%s\" at %p\n", name, uwsgi_up); - return uwsgi_up; + return uwsgi_up; } @@ -189,10 +190,10 @@ int uwsgi_add_probe(uint8_t sig, char *kind, char *args, int timeout, int freq) uwsgi_lock(uwsgi.probe_table_lock); - if (ushared->probes_cnt < MAX_PROBES) { + if (ushared->probes_cnt < MAX_PROBES) { struct uwsgi_probe *up = uwsgi.probes; - while(up) { + while (up) { if (!strcmp(up->name, kind)) { break; } @@ -201,15 +202,15 @@ int uwsgi_add_probe(uint8_t sig, char *kind, char *args, int timeout, int freq) if (!up) { uwsgi_log("unable to find probe \"%s\" !!!\n", kind); - uwsgi_unlock(uwsgi.probe_table_lock); - return -1; + uwsgi_unlock(uwsgi.probe_table_lock); + return -1; } - // fill the probe table - ushared->probes[ushared->probes_cnt].func = up->func; - strncpy(ushared->probes[ushared->probes_cnt].args, args, 1024-1); - ushared->probes[ushared->probes_cnt].registered = 0; - ushared->probes[ushared->probes_cnt].sig = sig; + // fill the probe table + ushared->probes[ushared->probes_cnt].func = up->func; + strncpy(ushared->probes[ushared->probes_cnt].args, args, 1024 - 1); + ushared->probes[ushared->probes_cnt].registered = 0; + ushared->probes[ushared->probes_cnt].sig = sig; ushared->probes[ushared->probes_cnt].fd = -1; ushared->probes[ushared->probes_cnt].state = 0; ushared->probes[ushared->probes_cnt].last_event = 0; @@ -225,15 +226,15 @@ int uwsgi_add_probe(uint8_t sig, char *kind, char *args, int timeout, int freq) freq = 1; } ushared->probes[ushared->probes_cnt].freq = freq; - ushared->probes_cnt++; - } - else { - uwsgi_log("you can register max %d probes !!!\n", MAX_PROBES); - uwsgi_unlock(uwsgi.probe_table_lock); - return -1; - } + ushared->probes_cnt++; + } + else { + uwsgi_log("you can register max %d probes !!!\n", MAX_PROBES); + uwsgi_unlock(uwsgi.probe_table_lock); + return -1; + } - uwsgi_unlock(uwsgi.probe_table_lock); + uwsgi_unlock(uwsgi.probe_table_lock); return 0; } @@ -267,107 +268,109 @@ void uwsgi_opt_add_cron(char *opt, char *value, void *foobar) { int i; struct uwsgi_cron *old_uc, *uc = uwsgi.crons; - if (!uc) { - uc = uwsgi_malloc(sizeof(struct uwsgi_cron)); - uwsgi.crons = uc; - } - else { - old_uc = uc; - while(uc->next) { - uc = uc->next; - old_uc = uc; - } + if (!uc) { + uc = uwsgi_malloc(sizeof(struct uwsgi_cron)); + uwsgi.crons = uc; + } + else { + old_uc = uc; + while (uc->next) { + uc = uc->next; + old_uc = uc; + } - old_uc->next = uwsgi_malloc(sizeof(struct uwsgi_cron)); - uc = old_uc->next; - } + old_uc->next = uwsgi_malloc(sizeof(struct uwsgi_cron)); + uc = old_uc->next; + } - memset(uc, 0, sizeof(struct uwsgi_cron)); + memset(uc, 0, sizeof(struct uwsgi_cron)); - if (sscanf(value, "%d %d %d %d %d %n", &uc->minute, &uc->hour, &uc->day, &uc->month, &uc->week, &i) != 5) { - uwsgi_log("invalid cron syntax\n"); - exit(1); - } - uc->command = value+i; + if (sscanf(value, "%d %d %d %d %d %n", &uc->minute, &uc->hour, &uc->day, &uc->month, &uc->week, &i) != 5) { + uwsgi_log("invalid cron syntax\n"); + exit(1); + } + uc->command = value + i; } int uwsgi_signal_add_cron(uint8_t sig, int minute, int hour, int day, int month, int week) { - if (!uwsgi.master_process) return -1; + if (!uwsgi.master_process) + return -1; uwsgi_lock(uwsgi.cron_table_lock); - if (ushared->cron_cnt < MAX_CRONS) { + if (ushared->cron_cnt < MAX_CRONS) { - ushared->cron[ushared->cron_cnt].sig = sig; - ushared->cron[ushared->cron_cnt].minute = minute; - ushared->cron[ushared->cron_cnt].hour = hour; - ushared->cron[ushared->cron_cnt].day = day; - ushared->cron[ushared->cron_cnt].month = month; - ushared->cron[ushared->cron_cnt].week = week; - ushared->cron_cnt++; - } - else { - uwsgi_log("you can register max %d cron !!!\n", MAX_CRONS); - uwsgi_unlock(uwsgi.cron_table_lock); - return -1; - } + ushared->cron[ushared->cron_cnt].sig = sig; + ushared->cron[ushared->cron_cnt].minute = minute; + ushared->cron[ushared->cron_cnt].hour = hour; + ushared->cron[ushared->cron_cnt].day = day; + ushared->cron[ushared->cron_cnt].month = month; + ushared->cron[ushared->cron_cnt].week = week; + ushared->cron_cnt++; + } + else { + uwsgi_log("you can register max %d cron !!!\n", MAX_CRONS); + uwsgi_unlock(uwsgi.cron_table_lock); + return -1; + } - uwsgi_unlock(uwsgi.cron_table_lock); + uwsgi_unlock(uwsgi.cron_table_lock); - return 0; + return 0; } int uwsgi_signal_add_rb_timer(uint8_t sig, int secs, int iterations) { - if (!uwsgi.master_process) return -1; + if (!uwsgi.master_process) + return -1; - uwsgi_lock(uwsgi.rb_timer_table_lock); + uwsgi_lock(uwsgi.rb_timer_table_lock); - if (ushared->rb_timers_cnt < 64) { + if (ushared->rb_timers_cnt < 64) { - // fill the timer table, the master will use it to add items to the event queue - ushared->rb_timers[ushared->rb_timers_cnt].value = secs; - ushared->rb_timers[ushared->rb_timers_cnt].registered = 0; - ushared->rb_timers[ushared->rb_timers_cnt].iterations = iterations; - ushared->rb_timers[ushared->rb_timers_cnt].iterations_done = 0; - ushared->rb_timers[ushared->rb_timers_cnt].sig = sig; - ushared->rb_timers_cnt++; - } - else { - uwsgi_log("you can register max 64 rb_timers !!!\n"); - uwsgi_unlock(uwsgi.rb_timer_table_lock); - return -1; - } + // fill the timer table, the master will use it to add items to the event queue + ushared->rb_timers[ushared->rb_timers_cnt].value = secs; + ushared->rb_timers[ushared->rb_timers_cnt].registered = 0; + ushared->rb_timers[ushared->rb_timers_cnt].iterations = iterations; + ushared->rb_timers[ushared->rb_timers_cnt].iterations_done = 0; + ushared->rb_timers[ushared->rb_timers_cnt].sig = sig; + ushared->rb_timers_cnt++; + } + else { + uwsgi_log("you can register max 64 rb_timers !!!\n"); + uwsgi_unlock(uwsgi.rb_timer_table_lock); + return -1; + } - uwsgi_unlock(uwsgi.rb_timer_table_lock); + uwsgi_unlock(uwsgi.rb_timer_table_lock); - return 0; + return 0; } void create_signal_pipe(int *sigpipe) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, sigpipe)) { - uwsgi_error("socketpair()\n"); - exit(1); - } - uwsgi_socket_nb(sigpipe[0]); - uwsgi_socket_nb(sigpipe[1]); + uwsgi_error("socketpair()\n"); + exit(1); + } + uwsgi_socket_nb(sigpipe[0]); + uwsgi_socket_nb(sigpipe[1]); if (uwsgi.signal_bufsize) { - if (setsockopt(sigpipe[0], SOL_SOCKET, SO_SNDBUF, &uwsgi.signal_bufsize, sizeof(int))) { - uwsgi_error("setsockopt()"); + if (setsockopt(sigpipe[0], SOL_SOCKET, SO_SNDBUF, &uwsgi.signal_bufsize, sizeof(int))) { + uwsgi_error("setsockopt()"); } - if (setsockopt(sigpipe[0], SOL_SOCKET, SO_RCVBUF, &uwsgi.signal_bufsize, sizeof(int))) { - uwsgi_error("setsockopt()"); + if (setsockopt(sigpipe[0], SOL_SOCKET, SO_RCVBUF, &uwsgi.signal_bufsize, sizeof(int))) { + uwsgi_error("setsockopt()"); } - if (setsockopt(sigpipe[1], SOL_SOCKET, SO_SNDBUF, &uwsgi.signal_bufsize, sizeof(int))) { - uwsgi_error("setsockopt()"); + if (setsockopt(sigpipe[1], SOL_SOCKET, SO_SNDBUF, &uwsgi.signal_bufsize, sizeof(int))) { + uwsgi_error("setsockopt()"); } - if (setsockopt(sigpipe[1], SOL_SOCKET, SO_RCVBUF, &uwsgi.signal_bufsize, sizeof(int))) { - uwsgi_error("setsockopt()"); + if (setsockopt(sigpipe[1], SOL_SOCKET, SO_RCVBUF, &uwsgi.signal_bufsize, sizeof(int))) { + uwsgi_error("setsockopt()"); } } } @@ -379,9 +382,10 @@ int uwsgi_remote_signal_send(char *addr, uint8_t sig) { uh.modifier1 = 110; uh.pktsize = 0; uh.modifier2 = sig; - + int fd = uwsgi_connect(addr, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0); - if (fd < 0) return -1; + if (fd < 0) + return -1; if (write(fd, (char *) &uh, 4) != 4) { uwsgi_error("uwsgi_remote_signal_send()"); @@ -403,16 +407,16 @@ int uwsgi_signal_send(int fd, uint8_t sig) { if (write(fd, &sig, 1) != 1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &so_bufsize, &so_bufsize_len)) { - uwsgi_error("getsockopt()"); - } - uwsgi_log("*** SIGNAL QUEUE IS FULL: buffer size %d bytes (you can tune it with --signal-bufsize) ***\n", so_bufsize); + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &so_bufsize, &so_bufsize_len)) { + uwsgi_error("getsockopt()"); + } + uwsgi_log("*** SIGNAL QUEUE IS FULL: buffer size %d bytes (you can tune it with --signal-bufsize) ***\n", so_bufsize); } else { uwsgi_error("uwsgi_signal_send()"); } return -1; - } + } return 0; } @@ -430,7 +434,7 @@ void uwsgi_route_signal(uint8_t sig) { } // send to all workers else if (!strcmp(use->receiver, "workers")) { - for(i=1;i<=uwsgi.numproc;i++) { + for (i = 1; i <= uwsgi.numproc; i++) { if (uwsgi_signal_send(uwsgi.workers[i].signal_pipe[0], sig)) { uwsgi_log("could not deliver signal %d to worker %d\n", sig, i); } @@ -438,13 +442,13 @@ void uwsgi_route_signal(uint8_t sig) { } // route to specific worker else if (!strncmp(use->receiver, "worker", 6)) { - i = atoi(use->receiver+6); + i = atoi(use->receiver + 6); if (i > uwsgi.numproc) { uwsgi_log("invalid signal target: %s\n", use->receiver); } if (uwsgi_signal_send(uwsgi.workers[i].signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to worker %d\n", sig, i); - } + uwsgi_log("could not deliver signal %d to worker %d\n", sig, i); + } } // route to subscribed else if (!strcmp(use->receiver, "subscribed")) { @@ -454,54 +458,54 @@ void uwsgi_route_signal(uint8_t sig) { else if (!strcmp(use->receiver, "spooler")) { if (ushared->worker_signal_pipe[0] != -1) { if (uwsgi_signal_send(ushared->spooler_signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to the spooler\n", sig); - } + uwsgi_log("could not deliver signal %d to the spooler\n", sig); + } } } #endif else if (!strcmp(use->receiver, "mules")) { - for(i=0;ireceiver, "mule", 4)) { - i = atoi(use->receiver+4); + i = atoi(use->receiver + 4); if (i > uwsgi.mules_cnt) { uwsgi_log("invalid signal target: %s\n", use->receiver); } else if (i == 0) { if (uwsgi_signal_send(ushared->mule_signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to a mule\n", sig); - } + uwsgi_log("could not deliver signal %d to a mule\n", sig); + } } else { - if (uwsgi_signal_send(uwsgi.mules[i-1].signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to mule %d\n", sig, i); - } + if (uwsgi_signal_send(uwsgi.mules[i - 1].signal_pipe[0], sig)) { + uwsgi_log("could not deliver signal %d to mule %d\n", sig, i); + } } } else if (!strncmp(use->receiver, "farm_", 5)) { - char *name = use->receiver+5; + char *name = use->receiver + 5; struct uwsgi_farm *uf = get_farm_by_name(name); if (!uf) { uwsgi_log("unknown farm: %s\n", name); return; } if (uwsgi_signal_send(uf->signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to farm %d (%s)\n", sig, uf->id, uf->name); - } + uwsgi_log("could not deliver signal %d to farm %d (%s)\n", sig, uf->id, uf->name); + } } else if (!strncmp(use->receiver, "farm", 4)) { - i = atoi(use->receiver+4); + i = atoi(use->receiver + 4); if (i > uwsgi.farms_cnt || i <= 0) { uwsgi_log("invalid signal target: %s\n", use->receiver); } else { - if (uwsgi_signal_send(uwsgi.farms[i-1].signal_pipe[0], sig)) { - uwsgi_log("could not deliver signal %d to farm %d (%s)\n", sig, i, uwsgi.farms[i-1].name); - } + if (uwsgi_signal_send(uwsgi.farms[i - 1].signal_pipe[0], sig)) { + uwsgi_log("could not deliver signal %d to farm %d (%s)\n", sig, i, uwsgi.farms[i - 1].name); + } } } @@ -512,51 +516,56 @@ void uwsgi_route_signal(uint8_t sig) { } -uint8_t uwsgi_signal_wait(int signum) { +int uwsgi_signal_wait(int signum) { - int wait_for_specific_signal = 0; - uint8_t uwsgi_signal = 0; - uint8_t received_signal; - int ret; - struct pollfd pfd[2]; + int wait_for_specific_signal = 0; + uint8_t uwsgi_signal = 0; + int received_signal = -1; + int ret; + struct pollfd pfd[2]; if (signum > -1) { - wait_for_specific_signal = 1; - } + wait_for_specific_signal = 1; + } + + pfd[0].fd = uwsgi.signal_socket; + pfd[0].events = POLLIN; + pfd[1].fd = uwsgi.my_signal_socket; + pfd[1].events = POLLIN; - pfd[0].fd = uwsgi.signal_socket; - pfd[0].events = POLLIN; - pfd[1].fd = uwsgi.my_signal_socket; - pfd[1].events = POLLIN; cycle: - ret = poll(pfd, 2, -1); - if (ret > 0) { - if (pfd[0].revents == POLLIN) { - if (read(uwsgi.signal_socket, &received_signal, 1) != 1) { - uwsgi_error("read()"); - } - else { - (void)uwsgi_signal_handler(received_signal); - if (wait_for_specific_signal) { - if (received_signal != uwsgi_signal) goto cycle; - } - } + ret = poll(pfd, 2, -1); + if (ret > 0) { + if (pfd[0].revents == POLLIN) { + if (read(uwsgi.signal_socket, &uwsgi_signal, 1) != 1) { + uwsgi_error("read()"); + } + else { + (void) uwsgi_signal_handler(uwsgi_signal); + if (wait_for_specific_signal) { + if (signum != uwsgi_signal) + goto cycle; + } + received_signal = uwsgi_signal; + } + } + if (pfd[1].revents == POLLIN) { + if (read(uwsgi.my_signal_socket, &uwsgi_signal, 1) != 1) { + uwsgi_error("read()"); + } + else { + (void) uwsgi_signal_handler(uwsgi_signal); + if (wait_for_specific_signal) { + if (signum != uwsgi_signal) + goto cycle; + } + } + received_signal = uwsgi_signal; } - if (pfd[1].revents == POLLIN) { - if (read(uwsgi.my_signal_socket, &received_signal, 1) != 1) { - uwsgi_error("read()"); - } - else { - (void)uwsgi_signal_handler(received_signal); - if (wait_for_specific_signal) { - if (received_signal != uwsgi_signal) goto cycle; - } - } - } - } + } - return received_signal; + return received_signal; } void uwsgi_receive_signal(int fd, char *name, int id) { @@ -565,27 +574,27 @@ void uwsgi_receive_signal(int fd, char *name, int id) { ssize_t ret = read(fd, &uwsgi_signal, 1); - if (ret == 0) { + if (ret == 0) { goto destroy; - } - else if (ret < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - uwsgi_error("[uwsgi-signal] read()"); + } + else if (ret < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { + uwsgi_error("[uwsgi-signal] read()"); goto destroy; - } - else if (ret > 0) { + } + else if (ret > 0) { #ifdef UWSGI_DEBUG - uwsgi_log_verbose("master sent signal %d to %s %d\n", uwsgi_signal, name, id); + uwsgi_log_verbose("master sent signal %d to %s %d\n", uwsgi_signal, name, id); #endif - if (uwsgi_signal_handler(uwsgi_signal)) { - uwsgi_log_verbose("error managing signal %d on %s %d\n", uwsgi_signal, name, id); - } - } + if (uwsgi_signal_handler(uwsgi_signal)) { + uwsgi_log_verbose("error managing signal %d on %s %d\n", uwsgi_signal, name, id); + } + } return; destroy: // better to kill the whole worker... - uwsgi_log_verbose("uWSGI %s %d screams: UAAAAAAH my master disconnected: i will kill myself !!!\n", name, id); + uwsgi_log_verbose("uWSGI %s %d screams: UAAAAAAH my master disconnected: i will kill myself !!!\n", name, id); end_me(0); } diff --git a/core/socket.c b/core/socket.c index 72e51da4..7440f0a9 100644 --- a/core/socket.c +++ b/core/socket.c @@ -174,6 +174,7 @@ int bind_to_udp(char *socket_name, int multicast, int broadcast) { struct sockaddr_in uws_addr; char *udp_port; int bcast = 1; + int reuse = 1; #ifdef UWSGI_MULTICAST struct ip_mreq mc; @@ -231,6 +232,10 @@ int bind_to_udp(char *socket_name, int multicast, int broadcast) { return -1; } + if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) { + uwsgi_error("setsockopt()"); + } + #ifdef UWSGI_MULTICAST if (multicast) { // if multicast is enabled remember to bind to INADDR_ANY @@ -265,6 +270,10 @@ int bind_to_udp(char *socket_name, int multicast, int broadcast) { uwsgi_error("setsockopt()"); } + if (setsockopt(serverfd, IPPROTO_IP, IP_MULTICAST_TTL, &uwsgi.multicast_ttl, sizeof(uwsgi.multicast_ttl))) { + uwsgi_error("setsockopt()"); + } + } #endif diff --git a/core/uwsgi.c b/core/uwsgi.c index d54bee2b..10119b6a 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -302,6 +302,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"stats-server", required_argument, 0, "enable the stats server on the specified address", uwsgi_opt_set_str, &uwsgi.stats, UWSGI_OPT_MASTER}, #ifdef UWSGI_MULTICAST {"multicast", required_argument, 0, "subscribe to specified multicast group", uwsgi_opt_set_str, &uwsgi.multicast_group, UWSGI_OPT_MASTER}, + {"multicast-ttl", required_argument, 0, "set multicast ttl", uwsgi_opt_set_int, &uwsgi.multicast_ttl, 0}, {"cluster", required_argument, 0, "join specified uWSGI cluster", uwsgi_opt_set_str, &uwsgi.cluster, UWSGI_OPT_MASTER}, {"cluster-nodes", required_argument, 0, "get nodes list from the specified cluster", uwsgi_opt_true, &uwsgi.cluster_nodes, UWSGI_OPT_MASTER | UWSGI_OPT_CLUSTER}, {"cluster-reload", required_argument, 0, "send a reload message to the cluster", uwsgi_opt_cluster_reload, NULL, UWSGI_OPT_IMMEDIATE}, @@ -2927,7 +2928,7 @@ void uwsgi_stdin_sendto(char *socket_name, uint8_t modifier1, uint8_t modifier2) #endif ptr += rlen; delta -= rlen; - if (delta <= 0) + if (delta == 0) break; rlen = read(0, ptr, delta); } diff --git a/plugins/php/php_plugin.c b/plugins/php/php_plugin.c index 638fe339..f971f221 100644 --- a/plugins/php/php_plugin.c +++ b/plugins/php/php_plugin.c @@ -208,7 +208,7 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers) static int sapi_uwsgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { uint read_bytes = 0; - size_t len; + ssize_t len; int fd = -1; struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context); diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 49aae6b5..9dca48fb 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -10,7 +10,7 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { struct wsgi_request *wsgi_req = current_wsgi_req(); int wait_for_specific_signal = 0; uint8_t uwsgi_signal = 0; - uint8_t received_signal; + int received_signal; wsgi_req->signal_received = -1; @@ -30,6 +30,11 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { received_signal = uwsgi_signal_wait(-1); } + if (received_signal < 0) { + UWSGI_GET_GIL; + return PyErr_Format(PyExc_SystemError, "error waiting for signal"); + } + wsgi_req->signal_received = received_signal; UWSGI_GET_GIL; diff --git a/plugins/rack/rack_api.c b/plugins/rack/rack_api.c index 71d17896..1436ad85 100644 --- a/plugins/rack/rack_api.c +++ b/plugins/rack/rack_api.c @@ -577,7 +577,7 @@ VALUE uwsgi_ruby_signal_wait(int argc, VALUE *argv, VALUE *class) { struct wsgi_request *wsgi_req = current_wsgi_req(); int wait_for_specific_signal = 0; uint8_t uwsgi_signal = 0; - uint8_t received_signal; + int received_signal; wsgi_req->signal_received = -1; @@ -594,7 +594,12 @@ VALUE uwsgi_ruby_signal_wait(int argc, VALUE *argv, VALUE *class) { received_signal = uwsgi_signal_wait(-1); } - wsgi_req->signal_received = received_signal; + if (received_signal < 0) { + rb_raise(rb_eRuntimeError, "unable to call rpc function"); + } + else { + wsgi_req->signal_received = received_signal; + } return Qnil; } diff --git a/uwsgi.h b/uwsgi.h index ad8d2055..860a718f 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1548,6 +1548,7 @@ struct uwsgi_server { #endif #ifdef UWSGI_MULTICAST + int multicast_ttl; char *multicast_group; #endif @@ -2885,7 +2886,7 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo ssize_t uwsgi_mule_get_msg(int, int, char *, size_t, int); -uint8_t uwsgi_signal_wait(int); +int uwsgi_signal_wait(int); struct uwsgi_app *uwsgi_add_app(int, uint8_t, char *, int, void *, void *); int uwsgi_signal_send(int, uint8_t); int uwsgi_remote_signal_send(char *, uint8_t); diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 3b41ddd8..4c2167ad 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -1,6 +1,6 @@ # uWSGI build system -uwsgi_version = '1.3-rc4' +uwsgi_version = '1.3-rc5' import os import re @@ -1202,6 +1202,8 @@ if __name__ == "__main__": os.system("rm -f lib/*.o") os.system("rm -f plugins/*/*.o") os.system("rm -f build/*.o") + elif cmd == '--check': + os.system("cppcheck --max-configs=1000 --enable=all -q core/ plugins/ proto/ lib/ apache2/") else: print("unknown uwsgiconfig command")