Add a forcelog variant of applog which invalidates any console lock to force output.
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
diff --git a/cgminer.c b/cgminer.c
index fb739f2..26482f1 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -423,7 +423,7 @@ static void applog_and_exit(const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(exit_buf, sizeof(exit_buf), fmt, ap);
va_end(ap);
- _applog(LOG_ERR, exit_buf);
+ _applog(LOG_ERR, exit_buf, true);
exit(1);
}
diff --git a/logging.c b/logging.c
index d00600f..52eb9ef 100644
--- a/logging.c
+++ b/logging.c
@@ -21,11 +21,17 @@ bool opt_log_output = false;
/* per default priorities higher than LOG_NOTICE are logged */
int opt_log_level = LOG_NOTICE;
-static void my_log_curses(int prio, const char *datetime, const char *str)
+static void my_log_curses(int prio, const char *datetime, const char *str, bool force)
{
if (opt_quiet && prio != LOG_ERR)
return;
+ /* Mutex could be locked by dead thread on shutdown so forcelog will
+ * invalidate any console lock status. */
+ if (force) {
+ mutex_trylock(&console_lock);
+ mutex_unlock(&console_lock);
+ }
#ifdef HAVE_CURSES
extern bool use_curses;
if (use_curses && log_curses_only(prio, datetime, str))
@@ -44,7 +50,7 @@ static void my_log_curses(int prio, const char *datetime, const char *str)
/*
* log function
*/
-void _applog(int prio, const char *str)
+void _applog(int prio, const char *str, bool force)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
@@ -77,6 +83,6 @@ void _applog(int prio, const char *str)
fflush(stderr);
}
- my_log_curses(prio, datetime, str);
+ my_log_curses(prio, datetime, str, force);
}
}
diff --git a/logging.h b/logging.h
index 2956452..4d8a250 100644
--- a/logging.h
+++ b/logging.h
@@ -28,7 +28,7 @@ extern int opt_log_level;
#define LOGBUFSIZ 256
-extern void _applog(int prio, const char *str);
+extern void _applog(int prio, const char *str, bool force);
#define IN_FMT_FFL " in %s %s():%d"
@@ -37,7 +37,7 @@ extern void _applog(int prio, const char *str);
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
- _applog(prio, tmp42); \
+ _applog(prio, tmp42, false); \
} \
} \
} while (0)
@@ -47,7 +47,17 @@ extern void _applog(int prio, const char *str);
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
char tmp42[_SIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
- _applog(prio, tmp42); \
+ _applog(prio, tmp42, false); \
+ } \
+ } \
+} while (0)
+
+#define forcelog(prio, fmt, ...) do { \
+ if (opt_debug || prio != LOG_DEBUG) { \
+ if (use_syslog || opt_log_output || prio <= opt_log_level) { \
+ char tmp42[LOGBUFSIZ]; \
+ snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
+ _applog(prio, tmp42, true); \
} \
} \
} while (0)
@@ -56,7 +66,7 @@ extern void _applog(int prio, const char *str);
if (fmt) { \
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
- _applog(LOG_ERR, tmp42); \
+ _applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
@@ -66,7 +76,7 @@ extern void _applog(int prio, const char *str);
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, __FILE__, __func__, __LINE__); \
- _applog(LOG_ERR, tmp42); \
+ _applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
@@ -76,7 +86,7 @@ extern void _applog(int prio, const char *str);
char tmp42[LOGBUFSIZ]; \
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
##__VA_ARGS__, _file, _func, _line); \
- _applog(LOG_ERR, tmp42); \
+ _applog(LOG_ERR, tmp42, true); \
} \
_quit(status); \
} while (0)
diff --git a/usbutils.c b/usbutils.c
index 8f083d6..0a9c78f 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -933,7 +933,7 @@ void usb_all(int level)
for (i = 0; i < count; i++)
usb_full(&j, list[i], &buf, &off, &len, level);
- _applog(LOG_WARNING, buf);
+ _applog(LOG_WARNING, buf, false);
free(buf);