QDnsLookup: fix "Resolver functions not found" error on FreeBSD
The current code only tries to load the required functions from LIBRESOLV_SO (if defined) and resolv, but on FreeBSD they are in libc: https://www.freebsd.org/cgi/man.cgi?query=res_query&sektion=3&apropos=0&manpath=freebsd This commit changes the code so that, after failing to load the non-existent libraries, it attempts to load the functions with dlsym() using the special handle RTLD_DEFAULT, which searches for the specified symbol in the loaded libraries. Task-number: QTBUG-74844 Change-Id: If97aaae233cabbfa01c30d26d9a7fb01ec3ff5c2 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
82ad4be4a2
commit
8eeb5150ed
@ -38,7 +38,11 @@ qtConfig(dnslookup) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
!integrity:qtConfig(dnslookup): SOURCES += kernel/qdnslookup_unix.cpp
|
!integrity:qtConfig(dnslookup) {
|
||||||
|
SOURCES += kernel/qdnslookup_unix.cpp
|
||||||
|
qtConfig(dlopen): QMAKE_USE_PRIVATE += libdl
|
||||||
|
}
|
||||||
|
|
||||||
SOURCES += kernel/qhostinfo_unix.cpp
|
SOURCES += kernel/qhostinfo_unix.cpp
|
||||||
|
|
||||||
qtConfig(linux-netlink): SOURCES += kernel/qnetworkinterface_linux.cpp
|
qtConfig(linux-netlink): SOURCES += kernel/qnetworkinterface_linux.cpp
|
||||||
|
@ -59,6 +59,10 @@
|
|||||||
# include <gnu/lib-names.h>
|
# include <gnu/lib-names.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(Q_OS_FREEBSD) || QT_CONFIG(dlopen)
|
||||||
|
# include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -87,6 +91,18 @@ struct QDnsLookupStateDeleter
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static QFunctionPointer resolveSymbol(QLibrary &lib, const char *sym)
|
||||||
|
{
|
||||||
|
if (lib.isLoaded())
|
||||||
|
return lib.resolve(sym);
|
||||||
|
|
||||||
|
#if defined(RTLD_DEFAULT) && (defined(Q_OS_FREEBSD) || QT_CONFIG(dlopen))
|
||||||
|
return reinterpret_cast<QFunctionPointer>(dlsym(RTLD_DEFAULT, sym));
|
||||||
|
#else
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static bool resolveLibraryInternal()
|
static bool resolveLibraryInternal()
|
||||||
{
|
{
|
||||||
QLibrary lib;
|
QLibrary lib;
|
||||||
@ -96,31 +112,30 @@ static bool resolveLibraryInternal()
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
lib.setFileName(QLatin1String("resolv"));
|
lib.setFileName(QLatin1String("resolv"));
|
||||||
if (!lib.load())
|
lib.load();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand"));
|
local_dn_expand = dn_expand_proto(resolveSymbol(lib, "__dn_expand"));
|
||||||
if (!local_dn_expand)
|
if (!local_dn_expand)
|
||||||
local_dn_expand = dn_expand_proto(lib.resolve("dn_expand"));
|
local_dn_expand = dn_expand_proto(resolveSymbol(lib, "dn_expand"));
|
||||||
|
|
||||||
local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose"));
|
local_res_nclose = res_nclose_proto(resolveSymbol(lib, "__res_nclose"));
|
||||||
if (!local_res_nclose)
|
if (!local_res_nclose)
|
||||||
local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose"));
|
local_res_nclose = res_nclose_proto(resolveSymbol(lib, "res_9_nclose"));
|
||||||
if (!local_res_nclose)
|
if (!local_res_nclose)
|
||||||
local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
|
local_res_nclose = res_nclose_proto(resolveSymbol(lib, "res_nclose"));
|
||||||
|
|
||||||
local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit"));
|
local_res_ninit = res_ninit_proto(resolveSymbol(lib, "__res_ninit"));
|
||||||
if (!local_res_ninit)
|
if (!local_res_ninit)
|
||||||
local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit"));
|
local_res_ninit = res_ninit_proto(resolveSymbol(lib, "res_9_ninit"));
|
||||||
if (!local_res_ninit)
|
if (!local_res_ninit)
|
||||||
local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
|
local_res_ninit = res_ninit_proto(resolveSymbol(lib, "res_ninit"));
|
||||||
|
|
||||||
local_res_nquery = res_nquery_proto(lib.resolve("__res_nquery"));
|
local_res_nquery = res_nquery_proto(resolveSymbol(lib, "__res_nquery"));
|
||||||
if (!local_res_nquery)
|
if (!local_res_nquery)
|
||||||
local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery"));
|
local_res_nquery = res_nquery_proto(resolveSymbol(lib, "res_9_nquery"));
|
||||||
if (!local_res_nquery)
|
if (!local_res_nquery)
|
||||||
local_res_nquery = res_nquery_proto(lib.resolve("res_nquery"));
|
local_res_nquery = res_nquery_proto(resolveSymbol(lib, "res_nquery"));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user