From 1cabe0f8be124cf67efdd4059cdb11decb1cd900 Mon Sep 17 00:00:00 2001 From: MikhailBurdukov Date: Wed, 20 Nov 2024 15:37:30 +0000 Subject: [PATCH] Review --- src/Common/ShellCommand.cpp | 2 +- src/Common/ShellCommand.h | 6 +++--- src/Common/ShellCommandsHolder.cpp | 20 +++++++------------- src/Common/ShellCommandsHolder.h | 2 +- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Common/ShellCommand.cpp b/src/Common/ShellCommand.cpp index bef7b7a0e9d..bd2c95629fe 100644 --- a/src/Common/ShellCommand.cpp +++ b/src/Common/ShellCommand.cpp @@ -61,7 +61,7 @@ LoggerPtr ShellCommand::getLogger() ShellCommand::~ShellCommand() { - if (is_manualy_terminated) + if (do_not_terminate) return; if (wait_called) diff --git a/src/Common/ShellCommand.h b/src/Common/ShellCommand.h index 6a4a8328b82..7aff975efa6 100644 --- a/src/Common/ShellCommand.h +++ b/src/Common/ShellCommand.h @@ -77,9 +77,9 @@ public: return wait_called; } - void setManuallyTerminated() + void setDoNotTerminate() { - is_manualy_terminated = true; + do_not_terminate = true; } /// Run the command using /bin/sh -c. @@ -111,7 +111,7 @@ private: pid_t pid; Config config; bool wait_called = false; - bool is_manualy_terminated = false; + bool do_not_terminate = false; ShellCommand(pid_t pid_, int & in_fd_, int & out_fd_, int & err_fd_, const Config & config); diff --git a/src/Common/ShellCommandsHolder.cpp b/src/Common/ShellCommandsHolder.cpp index 1354cd2e4b1..6cc44f27fa7 100644 --- a/src/Common/ShellCommandsHolder.cpp +++ b/src/Common/ShellCommandsHolder.cpp @@ -11,17 +11,11 @@ ShellCommandsHolder & ShellCommandsHolder::instance() return instance; } -LoggerPtr ShellCommandsHolder::getLogger() -{ - return ::getLogger("ShellCommandsHolder"); -} - - void ShellCommandsHolder::removeCommand(pid_t pid) { std::lock_guard lock(mutex); bool is_erased = shell_commands.erase(pid); - LOG_TRACE(getLogger(), "Try to erase command with the pid {}, is_erased: {}", pid, is_erased); + LOG_TRACE(log, "Try to erase command with the pid {}, is_erased: {}", pid, is_erased); } void ShellCommandsHolder::addCommand(std::unique_ptr command) @@ -30,30 +24,30 @@ void ShellCommandsHolder::addCommand(std::unique_ptr command) pid_t command_pid = command->getPid(); if (command->waitIfProccesTerminated()) { - LOG_TRACE(getLogger(), "Pid {} already finished. Do not insert it.", command_pid); + LOG_TRACE(log, "Pid {} already finished. Do not insert it.", command_pid); return; } auto [iterator, is_inserted] = shell_commands.try_emplace(command_pid, std::move(command)); if (is_inserted) { - LOG_TRACE(getLogger(), "Inserted the command with pid {}", command_pid); + LOG_TRACE(log, "Inserted the command with pid {}", command_pid); return; } if (iterator->second->isWaitCalled()) { iterator->second = std::move(command); - LOG_TRACE(getLogger(), "Replaced the command with pid {}", command_pid); + LOG_TRACE(log, "Replaced the command with pid {}", command_pid); return; } - /// We got two active ShellCommand with the same pid. /// Probably it is a bug, will try to replace the old shell command with a new one. + chassert(false); - LOG_WARNING(getLogger(), "The PID already presented in active shell commands, will try to replace with a new one."); + LOG_WARNING(log, "The PID already presented in active shell commands, will try to replace with a new one."); - iterator->second->setManuallyTerminated(); + iterator->second->setDoNotTerminate(); iterator->second = std::move(command); } } diff --git a/src/Common/ShellCommandsHolder.h b/src/Common/ShellCommandsHolder.h index 70934365768..2326d4042bc 100644 --- a/src/Common/ShellCommandsHolder.h +++ b/src/Common/ShellCommandsHolder.h @@ -26,7 +26,7 @@ private: std::mutex mutex; ShellCommands shell_commands TSA_GUARDED_BY(mutex); - static LoggerPtr getLogger(); + LoggerPtr log = getLogger("ShellCommandsHolder"); }; }