2017-04-15 06:02:08 +00: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 07:01:38 +00:00
|
|
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
2019-02-14 22:42:46 +00:00
|
|
|
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
2019-06-29 02:51:23 +00:00
|
|
|
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
2019-02-14 22:42:46 +00:00
|
|
|
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
2017-04-15 06:02:08 +00: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 17:52:21 +00:00
|
|
|
|
2019-09-21 12:26:27 +00:00
|
|
|
#include <cstdlib>
|
2017-06-04 17:52:21 +00:00
|
|
|
#include <uv.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "App.h"
|
2019-06-29 02:51:23 +00:00
|
|
|
#include "backend/cpu/Cpu.h"
|
2019-03-15 19:07:26 +00:00
|
|
|
#include "base/io/Console.h"
|
2019-03-26 12:56:35 +00:00
|
|
|
#include "base/io/log/Log.h"
|
2019-02-15 07:21:40 +00:00
|
|
|
#include "base/kernel/Signals.h"
|
2019-03-30 14:27:54 +00:00
|
|
|
#include "core/config/Config.h"
|
2018-03-27 07:01:38 +00:00
|
|
|
#include "core/Controller.h"
|
2019-07-16 15:10:50 +00:00
|
|
|
#include "core/Miner.h"
|
2019-07-16 21:57:58 +00:00
|
|
|
#include "crypto/common/VirtualMemory.h"
|
2017-06-04 17:52:21 +00:00
|
|
|
#include "net/Network.h"
|
2017-06-07 22:16:45 +00:00
|
|
|
#include "Summary.h"
|
2017-06-04 17:52:21 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
|
2019-09-21 12:26:27 +00:00
|
|
|
xmrig::App::App(Process *process)
|
2017-06-04 17:52:21 +00:00
|
|
|
{
|
2019-02-25 08:54:21 +00:00
|
|
|
m_controller = new Controller(process);
|
2017-06-04 17:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 22:42:46 +00:00
|
|
|
xmrig::App::~App()
|
2017-06-04 17:52:21 +00:00
|
|
|
{
|
2019-02-15 07:21:40 +00:00
|
|
|
delete m_signals;
|
2018-03-31 09:29:47 +00:00
|
|
|
delete m_console;
|
|
|
|
delete m_controller;
|
2017-06-04 17:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-14 22:42:46 +00:00
|
|
|
int xmrig::App::exec()
|
2017-06-04 17:52:21 +00:00
|
|
|
{
|
2018-03-31 10:51:33 +00:00
|
|
|
if (!m_controller->isReady()) {
|
2019-09-21 12:26:27 +00:00
|
|
|
LOG_EMERG("no valid configuration found.");
|
|
|
|
|
2018-01-20 05:58:43 +00:00
|
|
|
return 2;
|
2017-06-04 17:52:21 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 07:21:40 +00:00
|
|
|
m_signals = new Signals(this);
|
2017-06-13 10:20:15 +00:00
|
|
|
|
2019-09-21 12:26:27 +00:00
|
|
|
int rc = 0;
|
|
|
|
if (background(rc)) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = m_controller->init();
|
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_controller->isBackground()) {
|
|
|
|
m_console = new Console(this);
|
|
|
|
}
|
2017-06-13 10:20:15 +00:00
|
|
|
|
2019-07-16 21:57:58 +00:00
|
|
|
VirtualMemory::init(m_controller->config()->cpu().isHugePages());
|
2017-06-07 22:16:45 +00:00
|
|
|
|
2018-03-31 09:29:47 +00:00
|
|
|
Summary::print(m_controller);
|
|
|
|
|
|
|
|
if (m_controller->config()->isDryRun()) {
|
2018-01-20 13:43:31 +00:00
|
|
|
LOG_NOTICE("OK");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-29 17:16:01 +00:00
|
|
|
m_controller->start();
|
2017-06-04 17:52:21 +00:00
|
|
|
|
2019-09-21 12:26:27 +00:00
|
|
|
rc = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
2017-06-04 17:52:21 +00:00
|
|
|
uv_loop_close(uv_default_loop());
|
|
|
|
|
2019-09-21 12:26:27 +00:00
|
|
|
return rc;
|
2017-06-04 17:52:21 +00:00
|
|
|
}
|
2017-06-13 10:20:15 +00:00
|
|
|
|
|
|
|
|
2019-02-14 22:42:46 +00:00
|
|
|
void xmrig::App::onConsoleCommand(char command)
|
2017-07-23 06:36:30 +00:00
|
|
|
{
|
|
|
|
switch (command) {
|
|
|
|
case 'h':
|
|
|
|
case 'H':
|
2019-07-16 15:10:50 +00:00
|
|
|
m_controller->miner()->printHashrate(true);
|
2017-07-23 06:36:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
case 'P':
|
2019-07-16 15:10:50 +00:00
|
|
|
m_controller->miner()->setEnabled(false);
|
2017-07-23 06:36:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
2019-07-16 15:10:50 +00:00
|
|
|
m_controller->miner()->setEnabled(true);
|
2017-07-23 06:36:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
LOG_WARN("Ctrl+C received, exiting");
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-15 07:21:40 +00:00
|
|
|
void xmrig::App::onSignal(int signum)
|
2017-06-13 10:20:15 +00: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 08:54:21 +00:00
|
|
|
return;
|
2017-06-13 10:20:15 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 07:21:40 +00:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void xmrig::App::close()
|
|
|
|
{
|
2019-03-15 17:44:15 +00:00
|
|
|
m_signals->stop();
|
2019-09-21 12:05:52 +00:00
|
|
|
|
|
|
|
if (m_console) {
|
|
|
|
m_console->stop();
|
|
|
|
}
|
|
|
|
|
2019-03-15 17:44:15 +00:00
|
|
|
m_controller->stop();
|
|
|
|
|
2019-03-26 12:56:35 +00:00
|
|
|
Log::destroy();
|
2019-02-15 07:21:40 +00:00
|
|
|
}
|