From: Amos Jeffries Date: Thu, 22 Jun 2023 16:33:05 +0000 (+0000) Subject: Improve PSAPI.dll detection (#1391) X-Git-Tag: SQUID_7_0_1~421 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a186e0d91d2555de6e7d4d5ee3efedba1fdf19e7;p=thirdparty%2Fsquid.git Improve PSAPI.dll detection (#1391) Detect Windows PSAPI library like any other library dependency. Allowing build --with(out) options to disable or to set paths. Detect the psapi.h properly and set HAVE_* macro for proper include wrapping. Wrap PSAPI logic in check for PSAPI_VERSION which is defined whenever the API support is actually available. --- diff --git a/compat/mswindows.cc b/compat/mswindows.cc index db69088d7a..90ec3ffeb9 100644 --- a/compat/mswindows.cc +++ b/compat/mswindows.cc @@ -23,7 +23,7 @@ #include #include #include -#if HAVE_WIN32_PSAPI +#if HAVE_PSAPI_H #include #endif #ifndef _MSWSOCK_ @@ -62,7 +62,7 @@ void GetProcessName(pid_t pid, char *ProcessName) { strcpy(ProcessName, "unknown"); -#if HAVE_WIN32_PSAPI +#if defined(PSAPI_VERSION) /* Get a handle to the process. */ HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); /* Get the process name. */ @@ -79,7 +79,7 @@ GetProcessName(pid_t pid, char *ProcessName) } else return; CloseHandle(hProcess); -#endif /* HAVE_WIN32_PSAPI */ +#endif } int diff --git a/configure.ac b/configure.ac index 5c30a0722d..128c7b2503 100644 --- a/configure.ac +++ b/configure.ac @@ -186,16 +186,8 @@ AM_CONDITIONAL(ENABLE_WIN32_IPC,[test "x$squid_host_os" = "xmingw"]) AS_CASE(["$squid_host_os"], [mingw],[ - AC_PATH_PROG(WIN32_PSAPI, psapi.dll, none) CFLAGS="$CFLAGS -mthreads" CXXFLAGS="$CXXFLAGS -mthreads -static-libgcc -static-libstdc++" - AS_IF([test "x$ac_cv_path_WIN32_PSAPI" = "xnone"],[ - AC_MSG_NOTICE([PSAPI.DLL is recommended to run Squid on Windows NT Platform]) - AC_MSG_NOTICE([Please see PSAPI.DLL section on doc/win32-relnotes.html.]) - ],[ - AC_DEFINE(HAVE_WIN32_PSAPI,1,[Define if you have PSAPI.DLL on Windows systems]) - LIBS="$LIBS -lpsapi" - ]) MINGW_LIBS="-lmingwex" AC_SUBST(MINGW_LIBS) ], @@ -424,6 +416,30 @@ AS_IF([test "x$libatomic_checker_result" = "xno"],[ SQUID_STATE_ROLLBACK(LIBATOMIC) AC_SUBST(ATOMICLIB) +SQUID_AUTO_LIB(psapi,[Windows PSAPI.dll],[LIBPSAPI]) +AS_IF([test "x$with_psapi" != "xno"],[ + SQUID_STATE_SAVE(squid_psapi_state) + CPPFLAGS="$LIBPSAPI_CFLAGS $CPPFLAGS" + LIBS="$LIBPSAPI_PATH $LIBS" + AC_CHECK_LIB([psapi],[K32GetProcessMemoryInfo],[LIBPSAPI_LIBS="-lpsapi"]) + AC_CHECK_HEADER([psapi.h],,,[ +#if HAVE_WINDOWS_H +#include +#endif + ]) + SQUID_STATE_ROLLBACK(squid_psapi_state) + AS_IF([test "x$LIBPSAPI_LIBS" != "x"],[ + CXXFLAGS="$LIBPSAPI_CFLAGS $CXXFLAGS" + LIBPSAPI_LIBS="$LIBPSAPI_PATH $LIBPSAPI_LIBS" + ],[test "x$with_psapi" = "xyes"],[ + AC_MSG_ERROR([Required library PSAPI.dll not found]) + ],[ + AC_MSG_NOTICE([Library PSAPI.dll not found.]) + ]) +]) +AC_MSG_NOTICE([Using Windows PSAPI.dll library: ${with_psapi:=auto}]) +AC_SUBST(LIBPSAPI_LIBS) + AC_SEARCH_LIBS([shm_open], [rt]) AS_IF([test "x$ac_cv_search_shm_open" != "xno"],[ AC_DEFINE(HAVE_SHM,1,[Support shared memory features]) @@ -2347,20 +2363,13 @@ AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[ #endif ]) -dnl Override rusage() detect on MinGW because is emulated in source code -AS_IF([test "$squid_host_os" = "mingw"],[ - AC_DEFINE(HAVE_STRUCT_RUSAGE) - ac_cv_func_getrusage="yes" - AC_MSG_NOTICE([Using own rusage on Windows.]) -],[ - AC_CHECK_TYPE(struct rusage,AC_DEFINE(HAVE_STRUCT_RUSAGE,1,[The system provides struct rusage]),,[ +AC_CHECK_TYPE(struct rusage,AC_DEFINE(HAVE_STRUCT_RUSAGE,1,[The system provides struct rusage]),,[ #if HAVE_SYS_TIME_H #include #endif #if HAVE_SYS_RESOURCE_H #include #endif - ]) ]) AC_CHECK_MEMBERS([struct iphdr.ip_hl],,,[ diff --git a/doc/release-notes/release-7.sgml.in b/doc/release-notes/release-7.sgml.in index dffca86487..a475c26fa2 100644 --- a/doc/release-notes/release-7.sgml.in +++ b/doc/release-notes/release-7.sgml.in @@ -99,7 +99,8 @@ This section gives an account of those changes in three categories: New options