Browse Source

postsrsd.c: Close all file descriptors on process start.

Signed-off-by: Alexander GQ Gerasiov <gq@cs.msu.su>
master
Alexander GQ Gerasiov 7 years ago
parent
commit
a0f5ffa99a
1 changed files with 6 additions and 0 deletions
  1. 6
    0
      postsrsd.c

+ 6
- 0
postsrsd.c View File

@@ -262,6 +262,7 @@ int main (int argc, char **argv)
262 262
   size_t socket_count = 0, sc;
263 263
   int sockets[4] = { -1, -1, -1, -1 };
264 264
   handle_t handler[4] = { 0, 0, 0, 0 };
265
+  int fd, maxfd;
265 266
 
266 267
   excludes = (const char**)calloc(1, sizeof(char*));
267 268
   tmp = strrchr(argv[0], '/');
@@ -398,6 +399,11 @@ int main (int argc, char **argv)
398 399
   if (forward_service == NULL) forward_service = strdup("10001");
399 400
   if (reverse_service == NULL) reverse_service = strdup("10002");
400 401
 
402
+  /* Close all file descriptors (std ones will be closed later). */
403
+  maxfd = sysconf(_SC_OPEN_MAX);
404
+  for(fd = 3; fd < maxfd; fd++)
405
+    close(fd);
406
+
401 407
   /* The stuff we do first may not be possible from within chroot or without privileges */
402 408
 
403 409
   /* Open pid file for writing (the actual process ID is filled in later) */

Loading…
Cancel
Save