Browse Source

make LOG* macros typecheck and fix related errors/warnings

master
kanoi 10 years ago
parent
commit
503ec09f27
  1. 4
      src/ckdb.c
  2. 2
      src/ckdb.h
  3. 2
      src/ckdb_btc.c
  4. 2
      src/ckdb_cmd.c
  5. 8
      src/ckdb_data.c
  6. 12
      src/connector.c
  7. 27
      src/libckpool.h
  8. 36
      src/stratifier.c

4
src/ckdb.c

@ -3160,7 +3160,7 @@ static void confirm_reload()
} }
if (confirm_last_workinfoid == 0) { if (confirm_last_workinfoid == 0) {
LOGWARNING("%s(): there are no unconfirmed sharesummary records in the DB", LOGWARNING("%s(): there are no unconfirmed sharesummary records in the DB",
__func__, buf); __func__);
return; return;
} }
@ -3230,7 +3230,7 @@ static void confirm_reload()
// last from default // last from default
if (confirm_last_workinfoid < confirm_first_workinfoid) { if (confirm_last_workinfoid < confirm_first_workinfoid) {
LOGWARNING("%s(): no unconfirmed sharesummary records before start", LOGWARNING("%s(): no unconfirmed sharesummary records before start",
__func__, buf); __func__);
return; return;
} }
first_reason = "start range"; first_reason = "start range";

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.6" #define DB_VERSION "0.9.6"
#define CKDB_VERSION DB_VERSION"-0.667" #define CKDB_VERSION DB_VERSION"-0.700"
#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__

2
src/ckdb_btc.c

@ -329,7 +329,7 @@ void btc_blockstatus(BLOCKS *blocks)
len = strlen(blocks->blockhash); len = strlen(blocks->blockhash);
if (len != SHA256SIZHEX) { if (len != SHA256SIZHEX) {
LOGERR("%s() invalid blockhash size %d (%d) for block %d", LOGERR("%s() invalid blockhash size %d (%d) for block %d",
__func__, len, SHA256SIZHEX, blocks->height); __func__, (int)len, SHA256SIZHEX, blocks->height);
/* So we don't keep repeating the message /* So we don't keep repeating the message
* This should never happen */ * This should never happen */

2
src/ckdb_cmd.c

@ -1665,7 +1665,7 @@ awconf:
return strdup(reply); return strdup(reply);
} }
LOGERR("%s.bad.cmd %s", cmd); LOGERR("%s.bad.cmd %s", id, cmd);
return strdup("bad.cmd"); return strdup("bad.cmd");
} }

8
src/ckdb_data.c

