From 645b94c949c09c70912cd6c651aa30021c00c6db Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 17 Jun 2014 16:45:53 +1000 Subject: [PATCH] Log all ckdb requests to the rotating ckdb log --- src/ckpool.c | 8 +++++++- src/ckpool.h | 4 ++-- src/stratifier.c | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index 7532d12c..5266d310 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -325,7 +325,7 @@ out: /* Send a json msg to ckdb with its idmsg and return the response, consuming * the json on success */ -char *_json_ckdb_call(const ckpool_t *ckp, const char *idmsg, json_t *val, +char *_json_ckdb_call(const ckpool_t *ckp, const char *idmsg, json_t *val, bool logged, const char *file, const char *func, const int line) { char *msg = NULL, *dump, *buf = NULL; @@ -336,6 +336,12 @@ char *_json_ckdb_call(const ckpool_t *ckp, const char *idmsg, json_t *val, return buf; } ASPRINTF(&msg, "id.%s.json=%s", idmsg, dump); + if (!logged) { + char logname[512]; + + snprintf(logname, 511, "%s%s", ckp->logdir, ckp->ckdb_name); + rotating_log(logname, msg); + } free(dump); LOGDEBUG("Sending ckdb: %s", msg); buf = _send_recv_ckdb(ckp, msg, file, func, line); diff --git a/src/ckpool.h b/src/ckpool.h index 58f75553..804095a0 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -136,9 +136,9 @@ char *_send_recv_proc(proc_instance_t *pi, const char *msg, const char *file, co #define send_recv_proc(pi, msg) _send_recv_proc(pi, msg, __FILE__, __func__, __LINE__) char *_send_recv_ckdb(const ckpool_t *ckp, const char *msg, const char *file, const char *func, const int line); #define send_recv_ckdb(ckp, msg) _send_recv_ckdb(ckp, msg, __FILE__, __func__, __LINE__) -char *_json_ckdb_call(const ckpool_t *ckp, const char *idmsg, json_t *val, +char *_json_ckdb_call(const ckpool_t *ckp, const char *idmsg, json_t *val, bool logged, const char *file, const char *func, const int line); -#define json_ckdb_call(ckp, idmsg, val) _json_ckdb_call(ckp, idmsg, val, __FILE__, __func__, __LINE__) +#define json_ckdb_call(ckp, idmsg, val, logged) _json_ckdb_call(ckp, idmsg, val, logged, __FILE__, __func__, __LINE__) json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); diff --git a/src/stratifier.c b/src/stratifier.c index a4d15722..598877fb 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1171,7 +1171,7 @@ static bool send_recv_auth(stratum_instance_t *client) "createby", "code", "createcode", __func__, "createinet", "127.0.0.1"); - buf = json_ckdb_call(client->ckp, ckdb_ids[ID_AUTH], val); + buf = json_ckdb_call(client->ckp, ckdb_ids[ID_AUTH], val, false); if (likely(buf)) { char *secondaryuserid, *response = alloca(128); @@ -2106,6 +2106,7 @@ static void *ckdbqueue(void *arg) rename_proc("ckdbqueue"); while (42) { + bool logged = false; char *buf = NULL; ckdb_msg_t *msg; @@ -2121,11 +2122,12 @@ static void *ckdbqueue(void *arg) continue; while (!buf) { - buf = json_ckdb_call(ckp, ckdb_ids[msg->idtype], msg->val); + buf = json_ckdb_call(ckp, ckdb_ids[msg->idtype], msg->val, logged); if (unlikely(!buf)) { LOGWARNING("Failed to talk to ckdb, queueing messages"); sleep(5); } + logged = true; } LOGINFO("Got %s ckdb response: %s", ckdb_ids[msg->idtype], buf); free(buf);