Browse Source

Shut down more gracefully on startup failure

master
Con Kolivas 11 years ago
parent
commit
28f3f6cb2e
  1. 30
      src/ckpool.c

30
src/ckpool.c

@ -215,6 +215,7 @@ static void sighandler(int sig)
sleep(1); sleep(1);
__shutdown_children(global_ckp, SIGKILL); __shutdown_children(global_ckp, SIGKILL);
pthread_cancel(global_ckp->pth_listener); pthread_cancel(global_ckp->pth_listener);
exit(0);
} else { } else {
__shutdown_children(global_ckp, SIGKILL); __shutdown_children(global_ckp, SIGKILL);
exit(1); exit(1);
@ -280,29 +281,6 @@ static void parse_config(ckpool_t *ckp)
json_decref(json_conf); 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) static void prepare_generator(ckpool_t *ckp)
{ {
proc_instance_t *pi = &ckp->generator; proc_instance_t *pi = &ckp->generator;
@ -459,16 +437,14 @@ int main(int argc, char **argv)
launch_process(&ckp.stratifier); launch_process(&ckp.stratifier);
launch_process(&ckp.connector); launch_process(&ckp.connector);
create_pthread(&ckp.pth_watchdog, watchdog, &ckp);
handler.sa_handler = &sighandler; handler.sa_handler = &sighandler;
handler.sa_flags = 0; handler.sa_flags = 0;
sigemptyset(&handler.sa_mask); sigemptyset(&handler.sa_mask);
sigaction(SIGTERM, &handler, NULL); sigaction(SIGTERM, &handler, NULL);
sigaction(SIGINT, &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 */ /* Shutdown from here if the listener is sent a shutdown message */
join_pthread(ckp.pth_listener); join_pthread(ckp.pth_listener);

Loading…
Cancel
Save