diff --git a/src/common/execio.c b/src/common/execio.c --- a/src/common/execio.c +++ b/src/common/execio.c @@ -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,26 +130,54 @@ 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) { - - return 0; + int toreturn; + + /* + 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) { - - return 0; + int toreturn; + /* + TODO: errno handling + */ + toreturn = write(eio->pipe_write, buf, len); + if(!toreturn) + eio->state = EXECIO_STATE_ERROR; + + 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; }