WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] ioemu: Close file descriptors when forkin

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] ioemu: Close file descriptors when forking processes.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 07 Mar 2007 11:31:11 -0800
Delivery-date: Wed, 07 Mar 2007 11:33:40 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1173199902 0
# Node ID 095a476a96b18c5d93b6b856bffd1f82a977e358
# Parent  2cf842558b2eabbcb33909578c14bfcb3520c50f
ioemu: Close file descriptors when forking processes.
Just leave stdin/stdout/stderr (and possibly tap fd) open.
Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tools/ioemu/vl.c  |    8 ++++++++
 tools/ioemu/vnc.c |    8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff -r 2cf842558b2e -r 095a476a96b1 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Tue Mar 06 16:46:20 2007 +0000
+++ b/tools/ioemu/vl.c  Tue Mar 06 16:51:42 2007 +0000
@@ -3250,6 +3250,14 @@ static int net_tap_init(VLANState *vlan,
         pid = fork();
         if (pid >= 0) {
             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)
+                        close(i);
+
                 parg = args;
                 *parg++ = (char *)setup_script;
                 *parg++ = ifname;
diff -r 2cf842558b2e -r 095a476a96b1 tools/ioemu/vnc.c
--- a/tools/ioemu/vnc.c Tue Mar 06 16:46:20 2007 +0000
+++ b/tools/ioemu/vnc.c Tue Mar 06 16:51:42 2007 +0000
@@ -1445,7 +1445,7 @@ int vnc_display_init(DisplayState *ds, i
 
 int vnc_start_viewer(int port)
 {
-    int pid;
+    int pid, i, open_max;
     char s[16];
 
     sprintf(s, ":%d", port);
@@ -1456,6 +1456,12 @@ int vnc_start_viewer(int port)
        exit(1);
 
     case 0:    /* child */
+       open_max = sysconf(_SC_OPEN_MAX);
+       for (i = 0; i < open_max; i++)
+           if (i != STDIN_FILENO &&
+               i != STDOUT_FILENO &&
+               i != STDERR_FILENO)
+               close(i);
        execlp("vncviewer", "vncviewer", s, NULL);
        fprintf(stderr, "vncviewer execlp failed\n");
        exit(1);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] ioemu: Close file descriptors when forking processes., Xen patchbot-unstable <=