Changeset - 84f81c551688
[Not reviewed]
default
0 3 0
ethanzonca - 16 years ago 2009-10-10 17:18:28

Some moving, killed threads var for now
3 files changed with 24 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/server/slave.c
Show inline comments
 
@@ -73,28 +73,28 @@ if(argc>1 && (strcmp("-c", argv[1]) == 0
 
      {
 
        fprintf(stderr,"Please try again! :D\n");
 
        return 0;
 
      }
 
}
 
/* End arg parser */
 

	
 
/* Option getter: Creates vars to grab stuff from conf, uses the options include to grab this data */
 
char *username;
 
char *datadir;
 
cfg_t * my_cfg;
 
cfg_opt_t myopts[] = {
 
		CFG_SIMPLE_STR("username", &username),
 
		CFG_SIMPLE_STR("datadir", &datadir),
 
		CFG_END()
 
		};
 
    CFG_SIMPLE_STR("username", &username),
 
    CFG_SIMPLE_STR("datadir", &datadir),
 
    CFG_END()
 
  };
 
struct options_common *commonopts;
 

	
 
username = NULL;
 
options_init(argc,argv,&my_cfg, myopts, "slave", &commonopts);
 
/* End option getter */
 

	
 
software_updatecheck(); // Should be run every day-ish, if the slave is constantly running.
 

	
 
/* Notifies the user if there is no username in the conf file */
 
if(username == NULL || strcmp(username, "!username") == 0 ){
 
  fprintf(stderr, "\nYou didn't register!\nPlease register or edit your config. (see -h)\nIf this error persists, check distrenslave.conf to ensure all items are filled.\n");
 
}
 
@@ -121,27 +121,24 @@ int framenum;        // @TODO: Remotio s
 
int gotframe = 0;        // set this to 1 after data for a job is received from the server
 
int busy = 0;        // Client business 1=busy 0=idle
 

	
 
char *urltoTar;      // Full URL to the server-side location of job#.tgz
 
char *pathtoTar;     // Full path to the location of the job#.tgz
 

	
 
char *urltoOutput;   // Full URL where output is posted
 
char *pathtoJobfile; // Full path to the job's main file
 
char *pathtoXml;     // Full path to the job's xml file
 
char *pathtoOutput;  // Full path to the output (rendered) file
 
char *outputExt;     // Output Extension (e.g., JPG)
 

	
 
int threads = sysconf(_SC_NPROCESSORS_ONLN); // Equals the number of currently online processors
 
// FOR Win32: int threads = sysinfo.dwNumberOfProcessors;
 

	
 
struct distrenjob *myjob; // Structure to hold data gathered from the XML file
 

	
 
/* If the server says that every frame for jobnum is finished */
 
if( 1 == 0)
 
  {
 
    delete_jobdata(jobnum, datadir);
 
  }
 

	
 
// If the slave is getting job info...
 
if(gotframe ==1)
 
{
 
  /* @TODO: Add remotio hooks */
 
@@ -201,35 +198,26 @@ if(gotframe ==1)
 
  else{
 
    fprintf(stderr,"I think the XML craziness may have failed, so I'll terminate just for fun.\n");
 
    return 1;
 
  }
 

	
 
  /* Variable-fillers which require XML */
 
  outputExt = myjob->output_format; /* @TODO: FIXME! */
 
  _distren_asprintf(&pathtoOutput, "%s/job%d/output/job%d-frame%d.%s", datadir, jobnum, jobnum, framenum, outputExt ); // Prepares the path to the jobfile
 

	
 

	
 
  /** Series of IF's for jobtype based on xml content */
 
  if(1==1){
 
   exec_blender(myjob, pathtoJobfile, pathtoOutput, framenum, threads); // @TODO: This warning should be fixed :D
 
  }
 

	
 
  // Consider placing the following in the exec_blender() function
 
  while(busy == 1){
 
    tell_the_server(DISTREN_REQUEST_PROGRESS);
 
      fprintf(stderr, "Rendering frame %d in job %d...",framenum,jobnum);
 
      sleep(5); // or not... this should be more event-driven, but should still give a heartbeat to the server
 
  }
 
  busy = 2;
 
  // busy = 1; // @TODO: When done rendering, set this.
 
   exec_blender(myjob, pathtoJobfile, pathtoOutput, framenum); // @TODO: This warning should be fixed :D
 
  }
 
  // When blender is finished, run this...
 
  if(busy==2){
 
    fprintf(stderr, "Finished frame %d in job %d, uploading...",framenum,jobnum);
 
    curlpost(pathtoOutput, urltoOutput); // uploads (HTML POST) the output at outputpath to the server at outputurl
 
    tell_the_server(DISTREN_REQUEST_DONEFRAME); // Tells the server that it's finished rendering this frame
 
    busy=0;
 
    // Slave now becomes idle, doesn't need to tell the server anything, ssh handles this.
 
  }
 
  fprintf(stderr, "Finished frame %d in job %d, uploading...",framenum,jobnum);
 
  curlpost(pathtoOutput, urltoOutput); // uploads (HTML POST) the output at outputpath to the server at outputurl
 
  tell_the_server(DISTREN_REQUEST_DONEFRAME); // Tells the server that it's finished rendering this frame
 
  busy=0;
 
  // Slave now becomes idle, doesn't need to tell the server anything, ssh handles this.
 

	
 
}
 

	
 

	
 
  return 0;
 
}
src/server/slavefuncs.c
Show inline comments
 
