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 30 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/common/execio.c
Show inline comments
 
@@ -72,12 +72,13 @@ int execio_open(struct execio **rem, con
 
      /* close sides of pipe we won't use */
 
      close(pipe_write[0]);
 
      close(pipe_read[1]);
 
      
 
      /* 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! */
 
	  close(pipe_write[1]);
 
	  close(pipe_read[0]);
 
	  /* we should probably pass of the wait() call to a thread that just does boring things like that. Especially for when the server tries to connect to other servers... */
 
@@ -136,14 +137,14 @@ int execio_open(struct execio **rem, con
 

	
 
      /*
 
	now exec: execvp uses interpreter to find the file to exec
 
       */
 
      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);
 
    }
 
}
 

	
 
/*
 
  returns 1 if child has exited, 
 
  returns 0 if child is still alive
 
@@ -162,21 +163,39 @@ int _execio_checkpid(struct execio *eio)
 
  return WIFEXITED(childstatus);
 
}
 

	
 

	
 
int execio_read(struct execio *eio, void *buf, size_t len, size_t *bytesread)
 
{
 
  ssize_t ret;
 
  /*
 
    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
 
   */
 
  (*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;
 
      return 1;
 
    }
 

	
src/server/slavefuncs.c
Show inline comments
 
@@ -313,18 +313,20 @@ int exec_blender(char *input, char *outp
 
  char buf[20];
 
  struct execio *testrem;
 
  size_t readlen;
 

	
 
  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);
 
    }
 
  execio_close(testrem);
 
  free(frame_str);
 
  return ret;
 
@@ -815,15 +817,12 @@ int slaveBenchmark(char *datadir, int *b
 
      return 1;
 
    }
 

	
 
  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);
 
    }
 
  execio_close(testrem);
 

	
 
  time(&endTime);
0 comments (0 inline, 0 general)