提交 13a12f86 编写于 作者: P Pankaj Gupta 提交者: Stefan Hajnoczi

tap: Avoid extra iterations while closing file fd

Avoid iterations for fd 0, 1 & 2 when we are closing file fds in child process.
Signed-off-by: NPankaj Gupta <pagupta@redhat.com>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
上级 0e96643c
...@@ -367,11 +367,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) ...@@ -367,11 +367,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
if (pid == 0) { if (pid == 0) {
int open_max = sysconf(_SC_OPEN_MAX), i; int open_max = sysconf(_SC_OPEN_MAX), i;
for (i = 0; i < open_max; i++) { for (i = 3; i < open_max; i++) {
if (i != STDIN_FILENO && if (i != fd) {
i != STDOUT_FILENO &&
i != STDERR_FILENO &&
i != fd) {
close(i); close(i);
} }
} }
...@@ -452,11 +449,8 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) ...@@ -452,11 +449,8 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
char br_buf[6+IFNAMSIZ] = {0}; char br_buf[6+IFNAMSIZ] = {0};
char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15]; char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15];
for (i = 0; i < open_max; i++) { for (i = 3; i < open_max; i++) {
if (i != STDIN_FILENO && if (i != sv[1]) {
i != STDOUT_FILENO &&
i != STDERR_FILENO &&
i != sv[1]) {
close(i); close(i);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册