Changeset - a97b3182afc5
[Not reviewed]
default
0 2 0
Nathan Brink (binki) - 15 years ago 2010-03-25 01:45:22
ohnobinki@ohnopublishing.net
better handle execio failure
2 files changed with 29 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/common/execio.c
Show inline comments
 
@@ -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;
src/server/slavefuncs.c
Show inline comments
 
@@ -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);
 
    }
0 comments (0 inline, 0 general)