Changeset - ad2cdad338b7
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 17 years ago 2009-02-21 13:53:36
ohnobinki@ohnopublishing.net
closer
1 file changed with 26 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/common/remoteio.c
Show inline comments
 
@@ -36,7 +36,9 @@ int remoteio_open(const char *spec, stru
 
  pid_t child;
 

	
 
  /* for wait(2) if needed */
 
  int childstatus; 
 
  int childstatus;
 
  
 
  int counter;
 

	
 
  /* create two pipes to facilitate communication with child */
 
  if(pipe(pipe_write))
 
@@ -91,8 +93,30 @@ int remoteio_open(const char *spec, stru
 
      close(pipe_write[1]);
 
      close(pipe_read[0]);
 

	
 
      /* reset stdin, stdout, and stderr to the appropriate streams. OK, not stderr :-) */
 
      /*
 
	reset stdin, stdout, and stderr to the appropriate files. OK, not stderr :-) 
 
      */
 
      dup2(pipe_read[1], 0);
 
      dup2(pipe_write[0], 1);
 
      /* 
 
	 close all other file descriptors. We want to keep 0, 1, and 2 open. We don't know that the last open() or pipe() always gives the highest fd number. However, I will assume that it does. Maybe this is a bad idea:
 
       */
 
      counter = pipe_write[0];
 
      if(counter < pipe_write[1])
 
	counter = pipe_write[1];
 
      if(counter < pipe_read[0])
 
	counter = pipe_read[0];
 
      if(counter < pipe_read[1])
 
	counter = pipe_read[1];
 
      while(counter > 2)
 
	{
 
	  close(counter);
 
	  counter --;
 
	}
 
      
 
      /*
 
	now exec
 
       */
 

	
 
      return 1; /* this line should never be reached because we exec*/
 
    }
0 comments (0 inline, 0 general)