diff --git a/src/ckpool.c b/src/ckpool.c index 31746936..2cade1eb 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -286,6 +286,18 @@ retry: Close(connfd); } else LOGWARNING("Failed to send_procmsg to connector"); + } else if (cmdmatch(buf, "accept")) { + LOGWARNING("Listener received accept message, accepting clients"); + send_procmsg(ckp->connector, "accept"); + send_unix_msg(sockd, "accepting"); + } else if (cmdmatch(buf, "reject")) { + LOGWARNING("Listener received reject message, rejecting clients"); + send_procmsg(ckp->connector, "reject"); + send_unix_msg(sockd, "rejecting"); + } else if (cmdmatch(buf, "reconnect")) { + LOGWARNING("Listener received request to send reconnect to clients"); + send_procmsg(ckp->stratifier, "reconnect"); + send_unix_msg(sockd, "reconnecting"); } else if (cmdmatch(buf, "restart")) { LOGWARNING("Listener received restart message, attempting handover"); send_unix_msg(sockd, "restarting"); @@ -772,7 +784,7 @@ int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret) LOGWARNING("%s %s exiting with return code %d, shutting down!", ckp->name, pi->processname, ret); send_proc(&ckp->main, "shutdown"); - sleep(1); + cksleep_ms(100); ret = 1; } else /* Should be part of a normal shutdown */ LOGNOTICE("%s %s exited normally", ckp->name, pi->processname); @@ -844,8 +856,8 @@ static void sighandler(int sig) cancel_join_pthread(&ckp->pth_watchdog); __shutdown_children(ckp, SIGUSR1); - /* Wait a second, then send SIGKILL */ - sleep(1); + /* Wait, then send SIGKILL */ + cksleep_ms(100); __shutdown_children(ckp, SIGKILL); cancel_pthread(&ckp->pth_listener); exit(0); @@ -1094,6 +1106,18 @@ static struct option long_options[] = { }; #endif +static void send_recv_path(const char *path, const char *msg) +{ + int sockd = open_unix_client(path); + char *response; + + send_unix_msg(sockd, msg); + response = recv_unix_msg(sockd); + LOGWARNING("Received: %s in response to %s request", response, msg); + dealloc(response); + Close(sockd); +} + int main(int argc, char **argv) { struct sigaction handler; @@ -1312,13 +1336,15 @@ int main(int argc, char **argv) if (sockd > 0 && send_unix_msg(sockd, "getfd")) { ckp.oldconnfd = get_fd(sockd); - Close(sockd); - sockd = open_unix_client(ckp.main.us.path); - send_unix_msg(sockd, "shutdown"); + + send_recv_path(ckp.main.us.path, "reject"); + send_recv_path(ckp.main.us.path, "reconnect"); + send_recv_path(ckp.main.us.path, "shutdown"); + cksleep_ms(500); + if (ckp.oldconnfd > 0) LOGWARNING("Inherited old socket with new file descriptor %d!", ckp.oldconnfd); - Close(sockd); } } diff --git a/src/stratifier.c b/src/stratifier.c index 47ef38ca..6bc8e952 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1138,6 +1138,17 @@ static void stratum_broadcast_message(const char *msg) stratum_broadcast(json_msg); } +/* Send a generic reconnect to all clients without parameters to make them + * reconnect to the same server. */ +static void reconnect_clients(void) +{ + json_t *json_msg; + + JSON_CPACK(json_msg, "{sosss[]}", "id", json_null(), "method", "client.reconnect", + "params"); + stratum_broadcast(json_msg); +} + static void block_solve(ckpool_t *ckp) { char cdfield[64]; @@ -1281,6 +1292,8 @@ retry: drop_allclients(ckp); } else if (cmdmatch(buf, "block")) { block_solve(ckp); + } else if (cmdmatch(buf, "reconnect")) { + reconnect_clients(); } else if (cmdmatch(buf, "loglevel")) { sscanf(buf, "loglevel=%d", &ckp->loglevel); } else {