浏览代码

Move sysconf(_SC_OPEN_MAX); out of the for() loop to avoid unneeded syscalls

Michael Vogt 11 年之前
父节点
当前提交
1590151632
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      apt-pkg/contrib/fileutl.cc

+ 2 - 1
apt-pkg/contrib/fileutl.cc

@@ -778,8 +778,9 @@ pid_t ExecFork(std::set<int> KeepFDs)
       signal(SIGCONT,SIG_DFL);
       signal(SIGCONT,SIG_DFL);
       signal(SIGTSTP,SIG_DFL);
       signal(SIGTSTP,SIG_DFL);
 
 
+      long ScOpenMax = sysconf(_SC_OPEN_MAX);
       // Close all of our FDs - just in case
       // Close all of our FDs - just in case
-      for (int K = 3; K != sysconf(_SC_OPEN_MAX); K++)
+      for (int K = 3; K != ScOpenMax; K++)
       {
       {
 	 if(KeepFDs.find(K) == KeepFDs.end())
 	 if(KeepFDs.find(K) == KeepFDs.end())
 	    fcntl(K,F_SETFD,FD_CLOEXEC);
 	    fcntl(K,F_SETFD,FD_CLOEXEC);