# HG changeset patch # User Binki # Date 2009-03-16 23:11:35 # Node ID 7b322e60270cc92f27cbd95b398eeb42bd59c535 # Parent 2e10900d91d9eebc8e97ed748b10cc214089eae2 a few polishes to execio maybe we're ready to start working on: common configfile setup and then remoteio, which uses the configfile diff --git a/src/common/execio.c b/src/common/execio.c --- a/src/common/execio.c +++ b/src/common/execio.c @@ -26,6 +26,7 @@ #include #include #include +#include int execio_open(struct execio **rem, const char *progname, char *const argv[]) { @@ -182,12 +183,30 @@ int execio_read(struct execio *eio, void int execio_write(struct execio *eio, void *buf, size_t len, size_t *bytesread) { - /* - TODO: errno handling - */ + errno = 0; (*bytesread) = write(eio->pipe_write, buf, len); if(!*bytesread) - eio->state = EXECIO_STATE_ERROR; + { + switch(errno) + { + case EPIPE: + /* + the program closed the pipe (died) + */ + fprintf(stderr, "execio_write: the child program closed its stdin pipe\n"); + eio->state = EXECIO_STATE_EOF; + break; + + default: + fprintf(stderr, "execio_write: unhandled error writing to an fd: \n"); + perror("write"); + eio->state = EXECIO_STATE_ERROR; + break; + + } + + return 1; + } return 0; } @@ -208,7 +227,11 @@ int execio_close(struct execio *eio) /* maybe we should just kill the child */ kill(eio->child, SIGTERM); - /* the waitpid(2) seems to indicate that only when the child is terminated will this wait return. */ + /* + the waitpid(2) seems to indicate that only when the child is terminated will this wait return. + This are of code will probably need improving - the ability to seng SIGKILL after a timeout? So we'll output a debug line before running waitpid + */ + fprintf(stderr, "execio_close: running waitpid\n"); waitpid(eio->child, &childstatus, 0); return 0; diff --git a/src/common/execio.h b/src/common/execio.h --- a/src/common/execio.h +++ b/src/common/execio.h @@ -57,9 +57,14 @@ int execio_open(struct execio **rem, con int execio_read(struct execio *eio, void *buf, size_t len, size_t *bytesread); int execio_write(struct execio *eio, void *buf, size_t len, size_t *bytesread); +/* + use this function to determine if the using program should keep trying to read/write + */ enum execio_state execio_state(struct execio *eio); -/* nonzero return on error */ +/* + nonzero return on error +*/ int execio_close(struct execio *eio); #endif