From 8b8eb5dc62dbc59220f45b9be5fe366e355f0772 Mon Sep 17 00:00:00 2001 From: kanoi Date: Tue, 15 Sep 2015 20:27:21 +1000 Subject: [PATCH] ckdb - shift wasn't flagging workers used if not in the last shift --- src/ckdb.h | 2 +- src/ckdb_cmd.c | 30 ++++++++++++++++++++++++++---- src/ckdb_crypt.c | 6 +++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/ckdb.h b/src/ckdb.h index 4bb19b5b..c34666c5 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -55,7 +55,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.2" -#define CKDB_VERSION DB_VERSION"-1.301" +#define CKDB_VERSION DB_VERSION"-1.302" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 935adca5..1f501c2d 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -269,6 +269,7 @@ static char *cmd_2fa(__maybe_unused PGconn *conn, char *cmd, char *id, __func__, st = safe_text_nonull(users->username), users->databits); + FREENULL(st); goto dame; } @@ -5073,6 +5074,7 @@ typedef struct worker_match { bool match; size_t len; bool used; + bool everused; } WM; static char *worker_offset(char *workername) @@ -5158,7 +5160,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, size_t siz = sizeof(reply); char *select = NULL; WM workm[SELECT_LIMIT+1]; - char *buf, *work; + char *buf = NULL, *work, *st = NULL; size_t len, off; tv_t marker_end = { 0L, 0L }; int rows, want, i, where_all; @@ -5198,12 +5200,19 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, if (i_select) select = strdup(transfer_data(i_select)); + APPEND_REALLOC_INIT(buf, off, len); + snprintf(tmp, sizeof(tmp), " select='%s'", + select ? st = safe_text_nonull(select) : "null"); + FREENULL(st); + APPEND_REALLOC(buf, off, len, tmp); + bzero(workm, sizeof(workm)); where_all = select_list(&(workm[0]), select); // Nothing selected = all if (workm[0].worker == NULL) { where_all = 0; workm[0].worker = WORKERS_ALL; + APPEND_REALLOC(buf, off, len, " no workers"); } else { for (i = 0; workm[i].worker; i++) { // N.B. len is only used if match is true @@ -5214,12 +5223,24 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, workm[i].match = true; workm[i].len--; } + snprintf(tmp, sizeof(tmp), " workm[%d]=%s,%s,%d", + i, st = safe_text_nonull(workm[i].worker), + workm[i].match ? "Y" : "N", + (int)(workm[i].len)); + FREENULL(st); + APPEND_REALLOC(buf, off, len, tmp); } } if (where_all >= 0) workm[where_all].used = true; + snprintf(tmp, sizeof(tmp), " where_all=%d", where_all); + APPEND_REALLOC(buf, off, len, tmp); + LOGDEBUG("%s() user=%"PRId64"/%s' %s", + __func__, users->userid, users->username, buf+1); + FREENULL(buf); + APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC(buf, off, len, "ok."); INIT_MARKERSUMMARY(&ms_look); @@ -5269,6 +5290,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, (workm[want].match && strncmp(work, workm[want].worker, workm[want].len) == 0) || (!(workm[want].match) && strcmp(workm[want].worker, work) == 0)) { workm[want].used = true; + workm[want].everused = true; ms_add[want].diffacc += ms->diffacc; ms_add[want].diffsta += ms->diffsta; ms_add[want].diffdup += ms->diffdup; @@ -5414,7 +5436,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, K_RUNLOCK(workmarkers_free); for (i = 0; workm[i].worker; i++) { - if (workm[i].used) { + if (workm[i].everused) { snprintf(tmp, sizeof(tmp), "%d_worker=%s%s%c", i, workm[i].worker, @@ -5448,7 +5470,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "arn=%s", "Shifts"); APPEND_REALLOC(buf, off, len, tmp); for (i = 0; workm[i].worker; i++) { - if (workm[i].used) { + if (workm[i].everused) { snprintf(tmp, sizeof(tmp), ",Worker_%d", i); APPEND_REALLOC(buf, off, len, tmp); } @@ -5457,7 +5479,7 @@ static char *cmd_shifts(__maybe_unused PGconn *conn, char *cmd, char *id, snprintf(tmp, sizeof(tmp), "%carp=", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); for (i = 0; workm[i].worker; i++) { - if (workm[i].used) { + if (workm[i].everused) { snprintf(tmp, sizeof(tmp), ",%d_", i); APPEND_REALLOC(buf, off, len, tmp); } diff --git a/src/ckdb_crypt.c b/src/ckdb_crypt.c index 7ad0109f..e21cddf4 100644 --- a/src/ckdb_crypt.c +++ b/src/ckdb_crypt.c @@ -36,7 +36,7 @@ char *_tob32(USERS *users, unsigned char *bin, size_t len, char *name, if (osiz != olen) { LOGEMERG("%s() of '%s' data for '%s' invalid olen=%d != osiz=%d" WHERE_FFL, - __func__, name, safe_text_nonull(users->username), + __func__, name, st = safe_text_nonull(users->username), (int)olen, (int)osiz, WHERE_FFL_PASS); FREENULL(st); olen = osiz; @@ -59,8 +59,8 @@ char *_tob32(USERS *users, unsigned char *bin, size_t len, char *name, "ch=%d, i=%d j=%d bits=%d bin=0x%s len=%d " "olen=%d" WHERE_FFL, __func__, name, - safe_text_nonull(users->username), ch, i, j, - bits, binstr, (int)len, (int)olen, + st = safe_text_nonull(users->username), + ch, i, j, bits, binstr, (int)len, (int)olen, WHERE_FFL_PASS); FREENULL(st); FREENULL(binstr);