From b563a92cd6797ec40d7cd73d51f9c31e637463f4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 1 Nov 2022 22:27:28 +0000 Subject: [PATCH] tidy-up: process.h detection and use This patch aims to cleanup the use of `process.h` header and the macro `HAVE_PROCESS_H` associated with it. - `process.h` is always available on Windows. In curl, it is required only for `_beginthreadex()` in `lib/curl_threads.c`. - `process.h` is also available in MS-DOS. In curl, its only use was in `lib/smb.c` for `getpid()`. But `getpid()` is in fact declared by `unistd.h`, which is always enabled via `lib/config-dos.h`. So the header is not necessary. - `HAVE_PROCESS_H` was detected by CMake, forced to 1 on Windows and left to real detection for other platforms. It was also set to always-on in `lib/config-win32.h` and `lib/config-dos.h`. In autotools builds, there was no detection and the macro was never set. Based on these observations, in this patch we: - Rework Windows `getpid` logic in `lib/smb.c` to always use the equivalent direct Win32 API function `GetCurrentProcessId()`, as we already did for Windows UWP apps. This makes `process.h` unnecessary here on Windows. - Stop #including `process.h` into files where it was not necessary. This is everywhere, except `lib/curl_threads.c`. > Strangely enough, `lib/curl_threads.c` compiled fine with autotools > because `process.h` is also indirecty included via `unistd.h`. This > might have been broken in autotools MSVC builds, where the latter > header is missing. - Delete all remaining `HAVE_PROCESS_H` feature guards, for they were unnecessary. - Delete `HAVE_PROCESS_H` detection from CMake and predefined values from `lib/config-*.h` headers. Reviewed-by: Jay Satiro Closes #9703 --- CMake/Platforms/WindowsCache.cmake | 1 - CMakeLists.txt | 1 - lib/asyn-ares.c | 4 ---- lib/asyn-thread.c | 10 ++-------- lib/config-dos.h | 1 - lib/config-win32.h | 5 ----- lib/config-win32ce.h | 3 --- lib/curl_config.h.cmake | 3 --- lib/curl_threads.c | 4 +--- lib/hostasyn.c | 4 ---- lib/hostip.c | 4 ---- lib/hostip4.c | 4 ---- lib/hostip6.c | 4 ---- lib/hostsyn.c | 4 ---- lib/smb.c | 7 +------ lib/vtls/mbedtls_threadlock.c | 13 ++++++------- lib/vtls/mbedtls_threadlock.h | 2 +- 17 files changed, 11 insertions(+), 63 deletions(-) diff --git a/CMake/Platforms/WindowsCache.cmake b/CMake/Platforms/WindowsCache.cmake index 9a513bb6cb..3bcfcd1eec 100644 --- a/CMake/Platforms/WindowsCache.cmake +++ b/CMake/Platforms/WindowsCache.cmake @@ -34,7 +34,6 @@ if(NOT UNIX) set(HAVE_NETDB_H 0) set(HAVE_NETINET_IN_H 0) set(HAVE_NET_IF_H 0) - set(HAVE_PROCESS_H 1) set(HAVE_PWD_H 0) set(HAVE_SETJMP_H 1) set(HAVE_SIGNAL_H 1) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6714543098..6719c872a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1006,7 +1006,6 @@ check_include_file_concat("time.h" HAVE_TIME_H) check_include_file_concat("unistd.h" HAVE_UNISTD_H) check_include_file_concat("utime.h" HAVE_UTIME_H) -check_include_file_concat("process.h" HAVE_PROCESS_H) check_include_file_concat("stddef.h" HAVE_STDDEF_H) check_include_file_concat("stdint.h" HAVE_STDINT_H) check_include_file_concat("sys/utsname.h" HAVE_SYS_UTSNAME_H) diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 33edba1395..993222b83c 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -47,10 +47,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #if (defined(NETWARE) && defined(__NOVELL_LIBC__)) #undef in_addr_t #define in_addr_t unsigned long diff --git a/lib/asyn-thread.c b/lib/asyn-thread.c index e121c516fe..283629e845 100644 --- a/lib/asyn-thread.c +++ b/lib/asyn-thread.c @@ -44,14 +44,8 @@ #include #endif -#if defined(USE_THREADS_POSIX) -# ifdef HAVE_PTHREAD_H -# include -# endif -#elif defined(USE_THREADS_WIN32) -# ifdef HAVE_PROCESS_H -# include -# endif +#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) +# include #endif #if (defined(NETWARE) && defined(__NOVELL_LIBC__)) diff --git a/lib/config-dos.h b/lib/config-dos.h index 8e3c940d9c..34e8c5f516 100644 --- a/lib/config-dos.h +++ b/lib/config-dos.h @@ -56,7 +56,6 @@ #define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_TCP_H 1 #define HAVE_NET_IF_H 1 -#define HAVE_PROCESS_H 1 #define HAVE_RECV 1 #define HAVE_SELECT 1 #define HAVE_SEND 1 diff --git a/lib/config-win32.h b/lib/config-win32.h index 00e8663d2f..2837380227 100644 --- a/lib/config-win32.h +++ b/lib/config-win32.h @@ -66,11 +66,6 @@ /* Define if you have the header file. */ /* #define HAVE_NETINET_IN_H 1 */ -/* Define if you have the header file. */ -#ifndef __SALFORDC__ -#define HAVE_PROCESS_H 1 -#endif - /* Define if you have the header file. */ #define HAVE_SIGNAL_H 1 diff --git a/lib/config-win32ce.h b/lib/config-win32ce.h index 308bfe9e0a..e702a0c32e 100644 --- a/lib/config-win32ce.h +++ b/lib/config-win32ce.h @@ -65,9 +65,6 @@ /* Define if you have the header file. */ #define HAVE_STDLIB_H 1 -/* Define if you have the header file. */ -/* #define HAVE_PROCESS_H 1 */ - /* Define if you have the header file. */ /* #define HAVE_SYS_PARAM_H 1 */ diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index 2ce4a43c07..e12d48901f 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -595,9 +595,6 @@ /* Define to 1 if you have the ws2tcpip.h header file. */ #cmakedefine HAVE_WS2TCPIP_H 1 -/* Define if you have the header file. */ -#cmakedefine HAVE_PROCESS_H 1 - /* Define to 1 if you need the lber.h header file even with ldap.h */ #cmakedefine NEED_LBER_H 1 diff --git a/lib/curl_threads.c b/lib/curl_threads.c index eb8e136087..dff61676c9 100644 --- a/lib/curl_threads.c +++ b/lib/curl_threads.c @@ -31,9 +31,7 @@ # include # endif #elif defined(USE_THREADS_WIN32) -# ifdef HAVE_PROCESS_H -# include -# endif +# include #endif #include "curl_threads.h" diff --git a/lib/hostasyn.c b/lib/hostasyn.c index 0bfbe2ef86..df50d13e19 100644 --- a/lib/hostasyn.c +++ b/lib/hostasyn.c @@ -43,10 +43,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip.c b/lib/hostip.c index 941ecacf4a..dd427a2c66 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -48,10 +48,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip4.c b/lib/hostip4.c index 1dd54e879d..b0280cd092 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -43,10 +43,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostip6.c b/lib/hostip6.c index c62c254c72..af8bc23021 100644 --- a/lib/hostip6.c +++ b/lib/hostip6.c @@ -43,10 +43,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/hostsyn.c b/lib/hostsyn.c index ee54363bf9..73d1e50569 100644 --- a/lib/hostsyn.c +++ b/lib/hostsyn.c @@ -43,10 +43,6 @@ #include #endif -#ifdef HAVE_PROCESS_H -#include -#endif - #include "urldata.h" #include "sendf.h" #include "hostip.h" diff --git a/lib/smb.c b/lib/smb.c index a62e858143..b347f1b74e 100644 --- a/lib/smb.c +++ b/lib/smb.c @@ -30,13 +30,8 @@ #define BUILDING_CURL_SMB_C -#ifdef HAVE_PROCESS_H -#include -#ifdef CURL_WINDOWS_APP +#ifdef WIN32 #define getpid GetCurrentProcessId -#elif defined(WIN32) -#define getpid _getpid -#endif #endif #include "smb.h" diff --git a/lib/vtls/mbedtls_threadlock.c b/lib/vtls/mbedtls_threadlock.c index 3971e69b25..7d019ede53 100644 --- a/lib/vtls/mbedtls_threadlock.c +++ b/lib/vtls/mbedtls_threadlock.c @@ -26,13 +26,12 @@ #if defined(USE_MBEDTLS) && \ ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H))) + defined(USE_THREADS_WIN32)) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) # include # define MBEDTLS_MUTEX_T pthread_mutex_t -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) -# include +#elif defined(USE_THREADS_WIN32) # define MBEDTLS_MUTEX_T HANDLE #endif @@ -60,7 +59,7 @@ int Curl_mbedtlsthreadlock_thread_setup(void) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_init(&mutex_buf[i], NULL)) return 0; /* pthread_mutex_init failed */ -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) mutex_buf[i] = CreateMutex(0, FALSE, 0); if(mutex_buf[i] == 0) return 0; /* CreateMutex failed */ @@ -81,7 +80,7 @@ int Curl_mbedtlsthreadlock_thread_cleanup(void) #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H) if(pthread_mutex_destroy(&mutex_buf[i])) return 0; /* pthread_mutex_destroy failed */ -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(!CloseHandle(mutex_buf[i])) return 0; /* CloseHandle failed */ #endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */ @@ -101,7 +100,7 @@ int Curl_mbedtlsthreadlock_lock_function(int n) "Error: mbedtlsthreadlock_lock_function failed\n")); return 0; /* pthread_mutex_lock failed */ } -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED) { DEBUGF(fprintf(stderr, "Error: mbedtlsthreadlock_lock_function failed\n")); @@ -121,7 +120,7 @@ int Curl_mbedtlsthreadlock_unlock_function(int n) "Error: mbedtlsthreadlock_unlock_function failed\n")); return 0; /* pthread_mutex_unlock failed */ } -#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H) +#elif defined(USE_THREADS_WIN32) if(!ReleaseMutex(mutex_buf[n])) { DEBUGF(fprintf(stderr, "Error: mbedtlsthreadlock_unlock_function failed\n")); diff --git a/lib/vtls/mbedtls_threadlock.h b/lib/vtls/mbedtls_threadlock.h index 3a50d03817..22e8725ab0 100644 --- a/lib/vtls/mbedtls_threadlock.h +++ b/lib/vtls/mbedtls_threadlock.h @@ -29,7 +29,7 @@ #ifdef USE_MBEDTLS #if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \ - (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)) + defined(USE_THREADS_WIN32) int Curl_mbedtlsthreadlock_thread_setup(void); int Curl_mbedtlsthreadlock_thread_cleanup(void);