diff options
author | qwerty <qwerty@yandex-team.ru> | 2022-02-10 16:49:25 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:25 +0300 |
commit | ca6b8a0150d5ee4cc8fb804d1285d9c32fb4fe88 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/system | |
parent | 34e37ee57f5837a8da2fdfaccaac9bbe6c7f02ba (diff) | |
download | ydb-ca6b8a0150d5ee4cc8fb804d1285d9c32fb4fe88.tar.gz |
Restoring authorship annotation for <qwerty@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/backtrace.cpp | 2 | ||||
-rw-r--r-- | util/system/daemon.cpp | 126 | ||||
-rw-r--r-- | util/system/daemon.h | 10 | ||||
-rw-r--r-- | util/system/defaults.h | 2 | ||||
-rw-r--r-- | util/system/error.cpp | 2 | ||||
-rw-r--r-- | util/system/progname.cpp | 8 | ||||
-rw-r--r-- | util/system/progname.h | 4 |
7 files changed, 77 insertions, 77 deletions
diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp index d726803ac3..b77fe58fb1 100644 --- a/util/system/backtrace.cpp +++ b/util/system/backtrace.cpp @@ -73,7 +73,7 @@ namespace { TBackTraceContext* bt = (TBackTraceContext*)h; if (bt->cnt != 0) { - bt->sym[bt->cnt - 1] = (void*)_Unwind_GetIP(c); + bt->sym[bt->cnt - 1] = (void*)_Unwind_GetIP(c); } if (bt->cnt == bt->size) { diff --git a/util/system/daemon.cpp b/util/system/daemon.cpp index 8f58813c52..130e6c8f45 100644 --- a/util/system/daemon.cpp +++ b/util/system/daemon.cpp @@ -18,7 +18,7 @@ using namespace NDaemonMaker; static bool Fork(EParent parent) { - pid_t pid = fork(); + pid_t pid = fork(); if (pid > 0) { int status = 0; @@ -30,11 +30,11 @@ static bool Fork(EParent parent) { return true; } } else if (pid < 0) { - ythrow TSystemError() << "Cannot fork"; + ythrow TSystemError() << "Cannot fork"; } if (setsid() < 0) { - ythrow TSystemError() << "Cannot setsid"; + ythrow TSystemError() << "Cannot setsid"; } pid = fork(); @@ -42,24 +42,24 @@ static bool Fork(EParent parent) { if (pid > 0) { _exit(0); } else if (pid < 0) { - ythrow TSystemError() << "Cannot second fork"; + ythrow TSystemError() << "Cannot second fork"; } return false; } -#endif - +#endif + static void CloseFromToExcept(int from, int to, const int* except) { (void)from; (void)to; (void)except; -#ifdef _unix_ +#ifdef _unix_ int mfd = NSystemInfo::MaxOpenFiles(); - for (int s = from; s < mfd && (to == -1 || s < to); s++) { + for (int s = from; s < mfd && (to == -1 || s < to); s++) { for (const int* ex = except; *ex >= 0; ++ex) { if (s == *ex) { - goto dontclose; + goto dontclose; } } while (close(s) == -1) { @@ -71,98 +71,98 @@ static void CloseFromToExcept(int from, int to, const int* except) { } } dontclose:; - } + } #endif /* _unix_ */ } - + bool NDaemonMaker::MakeMeDaemon(ECloseDescriptors cd, EStdIoDescriptors iod, EChDir chd, EParent parent) { (void)cd; (void)iod; (void)chd; -#ifdef _unix_ +#ifdef _unix_ if (Fork(parent)) { return true; } - + if (chd == chdirRoot) { if (chdir("/")) { ythrow TSystemError() << "chdir(\"/\") failed"; } } - + int fd[4] = {-1, -1, -1, -1}; switch (iod) { - case openYandexStd: - fd[0] = open("yandex.stdin", O_RDONLY); + case openYandexStd: + fd[0] = open("yandex.stdin", O_RDONLY); if (fd[0] < 0) { - ythrow TSystemError() << "Cannot open 'yandex.stdin'"; + ythrow TSystemError() << "Cannot open 'yandex.stdin'"; } - fd[1] = open("yandex.stdout", O_WRONLY | O_APPEND | O_CREAT, 660); + fd[1] = open("yandex.stdout", O_WRONLY | O_APPEND | O_CREAT, 660); if (fd[1] < 0) { - ythrow TSystemError() << "Cannot open 'yandex.stdout'"; + ythrow TSystemError() << "Cannot open 'yandex.stdout'"; } - fd[2] = open("yandex.stderr", O_WRONLY | O_APPEND | O_CREAT, 660); + fd[2] = open("yandex.stderr", O_WRONLY | O_APPEND | O_CREAT, 660); if (fd[2] < 0) { - ythrow TSystemError() << "Cannot open 'yandex.stderr'"; + ythrow TSystemError() << "Cannot open 'yandex.stderr'"; } - break; - case openDevNull: - fd[0] = open("/dev/null", O_RDWR, 0); - break; - case openNone: - break; - default: - ythrow yexception() << "Unknown open descriptors mode: " << (int)iod; - } - - const int except[4] = { - fd[0], - fd[1], - fd[2], + break; + case openDevNull: + fd[0] = open("/dev/null", O_RDWR, 0); + break; + case openNone: + break; + default: + ythrow yexception() << "Unknown open descriptors mode: " << (int)iod; + } + + const int except[4] = { + fd[0], + fd[1], + fd[2], -1}; if (closeAll == cd) { - CloseFromToExcept(0, -1, except); + CloseFromToExcept(0, -1, except); } else if (closeStdIoOnly == cd) { - CloseFromToExcept(0, 3, except); + CloseFromToExcept(0, 3, except); } else { - ythrow yexception() << "Unknown close descriptors mode: " << (int)cd; + ythrow yexception() << "Unknown close descriptors mode: " << (int)cd; } - + switch (iod) { - case openYandexStd: - /* Assuming that open(2) acquires fds in order. */ - dup2(fd[0], STDIN_FILENO); + case openYandexStd: + /* Assuming that open(2) acquires fds in order. */ + dup2(fd[0], STDIN_FILENO); if (fd[0] > 2) { - close(fd[0]); + close(fd[0]); } - dup2(fd[1], STDOUT_FILENO); + dup2(fd[1], STDOUT_FILENO); if (fd[1] > 2) { - close(fd[1]); + close(fd[1]); } - dup2(fd[2], STDERR_FILENO); + dup2(fd[2], STDERR_FILENO); if (fd[2] > 2) { - close(fd[2]); + close(fd[2]); } - break; - case openDevNull: - dup2(fd[0], STDIN_FILENO); - dup2(fd[0], STDOUT_FILENO); - dup2(fd[0], STDERR_FILENO); + break; + case openDevNull: + dup2(fd[0], STDIN_FILENO); + dup2(fd[0], STDOUT_FILENO); + dup2(fd[0], STDERR_FILENO); if (fd[0] > 2) { - close(fd[0]); + close(fd[0]); } - break; - default: - break; - } + break; + default: + break; + } return false; #else return true; -#endif -} - -void NDaemonMaker::CloseFrom(int fd) { +#endif +} + +void NDaemonMaker::CloseFrom(int fd) { static const int except[1] = {-1}; - CloseFromToExcept(fd, -1, except); -} + CloseFromToExcept(fd, -1, except); +} diff --git a/util/system/daemon.h b/util/system/daemon.h index 01a5d319ce..b00793b9c9 100644 --- a/util/system/daemon.h +++ b/util/system/daemon.h @@ -12,11 +12,11 @@ namespace NDaemonMaker { openYandexStd }; - enum EChDir { - chdirNone = 0, - chdirRoot - }; - + enum EChDir { + chdirNone = 0, + chdirRoot + }; + enum EParent { callExitFromParent = 0, returnFromParent diff --git a/util/system/defaults.h b/util/system/defaults.h index 7633fc7dd1..dcd7abea38 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -143,7 +143,7 @@ constexpr bool Y_IS_DEBUG_BUILD = true; #define Y_STRINGIZE(X) UTIL_PRIVATE_STRINGIZE_AUX(X) #define UTIL_PRIVATE_STRINGIZE_AUX(X) #X - + #if defined(__COUNTER__) #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __COUNTER__) #endif diff --git a/util/system/error.cpp b/util/system/error.cpp index a38abb0263..f778ec42cb 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -19,7 +19,7 @@ void ClearLastSystemError() { #if defined(_win_) SetLastError(0); -#else +#else errno = 0; #endif } diff --git a/util/system/progname.cpp b/util/system/progname.cpp index 6b0ed56bff..2c29119320 100644 --- a/util/system/progname.cpp +++ b/util/system/progname.cpp @@ -5,7 +5,7 @@ #include <util/generic/singleton.h> static const char* Argv0; - + namespace { struct TProgramNameHolder { inline TProgramNameHolder() @@ -20,7 +20,7 @@ namespace { const TString& GetProgramName() { return Singleton<TProgramNameHolder>()->ProgName; } - + void SetProgramName(const char* argv0) { - Argv0 = argv0; -} + Argv0 = argv0; +} diff --git a/util/system/progname.h b/util/system/progname.h index 75788605e5..e5e2a0eee2 100644 --- a/util/system/progname.h +++ b/util/system/progname.h @@ -3,11 +3,11 @@ #include <util/generic/fwd.h> void SetProgramName(const char* argv0); - + #define SAVE_PROGRAM_NAME \ do { \ SetProgramName(argv[0]); \ } while (0) - + /// guaranted return the same immutable instance of TString const TString& GetProgramName(); |