Changeset - cc2161d16a5b
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 17 years ago 2009-02-21 01:18:44
ohnobinki@ohnopublishing.net
close the correct end of pipes at the right time
1 file changed with 10 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/common/remoteio.c
Show inline comments
 
@@ -21,12 +21,13 @@
 

	
 
#include <unistd.h>
 
#include <sys/types.h>
 
#include <sys/wait.h>
 
#include <signal.h>
 
#include <malloc.h>
 
#include <stdio.h>
 

	
 
int remoteio_open(const char *spec, struct remoteio **rem)
 
{
 
  /* pipe used to write to child */
 
  int pipe_write[2];
 
  /* pipe used to read from child */
 
@@ -56,12 +57,16 @@ int remoteio_open(const char *spec, stru
 
      close(pipe_read[0]);
 
      close(pipe_read[1]);
 
      return 1;
 
    }
 
  if(child)
 
    {
 
      /* close sides of pipe we won't use */
 
      close(pipe_write[0]);
 
      close(pipe_read[1]);
 
      
 
      /* setup remoteio struct */
 
      (*rem) = malloc(sizeof(struct remoteio));
 
      if(!(*rem))
 
	{
 
	  /* we should tell the child we're dead - use wait and close our end of the pipes! */
 
	  close(pipe_write[1]);
 
@@ -79,12 +84,17 @@ int remoteio_open(const char *spec, stru
 
      return 0;
 
    }
 
  
 
  /* child */
 
  else
 
    {
 
      /* close unused pipes */
 
      close(pipe_write[1]);
 
      close(pipe_read[0]);
 

	
 
      /* reset stdin, stdout, and stderr to the appropriate streams. OK, not stderr :-) */
 
      
 

	
 
      return 1; /* this line should never be reached because we exec*/
 
    }
 
}
 

	
0 comments (0 inline, 0 general)