From 713509823f73c430e1f9d5ab1611a1a424653942 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 7 Aug 2014 22:25:51 +1000 Subject: [PATCH 1/2] Rate limit the throbber to one update per second --- src/stratifier.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 37ede260..ea44d8e9 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -419,12 +419,19 @@ static void _ckdbq_add(ckpool_t *ckp, const int idtype, json_t *val, const char const char *func, const int line) { static int counter = 0; + static time_t time_counter; ckdb_msg_t *msg; + time_t now_t; char ch; - ch = status_chars[(counter++) & 0x3]; - fprintf(stdout, "%c\r", ch); - fflush(stdout); + now_t = time(NULL); + if (now_t != time_counter) { + /* Rate limit to 1 update per second */ + time_counter = now_t; + ch = status_chars[(counter++) & 0x3]; + fprintf(stdout, "%c\r", ch); + fflush(stdout); + } if (!val) { LOGWARNING("Invalid json sent to ckdbq_add from %s %s:%d", file, func, line); From d728f7d8639e09d990f8402a98ab154764554a5b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 7 Aug 2014 22:38:27 +1000 Subject: [PATCH 2/2] Inherit pids of processes that are forked later --- src/ckpool.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ckpool.c b/src/ckpool.c index b24ecb83..538ed647 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -379,6 +379,24 @@ out: static void childsighandler(int sig); +static int get_proc_pid(proc_instance_t *pi) +{ + int ret, pid = 0; + char path[256]; + FILE *fp; + + sprintf(path, "%s%s.pid", pi->ckp->socket_dir, pi->processname); + fp = fopen(path, "r"); + if (!fp) + goto out; + ret = fscanf(fp, "%d", &pid); + if (ret < 1) + pid = 0; + fclose(fp); +out: + return pid; +} + /* Send a single message to a process instance when there will be no response, * closing the socket immediately. */ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const char *func, const int line) @@ -395,6 +413,10 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch LOGERR("Attempted to send null message to socket %s in send_proc", path); goto out; } + /* At startup the pid fields are not set up before some processes are + * forked so they never inherit them. */ + if (unlikely(!pi->pid)) + pi->pid = get_proc_pid(pi); if (unlikely(kill_pid(pi->pid, 0))) { LOGALERT("Attempting to send message %s to non existent process %s", msg, pi->processname); goto out; @@ -410,8 +432,10 @@ bool _send_proc(proc_instance_t *pi, const char *msg, const char *file, const ch ret = true; close(sockd); out: - if (unlikely(!ret)) + if (unlikely(!ret)) { LOGERR("Failure in send_proc from %s %s:%d", file, func, line); + childsighandler(15); + } return ret; }