mirror of
https://github.com/curl/curl.git
synced 2025-09-13 15:42:39 +03:00
wakeup_create: use FD_CLOEXEC/SOCK_CLOEXEC
for `pipe()`/`socketpair()` Fixes #13618 Closes #13625
This commit is contained in:
parent
6eee810db4
commit
fd0d2ed74a
|
@ -159,7 +159,7 @@ struct Curl_multi {
|
||||||
WSAEVENT wsa_event; /* winsock event used for waits */
|
WSAEVENT wsa_event; /* winsock event used for waits */
|
||||||
#else
|
#else
|
||||||
#ifdef ENABLE_WAKEUP
|
#ifdef ENABLE_WAKEUP
|
||||||
curl_socket_t wakeup_pair[2]; /* socketpair() used for wakeup
|
curl_socket_t wakeup_pair[2]; /* pipe()/socketpair() used for wakeup
|
||||||
0 is used for read, 1 is used for write */
|
0 is used for read, 1 is used for write */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,6 +27,27 @@
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include "rand.h"
|
#include "rand.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_PIPE) && defined(HAVE_FCNTL)
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
int Curl_pipe(curl_socket_t socks[2])
|
||||||
|
{
|
||||||
|
if(pipe(socks))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if(fcntl(socks[0], F_SETFD, FD_CLOEXEC) ||
|
||||||
|
fcntl(socks[1], F_SETFD, FD_CLOEXEC) ) {
|
||||||
|
close(socks[0]);
|
||||||
|
close(socks[1]);
|
||||||
|
socks[0] = socks[1] = CURL_SOCKET_BAD;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(HAVE_SOCKETPAIR) && !defined(CURL_DISABLE_SOCKETPAIR)
|
#if !defined(HAVE_SOCKETPAIR) && !defined(CURL_DISABLE_SOCKETPAIR)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -31,7 +31,14 @@
|
||||||
#define wakeup_write write
|
#define wakeup_write write
|
||||||
#define wakeup_read read
|
#define wakeup_read read
|
||||||
#define wakeup_close close
|
#define wakeup_close close
|
||||||
#define wakeup_create pipe
|
#define wakeup_create(p) Curl_pipe(p)
|
||||||
|
|
||||||
|
#ifdef HAVE_FCNTL
|
||||||
|
#include <curl/curl.h>
|
||||||
|
int Curl_pipe(curl_socket_t socks[2]);
|
||||||
|
#else
|
||||||
|
#define Curl_pipe(p) pipe(p)
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* HAVE_PIPE */
|
#else /* HAVE_PIPE */
|
||||||
|
|
||||||
|
@ -40,17 +47,25 @@
|
||||||
#define wakeup_close sclose
|
#define wakeup_close sclose
|
||||||
|
|
||||||
#if defined(USE_UNIX_SOCKETS) && defined(HAVE_SOCKETPAIR)
|
#if defined(USE_UNIX_SOCKETS) && defined(HAVE_SOCKETPAIR)
|
||||||
#define SOCKET_FAMILY AF_UNIX
|
#define SOCKETPAIR_FAMILY AF_UNIX
|
||||||
#elif !defined(HAVE_SOCKETPAIR)
|
#elif !defined(HAVE_SOCKETPAIR)
|
||||||
#define SOCKET_FAMILY 0 /* not used */
|
#define SOCKETPAIR_FAMILY 0 /* not used */
|
||||||
#else
|
#else
|
||||||
#error "unsupported unix domain and socketpair build combo"
|
#error "unsupported unix domain and socketpair build combo"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define wakeup_create(p) Curl_socketpair(SOCKET_FAMILY, SOCK_STREAM, 0, p)
|
#ifdef SOCK_CLOEXEC
|
||||||
|
#define SOCKETPAIR_TYPE (SOCK_STREAM | SOCK_CLOEXEC)
|
||||||
|
#else
|
||||||
|
#define SOCKETPAIR_TYPE SOCK_STREAM
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define wakeup_create(p)\
|
||||||
|
Curl_socketpair(SOCKETPAIR_FAMILY, SOCKETPAIR_TYPE, 0, p)
|
||||||
|
|
||||||
#endif /* HAVE_PIPE */
|
#endif /* HAVE_PIPE */
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_SOCKETPAIR
|
#ifndef HAVE_SOCKETPAIR
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user