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
   size_t socket_count = 0, sc;
262
   size_t socket_count = 0, sc;
263
   int sockets[4] = { -1, -1, -1, -1 };
263
   int sockets[4] = { -1, -1, -1, -1 };
264
   handle_t handler[4] = { 0, 0, 0, 0 };
264
   handle_t handler[4] = { 0, 0, 0, 0 };
265
+  int fd, maxfd;
265
 
266
 
266
   excludes = (const char**)calloc(1, sizeof(char*));
267
   excludes = (const char**)calloc(1, sizeof(char*));
267
   tmp = strrchr(argv[0], '/');
268
   tmp = strrchr(argv[0], '/');
398
   if (forward_service == NULL) forward_service = strdup("10001");
399
   if (forward_service == NULL) forward_service = strdup("10001");
399
   if (reverse_service == NULL) reverse_service = strdup("10002");
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
   /* The stuff we do first may not be possible from within chroot or without privileges */
407
   /* The stuff we do first may not be possible from within chroot or without privileges */
402
 
408
 
403
   /* Open pid file for writing (the actual process ID is filled in later) */
409
   /* Open pid file for writing (the actual process ID is filled in later) */

Loading…
Cancel
Save