Skip to content

Commit

Permalink
close_fds: fix close of external fds
Browse files Browse the repository at this point in the history
commit 0f092d5 introduced the
regression.

Closes: #240

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe authored and haircommander committed Mar 1, 2021
1 parent 7310bf1 commit 3ac015e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/close_fds.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ static void __attribute__((constructor)) init()
ssize_t size = 0;
DIR *d;

/* Store how many FDs were open before the Go runtime kicked in. */
d = opendir("/proc/self/fd");
if (!d)
return;
Expand Down Expand Up @@ -74,10 +73,10 @@ void close_other_fds()
{
int fd;

for (fd = 3; fd < open_files_max_fd; fd++) {
if (open_files_set == NULL || FD_ISSET(fd % FD_SETSIZE, &(open_files_set[fd / FD_SETSIZE])))
if (fd == sync_pipe_fd || fd == attach_pipe_fd || fd == dev_null_r || fd == dev_null_w || fd == oom_cgroup_fd
|| fd == oom_event_fd)
close(fd);
if (open_files_set == NULL)
return;
for (fd = 3; fd <= open_files_max_fd; fd++) {
if (FD_ISSET(fd % FD_SETSIZE, &(open_files_set[fd / FD_SETSIZE])))
close(fd);
}
}

0 comments on commit 3ac015e

Please sign in to comment.