Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Correct handling of --display-interval. #1591

Merged
merged 3 commits into from
Sep 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions ethminer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct MiningChannel : public LogChannel
#include <ethminer/DBusInt.h>
#endif

bool g_running = false;
bool g_got_exit_signal = false;

class MinerCLI
{
Expand Down Expand Up @@ -110,7 +110,7 @@ class MinerCLI
static void signalHandler(int sig)
{
(void)sig;
g_running = false;
g_got_exit_signal = true;
}
#if API_CORE
static bool ParseBind(const std::string& inaddr, std::string& outaddr, int& outport,
Expand Down Expand Up @@ -301,8 +301,8 @@ class MinerCLI
->check(CLI::Range(-65535, 65535));

app.add_option("--api-password", m_api_password,
"Set the password to protect interaction with API server. If not set, any connection "
"is granted access. "
"Set the password to protect interaction with API server. If not set, any "
"connection is granted access. "
"Be advised passwords are sent unencrypted over plain TCP!!")
->group(APIGroup);

Expand Down Expand Up @@ -753,7 +753,6 @@ class MinerCLI
#endif
}

g_running = true;
signal(SIGINT, MinerCLI::signalHandler);
signal(SIGTERM, MinerCLI::signalHandler);

Expand Down Expand Up @@ -935,17 +934,20 @@ class MinerCLI
unsigned interval = m_displayInterval;

// Run CLI in loop
while (g_running && PoolManager::p().isRunning())
while (!g_got_exit_signal && PoolManager::p().isRunning())
{
// Wait at the beginning of the loop to give some time
// services to start properly. Otherwise we get a "not-connected"
// message immediately
this_thread::sleep_for(chrono::seconds(2));
if (interval > 2)
{
interval -= 2;

// Split m_displayInterval in 1 second parts to optain a faster exit
this_thread::sleep_for(chrono::seconds(1));
interval--;
if (interval)
continue;
}
interval = m_displayInterval;

// Display current stats of the farm if it's connected
if (PoolManager::p().isConnected())
{
auto solstats = Farm::f().getSolutionStats();
Expand All @@ -964,7 +966,8 @@ class MinerCLI
statdetails << "Solutions " << solstats << ' ';
for (size_t i = 0; i < Farm::f().getMiners().size(); i++)
{
if (i) statdetails << " ";
if (i)
statdetails << " ";
statdetails << "gpu" << i << ":" << solstats.getString(i);
}
minelog << statdetails.str();
Expand All @@ -978,7 +981,6 @@ class MinerCLI
{
minelog << "not-connected";
}
interval = m_displayInterval;
}

#if API_CORE
Expand Down