Changeset - cb26ccfc122d
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 15 years ago 2010-06-26 02:35:21
e@ethanzonca.com
Made conf replacing a bit cleaner
3 files changed with 26 insertions and 13 deletions:
0 comments (0 inline, 0 general)
etc/distrenslave.conf.in
Show inline comments
 
slave
 
{
 
  username = "!username"
 
  password = "!password"
 
  datadir = "@LOCALSTATEDIR@/@PACKAGE@"
 
  server = "protofusion"
 
  hostname = "protofusion.org"
 
}
 

	
 
include("distrencommon.conf")
src/server/simpleslave.c
Show inline comments
 
@@ -54,93 +54,105 @@ int main(int argc, char *argv[])
 

	
 
  /**
 
     initializations
 
  */
 
  datadir = NULL;
 
  server = NULL;
 
  username = NULL;
 
  password = NULL;
 
  hostname = NULL;
 

	
 
  char curopt;
 
  int runBenchmark = 0;
 
  int updateConf = 0;
 

	
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:rh")))
 
  while(((char)-1) != (curopt = getopt(argc, argv, "u:p:rh")))
 
     {
 
       if(curopt == ':')
 
         {
 
           fprintf(stderr, "-%c: is missing an argument\n", optopt);
 
           return 1;
 
         }
 
       else if(curopt == '?')
 
         {
 
           fprintf(stderr, "-%c: invalid option specified\n", optopt);
 
           return 1;
 
         }
 
       else if(curopt == 'h')
 
         {
 
           fprintf(stderr, "Usage: distrensimpleslave [option] \nStarts a distren slave\n\t-u\tset username (run after fresh install)\n\t-r\tRecalculate render power (benchmark)\n\t-h\tshow this help\n");
 
           fprintf(stderr, "Usage: distrensimpleslave [option] \nStarts a distren slave\n\t-u\tset Slave ID/Username (run after fresh install)\n\t-p\tset Slave Passphrase (run after fresh install)\n\t-r\tRecalculate render power (benchmark)\n\t-h\tshow this help\n");
 
           return 2;
 
         }
 
       else if(curopt == 'r')
 
         {
 
           runBenchmark = 1;
 
           break;
 
         }
 
       else if(curopt == 'u')
 
       else if(curopt == 'u'){
 
         username = strdup(optarg);
 
         if(DEBUG)
 
           fprintf(stderr, "Putting username \"%s\" in distrenslave.conf\n", username);
 

	
 
         conf_replace("distrenslave.conf", "!username", username);
 
         fprintf(stderr, "Please invoke distrensimpleslave with no arguments to run with the username you just set\n");
 
         return 0;
 
         updateConf = 1;
 
       }
 
       else if(curopt == 'p'){
 
         password = strdup(optarg);
 
         updateConf = 1;
 
       }
 
     }
 

	
 
if(updateConf){
 
  if(DEBUG)
 
    fprintf(stderr, "Putting Slave ID \"%s\" and Slave Passphrase \"%s\" in distrenslave.conf\n", username, password);
 
  if(username != NULL)
 
    conf_replace("distrenslave.conf", "!username", username);
 
  if(password != NULL)
 
    conf_replace("distrenslave.conf", "!password", password);
 

	
 
  fprintf(stderr, "Please invoke distrensimpleslave with no arguments to run with the slave ID and/or passphrase you just set\n");
 
  return 0;
 
}
 
  /* Get conf data */
 
  options_init(argc, argv, &my_cfg, myopts, "slave", &commonopts);
 

	
 
  if(!datadir)
 
    {
 
      fprintf(stderr, "datadir not set\n");
 
      return 1;
 
    }
 
  if(!server)
 
    {
 
      fprintf(stderr, "server not set\n");
 
      return 1;
 
    }
 
  if(!username)
 
    {
 
      fprintf(stderr, "username not set\n");
 
      fprintf(stderr, "username not set, try the -u flag \n");
 
      return 1;
 
    }
 
  if(!password)
 
    {
 
      fprintf(stderr, "password not set\n");
 
      fprintf(stderr, "password not set, try the -p flag\n");
 
      return 1;
 
    }
 
  if(!hostname)
 
    {
 
      fprintf(stderr, "hostname not set\n");
 
      return 1;
 
    }
 

	
 
  
 
  /* Notifies the user if there no username in .conf */
 
  if(checkUsername(username))
 
    return 1;
 
  if(!strncmp(password, "!password",10))
 
    {
 
      fprintf(stderr, "You haven't specified a password. Please edit distrenslave.conf!\n");
 
      fprintf(stderr, "You haven't specified a password. Please edit distrenslave.conf or try the -p flag!\n");
 
      return 1;
 
    }
 

	
 
  // Variables needed for main loop
 
  int jobnum = 0;
 
  int framenum = 0;
 
  int slavekey = atoi(username); // @TODO: Make this more friendly
 

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

	
src/server/slavefuncs.c
Show inline comments
 
@@ -403,25 +403,25 @@ void prepareJobPaths(int jobnum, int fra
 

	
 
   _distren_asprintf(pathtoRenderOutput, "%s/%s/output/job%d-frame#.%s", datadir, jobdatapath, jobnum, outputExt ); // Note: the # is for blender to put in framenum in output file
 
   _distren_asprintf(pathtoOutput, "%s/%s/output/job%d-frame%d.%s", datadir, jobdatapath, jobnum, framenum, outputExt ); // Note: the # is for blender to put in framenum in output file
 

	
 
   _distren_asprintf(pathtoOutdir, "%s/%s/output", datadir, jobdatapath);
 
   free(jobdatapath);
 
}
 

	
 
int checkUsername(char *username)
 
{
 
  if(username == NULL || strcmp(username, "!username") == 0 )
 
    {
 
     fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf\n");
 
     fprintf(stderr, "\nPlease ensure that your username is present in distrenslave.conf, or use the -u flag to set a username.\n");
 
     return 1;
 
   }
 
   else
 
     if( username != NULL || strcmp(username, "!username") != 0 )
 
       {
 
         // Log in the user
 
         if(login_user(username) == 1){
 
           // Logged in OK
 
           return 0;
 
         }
 
         else
 
           {
0 comments (0 inline, 0 general)