From 4ab9120e6165aebadfcca5e032e672aeed0c2681 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 23 Apr 2014 13:07:04 +1000 Subject: [PATCH] Handle failed generator startup as a fatal startup, sending listener a shutdown message and adding shutdown parsing --- src/ckpool.c | 13 +++++++++++-- src/generator.c | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index e7ff6d5d..9b3aca6a 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -29,10 +29,12 @@ static void *listener(void *arg) { proc_instance_t *pi = (proc_instance_t *)arg; unixsock_t *us = &pi->us; + char *buf = NULL; int sockd; rename_proc(pi->sockname); retry: + dealloc(buf); sockd = accept(us->sockd, NULL, NULL); if (sockd < 0) { if (interrupted()) @@ -41,9 +43,16 @@ retry: goto out; } /* Insert parsing and repeat code here */ -out: - if (sockd >= 0) + buf = recv_unix_msg(sockd); + if (!strncasecmp(buf, "shutdown", 8)) { + LOGWARNING("Listener received shutdown message, terminating ckpool"); close(sockd); + goto out; + } + close(sockd); + goto retry; +out: + dealloc(buf); close_unix_socket(us->sockd, us->path); return NULL; } diff --git a/src/generator.c b/src/generator.c index 887ec866..ba8bde85 100644 --- a/src/generator.c +++ b/src/generator.c @@ -147,5 +147,9 @@ out: dealloc(userpass); LOGINFO("%s generator exiting with return code %d", ckp->name, ret); + if (ret) { + send_proc(&ckp->main, "shutdown"); + sleep(1); + } return ret; }