Index: ioemu/vl.c
===================================================================
--- ioemu.orig/vl.c	2007-05-03 19:09:18.000000000 +0100
+++ ioemu/vl.c	2007-05-03 19:11:56.000000000 +0100
@@ -91,6 +91,7 @@
 
 #include <xen/hvm/params.h>
 #define DEFAULT_NETWORK_SCRIPT "/etc/xen/qemu-ifup"
+#define DEFAULT_BRIDGE "xenbr0"
 #ifdef __sun__
 #define SMBD_COMMAND "/usr/sfw/sbin/smbd"
 #else
@@ -3288,11 +3289,11 @@
 #endif
 
 static int net_tap_init(VLANState *vlan, const char *ifname1,
-                        const char *setup_script)
+                        const char *setup_script, const char *bridge)
 {
     TAPState *s;
     int pid, status, fd;
-    char *args[3];
+    char *args[4];
     char **parg;
     char ifname[128];
 
@@ -3311,9 +3312,18 @@
         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;
+                *parg++ = (char *)bridge;
                 *parg++ = NULL;
                 execv(setup_script, args);
                 _exit(1);
@@ -3869,6 +3879,7 @@
     if (!strcmp(device, "tap")) {
         char ifname[64];
         char setup_script[1024];
+        char bridge[16];
         int fd;
         if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
             fd = strtol(buf, NULL, 0);
@@ -3882,7 +3893,10 @@
             if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) {
                 pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT);
             }
-            ret = net_tap_init(vlan, ifname, setup_script);
+            if (get_param_value(bridge, sizeof(bridge), "bridge", p) == 0) {
+                pstrcpy(bridge, sizeof(bridge), DEFAULT_BRIDGE);
+            }
+            ret = net_tap_init(vlan, ifname, setup_script, bridge);
         }
     } else
 #endif
@@ -6101,7 +6115,7 @@
            "-net tap[,vlan=n],ifname=name\n"
            "                connect the host TAP network interface to VLAN 'n'\n"
 #else
-           "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file]\n"
+           "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,bridge=br]\n"
            "                connect the host TAP network interface to VLAN 'n' and use\n"
            "                the network script 'file' (default=%s);\n"
            "                use 'script=no' to disable script execution;\n"
