Browse Source

ckdb - use safe_text_null where trailing null isn't needed

master
kanoi 10 years ago
parent
commit
da2d33a497
  1. 6
      src/ckdb.h
  2. 54
      src/ckdb_dbio.c

6
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.070" #define CKDB_VERSION DB_VERSION"-1.071"
#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__
@ -790,7 +790,7 @@ extern tv_t missing_secuser_max;
* maxseq is incremented to the current maximum N+x each time a record is * maxseq is incremented to the current maximum N+x each time a record is
* processed * processed
* If we get up to N+3 but it is unexpectedly followed by N+5, that means N+4 * If we get up to N+3 but it is unexpectedly followed by N+5, that means N+4
* is currently missing - so it is flagged as missing by time=0 and the * is currently missing - so it is flagged as missing by MISSFLAG=0 and the
* missing counters are incremented - maxseq will now be N+5 * missing counters are incremented - maxseq will now be N+5
* Once we reach N+size we need to discard N and use it as N+size * Once we reach N+size we need to discard N and use it as N+size
* and increment seqbase N * and increment seqbase N
@ -804,7 +804,7 @@ extern tv_t missing_secuser_max;
* If we receive an item N-x i.e. less than seqbase N, then: * If we receive an item N-x i.e. less than seqbase N, then:
* If maxseq-N = size then N-x is considered stale and the stale counters * If maxseq-N = size then N-x is considered stale and the stale counters
* are incremented since there's no unused items below N available * are incremented since there's no unused items below N available
* this shouldn't normally happen after we've received size seq numbers * This shouldn't normally happen after we've received size seq numbers
* Else maxseq-N is less than size, that means there are unused items below N * Else maxseq-N is less than size, that means there are unused items below N
* This will usually only be with a new sequence and the first seq was out * This will usually only be with a new sequence and the first seq was out
* of order, before lower sequence numbers, thus maxseq should be close to * of order, before lower sequence numbers, thus maxseq should be close to

54
src/ckdb_dbio.c

