Skip to content

Commit 8e9f32a

Browse files
committed
Add a forcelog variant of applog which invalidates any console lock to force output.
1 parent 3956382 commit 8e9f32a

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

cgminer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ static void applog_and_exit(const char *fmt, ...)
423423
va_start(ap, fmt);
424424
vsnprintf(exit_buf, sizeof(exit_buf), fmt, ap);
425425
va_end(ap);
426-
_applog(LOG_ERR, exit_buf);
426+
_applog(LOG_ERR, exit_buf, true);
427427
exit(1);
428428
}
429429

logging.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ bool opt_log_output = false;
2121
/* per default priorities higher than LOG_NOTICE are logged */
2222
int opt_log_level = LOG_NOTICE;
2323

24-
static void my_log_curses(int prio, const char *datetime, const char *str)
24+
static void my_log_curses(int prio, const char *datetime, const char *str, bool force)
2525
{
2626
if (opt_quiet && prio != LOG_ERR)
2727
return;
2828

29+
/* Mutex could be locked by dead thread on shutdown so forcelog will
30+
* invalidate any console lock status. */
31+
if (force) {
32+
mutex_trylock(&console_lock);
33+
mutex_unlock(&console_lock);
34+
}
2935
#ifdef HAVE_CURSES
3036
extern bool use_curses;
3137
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)
4450
/*
4551
* log function
4652
*/
47-
void _applog(int prio, const char *str)
53+
void _applog(int prio, const char *str, bool force)
4854
{
4955
#ifdef HAVE_SYSLOG_H
5056
if (use_syslog) {
@@ -77,6 +83,6 @@ void _applog(int prio, const char *str)
7783
fflush(stderr);
7884
}
7985

80-
my_log_curses(prio, datetime, str);
86+
my_log_curses(prio, datetime, str, force);
8187
}
8288
}

logging.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern int opt_log_level;
2828

2929
#define LOGBUFSIZ 256
3030

31-
extern void _applog(int prio, const char *str);
31+
extern void _applog(int prio, const char *str, bool force);
3232

3333
#define IN_FMT_FFL " in %s %s():%d"
3434

@@ -37,7 +37,7 @@ extern void _applog(int prio, const char *str);
3737
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
3838
char tmp42[LOGBUFSIZ]; \
3939
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
40-
_applog(prio, tmp42); \
40+
_applog(prio, tmp42, false); \
4141
} \
4242
} \
4343
} while (0)
@@ -47,7 +47,17 @@ extern void _applog(int prio, const char *str);
4747
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
4848
char tmp42[_SIZ]; \
4949
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
50-
_applog(prio, tmp42); \
50+
_applog(prio, tmp42, false); \
51+
} \
52+
} \
53+
} while (0)
54+
55+
#define forcelog(prio, fmt, ...) do { \
56+
if (opt_debug || prio != LOG_DEBUG) { \
57+
if (use_syslog || opt_log_output || prio <= opt_log_level) { \
58+
char tmp42[LOGBUFSIZ]; \
59+
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
60+
_applog(prio, tmp42, true); \
5161
} \
5262
} \
5363
} while (0)
@@ -56,7 +66,7 @@ extern void _applog(int prio, const char *str);
5666
if (fmt) { \
5767
char tmp42[LOGBUFSIZ]; \
5868
snprintf(tmp42, sizeof(tmp42), fmt, ##__VA_ARGS__); \
59-
_applog(LOG_ERR, tmp42); \
69+
_applog(LOG_ERR, tmp42, true); \
6070
} \
6171
_quit(status); \
6272
} while (0)
@@ -66,7 +76,7 @@ extern void _applog(int prio, const char *str);
6676
char tmp42[LOGBUFSIZ]; \
6777
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
6878
##__VA_ARGS__, __FILE__, __func__, __LINE__); \
69-
_applog(LOG_ERR, tmp42); \
79+
_applog(LOG_ERR, tmp42, true); \
7080
} \
7181
_quit(status); \
7282
} while (0)
@@ -76,7 +86,7 @@ extern void _applog(int prio, const char *str);
7686
char tmp42[LOGBUFSIZ]; \
7787
snprintf(tmp42, sizeof(tmp42), fmt IN_FMT_FFL, \
7888
##__VA_ARGS__, _file, _func, _line); \
79-
_applog(LOG_ERR, tmp42); \
89+
_applog(LOG_ERR, tmp42, true); \
8090
} \
8191
_quit(status); \
8292
} while (0)

usbutils.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ void usb_all(int level)
933933
for (i = 0; i < count; i++)
934934
usb_full(&j, list[i], &buf, &off, &len, level);
935935

936-
_applog(LOG_WARNING, buf);
936+
_applog(LOG_WARNING, buf, false);
937937

938938
free(buf);
939939

0 commit comments

Comments
 (0)