From patchwork Fri Apr 25 14:09:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 342869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 53CBF1400D4 for ; Sat, 26 Apr 2014 00:10:55 +1000 (EST) Received: from localhost ([::1]:58167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wdgq4-0006Iy-QW for incoming@patchwork.ozlabs.org; Fri, 25 Apr 2014 10:10:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdgpI-0004Kw-DY for qemu-devel@nongnu.org; Fri, 25 Apr 2014 10:10:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WdgpC-0004Rg-9C for qemu-devel@nongnu.org; Fri, 25 Apr 2014 10:10:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WdgpC-0004RY-1M for qemu-devel@nongnu.org; Fri, 25 Apr 2014 10:09:58 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3PE9uPA011531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Apr 2014 10:09:56 -0400 Received: from localhost (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3PE9tUP030747; Fri, 25 Apr 2014 10:09:55 -0400 From: Stefan Hajnoczi To: Date: Fri, 25 Apr 2014 16:09:35 +0200 Message-Id: <1398434980-17149-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1398434980-17149-1-git-send-email-stefanha@redhat.com> References: <1398434980-17149-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Stefan Hajnoczi , Pankaj Gupta Subject: [Qemu-devel] [PULL 1/6] tap: Avoid extra iterations while closing file fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Pankaj Gupta Avoid iterations for fd 0, 1 & 2 when we are closing file fds in child process. Signed-off-by: Pankaj Gupta Signed-off-by: Stefan Hajnoczi --- net/tap.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/net/tap.c b/net/tap.c index 8847ce1..fc1b865 100644 --- a/net/tap.c +++ b/net/tap.c @@ -367,11 +367,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) if (pid == 0) { int open_max = sysconf(_SC_OPEN_MAX), i; - for (i = 0; i < open_max; i++) { - if (i != STDIN_FILENO && - i != STDOUT_FILENO && - i != STDERR_FILENO && - i != fd) { + for (i = 3; i < open_max; i++) { + if (i != fd) { close(i); } } @@ -452,11 +449,8 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) char br_buf[6+IFNAMSIZ] = {0}; char helper_cmd[PATH_MAX + sizeof(fd_buf) + sizeof(br_buf) + 15]; - for (i = 0; i < open_max; i++) { - if (i != STDIN_FILENO && - i != STDOUT_FILENO && - i != STDERR_FILENO && - i != sv[1]) { + for (i = 3; i < open_max; i++) { + if (i != sv[1]) { close(i); } }