From c26648e58b57312ccb513015bacdf40936d6400d Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Tue, 6 Jun 2023 08:19:13 +0100 Subject: [PATCH] Fix close_other_fds on FreeBSD While testing podman's restart policy handling, I noticed that containers which were publishing ports did not restart automatically. This was caused by conmon not properly closing the file descriptor which reserved the published port on the host before cleaning up the container. This commit lets conmon discover any extra file descriptors on FreeBSD. Signed-off-by: Doug Rabson --- src/close_fds.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/close_fds.c b/src/close_fds.c index 278ea67c..508ad7a1 100644 --- a/src/close_fds.c +++ b/src/close_fds.c @@ -22,6 +22,12 @@ #include +#ifdef __FreeBSD__ +#define OPEN_FILES_DIR "/dev/fd" +#else +#define OPEN_FILES_DIR "/proc/self/fd" +#endif + static int open_files_max_fd; static fd_set *open_files_set; @@ -31,7 +37,7 @@ static void __attribute__((constructor)) init() ssize_t size = 0; DIR *d; - d = opendir("/proc/self/fd"); + d = opendir(OPEN_FILES_DIR); if (!d) return; @@ -85,7 +91,7 @@ void close_all_fds_ge_than(int firstfd) struct dirent *ent; DIR *d; - d = opendir("/proc/self/fd"); + d = opendir(OPEN_FILES_DIR); if (!d) return;