Skip to content

Commit

Permalink
Fix close_other_fds on FreeBSD
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dfr authored and haircommander committed Jun 6, 2023
1 parent ebc6717 commit c26648e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/close_fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

#include <sys/stat.h>

#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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c26648e

Please sign in to comment.