From c1caca5927736b3003c914c09898972168c5880f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 23 Feb 2021 11:01:13 +0200 Subject: [PATCH] generic: drop support for libutil with mismatching utmp/utmpx struct Signed-off-by: Ivailo Monev --- ConfigureChecks.cmake | 44 +++++++++++++++++++++---------------------- config-pty.h.cmake | 8 ++++---- kpty/CMakeLists.txt | 1 - kpty/kpty.cpp | 28 ++++++++++++++++++--------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index aa6b6dfc..be0ee11c 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -13,6 +13,7 @@ include(CheckTypeSize) include(CheckStructHasMember) include(CheckCXXSourceCompiles) include(CheckPrototypeDefinition) +include(CMakePushCheckState) # The FindKDE4.cmake module sets _KDE4_PLATFORM_DEFINITIONS with # definitions like _GNU_SOURCE that are needed on each platform. @@ -81,11 +82,8 @@ check_library_exists(nsl gethostbyname "" HAVE_NSL_LIBRARY) check_library_exists(socket connect "" HAVE_SOCKET_LIBRARY) if (UNIX) - # for kpty - check_include_files("sys/types.h;libutil.h" HAVE_LIBUTIL_H) - check_include_files(util.h HAVE_UTIL_H) check_include_files(termio.h HAVE_TERMIO_H) check_include_files(pty.h HAVE_PTY_H) check_include_files(sys/stropts.h HAVE_SYS_STROPTS_H) @@ -93,27 +91,29 @@ if (UNIX) set(UTIL_LIBRARY) - check_function_exists(login login_in_libc) - if (NOT login_in_libc) - check_library_exists(util login "" login_in_libutil) - if (login_in_libutil) - set(UTIL_LIBRARY util) - endif (login_in_libutil) - endif (NOT login_in_libc) - check_function_exists(setutxent HAVE_UTMPX) + check_symbol_exists(setutxent "utmpx.h" HAVE_UTMPX) if (HAVE_UTMPX) set(utmp utmpx) - if (login_in_libutil) - check_library_exists(util loginx "" HAVE_LOGINX) - endif (login_in_libutil) - else (HAVE_UTMPX) + else () set(utmp utmp) - endif (HAVE_UTMPX) - if (login_in_libc OR login_in_libutil) - set(HAVE_LOGIN 1) - else (login_in_libc OR login_in_libutil) - set(HAVE_LOGIN) - endif (login_in_libc OR login_in_libutil) + endif () + + cmake_reset_check_state() + set(CMAKE_REQUIRED_LIBRARIES "util") + check_symbol_exists(loginx "util.h" HAVE_UTIL_LOGINX) + cmake_reset_check_state() + check_symbol_exists(login "${utmp}.h" HAVE_LOGIN) + if (NOT HAVE_LOGIN) + cmake_reset_check_state() + set(CMAKE_REQUIRED_LIBRARIES "util") + check_symbol_exists(login "util.h" HAVE_UTIL_LOGIN) + cmake_reset_check_state() + endif () + + if (HAVE_UTIL_LOGINX OR HAVE_UTIL_LOGIN) + set(UTIL_LIBRARY "util") + endif () + check_struct_has_member("struct ${utmp}" "ut_user" "${utmp}.h" HAVE_STRUCT_UTMP_UT_USER) check_struct_has_member("struct ${utmp}" "ut_type" "${utmp}.h" HAVE_STRUCT_UTMP_UT_TYPE) check_struct_has_member("struct ${utmp}" "ut_pid" "${utmp}.h" HAVE_STRUCT_UTMP_UT_PID) @@ -131,7 +131,7 @@ if (UNIX) if (openpty_in_libc OR openpty_in_libutil) set(HAVE_OPENPTY 1) else (openpty_in_libc OR openpty_in_libutil) - set(HAVE_OPENPTY) + set(HAVE_OPENPTY 0) execute_process( COMMAND sh -c " diff --git a/config-pty.h.cmake b/config-pty.h.cmake index c834a267..3daf8155 100644 --- a/config-pty.h.cmake +++ b/config-pty.h.cmake @@ -1,6 +1,7 @@ /* Defined to the path of the PTY multiplexer device, if any */ #cmakedefine PTM_DEVICE "${PTM_DEVICE}" +#cmakedefine HAVE_LIBUTIL_H 1 #cmakedefine HAVE_POSIX_OPENPT 1 #cmakedefine HAVE_GRANTPT 1 #cmakedefine HAVE_OPENPTY 1 @@ -10,16 +11,15 @@ #cmakedefine HAVE_TCGETATTR #cmakedefine HAVE_TCSETATTR -#cmakedefine HAVE_LIBUTIL_H 1 -#cmakedefine HAVE_UTIL_H 1 #cmakedefine HAVE_PTY_H 1 #cmakedefine HAVE_TERMIO_H 1 #cmakedefine HAVE_SYS_STROPTS_H 1 #cmakedefine HAVE_SYS_FILIO_H 1 -#cmakedefine HAVE_LOGIN 1 #cmakedefine HAVE_UTMPX 1 -#cmakedefine HAVE_LOGINX 1 +#cmakedefine HAVE_UTIL_LOGINX 1 +#cmakedefine HAVE_LOGIN 1 +#cmakedefine HAVE_UTIL_LOGIN 1 #cmakedefine HAVE_STRUCT_UTMP_UT_USER 1 #cmakedefine HAVE_STRUCT_UTMP_UT_TYPE 1 #cmakedefine HAVE_STRUCT_UTMP_UT_PID 1 diff --git a/kpty/CMakeLists.txt b/kpty/CMakeLists.txt index 8f5b8909..644b916e 100644 --- a/kpty/CMakeLists.txt +++ b/kpty/CMakeLists.txt @@ -44,7 +44,6 @@ install( if(NOT HAVE_OPENPTY) add_executable(kgrantpty kgrantpty.c) - # it needs only some fakes but they are part of kdecore now target_link_libraries(kgrantpty ${KDE4_KDECORE_LIBS}) install(TARGETS kgrantpty DESTINATION ${LIBEXEC_INSTALL_DIR}) endif() diff --git a/kpty/kpty.cpp b/kpty/kpty.cpp index cc8ecbaf..2a02668d 100644 --- a/kpty/kpty.cpp +++ b/kpty/kpty.cpp @@ -45,12 +45,14 @@ # include #endif -#ifdef HAVE_LIBUTIL_H -# include -#elif defined(HAVE_UTIL_H) +#if defined(HAVE_UTIL_LOGINX) || defined(HAVE_UTIL_LOGIN) # include #endif +#if defined(HAVE_LIBUTIL_H) +# include +#endif + #ifdef HAVE_UTMPX # include #else @@ -491,7 +493,11 @@ void KPty::login(const char *user, const char *remotehost) #endif #ifdef HAVE_UTMPX - gettimeofday(&l_struct.ut_tv, 0); + // due to binary hacks ut_tv members must be set explicitly + struct timeval tod; + gettimeofday(&tod, 0); + l_struct.ut_tv.tv_sec = tod.tv_sec; + l_struct.ut_tv.tv_usec = tod.tv_usec; #else l_struct.ut_time = time(0); #endif @@ -509,9 +515,9 @@ void KPty::login(const char *user, const char *remotehost) l_struct.ut_session = getsid(0); #endif -#if defined(HAVE_LOGINX) +#if defined(HAVE_UTIL_LOGINX) ::loginx(&l_struct); -#elif defined(HAVE_LOGIN) +#elif defined(HAVE_LOGIN) || defined(HAVE_UTIL_LOGIN) ::login(&l_struct); #elif defined(HAVE_UTMPX) # ifdef _PATH_UTMPX @@ -550,9 +556,9 @@ void KPty::logout() str_ptr = sl_ptr + 1; } #endif -#if defined(HAVE_LOGINX) +#if defined(HAVE_UTIL_LOGINX) ::logoutx(str_ptr, 0, DEAD_PROCESS); -#elif defined(HAVE_LOGIN) +#elif defined(HAVE_LOGIN) || defined(HAVE_UTIL_LOGIN) ::logout(str_ptr); #else # ifdef HAVE_UTMPX @@ -590,7 +596,11 @@ void KPty::logout() ut->ut_type = DEAD_PROCESS; # endif # ifdef HAVE_UTMPX - gettimeofday(&(ut->ut_tv), 0); + // due to binary hacks ut_tv members must be set explicitly + struct timeval tod; + gettimeofday(&tod, 0); + ut->ut_tv.tv_sec = tod.tv_sec; + ut->ut_tv.tv_usec = tod.tv_usec; pututxline(ut); } endutxent();