2017-04-15 09:02:08 +03:00
|
|
|
/* 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>
|
2018-03-27 14:01:38 +07:00
|
|
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
2019-02-15 05:42:46 +07:00
|
|
|
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
|
|
|
|
* Copyright 2018 SChernykh <https://github.com/SChernykh>
|
|
|
|
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
2017-04-15 09:02:08 +03:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-06-04 20:52:21 +03:00
|
|
|
|
2017-06-14 16:11:01 +03:00
|
|
|
#include <stdlib.h>
|
2017-06-04 20:52:21 +03:00
|
|
|
#include <uv.h>
|
|
|
|
|
|
|
|
|
|
|
2017-08-31 04:30:59 +03:00
|
|
|
#include "api/Api.h"
|
2017-06-04 20:52:21 +03:00
|
|
|
#include "App.h"
|
2019-03-16 02:07:26 +07:00
|
|
|
#include "base/io/Console.h"
|
2019-03-26 19:56:35 +07:00
|
|
|
#include "base/io/log/Log.h"
|
2019-02-15 14:21:40 +07:00
|
|
|
#include "base/kernel/Signals.h"
|
2018-09-23 17:51:56 +03:00
|
|
|
#include "common/cpu/Cpu.h"
|
2018-04-13 07:23:01 +07:00
|
|
|
#include "common/Platform.h"
|
2019-03-30 21:27:54 +07:00
|
|
|
#include "core/config/Config.h"
|
2018-03-27 14:01:38 +07:00
|
|
|
#include "core/Controller.h"
|
2017-06-09 15:09:21 +03:00
|
|
|
#include "Mem.h"
|
2017-06-04 20:52:21 +03:00
|
|
|
#include "net/Network.h"
|
2017-06-08 01:16:45 +03:00
|
|
|
#include "Summary.h"
|
2017-06-04 20:52:21 +03:00
|
|
|
#include "version.h"
|
2017-06-10 09:41:08 +03:00
|
|
|
#include "workers/Workers.h"
|
2017-06-04 20:52:21 +03:00
|
|
|
|
|
|
|
|
|
2019-02-15 05:42:46 +07:00
|
|
|
xmrig::App::App(Process *process) :
|
2017-07-23 08:35:26 +03:00
|
|
|
m_console(nullptr),
|
2019-02-15 14:21:40 +07:00
|
|
|
m_signals(nullptr)
|
2017-06-04 20:52:21 +03:00
|
|
|
{
|
2019-02-25 15:54:21 +07:00
|
|
|
m_controller = new Controller(process);
|
2019-02-15 05:42:46 +07:00
|
|
|
if (m_controller->init() != 0) {
|
2017-08-04 21:47:43 +03:00
|
|
|
return;
|
|
|
|
|
}
|
2017-06-19 10:58:28 +03:00
|
|
|
|
2018-03-31 16:29:47 +07:00
|
|
|
if (!m_controller->config()->isBackground()) {
|
2017-07-23 09:36:30 +03:00
|
|
|
m_console = new Console(this);
|
2017-06-22 14:41:34 +03:00
|
|
|
}
|
2017-06-04 20:52:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-15 05:42:46 +07:00
|
|
|
xmrig::App::~App()
|
2017-06-04 20:52:21 +03:00
|
|
|
{
|
2019-02-15 14:21:40 +07:00
|
|
|
delete m_signals;
|
2018-03-31 16:29:47 +07:00
|
|
|
delete m_console;
|
|
|
|
|
delete m_controller;
|
2017-06-04 20:52:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-15 05:42:46 +07:00
|
|
|
int xmrig::App::exec()
|
2017-06-04 20:52:21 +03:00
|
|
|
{
|
2018-03-31 17:51:33 +07:00
|
|
|
if (!m_controller->isReady()) {
|
2018-01-20 12:58:43 +07:00
|
|
|
return 2;
|
2017-06-04 20:52:21 +03:00
|
|
|
}
|
|
|
|
|
|
2019-02-15 14:21:40 +07:00
|
|
|
m_signals = new Signals(this);
|
2017-06-13 13:20:15 +03:00
|
|
|
|
|
|
|
|
background();
|
|
|
|
|
|
2019-06-28 22:28:40 +07:00
|
|
|
Mem::init(m_controller->config()->cpu().isHugePages());
|
2017-06-08 01:16:45 +03:00
|
|
|
|
2018-03-31 16:29:47 +07:00
|
|
|
Summary::print(m_controller);
|
|
|
|
|
|
|
|
|
|
if (m_controller->config()->isDryRun()) {
|
2018-01-20 20:43:31 +07:00
|
|
|
LOG_NOTICE("OK");
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-03 03:27:44 +07:00
|
|
|
Workers::start(m_controller);
|
2017-06-10 07:05:00 +03:00
|
|
|
|
2019-03-30 00:16:01 +07:00
|
|
|
m_controller->start();
|
2017-06-04 20:52:21 +03:00
|
|
|
|
|
|
|
|
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
|
|
|
|
uv_loop_close(uv_default_loop());
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
2017-06-13 13:20:15 +03:00
|
|
|
|
|
|
|
|
|
2019-02-15 05:42:46 +07:00
|
|
|
void xmrig::App::onConsoleCommand(char command)
|
2017-07-23 09:36:30 +03:00
|
|
|
{
|
|
|
|
|
switch (command) {
|
|
|
|
|
case 'h':
|
|
|
|
|
case 'H':
|
|
|
|
|
Workers::printHashrate(true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
|
case 'P':
|
2018-01-10 22:55:45 +07:00
|
|
|
if (Workers::isEnabled()) {
|
2019-03-26 19:56:35 +07:00
|
|
|
LOG_INFO(YELLOW_BOLD("paused") ", press " MAGENTA_BOLD("r") " to resume");
|
2018-01-10 22:55:45 +07:00
|
|
|
Workers::setEnabled(false);
|
|
|
|
|
}
|
2017-07-23 09:36:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
|
case 'R':
|
|
|
|
|
if (!Workers::isEnabled()) {
|
2019-03-26 19:56:35 +07:00
|
|
|
LOG_INFO(GREEN_BOLD("resumed"));
|
2017-07-23 09:36:30 +03:00
|
|
|
Workers::setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
LOG_WARN("Ctrl+C received, exiting");
|
|
|
|
|
close();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-15 14:21:40 +07:00
|
|
|
void xmrig::App::onSignal(int signum)
|
2017-06-13 13:20:15 +03:00
|
|
|
{
|
|
|
|
|
switch (signum)
|
|
|
|
|
{
|
|
|
|
|
case SIGHUP:
|
|
|
|
|
LOG_WARN("SIGHUP received, exiting");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIGTERM:
|
|
|
|
|
LOG_WARN("SIGTERM received, exiting");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIGINT:
|
|
|
|
|
LOG_WARN("SIGINT received, exiting");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2019-02-25 15:54:21 +07:00
|
|
|
return;
|
2017-06-13 13:20:15 +03:00
|
|
|
}
|
|
|
|
|
|
2019-02-15 14:21:40 +07:00
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void xmrig::App::close()
|
|
|
|
|
{
|
2019-03-16 00:44:15 +07:00
|
|
|
m_signals->stop();
|
|
|
|
|
m_console->stop();
|
|
|
|
|
m_controller->stop();
|
|
|
|
|
|
|
|
|
|
Workers::stop();
|
2019-03-26 19:56:35 +07:00
|
|
|
Log::destroy();
|
2019-02-15 14:21:40 +07:00
|
|
|
}
|