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
 
@@ -23,25 +23,26 @@
 
#include <sys/types.h>
 
#include <sys/wait.h>
 
#include <signal.h>
 
#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];
 
  /* pipe used to read from child */
 
  int pipe_read[2];
 

	
 
  pid_t child;
 

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

	
 
  /* create two pipes to facilitate communication with child */
 
  if(pipe(pipe_write))
 
    return 1;
 
  if(pipe(pipe_read));
 
  {
 
@@ -105,23 +106,29 @@ int execio_open(const char *progname, st
 
      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];
 
      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... */
 
    }
 
}
 

	
 

	
 
size_t execio_read(struct execio *eio, void *buf, size_t len)
 
{
src/common/execio.h
Show inline comments
 
@@ -39,13 +39,13 @@ struct execio
 
  int pipe_read;
 
  
 
  pid_t child;
 
};
 

	
 
/* 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, 
 
   returns 0 if len is 0. Otherwise, only returns 0 on error/EOF: use execio_state() to determine
 
*/
 
size_t execio_read(struct execio *eio, void *buf, size_t len);
0 comments (0 inline, 0 general)