Convert remaining [f]print to applog(). Also, remove a few superfluous printouts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
diff --git a/cpu-miner.c b/cpu-miner.c
index 554a297..7ce1470 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -203,12 +203,12 @@ static bool jobj_binary(const json_t *obj, const char *key,
tmp = json_object_get(obj, key);
if (!tmp) {
- fprintf(stderr, "JSON key '%s' not found\n", key);
+ applog(LOG_ERR, "JSON key '%s' not found", key);
return false;
}
hexstr = json_string_value(tmp);
if (!hexstr) {
- fprintf(stderr, "JSON key '%s' is not a string\n", key);
+ applog(LOG_ERR, "JSON key '%s' is not a string", key);
return false;
}
if (!hex2bin(buf, hexstr, buflen))
@@ -221,22 +221,22 @@ static bool work_decode(const json_t *val, struct work *work)
{
if (!jobj_binary(val, "midstate",
work->midstate, sizeof(work->midstate))) {
- fprintf(stderr, "JSON inval midstate\n");
+ applog(LOG_ERR, "JSON inval midstate");
goto err_out;
}
if (!jobj_binary(val, "data", work->data, sizeof(work->data))) {
- fprintf(stderr, "JSON inval data\n");
+ applog(LOG_ERR, "JSON inval data");
goto err_out;
}
if (!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1))) {
- fprintf(stderr, "JSON inval hash1\n");
+ applog(LOG_ERR, "JSON inval hash1");
goto err_out;
}
if (!jobj_binary(val, "target", work->target, sizeof(work->target))) {
- fprintf(stderr, "JSON inval target\n");
+ applog(LOG_ERR, "JSON inval target");
goto err_out;
}
@@ -258,7 +258,7 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
/* build hex string */
hexstr = bin2hex(work->data, sizeof(work->data));
if (!hexstr) {
- fprintf(stderr, "submit_upstream_work OOM\n");
+ applog(LOG_ERR, "submit_upstream_work OOM");
goto out;
}
@@ -268,12 +268,12 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
hexstr);
if (opt_debug)
- fprintf(stderr, "DBG: sending RPC call:\n%s", s);
+ applog(LOG_DEBUG, "DBG: sending RPC call: %s", s);
/* issue JSON-RPC request */
val = json_rpc_call(curl, rpc_url, userpass, s, false, false);
if (!val) {
- fprintf(stderr, "submit_upstream_work json_rpc_call failed\n");
+ applog(LOG_ERR, "submit_upstream_work json_rpc_call failed");
goto out;
}
@@ -339,16 +339,14 @@ static bool workio_get_work(struct workio_cmd *wc, CURL *curl)
/* obtain new work from bitcoin via JSON-RPC */
while (!get_upstream_work(curl, ret_work)) {
- fprintf(stderr, "json_rpc_call failed, ");
-
if ((opt_retries >= 0) && (++failures > opt_retries)) {
- fprintf(stderr, "terminating workio thread\n");
+ applog(LOG_ERR, "json_rpc_call failed, terminating workio thread");
free(ret_work);
return false;
}
/* pause, then restart work-request loop */
- fprintf(stderr, "retry after %d seconds\n",
+ applog(LOG_ERR, "json_rpc_call failed, retry after %d seconds",
opt_fail_pause);
sleep(opt_fail_pause);
}
@@ -367,12 +365,12 @@ static bool workio_submit_work(struct workio_cmd *wc, CURL *curl)
/* submit solution to bitcoin via JSON-RPC */
while (!submit_upstream_work(curl, wc->u.work)) {
if ((opt_retries >= 0) && (++failures > opt_retries)) {
- fprintf(stderr, "...terminating workio thread\n");
+ applog(LOG_ERR, "...terminating workio thread");
return false;
}
/* pause, then restart work-request loop */
- fprintf(stderr, "...retry after %d seconds\n",
+ applog(LOG_ERR, "...retry after %d seconds",
opt_fail_pause);
sleep(opt_fail_pause);
}
@@ -388,7 +386,7 @@ static void *workio_thread(void *userdata)
curl = curl_easy_init();
if (!curl) {
- fprintf(stderr, "CURL initialization failed\n");
+ applog(LOG_ERR, "CURL initialization failed");
return NULL;
}
@@ -513,8 +511,8 @@ static void *miner_thread(void *userdata)
/* obtain new work from internal workio thread */
if (!get_work(mythr, &work)) {
- fprintf(stderr, "work retrieval failed, exiting "
- "mining thread %d\n", mythr->id);
+ applog(LOG_ERR, "work retrieval failed, exiting "
+ "mining thread %d", mythr->id);
goto out;
}
@@ -639,7 +637,7 @@ static void *longpoll_thread(void *userdata)
curl = curl_easy_init();
if (!curl) {
- fprintf(stderr, "CURL initialization failed\n");
+ applog(LOG_ERR, "CURL initialization failed");
goto out;
}
@@ -657,10 +655,10 @@ static void *longpoll_thread(void *userdata)
} else {
if (failures++ < 10) {
sleep(30);
- fprintf(stderr,
+ applog(LOG_ERR,
"longpoll failed, sleeping for 30s\n");
} else {
- fprintf(stderr,
+ applog(LOG_ERR,
"longpoll failed, ending thread\n");
goto out;
}
@@ -715,7 +713,7 @@ static void parse_arg (int key, char *arg)
json_decref(opt_config);
opt_config = json_load_file(arg, &err);
if (!json_is_object(opt_config)) {
- fprintf(stderr, "JSON decode of %s failed\n", arg);
+ applog(LOG_ERR, "JSON decode of %s failed", arg);
show_usage();
}
break;
@@ -810,7 +808,7 @@ static void parse_config(void)
} else if (!options[i].has_arg && json_is_true(val))
parse_arg(options[i].val, "");
else
- fprintf(stderr, "JSON option %s invalid\n",
+ applog(LOG_ERR, "JSON option %s invalid",
options[i].name);
}
}
@@ -870,7 +868,7 @@ int main (int argc, char *argv[])
/* start work I/O thread */
if (pthread_create(&thr->pth, NULL, workio_thread, thr)) {
- fprintf(stderr, "workio thread create failed\n");
+ applog(LOG_ERR, "workio thread create failed");
return 1;
}
@@ -885,7 +883,7 @@ int main (int argc, char *argv[])
/* start longpoll thread */
if (pthread_create(&thr->pth, NULL, longpoll_thread, thr)) {
- fprintf(stderr, "longpoll thread create failed\n");
+ applog(LOG_ERR, "longpoll thread create failed");
return 1;
}
} else
@@ -901,7 +899,7 @@ int main (int argc, char *argv[])
return 1;
if (pthread_create(&thr->pth, NULL, miner_thread, thr)) {
- fprintf(stderr, "thread %d create failed\n", i);
+ applog(LOG_ERR, "thread %d create failed", i);
return 1;
}
diff --git a/miner.h b/miner.h
index 0d8e682..edc7a63 100644
--- a/miner.h
+++ b/miner.h
@@ -59,7 +59,10 @@ void *alloca (size_t);
#include <syslog.h>
#else
enum {
+ LOG_ERR,
+ LOG_WARNING,
LOG_INFO,
+ LOG_DEBUG,
};
#endif
diff --git a/sha256_cryptopp.c b/sha256_cryptopp.c
index ed83dfc..c3eb29f 100644
--- a/sha256_cryptopp.c
+++ b/sha256_cryptopp.c
@@ -608,8 +608,6 @@ bool scanhash_asm32(int thr_id, const unsigned char *midstate,
}
if ((n >= max_nonce) || work_restart[thr_id].restart) {
- if (opt_debug)
- fprintf(stderr, "DBG: end of nonce range\n");
*hashes_done = stat_ctr;
return false;
}
diff --git a/util.c b/util.c
index 62cf422..58533f2 100644
--- a/util.c
+++ b/util.c
@@ -150,9 +150,6 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
char *rem, *val = NULL, *key = NULL;
void *tmp;
- if (opt_protocol)
- printf("In resp_hdr_cb\n");
-
val = calloc(1, ptrlen);
key = calloc(1, ptrlen);
if (!key || !val)
@@ -183,7 +180,7 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
goto out;
if (opt_protocol)
- printf("HTTP hdr(%s): %s\n", key, val);
+ applog(LOG_DEBUG, "HTTP hdr(%s): %s", key, val);
if (!strcasecmp("X-Long-Polling", key)) {
hi->lp_path = val; /* steal memory reference */
@@ -241,7 +238,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_POST, 1);
if (opt_protocol)
- printf("JSON protocol request:\n%s\n", rpc_req);
+ applog(LOG_DEBUG, "JSON protocol request:\n%s\n", rpc_req);
upload_data.buf = rpc_req;
upload_data.len = strlen(rpc_req);
@@ -257,7 +254,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
rc = curl_easy_perform(curl);
if (rc) {
- fprintf(stderr, "HTTP request failed: %s\n", curl_err_str);
+ applog(LOG_ERR, "HTTP request failed: %s", curl_err_str);
goto err_out;
}
@@ -272,13 +269,13 @@ json_t *json_rpc_call(CURL *curl, const char *url,
val = json_loads(all_data.buf, &err);
if (!val) {
- fprintf(stderr, "JSON decode failed(%d): %s\n", err.line, err.text);
+ applog(LOG_ERR, "JSON decode failed(%d): %s", err.line, err.text);
goto err_out;
}
if (opt_protocol) {
char *s = json_dumps(val, JSON_INDENT(3));
- printf("JSON protocol response:\n%s\n", s);
+ applog(LOG_DEBUG, "JSON protocol response:\n%s", s);
free(s);
}
@@ -297,7 +294,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
else
s = strdup("(unknown reason)");
- fprintf(stderr, "JSON-RPC call failed: %s\n", s);
+ applog(LOG_ERR, "JSON-RPC call failed: %s", s);
free(s);
@@ -336,7 +333,7 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
unsigned int v;
if (!hexstr[1]) {
- fprintf(stderr, "hex2bin str truncated\n");
+ applog(LOG_ERR, "hex2bin str truncated");
return false;
}
@@ -345,8 +342,7 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
hex_byte[2] = 0;
if (sscanf(hex_byte, "%x", &v) != 1) {
- fprintf(stderr, "hex2bin sscanf '%s' failed\n",
- hex_byte);
+ applog(LOG_ERR, "hex2bin sscanf '%s' failed", hex_byte);
return false;
}
@@ -421,7 +417,7 @@ bool fulltest(const unsigned char *hash, const unsigned char *target)
hash_str = bin2hex(hash_swap, 32);
target_str = bin2hex(target_swap, 32);
- fprintf(stderr, " Proof: %s\nTarget: %s\nTrgVal? %s\n",
+ applog(LOG_DEBUG, " Proof: %s\nTarget: %s\nTrgVal? %s",
hash_str,
target_str,
rc ? "YES (hash < target)" :