# HG changeset patch # User Nathan Phillip Brink # Date 2010-03-25 01:45:22 # Node ID a97b3182afc5d8e261c67f833b3e35fe5b467b52 # Parent 83327de5921682149331ab797ecd9dd57b0b7f56 better handle execio failure 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; diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -316,12 +316,14 @@ int exec_blender(char *input, char *outp fprintf(stderr,"Executing: %s\n", frame_str); ret = execio_open(&testrem, command, cmd); - buf[19] = '\0'; - while(!execio_read(testrem, buf, 20, &readlen)) + if(ret) { - if(readlen > 20) { - fprintf(stderr, "Something is terribly wrong!\n"); - } + fprintf(stderr, "error running blender\n"); + return 1; + } + buf[19] = '\0'; + while(!execio_read(testrem, buf, 19, &readlen)) + { buf[readlen] = '\0'; fprintf(stderr, "read \"%s\"\n", buf); } @@ -818,9 +820,6 @@ int slaveBenchmark(char *datadir, int *b buf[19] = '\0'; while(!execio_read(testrem, buf, 19, &readlen)) { - if(readlen > 20) { - fprintf(stderr, "Something is terribly wrong!\n"); - } buf[readlen] = '\0'; fprintf(stderr, "read \"%s\"\n", buf); }