From 1e35db47ccefa8371fdc6d70d8895df19d8a1b98 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 23 Aug 2022 21:53:58 +0200 Subject: net: use CLOEXEC I've only recently learned about this flag, seems generally useful. --- src/net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net.c b/src/net.c index b40cba8..e41d5ea 100644 --- a/src/net.c +++ b/src/net.c @@ -50,7 +50,7 @@ int bind_to_port(const char *port) } for (it = result; it; it = it->ai_next) { - socket_fd = socket(it->ai_family, it->ai_socktype, it->ai_protocol); + socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); if (socket_fd < 0) { print_errno("socket"); continue; @@ -105,7 +105,7 @@ int accept_connection(int fd, connection_handler handler, void *arg) { int conn_fd, ret = 0; - ret = accept(fd, NULL, NULL); + ret = accept4(fd, NULL, NULL, SOCK_CLOEXEC); if (ret < 0) { print_errno("accept"); return ret; @@ -149,7 +149,7 @@ int connect_to_host(const char *host, const char *port) } for (it = result; it; it = it->ai_next) { - socket_fd = socket(it->ai_family, it->ai_socktype, it->ai_protocol); + socket_fd = socket(it->ai_family, it->ai_socktype | SOCK_CLOEXEC, it->ai_protocol); if (socket_fd < 0) { print_errno("socket"); continue; -- cgit v1.2.3