Forcibly kill everything silently with an exit code of 1 should we fail to cleanly shut down and use a completion timeout for the __kill_work in app_restart.
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
diff --git a/cgminer.c b/cgminer.c
index 0df05b4..ece6778 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3577,7 +3577,7 @@ void app_restart(void)
{
applog(LOG_WARNING, "Attempting to restart %s", packagename);
- __kill_work();
+ cg_completion_timeout(&__kill_work, NULL, 5000);
clean_up(true);
#if defined(unix) || defined(__APPLE__)
@@ -7953,8 +7953,24 @@ static void clean_up(bool restarting)
curl_global_cleanup();
}
+/* Should all else fail and we're unable to clean up threads due to locking
+ * issues etc, just silently exit. */
+static void *killall_thread(void __maybe_unused *arg)
+{
+ pthread_detach(pthread_self());
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+ sleep(5);
+ exit(1);
+ return NULL;
+}
+
void __quit(int status, bool clean)
{
+ pthread_t killall_t;
+
+ if (unlikely(pthread_create(&killall_t, NULL, killall_thread, NULL)))
+ exit(1);
+
if (clean)
clean_up(false);
#ifdef HAVE_CURSES
@@ -7968,6 +7984,7 @@ void __quit(int status, bool clean)
forkpid = 0;
}
#endif
+ pthread_cancel(killall_t);
exit(status);
}