From 494386d8f5633696868f0cfb9e5b6499aefcd20e Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 24 Dec 2020 22:51:26 +0000 Subject: [PATCH] implement QHostInfo::localHostName() via getdomainname() instead of resolv Signed-off-by: Ivailo Monev --- CMakeLists.txt | 16 +------- README | 3 +- cmake/modules/FindResolv.cmake | 55 -------------------------- src/core/global/qconfig.h.cmake | 2 +- src/network/CMakeLists.txt | 11 ------ src/network/kernel/qhostinfo_unix.cpp | 56 ++++++++------------------- 6 files changed, 19 insertions(+), 124 deletions(-) delete mode 100644 cmake/modules/FindResolv.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c95306c5..8d4c90432 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,9 +128,6 @@ add_feature_info(postgresql WITH_POSTGRESQL "build PostgreSQL support") option(WITH_MYSQL "Build MySQL database plugin" ON) add_feature_info(mysql WITH_MYSQL "build MySQL support") -option(WITH_RESOLV "Build resolv support" ON) -add_feature_info(resolv WITH_RESOLV "build resolv support") - option(WITH_INTL "Build Intl support" ON) add_feature_info(intl WITH_INTL "build Intl support") @@ -242,14 +239,6 @@ set_package_properties(Sqlite PROPERTIES TYPE REQUIRED ) -find_package(Resolv) -set_package_properties(Resolv PROPERTIES - PURPOSE "Required for domain resolving support" - DESCRIPTION "Standard C library specific resolv implementation" - URL "" - TYPE RECOMMENDED -) - find_package(JPEG) set_package_properties(JPEG PROPERTIES PURPOSE "JPEG format handler" @@ -383,6 +372,7 @@ katie_check_function(kevent "sys/event.h") katie_check_function(pipe2 "unistd.h") katie_check_function(accept4 "sys/socket.h") katie_check_function(paccept "sys/socket.h") +katie_check_function(getdomainname "unistd.h") katie_check_struct(tm tm_gmtoff "time.h") katie_check_struct(tm tm_zone "time.h") katie_check_struct(sockaddr_ll sll_addr "netpacket/packet.h") @@ -464,10 +454,6 @@ if(NOT WITH_CUPS OR NOT CUPS_FOUND) katie_definition(-DQT_NO_CUPS) endif() -if(NOT WITH_RESOLV OR NOT RESOLV_FOUND) - katie_definition(-DQT_NO_RESOLV) -endif() - if(NOT WITH_JPEG OR NOT JPEG_FOUND) katie_definition(-DQT_NO_IMAGEFORMAT_JPEG) endif() diff --git a/README b/README index dd4969530..edcb0d40b 100644 --- a/README +++ b/README @@ -14,7 +14,7 @@ There are several things you should be aware before considering Katie: - QMake build system replaced with CMake - zlib, zstd, OpenSSL, PCRE, Freetype, ICU, X11, libpng and SQLite are required for building - - OpenSSL, D-Bus, CUPS and resolv must be linked to during build + - OpenSSL, D-Bus and CUPS must be linked to during build - QtUiTools is build as shared library by default - moc, uic, rcc, etc. are linked to components - updated bundled Harfbuzz from upstream (not Harfbuzz-NG) @@ -51,7 +51,6 @@ There are several things you should be aware before considering Katie: - building with OpenSSL v1.1+ is possible - building with IODBC instead of unixODBC is possible - building with LTO is possible and supported, if the toolchain can handle it - - building without resolv is possible - alternative libc implementations support - additional text codecs via ICU converter - Unicode v5.0+ characters and partial scripts support diff --git a/cmake/modules/FindResolv.cmake b/cmake/modules/FindResolv.cmake deleted file mode 100644 index 8b52702b0..000000000 --- a/cmake/modules/FindResolv.cmake +++ /dev/null @@ -1,55 +0,0 @@ -# - Try to find resolv -# Once done this will define -# -# RESOLV_FOUND - system has resolv -# RESOLV_INCLUDES - the resolv include directory -# RESOLV_LIBRARIES - the libraries needed to use resolv -# RESOLV_THREAD_SAFE - resolv has thread-safe functions (res_ninit/res_nclose) -# -# Copyright (c) 2016-2020, Ivailo Monev, -# -# Redistribution and use is allowed according to the terms of the BSD license. - -# resolv does not provide pkg-config files - -include(CMakePushCheckState) -include(FindPackageHandleStandardArgs) - -set(RESOLV_NAMES c resolv) - -find_path(RESOLV_INCLUDES - NAMES resolv.h - HINTS $ENV{RESOLVDIR}/include -) - -set(RESOLV_LIBRARIES) -foreach(name ${RESOLV_NAMES}) - if(NOT RESOLV_LIBRARIES) - unset(HAVE_res_ninit CACHE) - cmake_reset_check_state() - set(CMAKE_REQUIRED_LIBRARIES ${name}) - katie_check_defined(res_ninit "netinet/in.h;resolv.h") - cmake_reset_check_state() - if(NOT HAVE_res_ninit) - unset(HAVE_res_init CACHE) - cmake_reset_check_state() - set(CMAKE_REQUIRED_LIBRARIES ${name}) - katie_check_defined(res_init "netinet/in.h;resolv.h") - cmake_reset_check_state() - endif() - if(HAVE_res_ninit OR HAVE_res_init) - find_library(RESOLV_LIBRARIES - NAMES ${name} - HINTS $ENV{RESOLVDIR}/lib - ) - endif() - endif() -endforeach() - -find_package_handle_standard_args(Resolv - REQUIRED_VARS RESOLV_LIBRARIES RESOLV_INCLUDES -) - -set(RESOLV_THREAD_SAFE "${HAVE_res_ninit}" CACHE BOOL "resolv has thread-safe functions (res_ninit/res_nclose)") - -mark_as_advanced(RESOLV_INCLUDES RESOLV_LIBRARIES RESOLV_THREAD_SAFE) diff --git a/src/core/global/qconfig.h.cmake b/src/core/global/qconfig.h.cmake index 48fd4c37a..228ae6554 100644 --- a/src/core/global/qconfig.h.cmake +++ b/src/core/global/qconfig.h.cmake @@ -108,6 +108,7 @@ #define QT_NO_NAS #define QT_NO_IMAGEFORMAT_MNG #define QT_NO_TEXTODFWRITER +#define QT_NO_RESOLV // Not supported, used to bootstrap #cmakedefine QT_NO_QOBJECT @@ -140,7 +141,6 @@ #cmakedefine QT_NO_FONTCONFIG #cmakedefine QT_NO_IMAGEFORMAT_JPEG #cmakedefine QT_NO_IMAGEFORMAT_TIFF -#cmakedefine QT_NO_RESOLV #cmakedefine QT_NO_SESSIONMANAGER #cmakedefine QT_NO_TRANSLATION #cmakedefine QT_NO_XCURSOR diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 33e266122..a80aa3a3e 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -202,17 +202,6 @@ set(NETWORK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ssl/qsslsocket_openssl.cpp ) -if(WITH_RESOLV AND RESOLV_FOUND) - set(EXTRA_NETWORK_LIBS - ${EXTRA_NETWORK_LIBS} - ${RESOLV_LIBRARIES} - ) - include_directories(${RESOLV_INCLUDES}) - if(RESOLV_THREAD_SAFE) - add_definitions(-DQT_HAVE_RES_NINIT) - endif() -endif() - katie_generate_misc("${NETWORK_HEADERS}" QtNetwork) katie_generate_public("${NETWORK_PUBLIC_HEADERS}" QtNetwork) katie_generate_package(KtNetwork "KtCore") diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index 10c85ec1a..9628d9799 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -47,10 +47,6 @@ #include #include -#ifndef QT_NO_RESOLV -#include -#endif // QT_NO_RESOLV - QT_BEGIN_NAMESPACE #if !defined(QT_HAVE_GETADDRINFO) @@ -67,11 +63,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) hostName.toLatin1().constData()); #endif -#ifndef QT_NO_RESOLV - // If res_init is available, poll it. - res_init(); -#endif // QT_NO_RESOLV - QHostAddress address; if (address.setAddress(hostName)) { // Reverse lookup @@ -272,43 +263,28 @@ QString QHostInfo::localHostName() static long size_max = sysconf(_SC_HOST_NAME_MAX); if (size_max == -1) size_max = _POSIX_HOST_NAME_MAX; - char gethostbuffer[size_max]; - if (Q_LIKELY(::gethostname(gethostbuffer, size_max) == 0)) { - gethostbuffer[size_max - 1] = '\0'; - return QString::fromLocal8Bit(gethostbuffer); + char gethostbuff[size_max]; + if (Q_LIKELY(::gethostname(gethostbuff, size_max) == 0)) { + gethostbuff[size_max - 1] = '\0'; + return QString::fromLocal8Bit(gethostbuff); } return QString(); } QString QHostInfo::localDomainName() { -//support both thread-safe and unsafe versions -#if !defined(QT_NO_RESOLV) && defined(QT_HAVE_RES_NINIT) - // using thread-safe version - struct __res_state state; - res_ninit(&state); - QString domainName = QUrl::fromAce(state.defdname); - if (domainName.isEmpty()) - domainName = QUrl::fromAce(state.dnsrch[0]); - res_nclose(&state); - - return domainName; -#elif !defined(QT_NO_RESOLV) - // using thread-unsafe version - -#if !defined(QT_HAVE_GETADDRINFO) - // We have to call res_init to be sure that _res was initialized - // So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too - QMutexLocker locker(getHostByNameMutex()); -#endif - res_init(); - QString domainName = QUrl::fromAce(_res.defdname); - if (domainName.isEmpty()) - domainName = QUrl::fromAce(_res.dnsrch[0]); - return domainName; +#if defined(QT_HAVE_GETDOMAINNAME) + // thread-safe + static long size_max = sysconf(_SC_HOST_NAME_MAX); + if (size_max == -1) + size_max = _POSIX_HOST_NAME_MAX; + char getdomainbuff[size_max]; + if (Q_LIKELY(::getdomainname(getdomainbuff, size_max) == 0)) { + return QUrl::fromAce(getdomainbuff); + } + return QString(); #else - - // nothing worked, try doing it by ourselves: + // doing it by ourselves #if defined(_PATH_RESCONF) QFile resolvconf(QFile::decodeName(_PATH_RESCONF)); #else @@ -335,7 +311,7 @@ QString QHostInfo::localDomainName() // return the fallen-back-to searched domain return domainName; -#endif // QT_NO_RESOLV +#endif // QT_HAVE_GETDOMAINNAME } QT_END_NAMESPACE