Changeset 1173 in MondoRescue


Ignore:
Timestamp:
Feb 16, 2007, 12:25:24 PM (17 years ago)
Author:
Bruno Cornec
Message:

merges from trunk for memory management for libmondo-mountlist.c mainly

Location:
branches/stable/mondo/src/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-files.c

    r1158 r1173  
    8383    return (output);
    8484}
    85 
    86 
    87 /**
    88  * Get a not-quite-unique representation of some of the file's @c stat properties.
    89  * The returned string has the form <tt>size-mtime-ctime</tt>.
    90  * @param curr_fname The file to generate the "checksum" for.
    91  * @return The "checksum".
    92  * @note The returned string points to static storage that will be overwritten with each call.
    93  */
    94 char *calc_file_ugly_minichecksum(char *curr_fname)
    95 {
    96 
    97     /*@ buffers ***************************************************** */
    98     static char curr_cksum[1000];
    99 
    100     /*@ pointers **************************************************** */
    101 
    102     /*@ structures ************************************************** */
    103     struct stat buf;
    104 
    105     /*@ initialize data *************************************************** */
    106     curr_cksum[0] = '\0';
    107 
    108     /*@************************************************************** */
    109 
    110     assert_string_is_neither_NULL_nor_zerolength(curr_fname);
    111     if (lstat(curr_fname, &buf)) {
    112         return (curr_cksum);    // empty
    113     }
    114 
    115     sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),
    116             (long) (buf.st_mtime), (long) (buf.st_ctime));
    117     return (curr_cksum);
    118 }
    119 
    12085
    12186
     
    699664    long file_len_K = 0L;
    700665
    701     malloc_string(sz_res);
    702666    mr_asprintf(&command,
    703667            "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'",
    704668            dev, tmpdir);
    705669    log_it(command);
    706     strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     670    mr_asprintf(&sz_res, call_program_and_get_last_line_of_output(command));
    707671    file_len_K = atol(sz_res);
    708672    mr_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     
    982946    /*@ Char buffers ** */
    983947    char *command = NULL;
    984     char tmp[MAX_STR_LEN];
     948    char *tmp = NULL;
    985949    char old_pwd[MAX_STR_LEN];
    986950
     
    1008972    mr_free(command);
    1009973
    1010     sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     974    mr_asprintf(&tmp, "%s/payload.tgz", g_mondo_home);
    1011975    if (does_file_exist(tmp)) {
    1012976        log_it("Untarring payload %s to scratchdir %s", tmp,
     
    1021985        chdir(old_pwd);
    1022986    }
     987    mr_free(tmp);
    1023988
    1024989    mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    1025990            bkpinfo->scratchdir);
    1026 
    1027991    if (run_program_and_log_output(command, FALSE)) {
    1028992        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
     
    1030994    mr_free(command);
    1031995
    1032     strcpy(tmp,call_program_and_get_last_line_of_output("which mondorestore"));
     996    mr_asprintf(&tmp,call_program_and_get_last_line_of_output("which mondorestore"));
    1033997    if (!tmp) {
    1034998        fatal_error
     
    10361000    }
    10371001    mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1002    mr_free(tmp);
     1003
    10381004    if (run_program_and_log_output(command, FALSE)) {
    10391005        fatal_error("Failed to copy mondorestore to tmpdir");
     
    12671233            *(strchr(tmp, ' ')) = '\0';
    12681234        }
    1269         if (!strcmp(strrchr(filename,'.'), tmp)) {
     1235        if (!strcmp(strrchr(filename, '.'), tmp)) {
    12701236            mr_free(do_not_compress_these);
    12711237            mr_free(tmp);
  • branches/stable/mondo/src/common/libmondo-fork.c

    r1168 r1173  
    4646
    4747    assert_string_is_neither_NULL_nor_zerolength(call);
     48
    4849    if ((fin = popen(call, "r"))) {
    4950        for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     
    184185    char *callstr = NULL;
    185186    char *incoming = NULL;
    186     char *tmp = NULL;
    187187
    188188    /*@ int ********************************************************* */
    189189    int res = 0;
    190190    size_t n = 0;
    191     int i;
    192     int len;
    193191    bool log_if_failure = FALSE;
    194192    bool log_if_success = FALSE;
     
    325323        }
    326324    }
    327 #ifdef _XWIN
    328     /* This only can update when newline goes into the file,
    329        but it's *much* prettier/faster on Qt. */
    330     while (does_file_exist(lockfile)) {
    331         while (!feof(fin)) {
    332             if (!fgets(tmp, 512, fin))
    333                 break;
    334             log_to_screen(tmp);
    335         }
    336         usleep(500000);
    337     }
    338 #else
    339325    /* This works on Newt, and it gives quicker updates. */
    340326    for (; does_file_exist(lockfile); sleep(1)) {
     
    342328        update_evalcall_form(1);
    343329    }
    344 #endif
    345330    /* Evaluate the status returned by pclose to get the exit code of the called program. */
    346331    errno = 0;
     
    379364// if dir=='r' then copy from archived to orig
    380365    char *tmp = NULL;
     366    char *tmp1 = NULL;
    381367    char *buf = NULL;
    382368    long int bytes_to_be_read, bytes_read_in, bytes_written_out =
     
    396382        fin = f_orig;
    397383        fout = f_archived;
    398         sprintf(tmp, "%-64s", PIMP_START_SZ);
    399         if (fwrite(tmp, 1, 64, fout) != 64) {
     384        mr_asprintf(&tmp1, "%-64s", PIMP_START_SZ);
     385        if (fwrite(tmp1, 1, 64, fout) != 64) {
    400386            fatal_error("Can't write the introductory block");
    401387        }
     388        mr_free(tmp1);
     389
    402390        while (1) {
    403391            bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
     
    405393                break;
    406394            }
    407             sprintf(tmp, "%-64ld", bytes_read_in);
    408             if (fwrite(tmp, 1, 64, fout) != 64) {
     395            mr_asprintf(&tmp1, "%-64ld", bytes_read_in);
     396            if (fwrite(tmp1, 1, 64, fout) != 64) {
    409397                fatal_error("Cannot write introductory block");
    410398            }
     399            mr_free(tmp1);
     400
    411401            mr_msg(7,
    412402                    "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
    413403                    subsliceno, bytes_read_in, bytes_to_be_read);
    414404            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    415             sprintf(tmp, "%-64ld", subsliceno);
    416             if (fwrite(tmp, 1, 64, fout) != 64) {
     405            mr_asprintf(&tmp1, "%-64ld", subsliceno);
     406            if (fwrite(tmp1, 1, 64, fout) != 64) {
    417407                fatal_error("Cannot write post-thingy block");
    418408            }
     409            mr_free(tmp1);
     410
    419411            mr_msg(7, "Subslice #%d written OK", subsliceno);
    420412            subsliceno++;
     
    427419        fin = f_archived;
    428420        fout = f_orig;
     421        tmp = mr_malloc(64L);
    429422        if (fread(tmp, 1, 64L, fin) != 64L) {
    430423            fatal_error("Cannot read the introductory block");
     
    447440            }
    448441            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    449             if (fread(tmp, 1, 64, fin) != 64) {
     442            if (fread(tmp, 1, 64L, fin) != 64L) {
    450443                fatal_error("Cannot read post-thingy block");
    451444            }
     
    456449            mr_msg(7, "Subslice #%ld read OK", subsliceno);
    457450            subsliceno++;
    458             if (fread(tmp, 1, 64, fin) != 64) {
     451            if (fread(tmp, 1, 64L, fin) != 64L) {
    459452                fatal_error("Cannot read introductory block");
    460453            }
     
    466459
    467460    if (direction == 'w') {
    468         sprintf(tmp, "%-64s", PIMP_END_SZ);
    469         if (fwrite(tmp, 1, 64, fout) != 64) {
     461        mr_asprintf(&tmp1, "%-64s", PIMP_END_SZ);
     462        if (fwrite(tmp1, 1, 64L, fout) != 64L) {
    470463            fatal_error("Can't write the final block");
    471464        }
     465        mr_free(tmp1);
    472466    } else {
    473467        mr_msg(1, "tmpA is %s", tmp);
    474468        if (!strstr(tmp, PIMP_END_SZ)) {
    475             if (fread(tmp, 1, 64, fin) != 64) {
     469            if (fread(tmp, 1, 64L, fin) != 64L) {
    476470                fatal_error("Can't read the final block");
    477471            }
     
    479473            if (!strstr(tmp, PIMP_END_SZ)) {
    480474                ftmp = fopen("/tmp/out.leftover", "w");
    481                 bytes_read_in = fread(tmp, 1, 64, fin);
     475                bytes_read_in = fread(tmp, 1, 64L, fin);
    482476                mr_msg(1, "bytes_read_in = %ld", bytes_read_in);
    483477//      if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); }
  • branches/stable/mondo/src/common/libmondo-mountlist.c

    r1166 r1173  
    5757
    5858    /*@ buffers ******************************************************** */
    59     char tmp[MAX_STR_LEN];
    60     char device[MAX_STR_LEN];
    61     char mountpoint[MAX_STR_LEN];
     59    char *tmp = NULL;
     60    char *device = NULL;
     61    char *ndevice = NULL;
     62    // BERLIOS : useless ? char *mountpoint;
    6263
    6364    /*@ long *********************************************************** */
     
    6667
    6768    /*@ pointers ******************************************************* */
    68     char *part_table_fmt;
     69    char *part_table_fmt = NULL;
    6970
    7071    /*@ initialize ***************************************************** */
    7172    flaws_str[0] = '\0';
    7273    prev_part_no = 0;
    73     tmp[0] = '\0';
    7474
    7575
     
    7777
    7878    if (physical_drive_size < 0) {
    79         sprintf(tmp, " %s does not exist.", drive);
     79        mr_asprintf(&tmp, " %s does not exist.", drive);
    8080        strcat(flaws_str, tmp);
    8181    } else {
    82         sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     82        mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
    8383    }
    8484    log_it(tmp);
     85    mr_free(tmp);
    8586
    8687
    8788    /* check DD */
    8889    for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    89         sprintf(device, "%s%c", drive, cur_sp_no);
     90        mr_asprintf(&device, "%s%c", drive, cur_sp_no);
    9091        if (find_device_in_mountlist(mountlist, device) >= 0)
    9192            foundsome = TRUE;
     93        mr_free(device);
    9294    }
    9395    if (foundsome) {
    9496        for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    95             sprintf(device, "%s%c", drive, cur_sp_no);
     97            mr_asprintf(&device, "%s%c", drive, cur_sp_no);
    9698            pos = find_device_in_mountlist(mountlist, device);
    9799            if (pos < 0) {
    98100                continue;
    99101            }
    100             strcpy(mountpoint, mountlist->el[pos].mountpoint);
     102            // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
    101103            /* is it too big? */
    102104            if (curr_part_no > 'h') {
    103                 sprintf(tmp, " Can only have up to 'h' in disklabel.");
     105                mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
    104106                log_it(tmp);
    105107                strcat(flaws_str, tmp);
     108                mr_free(tmp);
    106109                res++;
    107110            }
     
    114117            }
    115118            if (device_copies > 1) {
    116                 sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    117                         device);
     119                mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
     120                         device);
    118121                if (!strstr(flaws_str, tmp)) {
    119122                    log_it(tmp);
     
    121124                    res++;
    122125                }
     126                mr_free(tmp);
    123127            }
    124128            /* silly partition size? */
    125129            if (mountlist->el[pos].size < 8192
    126130                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    127                 sprintf(tmp, " %s is tiny!", device);
     131                mr_asprintf(&tmp, " %s is tiny!", device);
    128132                log_it(tmp);
    129133                strcat(flaws_str, tmp);
     134                mr_free(tmp);
    130135                res++;
    131136            }
     
    137142                && strcmp(mountlist->el[pos].mountpoint, "none")
    138143                && mountlist->el[pos].mountpoint[0] != '/') {
    139                 sprintf(tmp, " %s has a weird mountpoint.", device);
     144                mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    140145                log_it(tmp);
    141146                strcat(flaws_str, tmp);
     147                mr_free(tmp);
    142148                res++;
    143149            }
    144150            /* is format sensible? */
    145151            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    146                 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     152                mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    147153                log_it(tmp);
    148154                strcat(flaws_str, tmp);
     155                mr_free(tmp);
    149156                res++;
    150157            }
    151158            amount_allocated += mountlist->el[pos].size / 1024;
    152159            prev_sp_no = cur_sp_no;
     160
     161            mr_free(device);
    153162        }
    154163    }
     
    156165    npos = pos = 0;
    157166    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
    158         sprintf(device, "%ss%d", drive, curr_part_no);
     167        mr_asprintf(&device, "%ss%d", drive, curr_part_no);
    159168        pos = find_device_in_mountlist(mountlist, device);
    160169        npos = 0;
    161170        for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) {
    162             sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);
    163             if (find_device_in_mountlist(mountlist, device) >= 0)
     171            mr_asprintf(&ndevice, "%ss%d%c", device, curr_part_no, cur_sp_no);
     172            if (find_device_in_mountlist(mountlist, ndevice) >= 0)
    164173                npos++;
    165         }
     174            mr_free(ndevice);
     175        }
     176        mr_free(device);
     177
    166178        if (((pos >= 0) || npos) && foundsome) {
    167179            sprintf(flaws_str + strlen(flaws_str),
     
    170182        }
    171183
    172         sprintf(device, "%ss%d", drive, curr_part_no);
    173         strcpy(mountpoint, mountlist->el[pos].mountpoint);
     184        mr_asprintf(&device, "%ss%d", drive, curr_part_no);
     185        // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
    174186        if (pos > 0 && !npos) {
    175187            /* gap in the partition list? */
    176188            if (curr_part_no - prev_part_no > 1) {
    177189                if (prev_part_no == 0) {
    178                     sprintf(tmp, " Gap prior to %s.", device);
     190                    mr_asprintf(&tmp, " Gap prior to %s.", device);
    179191                    log_it(tmp);
    180192                    strcat(flaws_str, tmp);
     193                    mr_free(tmp);
    181194                    res++;
    182195                } else if (curr_part_no > 5
    183196                           || (curr_part_no <= 4 && prev_part_no > 0)) {
    184                     sprintf(tmp, " Gap between %ss%d and %d.", drive,
    185                             prev_part_no, curr_part_no);
     197                    mr_asprintf(&tmp, " Gap between %ss%d and %d.", drive,
     198                             prev_part_no, curr_part_no);
    186199                    log_it(tmp);
    187200                    strcat(flaws_str, tmp);
     201                    mr_free(tmp);
    188202                    res++;
    189203                }
     
    194208            if ((curr_part_no >= 5 && prev_part_no == 4)
    195209                && (strcmp(part_table_fmt, "MBR") == 0)) {
    196                 sprintf(tmp, " Partition %ss4 is occupied.", drive);
     210                mr_asprintf(&tmp, " Partition %ss4 is occupied.", drive);
    197211                log_it(tmp);
    198212                strcat(flaws_str, tmp);
     213                mr_free(tmp);
    199214                res++;
    200215            }
     
    207222            }
    208223            if (device_copies > 1) {
    209                 sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    210                         device);
     224                mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
     225                         device);
    211226                if (!strstr(flaws_str, tmp)) {
    212227                    log_it(tmp);
     
    214229                    res++;
    215230                }
     231                mr_free(tmp);
    216232            }
    217233            /* silly partition size? */
    218234            if (mountlist->el[pos].size < 8192
    219235                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    220                 sprintf(tmp, " %s is tiny!", device);
     236                mr_asprintf(&tmp, " %s is tiny!", device);
    221237                log_it(tmp);
    222238                strcat(flaws_str, tmp);
     239                mr_free(tmp);
    223240                res++;
    224241            }
     
    230247                && strcmp(mountlist->el[pos].mountpoint, "none")
    231248                && mountlist->el[pos].mountpoint[0] != '/') {
    232                 sprintf(tmp, " %s has a weird mountpoint.", device);
     249                mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    233250                log_it(tmp);
    234251                strcat(flaws_str, tmp);
     252                mr_free(tmp);
    235253                res++;
    236254            }
    237255            /* is format sensible? */
    238256            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    239                 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     257                mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    240258                log_it(tmp);
    241259                strcat(flaws_str, tmp);
     260                mr_free(tmp);
    242261                res++;
    243262            }
     
    245264            /* Check subpartitions */
    246265            for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) {
    247                 sprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
     266                mr_asprintf(&device, "%ss%d%c", drive, curr_part_no, cur_sp_no);
    248267                pos = find_device_in_mountlist(mountlist, device);
    249268                if (pos < 0) {
    250269                    continue;
    251270                }
    252                 strcpy(mountpoint, mountlist->el[pos].mountpoint);
     271                // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint);
    253272                /* is it too big? */
    254273                if (curr_part_no > 'h') {
    255                     sprintf(tmp, " Can only have up to 'h' in disklabel.");
     274                    mr_asprintf(&tmp,
     275                             " Can only have up to 'h' in disklabel.");
    256276                    log_it(tmp);
    257277                    strcat(flaws_str, tmp);
     278                    mr_free(tmp);
    258279                    res++;
    259280                }
     
    266287                }
    267288                if (device_copies > 1) {
    268                     sprintf(tmp, " %s %s's.",
    269                             number_to_text(device_copies), device);
     289                    mr_asprintf(&tmp, " %s %s's.",
     290                             number_to_text(device_copies), device);
    270291                    if (!strstr(flaws_str, tmp)) {
    271292                        log_it(tmp);
     
    273294                        res++;
    274295                    }
     296                    mr_free(tmp);
    275297                }
    276298                /* silly partition size? */
    277299                if (mountlist->el[pos].size < 8192
    278300                    && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    279                     sprintf(tmp, " %s is tiny!", device);
     301                    mr_asprintf(&tmp, " %s is tiny!", device);
    280302                    log_it(tmp);
    281303                    strcat(flaws_str, tmp);
     304                    mr_free(tmp);
    282305                    res++;
    283306                }
     
    289312                    && strcmp(mountlist->el[pos].mountpoint, "none")
    290313                    && mountlist->el[pos].mountpoint[0] != '/') {
    291                     sprintf(tmp, " %s has a weird mountpoint.", device);
     314                    mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    292315                    log_it(tmp);
    293316                    strcat(flaws_str, tmp);
     317                    mr_free(tmp);
    294318                    res++;
    295319                }
     
    297321                if (!is_this_a_valid_disk_format
    298322                    (mountlist->el[pos].format)) {
    299                     sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     323                    mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    300324                    log_it(tmp);
    301325                    strcat(flaws_str, tmp);
     326                    mr_free(tmp);
    302327                    res++;
    303328                }
     
    306331            }
    307332        }
     333        mr_free(device);
    308334
    309335        /* OK, continue with main loop */
     
    315341    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
    316342    {
    317         sprintf(tmp, " %ld MB over-allocated on %s.",
    318                 amount_allocated - physical_drive_size, drive);
     343        mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
     344                 amount_allocated - physical_drive_size, drive);
    319345        log_it(tmp);
    320346        strcat(flaws_str, tmp);
     347        mr_free(tmp);
    321348        res++;
    322349    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    323         sprintf(tmp, " %ld MB unallocated on %s.",
    324                 physical_drive_size - amount_allocated, drive);
     350        mr_asprintf(&tmp, " %ld MB unallocated on %s.",
     351                 physical_drive_size - amount_allocated, drive);
    325352        log_it(tmp);
    326353        strcat(flaws_str, tmp);
     354        mr_free(tmp);
    327355        /* BERLIOS: Flawed since rev 1 !! */
    328356        res++;
     
    349377
    350378    /*@ buffers ******************************************************** */
    351     char *tmp;
    352     char *device;
    353     char *mountpoint;
     379    char *tmp = NULL;
     380    char *tmp1 = NULL;
     381    char *device = NULL;
    354382
    355383    /*@ long *********************************************************** */
    356     long physical_drive_size = 0;
    357     long amount_allocated = 0;
     384    long physical_drive_size = 0L;
     385    long amount_allocated = 0L;
    358386
    359387    /*@ pointers ******************************************************* */
    360     char *part_table_fmt;
     388    char *part_table_fmt = NULL;
    361389
    362390    /*@ initialize ***************************************************** */
     
    365393    assert(flaws_str != NULL);
    366394
    367     malloc_string(tmp);
    368     malloc_string(device);
    369     malloc_string(mountpoint);
    370395    flaws_str[0] = '\0';
    371396    prev_part_no = 0;
    372     tmp[0] = '\0';
    373 
    374397
    375398    physical_drive_size = get_phys_size_of_drive(drive);
    376399
    377400    if (physical_drive_size < 0) {
    378         sprintf(tmp, " %s does not exist.", drive);
     401        mr_asprintf(&tmp, " %s does not exist.", drive);
    379402        strcat(flaws_str, tmp);
    380403        res++;
    381404        mr_msg(1, tmp);
    382         goto endoffunc;
     405        mr_free(tmp);
     406        return (FALSE);
    383407    } else {
    384         sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     408        mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
    385409        log_it(tmp);
     410        mr_free(tmp);
    386411    }
    387412
    388413    for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) {
    389         sprintf(device, "%s%d", drive, curr_part_no);
     414        mr_asprintf(&device, "%s%d", drive, curr_part_no);
    390415        pos = find_device_in_mountlist(mountlist, device);
    391416        if (pos < 0) {
     
    393418        }
    394419        if (physical_drive_size < 0) {
    395             sprintf(tmp, " %s refers to non-existent hardware.", device);
     420            mr_asprintf(&tmp, " %s refers to non-existent hardware.", device);
    396421            strcat(flaws_str, tmp);
    397422            res++;
     423            mr_free(tmp);
    398424            continue;
    399425        }
    400         strcpy(mountpoint, mountlist->el[pos].mountpoint);
     426        // BERLIOS : useless ? str-cpy(mountpoint, mountlist->el[pos].mountpoint);
    401427        /* gap in the partition list? */
    402428        if (curr_part_no - prev_part_no > 1) {
    403429            if (prev_part_no == 0) {
    404                 sprintf(tmp, " Gap prior to %s.", device);
     430                mr_asprintf(&tmp, " Gap prior to %s.", device);
    405431                log_it(tmp);
    406432                strcat(flaws_str, tmp);
     433                mr_free(tmp);
    407434                res++;
    408435            } else if (curr_part_no > 5
    409436                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    410                 sprintf(tmp, " Gap between %s%d and %d.", drive,
     437                mr_asprintf(&tmp, " Gap between %s%d and %d.", drive,
    411438                        prev_part_no, curr_part_no);
    412439                log_it(tmp);
    413440                strcat(flaws_str, tmp);
     441                mr_free(tmp);
    414442                res++;
    415443            }
     
    420448        if ((curr_part_no >= 5 && prev_part_no == 4)
    421449            && (strcmp(part_table_fmt, "MBR") == 0)) {
    422             sprintf(tmp, " Partition %s4 is occupied.", drive);
     450            mr_asprintf(&tmp, " Partition %s4 is occupied.", drive);
    423451            log_it(tmp);
    424452            strcat(flaws_str, tmp);
     453            mr_free(tmp);
    425454            res++;
    426455        }
     
    433462        }
    434463        if (device_copies > 1) {
    435             sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    436                     device);
     464            mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
     465                     device);
    437466            if (!strstr(flaws_str, tmp)) {
    438467                log_it(tmp);
     
    440469                res++;
    441470            }
     471            mr_free(tmp);
    442472        }
    443473        /* silly partition size? */
    444474        if (mountlist->el[pos].size < 8192
    445475            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    446             sprintf(tmp, " %s is tiny!", device);
     476            mr_asprintf(&tmp, " %s is tiny!", device);
    447477            log_it(tmp);
    448478            strcat(flaws_str, tmp);
     479            mr_free(tmp);
    449480            res++;
    450481        }
     
    455486            && strcmp(mountlist->el[pos].mountpoint, "image")
    456487            && mountlist->el[pos].mountpoint[0] != '/') {
    457             sprintf(tmp, " %s has a weird mountpoint.", device);
     488            mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    458489            log_it(tmp);
    459490            strcat(flaws_str, tmp);
     491            mr_free(tmp);
    460492            res++;
    461493        }
    462494        /* is format sensible? */
    463495        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    464             sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     496            mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    465497            log_it(tmp);
    466498            strcat(flaws_str, tmp);
     499            mr_free(tmp);
    467500            res++;
    468501        }
     
    470503        amount_allocated += mountlist->el[pos].size / 1024;
    471504        prev_part_no = curr_part_no;
     505        mr_free(device);
    472506    }
    473507
    474508    /* Over-allocated the disk? Unallocated space on disk? */
    475509    if (amount_allocated > physical_drive_size + 1) {
    476         sprintf(tmp, " %ld MB over-allocated on %s.",
    477                 amount_allocated - physical_drive_size, drive);
     510        mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
     511                 amount_allocated - physical_drive_size, drive);
    478512        log_it(tmp);
    479513        strcat(flaws_str, tmp);
     514        mr_free(tmp);
    480515        res++;
    481516    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    482         sprintf(tmp, " %ld MB unallocated on %s.",
    483                 physical_drive_size - amount_allocated, drive);
     517        mr_asprintf(&tmp, " %ld MB unallocated on %s.",
     518                 physical_drive_size - amount_allocated, drive);
    484519        log_it(tmp);
    485520        strcat(flaws_str, tmp);
    486         /* BERLIOS: Flawed since rev 1 !! */
     521        mr_free(tmp);
     522        /* BERLIOS: Flawed since rev 1 !! - Is it sure ?? */
    487523        res++;
    488524    }
    489 
    490   endoffunc:
    491     mr_free(tmp);
    492     mr_free(device);
    493     mr_free(mountpoint);
    494525
    495526    if (res) {
     
    500531}
    501532#endif
    502 
    503533
    504534
     
    519549
    520550    /*@ buffer *********************************************************** */
    521     struct list_of_disks *drivelist;
    522     char *tmp;
    523     char *flaws_str;
     551    struct list_of_disks *drivelist = NULL;
     552    char *tmp = NULL;
     553    char *tmp1 = NULL;
     554    char *flaws_str = NULL;
    524555
    525556    /*@ int ************************************************************** */
     
    559590    }
    560591    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    561 /*  res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see
    562  which formarts are actually _supported_ by the kernel */
    563     /* log_it(flaws_str); */
    564592    return (spread_flaws_across_three_lines
    565593            (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     
    580608    /*@ int ************************************************************** */
    581609    int i = 0;
    582     char *tmp;
    583     char *flaws_str;
    584 
    585     malloc_string(tmp);
    586     malloc_string(flaws_str);
    587610
    588611    assert(mountlist != NULL);
     
    592615         && strcmp(mountlist->el[i].device, device) != 0; i++);
    593616
    594     mr_free(tmp);
    595     mr_free(flaws_str);
    596 
    597617    if (i == mountlist->entries) {
    598618        return (-1);
     
    601621    }
    602622}
    603 
    604 
    605 
    606623
    607624
     
    625642
    626643    /*@ buffetr ********************************************************* */
    627     char *curr_mountpoint;
    628     char *tmp;
    629 
    630     malloc_string(curr_mountpoint);
    631     malloc_string(tmp);
     644    char *curr_mountpoint = NULL;
     645    char *tmp = NULL;
     646    char *tmp1 = NULL;
     647
    632648    assert(mountlist != NULL);
    633649    assert(flaws_str != NULL);
     650
    634651    for (currline = 0; currline < mountlist->entries; currline++) {
    635         strcpy(curr_mountpoint, mountlist->el[currline].mountpoint);
     652        mr_asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint);
    636653        for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries;
    637654             i++) {
     
    645662        if (copies > 1 && last_copy == currline
    646663            && strcmp(curr_mountpoint, "raid")) {
    647             sprintf(tmp, " %s %s's.", number_to_text(copies),
     664            mr_asprintf(&tmp, " %s %s's.", number_to_text(copies),
    648665                    curr_mountpoint);
    649666            strcat(flaws_str, tmp);
    650667            log_it(tmp);
     668            mr_free(tmp);
    651669            res++;
    652670        }
    653     }
    654     mr_free(curr_mountpoint);
    655     mr_free(tmp);
     671        mr_free(curr_mountpoint);
     672    }
    656673    return (res);
    657674}
    658 
    659 /**
    660  * Look for strange formats. Does not respect /proc/filesystems.
    661  * @param mountlist The mountlist to check.
    662  * @param flaws_str The flaws string to append the results to.
    663  * @return The number of weird formats found, or 0 for success.
    664  * @bug Seems orphaned; please remove.
    665  */
    666 int
    667 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)
    668 {
    669 
    670     /*@ int ************************************************************* */
    671     int i = 0;
    672     int res = 0;
    673 
    674     /*@ buffers ********************************************************* */
    675     char *tmp;
    676     char *format_sz;
    677 
    678     malloc_string(tmp);
    679     malloc_string(format_sz);
    680 
    681     assert(mountlist != NULL);
    682     assert(flaws_str != NULL);
    683 
    684     for (i = 0; i < mountlist->entries; i++) {
    685         sprintf(format_sz, " %s ", mountlist->el[i].format);
    686         if (!strstr(SANE_FORMATS, format_sz)
    687             && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
    688             sprintf(tmp, " %s has unknown format.",
    689                     mountlist->el[i].device);
    690             log_it(tmp);
    691             strcat(flaws_str, tmp);
    692             res++;
    693         } else if ((!strcmp(mountlist->el[i].format, "swap")
    694                     && strcmp(mountlist->el[i].mountpoint, "swap")
    695                     && strcmp(mountlist->el[i].mountpoint, "none"))
    696                    || (strcmp(mountlist->el[i].format, "swap")
    697                        && !strcmp(mountlist->el[i].mountpoint, "swap")
    698                        && !strcmp(mountlist->el[i].mountpoint, "none"))) {
    699             sprintf(tmp, " %s is half-swap.", mountlist->el[i].device);
    700             log_it(tmp);
    701             strcat(flaws_str, tmp);
    702             res++;
    703         }
    704     }
    705     mr_free(tmp);
    706     mr_free(format_sz);
    707     return (res);
    708 }
    709 
    710675
    711676
     
    727692
    728693    /*@ buffers ********************************************************* */
    729     char *drive;
    730     char *tmp;
     694    char *drive = NULL;
    731695
    732696    long long size;
    733697
    734     malloc_string(drive);
    735     malloc_string(tmp);
    736698    assert(mountlist != NULL);
    737699    assert(drivelist != NULL);
     
    739701    for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
    740702
    741         strcpy(drive, mountlist->el[lino].device);
     703        mr_asprintf(&drive, mountlist->el[lino].device);
    742704        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    743             sprintf(tmp,
    744                     "Not putting %s in list of drives: it's a virtual drive",
    745                     drive);
    746             mr_msg(8, tmp);
     705            mr_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);
    747706            continue;
    748707        }
     
    750709        size = mountlist->el[lino].size;
    751710        if (size == 0) {
    752             sprintf(tmp,
    753                     "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",
    754                     drive);
    755             mr_msg(8, tmp);
     711            mr_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive);
    756712            continue;
    757713        }
    758714
    759 /*
    760       for (i = strlen (drive); isdigit (drive[i - 1]); i--);
    761       drive[i] = '\0';
    762       if (get_phys_size_of_drive (drive) <= 0 && drive[i - 1] == 'p')
    763     {
    764       i--;
    765       drive[i] = '\0';
    766     }
    767       for (j = 0; j < noof_drives && strcmp (drivelist[j], drive) != 0; j++);
    768 */
    769 
    770         sprintf(tmp,
    771                 "Putting %s with size %lli in list of drives",
    772                 drive, size);
    773         mr_msg(8, tmp);
     715        mr_msg(8, "Putting %s with size %lli in list of drives", drive, size);
    774716
    775717        (void) truncate_to_drive_name(drive);
     
    781723            strcpy(drivelist->el[noof_drives++].device, drive);
    782724        }
     725        mr_free(drive);
     726
    783727    }
    784728    drivelist->entries = noof_drives;
    785729    mr_msg(8, "Made list of drives");
    786     mr_free(drive);
    787     mr_free(tmp);
    788730
    789731    return (noof_drives);
    790732}
    791 
    792 
    793 
    794 
    795733
    796734
     
    816754
    817755    /*@ buffers ********************************************************* */
    818     char *tmp;
    819 
    820     malloc_string(tmp);
     756    char *tmp = NULL;
     757
    821758    assert(output_list != NULL);
    822759    assert(mountlist != NULL);
     
    836773                       (void *) &mountlist->el[i],
    837774                       sizeof(struct mountlist_line));
    838                 sprintf(tmp,
    839                         "%s is available; user may choose to add it to raid device",
    840                         output_list->el[items - 1].device);
    841                 log_it(tmp);
     775                mr_asprintf(&tmp,
     776                         "%s is available; user may choose to add it to raid device",
     777                         output_list->el[items - 1].device);
     778                log_it(tmp);
     779                mr_free(tmp);
    842780            }
    843781        }
     
    845783    output_list->entries = items;
    846784    log_it("MLUORP -- ending");
    847     mr_free(tmp);
    848 }
    849 
    850 
    851 
     785}
    852786
    853787
     
    878812    }
    879813}
    880 
    881 
    882814
    883815
     
    894826int load_mountlist(struct mountlist_itself *mountlist, char *fname)
    895827{
    896     FILE *fin;
     828    FILE *fin = NULL;
    897829    /* malloc ** */
    898     char *incoming;
    899     char *siz;
    900     char *tmp;
    901     char *p;
    902 
    903     int items;
    904     int j;
     830    char *incoming = NULL;
     831    char *siz = NULL;
     832    char *tmp = NULL;
     833    char *p = NULL;
     834
     835    int items = 0;
     836    int j = 0;
     837    size_t n = 0;
    905838
    906839    assert(mountlist != NULL);
    907840    assert_string_is_neither_NULL_nor_zerolength(fname);
    908     malloc_string(incoming);
    909     malloc_string(siz);
    910     malloc_string(tmp);
     841
    911842    if (!(fin = fopen(fname, "r"))) {
    912843        log_it("Unable to open mountlist - '%s'", fname);
    913         log_to_screen("Cannot open mountlist");
    914         mr_free(incoming);
    915         mr_free(siz);
    916         mr_free(tmp);
     844        log_to_screen(_("Cannot open mountlist"));
    917845        return (1);
    918846    }
    919     items = 0;
    920     (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     847    malloc_string(siz);
     848    mr_getline(&incoming, &n, fin);
    921849    log_it("Loading mountlist...");
    922850    while (!feof(fin)) {
     
    947875                    "Ignoring %s in mountlist - not loading that line :) ",
    948876                    mountlist->el[items].device);
    949             (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     877            mr_getline(&incoming, &n, fin);
    950878            continue;
    951879        }
     
    954882            && mountlist->el[items].device[0] != '#') {
    955883            if (items >= ARBITRARY_MAXIMUM) {
    956                 log_to_screen("Too many lines in mountlist.. ABORTING");
     884                log_to_screen(_("Too many lines in mountlist.. ABORTING"));
    957885                finish(1);
    958886            }
     
    963891            if (j < items) {
    964892                strcat(mountlist->el[items].device, "_dup");
    965                 sprintf(tmp,
    966                         "Duplicate entry in mountlist - renaming to %s",
    967                         mountlist->el[items].device);
    968                 log_it(tmp);
    969             }
    970             strcpy(tmp, mountlist->el[items].device);
     893                mr_asprintf(&tmp,
     894                         "Duplicate entry in mountlist - renaming to %s",
     895                         mountlist->el[items].device);
     896                log_it(tmp);
     897                mr_free(tmp);
     898            }
     899            mr_asprintf(&tmp, mountlist->el[items].device);
    971900            if (strstr(tmp, "/dev/md/")) {
    972901                log_it("format_device() --- Contracting %s", tmp);
     
    981910                strcpy(mountlist->el[items].device, tmp);
    982911            }
    983 
    984             sprintf(tmp,
    985                     "%s %s %s %lld %s",
    986                     mountlist->el[items].device,
    987                     mountlist->el[items].mountpoint,
    988                     mountlist->el[items].format,
    989                     mountlist->el[items].size, mountlist->el[items].label);
    990 
    991             log_it(tmp);
     912            mr_free(tmp);
     913
     914            log_it("%s %s %s %lld %s",
     915                     mountlist->el[items].device,
     916                     mountlist->el[items].mountpoint,
     917                     mountlist->el[items].format,
     918                     mountlist->el[items].size,
     919                     mountlist->el[items].label);
    992920            items++;
    993921        }
    994         (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     922        mr_getline(&incoming, &n, fin);
    995923    }
    996924    paranoid_fclose(fin);
     925    mr_free(incoming);
    997926    mountlist->entries = items;
    998927
    999928    log_it("Mountlist loaded successfully.");
    1000     sprintf(tmp, "%d entries in mountlist", items);
    1001     log_it(tmp);
    1002     mr_free(incoming);
     929    log_it("%d entries in mountlist", items);
     930
    1003931    mr_free(siz);
    1004     mr_free(tmp);
    1005932    return (0);
    1006933}
    1007 
    1008934
    1009935
     
    1038964    return (0);
    1039965}
    1040 
    1041966
    1042967
     
    1066991}
    1067992
     993
    1068994/**
    1069995 * Sort the mountlist alphabetically by mountpoint.
     
    11051031{
    11061032    /*@ mallocs *** */
    1107     char device[64];
    1108     char mountpoint[256];
    1109     char format[64];
     1033    char *device = NULL;
     1034    char *mountpoint = NULL;
     1035    char *format = NULL;
    11101036
    11111037    long long size;
     
    11151041    assert(b >= 0);
    11161042
    1117     strcpy(device, mountlist->el[a].device);
    1118     strcpy(mountpoint, mountlist->el[a].mountpoint);
    1119     strcpy(format, mountlist->el[a].format);
     1043    mr_asprintf(&device, mountlist->el[a].device);
     1044    mr_asprintf(&mountpoint, mountlist->el[a].mountpoint);
     1045    mr_asprintf(&format, mountlist->el[a].format);
    11201046
    11211047    size = mountlist->el[a].size;
     
    11321058
    11331059    mountlist->el[b].size = size;
     1060    mr_free(device);
     1061    mr_free(mountpoint);
     1062    mr_free(format);
    11341063}
    11351064
Note: See TracChangeset for help on using the changeset viewer.