Browse Source

Update Process class and use APP_ID instead of hardcoded config name for #1925

pull/1926/head
XMRig 4 years ago
parent
commit
eb95d0339e
No known key found for this signature in database GPG Key ID: 446A53638BE94409
  1. 1
      CHANGELOG.md
  2. 3
      src/base/base.cmake
  3. 8
      src/base/kernel/Base.cpp
  4. 44
      src/base/kernel/Process.cpp
  5. 23
      src/base/kernel/Process.h
  6. 34
      src/base/kernel/Process_unix.cpp
  7. 33
      src/base/kernel/Process_win.cpp

1
CHANGELOG.md

@ -2,6 +2,7 @@
- **Added [online benchmark](https://xmrig.com/benchmark) mode for sharing results.**
- Added new command line options: `--submit`, ` --verify=ID`, ` --seed=SEED`, `--hash=HASH`.
- [#1912](https://github.com/xmrig/xmrig/pull/1912) Fixed MSR kernel module warning with new Linux kernels.
- [#1925](https://github.com/xmrig/xmrig/pull/1925) Add checking for config files in user home directory.
- Added vendor to ARM CPUs name and added `"arch"` field to API.
- Removed legacy CUDA plugin API.

3
src/base/base.cmake

@ -123,16 +123,19 @@ if (WIN32)
set(SOURCES_OS
src/base/io/json/Json_win.cpp
src/base/kernel/Platform_win.cpp
src/base/kernel/Process_win.cpp
)
elseif (APPLE)
set(SOURCES_OS
src/base/io/json/Json_unix.cpp
src/base/kernel/Platform_mac.cpp
src/base/kernel/Process_unix.cpp
)
else()
set(SOURCES_OS
src/base/io/json/Json_unix.cpp
src/base/kernel/Platform_unix.cpp
src/base/kernel/Process_unix.cpp
)
endif()

8
src/base/kernel/Base.cpp

@ -41,6 +41,7 @@
#include "base/net/tools/NetBuffer.h"
#include "core/config/Config.h"
#include "core/config/ConfigTransform.h"
#include "version.h"
#ifdef HAVE_SYSLOG_H
@ -132,19 +133,16 @@ private:
}
chain.addFile(Process::location(Process::DataLocation, "config.json"));
if (read(chain, config)) {
return config.release();
}
chain.addFile(Process::location(Process::HomeLocation, ".xmrig.json"));
chain.addFile(Process::location(Process::HomeLocation, "." APP_ID ".json"));
if (read(chain, config)) {
return config.release();
}
chain.addFile(Process::location(Process::HomeLocation, ".config/xmrig.json"));
chain.addFile(Process::location(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json"));
if (read(chain, config)) {
return config.release();
}

44
src/base/kernel/Process.cpp

@ -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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 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
@ -29,7 +23,21 @@
#include "base/kernel/Process.h"
#include "3rdparty/fmt/core.h"
#include "base/tools/Chrono.h"
#include "version.h"
#ifdef XMRIG_OS_WIN
# ifdef _MSC_VER
# include <direct.h>
# define MKDIR(path) _mkdir(path.c_str());
# else
# define MKDIR(path) mkdir((path).c_str());
# endif
#else
# define MKDIR(path) mkdir(path.c_str(), 0700);
#endif
namespace xmrig {
@ -73,7 +81,7 @@ static std::string getPath(Process::Location location)
}
const auto path = std::string(pathBuf, size);
const auto pos = path.rfind(Process::kDirSeparator);
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
if (pos != std::string::npos) {
return path.substr(0, pos);
@ -116,15 +124,17 @@ xmrig::Process::Process(int argc, char **argv) :
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
setDataDir(m_arguments.value("--data-dir", "-d"));
}
# ifdef XMRIG_SHARED_DATADIR
if (dataDir.empty()) {
dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, location(HomeLocation));
MKDIR(dataDir);
int xmrig::Process::pid()
{
# if UV_VERSION_HEX >= 0x011200
return uv_os_getpid();
# else
return 0;
dataDir += APP_KIND;
MKDIR(dataDir);
uv_chdir(dataDir.c_str());
}
# endif
}
@ -154,5 +164,5 @@ xmrig::String xmrig::Process::location(Location location, const char *fileName)
return path.c_str();
}
return (path + kDirSeparator + fileName).c_str();
return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str();
}

23
src/base/kernel/Process.h

@ -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-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 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
@ -29,6 +23,13 @@
#include "base/tools/Arguments.h"
#ifdef WIN32
# define XMRIG_DIR_SEPARATOR "\\"
#else
# define XMRIG_DIR_SEPARATOR "/"
#endif
namespace xmrig {
@ -43,12 +44,6 @@ public:
TempLocation
};
# ifdef WIN32
constexpr const static char kDirSeparator = '\\';
# else
constexpr const static char kDirSeparator = '/';
# endif
Process(int argc, char **argv);
static int pid();

34
src/base/kernel/Process_unix.cpp

@ -0,0 +1,34 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 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 <uv.h>
#include <unistd.h>
#include "base/kernel/Process.h"
int xmrig::Process::pid()
{
# if UV_VERSION_HEX >= 0x011200
return uv_os_getpid();
# else
return getpid();
# endif
}

33
src/base/kernel/Process_win.cpp

@ -0,0 +1,33 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 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 <uv.h>
#include "base/kernel/Process.h"
int xmrig::Process::pid()
{
# if UV_VERSION_HEX >= 0x011200
return uv_os_getpid();
# else
return GetCurrentProcessId();
# endif
}
Loading…
Cancel
Save