Changeset 2972


Ignore:
Timestamp:
Mar 27, 2012, 2:48:08 PM (7 years ago)
Author:
bruno
Message:
  • Uses mr_strcat again instead of multiple mr_asprintf
  • Generats the correct mdadm create command when using UUID for fixing #596. Needs to be checked
  • More valgrind warning reported that may be fixed here.
Location:
branches/3.0/mondo/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-filelist.c

    r2970 r2972  
    13371337    char *skip_these;
    13381338    char *new_with_pipe;
    1339     char *strtmp;
    1340     char *token;
     1339    char *strtmp = NULL;
     1340    char *token = NULL;
    13411341    char *find_excludes = NULL;
    13421342    static char *name_of_evalcall_form;
     
    13661366        malloc_string(name_of_evalcall_form);
    13671367        malloc_string(find_skeleton_marker);
    1368         while((token = mr_strtok(sth, delims, &lastpos))) {
    1369           mr_asprintf(&strtmp,"%s", find_excludes);
    1370           paranoid_free(find_excludes);
    1371           mr_asprintf(&find_excludes,"%s -path %s -prune -o", strtmp, token);
    1372           paranoid_free(strtmp);
     1368        while((token = mr_strtok(sth, delims, &lastpos)) != NULL) {
     1369          mr_strcat(find_excludes," -path %s -prune -o", token);
    13731370          mr_free(token);
    13741371        }
  • branches/3.0/mondo/src/lib/mr_str.c

    r2970 r2972  
    3030
    3131    if (instr == NULL) {
     32        *lastpos = 0;
     33        return token;
     34    }
     35
     36    if (delims == NULL) {
    3237        *lastpos = 0;
    3338        return token;
  • branches/3.0/mondo/src/mondorestore/mondo-prep.c

    r2943 r2972  
    556556  int i   = 0;
    557557  int j   = 0;
     558  int v   = 0;
    558559  int res = 0;
    559560 
    560561  /** buffers ***********************************************************/
    561562  char *devices = NULL;
    562   char *strtmp  = NULL;
    563563  char *level   = NULL;
    564564  char *program = NULL;
     
    590590  mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);
    591591  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    592     mr_asprintf(&strtmp, "%s", devices);
    593     paranoid_free(devices);
    594     mr_asprintf(&devices, "%s %s", strtmp,
    595          raidlist->el[i].data_disks.el[j].device);
    596     paranoid_free(strtmp);
     592    mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device);
    597593  }
    598594  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    599     mr_asprintf(&strtmp, "%s", devices);
    600     paranoid_free(devices);
    601     mr_asprintf(&devices, "%s %s", strtmp,
    602          raidlist->el[i].spare_disks.el[j].device);
    603     paranoid_free(strtmp);
     595    mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device);
    604596  }
    605597  // translate RAID level
     
    641633  mr_asprintf(&program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d %s", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries, oldmd);
    642634  mr_free(oldmd);
     635  mr_free(level);
     636  // Restoring the UUID stored at backup time of present
     637  for (v = 0; v++ ; v <= raidlist->el[i].additional_vars.entries) {
     638    if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) {
     639        // We have a UUID to handle
     640        if (raidlist->el[i].additional_vars.el[v].value != NULL) {
     641            // force its restoration in order to avoid modifying all conf files using it
     642            mr_strcat(program, " --update=uuid --uuid %s",raidlist->el[i].additional_vars.el[v].value);
     643            break;
     644        }
     645    }
     646  }
    643647  if (raidlist->el[i].parity != -1) {
    644     mr_asprintf(&strtmp, "%s", program);
    645     paranoid_free(program);
    646648    switch(raidlist->el[i].parity) {
    647649    case 0:
    648       mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
     650      mr_strcat(program, " --parity=%s", "la");
    649651      break;
    650652    case 1:
    651       mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
     653      mr_strcat(program, " --parity=%s", "ra");
    652654      break;
    653655    case 2:
    654       mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
     656      mr_strcat(program, " --parity=%s", "ls");
    655657      break;
    656658    case 3:
    657       mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
     659      mr_strcat(program, " --parity=%s", "rs");
    658660      break;
    659661    default:
     
    661663      break;
    662664    }
    663     paranoid_free(strtmp);
    664665  }
    665666  if (raidlist->el[i].chunk_size != -1) {
    666     mr_asprintf(&strtmp, "%s", program);
    667     paranoid_free(program);
    668     mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
    669     paranoid_free(strtmp);
     667    mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size);
    670668  }
    671669  if (raidlist->el[i].spare_disks.entries > 0) {
    672     mr_asprintf(&strtmp, "%s", program);
    673     paranoid_free(program);
    674     mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    675          raidlist->el[i].spare_disks.entries);
    676     paranoid_free(strtmp);
     670    mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries);
    677671  }
    678   mr_asprintf(&strtmp, "%s", program);
    679   paranoid_free(program);
    680   mr_asprintf(&program, "%s %s", strtmp, devices);
    681   paranoid_free(strtmp);
     672  mr_strcat(program, " %s", devices);
    682673  res = run_program_and_log_output(program, 1);
    683674  // free memory
    684   paranoid_free(devices);
    685   paranoid_free(level);
    686   paranoid_free(program);
     675  mr_free(devices);
     676  mr_free(program);
    687677  // return to calling instance
    688678  return res;
Note: See TracChangeset for help on using the changeset viewer.