aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlad-savinov <vlad-savinov@yandex-team.ru>2022-02-10 16:51:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:51:46 +0300
commitaa109021468e8848c0c4f46894b8cc74d390d4c3 (patch)
tree04fb88139bef69d6d03cbe56dfae1ab64d3f95e5
parentcf6e6821eefccdbf1103566edb4a651fe0388df7 (diff)
downloadydb-aa109021468e8848c0c4f46894b8cc74d390d4c3.tar.gz
Restoring authorship annotation for <vlad-savinov@yandex-team.ru>. Commit 1 of 2.
-rw-r--r--util/system/shellcommand.cpp18
-rw-r--r--util/system/shellcommand.h26
-rw-r--r--util/system/shellcommand_ut.cpp52
3 files changed, 48 insertions, 48 deletions
diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp
index b1989b5c8c..6dae056736 100644
--- a/util/system/shellcommand.cpp
+++ b/util/system/shellcommand.cpp
@@ -226,7 +226,7 @@ private:
TShellCommandOptions::TUserOptions User;
THashMap<TString, TString> Environment;
int Nice = 0;
- std::function<void()> FuncAfterFork = {};
+ std::function<void()> FuncAfterFork = {};
struct TProcessInfo {
TImpl* Parent;
@@ -274,7 +274,7 @@ private:
};
#if defined(_unix_)
- void OnFork(TPipes& pipes, sigset_t oldmask, char* const* argv, char* const* envp, const std::function<void()>& afterFork) const;
+ void OnFork(TPipes& pipes, sigset_t oldmask, char* const* argv, char* const* envp, const std::function<void()>& afterFork) const;
#else
void StartProcess(TPipes& pipes);
#endif
@@ -306,7 +306,7 @@ public:
, User(options.User)
, Environment(options.Environment)
, Nice(options.Nice)
- , FuncAfterFork(options.FuncAfterFork)
+ , FuncAfterFork(options.FuncAfterFork)
{
if (InputStream) {
// TODO change usages to call SetInputStream instead of directly assigning to InputStream
@@ -665,7 +665,7 @@ TString TShellCommand::TImpl::GetQuotedCommand() const {
}
#if defined(_unix_)
-void TShellCommand::TImpl::OnFork(TPipes& pipes, sigset_t oldmask, char* const* argv, char* const* envp, const std::function<void()>& afterFork) const {
+void TShellCommand::TImpl::OnFork(TPipes& pipes, sigset_t oldmask, char* const* argv, char* const* envp, const std::function<void()>& afterFork) const {
try {
if (DetachSession) {
setsid();
@@ -734,9 +734,9 @@ void TShellCommand::TImpl::OnFork(TPipes& pipes, sigset_t oldmask, char* const*
// Don't verify Nice() call - it does not work properly with WSL https://github.com/Microsoft/WSL/issues/1838
::Nice(Nice);
}
- if (afterFork) {
- afterFork();
- }
+ if (afterFork) {
+ afterFork();
+ }
if (envp == nullptr) {
execvp(argv[0], argv);
@@ -824,9 +824,9 @@ void TShellCommand::TImpl::Run() {
ythrow TSystemError() << "Cannot fork";
} else if (pid == 0) { // child
if (envp.size() != 0) {
- OnFork(pipes, oldmask, qargv.data(), envp.data(), FuncAfterFork);
+ OnFork(pipes, oldmask, qargv.data(), envp.data(), FuncAfterFork);
} else {
- OnFork(pipes, oldmask, qargv.data(), nullptr, FuncAfterFork);
+ OnFork(pipes, oldmask, qargv.data(), nullptr, FuncAfterFork);
}
} else { // parent
// restore signal mask
diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h
index 8730627fe5..093610c1d2 100644
--- a/util/system/shellcommand.h
+++ b/util/system/shellcommand.h
@@ -55,7 +55,7 @@ public:
, OutputStream(nullptr)
, ErrorStream(nullptr)
, Nice(0)
- , FuncAfterFork(std::function<void()>())
+ , FuncAfterFork(std::function<void()>())
{
}
@@ -237,17 +237,17 @@ public:
}
/**
- * @brief specifies pure function to be called in the child process after fork, before calling execve
- * @note currently ignored on windows
- * @param function function to be called after fork
- * @return self
- */
- inline TShellCommandOptions& SetFuncAfterFork(const std::function<void()>& function) {
- FuncAfterFork = function;
- return *this;
- }
-
- /**
+ * @brief specifies pure function to be called in the child process after fork, before calling execve
+ * @note currently ignored on windows
+ * @param function function to be called after fork
+ * @return self
+ */
+ inline TShellCommandOptions& SetFuncAfterFork(const std::function<void()>& function) {
+ FuncAfterFork = function;
+ return *this;
+ }
+
+ /**
* @brief create a pipe for child input
* Write end of the pipe will be accessible via TShellCommand::GetInputHandle
*
@@ -322,7 +322,7 @@ public:
int Nice = 0;
static const size_t DefaultSyncPollDelay = 1000; // ms
- std::function<void()> FuncAfterFork = {};
+ std::function<void()> FuncAfterFork = {};
};
/**
diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp
index 9d849279d2..b1de429a01 100644
--- a/util/system/shellcommand_ut.cpp
+++ b/util/system/shellcommand_ut.cpp
@@ -15,7 +15,7 @@
#include <util/stream/str.h>
#include <util/stream/mem.h>
#include <util/string/strip.h>
-#include <util/folder/tempdir.h>
+#include <util/folder/tempdir.h>
#if defined(_win_)
#define NL "\r\n"
@@ -465,29 +465,29 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) {
UNIT_ASSERT(options.OutputMode == TShellCommandOptions::HANDLE_STREAM);
UNIT_ASSERT(options.ErrorMode == TShellCommandOptions::HANDLE_STREAM);
}
- Y_UNIT_TEST(TestForkCallback) {
- TString tmpFile = TString("shellcommand_ut.test_for_callback.txt");
- TFsPath cwd(::NFs::CurrentWorkingDirectory());
- const TString tmpFilePath = cwd.Child(tmpFile);
-
- const TString text = "test output";
- auto afterForkCallback = [&tmpFilePath, &text]() -> void {
- TFixedBufferFileOutput out(tmpFilePath);
- out << text;
- };
-
- TShellCommandOptions options;
- options.SetFuncAfterFork(afterForkCallback);
-
- const TString command = "ls";
- TShellCommand cmd(command, options);
- cmd.Run();
-
- UNIT_ASSERT(NFs::Exists(tmpFilePath));
-
- TUnbufferedFileInput fileOutput(tmpFilePath);
- TString firstLine = fileOutput.ReadLine();
-
- UNIT_ASSERT_VALUES_EQUAL(firstLine, text);
- }
+ Y_UNIT_TEST(TestForkCallback) {
+ TString tmpFile = TString("shellcommand_ut.test_for_callback.txt");
+ TFsPath cwd(::NFs::CurrentWorkingDirectory());
+ const TString tmpFilePath = cwd.Child(tmpFile);
+
+ const TString text = "test output";
+ auto afterForkCallback = [&tmpFilePath, &text]() -> void {
+ TFixedBufferFileOutput out(tmpFilePath);
+ out << text;
+ };
+
+ TShellCommandOptions options;
+ options.SetFuncAfterFork(afterForkCallback);
+
+ const TString command = "ls";
+ TShellCommand cmd(command, options);
+ cmd.Run();
+
+ UNIT_ASSERT(NFs::Exists(tmpFilePath));
+
+ TUnbufferedFileInput fileOutput(tmpFilePath);
+ TString firstLine = fileOutput.ReadLine();
+
+ UNIT_ASSERT_VALUES_EQUAL(firstLine, text);
+ }
}