Ignore:
Timestamp:
Sep 20, 2013, 2:29:57 PM (11 years ago)
Author:
Bruno Cornec
Message:

Simplify the interface of mr_getline and mr_asprintf. With 3.1 compatibility now will allow backports from this branch into 3.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/mondorestore/mondo-prep.c

    r3071 r3185  
    335335            log_it("%s... so I'll get creative.", tmp);
    336336            if (lvmversion == 2) {
    337                 mr_asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);
     337                mr_asprintf(tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);
    338338                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    339339                free(tmp1);
    340340            } else {
    341                 mr_asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);
     341                mr_asprintf(tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);
    342342                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    343343                free(tmp1);
     
    586586    // create device list from normal disks followed by spare ones
    587587    if (raidlist->el[i].data_disks.el[0].device != NULL) {
    588         mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);
     588        mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device);
    589589        log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device);
    590590    } else {
     
    602602    // translate RAID level
    603603    if (raidlist->el[i].raid_level == -2) {
    604       mr_asprintf(&level, "multipath");
     604      mr_asprintf(level, "multipath");
    605605    } else if (raidlist->el[i].raid_level == -1) {
    606       mr_asprintf(&level, "linear");
     606      mr_asprintf(level, "linear");
    607607    } else {
    608       mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     608      mr_asprintf(level, "raid%d", raidlist->el[i].raid_level);
    609609    }
    610610    // create RAID device:
     
    614614    // - persistent superblock always used as this is recommended
    615615
    616     mr_asprintf(&program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries);
     616    mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries);
    617617    mr_free(level);
    618618    log_msg(4, "cmd built: %s", program);
     
    718718
    719719    if (strstr(format, "raid")) {   // do not form RAID disks; do it to /dev/md* instead
    720         mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device);
     720        mr_asprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
    721721        log_it(tmp);
    722722        paranoid_free(tmp);
     
    733733#endif
    734734    if (strlen(format) <= 2) {
    735         mr_asprintf(&tmp, "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", device, format);
     735        mr_asprintf(tmp, "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", device, format);
    736736        log_it(tmp);
    737737        paranoid_free(tmp);
     
    740740    }
    741741    if (is_this_device_mounted(device)) {
    742         mr_asprintf(&tmp, "%s is mounted - cannot format it      ", device);
     742        mr_asprintf(tmp, "%s is mounted - cannot format it       ", device);
    743743        log_to_screen(tmp);
    744744        paranoid_free(tmp);
     
    771771            char line[MAX_STR_LEN];
    772772
    773             mr_asprintf(&tmp, "Initializing Vinum device %s (this may take a *long* time)", device);
     773            mr_asprintf(tmp, "Initializing Vinum device %s (this may take a *long* time)", device);
    774774            log_to_screen(tmp);
    775775            paranoid_free(tmp);
     
    789789                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    790790
    791                 mr_asprintf(&tmp, "Initializing plex: %s", line);
     791                mr_asprintf(tmp, "Initializing plex: %s", line);
    792792                open_evalcall_form(tmp);
    793793                paranoid_free(tmp);
    794794
    795                 mr_asprintf(&tmp, "vinum init %s", line);
     795                mr_asprintf(tmp, "vinum init %s", line);
    796796                paranoid_system(tmp);
    797797                paranoid_free(tmp);
    798798
    799799                while (1) {
    800                     mr_asprintf(&tmp, "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", line);
     800                    mr_asprintf(tmp, "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", line);
    801801                    FILE *pin = popen(tmp, "r");
    802802                    paranoid_free(tmp);
     
    820820        }
    821821#else
    822         mr_asprintf(&tmp, "Initializing RAID device %s", device);
     822        mr_asprintf(tmp, "Initializing RAID device %s", device);
    823823        log_to_screen(tmp);
    824824        paranoid_free(tmp);
     
    871871    }
    872872    res = which_format_command_do_i_need(format, program);
    873     mr_asprintf(&tmp, "%s %s", program, device);
     873    mr_asprintf(tmp, "%s %s", program, device);
    874874    if (strstr(program, "kludge")) {
    875875        mr_strcat(tmp, " /");
     
    878878    paranoid_free(tmp);
    879879
    880     mr_asprintf(&tmp, "Formatting %s as %s", device, format);
     880    mr_asprintf(tmp, "Formatting %s as %s", device, format);
    881881    update_progress_form(tmp);
    882882    paranoid_free(tmp);
     
    892892
    893893    if (res && strstr(program, "kludge")) {
    894         mr_asprintf(&tmp, "Kludge failed; using regular mkfs.%s to format %s",
     894        mr_asprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
    895895                format, device);
    896896#ifdef __FreeBSD__
     
    17051705        paranoid_system(tmp);
    17061706        // mark relevant partition as bootable
    1707         mr_asprintf(&tmp1,"make-me-bootable /tmp/mountlist.txt %s",drivename);
     1707        mr_asprintf(tmp1,"make-me-bootable /tmp/mountlist.txt %s",drivename);
    17081708        call_program_and_get_last_line_of_output(tmp1);
    17091709        mr_free(tmp1);
     
    18171817    /* BERLIOS: should not be called each time */
    18181818    part_table_fmt = which_partition_format(drive);
    1819     mr_asprintf(&output, "");
     1819    mr_asprintf(output, "");
    18201820    /* make it a primary/extended/logical */
    18211821    if (partno <= 4) {
     
    21692169            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    21702170        } else {
    2171             mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
     2171            mr_asprintf(output, "t\n%d\n%s\nw\n", partno, partcode);
    21722172            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
    21732173                    MONDO_LOGFILE, MONDO_LOGFILE);
     
    25192519        return;
    25202520    }
    2521     mr_asprintf(&tmp, "Expanding entries to suit drive %s (%lld MB)", drive_name, current_size_of_drive / 1024);
     2521    mr_asprintf(tmp, "Expanding entries to suit drive %s (%lld MB)", drive_name, current_size_of_drive / 1024);
    25222522    log_to_screen(tmp);
    25232523    mr_free(tmp);
     
    25392539
    25402540    if (original_size_of_drive <= 0LL) {
    2541         mr_asprintf(&tmp, "Cannot resize %s's entries. Drive not found.", drive_name);
     2541        mr_asprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name);
    25422542        log_to_screen(tmp);
    25432543        mr_free(tmp);
     
    25452545    }
    25462546    factor = ((float)current_size_of_drive/(float)original_size_of_drive);
    2547     mr_asprintf(&tmp, "Disk %s was %lld MB; is now %lld MB; Proportionally resizing partitions (factor ~= %.5f)",
     2547    mr_asprintf(tmp, "Disk %s was %lld MB; is now %lld MB; Proportionally resizing partitions (factor ~= %.5f)",
    25482548            drive_name, original_size_of_drive/1024, current_size_of_drive/1024, factor);
    25492549    log_to_screen(tmp);
     
    25722572        totalsizL += newsizL;
    25732573
    2574         mr_asprintf(&tmp, "Changing %s from %lld KB to %lld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size, newsizL);
     2574        mr_asprintf(tmp, "Changing %s from %lld KB to %lld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size, newsizL);
    25752575        log_to_screen(tmp);
    25762576        mr_free(tmp);
     
    25792579    // Ensures over-allocation alert and prompt for interactive mode does not happen
    25802580    if (totalsizL > current_size_of_drive) {
    2581         mr_asprintf(&tmp, "Last partition size calculated would be over-allocated, reducing %s from %lld KB to %lld KB.", drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size - (totalsizL - current_size_of_drive));
     2581        mr_asprintf(tmp, "Last partition size calculated would be over-allocated, reducing %s from %lld KB to %lld KB.", drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size - (totalsizL - current_size_of_drive));
    25822582        drivemntlist->el[drivemntlist->entries-1]->size -= (totalsizL - current_size_of_drive);
    25832583    } else if (totalsizL < current_size_of_drive) {
    2584         mr_asprintf(&tmp, "Last partition size calculated would be under-allocated, increasing %s from %lld KB to %lld KB.",drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size + (current_size_of_drive - totalsizL));
     2584        mr_asprintf(tmp, "Last partition size calculated would be under-allocated, increasing %s from %lld KB to %lld KB.",drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size + (current_size_of_drive - totalsizL));
    25852585        drivemntlist->el[drivemntlist->entries-1]->size += (current_size_of_drive - totalsizL);
    25862586    }
    25872587    log_to_screen(tmp);
    25882588    mr_free(tmp);
    2589     mr_asprintf(&tmp, "final_size = %lld MB", current_size_of_drive / 1024);
     2589    mr_asprintf(tmp, "final_size = %lld MB", current_size_of_drive / 1024);
    25902590    log_to_screen(tmp);
    25912591    mr_free(tmp);
Note: See TracChangeset for help on using the changeset viewer.