浏览代码

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

Signed-off-by: Alexander GQ Gerasiov <gq@cs.msu.su>
master
Alexander GQ Gerasiov 8 年前
父节点
当前提交
a0f5ffa99a
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6
    0
      postsrsd.c

+ 6
- 0
postsrsd.c 查看文件

@@ -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) */

正在加载...
取消
保存