From 4a0b974b85f36011fb1a8c17bf59bc272d96a522 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 4 Jul 2023 16:43:52 +0200 Subject: tcp_server: always clean up connection descriptors --- src/file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/file.c') diff --git a/src/file.c b/src/file.c index eb7135a..27709be 100644 --- a/src/file.c +++ b/src/file.c @@ -9,6 +9,7 @@ #include "compiler.h" #include "log.h" +#include #include #include #include @@ -98,6 +99,19 @@ free: return NULL; } +int file_dup(int fd) +{ + int ret = 0; + + ret = fcntl(fd, F_DUPFD_CLOEXEC, 0); + if (ret < 0) { + log_errno("fcntl"); + return ret; + } + + return ret; +} + void file_close(int fd) { log_errno_if(close(fd), "close"); -- cgit v1.2.3