mirror of
https://github.com/resiprocate/resiprocate.git
synced 2026-01-12 00:05:02 +08:00
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:
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user