qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Avoiding extra iterations while closing file fd
@ 2014-03-12 16:54 Pankaj Gupta
  2014-03-13 12:48 ` Stefan Hajnoczi
  0 siblings, 1 reply; 2+ messages in thread
From: Pankaj Gupta @ 2014-03-12 16:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: Pankaj Gupta, stefanha, aliguori

Avoiding iterations for fd 0, 1 & 2 when we are closing file fds in child process.

Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
---
 net/tap.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index 2d5099b..3253838 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -364,11 +364,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);
             }
         }
@@ -449,11 +446,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);
             }
         }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] Avoiding extra iterations while closing file fd
  2014-03-12 16:54 [Qemu-devel] [PATCH] Avoiding extra iterations while closing file fd Pankaj Gupta
@ 2014-03-13 12:48 ` Stefan Hajnoczi
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2014-03-13 12:48 UTC (permalink / raw)
  To: Pankaj Gupta; +Cc: qemu-devel, aliguori

On Wed, Mar 12, 2014 at 10:24:27PM +0530, Pankaj Gupta wrote:
> Avoiding iterations for fd 0, 1 & 2 when we are closing file fds in child process.
> 
> Signed-off-by: Pankaj Gupta <pagupta@redhat.com>
> ---
>  net/tap.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)

POSIX defines the values of standard in, out, and error as 0, 1, and 2
constants.  So this patch is correct but it doesn't do anything useful.
This is something compiler can optimize (but speed doesn't even matter
here).

Please try to focus on patches that fix bugs, add features, or otherwise
add value - it takes the community time to review, test, and merge
patches.

Thanks, applied to my net-next tree:
https://github.com/stefanha/qemu/commits/net-next

Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-03-13 12:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-12 16:54 [Qemu-devel] [PATCH] Avoiding extra iterations while closing file fd Pankaj Gupta
2014-03-13 12:48 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).