From 28f3f6cb2ea73184dd25cf9965d0780e412dee5c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 12 May 2014 21:51:18 +1000 Subject: [PATCH] Shut down more gracefully on startup failure --- src/ckpool.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 46cddf6a..18b374f7 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -215,6 +215,7 @@ static void sighandler(int sig) sleep(1); __shutdown_children(global_ckp, SIGKILL); pthread_cancel(global_ckp->pth_listener); + exit(0); } else { __shutdown_children(global_ckp, SIGKILL); exit(1); @@ -280,29 +281,6 @@ static void parse_config(ckpool_t *ckp) json_decref(json_conf); } -static void test_functions(ckpool_t *ckp) -{ - char *path = ckp->generator.us.path, *buf; - int genfd; - - genfd = open_unix_client(ckp->generator.us.path); - if (genfd < 0) { - LOGWARNING("Failed to open generator socket %s", path); - return; - } - send_unix_msg(genfd, "getbase"); - buf = recv_unix_msg(genfd); - dealloc(buf); -#if 0 - genfd = open_unix_client(ckp->generator.us.path); - if (genfd < 0) { - LOGWARNING("Failed to open generator socket %s", path); - return; - } - send_unix_msg(genfd, "shutdown"); -#endif -} - static void prepare_generator(ckpool_t *ckp) { proc_instance_t *pi = &ckp->generator; @@ -459,16 +437,14 @@ int main(int argc, char **argv) launch_process(&ckp.stratifier); launch_process(&ckp.connector); + create_pthread(&ckp.pth_watchdog, watchdog, &ckp); + handler.sa_handler = &sighandler; handler.sa_flags = 0; sigemptyset(&handler.sa_mask); sigaction(SIGTERM, &handler, NULL); sigaction(SIGINT, &handler, NULL); - test_functions(&ckp); - - create_pthread(&ckp.pth_watchdog, watchdog, &ckp); - /* Shutdown from here if the listener is sent a shutdown message */ join_pthread(ckp.pth_listener);