Ignore:
Timestamp:
Sep 25, 2013, 8:55:39 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Backport tons of dynamic memory management rewrite from 3.1 branch. Test is needed
File:
1 edited

Legend:

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

    r3185 r3188  
    5959    char tmp = NULL;
    6060    char device[MAX_STR_LEN];
    61     char mountpoint[MAX_STR_LEN];
    6261
    6362    char *flaws_str = NULL;
     
    10099                continue;
    101100            }
    102             strcpy(mountpoint, mountlist->el[pos].mountpoint);
    103101            /* is it too big? */
    104102            if (curr_part_no > 'h') {
     
    176174
    177175        build_partition_name(device, drive, curr_part_no);
    178         strcpy(mountpoint, mountlist->el[pos].mountpoint);
    179176        if (pos > 0 && !npos) {
    180177            /* gap in the partition list? */
     
    260257                    continue;
    261258                }
    262                 strcpy(mountpoint, mountlist->el[pos].mountpoint);
    263259                /* is it too big? */
    264260                if (curr_part_no > 'h') {
     
    327323        if (amount_allocated > physical_drive_size) {
    328324            // Used to be +1, but what if you're 1 MB too high?
    329             mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    330                     amount_allocated - physical_drive_size, drive);
     325            mr_asprintf(tmp, " %ld MB over-allocated on %s.",amount_allocated - physical_drive_size, drive);
    331326            log_it(tmp);
    332327
     
    348343
    349344    /* Over-allocated the disk? Unallocated space on disk? */
    350     if (amount_allocated < physical_drive_size - 1) {   /* NOT AN ERROR, JUST A WARNING :-) */
    351         mr_asprintf(tmp, " %ld MB unallocated on %s.",
    352                 physical_drive_size - amount_allocated, drive);
     345    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
     346    {
     347        mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive);
     348        log_it(tmp);
     349        mr_strcat(flaws_str, "%s", tmp);
     350        mr_free(tmp);
     351        res++;
     352    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     353        mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive);
    353354        log_it(tmp);
    354355        mr_strcat(flaws_str, "%s", tmp);
     
    405406            goto endoffunc;
    406407        } else {
    407             mr_asprintf(tmp, " %s (dm) will be setup later on", drive);
    408             log_it(tmp);
    409             mr_free(tmp);
     408            log_it(" %s (dm) will be setup later on", drive);
    410409        }
    411410    } else {
    412         mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
    413         log_it(tmp);
    414         mr_free(tmp);
     411        log_it("%s is %ld MB", drive, physical_drive_size);
    415412    }
    416413
     
    432429            } else if (curr_part_no > 5
    433430                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    434                 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive,
    435                         prev_part_no, curr_part_no);
     431                mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, prev_part_no, curr_part_no);
    436432                log_it(tmp);
    437433                mr_strcat(flaws_str, "%s", tmp);
     
    443439        part_table_fmt = which_partition_format(drive);
    444440        /* no spare primary partitions to help accommodate the logical(s)? */
    445         if ((curr_part_no >= 5 && prev_part_no == 4)
    446             && (strcmp(part_table_fmt, "MBR") == 0)) {
     441        if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt, "MBR") == 0)) {
    447442            mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive);
    448443            log_it(tmp);
     
    451446            res++;
    452447        }
     448        mr_free(part_table_fmt);
     449
    453450        /* does partition /dev/hdNX exist more than once in the mountlist? */
    454451        for (i = 0, device_copies = 0;
     
    459456        }
    460457        if (device_copies > 1) {
    461             mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies),
    462                     device);
     458            mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
    463459            if (!strstr(flaws_str, tmp)) {
    464460                log_it(tmp);
     
    504500    /* Over-allocated the disk? Unallocated space on disk? */
    505501    if (amount_allocated > physical_drive_size + 1) {
    506         mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    507                 amount_allocated - physical_drive_size, drive);
     502        mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive);
    508503        log_it(tmp);
    509504        mr_strcat(flaws_str, "%s", tmp);
     
    511506        res++;
    512507    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    513         mr_asprintf(tmp, " %ld MB unallocated on %s.",
    514                 physical_drive_size - amount_allocated, drive);
     508        mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive);
    515509        log_it(tmp);
    516510        mr_strcat(flaws_str, "%s", tmp);
     
    570564            (drivelist->el[i].device,
    571565             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);
    573             log_it(tmp);
    574             paranoid_free(tmp);
     566            log_it(" Not evaluating %s (I don't know how yet)", drivelist->el[i].device);
    575567        } else {
    576568            log_msg(8, "Evaluating drive #%d (%s) within mountlist", i, drivelist->el[i].device);
     
    582574            log_msg(8,"Adding: %s to flaws_str", tmp);
    583575            mr_strcat(flaws_str, "%s", tmp);
    584             paranoid_free(tmp);
     576            mr_free(tmp);
    585577        }
    586578    }
     
    602594            mr_strcat(flaws_str, "%s", tmp);
    603595            log_msg(8,"Adding: %s to flaws_str", tmp);
    604             paranoid_free(tmp);
    605         }
    606         paranoid_free(curr_mountpoint);
     596            mr_free(tmp);
     597        }
     598        mr_free(curr_mountpoint);
    607599    }
    608600
     
    669661        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    670662            log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);
    671             paranoid_free(drive);
     663            mr_free(drive);
    672664            continue;
    673665        }
     
    676668        if (size == 0) {
    677669            log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive);
    678             paranoid_free(drive);
     670            mr_free(drive);
    679671            continue;
    680672        }
     
    684676        /* memory allocation */
    685677        truncdrive = truncate_to_drive_name(drive);
    686         paranoid_free(drive);
     678        mr_free(drive);
    687679
    688680        log_msg(8, "drive truncated to %s", truncdrive);
     
    733725    int used_by = 0;
    734726
    735     /*@ buffers ********************************************************* */
    736     char *tmp = NULL;
    737 
    738727    assert(output_list != NULL);
    739728    assert(mountlist != NULL);
     
    745734    for (i = 0; i < mountlist->entries; i++) {
    746735        if (strstr(mountlist->el[i].mountpoint, "raid")) {
    747             used_by =
    748                 which_raid_device_is_using_this_partition(raidlist,
    749                                                           mountlist->el[i].
    750                                                           device);
     736            used_by = which_raid_device_is_using_this_partition(raidlist, mountlist->el[i].device);
    751737            if (used_by < 0) {
    752738                memcpy((void *) &output_list->el[items++],
    753739                       (void *) &mountlist->el[i],
    754740                       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);
    756                 log_it(tmp);
    757                 paranoid_free(tmp);
     741                log_it("%s is available; user may choose to add it to raid device", output_list->el[items - 1].device);
    758742            }
    759743        }
     
    810794    char *tmp = NULL;
    811795    char *p = NULL;
    812     char *q = NULL;
    813796
    814797    int items = 0;
     
    824807        return (1);
    825808    }
    826     malloc_string(incoming);
    827809    malloc_string(siz);
    828     q = fgets(incoming, MAX_STR_LEN - 1, fin);
    829810    log_it("Loading mountlist...");
    830     while (!feof(fin) && (q != NULL)) {
     811    mr_getline(incoming, fin);
     812    while (!feof(fin)) {
    831813#if linux
    832         res = sscanf(incoming,
    833                "%s %s %s %s %s",
    834                mountlist->el[items].device,
    835                mountlist->el[items].mountpoint,
    836                mountlist->el[items].format,
    837                siz, mountlist->el[items].label);
     814        res = sscanf(incoming, "%s %s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz, mountlist->el[items].label);
    838815        if (res < 5) {
    839816            /* no label found */
     
    842819        }
    843820#elif __FreeBSD__
    844         res = sscanf(incoming,
    845                "%s %s %s %s",
    846                mountlist->el[items].device,
    847                mountlist->el[items].mountpoint,
    848                mountlist->el[items].format, siz);
     821        res = sscanf(incoming, "%s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz);
    849822        strcpy(mountlist->el[items].label,"");
    850823#endif
     
    859832            !strcmp(mountlist->el[items].device, "devpts")
    860833            ) {
    861             log_msg(1,
    862                     "Ignoring %s in mountlist - not loading that line :) ",
    863                     mountlist->el[items].device);
    864             q = fgets(incoming, MAX_STR_LEN - 1, fin);
     834            log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device);
     835            mr_free(incoming);
     836            mr_getline(incoming, fin);
    865837            continue;
    866838        }
     
    874846            if (j < items) {
    875847                strcat(mountlist->el[items].device, "_dup");
    876                 mr_asprintf(tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
    877                 log_it(tmp);
    878                 paranoid_free(tmp);
     848                log_it("Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
    879849            }
    880850            mr_asprintf(tmp, "%s", mountlist->el[items].device);
     
    887857                    *(p + 2) = *(p + 3);
    888858                }
    889                 log_it("It was %s; it is now %s",
    890                        mountlist->el[items].device, tmp);
     859                log_it("It was %s; it is now %s", mountlist->el[items].device, tmp);
    891860                strcpy(mountlist->el[items].device, tmp);
    892861            }
    893862            paranoid_free(tmp);
    894863
    895             log_it("%s %s %s %lld %s",
    896                      mountlist->el[items].device,
    897                      mountlist->el[items].mountpoint,
    898                      mountlist->el[items].format,
    899                      mountlist->el[items].size,
    900                      mountlist->el[items].label);
     864            log_it("%s %s %s %lld %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, mountlist->el[items].size, mountlist->el[items].label);
    901865            items++;
    902866            if (items >= MAX_MOUNTLIST_ENTRIES) {
     
    905869            }
    906870        }
    907         q = fgets(incoming, MAX_STR_LEN - 1, fin);
    908     }
     871        mr_free(incoming);
     872        mr_getline(incoming, fin);
     873    }
     874    mr_free(incoming);
    909875    paranoid_fclose(fin);
    910876    mountlist->entries = items;
     
    913879    log_it("%d entries in mountlist", items);
    914880
    915     paranoid_free(incoming);
    916881    paranoid_free(siz);
    917882    return (0);
     
    10501015
    10511016    mountlist->el[b].size = size;
    1052     paranoid_free(device);
    1053     paranoid_free(mountpoint);
    1054     paranoid_free(format);
     1017    mr_free(device);
     1018    mr_free(mountpoint);
     1019    mr_free(format);
    10551020}
    10561021
Note: See TracChangeset for help on using the changeset viewer.