]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
eventfd: fix feature guards
authorViktor Szakats <commit@vsz.me>
Tue, 1 Apr 2025 21:32:16 +0000 (23:32 +0200)
committerViktor Szakats <commit@vsz.me>
Wed, 2 Apr 2025 23:12:19 +0000 (01:12 +0200)
Enable eventfd code consistently when both `HAVE_EVENTFD` and
`HAVE_SYS_EVENTFD_H` macros are defined.

Before this patch `HAVE_EVENTFD` guarded it alone, though the code
also required the header, which was guarded by `HAVE_SYS_EVENTFD_H`.

These should normally be detected in pairs. When they aren't, omit using
`eventfd()` to avoid calling it without a known matching header.

If this disables valid cases (e.g. some system declares this function
via a different header), feature detection and the code may be extended
for those cases. If these are known to come in pairs, always, another
option is detect them both at build stage, and forward a single macro
to C.

Reported-by: Abhinav Singhal
Bug: https://curl.se/mail/lib-2025-04/0000.html
Closes #16909

lib/asyn-thread.c
lib/curl_setup.h
lib/multi.c
lib/socketpair.c
lib/socketpair.h

index c3edf7203303375db3dc96fc05a8f3d9a7f5f62a..177cfc0c7dfab1e32c815917cdc7f5e3572d0bad 100644 (file)
@@ -170,7 +170,7 @@ void destroy_thread_sync_data(struct thread_sync_data *tsd)
    * close one end of the socket pair (may be done in resolver thread);
    * the other end (for reading) is always closed in the parent thread.
    */
-#ifndef HAVE_EVENTFD
+#ifndef USE_EVENTFD
   if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
     wakeup_close(tsd->sock_pair[1]);
   }
@@ -293,7 +293,7 @@ CURL_STDCALL getaddrinfo_thread(void *arg)
   else {
 #ifndef CURL_DISABLE_SOCKETPAIR
     if(tsd->sock_pair[1] != CURL_SOCKET_BAD) {
-#ifdef HAVE_EVENTFD
+#ifdef USE_EVENTFD
       const uint64_t buf[1] = { 1 };
 #else
       const char buf[1] = { 1 };
index ff63d3d72f142f3e3105d6dbecfc9a3c2af8ac60..c5433c02a456d75c81301378c5fe6940412d2c52 100644 (file)
 #  define __NO_NET_API
 #endif
 
+/* Whether to use eventfd() */
+#if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H)
+#define USE_EVENTFD
+#endif
+
 #include <stdio.h>
 #include <assert.h>
 
index 09afe804c0bfaab94b72467236f2f9b0d54d37ab..858704bebaa44fcb1cf1577afdf322ca6408af0a 100644 (file)
@@ -1408,7 +1408,7 @@ CURLMcode curl_multi_wakeup(CURLM *m)
      and before cleanup */
   if(multi->wakeup_pair[1] != CURL_SOCKET_BAD) {
     while(1) {
-#ifdef HAVE_EVENTFD
+#ifdef USE_EVENTFD
       /* eventfd has a stringent rule of requiring the 8-byte buffer when
          calling write(2) on it */
       const uint64_t buf[1] = { 1 };
@@ -2748,7 +2748,7 @@ CURLMcode curl_multi_cleanup(CURLM *m)
 #else
 #ifdef ENABLE_WAKEUP
     wakeup_close(multi->wakeup_pair[0]);
-#ifndef HAVE_EVENTFD
+#ifndef USE_EVENTFD
     wakeup_close(multi->wakeup_pair[1]);
 #endif
 #endif
index 85fb7a826cff7131bb31d9163c61224a2b428608..e4ca2cffa03b9031a8ba27532939b6bc1b9156c3 100644 (file)
 #include "urldata.h"
 #include "rand.h"
 
-#ifdef HAVE_EVENTFD
-#ifdef HAVE_SYS_EVENTFD_H
+#ifdef USE_EVENTFD
+
 #include <sys/eventfd.h>
-#endif
 
 int Curl_eventfd(curl_socket_t socks[2], bool nonblocking)
 {
@@ -42,7 +41,9 @@ int Curl_eventfd(curl_socket_t socks[2], bool nonblocking)
   socks[0] = socks[1] = efd;
   return 0;
 }
+
 #elif defined(HAVE_PIPE)
+
 #ifdef HAVE_FCNTL
 #include <fcntl.h>
 #endif
@@ -72,8 +73,8 @@ int Curl_pipe(curl_socket_t socks[2], bool nonblocking)
 
   return 0;
 }
-#endif
 
+#endif /* USE_EVENTFD */
 
 #ifndef CURL_DISABLE_SOCKETPAIR
 #ifdef HAVE_SOCKETPAIR
index da0d08b767c9fbe16029d83b70c6a0a7d502f9e3..5541899445b6605c6ab833500a2090fae92786db 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "curl_setup.h"
 
-#ifdef HAVE_EVENTFD
+#ifdef USE_EVENTFD
 
 #define wakeup_write  write
 #define wakeup_read   read
@@ -46,7 +46,7 @@ int Curl_eventfd(curl_socket_t socks[2], bool nonblocking);
 #include <curl/curl.h>
 int Curl_pipe(curl_socket_t socks[2], bool nonblocking);
 
-#else /* !HAVE_EVENTFD && !HAVE_PIPE */
+#else /* !USE_EVENTFD && !HAVE_PIPE */
 
 #define wakeup_write     swrite
 #define wakeup_read      sread
@@ -69,7 +69,7 @@ int Curl_pipe(curl_socket_t socks[2], bool nonblocking);
 #define wakeup_create(p,nb)\
 Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p, nb)
 
-#endif /* HAVE_EVENTFD */
+#endif /* USE_EVENTFD */
 
 #ifndef CURL_DISABLE_SOCKETPAIR
 #include <curl/curl.h>