diff --git a/src/ckdb.c b/src/ckdb.c index 5b620b24..afe545cc 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -494,12 +494,12 @@ void logmsg(int loglevel, const char *fmt, ...) now_t = time(NULL); localtime_r(&now_t, &tm); - minoff = timezone / 60; + minoff = tm.tm_gmtoff / 60; if (minoff < 0) { - tzch = '+'; + tzch = '-'; minoff *= -1; } else - tzch = '-'; + tzch = '+'; hroff = minoff / 60; if (minoff % 60) { snprintf(tzinfo, sizeof(tzinfo), @@ -1606,7 +1606,7 @@ static void summarise_poolstats() // TODO: consider limiting how much/how long this processes each time static void summarise_userstats() { - K_TREE_CTX ctx[1], ctx2[1]; + K_TREE_CTX ctx[1]; K_ITEM *first, *last, *new, *next, *tmp; USERSTATS *userstats, *us_first, *us_last, *us_next; double statrange, factor; @@ -1675,9 +1675,9 @@ static void summarise_userstats() DATA_USERSTATS(userstats, new); memcpy(userstats, us_first, sizeof(USERSTATS)); - userstats_root = remove_from_ktree(userstats_root, first, cmp_userstats, ctx2); + userstats_root = remove_from_ktree(userstats_root, first, cmp_userstats); userstats_statsdate_root = remove_from_ktree(userstats_statsdate_root, first, - cmp_userstats_statsdate, ctx2); + cmp_userstats_statsdate); k_unlink_item(userstats_store, first); k_add_head(userstats_summ, first); @@ -1702,9 +1702,9 @@ static void summarise_userstats() userstats->elapsed = us_next->elapsed; userstats->summarycount += us_next->summarycount; - userstats_root = remove_from_ktree(userstats_root, next, cmp_userstats, ctx2); + userstats_root = remove_from_ktree(userstats_root, next, cmp_userstats); userstats_statsdate_root = remove_from_ktree(userstats_statsdate_root, next, - cmp_userstats_statsdate, ctx2); + cmp_userstats_statsdate); k_unlink_item(userstats_store, next); k_add_head(userstats_summ, next); } diff --git a/src/ckdb.h b/src/ckdb.h index da341b46..72aa2e6b 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9.2" -#define CKDB_VERSION DB_VERSION"-0.601" +#define CKDB_VERSION DB_VERSION"-0.602" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_data.c b/src/ckdb_data.c index 32976426..9985c827 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -1239,7 +1239,7 @@ bool workinfo_age(PGconn *conn, int64_t workinfoid, char *poolinstance, int64_t *s_count, int64_t *s_diff) { K_ITEM *wi_item, ss_look, *ss_item, s_look, *s_item, *tmp_item; - K_TREE_CTX ss_ctx[1], s_ctx[1], tmp_ctx[1]; + K_TREE_CTX ss_ctx[1], s_ctx[1]; char cd_buf[DATE_BUFSIZ]; int64_t ss_tot, ss_already, ss_failed, shares_tot, shares_dumped; SHARESUMMARY looksharesummary, *sharesummary; @@ -1353,7 +1353,7 @@ bool workinfo_age(PGconn *conn, int64_t workinfoid, char *poolinstance, shares_tot++; tmp_item = next_in_ktree(s_ctx); - shares_root = remove_from_ktree(shares_root, s_item, cmp_shares, tmp_ctx); + shares_root = remove_from_ktree(shares_root, s_item, cmp_shares); k_unlink_item(shares_store, s_item); if (reloading && skipupdate) shares_dumped++; diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index df791e24..5c645083 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -310,7 +310,6 @@ bool users_pass_email(PGconn *conn, K_ITEM *u_item, char *oldhash, { ExecStatusType rescode; bool conned = false; - K_TREE_CTX ctx[1]; PGresult *res; K_ITEM *item; USERS *row, *users; @@ -428,8 +427,8 @@ unparam: if (!ok) k_add_head(users_free, item); else { - users_root = remove_from_ktree(users_root, u_item, cmp_users, ctx); - userid_root = remove_from_ktree(userid_root, u_item, cmp_userid, ctx); + users_root = remove_from_ktree(users_root, u_item, cmp_users); + userid_root = remove_from_ktree(userid_root, u_item, cmp_userid); copy_tv(&(users->expirydate), cd); users_root = add_to_ktree(users_root, u_item, cmp_users); userid_root = add_to_ktree(userid_root, u_item, cmp_userid); @@ -684,7 +683,6 @@ bool useratts_item_add(PGconn *conn, K_ITEM *ua_item, tv_t *cd, bool begun) { ExecStatusType rescode; bool conned = false; - K_TREE_CTX ctx[1]; PGresult *res; K_ITEM *old_item; USERATTS *old_useratts, *useratts; @@ -789,7 +787,7 @@ unparam: if (ok) { // Update it if (old_item) { - useratts_root = remove_from_ktree(useratts_root, old_item, cmp_useratts, ctx); + useratts_root = remove_from_ktree(useratts_root, old_item, cmp_useratts); copy_tv(&(old_useratts->expirydate), cd); useratts_root = add_to_ktree(useratts_root, old_item, cmp_useratts); } @@ -879,7 +877,6 @@ bool useratts_item_expire(PGconn *conn, K_ITEM *ua_item, tv_t *cd) { ExecStatusType rescode; bool conned = false; - K_TREE_CTX ctx[1]; PGresult *res; K_ITEM *item; USERATTS *useratts; @@ -934,7 +931,7 @@ unparam: K_WLOCK(useratts_free); if (ok && item) { - useratts_root = remove_from_ktree(useratts_root, item, cmp_useratts, ctx); + useratts_root = remove_from_ktree(useratts_root, item, cmp_useratts); copy_tv(&(useratts->expirydate), cd); useratts_root = add_to_ktree(useratts_root, item, cmp_useratts); } @@ -1434,7 +1431,7 @@ K_ITEM *paymentaddresses_set(PGconn *conn, int64_t userid, char *payaddress, ExecStatusType rescode; bool conned = false; PGresult *res; - K_TREE_CTX ctx[1], ctx2[1]; + K_TREE_CTX ctx[1]; K_ITEM *item, *old, *this, look; PAYMENTADDRESSES *row, pa, *thispa; char *upd, *ins; @@ -1550,7 +1547,7 @@ unitem: * this test will avoid reprocessing */ if (CURRENT(&(thispa->expirydate))) { paymentaddresses_root = remove_from_ktree(paymentaddresses_root, this, - cmp_paymentaddresses, ctx2); + cmp_paymentaddresses); copy_tv(&(thispa->expirydate), cd); paymentaddresses_root = add_to_ktree(paymentaddresses_root, this, cmp_paymentaddresses); @@ -1938,7 +1935,7 @@ nostart: // Discard it if (old_item) { optioncontrol_root = remove_from_ktree(optioncontrol_root, old_item, - cmp_optioncontrol, ctx); + cmp_optioncontrol); k_add_head(optioncontrol_free, old_item); } optioncontrol_root = add_to_ktree(optioncontrol_root, oc_item, cmp_optioncontrol); @@ -3136,7 +3133,6 @@ bool blocks_stats(PGconn *conn, int32_t height, char *blockhash, ExecStatusType rescode; bool conned = false; PGresult *res = NULL; - K_TREE_CTX ctx[1]; K_ITEM *b_item, *old_b_item; BLOCKS *row, *oldblocks; char hash_dsp[16+1]; @@ -3261,7 +3257,7 @@ unparam: k_add_head(blocks_free, b_item); else { if (update_old) { - blocks_root = remove_from_ktree(blocks_root, old_b_item, cmp_blocks, ctx); + blocks_root = remove_from_ktree(blocks_root, old_b_item, cmp_blocks); copy_tv(&(oldblocks->expirydate), cd); blocks_root = add_to_ktree(blocks_root, old_b_item, cmp_blocks); } @@ -3283,7 +3279,6 @@ bool blocks_add(PGconn *conn, char *height, char *blockhash, ExecStatusType rescode; bool conned = false; PGresult *res = NULL; - K_TREE_CTX ctx[1]; K_ITEM *b_item, *u_item, *old_b_item; char cd_buf[DATE_BUFSIZ]; char hash_dsp[16+1]; @@ -3564,7 +3559,7 @@ flail: k_add_head(blocks_free, b_item); else { if (update_old) { - blocks_root = remove_from_ktree(blocks_root, old_b_item, cmp_blocks, ctx); + blocks_root = remove_from_ktree(blocks_root, old_b_item, cmp_blocks); copy_tv(&(oldblocks->expirydate), cd); blocks_root = add_to_ktree(blocks_root, old_b_item, cmp_blocks); } diff --git a/src/ktree.c b/src/ktree.c index 57525c4e..c94d12fb 100644 --- a/src/ktree.c +++ b/src/ktree.c @@ -947,6 +947,18 @@ DBG("@remove after balance=%f :(\n", cmp); return root; } +K_TREE *_remove_from_ktree_free(K_TREE *root, K_ITEM *data, cmp_t (*cmp_funct)(K_ITEM *, K_ITEM *), KTREE_FFL_ARGS) +{ + K_TREE_CTX ctx[1]; + + root = _remove_from_ktree(root, data, cmp_funct, ctx, KTREE_FFL_PASS); + + if (*ctx) + free(*ctx); + + return root; +} + static void free_ktree_sub(K_TREE *ktree, void (*free_funct)(void *)) { if (ktree != NULL && ktree != nil) diff --git a/src/ktree.h b/src/ktree.h index dfacb4c1..0721610a 100644 --- a/src/ktree.h +++ b/src/ktree.h @@ -70,7 +70,8 @@ extern K_ITEM *_find_after_in_ktree(K_TREE *ktree, K_ITEM *data, cmp_t (*cmp_fun extern K_ITEM *_find_before_in_ktree(K_TREE *ktree, K_ITEM *data, cmp_t (*cmp_funct)(K_ITEM *, K_ITEM *), K_TREE_CTX *ctx, KTREE_FFL_ARGS); #define find_before_in_ktree(_ktree, _data, _cmp_funct, _ctx) _find_before_in_ktree(_ktree, _data, _cmp_funct, _ctx, KLIST_FFL_HERE) extern K_TREE *_remove_from_ktree(K_TREE *root, K_ITEM *data, cmp_t (*cmp_funct)(K_ITEM *, K_ITEM *), K_TREE_CTX *ctx, KTREE_FFL_ARGS); -#define remove_from_ktree(_root, _data, _cmp_funct, _ctx) _remove_from_ktree(_root, _data, _cmp_funct, _ctx, KLIST_FFL_HERE) +extern K_TREE *_remove_from_ktree_free(K_TREE *root, K_ITEM *data, cmp_t (*cmp_funct)(K_ITEM *, K_ITEM *), KTREE_FFL_ARGS); +#define remove_from_ktree(_root, _data, _cmp_funct) _remove_from_ktree_free(_root, _data, _cmp_funct, KLIST_FFL_HERE) extern K_TREE *_free_ktree(K_TREE *root, void (*free_funct)(void *), KTREE_FFL_ARGS); #define free_ktree(_root, _free_funct) _free_ktree(_root, _free_funct, KLIST_FFL_HERE)