Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SIGUSR1 #415

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion src/mining/Miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//
// ==========================================================================

#include <signal.h>
#include "Miner.hpp"
#include "logging/MinerLogger.hpp"
#include "MinerConfig.hpp"
Expand All @@ -35,6 +36,8 @@
#include <Poco/Delegate.h>
#include "plots/PlotVerifier.hpp"

Burst::Miner *Burst::Miner::instance;

namespace Burst
{
namespace MinerHelper
Expand Down Expand Up @@ -83,7 +86,9 @@ namespace Burst
}

Burst::Miner::Miner()
{}
{
instance = this;
}

Burst::Miner::~Miner() = default;

Expand Down Expand Up @@ -156,6 +161,8 @@ void Burst::Miner::run()
size_t currentMiningInfoIndex = 0;
std::string currentUrl;

signal(SIGUSR1, Burst::Miner::sigUsr1Handler);

while (running_)
{
try
Expand Down Expand Up @@ -206,6 +213,8 @@ void Burst::Miner::run()
std::this_thread::sleep_for(std::chrono::seconds(MinerConfig::getConfig().getMiningInfoInterval()));
}

signal(SIGUSR1, NULL);

if (wakeUpTime > 0)
wakeUpTimer_.stop();

Expand Down Expand Up @@ -233,6 +242,11 @@ void Burst::Miner::restart()
stop();
}

void Burst::Miner::sigUsr1Handler(int sigNum)
{
instance->restart();
}

void Burst::Miner::addPlotReadNotifications(bool wakeUpCall)
{
const auto initPlotReadNotification = [this, wakeUpCall](PlotDir& plotDir)
Expand Down Expand Up @@ -648,6 +662,11 @@ bool Burst::Miner::getMiningInfo(const Url& url)

return false;
}
catch (const Poco::NotFoundException& e)
{
log_error(MinerLogger::miner, "Could not get the mining information: %s", e.displayText());
return false;
}
catch (const Poco::Exception& e)
{
log_error(MinerLogger::miner, "Could not get the mining information: %s", e.displayText());
Expand Down
2 changes: 2 additions & 0 deletions src/mining/Miner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace Burst
void run();
void stop();
void restart();
static void sigUsr1Handler(int sigNum);
void addPlotReadNotifications(bool wakeUpCall = false);
bool wantRestart() const;

Expand Down Expand Up @@ -106,5 +107,6 @@ namespace Burst
Poco::Timer wakeUpTimer_;
mutable Poco::Mutex workerMutex_;
std::chrono::high_resolution_clock::time_point startPoint_;
static Miner *instance;
};
}