Changeset - 815127c2345a
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-05-29 07:41:03
ohnobinki@ohnopublishing.net
added some error checking to client
1 file changed with 21 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/client/distren.c
Show inline comments
 
@@ -75,57 +75,74 @@ int main(int argc, char *argv[])
 
      else if(curopt == 'i')
 
	/* 
 
	   TODO: is strdup good or bad? what about 
 
	   the idea that all libs should allow plugging different
 
	   malloc/free implementations in?
 
	 */
 
	input = strdup(optarg);
 
      else if(curopt == 'o')
 
	output = strdup(optarg);
 
    } 
 

	
 
  /* 
 
     give this error after the general arguments parsing so that
 
     the general help from options_init can have effect 
 
  */
 
  if(!input
 
     || !output)
 
    {
 
      fprintf(stderr, "Input and output files must be specified\n");
 
      return 1;
 
    }
 

	
 
  fprintf(stderr, "reading from %s\nwriting to %s\n", input, output);
 
  
 
  distren_init_mf(&distren, &malloc, &free);
 
  if(distren_init_mf(&distren, &malloc, &free))
 
    {
 
      fprintf(stderr, "error initializing distren handle\n");
 
      return 1;
 
    }
 
  
 
  distren_submit_file(distren, &distren_job, input);
 
  if(distren_submit_file(distren, &distren_job, input))
 
    {
 
      fprintf(stderr, "error submitting file\n");
 
      return 1;
 
    } 
 
  
 
  distren_job_getid(distren_job, &jobid);
 
  if(distren_job_getid(distren_job, &jobid))
 
    {
 
      fprintf(stderr, "error retrieving job id\n");
 
      return 1;
 
    }
 
  fprintf(stdout, "jobid: %s\n", jobid);
 

	
 
  distren_job_retrieve_file(distren_job, output);
 
  if(distren_job_retrieve_file(distren_job, output))
 
    {
 
      fprintf(stderr, "error retrieving output file\n");
 
      return 1;
 
    }
 

	
 
  /* if these following lines fail, it'll be reported as a core dump ;-) */
 
  distren_job_free(distren_job);
 
  
 
  distren_free(distren);
 
  
 

	
 
  // Please find a better way of doing this :( you can't strcat multiple strings.. meh
 
  // use something like sprintf
 
  //char *username = cfg_getstr(cfg, "username");
 
  //char *hostname = cfg_getstr(cfg, "hostname");
 
  //strcat(username, "@");
 
  //strcat(username, hostname);
 

	
 
  // SSH's to client machine with the username speficied.
 
    char buf[10];
 
    struct execio *testrem;
 
    char *execargv[] =
 
      {
 
	"ssh",
 
	"username", //cfg_getstr(cfg, "username") . "@" . cfg_getstr(cfg, "hostname"),
 
	"-i guest.rsa", //yeaaaah any better ideas?
 
	"sh",
 
	"-c",
 
	"\"echo hello from ${HOSTNAME}\"", // "\"useradd -M -c" strcat( cfg_getstr(cfg, "name") cfg_getstr(cfg, "email")) "-d /home/distren --gid 537" cfg_getstr(cfg, "username") "\"",
 
	(char *)NULL
0 comments (0 inline, 0 general)