Module: check_mk
Branch: master
Commit: 394b01c0208657bd87233220dfcb0c56667d9e47
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=394b01c0208657…
Author: Sergey Kipnis <sk(a)mathias-kettner.de>
Date: Wed Mar 27 16:15:12 2019 +0100
[CMK-1791] - handle leak preparation
- code clean and refactor
Change-Id: I22e2d6ec803723594ed4e275cdbeec257a2acaf3
---
agents/wnx/include/tools/_misc.h | 3 +--
agents/wnx/include/tools/_raii.h | 9 +++++++++
agents/wnx/src/common/cfg_info.h | 13 +++++++------
agents/wnx/src/common/cmdline_info.h | 1 -
agents/wnx/src/engine/cma_core.h | 15 ++++-----------
5 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/agents/wnx/include/tools/_misc.h b/agents/wnx/include/tools/_misc.h
index fa7c762..26e3504 100644
--- a/agents/wnx/include/tools/_misc.h
+++ b/agents/wnx/include/tools/_misc.h
@@ -96,8 +96,7 @@ inline void WideLower(std::wstring& WideStr) {
// auto vector_of string
template <typename... Args>
std::vector<std::wstring> ConstructVectorWstring(Args&&... args) {
- using namespace std;
- vector<wstring> cfg_files;
+ std::vector<std::wstring> cfg_files;
static_assert((std::is_constructible_v<std::wstring, Args&> &&
...));
(cfg_files.emplace_back(args), ...);
return cfg_files;
diff --git a/agents/wnx/include/tools/_raii.h b/agents/wnx/include/tools/_raii.h
index 6603484..e7e671e 100644
--- a/agents/wnx/include/tools/_raii.h
+++ b/agents/wnx/include/tools/_raii.h
@@ -67,4 +67,13 @@ struct InternalScopeGuard {
std::lock_guard<decltype(Mutex)> Mutex##CmkAutoLock(Mutex);
#endif
+// For Ranging experimental
+namespace cma {
+template <typename I, typename F>
+void for_each(I IterObject, F Fn) {
+ ::std::for_each(std::begin(IterObject), std::end(IterObject), Fn);
+}
+
+} // namespace cma
+
#endif // ___RAAI_H
diff --git a/agents/wnx/src/common/cfg_info.h b/agents/wnx/src/common/cfg_info.h
index de0828b..1533f1e 100644
--- a/agents/wnx/src/common/cfg_info.h
+++ b/agents/wnx/src/common/cfg_info.h
@@ -115,15 +115,15 @@ inline const std::wstring
kSolutionUnitTestsFolderName(L"unit_test");
inline const std::wstring kSolutionConfigTestFilesFolderName(L"config");
inline std::filesystem::path MakePathToUnitTestFiles(std::wstring Root) {
- using namespace std::filesystem;
- path r = Root;
+ namespace fs = std::filesystem;
+ fs::path r = Root;
r = r / kSolutionTestFilesFolderName / kSolutionUnitTestsFolderName;
return r.lexically_normal();
}
inline std::filesystem::path MakePathToConfigTestFiles(std::wstring Root) {
- using namespace std::filesystem;
- path r = Root;
+ namespace fs = std::filesystem;
+ fs::path r = Root;
r = r / kSolutionTestFilesFolderName / kSolutionConfigTestFilesFolderName;
return r.lexically_normal();
}
@@ -146,8 +146,9 @@ constexpr const wchar_t* kBakery = L"bakery"; //
owned by site
constexpr const wchar_t* kState = L"state"; // owned by plugins
constexpr const wchar_t* kPluginConfig = L"config"; // owned by plugins
-constexpr const wchar_t* kSpool = L"spool"; // owned by user/sys plugins
-constexpr const wchar_t* kTemp = L"temp"; // owned by user plugins
+constexpr const wchar_t* kSpool = L"spool"; // owned by user/sys plugins
+constexpr const wchar_t* kTemp = L"temp"; // owned by user plugins
+constexpr const wchar_t* kUpdate = L"update"; // owned by agent
}; // namespace dirs
namespace envs {
diff --git a/agents/wnx/src/common/cmdline_info.h b/agents/wnx/src/common/cmdline_info.h
index 209dea0..a83ab09 100644
--- a/agents/wnx/src/common/cmdline_info.h
+++ b/agents/wnx/src/common/cmdline_info.h
@@ -26,7 +26,6 @@ constexpr const wchar_t* kTimeout = L"timeout";
constexpr wchar_t kSplitter = L':';
inline auto ParseExeCommandLine(int argc, wchar_t const* argv[]) {
- using namespace std;
auto make_error_answer = [](int ErrorCode) -> auto {
return make_tuple(ErrorCode, std::wstring(), std::wstring(),
std::wstring());
diff --git a/agents/wnx/src/engine/cma_core.h b/agents/wnx/src/engine/cma_core.h
index 490c556..3f1b504 100644
--- a/agents/wnx/src/engine/cma_core.h
+++ b/agents/wnx/src/engine/cma_core.h
@@ -212,10 +212,9 @@ public:
uint32_t startedProcId() const { return proc_id_; }
bool appendResult(HANDLE Handle, std::vector<char>& Buf) {
- using namespace std;
if (Buf.size() == 0) return true;
- lock_guard lk(lock_);
+ std::lock_guard lk(lock_);
{
auto h = process_->getStdioRead();
if (h && h == Handle) {
@@ -227,8 +226,7 @@ public:
}
bool storeExitCode(uint32_t Pid, uint32_t Code) {
- using namespace std;
- lock_guard lk(lock_);
+ std::lock_guard lk(lock_);
if (process_->trySetExitCode(Pid, Code)) return true;
return false;
}
@@ -263,8 +261,8 @@ public:
// returns true if all processes ended
// returns false on timeout or break;
bool waitForEnd(std::chrono::milliseconds Timeout, bool KillWhatLeft) {
+ using namespace std::chrono;
if (stop_set_) return false;
- using namespace std;
ON_OUT_OF_SCOPE(readWhatLeft());
constexpr std::chrono::milliseconds kGrane = 250ms;
@@ -273,7 +271,7 @@ public:
for (;;) {
auto ready = checkProcessExit(waiting_processes);
{
- auto buf = readFromHandle<vector<char>>(read_handle);
+ auto buf = readFromHandle<std::vector<char>>(read_handle);
if (buf.size()) appendResult(read_handle, buf);
}
@@ -374,8 +372,6 @@ private:
// updates object
// returns list of active processes
bool checkProcessExit(const uint32_t Process) {
- using namespace std;
-
auto h = OpenProcess(
PROCESS_QUERY_LIMITED_INFORMATION, // not supported on XP
FALSE, Process);
@@ -416,9 +412,6 @@ private:
}
bool isExecIn(const std::filesystem::path& FileExec) {
- using namespace std::filesystem;
- using namespace std;
-
// now check for duplicates:
auto cmd_line = BuildCommand(FileExec);
return exec_ == cmd_line;