mirror of
https://github.com/xmrig/xmrig.git
synced 2025-03-21 06:38:56 +00:00
Fix error if stdout not available.
This commit is contained in:
parent
168b1aac2f
commit
60224ccd23
2 changed files with 19 additions and 1 deletions
|
@ -40,7 +40,10 @@
|
||||||
ConsoleLog::ConsoleLog(bool colors) :
|
ConsoleLog::ConsoleLog(bool colors) :
|
||||||
m_colors(colors)
|
m_colors(colors)
|
||||||
{
|
{
|
||||||
uv_tty_init(uv_default_loop(), &m_tty, 1, 0);
|
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL);
|
uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL);
|
||||||
|
|
||||||
# ifdef WIN32
|
# ifdef WIN32
|
||||||
|
@ -58,6 +61,10 @@ ConsoleLog::ConsoleLog(bool colors) :
|
||||||
|
|
||||||
void ConsoleLog::message(int level, const char* fmt, va_list args)
|
void ConsoleLog::message(int level, const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
|
if (!isWritable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
time_t now = time(nullptr);
|
time_t now = time(nullptr);
|
||||||
tm stime;
|
tm stime;
|
||||||
|
|
||||||
|
@ -112,6 +119,10 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
|
||||||
|
|
||||||
void ConsoleLog::text(const char* fmt, va_list args)
|
void ConsoleLog::text(const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
|
if (!isWritable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char *buf = new char[64 + strlen(fmt) + 2];
|
char *buf = new char[64 + strlen(fmt) + 2];
|
||||||
|
|
||||||
sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
|
sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
|
||||||
|
@ -120,6 +131,12 @@ void ConsoleLog::text(const char* fmt, va_list args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ConsoleLog::isWritable() const
|
||||||
|
{
|
||||||
|
return uv_is_writable(reinterpret_cast<const uv_stream_t*>(&m_tty)) == 1 && uv_guess_handle(1) == UV_TTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ConsoleLog::print(char *fmt, va_list args)
|
void ConsoleLog::print(char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
vsnprintf(m_buf, sizeof(m_buf) - 1, fmt, args);
|
vsnprintf(m_buf, sizeof(m_buf) - 1, fmt, args);
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
void text(const char *fmt, va_list args) override;
|
void text(const char *fmt, va_list args) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool isWritable() const;
|
||||||
void print(char *fmt, va_list args);
|
void print(char *fmt, va_list args);
|
||||||
|
|
||||||
bool m_colors;
|
bool m_colors;
|
||||||
|
|
Loading…
Reference in a new issue