Skip to content

Commit

Permalink
close unused file descriptors after fork()
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Sep 23, 2015
1 parent 7f3a8d3 commit 3d56781
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions neverbleed.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,15 @@ static void daemon_main(int listen_fd, int close_notify_fd, const char *tempdir)
pthread_attr_t thattr;
int sock_fd;

{ /* close all descriptors (except STDIN, STDOUT, STRERR, listen_fd, close_notify_fd) */
int fd = (int)sysconf(_SC_OPEN_MAX) - 1;
for (; fd > 2; --fd) {
if (fd == listen_fd || fd == close_notify_fd)
continue;
close(fd);
}
}

pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, 1);

Expand Down

0 comments on commit 3d56781

Please sign in to comment.