Update Entry class.
This commit is contained in:
parent
de97f3492e
commit
603eb261c5
@ -157,14 +157,12 @@ endif()
|
||||
if (XMRIG_OS_WIN)
|
||||
list(APPEND SOURCES_OS
|
||||
res/app.rc
|
||||
src/App_win.cpp
|
||||
src/crypto/common/VirtualMemory_win.cpp
|
||||
)
|
||||
|
||||
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
|
||||
elseif (XMRIG_OS_APPLE)
|
||||
list(APPEND SOURCES_OS
|
||||
src/App_unix.cpp
|
||||
src/crypto/common/VirtualMemory_unix.cpp
|
||||
)
|
||||
|
||||
@ -173,7 +171,6 @@ elseif (XMRIG_OS_APPLE)
|
||||
set(EXTRA_LIBS ${IOKIT_LIBRARY} ${CORESERVICES_LIBRARY})
|
||||
else()
|
||||
list(APPEND SOURCES_OS
|
||||
src/App_unix.cpp
|
||||
src/crypto/common/VirtualMemory_unix.cpp
|
||||
)
|
||||
|
||||
|
26
src/App.cpp
26
src/App.cpp
@ -1,13 +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 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 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
|
||||
@ -21,9 +14,15 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional permission under GNU GPL version 3 section 7
|
||||
*
|
||||
* If you modify this Program, or any covered work, by linking or combining
|
||||
* it with OpenSSL (or a modified version of that library), containing parts
|
||||
* covered by the terms of OpenSSL License and SSLeay License, the licensors
|
||||
* of this Program grant you additional permission to convey the resulting work.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
#include <uv.h>
|
||||
|
||||
@ -62,12 +61,7 @@ int xmrig::App::exec()
|
||||
|
||||
m_signals = std::make_shared<Signals>(this);
|
||||
|
||||
int rc = 0;
|
||||
if (background(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = m_controller->init();
|
||||
int rc = m_controller->init();
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
19
src/App.h
19
src/App.h
@ -1,13 +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 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 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
|
||||
@ -21,6 +14,13 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional permission under GNU GPL version 3 section 7
|
||||
*
|
||||
* If you modify this Program, or any covered work, by linking or combining
|
||||
* it with OpenSSL (or a modified version of that library), containing parts
|
||||
* covered by the terms of OpenSSL License and SSLeay License, the licensors
|
||||
* of this Program grant you additional permission to convey the resulting work.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_APP_H
|
||||
@ -60,7 +60,6 @@ protected:
|
||||
void onSignal(int signum) override;
|
||||
|
||||
private:
|
||||
bool background(int &rc);
|
||||
void close();
|
||||
|
||||
std::shared_ptr<Console> m_console;
|
||||
|
@ -1,68 +0,0 @@
|
||||
/* 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-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
|
||||
* 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 <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "core/Controller.h"
|
||||
|
||||
|
||||
bool xmrig::App::background(int &rc)
|
||||
{
|
||||
if (!m_controller->isBackground()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = fork();
|
||||
if (i < 0) {
|
||||
rc = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
rc = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
i = setsid();
|
||||
|
||||
if (i < 0) {
|
||||
LOG_ERR("setsid() failed (errno = %d)", errno);
|
||||
}
|
||||
|
||||
i = chdir("/");
|
||||
if (i < 0) {
|
||||
LOG_ERR("chdir() failed (errno = %d)", errno);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -152,18 +152,21 @@ set(SOURCES_BASE
|
||||
if (WIN32)
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_win.cpp
|
||||
src/base/kernel/Entry_win.cpp
|
||||
src/base/kernel/OS_win.cpp
|
||||
src/base/kernel/Process_win.cpp
|
||||
)
|
||||
elseif (APPLE)
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_unix.cpp
|
||||
src/base/kernel/Entry_unix.cpp
|
||||
src/base/kernel/OS_mac.cpp
|
||||
src/base/kernel/Process_unix.cpp
|
||||
)
|
||||
else()
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_unix.cpp
|
||||
src/base/kernel/Entry_unix.cpp
|
||||
src/base/kernel/OS_unix.cpp
|
||||
src/base/kernel/Process_unix.cpp
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -20,29 +20,38 @@
|
||||
#define XMRIG_ENTRY_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Process;
|
||||
|
||||
|
||||
class Entry
|
||||
{
|
||||
public:
|
||||
enum Id {
|
||||
Default,
|
||||
Usage,
|
||||
Version,
|
||||
Topo,
|
||||
Platforms
|
||||
};
|
||||
XMRIG_DISABLE_COPY_MOVE(Entry)
|
||||
|
||||
static Id get(const Process &process);
|
||||
static int exec(const Process &process, Id id);
|
||||
using Fn = std::function<bool(int &rc)>;
|
||||
using Usage = std::function<std::string()>;
|
||||
|
||||
Entry(const Usage &usage);
|
||||
|
||||
bool exec(int &rc) const;
|
||||
void add(Fn &&fn);
|
||||
|
||||
private:
|
||||
static bool background(int &rc);
|
||||
|
||||
std::vector<Fn> m_entries;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_ENTRY_H */
|
||||
#endif // XMRIG_ENTRY_H
|
||||
|
46
src/base/kernel/Entry_unix.cpp
Normal file
46
src/base/kernel/Entry_unix.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 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
|
||||
* 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 <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "base/kernel/Entry.h"
|
||||
|
||||
|
||||
bool xmrig::Entry::background(int &rc)
|
||||
{
|
||||
const int i = fork();
|
||||
if (i < 0) {
|
||||
rc = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (setsid() < 0) {
|
||||
fprintf(stderr, "setsid() failed (errno = %d)\n", errno);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -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) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 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
|
||||
@ -22,21 +16,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "core/Controller.h"
|
||||
#include "base/kernel/Entry.h"
|
||||
|
||||
|
||||
bool xmrig::App::background(int &)
|
||||
bool xmrig::Entry::background(int &)
|
||||
{
|
||||
if (!m_controller->isBackground()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HWND hcon = GetConsoleWindow();
|
||||
if (hcon) {
|
||||
ShowWindow(hcon, SW_HIDE);
|
@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 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
|
||||
@ -14,11 +14,19 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional permission under GNU GPL version 3 section 7
|
||||
*
|
||||
* If you modify this Program, or any covered work, by linking or combining
|
||||
* it with OpenSSL (or a modified version of that library), containing parts
|
||||
* covered by the terms of OpenSSL License and SSLeay License, the licensors
|
||||
* of this Program grant you additional permission to convey the resulting work.
|
||||
*/
|
||||
|
||||
#include "App.h"
|
||||
#include "base/kernel/Entry.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "core/config/usage.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -26,11 +34,17 @@ int main(int argc, char **argv)
|
||||
using namespace xmrig;
|
||||
|
||||
Process process(argc, argv);
|
||||
const Entry::Id entry = Entry::get(process);
|
||||
if (entry) {
|
||||
return Entry::exec(process, entry);
|
||||
|
||||
{
|
||||
int rc = 0;
|
||||
Entry entry(usage);
|
||||
|
||||
if (entry.exec(rc)) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
App app(&process);
|
||||
|
||||
return app.exec();
|
||||
|
Loading…
x
Reference in New Issue
Block a user