aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-23 21:53:58 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-23 21:53:58 +0200
commit1e35db47ccefa8371fdc6d70d8895df19d8a1b98 (patch)
tree13485f4144847002d58512773fd73a195e2e33ea
parentnet: fix recv_all (diff)
downloadcimple-1e35db47ccefa8371fdc6d70d8895df19d8a1b98.tar.gz
cimple-1e35db47ccefa8371fdc6d70d8895df19d8a1b98.zip
net: use CLOEXEC
I've only recently learned about this flag, seems generally useful.
-rw-r--r--src/net.c6
1 files 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;