Merge pull request #271 from luke-jr/cg_logfixes Logging bugfixes
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
diff --git a/adl.c b/adl.c
index 8573e16..85ec0aa 100644
--- a/adl.c
+++ b/adl.c
@@ -33,6 +33,10 @@
#endif
#include "adl_functions.h"
+#ifndef HAVE_CURSES
+#define wlogprint(...) applog(LOG_WARNING, __VA_ARGS__)
+#endif
+
bool adl_active;
bool opt_reorder = false;
@@ -764,6 +768,7 @@ bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vdd
return true;
}
+#ifdef HAVE_CURSES
static void get_enginerange(int gpu, int *imin, int *imax)
{
struct gpu_adl *ga;
@@ -776,6 +781,7 @@ static void get_enginerange(int gpu, int *imin, int *imax)
*imin = ga->lpOdParameters.sEngineClock.iMin / 100;
*imax = ga->lpOdParameters.sEngineClock.iMax / 100;
}
+#endif
int set_engineclock(int gpu, int iEngineClock)
{
@@ -824,6 +830,7 @@ out:
return ret;
}
+#ifdef HAVE_CURSES
static void get_memoryrange(int gpu, int *imin, int *imax)
{
struct gpu_adl *ga;
@@ -836,6 +843,7 @@ static void get_memoryrange(int gpu, int *imin, int *imax)
*imin = ga->lpOdParameters.sMemoryClock.iMin / 100;
*imax = ga->lpOdParameters.sMemoryClock.iMax / 100;
}
+#endif
int set_memoryclock(int gpu, int iMemoryClock)
{
@@ -876,6 +884,7 @@ out:
return ret;
}
+#ifdef HAVE_CURSES
static void get_vddcrange(int gpu, float *imin, float *imax)
{
struct gpu_adl *ga;
@@ -889,7 +898,6 @@ static void get_vddcrange(int gpu, float *imin, float *imax)
*imax = (float)ga->lpOdParameters.sVddc.iMax / 1000;
}
-#ifdef HAVE_CURSES
static float curses_float(const char *query)
{
float ret;
@@ -997,6 +1005,7 @@ int set_fanspeed(int gpu, int iFanSpeed)
return ret;
}
+#ifdef HAVE_CURSES
static int set_powertune(int gpu, int iPercentage)
{
struct gpu_adl *ga;
@@ -1018,6 +1027,7 @@ static int set_powertune(int gpu, int iPercentage)
unlock_adl();
return ret;
}
+#endif
/* Returns whether the fanspeed is optimal already or not. The fan_window bool
* tells us whether the current fanspeed is in the target range for fanspeeds.
diff --git a/cgminer.c b/cgminer.c
index 36bdf22..edfe4e3 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -87,7 +87,7 @@ static bool opt_benchmark;
static bool have_longpoll;
static bool want_per_device_stats;
bool use_syslog;
-static bool opt_quiet;
+bool opt_quiet;
static bool opt_realquiet;
bool opt_loginput;
const int opt_cutofftemp = 95;
@@ -167,9 +167,7 @@ static int total_threads;
static pthread_mutex_t hash_lock;
static pthread_mutex_t qd_lock;
static pthread_mutex_t *stgd_lock;
-#ifdef HAVE_CURSES
-static pthread_mutex_t curses_lock;
-#endif
+pthread_mutex_t console_lock;
static pthread_mutex_t ch_lock;
static pthread_rwlock_t blk_lock;
@@ -205,10 +203,11 @@ enum pool_strategy pool_strategy = POOL_FAILOVER;
int opt_rotate_period;
static int total_urls, total_users, total_passes, total_userpasses;
+static
#ifndef HAVE_CURSES
const
#endif
-static bool curses_active;
+bool curses_active;
static char current_block[37];
static char *current_hash;
@@ -1339,8 +1338,10 @@ double total_secs = 0.1;
static char statusline[256];
/* logstart is where the log window should start */
static int devcursor, logstart, logcursor;
+#ifdef HAVE_CURSES
/* statusy is where the status window goes up to in cases where it won't fit at startup */
static int statusy;
+#endif
#ifdef HAVE_OPENCL
struct cgpu_info gpus[MAX_GPUDEVICES]; /* Maximum number apparently possible */
#endif
@@ -1349,12 +1350,12 @@ struct cgpu_info *cpus;
#ifdef HAVE_CURSES
static inline void unlock_curses(void)
{
- mutex_unlock(&curses_lock);
+ mutex_unlock(&console_lock);
}
static inline void lock_curses(void)
{
- mutex_lock(&curses_lock);
+ mutex_lock(&console_lock);
}
static bool curses_active_locked(void)
@@ -1588,13 +1589,10 @@ void wlogprint(const char *f, ...)
#endif
#ifdef HAVE_CURSES
-void log_curses(int prio, const char *f, va_list ap)
+bool log_curses_only(int prio, const char *f, va_list ap)
{
bool high_prio;
- if (opt_quiet && prio != LOG_ERR)
- return;
-
high_prio = (prio == LOG_WARNING || prio == LOG_ERR);
if (curses_active_locked()) {
@@ -1606,8 +1604,9 @@ void log_curses(int prio, const char *f, va_list ap)
}
}
unlock_curses();
- } else
- vprintf(f, ap);
+ return true;
+ }
+ return false;
}
void clear_logwin(void)
@@ -5126,9 +5125,7 @@ int main(int argc, char *argv[])
mutex_init(&hash_lock);
mutex_init(&qd_lock);
-#ifdef HAVE_CURSES
- mutex_init(&curses_lock);
-#endif
+ mutex_init(&console_lock);
mutex_init(&control_lock);
mutex_init(&sharelog_lock);
mutex_init(&ch_lock);
diff --git a/driver-opencl.c b/driver-opencl.c
index 8df0b10..0d1d0ea 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -1322,16 +1322,17 @@ static bool opencl_thread_prepare(struct thr_info *thr)
applog(LOG_INFO, "Init GPU thread %i GPU %i virtual GPU %i", i, gpu, virtual_gpu);
clStates[i] = initCl(virtual_gpu, name, sizeof(name));
if (!clStates[i]) {
+#ifdef HAVE_CURSES
if (use_curses)
enable_curses();
+#endif
applog(LOG_ERR, "Failed to init GPU thread %d, disabling device %d", i, gpu);
if (!failmessage) {
- char *buf;
-
applog(LOG_ERR, "Restarting the GPU from the menu will not fix this.");
applog(LOG_ERR, "Try restarting cgminer.");
failmessage = true;
#ifdef HAVE_CURSES
+ char *buf;
if (use_curses) {
buf = curses_input("Press enter to continue");
if (buf)
diff --git a/logging.c b/logging.c
index 3195663..47d1970 100644
--- a/logging.c
+++ b/logging.c
@@ -18,12 +18,15 @@ 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, char *f, va_list ap)
+static void my_log_curses(__maybe_unused int prio, char *f, va_list ap)
{
+ if (opt_quiet && prio != LOG_ERR)
+ return;
+
#ifdef HAVE_CURSES
extern bool use_curses;
- if (use_curses)
- log_curses(prio, f, ap);
+ if (use_curses && log_curses_only(prio, f, ap))
+ ;
else
#endif
{
@@ -31,57 +34,20 @@ static void my_log_curses(int prio, char *f, va_list ap)
strcpy(f + len - 1, " \n");
-#ifdef HAVE_CURSES
- log_curses(prio, f, ap);
-#else
+ mutex_lock(&console_lock);
vprintf(f, ap);
-#endif
+ mutex_unlock(&console_lock);
}
}
+static void log_generic(int prio, const char *fmt, va_list ap);
+
void vapplog(int prio, const char *fmt, va_list ap)
{
if (!opt_debug && prio == LOG_DEBUG)
return;
-
-#ifdef HAVE_SYSLOG_H
- if (use_syslog) {
- vsyslog(prio, fmt, ap);
- }
-#else
- if (0) {}
-#endif
- else if (opt_log_output || prio <= LOG_NOTICE) {
- char *f;
- int len;
- struct timeval tv = {0, 0};
- struct tm *tm;
-
- gettimeofday(&tv, NULL);
-
- tm = localtime(&tv.tv_sec);
-
- len = 40 + strlen(fmt) + 22;
- f = alloca(len);
- sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d] %s\n",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- fmt);
- /* Only output to stderr if it's not going to the screen as well */
- if (!isatty(fileno((FILE *)stderr))) {
- va_list apc;
-
- va_copy(apc, ap);
- vfprintf(stderr, f, apc); /* atomic write to stderr */
- fflush(stderr);
- }
-
- my_log_curses(prio, f, ap);
- }
+ if (use_syslog || opt_log_output || prio <= LOG_NOTICE)
+ log_generic(prio, fmt, ap);
}
void applog(int prio, const char *fmt, ...)
@@ -100,7 +66,7 @@ void applog(int prio, const char *fmt, ...)
* generic log function used by priority specific ones
* equals vapplog() without additional priority checks
*/
-static void __maybe_unused log_generic(int prio, const char *fmt, va_list ap)
+static void log_generic(int prio, const char *fmt, va_list ap)
{
#ifdef HAVE_SYSLOG_H
if (use_syslog) {
@@ -121,7 +87,7 @@ static void __maybe_unused log_generic(int prio, const char *fmt, va_list ap)
len = 40 + strlen(fmt) + 22;
f = alloca(len);
- sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n",
+ sprintf(f, " [%d-%02d-%02d %02d:%02d:%02d] %s\n",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
diff --git a/miner.h b/miner.h
index 11dcb5f..4f553cd 100644
--- a/miner.h
+++ b/miner.h
@@ -584,6 +584,8 @@ extern bool fulltest(const unsigned char *hash, const unsigned char *target);
extern int opt_scantime;
+extern pthread_mutex_t console_lock;
+
extern pthread_mutex_t restart_lock;
extern pthread_cond_t restart_cond;
@@ -627,6 +629,7 @@ extern int opt_n_threads;
extern int num_processors;
extern int hw_errors;
extern bool use_syslog;
+extern bool opt_quiet;
extern struct thr_info *thr_info;
extern struct cgpu_info gpus[MAX_GPUDEVICES];
extern int gpu_threads;
@@ -817,7 +820,7 @@ extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
extern void default_save_file(char *filename);
-extern void log_curses(int prio, const char *f, va_list ap);
+extern bool log_curses_only(int prio, const char *f, va_list ap);
extern void clear_logwin(void);
extern bool pool_tclear(struct pool *pool, bool *var);
extern struct thread_q *tq_new(void);