Changeset - 5b500e68d091
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 17 years ago 2009-02-23 18:19:00
ohnobinki@ohnopublishing.net
execio: typo in new API, added exec()
2 files changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/common/execio.c
Show inline comments
 
@@ -26,7 +26,7 @@
 
#include <malloc.h>
 
#include <stdio.h>
 

	
 
int execio_open(const char *progname, struct execio **rem)
 
int execio_open(struct execio **rem, const char *progname, char *const argv[])
 
{
 
  /* pipe used to write to child */
 
  int pipe_write[2];
 
@@ -39,6 +39,7 @@ int execio_open(const char *progname, st
 
  int childstatus;
 
  
 
  int counter;
 
  int counter2;
 

	
 
  /* create two pipes to facilitate communication with child */
 
  if(pipe(pipe_write))
 
@@ -108,17 +109,23 @@ int execio_open(const char *progname, st
 
	counter = pipe_read[0];
 
      if(counter < pipe_read[1])
 
	counter = pipe_read[1];
 
      counter2 = 0;
 
      while(counter > 2)
 
	{
 
	  close(counter);
 
	  if(!close(counter))
 
	    counter2 ++; /* record how many descriptors we still had open :-) */
 
	  counter --;
 
	}
 
      
 
      /* stderr is the only stream we haven't confiscated atm - just for fun - I will confiscate it later, though, to support parsing error messages */
 
      fprintf(stderr, "closed %d fds before execing \"%s\"\n", counter2, progname);
 

	
 
      /*
 
	now exec
 
	now exec: execvp uses interpreter to find the file to exec
 
       */
 
      execvp(progname, argv);
 

	
 
      return 1; /* this line should never be reached because we exec*/
 
      return 1; /* this line should never be reached because we exec -- unless if the exec returns something bad. Then we'd have to tell execio over the pipe about that somehow... */
 
    }
 
}
 

	
src/common/execio.h
Show inline comments
 
@@ -42,7 +42,7 @@ struct execio
 
};
 

	
 
/* nonzsero return on error */
 
int execio_open(struct execio **rem, const char *progname, char *cont argv[]);
 
int execio_open(struct execio **rem, const char *progname, char *const argv[]);
 

	
 
/* 
 
   blocks, 
0 comments (0 inline, 0 general)