diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | 6170310e8721e225f64ddabf7a7358253d7a1249 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/system | |
parent | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (diff) | |
download | ydb-6170310e8721e225f64ddabf7a7358253d7a1249.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/system')
-rw-r--r-- | util/system/hostname.cpp | 82 | ||||
-rw-r--r-- | util/system/hostname.h | 4 | ||||
-rw-r--r-- | util/system/hostname_ut.cpp | 4 | ||||
-rw-r--r-- | util/system/spin_wait.cpp | 2 |
4 files changed, 46 insertions, 46 deletions
diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 56a322a790..386f646d6b 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -1,7 +1,7 @@ #include <util/memory/tempbuf.h> #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <util/network/ip.h> +#include <util/network/ip.h> #if defined(_unix_) #include <unistd.h> @@ -31,24 +31,24 @@ namespace { TString HostName; }; - - struct TFQDNHostNameHolder { - inline TFQDNHostNameHolder() { - struct addrinfo hints; - struct addrinfo* ais{nullptr}; - char buf[1024]; - - memset(buf, 0, sizeof(buf)); - int res = gethostname(buf, sizeof(buf) - 1); - if (res) { - ythrow TSystemError() << "can not get hostname"; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_CANONNAME; - res = getaddrinfo(buf, nullptr, &hints, &ais); - if (res) { + + struct TFQDNHostNameHolder { + inline TFQDNHostNameHolder() { + struct addrinfo hints; + struct addrinfo* ais{nullptr}; + char buf[1024]; + + memset(buf, 0, sizeof(buf)); + int res = gethostname(buf, sizeof(buf) - 1); + if (res) { + ythrow TSystemError() << "can not get hostname"; + } + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + res = getaddrinfo(buf, nullptr, &hints, &ais); + if (res) { if (res != EAI_NONAME) { ythrow TSystemError() << "can not get FQDN (return code is " << res << ", hostname is \"" << buf << "\")"; } @@ -56,12 +56,12 @@ namespace { } else { FQDNHostName = ais->ai_canonname; freeaddrinfo(ais); - } - FQDNHostName.to_lower(); - } - + } + FQDNHostName.to_lower(); + } + TString FQDNHostName; - }; + }; } const TString& HostName() { @@ -71,26 +71,26 @@ const TString& HostName() { const char* GetHostName() { return HostName().data(); } - + const TString& FQDNHostName() { - return (Singleton<TFQDNHostNameHolder>())->FQDNHostName; -} - -const char* GetFQDNHostName() { + return (Singleton<TFQDNHostNameHolder>())->FQDNHostName; +} + +const char* GetFQDNHostName() { return FQDNHostName().data(); -} - +} + bool IsFQDN(const TString& name) { TString absName = name; if (!absName.EndsWith('.')) { - absName.append("."); - } - - try { - // ResolveHost() can't be used since it is ipv4-only, port is not important - TNetworkAddress addr(absName, 0); + absName.append("."); + } + + try { + // ResolveHost() can't be used since it is ipv4-only, port is not important + TNetworkAddress addr(absName, 0); } catch (const TNetworkResolutionError&) { - return false; - } - return true; -} + return false; + } + return true; +} diff --git a/util/system/hostname.h b/util/system/hostname.h index e25e1d0c05..0839ee2b59 100644 --- a/util/system/hostname.h +++ b/util/system/hostname.h @@ -4,7 +4,7 @@ const char* GetHostName(); const TString& HostName(); - -const char* GetFQDNHostName(); + +const char* GetFQDNHostName(); const TString& FQDNHostName(); bool IsFQDN(const TString& name); diff --git a/util/system/hostname_ut.cpp b/util/system/hostname_ut.cpp index 03eacb8aeb..fb1cb7dde4 100644 --- a/util/system/hostname_ut.cpp +++ b/util/system/hostname_ut.cpp @@ -6,11 +6,11 @@ Y_UNIT_TEST_SUITE(THostNameTest) { Y_UNIT_TEST(Test1) { UNIT_ASSERT(*GetHostName() != '?'); } - + Y_UNIT_TEST(TestFQDN) { UNIT_ASSERT(*GetFQDNHostName() != '?'); } - + Y_UNIT_TEST(TestIsFQDN) { const auto x = GetFQDNHostName(); diff --git a/util/system/spin_wait.cpp b/util/system/spin_wait.cpp index 88ce48d7b6..e27045e74f 100644 --- a/util/system/spin_wait.cpp +++ b/util/system/spin_wait.cpp @@ -17,7 +17,7 @@ static inline T RandomizeSleepTime(T t) noexcept { //arbitrary values #define MIN_SLEEP_TIME 500 -#define MAX_SPIN_COUNT 0x7FF +#define MAX_SPIN_COUNT 0x7FF TSpinWait::TSpinWait() noexcept : T(MIN_SLEEP_TIME) |