rutil/Log: Selectively enable FQDN resolution upon Logger initialization

FQDN resolution uses `getaddrinfo` with `AI_CANONNAME` and may cause DNS
lookup in some cases. If the DNS server is slow or unresponsive, the
logger initialization hangs until the system network timeout occurs.

Disable FQDN resolution and use local hostname `mHostname` for JSON CEE
logging by default.

A new compilation option `USE_FQDN_FOR_JSON_CEE_HOSTNAME` is introduced
to re-enable FQDN resolution upon Logger initialization if required.
This commit is contained in:
Mykhailo Popivniak
2025-12-18 17:29:50 +02:00
parent 947b8654b2
commit 7fe9084ed7
3 changed files with 14 additions and 8 deletions

View File

@@ -114,6 +114,7 @@ option(WITH_SSL "Link against SSL libraries" TRUE)
option(USE_POPT "Link against POPT libraries" TRUE)
option(USE_SIGCOMP "Use OpenSigComp" FALSE)
option(USE_FMT "Link against fmt library" FALSE)
option(USE_FQDN_FOR_JSON_CEE_HOSTNAME "Use canonical hostnames in JSON CEE log output" FALSE)
option(VERSIONED_SONAME "Include Major.Minor version in SONAME" TRUE)
option(ENABLE_ANDROID "Enable Android build" FALSE)
option(USE_IPV6 "Enable IPv6" TRUE)

View File

@@ -15,6 +15,7 @@
#cmakedefine ENABLE_LOG_REPOSITORY_DETAILS
#cmakedefine RESIPROCATE_GIT_ID "@RESIPROCATE_GIT_ID@"
#cmakedefine RESIPROCATE_BRANCH_NAME "@RESIPROCATE_BRANCH_NAME@"
#cmakedefine USE_FQDN_FOR_JSON_CEE_HOSTNAME
#cmakedefine RESIP_BIG_ENDIAN
#cmakedefine REPRO_BUILD_REV "@REPRO_BUILD_REV@"
#cmakedefine REPRO_BUILD_HOST "localhost"

View File

@@ -321,28 +321,32 @@ Log::initialize(Type type, Level level, const Data& appName,
mHostname = buffer;
}
#ifdef USE_FQDN_FOR_JSON_CEE_HOSTNAME
// Note: for Windows users, you must call initNetwork to initialize WinSock before calling
// Log::initialize in order for getaddrinfo to be successful
{
struct addrinfo hints;
struct addrinfo* info = nullptr;
int gai_result;
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC; /*either IPV4 or IPV6 */
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
if ((gai_result = getaddrinfo (buffer, 0, &hints, &info)) != 0) {
mFqdn = mHostname;
} else if (info == NULL) {
mFqdn = mHostname;
} else {
if (getaddrinfo(buffer, 0, &hints, &info) == 0
&& info != nullptr)
{
mFqdn = info->ai_canonname;
freeaddrinfo(info);
}
else
{
mFqdn = mHostname;
}
freeaddrinfo (info);
}
#else
mFqdn = mHostname;
#endif
}