@ -901,7 +901,7 @@ K_ITEM *useratts_add(PGconn *conn, char *username, char *attname,
if (!u_item) { if (!u_item) {
LOGERR("%s(): unknown user '%s'", LOGERR("%s(): unknown user '%s'",
__func__, __func__,
st = safe_text(username)); st = safe_text_nonull(username));
FREENULL(st); FREENULL(st);
goto unitem; goto unitem;
} }
@ -2797,7 +2797,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
if (!w_item) { if (!w_item) {
LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld", LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld",
__func__, shares->userid, __func__, shares->userid,
st = safe_text(shares->workername), st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec, shares->createdate.tv_usec); shares->createdate.tv_sec, shares->createdate.tv_usec);
FREENULL(st); FREENULL(st);
return false; return false;
@ -2811,7 +2811,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
LOGDEBUG("%s(): workmarker exists for wid %"PRId64 LOGDEBUG("%s(): workmarker exists for wid %"PRId64
" %"PRId64"/%s/%ld,%ld", " %"PRId64"/%s/%ld,%ld",
__func__, shares->workinfoid, shares->userid, __func__, shares->workinfoid, shares->userid,
st = safe_text(shares->workername), st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec, shares->createdate.tv_sec,
shares->createdate.tv_usec); shares->createdate.tv_usec);
FREENULL(st); FREENULL(st);
@ -2827,7 +2827,7 @@ static bool shares_process(PGconn *conn, SHARES *shares, K_TREE *trf_root)
"%"PRId64" %"PRId64"/%s/%ld,%ld", "%"PRId64" %"PRId64"/%s/%ld,%ld",
__func__, sharesummary->complete, __func__, sharesummary->complete,
shares->workinfoid, shares->userid, shares->workinfoid, shares->userid,
st = safe_text(shares->workername), st = safe_text_nonull(shares->workername),
shares->createdate.tv_sec, shares->createdate.tv_sec,
shares->createdate.tv_usec); shares->createdate.tv_usec);
FREENULL(st); FREENULL(st);
@ -2938,7 +2938,7 @@ keep:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32 LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share procured", " Early share procured",
__func__, early_shares->workinfoid, __func__, early_shares->workinfoid,
st = safe_text(early_shares->workername), st = safe_text_nonull(early_shares->workername),
early_shares->createdate.tv_sec, early_shares->createdate.tv_sec,
early_shares->createdate.tv_usec, cd_buf, early_shares->createdate.tv_usec, cd_buf,
early_shares->oldcount, early_shares->redo); early_shares->oldcount, early_shares->redo);
@ -2953,7 +2953,7 @@ discard:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32 LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share discarded!%s", " Early share discarded!%s",
__func__, early_shares->workinfoid, __func__, early_shares->workinfoid,
st = safe_text(early_shares->workername), st = safe_text_nonull(early_shares->workername),
early_shares->createdate.tv_sec, early_shares->createdate.tv_sec,
early_shares->createdate.tv_usec, cd_buf, early_shares->createdate.tv_usec, cd_buf,
early_shares->oldcount, early_shares->redo, why); early_shares->oldcount, early_shares->redo, why);
@ -2982,7 +2982,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld", LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld",
__func__, __func__,
workinfoid, st = safe_text(workername), nonce, workinfoid, st = safe_text_nonull(workername), nonce,
errn, cd->tv_sec, cd->tv_usec); errn, cd->tv_sec, cd->tv_usec);
FREENULL(st); FREENULL(st);
@ -3002,7 +3002,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
or the authentication information got to ckdb after or the authentication information got to ckdb after
the shares ... which shouldn't ever happen */ the shares ... which shouldn't ever happen */
LOGERR("%s() %s/%ld,%ld %s no user! Share discarded!", LOGERR("%s() %s/%ld,%ld %s no user! Share discarded!",
__func__, st = safe_text(username), __func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
goto tisbad; goto tisbad;
@ -3029,7 +3029,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
btv_to_buf(cd, cd_buf, sizeof(cd_buf)); btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! " LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! "
"Share corrected", "Share corrected",
__func__, st = safe_text(username), __func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
} }
@ -3044,7 +3044,7 @@ bool shares_add(PGconn *conn, char *workinfoid, char *username, char *workername
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! " LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! "
"Early share queued!", "Early share queued!",
__func__, shares->workinfoid, __func__, shares->workinfoid,
st = safe_text(workername), st = safe_text_nonull(workername),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
shares->redo = 0; shares->redo = 0;
@ -3102,7 +3102,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
if (!w_item) { if (!w_item) {
LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld", LOGDEBUG("%s(): new_default_worker failed %"PRId64"/%s/%ld,%ld",
__func__, shareerrors->userid, __func__, shareerrors->userid,
st = safe_text(shareerrors->workername), st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec, shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec); shareerrors->createdate.tv_usec);
FREENULL(st); FREENULL(st);
@ -3118,7 +3118,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
" %"PRId64"/%s/%ld,%ld", " %"PRId64"/%s/%ld,%ld",
__func__, shareerrors->workinfoid, __func__, shareerrors->workinfoid,
shareerrors->userid, shareerrors->userid,
st = safe_text(shareerrors->workername), st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec, shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec); shareerrors->createdate.tv_usec);
FREENULL(st); FREENULL(st);
@ -3136,7 +3136,7 @@ static bool shareerrors_process(PGconn *conn, SHAREERRORS *shareerrors,
__func__, sharesummary->complete, __func__, sharesummary->complete,
shareerrors->workinfoid, shareerrors->workinfoid,
shareerrors->userid, shareerrors->userid,
st = safe_text(shareerrors->workername), st = safe_text_nonull(shareerrors->workername),
shareerrors->createdate.tv_sec, shareerrors->createdate.tv_sec,
shareerrors->createdate.tv_usec); shareerrors->createdate.tv_usec);
FREENULL(st); FREENULL(st);
@ -3249,7 +3249,7 @@ keep:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32 LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share procured", " Early share procured",
__func__, early_shareerrors->workinfoid, __func__, early_shareerrors->workinfoid,
st = safe_text(early_shareerrors->workername), st = safe_text_nonull(early_shareerrors->workername),
early_shareerrors->createdate.tv_sec, early_shareerrors->createdate.tv_sec,
early_shareerrors->createdate.tv_usec, cd_buf, early_shareerrors->createdate.tv_usec, cd_buf,
early_shareerrors->oldcount, early_shareerrors->redo); early_shareerrors->oldcount, early_shareerrors->redo);
@ -3264,7 +3264,7 @@ discard:
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32 LOGERR("%s() %"PRId64"/%s/%ld,%ld %s/%"PRId32"/%"PRId32
" Early share discarded!%s", " Early share discarded!%s",
__func__, early_shareerrors->workinfoid, __func__, early_shareerrors->workinfoid,
st = safe_text(early_shareerrors->workername), st = safe_text_nonull(early_shareerrors->workername),
early_shareerrors->createdate.tv_sec, early_shareerrors->createdate.tv_sec,
early_shareerrors->createdate.tv_usec, cd_buf, early_shareerrors->createdate.tv_usec, cd_buf,
early_shareerrors->oldcount, early_shareerrors->redo, why); early_shareerrors->oldcount, early_shareerrors->redo, why);
@ -3290,7 +3290,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld", LOGDEBUG("%s(): %s/%s/%s/%s/%ld,%ld",
__func__, __func__,
workinfoid, st = safe_text(workername), errn, workinfoid, st = safe_text_nonull(workername), errn,
error, cd->tv_sec, cd->tv_usec); error, cd->tv_sec, cd->tv_usec);
FREENULL(st); FREENULL(st);
@ -3307,7 +3307,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
if (!u_item) { if (!u_item) {
btv_to_buf(cd, cd_buf, sizeof(cd_buf)); btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s no user! Shareerror discarded!", LOGERR("%s() %s/%ld,%ld %s no user! Shareerror discarded!",
__func__, st = safe_text(username), __func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
goto tisbad; goto tisbad;
@ -3330,7 +3330,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
btv_to_buf(cd, cd_buf, sizeof(cd_buf)); btv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! " LOGERR("%s() %s/%ld,%ld %s missing secondaryuserid! "
"Sharerror corrected", "Sharerror corrected",
__func__, st = safe_text(username), __func__, st = safe_text_nonull(username),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
} }
@ -3345,7 +3345,7 @@ bool shareerrors_add(PGconn *conn, char *workinfoid, char *username,
LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! " LOGERR("%s() %"PRId64"/%s/%ld,%ld %s no workinfo! "
"Early shareerror queued!", "Early shareerror queued!",
__func__, shareerrors->workinfoid, __func__, shareerrors->workinfoid,
st = safe_text(workername), st = safe_text_nonull(workername),
cd->tv_sec, cd->tv_usec, cd_buf); cd->tv_sec, cd->tv_usec, cd_buf);
FREENULL(st); FREENULL(st);
shareerrors->redo = 0; shareerrors->redo = 0;
@ -4004,7 +4004,7 @@ bool _sharesummary_update(PGconn *conn, SHARES *s_row, SHAREERRORS *e_row, K_ITE
LOGDEBUG("%s(): updating sharesummary not '%c'" LOGDEBUG("%s(): updating sharesummary not '%c'"
" %"PRId64"/%s/%"PRId64"/%s", " %"PRId64"/%s/%"PRId64"/%s",
__func__, SUMMARY_NEW, row->userid, __func__, SUMMARY_NEW, row->userid,
st = safe_text(row->workername), st = safe_text_nonull(row->workername),
row->workinfoid, row->complete); row->workinfoid, row->complete);
FREENULL(st); FREENULL(st);
} }
@ -4956,7 +4956,7 @@ flail:
snprintf(tmp, sizeof(tmp), snprintf(tmp, sizeof(tmp),
" Reward: %f, Worker: %s, ShareEst: %.1f %s%s%% UTC:%s", " Reward: %f, Worker: %s, ShareEst: %.1f %s%s%% UTC:%s",
BTC_TO_D(row->reward), BTC_TO_D(row->reward),
st = safe_text(row->workername), st = safe_text_nonull(row->workername),
pool.diffacc, est, pct, cd_buf); pool.diffacc, est, pct, cd_buf);
FREENULL(st); FREENULL(st);
if (pool.workinfoid < row->workinfoid) { if (pool.workinfoid < row->workinfoid) {
@ -5686,7 +5686,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username,
} else { } else {
LOGDEBUG("%s(): unknown user '%s'", LOGDEBUG("%s(): unknown user '%s'",
__func__, __func__,
st = safe_text(username)); st = safe_text_nonull(username));
FREENULL(st); FREENULL(st);
} }
if (!u_item) if (!u_item)
@ -5727,7 +5727,7 @@ bool auths_add(PGconn *conn, char *poolinstance, char *username,
// Shouldn't actually be possible unless twice in the logs // Shouldn't actually be possible unless twice in the logs
tv_to_buf(cd, cd_buf, sizeof(cd_buf)); tv_to_buf(cd, cd_buf, sizeof(cd_buf));
LOGERR("%s(): Duplicate auths ignored %s/%s/%s", LOGERR("%s(): Duplicate auths ignored %s/%s/%s",
__func__, poolinstance, st = safe_text(workername), __func__, poolinstance, st = safe_text_nonull(workername),
cd_buf); cd_buf);
FREENULL(st); FREENULL(st);
@ -6056,7 +6056,7 @@ bool userstats_add(char *poolinstance, char *elapsed, char *username,
if (!u_item) { if (!u_item) {
LOGERR("%s(): unknown user '%s'", LOGERR("%s(): unknown user '%s'",
__func__, __func__,
st = safe_text(username)); st = safe_text_nonull(username));
FREENULL(st); FREENULL(st);
return false; return false;
} }
@ -6166,8 +6166,8 @@ bool workerstats_add(char *poolinstance, char *elapsed, char *username,
char *usr = NULL, *wrk = NULL; char *usr = NULL, *wrk = NULL;
LOGERR("%s(): unknown user '%s' (worker=%s)", LOGERR("%s(): unknown user '%s' (worker=%s)",
__func__, __func__,
usr = safe_text(username), usr = safe_text_nonull(username),
wrk = safe_text(workername)); wrk = safe_text_nonull(workername));
FREENULL(usr); FREENULL(usr);
FREENULL(wrk); FREENULL(wrk);
return false; return false;
@ -6261,7 +6261,7 @@ bool markersummary_add(PGconn *conn, K_ITEM *ms_item, char *by, char *code,
LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f", LOGDEBUG("%s() adding ms %"PRId64"/%"PRId64"/%s/%.0f",
__func__, row->markerid, row->userid, __func__, row->markerid, row->userid,
st = safe_text(row->workername), st = safe_text_nonull(row->workername),
row->diffacc); row->diffacc);
FREENULL(st); FREENULL(st);

Loading…
Cancel
Save