From 9606d683ae55744e443be64d2572368c56b1bd87 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 11 Jul 2021 13:28:35 +0300 Subject: [PATCH] generic: make use of QHostInfo::localHostName() and QHostInfo::localDomainName() Signed-off-by: Ivailo Monev --- kdm/ConfigureChecks.cmake | 2 -- kdm/config-kdm.h.cmake | 3 -- kdm/kfrontend/CMakeLists.txt | 11 +++++-- kdm/kfrontend/themer/kdmlabel.cpp | 22 +++++++------- libs/ksysguard/processcore/processes_openbsd_p.cpp | 2 +- plasma/applets/kickoff/CMakeLists.txt | 34 ++++++++++++++++++---- plasma/applets/kickoff/ui/launcher.cpp | 10 ++----- 7 files changed, 50 insertions(+), 34 deletions(-) diff --git a/kdm/ConfigureChecks.cmake b/kdm/ConfigureChecks.cmake index 939b7564..95f3869e 100644 --- a/kdm/ConfigureChecks.cmake +++ b/kdm/ConfigureChecks.cmake @@ -12,8 +12,6 @@ check_include_files(termios.h HAVE_TERMIOS_H) check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H) check_symbol_exists(sysinfo "sys/sysinfo.h" HAVE_SYSINFO) -check_symbol_exists(systeminfo "sys/systeminfo.h" HAVE_SYS_SYSTEMINFO) -check_symbol_exists(getdomainname "unistd.h" HAVE_GETDOMAINNAME) check_function_exists(initgroups HAVE_INITGROUPS) check_function_exists(mkstemp HAVE_MKSTEMP) diff --git a/kdm/config-kdm.h.cmake b/kdm/config-kdm.h.cmake index 9d656a64..d508f59a 100644 --- a/kdm/config-kdm.h.cmake +++ b/kdm/config-kdm.h.cmake @@ -100,9 +100,6 @@ /* Define to 1 if `sin_len' is member of `struct sockaddr_in'. */ #cmakedefine HAVE_STRUCT_SOCKADDR_IN_SIN_LEN -/* Define if you have getdomainname */ -#cmakedefine HAVE_GETDOMAINNAME 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_TERMIO_H 1 diff --git a/kdm/kfrontend/CMakeLists.txt b/kdm/kfrontend/CMakeLists.txt index 4cf69637..ae40002e 100644 --- a/kdm/kfrontend/CMakeLists.txt +++ b/kdm/kfrontend/CMakeLists.txt @@ -69,12 +69,17 @@ endif (WITH_KDM_XCONSOLE) macro_add_file_dependencies(kdmconfig.h ${confci}) macro_add_file_dependencies(kdmconfig.cpp ${confci}) add_executable(kdm_greet ${kdm_greet_SRCS}) -target_link_libraries(kdm_greet ${KDE4_KDEUI_LIBS} ${QT_QTXML_LIBRARY} ${X11_X11_LIB}) +target_link_libraries(kdm_greet + ${KDE4_KDEUI_LIBS} + ${QT_QTXML_LIBRARY} + ${QT_QTNETWORK_LIBRARY} + ${X11_X11_LIB} +) if (X11_XTest_FOUND) - target_link_libraries(kdm_greet ${X11_XTest_LIB}) + target_link_libraries(kdm_greet ${X11_XTest_LIB}) endif (X11_XTest_FOUND) if (WITH_KDM_XCONSOLE) - target_link_libraries(kdm_greet ${KDE4_KPTY_LIBS}) + target_link_libraries(kdm_greet ${KDE4_KPTY_LIBS}) endif (WITH_KDM_XCONSOLE) add_dependencies(kdm_greet ConfigCi) diff --git a/kdm/kfrontend/themer/kdmlabel.cpp b/kdm/kfrontend/themer/kdmlabel.cpp index 435d08bc..d171732a 100644 --- a/kdm/kfrontend/themer/kdmlabel.cpp +++ b/kdm/kfrontend/themer/kdmlabel.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -43,9 +44,6 @@ #include #include -#if !defined(HAVE_GETDOMAINNAME) && defined(HAVE_SYS_SYSTEMINFO) -# include -#endif KdmLabel::KdmLabel(QObject *parent, const QDomNode &node) : KdmItem(parent, node) @@ -313,14 +311,16 @@ KdmLabel::expandMacro(QChar chr, QStringList &ret) expandoMap['s'] = QString::fromLocal8Bit(uts.sysname); expandoMap['r'] = QString::fromLocal8Bit(uts.release); expandoMap['m'] = QString::fromLocal8Bit(uts.machine); - char buf[256]; - buf[sizeof(buf) - 1] = '\0'; - expandoMap['h'] = gethostname(buf, sizeof(buf) - 1) ? "localhost" : QString::fromLocal8Bit(buf); -#ifdef HAVE_GETDOMAINNAME - expandoMap['o'] = getdomainname(buf, sizeof(buf) - 1) ? "localdomain" : QString::fromLocal8Bit(buf); -#elif defined(HAVE_SYS_SYSTEMINFO) - expandoMap['o'] = (unsigned)sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf)) > sizeof(buf) ? "localdomain" : QString::fromLocal8Bit(buf); -#endif + QString hostname = QHostInfo::localHostName(); + if (hostname.isEmpty()) { + hostname = QLatin1String("localhost"); + } + QString domainname = QHostInfo::localDomainName(); + if (domainname.isEmpty()) { + domainname = QLatin1String("localdomain"); + } + expandoMap['h'] = hostname; + expandoMap['o'] = domainname; } QHash::const_iterator mi = expandoMap.constFind(chr); if (mi != expandoMap.constEnd()) { diff --git a/libs/ksysguard/processcore/processes_openbsd_p.cpp b/libs/ksysguard/processcore/processes_openbsd_p.cpp index 6fc238db..2e7d97ca 100644 --- a/libs/ksysguard/processcore/processes_openbsd_p.cpp +++ b/libs/ksysguard/processcore/processes_openbsd_p.cpp @@ -224,7 +224,7 @@ QSet ProcessesLocal::getAllPids( ) bool ProcessesLocal::sendSignal(long pid, int sig) { - if (:;kill((pid_t)pid, sig) == -1) { + if (::kill((pid_t)pid, sig) == -1) { // kill failed return false; } diff --git a/plasma/applets/kickoff/CMakeLists.txt b/plasma/applets/kickoff/CMakeLists.txt index c8c5ef8b..29c68168 100644 --- a/plasma/applets/kickoff/CMakeLists.txt +++ b/plasma/applets/kickoff/CMakeLists.txt @@ -50,9 +50,20 @@ set(Applet_SRCS ) kde4_add_plugin(plasma_applet_launcher ${Applet_SRCS}) -target_link_libraries(plasma_applet_launcher ${KDE4_PLASMA_LIBS} ${Kickoff_LIBS} kickoff) -install(TARGETS plasma_applet_launcher DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) -install(FILES applet/plasma-applet-launcher.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) +target_link_libraries(plasma_applet_launcher + ${KDE4_PLASMA_LIBS} + ${QT_QTNETWORK_LIBRARY} + ${Kickoff_LIBS} + kickoff +) +install( + TARGETS plasma_applet_launcher + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) +install( + FILES applet/plasma-applet-launcher.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) ####################################################################################### # Kickoff Simple KMenu Plasma Applet @@ -63,9 +74,20 @@ set(SimpleApplet_SRCS simpleapplet/simpleapplet.cpp ) kde4_add_plugin(plasma_applet_simplelauncher ${SimpleApplet_SRCS}) -target_link_libraries(plasma_applet_simplelauncher ${KDE4_KCMUTILS_LIBS} ${KDE4_PLASMA_LIBS} ${Kickoff_LIBS} kickoff) -install(TARGETS plasma_applet_simplelauncher DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}) -install(FILES simpleapplet/plasma-applet-simplelauncher.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}) +target_link_libraries(plasma_applet_simplelauncher + ${KDE4_KCMUTILS_LIBS} + ${KDE4_PLASMA_LIBS} + ${Kickoff_LIBS} + kickoff +) +install( + TARGETS plasma_applet_simplelauncher + DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} +) +install( + FILES simpleapplet/plasma-applet-simplelauncher.desktop + DESTINATION ${KDE4_SERVICES_INSTALL_DIR} +) # Kickoff Standalone Test Application #IF (CMAKE_BUILD_TYPE MATCHES Debug) diff --git a/plasma/applets/kickoff/ui/launcher.cpp b/plasma/applets/kickoff/ui/launcher.cpp index 56c17da7..65873f6d 100644 --- a/plasma/applets/kickoff/ui/launcher.cpp +++ b/plasma/applets/kickoff/ui/launcher.cpp @@ -21,9 +21,6 @@ #include "ui/launcher.h" -// System -#include - // Qt #include #include @@ -34,6 +31,7 @@ #include #include #include +#include // KDE #include @@ -552,11 +550,7 @@ void Launcher::init() // Add status information footer d->footer = new QWidget; - char hostname[256]; - hostname[0] = '\0'; - if (!gethostname(hostname, sizeof(hostname))) { - hostname[sizeof(hostname)-1] = '\0'; - } + const QString hostname = QHostInfo::localHostName(); KUser user; QString fullName = user.property(KUser::FullName).toString(); QString labelText; -- 2.11.0