Changeset - 64b7b0fe164c
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 17 years ago 2009-02-24 21:52:34
ohnobinki@ohnopublishing.net
more complete execio api/code
2 files changed with 34 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/common/execio.c
Show inline comments
 
@@ -84,6 +84,7 @@ int execio_open(struct execio **rem, con
 
	}
 
      (*rem)->pipe_write = pipe_write[1];
 
      (*rem)->pipe_read = pipe_read[0];
 
      (*rem)->state = 0;
 
      (*rem)->child = child;
 
      
 
      return 0;
 
@@ -129,25 +130,53 @@ int execio_open(struct execio **rem, con
 
      execvp(progname, argv);
 

	
 
      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... */
 
      /* in fact, maybe we should abort() here because if we returned, a monster of a distren client would exist! */
 
    }
 
}
 

	
 

	
 
size_t execio_read(struct execio *eio, void *buf, size_t len)
 
{
 
  int toreturn;
 
  
 
  return 0;
 
  /*
 
    TODO: detect NULL eio? 
 
    TODO: errno?
 
    update status of eio for execio_status/to be able to cleanup subproc??
 

	
 
    whenever read() returns 0, it means EOF
 
   */
 
  toreturn = read(eio->pipe_read, buf, len);
 
  if(!toreturn)
 
    /* should also be able to figure out if is bad fd and should set EXECIO_STATE_ERROR instead of _EOF */
 
    eio->state = EXECIO_STATE_EOF;
 

	
 
  return toreturn;
 
}
 

	
 
size_t execio_write(struct execio *eio, void *buf, size_t len)
 
{
 
  int toreturn;
 
  /*
 
    TODO: errno handling
 
   */
 
  toreturn = write(eio->pipe_write, buf, len);
 
  if(!toreturn)
 
    eio->state = EXECIO_STATE_ERROR;
 
  
 
  return 0;
 
   return toreturn;
 
}
 

	
 

	
 
enum execio_state execio_state(struct execio *eio)
 
{
 
  return eio->state;
 
}
 

	
 

	
 
int execio_close(struct execio *eio)
 
{
 
  close(eio->pipe_read);
 
  close(eio->pipe_write);
 
  
 
  return 0;
 
}
src/common/execio.h
Show inline comments
 
@@ -38,6 +38,8 @@ struct execio
 
  int pipe_write;
 
  int pipe_read;
 
  
 
  enum execio_state state;
 
  
 
  pid_t child;
 
};
 

	
0 comments (0 inline, 0 general)