diff --git a/src/server/slave.c b/src/server/slave.c --- a/src/server/slave.c +++ b/src/server/slave.c @@ -54,22 +54,6 @@ int main(int argc, char *argv[]) struct options_common *commonopts; - int jobnum = 0; - int framenum = 0; - - 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) */ - - char *tarcmd; /* Command to run for tar. Migrate to libtar sometime */ - char *outdir; /* Output Directory for tar */ - char *jobdatapath; /* Path to job data */ - struct distrenjob *myjob; /* Structure to hold data gathered from the XML file */ struct remoteio *comm_slave; @@ -134,11 +118,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n"); } - - - fprintf(stderr, "Loading config...\n"); - - fprintf(stderr, "Connecting to server...\n"); tmp = remoteio_open(&comm_slave, commonopts->remoteio, server); if(tmp) @@ -147,9 +126,28 @@ int main(int argc, char *argv[]) return 1; } - int haveWork = 0; + + // Variables needed for main loop + int jobnum = 0; + int framenum = 0; + + 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 *pathtoOutput; /* Full path to the output (rendered) file */ - while(1) + char *pathtoJobfile; /* Full path to the job's main file */ + char *pathtoXml; /* Full path to the job's xml file */ + char *outputExt; /* Output Extension (e.g., JPG) */ + + char *jobdatapath; /* Path to job data */ + + int haveWork = 0; + int quit = 0; + + // Main loop + while(!quit) { // request work @@ -179,15 +177,7 @@ int main(int argc, char *argv[]) if(downloadTar(urltoTar, pathtoTar)) return 1; - _distren_asprintf(&outdir, "/tmp/distren/job%d", jobnum); - mkdir("/tmp/distren", 0750); /* @FIXME: Change to tmpdir once it exists */ - mkdir(outdir, 0750); - - _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @FIXME:Use a lib here! */ - system(tarcmd); - free(tarcmd); - free(pathtoTar); - free(outdir); + unpackJob(pathtoTar, jobnum); /* Parses a job's XML file, puts data in the myjob struct */ if(distrenjob_unserialize(&myjob, pathtoXml) == 0) @@ -221,7 +211,6 @@ int main(int argc, char *argv[]) /* Post-execution */ fprintf(stderr, "Finished frame %d in job %d, uploading...\n", framenum, jobnum); - uploadOutput(pathtoOutput, urltoOutput); // @TODO: Handle return value free(urltoOutput);