From 7dee1e28b5e9f3e9df5a2b4eaad177450586493d Mon Sep 17 00:00:00 2001 From: kanoi Date: Mon, 28 Mar 2016 01:19:24 +1100 Subject: [PATCH] ckdb - report the msg sent on a unix socket send failure --- src/ckdb.c | 35 +++++++++++++++++++++++------------ src/ckdb.h | 4 +++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index f2f58c18..84e0ce47 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -837,6 +837,17 @@ static void check_createdate_ccl(char *cmd, tv_t *cd) STRNCPY(last_cmd, cmd); } +void _ckdb_unix_msg(int sockd, const char *msg, WHERE_FFL_ARGS) +{ + bool ok; + + ok = _send_unix_msg(sockd, msg, UNIX_WRITE_TIMEOUT, WHERE_FFL_PASS); + if (!ok) { + LOGWARNING(" msg was %.42s%s", msg ? : nullstr, + msg ? "..." : EMPTY); + } +} + static uint64_t ticks; static time_t last_tick; @@ -4334,7 +4345,7 @@ static void process_sockd(PGconn *conn, K_ITEM *wq_item) snprintf(rep, siz, "%s.%ld.%s", msgline->id, msgline->now.tv_sec, ans); - send_unix_msg(msgline->sockd, rep); + ckdb_unix_msg(msgline->sockd, rep); close(msgline->sockd); K_WLOCK(breakqueue_free); sockd_count--; @@ -4478,7 +4489,7 @@ static void *process_socket(void *arg) "%s.%ld.?.", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); break; case CMD_ALERTEVENT: case CMD_ALERTOVENT: @@ -4490,7 +4501,7 @@ static void *process_socket(void *arg) tmp = reply_event(EVENTID_NONE, reply); else tmp = reply_ovent(OVENTID_NONE, reply); - send_unix_msg(bq->sockd, tmp); + ckdb_unix_msg(bq->sockd, tmp); FREENULL(tmp); break; case CMD_TERMINATE: @@ -4501,7 +4512,7 @@ static void *process_socket(void *arg) "%s.%ld.ok.exiting", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); everyone_die = true; break; case CMD_PING: @@ -4511,7 +4522,7 @@ static void *process_socket(void *arg) "%s.%ld.ok.pong", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); break; case CMD_VERSION: LOGDEBUG("Listener received" @@ -4521,7 +4532,7 @@ static void *process_socket(void *arg) msgline->id, bq->now.tv_sec, CKDB_VERSION); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); break; case CMD_LOGLEVEL: if (!*(msgline->id)) { @@ -4565,7 +4576,7 @@ static void *process_socket(void *arg) " %d currently %d B", loglevel, oldloglevel); } - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); break; case CMD_FLUSH: LOGDEBUG("Listener received" @@ -4573,7 +4584,7 @@ static void *process_socket(void *arg) snprintf(reply, sizeof(reply), "%s.%ld.ok.splash", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); fflush(stdout); fflush(stderr); if (global_ckp && global_ckp->logfd) @@ -4638,7 +4649,7 @@ static void *process_socket(void *arg) msgline->id, bq->now.tv_sec, msgline->cmd); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); } else { msgline->sockd = bq->sockd; bq->sockd = -1; @@ -4683,7 +4694,7 @@ static void *process_socket(void *arg) snprintf(rep, siz, "%s.%ld.%s", msgline->id, bq->now.tv_sec, ans); - send_unix_msg(bq->sockd, rep); + ckdb_unix_msg(bq->sockd, rep); FREENULL(ans); FREENULL(rep); replied = true; @@ -4705,7 +4716,7 @@ static void *process_socket(void *arg) "%s.%ld.ok.queued", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); } K_WLOCK(workqueue_free); @@ -4746,7 +4757,7 @@ static void *process_socket(void *arg) "%s.%ld.failed.code", msgline->id, bq->now.tv_sec); - send_unix_msg(bq->sockd, reply); + ckdb_unix_msg(bq->sockd, reply); break; } if (bq->sockd >= 0) { diff --git a/src/ckdb.h b/src/ckdb.h index 9487deb8..beacd968 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -51,7 +51,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.5" -#define CKDB_VERSION DB_VERSION"-2.000" +#define CKDB_VERSION DB_VERSION"-2.001" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -2649,6 +2649,8 @@ extern K_STORE *userinfo_store; extern void logmsg(int loglevel, const char *fmt, ...); extern void setnow(tv_t *now); +extern void _ckdb_unix_msg(int sockd, const char *msg, WHERE_FFL_ARGS); +#define ckdb_unix_msg(_sockd, _msg) _ckdb_unix_msg(_sockd, _msg, WHERE_FFL_HERE) extern void tick(); extern PGconn *dbconnect(); extern void sequence_report(bool lock);