# 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
|