diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-11-21 09:56:28 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2023-11-21 09:56:28 +0100 |
commit | 45e1231149779c363c9abb78cc09e21d047c463f (patch) | |
tree | 111b91a23e747bb2c9df60b0170914cbbd74dec3 /src/socket.c | |
parent | d391e80c7378e6604c8f84538f27df8b915ebd2a (diff) | |
parent | 987942a206ef0f2342bf81d5de6432c6af42b7e7 (diff) |
Update upstream source from tag 'upstream/4.17'
Update to upstream version '4.17'
with Debian dir da192eda54f0b421cbc1b9ba383659593db8d3db
Diffstat (limited to 'src/socket.c')
-rw-r--r-- | src/socket.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/socket.c b/src/socket.c index 0b6f674..e2ad9ed 100644 --- a/src/socket.c +++ b/src/socket.c @@ -41,12 +41,17 @@ #else # define STUPIDWIN(x) (x) #endif -#if defined(__sunos__) && !defined(SO_PROTOCOL) +#if defined(__sun) && !defined(SO_PROTOCOL) # define SO_PROTOCOL SO_PROTOTYPE #endif #ifndef AI_V4MAPPED # define AI_V4MAPPED 0 #endif +#ifdef SOCK_CLOEXEC +# define PLATFORM_SKFLAGS SOCK_CLOEXEC +#else +# define PLATFORM_SKFLAGS 0 +#endif /** * Return the pointer to the singular colon character, any other input @@ -152,7 +157,8 @@ int HX_inet_connect(const char *host, uint16_t port, unsigned int oflags) if (ret != 0) ; for (const struct addrinfo *r = aires; r != nullptr; r = r->ai_next) { - int fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); + int fd = socket(r->ai_family, r->ai_socktype | PLATFORM_SKFLAGS, + r->ai_protocol); if (fd < 0) { if (saved_errno == 0) saved_errno = errno; @@ -195,7 +201,8 @@ int HX_inet_connect(const char *host, uint16_t port, unsigned int oflags) static int HX_gai_listen(const struct addrinfo *r) { - int fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol); + int fd = socket(r->ai_family, r->ai_socktype | PLATFORM_SKFLAGS, + r->ai_protocol); if (fd < 0) return -2; static const int y = 1; @@ -282,7 +289,7 @@ int HX_local_listen(const char *path) if (!S_ISSOCK(sb.st_mode)) return -ENOTSOCK; - int testfd = socket(AF_LOCAL, SOCK_STREAM, 0); + int testfd = socket(AF_LOCAL, SOCK_STREAM | PLATFORM_SKFLAGS, 0); if (testfd < 0) return -errno; ret = connect(testfd, r.ai_addr, r.ai_addrlen); @@ -388,8 +395,12 @@ EXPORT_SYMBOL int HX_socket_from_env(const struct addrinfo *ai, const char *intf top_fd = x; } for (int fd = 3; fd < top_fd; ++fd) - if (try_sk_from_env(fd, ai, intf) == fd) + if (try_sk_from_env(fd, ai, intf) == fd) { +#ifdef SOCK_CLOEXEC + fcntl(fd, F_SETFD, fcntl(fd, F_GETFD, 0) | FD_CLOEXEC); +#endif return fd; + } errno = ENOENT; return -1; } @@ -415,7 +426,7 @@ static int linux_sockaddr_local3(int sk, const void *buf, size_t bufsize) static int linux_sockaddr_local2(const struct sockaddr *sa, socklen_t sl) { - int sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + int sk = socket(AF_NETLINK, SOCK_DGRAM | PLATFORM_SKFLAGS, NETLINK_ROUTE); if (sk < 0) return -errno; struct { @@ -474,7 +485,7 @@ static int openbsd_sockaddr_local3(int rsk, const void *buf, size_t bufsize) static int openbsd_sockaddr_local2(const struct sockaddr *sa, socklen_t sl) { - int sk = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC); + int sk = socket(AF_ROUTE, SOCK_RAW | PLATFORM_SKFLAGS, AF_UNSPEC); if (sk < 0) return -errno; struct { |