@ -488,7 +488,7 @@ K_ITEM *_optional_name(K_TREE *trf_root, char *name, int len, char *patt,
dlen = 0; dlen = 0;
if (!mvalue || (int)dlen < len) { if (!mvalue || (int)dlen < len) {
if (!mvalue) { if (!mvalue) {
LOGERR("%s(): field '%s' NULL (%d) from %s():%d", LOGERR("%s(): field '%s' NULL (%d:%d) from %s():%d",
__func__, name, (int)dlen, len, func, line); __func__, name, (int)dlen, len, func, line);
} else } else
snprintf(reply, siz, "failed.short %s", name); snprintf(reply, siz, "failed.short %s", name);
@ -1749,8 +1749,8 @@ void auto_age_older(PGconn *conn, int64_t workinfoid, char *poolinstance,
min_buf, max_buf); min_buf, max_buf);
} }
LOGWARNING("%s() Auto-aged %"PRId64"(%"PRId64") " LOGWARNING("%s() Auto-aged %"PRId64"(%"PRId64") "
"share%s %d sharesummar%s %d workinfoid%s " "share%s %"PRId64" sharesummar%s %"PRId32
"%s %s", " workinfoid%s %s %s",
__func__, __func__,
s_count_tot, s_diff_tot, s_count_tot, s_diff_tot,
(s_count_tot == 1) ? "" : "s", (s_count_tot == 1) ? "" : "s",
@ -2028,7 +2028,7 @@ void set_block_share_counters()
LOGEMERG("%s(): ERROR workmarker %"PRId64" has an invalid" LOGEMERG("%s(): ERROR workmarker %"PRId64" has an invalid"
" workinfoid range start=%"PRId64" end=%"PRId64 " workinfoid range start=%"PRId64" end=%"PRId64
" due to pool lastblock=%"PRId32 " due to pool lastblock=%"PRId32
" workinfoid="PRId64, " workinfoid=%"PRId64,
__func__, workmarkers->markerid, __func__, workmarkers->markerid,
workmarkers->workinfoidstart, workmarkers->workinfoidstart,
workmarkers->workinfoidend, workmarkers->workinfoidend,

12
src/connector.c

@ -176,7 +176,7 @@ static int drop_client(conn_instance_t *ci, client_instance_t *client)
ck_wunlock(&ci->lock); ck_wunlock(&ci->lock);
if (fd > -1) if (fd > -1)
LOGINFO("Connector dropped client %d fd %d", client->id, fd); LOGINFO("Connector dropped client %"PRId64" fd %d", client->id, fd);
return fd; return fd;
} }
@ -261,7 +261,7 @@ reparse:
if (!(val = json_loads(msg, 0, NULL))) { if (!(val = json_loads(msg, 0, NULL))) {
char *buf = strdup("Invalid JSON, disconnecting\n"); char *buf = strdup("Invalid JSON, disconnecting\n");
LOGINFO("Client id %d sent invalid json message %s", client->id, msg); LOGINFO("Client id %"PRId64" sent invalid json message %s", client->id, msg);
send_client(ci, client->id, buf); send_client(ci, client->id, buf);
invalidate_client(ckp, ci, client); invalidate_client(ckp, ci, client);
return; return;
@ -421,13 +421,13 @@ void *sender(void *arg)
ret = wait_write_select(fd, 0); ret = wait_write_select(fd, 0);
if (ret < 1) { if (ret < 1) {
if (ret < 0) { if (ret < 0) {
LOGINFO("Client id %d fd %d interrupted", client->id, fd); LOGINFO("Client id %"PRId64" fd %d interrupted", client->id, fd);
invalidate_client(ckp, ci, client); invalidate_client(ckp, ci, client);
free(sender_send->buf); free(sender_send->buf);
free(sender_send); free(sender_send);
continue; continue;
} }
LOGDEBUG("Client %d not ready for writes", client->id); LOGDEBUG("Client %"PRId64" not ready for writes", client->id);
/* Append it to the tail of the delayed sends list. /* Append it to the tail of the delayed sends list.
* This is the only function that alters it so no * This is the only function that alters it so no
@ -439,7 +439,7 @@ void *sender(void *arg)
while (sender_send->len) { while (sender_send->len) {
ret = send(fd, sender_send->buf + ofs, sender_send->len , 0); ret = send(fd, sender_send->buf + ofs, sender_send->len , 0);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {
LOGINFO("Client id %d fd %d disconnected", client->id, fd); LOGINFO("Client id %"PRId64" fd %d disconnected", client->id, fd);
invalidate_client(ckp, ci, client); invalidate_client(ckp, ci, client);
break; break;
} }
@ -519,7 +519,7 @@ static void passthrough_client(conn_instance_t *ci, client_instance_t *client)
{ {
char *buf; char *buf;
LOGINFO("Connector adding passthrough client %d", client->id); LOGINFO("Connector adding passthrough client %"PRId64, client->id);
client->passthrough = true; client->passthrough = true;
ASPRINTF(&buf, "{\"result\": true}\n"); ASPRINTF(&buf, "{\"result\": true}\n");
send_client(ci, client->id, buf); send_client(ci, client->id, buf);

27
src/libckpool.h

@ -190,14 +190,25 @@ static inline void flip_80(void *dest_p, const void *src_p)
void logmsg(int loglevel, const char *fmt, ...); void logmsg(int loglevel, const char *fmt, ...);
#define LOGEMERG(fmt, ...) logmsg(LOG_EMERG, fmt, ##__VA_ARGS__) #define DEFLOGBUFSIZ 512
#define LOGALERT(fmt, ...) logmsg(LOG_ALERT, fmt, ##__VA_ARGS__)
#define LOGCRIT(fmt, ...) logmsg(LOG_CRIT, fmt, ##__VA_ARGS__) #define LOGMSGSIZ(__siz, __lvl, __fmt, ...) do { \
#define LOGERR(fmt, ...) logmsg(LOG_ERR, fmt, ##__VA_ARGS__) char tmp42[__siz]; \
#define LOGWARNING(fmt, ...) logmsg(LOG_WARNING, fmt, ##__VA_ARGS__) snprintf(tmp42, sizeof(tmp42), __fmt, ##__VA_ARGS__); \
#define LOGNOTICE(fmt, ...) logmsg(LOG_NOTICE, fmt, ##__VA_ARGS__) logmsg(__lvl, "%s", tmp42); \
#define LOGINFO(fmt, ...) logmsg(LOG_INFO, fmt, ##__VA_ARGS__) } while(0)
#define LOGDEBUG(fmt, ...) logmsg(LOG_DEBUG, fmt, ##__VA_ARGS__)
#define LOGMSG(_lvl, _fmt, ...) \
LOGMSGSIZ(DEFLOGBUFSIZ, _lvl, _fmt, ##__VA_ARGS__)
#define LOGEMERG(fmt, ...) LOGMSG(LOG_EMERG, fmt, ##__VA_ARGS__)
#define LOGALERT(fmt, ...) LOGMSG(LOG_ALERT, fmt, ##__VA_ARGS__)
#define LOGCRIT(fmt, ...) LOGMSG(LOG_CRIT, fmt, ##__VA_ARGS__)
#define LOGERR(fmt, ...) LOGMSG(LOG_ERR, fmt, ##__VA_ARGS__)
#define LOGWARNING(fmt, ...) LOGMSG(LOG_WARNING, fmt, ##__VA_ARGS__)
#define LOGNOTICE(fmt, ...) LOGMSG(LOG_NOTICE, fmt, ##__VA_ARGS__)
#define LOGINFO(fmt, ...) LOGMSG(LOG_INFO, fmt, ##__VA_ARGS__)
#define LOGDEBUG(fmt, ...) LOGMSG(LOG_DEBUG, fmt, ##__VA_ARGS__)
#define IN_FMT_FFL " in %s %s():%d" #define IN_FMT_FFL " in %s %s():%d"
#define quitfrom(status, _file, _func, _line, fmt, ...) do { \ #define quitfrom(status, _file, _func, _line, fmt, ...) do { \

36
src/stratifier.c

@ -2500,12 +2500,12 @@ out:
if (client->first_invalid < client->last_share.tv_sec || !client->first_invalid) if (client->first_invalid < client->last_share.tv_sec || !client->first_invalid)
client->first_invalid = now_t; client->first_invalid = now_t;
else if (client->first_invalid && client->first_invalid < now_t - 120) { else if (client->first_invalid && client->first_invalid < now_t - 120) {
LOGNOTICE("Client %d rejecting for 120s, disconnecting", client->id); LOGNOTICE("Client %"PRId64" rejecting for 120s, disconnecting", client->id);
stratum_send_message(client, "Disconnecting for continuous invalid shares"); stratum_send_message(client, "Disconnecting for continuous invalid shares");
client->reject = 2; client->reject = 2;
} else if (client->first_invalid && client->first_invalid < now_t - 60) { } else if (client->first_invalid && client->first_invalid < now_t - 60) {
if (!client->reject) { if (!client->reject) {
LOGINFO("Client %d rejecting for 60s, sending diff", client->id); LOGINFO("Client %"PRId64" rejecting for 60s, sending diff", client->id);
stratum_send_diff(client); stratum_send_diff(client);
client->reject = 1; client->reject = 1;
} }
@ -2625,8 +2625,10 @@ static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindif
ck_runlock(&instance_lock); ck_runlock(&instance_lock);
/* They may just have not connected yet */ /* They may just have not connected yet */
if (!instance) if (!instance) {
return LOGINFO("Failed to find user %s in set_worker_mindiff", username); LOGINFO("Failed to find user %s in set_worker_mindiff", username);
return;
}
/* Then find the matching worker instance */ /* Then find the matching worker instance */
ck_rlock(&instance_lock); ck_rlock(&instance_lock);
@ -2639,11 +2641,15 @@ static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindif
ck_runlock(&instance_lock); ck_runlock(&instance_lock);
/* They may just not be connected at the moment */ /* They may just not be connected at the moment */
if (!worker) if (!worker) {
return LOGINFO("Failed to find worker %s in set_worker_mindiff", workername); LOGINFO("Failed to find worker %s in set_worker_mindiff", workername);
return;
}
if (mindiff < 1) if (mindiff < 1) {
return LOGINFO("Worker %s requested invalid diff %ld", worker->workername, mindiff); LOGINFO("Worker %s requested invalid diff %d", worker->workername, mindiff);
return;
}
if (mindiff < ckp->mindiff) if (mindiff < ckp->mindiff)
mindiff = ckp->mindiff; mindiff = ckp->mindiff;
if (mindiff == worker->mindiff) if (mindiff == worker->mindiff)
@ -2676,12 +2682,16 @@ static void suggest_diff(stratum_instance_t *client, const char *method, json_t
json_t *arr_val = json_array_get(params_val, 0); json_t *arr_val = json_array_get(params_val, 0);
int64_t sdiff; int64_t sdiff;
if (unlikely(!client->authorised)) if (unlikely(!client->authorised)) {
return LOGWARNING("Attempted to suggest diff on unauthorised client %ld", client->id); LOGWARNING("Attempted to suggest diff on unauthorised client %ld", client->id);
return;
}
if (arr_val && json_is_integer(arr_val)) if (arr_val && json_is_integer(arr_val))
sdiff = json_integer_value(arr_val); sdiff = json_integer_value(arr_val);
else if (sscanf(method, "mining.suggest_difficulty(%ld", &sdiff) != 1) else if (sscanf(method, "mining.suggest_difficulty(%ld", &sdiff) != 1) {
return LOGINFO("Failed to parse suggest_difficulty for client %ld", client->id); LOGINFO("Failed to parse suggest_difficulty for client %"PRId64, client->id);
return;
}
if (sdiff == client->suggest_diff) if (sdiff == client->suggest_diff)
return; return;
client->suggest_diff = sdiff; client->suggest_diff = sdiff;
@ -2711,7 +2721,7 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method
} }
if (unlikely(client->reject == 2)) { if (unlikely(client->reject == 2)) {
LOGINFO("Dropping client %d tagged for lazy invalidation", client_id); LOGINFO("Dropping client %"PRId64" tagged for lazy invalidation", client_id);
snprintf(buf, 255, "dropclient=%ld", client->id); snprintf(buf, 255, "dropclient=%ld", client->id);
send_proc(client->ckp->connector, buf); send_proc(client->ckp->connector, buf);
return; return;

Loading…
Cancel
Save