Skip to content

Commit

Permalink
Merge pull request #65 from gerasiov/master
Browse files Browse the repository at this point in the history
postsrsd.c: Close all file descriptors on process start.
  • Loading branch information
roehling committed Jan 18, 2017
2 parents d0c8e01 + a0f5ffa commit a77bf99
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions postsrsd.c
Expand Up @@ -262,6 +262,7 @@ int main (int argc, char **argv)
size_t socket_count = 0, sc;
int sockets[4] = { -1, -1, -1, -1 };
handle_t handler[4] = { 0, 0, 0, 0 };
int fd, maxfd;

excludes = (const char**)calloc(1, sizeof(char*));
tmp = strrchr(argv[0], '/');
Expand Down Expand Up @@ -398,6 +399,11 @@ int main (int argc, char **argv)
if (forward_service == NULL) forward_service = strdup("10001");
if (reverse_service == NULL) reverse_service = strdup("10002");

/* Close all file descriptors (std ones will be closed later). */
maxfd = sysconf(_SC_OPEN_MAX);
for(fd = 3; fd < maxfd; fd++)
close(fd);

/* The stuff we do first may not be possible from within chroot or without privileges */

/* Open pid file for writing (the actual process ID is filled in later) */
Expand Down

0 comments on commit a77bf99

Please sign in to comment.