Ensure we connect at least once successfully before continuing to try to connect.
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
diff --git a/main.c b/main.c
index 81dadb1..f5ba3c1 100644
--- a/main.c
+++ b/main.c
@@ -756,12 +756,25 @@ static void workio_cmd_free(struct workio_cmd *wc)
free(wc);
}
-static void kill_work(void)
+static void disable_curses(void)
+{
+ if (curses_active) {
+ curses_active = false;
+ delwin(logwin);
+ delwin(statuswin);
+ delwin(mainwin);
+ endwin();
+ refresh();
+ }
+}
+
+void kill_work(void)
{
struct workio_cmd *wc;
struct thr_info *thr;
unsigned int i;
+ disable_curses();
applog(LOG_INFO, "Received kill message");
/* Kill the watchdog thread */
@@ -796,19 +809,6 @@ static void kill_work(void)
applog(LOG_ERR, "Failed to tq_push work in kill_work");
exit (1);
}
-
-}
-
-static void disable_curses(void)
-{
- if (curses_active) {
- curses_active = false;
- delwin(logwin);
- delwin(statuswin);
- delwin(mainwin);
- endwin();
- refresh();
- }
}
static void sighandler(int sig)
@@ -2004,12 +2004,14 @@ static void print_summary(void)
printf("\nSummary of runtime statistics:\n\n");
printf("Started at %s\n", datestamp);
printf("Runtime: %d hrs : %d mins : %d secs\n", hours, mins, secs);
- printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs);
+ if (total_secs)
+ printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs);
printf("Queued work requests: %d\n", getwork_requested);
printf("Share submissions: %d\n", accepted + rejected);
printf("Accepted shares: %d\n", accepted);
printf("Rejected shares: %d\n", rejected);
- printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected));
+ if (accepted || rejected)
+ printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected));
printf("Hardware errors: %d\n", hw_errors);
printf("Efficiency (accepted / queued): %.0f%%\n", efficiency);
printf("Utility (accepted shares / min): %.2f/min\n\n", utility);
@@ -2332,7 +2334,7 @@ int main (int argc, char *argv[])
gettimeofday(&total_tv_end, NULL);
curl_global_cleanup();
disable_curses();
- if (!opt_quiet)
+ if (!opt_quiet && successful_connect)
print_summary();
if (gpu_threads)
diff --git a/miner.h b/miner.h
index 6ff9e1c..53a537e 100644
--- a/miner.h
+++ b/miner.h
@@ -269,6 +269,7 @@ struct work {
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
+extern void kill_work(void);
extern void log_curses(const char *f, va_list ap);
extern void vapplog(int prio, const char *fmt, va_list ap);
extern void applog(int prio, const char *fmt, ...);
@@ -278,5 +279,6 @@ extern bool tq_push(struct thread_q *tq, void *data);
extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
extern void tq_freeze(struct thread_q *tq);
extern void tq_thaw(struct thread_q *tq);
+extern bool successful_connect;
#endif /* __MINER_H__ */
diff --git a/util.c b/util.c
index 0a72d63..ad4cd40 100644
--- a/util.c
+++ b/util.c
@@ -32,6 +32,8 @@
#define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
#endif
+bool successful_connect = false;
+
struct data_buffer {
void *buf;
size_t len;
@@ -340,6 +342,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out;
}
+ successful_connect = true;
comms_error = false;
databuf_free(&all_data);
curl_slist_free_all(headers);
@@ -350,6 +353,10 @@ err_out:
databuf_free(&all_data);
curl_slist_free_all(headers);
curl_easy_reset(curl);
+ if (!successful_connect) {
+ kill_work();
+ applog(LOG_ERR, "Failed to connect - wrong URL or login details?");
+ }
return NULL;
}