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/common/libmondo-mountlist.c

    r3060 r3185  
    7272    /*@ initialize ***************************************************** */
    7373    prev_part_no = 0;
    74     mr_asprintf(&flaws_str, "%s", "");
     74    mr_asprintf(flaws_str, "%s", "");
    7575
    7676
     
    7878
    7979    if (physical_drive_size < 0) {
    80         mr_asprintf(&tmp, " %s does not exist.", drive);
     80        mr_asprintf(tmp, " %s does not exist.", drive);
    8181        mr_strcat(flaws_str, "%s", tmp);
    8282    } else {
    83         mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
     83        mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
    8484    }
    8585    log_it(tmp);
     
    103103            /* is it too big? */
    104104            if (curr_part_no > 'h') {
    105                 mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
     105                mr_asprintf(tmp, " Can only have up to 'h' in disklabel.");
    106106                log_it(tmp);
    107107                mr_strcat(flaws_str, tmp);
     
    117117            }
    118118            if (device_copies > 1) {
    119                 mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
     119                mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
    120120                if (!strstr(flaws_str, tmp)) {
    121121                    log_it(tmp);
     
    128128            if (mountlist->el[pos].size < 8192
    129129                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    130                 mr_asprintf(&tmp, " %s is tiny!", device);
     130                mr_asprintf(tmp, " %s is tiny!", device);
    131131                log_it(tmp);
    132132                mr_strcat(flaws_str, tmp);
     
    141141                && strcmp(mountlist->el[pos].mountpoint, "none")
    142142                && mountlist->el[pos].mountpoint[0] != '/') {
    143                 mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
     143                mr_asprintf(tmp, " %s has a weird mountpoint.", device);
    144144                log_it(tmp);
    145145                mr_strcat(flaws_str, tmp);
     
    149149            /* is format sensible? */
    150150            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    151                 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     151                mr_asprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    152152                log_it(tmp);
    153153                mr_strcat(flaws_str, tmp);
     
    181181            if (curr_part_no - prev_part_no > 1) {
    182182                if (prev_part_no == 0) {
    183                     mr_asprintf(&tmp, " Gap prior to %s.", device);
     183                    mr_asprintf(tmp, " Gap prior to %s.", device);
    184184                    log_it(tmp);
    185185                    mr_strcat(flaws_str, "%s", tmp);
     
    188188                } else if (curr_part_no > 5
    189189                           || (curr_part_no <= 4 && prev_part_no > 0)) {
    190                     mr_asprintf(&tmp, " Gap between %ss%d and %d.", drive, prev_part_no, curr_part_no);
     190                    mr_asprintf(tmp, " Gap between %ss%d and %d.", drive, prev_part_no, curr_part_no);
    191191                    log_it(tmp);
    192192                    mr_strcat(flaws_str, "%s", tmp);
     
    200200            if ((curr_part_no >= 5 && prev_part_no == 4)
    201201                && (strcmp(part_table_fmt, "MBR") == 0)) {
    202                 mr_asprintf(&tmp, " Partition %ss4 is occupied.", drive);
     202                mr_asprintf(tmp, " Partition %ss4 is occupied.", drive);
    203203                log_it(tmp);
    204204                mr_strcat(flaws_str, "%s", tmp);
     
    214214            }
    215215            if (device_copies > 1) {
    216                 mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
     216                mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
    217217                if (!strstr(flaws_str, "%s", tmp)) {
    218218                    log_it(tmp);
     
    225225            if (mountlist->el[pos].size < 8192
    226226                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    227                 mr_asprintf(&tmp, " %s is tiny!", device);
     227                mr_asprintf(tmp, " %s is tiny!", device);
    228228                log_it(tmp);
    229229                mr_strcat(flaws_str, "%s", tmp);
     
    238238                && strcmp(mountlist->el[pos].mountpoint, "none")
    239239                && mountlist->el[pos].mountpoint[0] != '/') {
    240                 mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
     240                mr_asprintf(tmp, " %s has a weird mountpoint.", device);
    241241                log_it(tmp);
    242242                mr_strcat(flaws_str, "%s", tmp);
     
    246246            /* is format sensible? */
    247247            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    248                 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     248                mr_asprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    249249                log_it(tmp);
    250250                mr_strcat(flaws_str, "%s", tmp);
     
    263263                /* is it too big? */
    264264                if (curr_part_no > 'h') {
    265                     mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
     265                    mr_asprintf(tmp, " Can only have up to 'h' in disklabel.");
    266266                    log_it(tmp);
    267267                    mr_strcat(flaws_str, "%s", tmp);
     
    277277                }
    278278                if (device_copies > 1) {
    279                     mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
     279                    mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
    280280                    if (!strstr(flaws_str, tmp)) {
    281281                        log_it(tmp);
     
    288288                if (mountlist->el[pos].size < 8192
    289289                    && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    290                     mr_asprintf(&tmp, " %s is tiny!", device);
     290                    mr_asprintf(tmp, " %s is tiny!", device);
    291291                    log_it(tmp);
    292292                    mr_strcat(flaws_str, "%s", tmp);
     
    301301                    && strcmp(mountlist->el[pos].mountpoint, "none")
    302302                    && mountlist->el[pos].mountpoint[0] != '/') {
    303                     mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
     303                    mr_asprintf(tmp, " %s has a weird mountpoint.", device);
    304304                    log_it(tmp);
    305305                    mr_strcat(flaws_str, "%s", tmp);
     
    310310                if (!is_this_a_valid_disk_format
    311311                    (mountlist->el[pos].format)) {
    312                     mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     312                    mr_asprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    313313                    log_it(tmp);
    314314                    mr_strcat(flaws_str, "%s", tmp);
     
    327327        if (amount_allocated > physical_drive_size) {
    328328            // Used to be +1, but what if you're 1 MB too high?
    329             mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
     329            mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    330330                    amount_allocated - physical_drive_size, drive);
    331331            log_it(tmp);
     
    349349    /* Over-allocated the disk? Unallocated space on disk? */
    350350    if (amount_allocated < physical_drive_size - 1) {   /* NOT AN ERROR, JUST A WARNING :-) */
    351         mr_asprintf(&tmp, " %ld MB unallocated on %s.",
     351        mr_asprintf(tmp, " %ld MB unallocated on %s.",
    352352                physical_drive_size - amount_allocated, drive);
    353353        log_it(tmp);
     
    389389    assert_string_is_neither_NULL_nor_zerolength(drive);
    390390    assert(mountlist != NULL);
    391     mr_asprintf(&flaws_str, "%s", "");
     391    mr_asprintf(flaws_str, "%s", "");
    392392
    393393    malloc_string(device);
     
    398398    if (physical_drive_size < 0) {
    399399        if (strstr(drive,"/dev/dm-") == NULL) {
    400             mr_asprintf(&tmp, " %s does not exist.", drive);
     400            mr_asprintf(tmp, " %s does not exist.", drive);
    401401            log_it(tmp);
    402402            mr_strcat(flaws_str, "%s", tmp);
     
    405405            goto endoffunc;
    406406        } else {
    407             mr_asprintf(&tmp, " %s (dm) will be setup later on", drive);
     407            mr_asprintf(tmp, " %s (dm) will be setup later on", drive);
    408408            log_it(tmp);
    409409            mr_free(tmp);
    410410        }
    411411    } else {
    412         mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
     412        mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
    413413        log_it(tmp);
    414414        mr_free(tmp);
     
    425425        if (curr_part_no - prev_part_no > 1) {
    426426            if (prev_part_no == 0) {
    427                 mr_asprintf(&tmp, " Gap prior to %s.", device);
     427                mr_asprintf(tmp, " Gap prior to %s.", device);
    428428                log_it(tmp);
    429429                mr_strcat(flaws_str, "%s", tmp);
     
    432432            } else if (curr_part_no > 5
    433433                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    434                 mr_asprintf(&tmp, " Gap on %s between %d and %d.", drive,
     434                mr_asprintf(tmp, " Gap on %s between %d and %d.", drive,
    435435                        prev_part_no, curr_part_no);
    436436                log_it(tmp);
     
    445445        if ((curr_part_no >= 5 && prev_part_no == 4)
    446446            && (strcmp(part_table_fmt, "MBR") == 0)) {
    447             mr_asprintf(&tmp, " Partition 4 of %s is occupied.", drive);
     447            mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive);
    448448            log_it(tmp);
    449449            mr_strcat(flaws_str, "%s", tmp);
     
    459459        }
    460460        if (device_copies > 1) {
    461             mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
     461            mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies),
    462462                    device);
    463463            if (!strstr(flaws_str, tmp)) {
     
    471471        if (mountlist->el[pos].size < 8192
    472472            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    473             mr_asprintf(&tmp, " %s is tiny!", device);
     473            mr_asprintf(tmp, " %s is tiny!", device);
    474474            log_it(tmp);
    475475            mr_strcat(flaws_str, "%s", tmp);
     
    483483            && strcmp(mountlist->el[pos].mountpoint, "image")
    484484            && mountlist->el[pos].mountpoint[0] != '/') {
    485             mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
     485            mr_asprintf(tmp, " %s has a weird mountpoint.", device);
    486486            log_it(tmp);
    487487            mr_strcat(flaws_str, "%s", tmp);
     
    491491        /* is format sensible? */
    492492        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    493             mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     493            mr_asprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    494494            log_it(tmp);
    495495            mr_strcat(flaws_str, "%s", tmp);
     
    504504    /* Over-allocated the disk? Unallocated space on disk? */
    505505    if (amount_allocated > physical_drive_size + 1) {
    506         mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
     506        mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    507507                amount_allocated - physical_drive_size, drive);
    508508        log_it(tmp);
     
    511511        res++;
    512512    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    513         mr_asprintf(&tmp, " %ld MB unallocated on %s.",
     513        mr_asprintf(tmp, " %ld MB unallocated on %s.",
    514514                physical_drive_size - amount_allocated, drive);
    515515        log_it(tmp);
     
    570570            (drivelist->el[i].device,
    571571             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
    572             mr_asprintf(&tmp, " Not evaluating %s (I don't know how yet)", drivelist->el[i].device);
     572            mr_asprintf(tmp, " Not evaluating %s (I don't know how yet)", drivelist->el[i].device);
    573573            log_it(tmp);
    574574            paranoid_free(tmp);
     
    588588    /* Look for duplicate mountpoints in mountlist. */
    589589    for (currline = 0; currline < mountlist->entries; currline++) {
    590         mr_asprintf(&curr_mountpoint, "%s", mountlist->el[currline].mountpoint);
     590        mr_asprintf(curr_mountpoint, "%s", mountlist->el[currline].mountpoint);
    591591        for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; i++) {
    592592            if (!strcmp(mountlist->el[i].mountpoint, curr_mountpoint)
     
    599599        if (copies > 1 && last_copy == currline
    600600            && strcmp(curr_mountpoint, "raid")) {
    601             mr_asprintf(&tmp, " %s %s's.", number_to_text(copies), curr_mountpoint);
     601            mr_asprintf(tmp, " %s %s's.", number_to_text(copies), curr_mountpoint);
    602602            mr_strcat(flaws_str, "%s", tmp);
    603603            log_msg(8,"Adding: %s to flaws_str", tmp);
     
    666666    for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
    667667
    668         mr_asprintf(&drive, "%s", mountlist->el[lino].device);
     668        mr_asprintf(drive, "%s", mountlist->el[lino].device);
    669669        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    670670            log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);
     
    753753                       (void *) &mountlist->el[i],
    754754                       sizeof(struct mountlist_line));
    755                 mr_asprintf(&tmp, "%s is available; user may choose to add it to raid device", output_list->el[items - 1].device);
     755                mr_asprintf(tmp, "%s is available; user may choose to add it to raid device", output_list->el[items - 1].device);
    756756                log_it(tmp);
    757757                paranoid_free(tmp);
     
    874874            if (j < items) {
    875875                strcat(mountlist->el[items].device, "_dup");
    876                 mr_asprintf(&tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
     876                mr_asprintf(tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
    877877                log_it(tmp);
    878878                paranoid_free(tmp);
    879879            }
    880             mr_asprintf(&tmp, "%s", mountlist->el[items].device);
     880            mr_asprintf(tmp, "%s", mountlist->el[items].device);
    881881            if (strstr(tmp, "/dev/md/")) {
    882882                log_it("format_device() --- Contracting %s", tmp);
     
    10331033    assert(b >= 0);
    10341034
    1035     mr_asprintf(&device, "%s", mountlist->el[a].device);
    1036     mr_asprintf(&mountpoint, "%s", mountlist->el[a].mountpoint);
    1037     mr_asprintf(&format, "%s", mountlist->el[a].format);
     1035    mr_asprintf(device, "%s", mountlist->el[a].device);
     1036    mr_asprintf(mountpoint, "%s", mountlist->el[a].mountpoint);
     1037    mr_asprintf(format, "%s", mountlist->el[a].format);
    10381038
    10391039    size = mountlist->el[a].size;
Note: See TracChangeset for help on using the changeset viewer.