# HG changeset patch # User Binki # Date 2009-12-19 22:22:06 # Node ID 09d5f6b5dbd24015d48f0b3d8083b252227a3ab0 # Parent e1169a0b7eae3e648d266d05cd4a7813833f1206 makeJobDataXML() --> distrenjob_serialize(), missing free()s diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -78,7 +78,7 @@ void distrenjob_remove(struct general_in struct distrenjob *distrenjob_get(struct distrenjob *head, jobnum_t jobnum); int distrenjob_enqueue(struct general_info *, struct distrenjob *job); int mortition(struct general_info *, struct distrenjob *job); -int makeJobDataXML(struct distrenjob *job); +int distrenjob_serialize(struct general_info *geninfo, struct distrenjob *job); int update_xml_joblist(struct general_info *); int createQueueFromXML(struct distrenjob *head); int reCreateQueueFromXML(struct distrenjob *head, xmlDocPtr doc, xmlNodePtr current); @@ -276,8 +276,8 @@ int prepare_distrenjob(struct general_in fprintf(stderr, "creating dir '%s'", path_with_num); /* add job to queue */ - fprintf(stderr, "\nprepare_distrenjob: attempting makeJobDataXML()\n"); - makeJobDataXML(distrenjob); + fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_serialize()\n"); + distrenjob_serialize(geninfo, distrenjob); fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_enqueue()\n"); distrenjob_enqueue(geninfo, distrenjob); @@ -357,7 +357,7 @@ int change_job_priority(struct general_i update_xml_joblist(geninfo); - makeJobDataXML(job); // because priority is changed + distrenjob_serialize(geninfo, job); // because priority is changed return 0; } @@ -736,54 +736,87 @@ int import_general_info(struct general_i return 0; } -// returns 1 on successful completion of xml file -// creates the xml file that slaves read from, and is used to restart distren -int makeJobDataXML(struct distrenjob *job) +/** + serializes a distrenjob into XML +*/ +int distrenjob_serialize(struct general_info *geninfo, struct distrenjob *job) { xmlTextWriterPtr writer; - char *tmp; // temporarily holds strings to be given to the xml writer + char *tmp; + char *tmpfile; + char *outfile; + int tmprtn; - _distren_asprintf(&tmp, "stor/job%d/job_info.xml", job->jobnum); + _distren_asprintf(&tmpfile, "%s/stor/job%d/.job_info.xml", geninfo->config->datadir, job->jobnum); - // create xml document at the location tmp with no compression - writer = xmlNewTextWriterFilename(tmp, 0); + /* create xml document at the location tmp with no compression */ + writer = xmlNewTextWriterFilename(tmpfile, 0); xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); - // write distrenjob element and add its attributes + /** + write distrenjob element and add its attributes */ xmlTextWriterStartElement(writer, (xmlChar*)"job"); xmlTextWriterWriteAttribute(writer, (xmlChar*)"name", (xmlChar*)job->name); xmlTextWriterWriteAttribute(writer, (xmlChar*)"submitter", (xmlChar*)job->submitter); _distren_asprintf(&tmp, "%d", job->priority); xmlTextWriterWriteAttribute(writer, (xmlChar*)"priority", (xmlChar*)tmp); + free(tmp); - // write resolution element and add its attributes + /** + write resolution element and add its attributes */ xmlTextWriterStartElement(writer, (xmlChar*)"resolution"); _distren_asprintf(&tmp, "%d", job->width); xmlTextWriterWriteAttribute(writer, (xmlChar*)"width", (xmlChar*)tmp); + free(tmp); + _distren_asprintf(&tmp, "%d", job->height); xmlTextWriterWriteAttribute(writer, (xmlChar*)"height", (xmlChar*)tmp); + free(tmp); + xmlTextWriterEndElement(writer); - // write video element and its attributes + /** + write video element and its attributes */ xmlTextWriterStartElement(writer, (xmlChar*)"video"); _distren_asprintf(&tmp, "%d", job->frameset[0].num); xmlTextWriterWriteAttribute(writer, (xmlChar*)"start_frame", (xmlChar*)tmp); + free(tmp); + _distren_asprintf(&tmp, "%d", job->frameset[(job->total_frames - 1)].num); xmlTextWriterWriteAttribute(writer, (xmlChar*)"end_fame", (xmlChar*)tmp); + free(tmp); + xmlTextWriterWriteAttribute(writer, (xmlChar*)"output_format", (xmlChar*)job->output_format); xmlTextWriterEndElement(writer); - // write watchdog forgiveness element + /** + write watchdog forgiveness element */ _distren_asprintf(&tmp, "%d", job->watchdog_forgiveness); xmlTextWriterWriteElement(writer, (xmlChar*)"wd_forgiveness", (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 */ xmlFreeTextWriter(writer); - return 1; + _distren_asprintf(&outfile, "%s/stor/job%d/job_info.xml", geninfo->config->datadir, job->jobnum); + tmprtn = rename(tmpfile, outfile); + if(tmprtn == -1) + { + fprintf(stderr, "%s:%d: Error renaming ``%s'' to ``%s''\n", + __FILE__, __LINE__, + tmpfile, outfile); + perror("rename"); + tmprtn = 1; + } + free(tmpfile); + free(outfile); + + return tmprtn; } // extracts data from the xml created by above function and creates a job from it