diff options
author | jimmy <jimmy@yandex-team.ru> | 2022-02-10 16:49:38 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:38 +0300 |
commit | affdafdb1fc09bf0bfc384355143ee6db9e90046 (patch) | |
tree | da80bda4720043db2e41dfd1c7fd04de32021fd3 | |
parent | 4e4faf8d95a4916a49f6674f3ff50e13799fbaa6 (diff) | |
download | ydb-affdafdb1fc09bf0bfc384355143ee6db9e90046.tar.gz |
Restoring authorship annotation for <jimmy@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/balloc/balloc.cpp | 24 | ||||
-rw-r--r-- | library/cpp/http/server/http.cpp | 16 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/json/ut/json_writer_ut.cpp | 24 | ||||
-rw-r--r-- | library/cpp/json/writer/json.cpp | 4 | ||||
-rw-r--r-- | library/cpp/json/writer/json.h | 2 | ||||
-rw-r--r-- | library/cpp/json/writer/json_ut.cpp | 4 | ||||
-rw-r--r-- | library/cpp/logger/log.cpp | 8 | ||||
-rw-r--r-- | library/cpp/messagebus/config/netaddr.cpp | 14 | ||||
-rw-r--r-- | library/cpp/messagebus/config/netaddr.h | 4 | ||||
-rw-r--r-- | library/cpp/messagebus/locator.cpp | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/message.cpp | 4 | ||||
-rw-r--r-- | library/cpp/messagebus/oldmodule/startsession.cpp | 2 | ||||
-rw-r--r-- | util/generic/bitops.h | 4 | ||||
-rw-r--r-- | util/generic/bitops_ut.cpp | 10 | ||||
-rw-r--r-- | util/system/shellcommand.cpp | 82 | ||||
-rw-r--r-- | util/system/shellcommand.h | 64 | ||||
-rw-r--r-- | util/system/shellcommand_ut.cpp | 96 |
18 files changed, 186 insertions, 186 deletions
diff --git a/library/cpp/balloc/balloc.cpp b/library/cpp/balloc/balloc.cpp index fab489db4c..2109ac4e35 100644 --- a/library/cpp/balloc/balloc.cpp +++ b/library/cpp/balloc/balloc.cpp @@ -6,7 +6,7 @@ namespace NBalloc { static constexpr size_t ALIVE_SIGNATURE = 0xaULL << 56; static constexpr size_t DISABLED_SIGNATURE = 0xbULL << 56; static constexpr size_t SIGNATURE_MASK = 0xfULL << 56; - + static constexpr size_t MINIMAL_ALIGNMENT = sizeof(NBalloc::TAllocHeader); static_assert(((MINIMAL_ALIGNMENT - 1) & MINIMAL_ALIGNMENT) == 0, "invalid BALLOC_MINIMAL_ALIGNMENT"); @@ -63,7 +63,7 @@ namespace NBalloc { } NMalloc::AbortFromCorruptedAllocator(); Y_UNREACHABLE(); - } + } static void Y_FORCE_INLINE Disable() { #if defined(_musl_) @@ -224,7 +224,7 @@ extern "C" void cfree(void* ptr) { #if defined(Y_COVER_PTR) free(ptr); #else - NBalloc::Free(ptr); + NBalloc::Free(ptr); #endif } @@ -238,7 +238,7 @@ extern "C" void* realloc(void* oldPtr, size_t newSize) { return result; } if (newSize == 0) { - NBalloc::Free(oldPtr); + NBalloc::Free(oldPtr); return nullptr; } void* newPtr = NBalloc::Malloc(newSize); @@ -249,14 +249,14 @@ extern "C" void* realloc(void* oldPtr, size_t newSize) { const size_t oldSize = header->AllocSize & ~NBalloc::SIGNATURE_MASK; const size_t signature = header->AllocSize & NBalloc::SIGNATURE_MASK; if (Y_LIKELY((signature == NBalloc::ALIVE_SIGNATURE) || (signature == NBalloc::DISABLED_SIGNATURE))) { - memcpy(newPtr, oldPtr, oldSize < newSize ? oldSize : newSize); - NBalloc::Free(oldPtr); - return newPtr; - } + memcpy(newPtr, oldPtr, oldSize < newSize ? oldSize : newSize); + NBalloc::Free(oldPtr); + return newPtr; + } NMalloc::AbortFromCorruptedAllocator(); return nullptr; } - + #if defined(Y_COVER_PTR) extern "C" void* realloc(void* oldPtr, size_t newSize) { if (!oldPtr) { @@ -282,9 +282,9 @@ extern "C" bool BallocDisabled() { return NBalloc::IsDisabled(); } -extern "C" void DisableBalloc() { - NBalloc::Disable(); -} +extern "C" void DisableBalloc() { + NBalloc::Disable(); +} extern "C" void EnableBalloc() { NBalloc::Enable(); diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd7..13e3832f53 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -197,8 +197,8 @@ public: ListenStartEvent.Reset(); try { - ListenThread.Reset(new TThread(ListenSocketFunction, this)); - ListenThread->Start(); + ListenThread.Reset(new TThread(ListenSocketFunction, this)); + ListenThread->Start(); } catch (const yexception&) { SaveErrorCode(); return false; @@ -214,9 +214,9 @@ public: Cb_->OnWait(); TGuard<TMutex> g(StopMutex); if (ListenThread) { - ListenThread->Join(); + ListenThread->Join(); ListenThread.Reset(nullptr); - } + } } void Stop() { @@ -224,9 +224,9 @@ public: TGuard<TMutex> g(StopMutex); if (ListenThread) { - ListenThread->Join(); + ListenThread->Join(); ListenThread.Reset(nullptr); - } + } while (ConnectionCount) { usleep(10000); @@ -398,7 +398,7 @@ public: } TImpl(THttpServer* parent, ICallBack* cb, TMtpQueueRef mainWorkers, TMtpQueueRef failWorkers, const TOptions& options_) - : Requests(mainWorkers) + : Requests(mainWorkers) , FailRequests(failWorkers) , Options_(options_) , Cb_(cb) @@ -442,7 +442,7 @@ public: return Options_.MaxConnections && ((size_t)GetClientCount() >= Options_.MaxConnections); } - THolder<TThread> ListenThread; + THolder<TThread> ListenThread; TPipeHandle ListenWakeupReadFd; TPipeHandle ListenWakeupWriteFd; TSystemEvent ListenStartEvent; diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..a96f4ab68b 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -329,7 +329,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { TEchoServer serverImpl(res); THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); - for (int i = 0; i < 2; ++i) { + for (int i = 0; i < 2; ++i) { UNIT_ASSERT(server.Start()); TTestRequest r(port); @@ -362,9 +362,9 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } } } - } - - server.Stop(); + } + + server.Stop(); } } diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp index ca11d34dad..2c838d243f 100644 --- a/library/cpp/json/ut/json_writer_ut.cpp +++ b/library/cpp/json/ut/json_writer_ut.cpp @@ -57,18 +57,18 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) { Y_UNIT_TEST(FormatOutput) { TString expected = "{\n \"key1\":null,\n \"key2\":\n {\n \"subkey1\":\n [\n 1,\n {\n \"subsubkey\":\"test2\"\n },\n null,\n true\n ],\n \"subkey2\":\"test\"\n }\n}"; - TJsonValue v; - v["key1"] = JSON_NULL; - v["key2"]["subkey1"].AppendValue(1); - v["key2"]["subkey1"].AppendValue(JSON_MAP)["subsubkey"] = "test2"; - v["key2"]["subkey1"].AppendValue(JSON_NULL); - v["key2"]["subkey1"].AppendValue(true); - v["key2"]["subkey2"] = "test"; - TStringStream out; - WriteJson(&out, &v, true); - UNIT_ASSERT_STRINGS_EQUAL(out.Str(), expected); - } - + TJsonValue v; + v["key1"] = JSON_NULL; + v["key2"]["subkey1"].AppendValue(1); + v["key2"]["subkey1"].AppendValue(JSON_MAP)["subsubkey"] = "test2"; + v["key2"]["subkey1"].AppendValue(JSON_NULL); + v["key2"]["subkey1"].AppendValue(true); + v["key2"]["subkey2"] = "test"; + TStringStream out; + WriteJson(&out, &v, true); + UNIT_ASSERT_STRINGS_EQUAL(out.Str(), expected); + } + Y_UNIT_TEST(SortKeys) { TString expected = "{\"a\":null,\"j\":null,\"n\":null,\"y\":null,\"z\":null}"; TJsonValue v; diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79..268722fe66 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -136,12 +136,12 @@ namespace NJsonWriter { NeedComma = false; NeedNewline = false; } - + inline void TBuf::EndValue() { if (StackTop() == JE_PAIR) { StackPop(); } - } + } TValueContext TBuf::BeginList() { NeedNewline = true; diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 0aae2531b9..e6693feb68 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -152,7 +152,7 @@ namespace NJsonWriter { TVector<EJsonEntity> Stack; bool NeedComma; - bool NeedNewline; + bool NeedNewline; const EHtmlEscapeMode EscapeMode; int IndentSpaces; bool WriteNanAsString; diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index 9980555683..0c706e9305 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -118,8 +118,8 @@ Y_UNIT_TEST_SUITE(JsonWriter) { " 1,\n" " \"hello\",\n" " {\n" - " \"abc\":3,\n" - " \"def\":4\n" + " \"abc\":3,\n" + " \"def\":4\n" " }\n" "]"; UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str()); diff --git a/library/cpp/logger/log.cpp b/library/cpp/logger/log.cpp index e1d70cc3d2..65fb603c5e 100644 --- a/library/cpp/logger/log.cpp +++ b/library/cpp/logger/log.cpp @@ -72,7 +72,7 @@ public: } TPriorityLogStream ls(priority, this); - + Printf(ls, format, args); } @@ -219,9 +219,9 @@ void TLog::ResetBackend(THolder<TLogBackend> backend) noexcept { } bool TLog::IsNullLog() const noexcept { - return Impl_->IsNullLog(); -} - + return Impl_->IsNullLog(); +} + THolder<TLogBackend> TLog::ReleaseBackend() noexcept { return Impl_->ReleaseBackend(); } diff --git a/library/cpp/messagebus/config/netaddr.cpp b/library/cpp/messagebus/config/netaddr.cpp index 962ac538e2..239c178473 100644 --- a/library/cpp/messagebus/config/netaddr.cpp +++ b/library/cpp/messagebus/config/netaddr.cpp @@ -94,7 +94,7 @@ namespace NBus { } else if (!addr) { addr.Reset(new TNetworkAddressRef(na, &*it)); } - } + } } return addr; } @@ -112,7 +112,7 @@ namespace NBus { TNetworkAddress na(TString(hostPort, portStr), port); return MakeAddress(na, requireVersion, preferVersion); } - } + } TNetAddr::TNetAddr(const char* hostPort, EIpVersion requireVersion /*= EIP_VERSION_ANY*/, EIpVersion preferVersion /*= EIP_VERSION_ANY*/) : Ptr(MakeAddress(hostPort, requireVersion, preferVersion)) @@ -120,15 +120,15 @@ namespace NBus { if (!Ptr) { ythrow TNetAddr::TError() << "cannot resolve " << hostPort << " into " << Describe(requireVersion); } - } + } TNetAddr::TNetAddr(TStringBuf host, int port, EIpVersion requireVersion /*= EIP_VERSION_ANY*/, EIpVersion preferVersion /*= EIP_VERSION_ANY*/) : Ptr(MakeAddress(host, port, requireVersion, preferVersion)) { if (!Ptr) { ythrow TNetAddr::TError() << "cannot resolve " << host << ":" << port << " into " << Describe(requireVersion); - } - } + } + } TNetAddr::TNetAddr(const TNetworkAddress& na, EIpVersion requireVersion /*= EIP_VERSION_ANY*/, EIpVersion preferVersion /*= EIP_VERSION_ANY*/) : Ptr(MakeAddress(na, requireVersion, preferVersion)) @@ -141,11 +141,11 @@ namespace NBus { TNetAddr::TNetAddr(const TNetworkAddress& na, const TAddrInfo& ai) : Ptr(new TNetworkAddressRef(na, ai)) { - } + } const sockaddr* TNetAddr::Addr() const { return Ptr->Addr(); - } + } socklen_t TNetAddr::Len() const { return Ptr->Len(); diff --git a/library/cpp/messagebus/config/netaddr.h b/library/cpp/messagebus/config/netaddr.h index b79c0cc355..395e3bcae6 100644 --- a/library/cpp/messagebus/config/netaddr.h +++ b/library/cpp/messagebus/config/netaddr.h @@ -25,8 +25,8 @@ namespace NBus { return false; } return true; - } - + } + const char* ToCString(EIpVersion); int ToAddrFamily(EIpVersion); diff --git a/library/cpp/messagebus/locator.cpp b/library/cpp/messagebus/locator.cpp index e38a35c426..1b2fc635de 100644 --- a/library/cpp/messagebus/locator.cpp +++ b/library/cpp/messagebus/locator.cpp @@ -395,7 +395,7 @@ namespace NBus { } int TBusLocator::Register(TBusService service, TBusKey start, TBusKey end, const TNetAddr& addr) { - TGuard<TMutex> G(Lock); + TGuard<TMutex> G(Lock); TServiceId serviceId = GetServiceId(service); TItems::const_iterator it; diff --git a/library/cpp/messagebus/message.cpp b/library/cpp/messagebus/message.cpp index bfa7ed8e9b..ae83c82e0f 100644 --- a/library/cpp/messagebus/message.cpp +++ b/library/cpp/messagebus/message.cpp @@ -171,8 +171,8 @@ namespace NBus { } else { GetHeader()->FlagsInternal &= ~(MESSAGE_COMPRESS_RESPONSE); } - } - + } + TString TBusIdentity::ToString() const { TStringStream ss; ss << "msg-id=" << MessageId diff --git a/library/cpp/messagebus/oldmodule/startsession.cpp b/library/cpp/messagebus/oldmodule/startsession.cpp index 7c38801d62..e65df59e62 100644 --- a/library/cpp/messagebus/oldmodule/startsession.cpp +++ b/library/cpp/messagebus/oldmodule/startsession.cpp @@ -48,7 +48,7 @@ namespace NBus { } void TBusStarter::Starter() { - TGuard<TMutex> g(ExitLock); + TGuard<TMutex> g(ExitLock); while (!Exiting) { TAutoPtr<TBusMessage> empty(new TBusMessage(0)); diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..e4ff0a1a85 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -93,7 +93,7 @@ namespace NBitOps { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctz(value); } - + inline unsigned CountTrailingZeroBitsImpl(unsigned long value) noexcept { Y_ASSERT(value); // because __builtin_ctz* have undefined result for zero. return __builtin_ctzl(value); @@ -211,7 +211,7 @@ static inline T FastClp2(T t) noexcept { using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type; return 1 + ::NBitOps::NPrivate::TClp2Helper<sizeof(TCvt) * 4, T>::Calc(static_cast<TCvt>(t)); } - + /** * Check if integer is a power of 2. */ diff --git a/util/generic/bitops_ut.cpp b/util/generic/bitops_ut.cpp index d23c2b5c27..96c3a61ab8 100644 --- a/util/generic/bitops_ut.cpp +++ b/util/generic/bitops_ut.cpp @@ -1,7 +1,7 @@ -#include "bitops.h" - +#include "bitops.h" + #include <library/cpp/testing/unittest/registar.h> - + #include <util/string/builder.h> template <typename T> @@ -46,11 +46,11 @@ static T ReverseBitsSlow(T v) { // DO_NOT_STYLE Y_UNIT_TEST_SUITE(TBitOpsTest) { Y_UNIT_TEST(TestCountTrailingZeroBits) { - TestCTZ<unsigned int>(); + TestCTZ<unsigned int>(); TestCTZ<unsigned long>(); TestCTZ<unsigned long long>(); } - + Y_UNIT_TEST(TestIsPowerOf2) { UNIT_ASSERT(!IsPowerOf2(-2)); UNIT_ASSERT(!IsPowerOf2(-1)); diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b1989b5c8c..e253cc99be 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -291,8 +291,8 @@ public: , ErrorStream(options.ErrorStream) , WatchThread(nullptr) , TerminateFlag(false) - , ClearSignalMask(options.ClearSignalMask) - , CloseAllFdsOnExec(options.CloseAllFdsOnExec) + , ClearSignalMask(options.ClearSignalMask) + , CloseAllFdsOnExec(options.CloseAllFdsOnExec) , AsyncMode(options.AsyncMode) , PollDelayMs(options.PollDelayMs) , UseShell(options.UseShell) @@ -389,25 +389,25 @@ public: // start child process void Run(); - inline void Terminate() { + inline void Terminate() { if (!!Pid && (AtomicGet(ExecutionStatus) == SHELL_RUNNING)) { bool ok = #if defined(_unix_) kill(DetachSession ? -1 * Pid : Pid, SIGTERM) == 0; - if (!ok && (errno == ESRCH) && DetachSession) { - // this could fail when called before child proc completes setsid(). - ok = kill(Pid, SIGTERM) == 0; + if (!ok && (errno == ESRCH) && DetachSession) { + // this could fail when called before child proc completes setsid(). + ok = kill(Pid, SIGTERM) == 0; kill(-Pid, SIGTERM); // between a failed kill(-Pid) and a successful kill(Pid) a grandchild could have been spawned - } + } #else TerminateProcess(Pid, 1 /* exit code */); #endif if (!ok) { ythrow TSystemError() << "cannot terminate " << Pid; } - } - } - + } + } + inline void Wait() { if (WatchThread) { WatchThread->Join(); @@ -670,24 +670,24 @@ void TShellCommand::TImpl::OnFork(TPipes& pipes, sigset_t oldmask, char* const* if (DetachSession) { setsid(); } - - // reset signal handlers from parent - struct sigaction sa; - sa.sa_handler = SIG_DFL; - sa.sa_flags = 0; - SigEmptySet(&sa.sa_mask); - for (int i = 0; i < NSIG; ++i) { - // some signals cannot be caught, so just ignore return value + + // reset signal handlers from parent + struct sigaction sa; + sa.sa_handler = SIG_DFL; + sa.sa_flags = 0; + SigEmptySet(&sa.sa_mask); + for (int i = 0; i < NSIG; ++i) { + // some signals cannot be caught, so just ignore return value sigaction(i, &sa, nullptr); - } - if (ClearSignalMask) { - SigEmptySet(&oldmask); - } - // clear / restore signal mask + } + if (ClearSignalMask) { + SigEmptySet(&oldmask); + } + // clear / restore signal mask if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { - ythrow TSystemError() << "Cannot " << (ClearSignalMask ? "clear" : "restore") << " signal mask in child"; - } - + ythrow TSystemError() << "Cannot " << (ClearSignalMask ? "clear" : "restore") << " signal mask in child"; + } + TFileHandle sIn(0); TFileHandle sOut(1); TFileHandle sErr(2); @@ -775,13 +775,13 @@ void TShellCommand::TImpl::Run() { AtomicSet(ExecutionStatus, SHELL_RUNNING); #if defined(_unix_) - // block all signals to avoid signal handler race after fork() - sigset_t oldmask, newmask; - SigFillSet(&newmask); - if (SigProcMask(SIG_SETMASK, &newmask, &oldmask) != 0) { - ythrow TSystemError() << "Cannot block all signals in parent"; - } - + // block all signals to avoid signal handler race after fork() + sigset_t oldmask, newmask; + SigFillSet(&newmask); + if (SigProcMask(SIG_SETMASK, &newmask, &oldmask) != 0) { + ythrow TSystemError() << "Cannot block all signals in parent"; + } + /* arguments holders */ TString shellArg; TVector<char*> qargv; @@ -828,11 +828,11 @@ void TShellCommand::TImpl::Run() { } else { OnFork(pipes, oldmask, qargv.data(), nullptr, FuncAfterFork); } - } else { // parent - // restore signal mask + } else { // parent + // restore signal mask if (SigProcMask(SIG_SETMASK, &oldmask, nullptr) != 0) { - ythrow TSystemError() << "Cannot restore signal mask in parent"; - } + ythrow TSystemError() << "Cannot restore signal mask in parent"; + } } Pid = pid; #else @@ -1181,10 +1181,10 @@ TShellCommand& TShellCommand::Run() { } TShellCommand& TShellCommand::Terminate() { - Impl->Terminate(); - return *this; -} - + Impl->Terminate(); + return *this; +} + TShellCommand& TShellCommand::Wait() { Impl->Wait(); return *this; diff --git a/util/system/shellcommand.h b/util/system/shellcommand.h index 8730627fe5..8498953ff6 100644 --- a/util/system/shellcommand.h +++ b/util/system/shellcommand.h @@ -67,33 +67,33 @@ public: /** * @brief clear signal mask from parent process. If true, child process - * clears the signal mask inherited from the parent process; otherwise - * child process retains the signal mask of the parent process. - * - * @param clearSignalMask true if child process should clear signal mask - * @note in default child process inherits signal mask. - * @return self - */ - inline TShellCommandOptions& SetClearSignalMask(bool clearSignalMask) { - ClearSignalMask = clearSignalMask; - return *this; - } - - /** + * clears the signal mask inherited from the parent process; otherwise + * child process retains the signal mask of the parent process. + * + * @param clearSignalMask true if child process should clear signal mask + * @note in default child process inherits signal mask. + * @return self + */ + inline TShellCommandOptions& SetClearSignalMask(bool clearSignalMask) { + ClearSignalMask = clearSignalMask; + return *this; + } + + /** * @brief set close-on-exec mode. If true, all file descriptors - * from the parent process, except stdin, stdout, stderr, will be closed - * in the child process upon exec(). - * - * @param closeAllFdsOnExec true if close-on-exec mode is needed - * @note in default close-on-exec mode is off. - * @return self - */ + * from the parent process, except stdin, stdout, stderr, will be closed + * in the child process upon exec(). + * + * @param closeAllFdsOnExec true if close-on-exec mode is needed + * @note in default close-on-exec mode is off. + * @return self + */ inline TShellCommandOptions& SetCloseAllFdsOnExec(bool closeAllFdsOnExec) { - CloseAllFdsOnExec = closeAllFdsOnExec; - return *this; - } - - /** + CloseAllFdsOnExec = closeAllFdsOnExec; + return *this; + } + + /** * @brief set asynchronous mode. If true, task will be run * in separate thread, and control will be returned immediately * @@ -443,14 +443,14 @@ public: TShellCommand& Run(); /** - * @brief terminate the execution - * @note if DetachSession is set, it terminates all procs in command's new process group - * - * @return self - */ + * @brief terminate the execution + * @note if DetachSession is set, it terminates all procs in command's new process group + * + * @return self + */ TShellCommand& Terminate(); - - /** + + /** * @brief wait until the execution is finished * * @return self diff --git a/util/system/shellcommand_ut.cpp b/util/system/shellcommand_ut.cpp index 9d849279d2..5df3277fae 100644 --- a/util/system/shellcommand_ut.cpp +++ b/util/system/shellcommand_ut.cpp @@ -229,7 +229,7 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { options.SetAsync(true); options.SetQuoteArguments(false); options.SetLatency(10); - options.SetClearSignalMask(true); + options.SetClearSignalMask(true); options.SetCloseAllFdsOnExec(true); options.SetCloseInput(false); TGuardedStringStream write; @@ -308,66 +308,66 @@ Y_UNIT_TEST_SUITE(TShellCommandTest) { cmd.Run(); sleep(1); UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); - // Async mode requires Terminate() + Wait() to send kill to child proc! - cmd.Terminate(); - cmd.Wait(); - UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); + // Async mode requires Terminate() + Wait() to send kill to child proc! + cmd.Terminate(); + cmd.Wait(); + UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); UNIT_ASSERT(cmd.GetExitCode().Defined() && -15 == cmd.GetExitCode()); } sleep(1); UNIT_ASSERT(!NFs::Exists(tmpfile)); } - // this ut is unix-only (win has no signal mask) + // this ut is unix-only (win has no signal mask) Y_UNIT_TEST(TestSignalMask) { - // block SIGTERM - int rc; - sigset_t newmask, oldmask; - SigEmptySet(&newmask); - SigAddSet(&newmask, SIGTERM); - rc = SigProcMask(SIG_SETMASK, &newmask, &oldmask); - UNIT_ASSERT(rc == 0); - + // block SIGTERM + int rc; + sigset_t newmask, oldmask; + SigEmptySet(&newmask); + SigAddSet(&newmask, SIGTERM); + rc = SigProcMask(SIG_SETMASK, &newmask, &oldmask); + UNIT_ASSERT(rc == 0); + TString tmpfile = TString("shellcommand_ut.interrupt.") + ToString(RandomNumber<ui32>()); - - TShellCommandOptions options; - options.SetAsync(true); - options.SetQuoteArguments(false); - - // child proc should not receive SIGTERM anymore - { - TShellCommand cmd("/bin/sleep", options); - // touch file only if sleep not interrupted by SIGTERM + + TShellCommandOptions options; + options.SetAsync(true); + options.SetQuoteArguments(false); + + // child proc should not receive SIGTERM anymore + { + TShellCommand cmd("/bin/sleep", options); + // touch file only if sleep not interrupted by SIGTERM cmd << " 10 & wait; [ $? == 0 ] || /usr/bin/touch " << tmpfile; - cmd.Run(); - sleep(1); - UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); - cmd.Terminate(); - cmd.Wait(); + cmd.Run(); + sleep(1); + UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); + cmd.Terminate(); + cmd.Wait(); UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus() || TShellCommand::SHELL_FINISHED == cmd.GetStatus()); - } - sleep(1); + } + sleep(1); UNIT_ASSERT(!NFs::Exists(tmpfile)); - - // child proc should receive SIGTERM - options.SetClearSignalMask(true); - { - TShellCommand cmd("/bin/sleep", options); - // touch file regardless -- it will be interrupted + + // child proc should receive SIGTERM + options.SetClearSignalMask(true); + { + TShellCommand cmd("/bin/sleep", options); + // touch file regardless -- it will be interrupted cmd << " 10 & wait; /usr/bin/touch " << tmpfile; - cmd.Run(); - sleep(1); - UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); - cmd.Terminate(); - cmd.Wait(); - UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); - } - sleep(1); + cmd.Run(); + sleep(1); + UNIT_ASSERT(TShellCommand::SHELL_RUNNING == cmd.GetStatus()); + cmd.Terminate(); + cmd.Wait(); + UNIT_ASSERT(TShellCommand::SHELL_ERROR == cmd.GetStatus()); + } + sleep(1); UNIT_ASSERT(!NFs::Exists(tmpfile)); - - // restore signal mask + + // restore signal mask rc = SigProcMask(SIG_SETMASK, &oldmask, nullptr); - UNIT_ASSERT(rc == 0); - } + UNIT_ASSERT(rc == 0); + } #else // This ut is windows-only Y_UNIT_TEST(TestStdinProperlyConstructed) { |