1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-31 00:44:19 +00:00

Write to both stderr and console within same console lock "session"

From 7dd230cd8f
This commit is contained in:
Jan Berdajs 2014-07-06 01:30:50 +02:00
parent 2d66c44b42
commit 363f52df47
3 changed files with 23 additions and 23 deletions

View File

@ -24,28 +24,18 @@ int opt_log_show_date = false;
/* per default priorities higher than LOG_NOTICE are logged */ /* per default priorities higher than LOG_NOTICE are logged */
int opt_log_level = LOG_NOTICE; int opt_log_level = LOG_NOTICE;
static void my_log_curses(int prio, const char *datetime, const char *str, bool force) static void _my_log_curses(int prio, const char *datetime, const char *str)
{ {
if (opt_quiet && prio != LOG_ERR) if (opt_quiet && prio != LOG_ERR)
return; 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 #ifdef HAVE_CURSES
extern bool use_curses; extern bool use_curses;
if (use_curses && log_curses_only(prio, datetime, str)) if (use_curses && _log_curses_only(prio, datetime, str))
; ;
else else
#endif #endif
{
mutex_lock(&console_lock);
printf("%s%s%s", datetime, str, " \n"); printf("%s%s%s", datetime, str, " \n");
mutex_unlock(&console_lock);
}
} }
void applog(int prio, const char* fmt, ...) void applog(int prio, const char* fmt, ...)
@ -131,14 +121,25 @@ void _applog(int prio, const char *str, bool force)
tm->tm_sec); tm->tm_sec);
} }
/* Only output to stderr if it's not going to the screen as well */ if (write_console || write_stderr) {
if (write_stderr) { /* Mutex could be locked by dead thread on shutdown so forcelog will
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */ * invalidate any console lock status. */
fflush(stderr); if (force) {
} mutex_trylock(&console_lock);
mutex_unlock(&console_lock);
}
if (write_console) { mutex_lock(&console_lock);
my_log_curses(prio, datetime, str, force); /* Only output to stderr if it's not going to the screen as well */
if (write_stderr) {
fprintf(stderr, "%s%s\n", datetime, str); /* atomic write to stderr */
fflush(stderr);
}
if (write_console) {
_my_log_curses(prio, datetime, str);
}
mutex_unlock(&console_lock);
} }
} }
} }

View File

@ -1460,7 +1460,7 @@ extern void remove_pool(struct pool *pool);
extern void zero_bestshare(void); extern void zero_bestshare(void);
extern void zero_stats(void); extern void zero_stats(void);
extern void default_save_file(char *filename); extern void default_save_file(char *filename);
extern bool log_curses_only(int prio, const char *datetime, const char *str); extern bool _log_curses_only(int prio, const char *datetime, const char *str);
extern void clear_logwin(void); extern void clear_logwin(void);
extern void logwin_update(void); extern void logwin_update(void);
extern bool pool_tclear(struct pool *pool, bool *var); extern bool pool_tclear(struct pool *pool, bool *var);

View File

@ -2624,13 +2624,13 @@ static void switch_logsize(bool __maybe_unused newdevs)
#endif #endif
#ifdef HAVE_CURSES #ifdef HAVE_CURSES
bool log_curses_only(int prio, const char *datetime, const char *str) bool _log_curses_only(int prio, const char *datetime, const char *str)
{ {
bool high_prio; bool high_prio;
high_prio = (prio == LOG_WARNING || prio == LOG_ERR); high_prio = (prio == LOG_WARNING || prio == LOG_ERR);
if (curses_active_locked()) { if (curses_active) {
if (!opt_loginput || high_prio) { if (!opt_loginput || high_prio) {
wprintw(logwin, "%s%s\n", datetime, str); wprintw(logwin, "%s%s\n", datetime, str);
if (high_prio) { if (high_prio) {
@ -2638,7 +2638,6 @@ bool log_curses_only(int prio, const char *datetime, const char *str)
wrefresh(logwin); wrefresh(logwin);
} }
} }
unlock_curses();
return true; return true;
} }
return false; return false;