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); diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -386,3 +386,20 @@ int uploadOutput(char *pathtoOutput, cha // @FUTURE: Keep track of files that we were unable to upload, and upload them later } } + + +int unpackJob(char *pathtoTar, int jobnum){ + char *tarcmd; /* Command to run for tar. Migrate to libtar sometime */ + char *outdir; /* Output Directory for tar */ + + _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); + return 0; +} diff --git a/src/server/slavefuncs.h b/src/server/slavefuncs.h --- a/src/server/slavefuncs.h +++ b/src/server/slavefuncs.h @@ -48,5 +48,6 @@ int distren_mkdir_recurse(char *dirname) int job_build_path(char *filename, unsigned int jobnum); int downloadTar(char *url, char *destinationPath); int uploadOutput(char *pathtoOutput, char *urltoOutput); +int unpackJob(char *pathtoTar, int jobnum); #endif