From 92c67ab289432756f42bfc30b958397a86f40c6b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 7 Aug 2014 22:09:11 +1000 Subject: [PATCH] Provide a restart command which does a handover to an new binary with the same arguments --- src/ckpool.c | 10 ++++++++++ src/ckpool.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/ckpool.c b/src/ckpool.c index 09b0501b..b24ecb83 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -273,6 +273,12 @@ retry: close(connfd); } else LOGWARNING("Failed to send_procmsg to connector"); + } else if (cmdmatch(buf, "restart")) { + if (!fork()) { + ckp->initial_args[ckp->args++] = strdup("-H"); + ckp->initial_args[ckp->args] = NULL; + execv(ckp->initial_args[0], (char *const *)ckp->initial_args); + } } else { LOGINFO("Listener received unhandled message: %s", buf); send_unix_msg(sockd, "unknown"); @@ -1072,6 +1078,10 @@ int main(int argc, char **argv) global_ckp = &ckp; memset(&ckp, 0, sizeof(ckp)); ckp.loglevel = LOG_NOTICE; + ckp.initial_args = ckalloc(sizeof(char *) * (argc + 2)); /* Leave room for extra -H */ + for (ckp.args = 0; ckp.args < argc; ckp.args++) + ckp.initial_args[ckp.args] = strdup(argv[ckp.args]); + ckp.initial_args[ckp.args] = NULL; while ((c = getopt_long(argc, argv, "Ac:d:g:Hhkl:n:pS:s:", long_options, &i)) != -1) { switch (c) { diff --git a/src/ckpool.h b/src/ckpool.h index 3a15c83f..43b14fab 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -79,6 +79,10 @@ struct server_instance { typedef struct server_instance server_instance_t; struct ckpool_instance { + /* The initial command line arguments */ + char **initial_args; + /* Number of arguments */ + int args; /* Filename of config file */ char *config; /* Kill old instance with same name */