mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-16 15:57:38 +00:00
Add signal handlers.
This commit is contained in:
parent
2d08f59184
commit
8c2951db2d
6 changed files with 114 additions and 8 deletions
|
@ -76,6 +76,7 @@ if (WIN32)
|
|||
res/app.rc
|
||||
src/3rdparty/winansi.cpp
|
||||
src/3rdparty/winansi.h
|
||||
src/App_win.cpp
|
||||
src/Cpu_win.cpp
|
||||
src/Mem_win.cpp
|
||||
src/net/Network_win.cpp
|
||||
|
|
55
src/App.cpp
55
src/App.cpp
|
@ -30,7 +30,6 @@
|
|||
#include "Cpu.h"
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "Mem.h"
|
||||
#include "net/Client.h"
|
||||
#include "net/Network.h"
|
||||
#include "Options.h"
|
||||
#include "Summary.h"
|
||||
|
@ -38,25 +37,28 @@
|
|||
#include "workers/Workers.h"
|
||||
|
||||
|
||||
App *App::m_self = nullptr;
|
||||
|
||||
App::App(int argc, char **argv)
|
||||
|
||||
|
||||
App::App(int argc, char **argv) :
|
||||
m_network(nullptr),
|
||||
m_options(nullptr)
|
||||
{
|
||||
m_self = this;
|
||||
|
||||
Console::init();
|
||||
Cpu::init();
|
||||
|
||||
m_options = Options::parse(argc, argv);
|
||||
m_network = new Network(m_options);
|
||||
|
||||
|
||||
uv_signal_init(uv_default_loop(), &m_signal);
|
||||
}
|
||||
|
||||
|
||||
App::~App()
|
||||
{
|
||||
LOG_DEBUG("~APP");
|
||||
|
||||
free(m_network);
|
||||
free(m_options);
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,6 +73,12 @@ int App::exec()
|
|||
return 1;
|
||||
}
|
||||
|
||||
uv_signal_start(&m_signal, App::onSignal, SIGHUP);
|
||||
uv_signal_start(&m_signal, App::onSignal, SIGTERM);
|
||||
uv_signal_start(&m_signal, App::onSignal, SIGINT);
|
||||
|
||||
background();
|
||||
|
||||
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash());
|
||||
Summary::print();
|
||||
|
||||
|
@ -81,5 +89,38 @@ int App::exec()
|
|||
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
uv_loop_close(uv_default_loop());
|
||||
|
||||
free(m_network);
|
||||
free(m_options);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void App::close()
|
||||
{
|
||||
uv_stop(uv_default_loop());
|
||||
}
|
||||
|
||||
|
||||
void App::onSignal(uv_signal_t *handle, int signum)
|
||||
{
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
m_self->close();
|
||||
}
|
||||
|
|
11
src/App.h
11
src/App.h
|
@ -25,6 +25,9 @@
|
|||
#define __APP_H__
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
class Network;
|
||||
class Options;
|
||||
|
||||
|
@ -38,8 +41,16 @@ public:
|
|||
int exec();
|
||||
|
||||
private:
|
||||
void background();
|
||||
void close();
|
||||
|
||||
static void onSignal(uv_signal_t *handle, int signum);
|
||||
|
||||
static App *m_self;
|
||||
|
||||
Network *m_network;
|
||||
Options *m_options;
|
||||
uv_signal_t m_signal;
|
||||
};
|
||||
|
||||
|
||||
|
|
52
src/App_win.cpp
Normal file
52
src/App_win.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* 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 2016-2017 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
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "Options.h"
|
||||
#include "Cpu.h"
|
||||
|
||||
|
||||
void App::background()
|
||||
{
|
||||
if (m_options->affinity() != -1L) {
|
||||
Cpu::setAffinity(-1, m_options->affinity());
|
||||
}
|
||||
|
||||
if (!m_options->background()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HWND hcon = GetConsoleWindow();
|
||||
if (hcon) {
|
||||
ShowWindow(hcon, SW_HIDE);
|
||||
} else {
|
||||
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CloseHandle(h);
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
|
@ -91,7 +91,7 @@ void Cpu::initCommon()
|
|||
m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0;
|
||||
}
|
||||
|
||||
# ifdef __x86_64__
|
||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
||||
m_flags |= X86_64;
|
||||
# endif
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
static inline Options* i() { return m_self; }
|
||||
static Options *parse(int argc, char **argv);
|
||||
|
||||
inline bool background() const { return m_background; }
|
||||
inline bool colors() const { return m_colors; }
|
||||
inline bool doubleHash() const { return m_doubleHash; }
|
||||
inline bool isReady() const { return m_ready; }
|
||||
|
|
Loading…
Reference in a new issue