mirror of
https://github.com/xmrig/xmrig.git
synced 2025-03-21 22:58:49 +00:00
Added command line option --data-dir.
This commit is contained in:
parent
64650bf121
commit
8698b73036
10 changed files with 126 additions and 63 deletions
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -127,7 +127,7 @@ private:
|
||||||
return config.release();
|
return config.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.addFile(Process::location(Process::ExeLocation, "config.json"));
|
chain.addFile(Process::location(Process::DataLocation, "config.json"));
|
||||||
|
|
||||||
if (read(chain, config)) {
|
if (read(chain, config)) {
|
||||||
return config.release();
|
return config.release();
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -57,8 +57,12 @@ static std::map<String, String> variables;
|
||||||
static void createVariables()
|
static void createVariables()
|
||||||
{
|
{
|
||||||
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
||||||
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
|
variables.insert({ "XMRIG_EXE", Process::exepath() });
|
||||||
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
|
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
|
||||||
|
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
|
||||||
|
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
|
||||||
|
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
|
||||||
|
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <string>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,20 +35,75 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
static size_t getLocation(Process::Location location, char *buf, size_t max)
|
static char pathBuf[520];
|
||||||
{
|
static std::string dataDir;
|
||||||
using namespace xmrig;
|
|
||||||
|
|
||||||
|
static std::string getPath(Process::Location location)
|
||||||
|
{
|
||||||
|
size_t size = sizeof(pathBuf);
|
||||||
|
|
||||||
|
if (location == Process::DataLocation) {
|
||||||
|
if (!dataDir.empty()) {
|
||||||
|
return dataDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
location = Process::ExeLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == Process::HomeLocation) {
|
||||||
|
# if UV_VERSION_HEX >= 0x010600
|
||||||
|
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||||
|
# else
|
||||||
|
location = Process::ExeLocation;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == Process::TempLocation) {
|
||||||
|
# if UV_VERSION_HEX >= 0x010900
|
||||||
|
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||||
|
# else
|
||||||
|
location = Process::ExeLocation;
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = max;
|
|
||||||
if (location == Process::ExeLocation) {
|
if (location == Process::ExeLocation) {
|
||||||
return uv_exepath(buf, &size) < 0 ? 0 : size;
|
if (uv_exepath(pathBuf, &size) < 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto path = std::string(pathBuf, size);
|
||||||
|
const auto pos = path.rfind(Process::kDirSeparator);
|
||||||
|
|
||||||
|
if (pos != std::string::npos) {
|
||||||
|
return path.substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == Process::CwdLocation) {
|
if (location == Process::CwdLocation) {
|
||||||
return uv_cwd(buf, &size) < 0 ? 0 : size;
|
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void setDataDir(const char *path)
|
||||||
|
{
|
||||||
|
if (path == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string dir = path;
|
||||||
|
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
|
||||||
|
dir.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
|
||||||
|
dataDir = dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,46 +114,25 @@ xmrig::Process::Process(int argc, char **argv) :
|
||||||
m_arguments(argc, argv)
|
m_arguments(argc, argv)
|
||||||
{
|
{
|
||||||
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
|
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
|
||||||
|
|
||||||
|
setDataDir(m_arguments.value("--data-dir"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::String xmrig::Process::exepath()
|
||||||
|
{
|
||||||
|
size_t size = sizeof(pathBuf);
|
||||||
|
|
||||||
|
return uv_exepath(pathBuf, &size) < 0 ? "" : String(pathBuf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xmrig::String xmrig::Process::location(Location location, const char *fileName)
|
xmrig::String xmrig::Process::location(Location location, const char *fileName)
|
||||||
{
|
{
|
||||||
constexpr const size_t max = 520;
|
auto path = getPath(location);
|
||||||
|
if (path.empty() || fileName == nullptr) {
|
||||||
char *buf = new char[max]();
|
return path.c_str();
|
||||||
size_t size = getLocation(location, buf, max);
|
|
||||||
|
|
||||||
if (size == 0) {
|
|
||||||
delete [] buf;
|
|
||||||
|
|
||||||
return String();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName == nullptr) {
|
return (path + kDirSeparator + fileName).c_str();
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (location == ExeLocation) {
|
|
||||||
char *p = strrchr(buf, kDirSeparator);
|
|
||||||
|
|
||||||
if (p == nullptr) {
|
|
||||||
delete [] buf;
|
|
||||||
|
|
||||||
return String();
|
|
||||||
}
|
|
||||||
|
|
||||||
size = static_cast<size_t>(p - buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size + strlen(fileName) + 2) >= max) {
|
|
||||||
delete [] buf;
|
|
||||||
|
|
||||||
return String();
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[size] = kDirSeparator;
|
|
||||||
strcpy(buf + size + 1, fileName);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -37,7 +37,10 @@ class Process
|
||||||
public:
|
public:
|
||||||
enum Location {
|
enum Location {
|
||||||
ExeLocation,
|
ExeLocation,
|
||||||
CwdLocation
|
CwdLocation,
|
||||||
|
DataLocation,
|
||||||
|
HomeLocation,
|
||||||
|
TempLocation
|
||||||
};
|
};
|
||||||
|
|
||||||
# ifdef WIN32
|
# ifdef WIN32
|
||||||
|
@ -48,6 +51,7 @@ public:
|
||||||
|
|
||||||
Process(int argc, char **argv);
|
Process(int argc, char **argv);
|
||||||
|
|
||||||
|
static String exepath();
|
||||||
static String location(Location location, const char *fileName = nullptr);
|
static String location(Location location, const char *fileName = nullptr);
|
||||||
|
|
||||||
inline const Arguments &arguments() const { return m_arguments; }
|
inline const Arguments &arguments() const { return m_arguments; }
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
DaemonKey = 1018,
|
DaemonKey = 1018,
|
||||||
DaemonPollKey = 1019,
|
DaemonPollKey = 1019,
|
||||||
SelfSelectKey = 1028,
|
SelfSelectKey = 1028,
|
||||||
|
DataDirKey = 1035,
|
||||||
|
|
||||||
// xmrig common
|
// xmrig common
|
||||||
CPUPriorityKey = 1021,
|
CPUPriorityKey = 1021,
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -52,6 +52,23 @@ bool xmrig::Arguments::hasArg(const char *name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *xmrig::Arguments::value(const char *key) const
|
||||||
|
{
|
||||||
|
const size_t size = m_data.size();
|
||||||
|
if (size < 3) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 1; i < size - 1; ++i) {
|
||||||
|
if (m_data[i] == key) {
|
||||||
|
return m_data[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void xmrig::Arguments::add(const char *arg)
|
void xmrig::Arguments::add(const char *arg)
|
||||||
{
|
{
|
||||||
if (arg == nullptr) {
|
if (arg == nullptr) {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -41,6 +41,7 @@ public:
|
||||||
Arguments(int argc, char **argv);
|
Arguments(int argc, char **argv);
|
||||||
|
|
||||||
bool hasArg(const char *name) const;
|
bool hasArg(const char *name) const;
|
||||||
|
const char *value(const char *key) const;
|
||||||
|
|
||||||
inline char **argv() const { return m_argv; }
|
inline char **argv() const { return m_argv; }
|
||||||
inline const std::vector<String> &data() const { return m_data; }
|
inline const std::vector<String> &data() const { return m_data; }
|
||||||
|
|
|
@ -89,6 +89,7 @@ static const option options[] = {
|
||||||
{ "cpu-no-yield", 0, nullptr, IConfig::YieldKey },
|
{ "cpu-no-yield", 0, nullptr, IConfig::YieldKey },
|
||||||
{ "verbose", 0, nullptr, IConfig::VerboseKey },
|
{ "verbose", 0, nullptr, IConfig::VerboseKey },
|
||||||
{ "proxy", 1, nullptr, IConfig::ProxyKey },
|
{ "proxy", 1, nullptr, IConfig::ProxyKey },
|
||||||
|
{ "data-dir", 1, nullptr, IConfig::DataDirKey },
|
||||||
# ifdef XMRIG_FEATURE_TLS
|
# ifdef XMRIG_FEATURE_TLS
|
||||||
{ "tls", 0, nullptr, IConfig::TlsKey },
|
{ "tls", 0, nullptr, IConfig::TlsKey },
|
||||||
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },
|
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },
|
||||||
|
|
Loading…
Reference in a new issue