]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tidy-up: process.h detection and use
authorViktor Szakats <commit@vsz.me>
Tue, 1 Nov 2022 22:27:28 +0000 (22:27 +0000)
committerViktor Szakats <commit@vsz.me>
Tue, 1 Nov 2022 22:27:28 +0000 (22:27 +0000)
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

17 files changed:
CMake/Platforms/WindowsCache.cmake
CMakeLists.txt
lib/asyn-ares.c
lib/asyn-thread.c
lib/config-dos.h
lib/config-win32.h
lib/config-win32ce.h
lib/curl_config.h.cmake
lib/curl_threads.c
lib/hostasyn.c
lib/hostip.c
lib/hostip4.c
lib/hostip6.c
lib/hostsyn.c
lib/smb.c
lib/vtls/mbedtls_threadlock.c
lib/vtls/mbedtls_threadlock.h

index 9a513bb6cb36dda60cdaa75f8964080396e82c55..3bcfcd1eec9d49ff5a33e3f39eff9e5d4e80f86b 100644 (file)
@@ -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)
index 6714543098c2e42d98e4b92b69c45024b8b62872..6719c872a5aa1116f850698f8125592bc0f2ed4c 100644 (file)
@@ -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)
index 33edba1395983bf30ebe1528ca9f7e6c5c8d6a72..993222b83cc6de85086de56f74630c622f1590a0 100644 (file)
 #include <inet.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #if (defined(NETWARE) && defined(__NOVELL_LIBC__))
 #undef in_addr_t
 #define in_addr_t unsigned long
index e121c516fee0d159127887552e926e29b10900de..283629e8453bf0d136d62b48ecc42cfc8d9eeb44 100644 (file)
 #include <inet.h>
 #endif
 
-#if defined(USE_THREADS_POSIX)
-#  ifdef HAVE_PTHREAD_H
-#    include <pthread.h>
-#  endif
-#elif defined(USE_THREADS_WIN32)
-#  ifdef HAVE_PROCESS_H
-#    include <process.h>
-#  endif
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
+#  include <pthread.h>
 #endif
 
 #if (defined(NETWARE) && defined(__NOVELL_LIBC__))
index 8e3c940d9cee5d896f7ac7e41389143573a40813..34e8c5f516acd7c12dc740a6d65fe05c1c868030 100644 (file)
@@ -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
index 00e8663d2fb85d09841006099df2298e2c194e10..2837380227cbff3c0b46de1065bcdb0fdd655f45 100644 (file)
 /* Define if you have the <netinet/in.h> header file. */
 /* #define HAVE_NETINET_IN_H 1 */
 
-/* Define if you have the <process.h> header file. */
-#ifndef __SALFORDC__
-#define HAVE_PROCESS_H 1
-#endif
-
 /* Define if you have the <signal.h> header file. */
 #define HAVE_SIGNAL_H 1
 
index 308bfe9e0aca3e85e8822559bea24c8bbd079651..e702a0c32ed84c49d00ffc745094f601ce38233c 100644 (file)
@@ -65,9 +65,6 @@
 /* Define if you have the <stdlib.h> header file.  */
 #define HAVE_STDLIB_H 1
 
-/* Define if you have the <process.h> header file.  */
-/* #define HAVE_PROCESS_H 1 */
-
 /* Define if you have the <sys/param.h> header file.  */
 /* #define HAVE_SYS_PARAM_H 1 */
 
index 2ce4a43c079e8a75dcdfb6d0c210d6955eea74b4..e12d48901fa6b8335289a58326b34ac3e4a9eb32 100644 (file)
 /* Define to 1 if you have the ws2tcpip.h header file. */
 #cmakedefine HAVE_WS2TCPIP_H 1
 
-/* Define if you have the <process.h> 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
 
index eb8e136087602670d6ff7d3ff77737930e12833a..dff61676c9b2d8f4026aad27357c4e545d204aae 100644 (file)
@@ -31,9 +31,7 @@
 #    include <pthread.h>
 #  endif
 #elif defined(USE_THREADS_WIN32)
-#  ifdef HAVE_PROCESS_H
-#    include <process.h>
-#  endif
+#  include <process.h>
 #endif
 
 #include "curl_threads.h"
index 0bfbe2ef860cb70ab4d46299a0ad14f2e7362872..df50d13e19cd4bf3d64cf98614427c5e1a50363d 100644 (file)
 #include <inet.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #include "urldata.h"
 #include "sendf.h"
 #include "hostip.h"
index 941ecacf4ad26a2e0900deb2b1c08081f9a2eecc..dd427a2c661087ba18507de5abb275dedd17e88e 100644 (file)
 #include <signal.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #include "urldata.h"
 #include "sendf.h"
 #include "hostip.h"
index 1dd54e879dbb6d274175438fa08766c24a14fa76..b0280cd0926d829c5058caf071197e8bdae4314a 100644 (file)
 #include <inet.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #include "urldata.h"
 #include "sendf.h"
 #include "hostip.h"
index c62c254c7224dda9234603a098dce5fd2a058f3a..af8bc2302177e0903a3949f6b41b261df46de952 100644 (file)
 #include <inet.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #include "urldata.h"
 #include "sendf.h"
 #include "hostip.h"
index ee54363bf9813a99ec794e803dd5e8e2f514a983..73d1e505693d67fa2ccc2e6171b8bdf468faa57e 100644 (file)
 #include <inet.h>
 #endif
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#endif
-
 #include "urldata.h"
 #include "sendf.h"
 #include "hostip.h"
index a62e858143bce0bbd45580ac83a6e0e88bdddc42..b347f1b74eceac43d6fde23524218abe661e1ae5 100644 (file)
--- a/lib/smb.c
+++ b/lib/smb.c
 
 #define BUILDING_CURL_SMB_C
 
-#ifdef HAVE_PROCESS_H
-#include <process.h>
-#ifdef CURL_WINDOWS_APP
+#ifdef WIN32
 #define getpid GetCurrentProcessId
-#elif defined(WIN32)
-#define getpid _getpid
-#endif
 #endif
 
 #include "smb.h"
index 3971e69b258dfc9579c8b209b91bbde877f96b1b..7d019ede536262f2ebd7508c6c7942dfb8a31cba 100644 (file)
 
 #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 <pthread.h>
 #  define MBEDTLS_MUTEX_T pthread_mutex_t
-#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
-#  include <process.h>
+#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"));
index 3a50d03817b64982985760cff22e7009a2d37f42..22e8725ab01be0370e3d093720446ce16d065fbc 100644 (file)
@@ -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);