ia64/xen-unstable

changeset 14282:095a476a96b1

ioemu: Close file descriptors when forking processes.
Just leave stdin/stdout/stderr (and possibly tap fd) open.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author kfraser@localhost.localdomain
date Tue Mar 06 16:51:42 2007 +0000 (2007-03-06)
parents 2cf842558b2e
children 87f626f1d5f5
files tools/ioemu/vl.c tools/ioemu/vnc.c
line diff
     1.1 --- a/tools/ioemu/vl.c	Tue Mar 06 16:46:20 2007 +0000
     1.2 +++ b/tools/ioemu/vl.c	Tue Mar 06 16:51:42 2007 +0000
     1.3 @@ -3250,6 +3250,14 @@ static int net_tap_init(VLANState *vlan,
     1.4          pid = fork();
     1.5          if (pid >= 0) {
     1.6              if (pid == 0) {
     1.7 +                int open_max = sysconf(_SC_OPEN_MAX), i;
     1.8 +                for (i = 0; i < open_max; i++)
     1.9 +                    if (i != STDIN_FILENO &&
    1.10 +                        i != STDOUT_FILENO &&
    1.11 +                        i != STDERR_FILENO &&
    1.12 +                        i != fd)
    1.13 +                        close(i);
    1.14 +
    1.15                  parg = args;
    1.16                  *parg++ = (char *)setup_script;
    1.17                  *parg++ = ifname;
     2.1 --- a/tools/ioemu/vnc.c	Tue Mar 06 16:46:20 2007 +0000
     2.2 +++ b/tools/ioemu/vnc.c	Tue Mar 06 16:51:42 2007 +0000
     2.3 @@ -1445,7 +1445,7 @@ int vnc_display_init(DisplayState *ds, i
     2.4  
     2.5  int vnc_start_viewer(int port)
     2.6  {
     2.7 -    int pid;
     2.8 +    int pid, i, open_max;
     2.9      char s[16];
    2.10  
    2.11      sprintf(s, ":%d", port);
    2.12 @@ -1456,6 +1456,12 @@ int vnc_start_viewer(int port)
    2.13  	exit(1);
    2.14  
    2.15      case 0:	/* child */
    2.16 +	open_max = sysconf(_SC_OPEN_MAX);
    2.17 +	for (i = 0; i < open_max; i++)
    2.18 +	    if (i != STDIN_FILENO &&
    2.19 +		i != STDOUT_FILENO &&
    2.20 +		i != STDERR_FILENO)
    2.21 +		close(i);
    2.22  	execlp("vncviewer", "vncviewer", s, NULL);
    2.23  	fprintf(stderr, "vncviewer execlp failed\n");
    2.24  	exit(1);