Console: check stdin handle early at startup

master
SChernykh 1 year ago
parent 6e258bb210
commit 7a83fd2f30

@ -34,6 +34,8 @@ static constexpr int DEFAULT_BACKLOG = 1;
namespace p2pool {
extern const uv_handle_type stdin_type;
ConsoleCommands::ConsoleCommands(p2pool* pool)
: TCPServer(DEFAULT_BACKLOG, ConsoleClient::allocate)
, m_pool(pool)
@ -43,6 +45,12 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
, m_readBuf{}
, m_readBufInUse(false)
{
LOGINFO(3, "uv_guess_handle returned " << static_cast<int>(stdin_type));
if (stdin_type != UV_TTY && stdin_type != UV_NAMED_PIPE) {
LOGERR(1, "tty or named pipe is not available");
throw std::exception();
}
std::random_device rd;
for (int i = 0; i < 10; ++i) {
@ -62,13 +70,6 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
PANIC_STOP();
}
const uv_handle_type stdin_type = uv_guess_handle(0);
LOGINFO(3, "uv_guess_handle returned " << static_cast<int>(stdin_type));
if (stdin_type != UV_TTY && stdin_type != UV_NAMED_PIPE) {
LOGERR(1, "tty or named pipe is not available");
throw std::exception();
}
if (stdin_type == UV_TTY) {
LOGINFO(3, "processing stdin as UV_TTY");
err = uv_tty_init(&m_loop, &m_tty, 0, 1);
@ -102,7 +103,7 @@ ConsoleCommands::ConsoleCommands(p2pool* pool)
if (m_pool->api() && m_pool->params().m_localStats) {
m_pool->api()->set(p2pool_api::Category::LOCAL, "console",
[stdin_type, this](log::Stream& s)
[this](log::Stream& s)
{
s << "{\"mode\":" << ((stdin_type == UV_TTY) ? "\"tty\"" : "\"pipe\"")
<< ",\"tcp_port\":" << m_listenPort

@ -32,6 +32,8 @@ static constexpr char log_file_name[] = "p2pool.log";
namespace p2pool {
extern const uv_handle_type stdin_type = uv_guess_handle(0);
namespace log {
int GLOBAL_LOG_LEVEL = 3;

Loading…
Cancel
Save