Update Signals and Console.

This commit is contained in:
XMRig 2020-12-03 12:06:18 +07:00
parent 86795aa5b7
commit 0a27c6d6af
No known key found for this signature in database
GPG key ID: 446A53638BE94409
7 changed files with 80 additions and 101 deletions

View file

@ -43,17 +43,13 @@
xmrig::App::App(Process *process)
{
m_controller = new Controller(process);
m_controller = std::make_shared<Controller>(process);
}
xmrig::App::~App()
{
Cpu::release();
delete m_signals;
delete m_console;
delete m_controller;
}
@ -65,7 +61,7 @@ int xmrig::App::exec()
return 2;
}
m_signals = new Signals(this);
m_signals = std::make_shared<Signals>(this);
int rc = 0;
if (background(rc)) {
@ -78,10 +74,10 @@ int xmrig::App::exec()
}
if (!m_controller->isBackground()) {
m_console = new Console(this);
m_console = std::make_shared<Console>(this);
}
Summary::print(m_controller);
Summary::print(m_controller.get());
if (m_controller->config()->isDryRun()) {
LOG_NOTICE("%s " WHITE_BOLD("OK"), Tags::config());
@ -115,32 +111,20 @@ void xmrig::App::onSignal(int signum)
switch (signum)
{
case SIGHUP:
LOG_WARN("%s " YELLOW("SIGHUP received, exiting"), Tags::signal());
break;
case SIGTERM:
LOG_WARN("%s " YELLOW("SIGTERM received, exiting"), Tags::signal());
break;
case SIGINT:
LOG_WARN("%s " YELLOW("SIGINT received, exiting"), Tags::signal());
break;
return close();
default:
return;
break;
}
close();
}
void xmrig::App::close()
{
m_signals->stop();
if (m_console) {
m_console->stop();
}
m_signals.reset();
m_console.reset();
m_controller->stop();

View file

@ -32,6 +32,9 @@
#include "base/tools/Object.h"
#include <memory>
namespace xmrig {
@ -60,9 +63,9 @@ private:
bool background(int &rc);
void close();
Console *m_console = nullptr;
Controller *m_controller = nullptr;
Signals *m_signals = nullptr;
std::shared_ptr<Console> m_console;
std::shared_ptr<Controller> m_controller;
std::shared_ptr<Signals> m_signals;
};

View file

@ -5,8 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,8 +36,6 @@
bool xmrig::App::background(int &rc)
{
signal(SIGPIPE, SIG_IGN);
if (!m_controller->isBackground()) {
return false;
}

View file

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -50,20 +44,9 @@ xmrig::Console::Console(IConsoleListener *listener)
xmrig::Console::~Console()
{
stop();
}
void xmrig::Console::stop()
{
if (!m_tty) {
return;
}
uv_tty_reset_mode();
Handle::close(m_tty);
m_tty = nullptr;
}

View file

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,7 +23,10 @@
#include "base/tools/Object.h"
#include <uv.h>
using uv_buf_t = struct uv_buf_t;
using uv_handle_t = struct uv_handle_s;
using uv_stream_t = struct uv_stream_s;
using uv_tty_t = struct uv_tty_s;
namespace xmrig {
@ -46,8 +43,6 @@ public:
Console(IConsoleListener *listener);
~Console();
void stop();
private:
bool isSupported() const;

View file

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,22 +17,29 @@
*/
#include <uv.h>
#include "base/io/Signals.h"
#include "base/kernel/interfaces/ISignalListener.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/io/Signals.h"
#include "base/tools/Handle.h"
#ifdef SIGUSR1
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM, SIGUSR1 };
#else
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
#endif
xmrig::Signals::Signals(ISignalListener *listener)
: m_listener(listener)
{
# ifndef XMRIG_OS_WIN
signal(SIGPIPE, SIG_IGN);
# endif
for (size_t i = 0; i < kSignalsCount; ++i) {
uv_signal_t *signal = new uv_signal_t;
auto signal = new uv_signal_t;
signal->data = this;
m_signals[i] = signal;
@ -51,24 +52,37 @@ xmrig::Signals::Signals(ISignalListener *listener)
xmrig::Signals::~Signals()
{
stop();
}
void xmrig::Signals::stop()
{
if (!m_signals[0]) {
return;
}
for (size_t i = 0; i < kSignalsCount; ++i) {
Handle::close(m_signals[i]);
m_signals[i] = nullptr;
for (auto signal : m_signals) {
Handle::close(signal);
}
}
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
{
switch (signum)
{
case SIGHUP:
LOG_WARN("%s " YELLOW("SIGHUP received, exiting"), Tags::signal());
break;
case SIGTERM:
LOG_WARN("%s " YELLOW("SIGTERM received, exiting"), Tags::signal());
break;
case SIGINT:
LOG_WARN("%s " YELLOW("SIGINT received, exiting"), Tags::signal());
break;
# ifdef SIGUSR1
case SIGUSR1:
LOG_V5("%s " WHITE_BOLD("SIGUSR1 received"), Tags::signal());
break;
# endif
default:
break;
}
static_cast<Signals *>(handle->data)->m_listener->onSignal(signum);
}

View file

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,10 +20,14 @@
#define XMRIG_SIGNALS_H
#include <stddef.h>
#include "base/tools/Object.h"
typedef struct uv_signal_s uv_signal_t;
#include <csignal>
#include <cstddef>
using uv_signal_t = struct uv_signal_s;
namespace xmrig {
@ -41,20 +39,24 @@ class ISignalListener;
class Signals
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Signals)
# ifdef SIGUSR1
constexpr static const size_t kSignalsCount = 4;
# else
constexpr static const size_t kSignalsCount = 3;
# endif
Signals(ISignalListener *listener);
~Signals();
void stop();
private:
void close(int signum);
static void onSignal(uv_signal_t *handle, int signum);
ISignalListener *m_listener;
uv_signal_t *m_signals[kSignalsCount];
uv_signal_t *m_signals[kSignalsCount]{};
};