diff --git a/src/common/execio.c b/src/common/execio.c --- a/src/common/execio.c +++ b/src/common/execio.c @@ -75,6 +75,7 @@ int execio_open(struct execio **rem, con /* setup execio struct */ (*rem) = malloc(sizeof(struct execio)); + fprintf(stderr, "Allocated rem at %d\n", rem); if(!(*rem)) { /* we should tell the child we're dead - use wait and close our end of the pipes! */ @@ -139,8 +140,8 @@ 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! */ + fprintf(stderr, "uh-oh, ``%s'' didn't start for execio\n", progname); + exit(1); } } @@ -165,6 +166,7 @@ int _execio_checkpid(struct execio *eio) int execio_read(struct execio *eio, void *buf, size_t len, size_t *bytesread) { + ssize_t ret; /* TODO: detect NULL eio? TODO: errno? @@ -172,8 +174,25 @@ int execio_read(struct execio *eio, void whenever read() returns 0, it means EOF */ - (*bytesread) = read(eio->pipe_read, buf, len); - if(!*bytesread) + + ret = read(eio->pipe_read, buf, len); + if(ret == -1) + { + (*bytesread) = 0; + perror("read"); + switch(errno) + { + case EAGAIN: + case EINTR: + return 0; + break; + default: + return 1; + } + } + + (*bytesread) = (size_t)ret; + if(!ret) { /* 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;