void terminate(int s) { MURDER = s == SIGTERM; switch(s) { case SIGHUP: if(!RELOAD) { RELOAD = 1; if(RELOAD_TASK) { tasksignal(RELOAD_TASK, s); } } break; default: if(!RUNNING) { log_info("SIGINT CAUGHT AGAIN, ASSUMING MURDER."); MURDER = 1; } else { RUNNING = 0; log_info("SHUTDOWN REQUESTED: %s", MURDER ? "MURDER" : "GRACEFUL (SIGINT again to EXIT NOW)"); Server *srv = Server_queue_latest(); if(srv != NULL) { fdclose(srv->listen_fd); } } break; } }
int Server_stop_handlers(Server *srv) { int i = 0; for(i = 0; i < darray_end(srv->handlers); i++) { Handler *handler = darray_get(srv->handlers, i); check(handler != NULL, "Invalid handler, can't be NULL."); if(handler->running) { log_info("STOPPING HANDLER %s", bdata(handler->send_spec)); if(handler->task != NULL) { tasksignal(handler->task, SIGINT); handler->running = 0; taskdelay(1); } } if(handler->recv_socket) zmq_close(handler->recv_socket); if(handler->send_socket) zmq_close(handler->send_socket); handler->recv_socket = NULL; handler->send_socket = NULL; } return 0; error: return -1; }
static inline void fdtask_shutdown() { int i = 0; for(i = 0; i < SuperPoll_active_hot(POLL); i++) { SuperPoll_compact_down(POLL, i); } // move all our sleeping tasks over to the main runqueue Task *t = NULL; while((t = sleeping.head)){ deltask(&sleeping, t); tasksignal(t, task_was_signaled()); } }
int Register_connect(int fd, Connection* data) { check(fd < MAX_REGISTERED_FDS, "FD given to register is greater than max."); check(data != NULL, "data can't be NULL"); Registration *reg = darray_get(REGISTRATIONS, fd); if(reg == NULL) { reg = darray_new(REGISTRATIONS); check(reg != NULL, "Failed to allocate a new registration."); // we only set this here since they stay in list forever rather than recycle darray_set(REGISTRATIONS, fd, reg); darray_attach(REGISTRATIONS, reg); } if(Register_valid(reg)) { // force them to exit int rc = Register_disconnect(fd); check(rc != -1, "Weird error trying to disconnect. Tell Zed."); tasksignal(reg->task, SIGINT); } reg->data = data; reg->last_ping = THE_CURRENT_TIME_IS; reg->fd = fd; reg->task = taskself(); reg->id = UINT32_MAX; // start off with an invalid conn_id // keep track of the number of registered things we're tracking NUM_REG_FD++; return 0; error: return -1; }
int cornet_signal(int id) { return tasksignal(id); }