Changeset - 5dc296ca954f
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-12-20 16:41:24
ohnobinki@ohnopublishing.net
fix return vals, free() after _distren_asprintf()
1 file changed with 66 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -734,12 +734,19 @@ void update_general_info(struct general_
 

	
 
  _distren_asprintf(&tmp, "%d", geninfo->jobs_in_queue);
 
  xmlTextWriterWriteElement(writer, (xmlChar*)"jobs_in_queue", (xmlChar*)tmp);
 
  free(tmp);
 

	
 
  _distren_asprintf(&tmp, "%d", geninfo->total_finished_jobs);
 
  xmlTextWriterWriteElement(writer, (xmlChar*)"total_finished_jobs", (xmlChar*)tmp);
 
  free(tmp);
 

	
 
  _distren_asprintf(&tmp, "%d", geninfo->total_frames_rendered);
 
  xmlTextWriterWriteElement(writer, (xmlChar*)"total_frames_rendered", (xmlChar*)tmp);
 
  free(tmp);
 

	
 
  _distren_asprintf(&tmp, "%d", geninfo->highest_jobnum);
 
  xmlTextWriterWriteElement(writer, (xmlChar*)"highest_jobnum", (xmlChar*)tmp);
 
  free(tmp);
 

	
 
  xmlTextWriterEndDocument(writer);
 
  xmlFreeTextWriter(writer);
 
@@ -826,6 +833,7 @@ struct distrenjob *createJobFromXML(stru
 
  _distren_asprintf(&file_name, "stor/job%d/stats.xml", jobnum);
 

	
 
  doc = xmlParseFile(file_name);
 
  free(file_name);
 
  cur = xmlDocGetRootElement(doc);
 

	
 
  distrenjob->total_render_time = (time_t)atol((char*)xmlGetProp(cur, (xmlChar*)"total_render_time"));
 
@@ -850,32 +858,51 @@ struct distrenjob *createJobFromXML(stru
 
int updateJobStatsXML(struct distrenjob *job)
 
{
 
	  xmlTextWriterPtr writer;
 
	  char *tmp; // temporarily holds strings to be given to the xml writer
 
	  char *tmp;
 

	
 
	  _distren_asprintf(&tmp, "stor/job%d/stats.xml", job->jobnum);
 

	
 
	  // create xml document at the location tmp with no compression
 
	  /**
 
	     create xml document at the location tmp with no compression
 
	  */
 
	  writer = xmlNewTextWriterFilename(tmp, 0);
 
	  free(tmp);
 
	  xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
 

	
 
	  xmlTextWriterStartElement(writer, (xmlChar*)"stats");
 
	  _distren_asprintf(&tmp, "%d", job->assigned_frames);
 
	  xmlTextWriterWriteAttribute(writer, (xmlChar*)"assigned_frames", (xmlChar*)tmp);
 
	  free(tmp);
 

	
 
	  _distren_asprintf(&tmp, "%d", job->completed_frames);
 
	  xmlTextWriterWriteAttribute(writer, (xmlChar*)"completed_frames", (xmlChar*)tmp);
 
	  free(tmp);
 

	
 
	  _distren_asprintf(&tmp, "%d", job->total_render_time);
 
	  xmlTextWriterWriteAttribute(writer, (xmlChar*)"total_render_time", (xmlChar*)tmp);
 
	  free(tmp);
 

	
 
	  // end document
 
	  /**
 
	     end document
 
	  */
 
	  xmlTextWriterEndDocument(writer);
 
	  // free writer and save xml file to disk
 
	  /**
 
	     free writer and save xml file to disk
 
	     @TODO confirma that calling xmlFreeTextWriter calls
 
	           write() and close(), respectively.
 
		   (close() causes asynchronous writes to be
 
		   completed).
 
	  */
 
	  xmlFreeTextWriter(writer);
 

	
 
	  return 1;
 
}
 

	
 
// returns 1 if successful
 
// updates job_list.xml which lists all the jobs in the queue
 

	
 
/**
 
   updates job_list.xml which lists all the jobs in the queue
 
   @return 0 means success
 
*/
 
int update_xml_joblist(struct general_info *geninfo)
 
{
 
  struct distrenjob *job;
 
@@ -884,7 +911,9 @@ int update_xml_joblist(struct general_in
 
  char *tmp2;
 
  int counter;
 

	
 
  // update timestamp
 
  /**
 
     update timestamp
 
  */
 
  geninfo->timestamp ++;
 
  if(geninfo->timestamp > 65530)
 
    geninfo->timestamp = 0;
 
@@ -892,11 +921,14 @@ int update_xml_joblist(struct general_in
 
  writer = xmlNewTextWriterFilename("job_list.xml", 0);
 
  xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
 

	
 
  // create root element job_list
 
  /**
 
     create root element job_list
 
  */
 
  xmlTextWriterStartElement(writer, (xmlChar*)"job_list");
 

	
 
  _distren_asprintf(&tmp, "%d", geninfo->timestamp);
 
  xmlTextWriterWriteAttribute(writer, (xmlChar*)"timestamp", (xmlChar*)tmp);
 
  free(tmp);
 

	
 
  geninfo->total_priority_pieces = 0;
 
  counter = 0;
 
@@ -905,8 +937,10 @@ int update_xml_joblist(struct general_in
 
      _distren_asprintf(&tmp, "jobnum%d", counter);
 
      _distren_asprintf(&tmp2, "%d", job->jobnum);
 
      xmlTextWriterWriteElement(writer, (xmlChar*)tmp, (xmlChar*)tmp2);
 
      free(tmp2);
 
      free(tmp);
 

	
 
      /*
 
      /**
 
	this is needed for the new frame finder to work 
 
      
 
	Why the random constant numeral 11? --ohnobinki
 
@@ -916,12 +950,16 @@ int update_xml_joblist(struct general_in
 
      counter++;
 
    }
 

	
 
  // close elements and end document
 
  /**
 
     close elements and end document
 
  */
 
  xmlTextWriterEndDocument(writer);
 

	
 
  // free writer and save xml file to disk
 
  /**
 
     free writer and save xml file to disk
 
  */
 
  xmlFreeTextWriter(writer);
 
  return 1;
 
  return 0;
 
}
 

	
 
/**
 
@@ -933,10 +971,12 @@ int createQueueFromXML(struct general_in
 
{
 
  int tmp;
 

	
 
  xmlDocPtr doc;  // holds xml document in memory
 
  xmlNodePtr cur; // points to the current xml element node
 
  xmlDocPtr doc;
 
  xmlNodePtr cur;
 

	
 
  // load xml document
 
  /**
 
     load xml document
 
  */
 
  doc = xmlParseFile("job_list.xml");
 
  if(doc == NULL)
 
    {
 
@@ -944,7 +984,9 @@ int createQueueFromXML(struct general_in
 
      return 1;
 
    }
 

	
 
  // have cur point to the root element of the xml document pointed to by doc
 
  /**
 
     have cur point to the root element of the xml document pointed to by doc
 
  */
 
  cur = xmlDocGetRootElement(doc);
 
  if(cur == NULL)
 
    {
 
@@ -957,7 +999,9 @@ int createQueueFromXML(struct general_in
 
      fprintf(stderr, "createQueueFromXML: incorrect root element (%s)", (char*)cur->name);
 
    }
 

	
 
  // moves into the children elements of job_list
 
  /**
 
     moves into the children elements of job_list
 
  */
 
  cur = cur->xmlChildrenNode;
 

	
 
  tmp = reCreateQueueFromXML(geninfo, doc, cur);
 
@@ -1036,8 +1080,9 @@ int printFrameInfo(struct frameset *fram
 
  }
 

	
 
  printf("frame #: %d --> %s\n", frame->num, status);
 
  free(status);
 

	
 
  return 1;
 
  return 0;
 
}
 

	
 
int printJob(struct distrenjob *job)
 
@@ -1281,6 +1326,9 @@ int main(int argc, char *argv[])
 
/**
 
   constructs the filename for a distrenjob's serialized XML
 
   to be stored/retrieved from/in.
 
   @return pointer to filename allocated using something
 
           malloc() and free() compatible. Must be free()ed by the
 
	   caller
 
 */
 
char *job_getserialfilename(struct general_info *geninfo, unsigned int jobnum)
 
{
0 comments (0 inline, 0 general)