Browse Source

ckdb - allocate seqnam with the full name and use it

master
kanoi 10 years ago
parent
commit
040dddc6ec
  1. 24
      src/ckdb.c
  2. 2
      src/ckdb.h

24
src/ckdb.c

@ -951,6 +951,7 @@ static void clean_up(ckpool_t *ckp)
static void alloc_storage() static void alloc_storage()
{ {
size_t len;
int seq; int seq;
seqset_free = k_new_list("SeqSet", sizeof(SEQSET), seqset_free = k_new_list("SeqSet", sizeof(SEQSET),
@ -958,7 +959,7 @@ static void alloc_storage()
seqset_store = k_new_store(seqset_free); seqset_store = k_new_store(seqset_free);
// Map the SEQ_NNN values to their cmd names // Map the SEQ_NNN values to their cmd names
seqnam[0] = SEQALL; seqnam[0] = strdup(SEQALL);
for (seq = 0; ckdb_cmds[seq].cmd_val != CMD_END; seq++) { for (seq = 0; ckdb_cmds[seq].cmd_val != CMD_END; seq++) {
if (ckdb_cmds[seq].seq != SEQ_NONE) { if (ckdb_cmds[seq].seq != SEQ_NONE) {
if (seqnam[ckdb_cmds[seq].seq]) { if (seqnam[ckdb_cmds[seq].seq]) {
@ -968,7 +969,12 @@ static void alloc_storage()
seq, seqnam[ckdb_cmds[seq].seq], seq, seqnam[ckdb_cmds[seq].seq],
ckdb_cmds[seq].cmd_str); ckdb_cmds[seq].cmd_str);
} }
seqnam[ckdb_cmds[seq].seq] = ckdb_cmds[seq].cmd_str; len = strlen(SEQRPE) + strlen(ckdb_cmds[seq].cmd_str) + 1;
seqnam[ckdb_cmds[seq].seq] = malloc(len);
if (!(seqnam[ckdb_cmds[seq].seq]))
quithere(1, "malloc (%d) OOM", (int)len);
snprintf(seqnam[ckdb_cmds[seq].seq], len, "%s%s",
SEQPRE, ckdb_cmds[seq].cmd_str);
} }
} }
for (seq = 0; seq < SEQ_MAX; seq++) { for (seq = 0; seq < SEQ_MAX; seq++) {
@ -1253,6 +1259,7 @@ static void dealloc_storage()
K_ITEM *s_item; K_ITEM *s_item;
char *st = NULL; char *st = NULL;
SHARES *shares; SHARES *shares;
int seq;
LOGWARNING("%s() logqueue ...", __func__); LOGWARNING("%s() logqueue ...", __func__);
@ -1387,6 +1394,9 @@ static void dealloc_storage()
FREE_LIST_DATA(seqset); FREE_LIST_DATA(seqset);
FREE_LISTS(seqset); FREE_LISTS(seqset);
for (seq = 0; seq < SEQ_MAX; seq++)
FREENULL(seqnam[seq]);
LOGWARNING("%s() finished", __func__); LOGWARNING("%s() finished", __func__);
} }
@ -2136,7 +2146,7 @@ static enum cmd_values process_seq(K_ITEM *seqall, int which, tv_t *cd,
size_t len, off; size_t len, off;
bool dupall, dupcmd; bool dupall, dupcmd;
char *code = NULL; char *code = NULL;
char buf[64]; char *seqcmdnam;
n_seqstt = n_seqpid = n_seqcmd = 0; n_seqstt = n_seqpid = n_seqcmd = 0;
n_seqall = atol(transfer_data(seqall)); n_seqall = atol(transfer_data(seqall));
@ -2157,8 +2167,8 @@ static enum cmd_values process_seq(K_ITEM *seqall, int which, tv_t *cd,
if ((seqpid = find_transfer(trf_root, SEQPID))) if ((seqpid = find_transfer(trf_root, SEQPID)))
n_seqpid = atol(transfer_data(seqpid)); n_seqpid = atol(transfer_data(seqpid));
snprintf(buf, sizeof(buf), "%s%s", SEQPRE, ckdb_cmds[which].cmd_str); seqcmdnam = seqnam[ckdb_cmds[which].seq];
if ((seqcmd = find_transfer(trf_root, buf))) if ((seqcmd = find_transfer(trf_root, seqcmdnam)))
n_seqcmd = atol(transfer_data(seqcmd)); n_seqcmd = atol(transfer_data(seqcmd));
/* Make one message with the initial seq missing/value problems ... /* Make one message with the initial seq missing/value problems ...
@ -2176,7 +2186,7 @@ static enum cmd_values process_seq(K_ITEM *seqall, int which, tv_t *cd,
APPEND_REALLOC(err, off, len, BLANK SEQPID); APPEND_REALLOC(err, off, len, BLANK SEQPID);
if (!seqcmd) { if (!seqcmd) {
APPEND_REALLOC(err, off, len, BLANK); APPEND_REALLOC(err, off, len, BLANK);
APPEND_REALLOC(err, off, len, buf); APPEND_REALLOC(err, off, len, seqcmdnam);
} }
} }
if (seqstt && n_seqstt < DATE_BEGIN) { if (seqstt && n_seqstt < DATE_BEGIN) {
@ -2220,7 +2230,7 @@ static enum cmd_values process_seq(K_ITEM *seqall, int which, tv_t *cd,
dupall = update_seq(SEQ_ALL, n_seqall, n_seqstt, n_seqpid, SEQALL, dupall = update_seq(SEQ_ALL, n_seqall, n_seqstt, n_seqpid, SEQALL,
now, cd, code, seqitemflags, msg); now, cd, code, seqitemflags, msg);
dupcmd = update_seq(ckdb_cmds[which].seq, n_seqcmd, n_seqstt, n_seqpid, dupcmd = update_seq(ckdb_cmds[which].seq, n_seqcmd, n_seqstt, n_seqpid,
buf, now, cd, code, seqitemflags, msg); seqcmdnam, now, cd, code, seqitemflags, msg);
if (dupall != dupcmd) { if (dupall != dupcmd) {
// Bad/corrupt data or a code bug // Bad/corrupt data or a code bug

2
src/ckdb.h

@ -55,7 +55,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.0" #define DB_VERSION "1.0.0"
#define CKDB_VERSION DB_VERSION"-1.079" #define CKDB_VERSION DB_VERSION"-1.080"
#define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

Loading…
Cancel
Save