@@ -402,25 +402,25 @@ int conf_replace(char *username){
 
  }
 
  fclose(fp2);
 
  fclose(fp1);
 
  fprintf(stderr,"Wrote conf file...\n");
 
return 1; // Success
 
}
 

	
 

	
 
/* Executors */
 

	
 

	
 
/** Executor function for Blender operations */
 
void exec_blender(struct distrenjob* distrenjob, char *input, char *output, int frame, int threads)
 
void exec_blender(struct distrenjob* distrenjob, char *input, char *output, int frame)
 
{
 
  int ret;
 
  char *frame_str;
 

	
 
  /* start execio code */
 
  char *command = "blender"; // @TODO: append .exe if win32?
 

	
 
  char *cmd[] = { command, "-b", "-o", output, input, "-f", frame_str, (char *)NULL };
 

	
 
  char buf[10];
 
  struct execio *testrem;
 
  size_t readlen;
 
@@ -430,30 +430,39 @@ void exec_blender(struct distrenjob* dis
 
  ret = execio_open(&testrem, command, cmd); // This path will be absolute for testing, @TODO: should be relative to install on production
 
  buf[9] = '\0';
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
  	    {
 
  	      if(readlen > 9) {
 
  		fprintf(stderr, "Something is terribly wrong!\n");
 
  	      }
 
  	      buf[readlen] = '\0';
 
  	      fprintf(stderr, "read \"%s\"\n", buf);
 
  	    }
 
  	execio_close(testrem);
 
  /* end execio code */
 

	
 
  	if(ret == 1){
 
  		fprintf(stderr,"Error starting Blender. Check your install.\n");
 
  	}
 
  	else{
 
  		fprintf(stderr,"Blender at least started nicely, we don't know if it rendered anything though.\n");
 
  	}
 
  	// Consider placing the following in the exec_blender() function
 
  	while(busy){
 
  	  tell_the_server(DISTREN_REQUEST_PROGRESS);
 
  	    fprintf(stderr, "Rendering frame %d in job %d...",framenum,jobnum);
 
  	    sleep(5); // or not... this should be more event-driven, but should still give a heartbeat to the server
 
  	}
 

	
 

	
 
}
 

	
 
void xmlinit()
 
{
 
  xmlInitParser();
 
  xmlXPathInit();
 
}
 

	
 
void xmlcleanup()
 
{
 
  xmlCleanupParser();
 
}
src/server/slavefuncs.h
Show inline comments
 
@@ -27,17 +27,17 @@
 

	
 
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path);
 
int software_updatecheck();
 
void tell_the_server(int stuff);
 
int delete_jobdata(int jobnum, char *datadir);
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream);
 
int curlget(char *url, char *out);
 
int curlpost(char *filename, char *url);
 
int ssh_keygen();
 
int register_user(char *username, char *email);
 
int login_user(char *username);
 
int conf_replace(char *username);
 
void exec_blender(struct distrenjob* distrenjob, char *input, char *output, int frame, int threads);
 
void exec_blender(struct distrenjob* distrenjob, char *input, char *output, int frame);
 
void xmlinit();
 
void xmlcleanup();
 

	
 
#endif
0 comments (0 inline, 0 general)