Ignore:
Timestamp:
Oct 24, 2006, 8:49:18 AM (18 years ago)
Author:
Bruno Cornec
Message:

Huge patch to introduce low level functions that will bw used everywhere (mr_free, mr_asprintf, ...)
Nearly linking now due to that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/mondorestore/mondo-rstr-compare.c

    r783 r900  
    1414#include <pthread.h>
    1515#endif
     16#include "mr_mem.h"
    1617
    1718void popup_changelist_from_file(char *);
     
    6162    }
    6263    if (!(fin = fopen(tmp1, "r"))) {
    63         asprintf(&tmp, _("Cannot open bigfile %ld (%s)'s info file"),
     64        mr_asprintf(&tmp, _("Cannot open bigfile %ld (%s)'s info file"),
    6465                bigfileno + 1, tmp);
    6566        log_to_screen(tmp);
    66         paranoid_free(tmp);
    67         paranoid_free(tmp1);
     67        mr_free(tmp);
     68        mr_free(tmp1);
    6869        return (1);
    6970    }
    70     paranoid_free(tmp1);
     71    mr_free(tmp1);
    7172
    7273    fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin);
    7374    paranoid_fclose(fin);
    7475
    75     asprintf(&checksum, biggiestruct.checksum);
    76     asprintf(&bigfile_fname, biggiestruct.filename);
     76    mr_asprintf(&checksum, biggiestruct.checksum);
     77    mr_asprintf(&bigfile_fname, biggiestruct.filename);
    7778
    7879    log_msg(2, "biggiestruct.filename = %s", bigfile_fname);
     
    8081
    8182    if (!g_text_mode) {
    82         asprintf(&tmp, _("Comparing %s"), bigfile_fname);
     83        mr_asprintf(&tmp, _("Comparing %s"), bigfile_fname);
    8384        newtDrawRootText(0, 22, tmp);
    8485        newtRefresh();
    85         paranoid_free(tmp);
     86        mr_free(tmp);
    8687    }
    8788    /* BERLIOS: Useless ?
     
    9394        return(0);
    9495    } else {
    95         asprintf(&command,
     96        mr_asprintf(&command,
    9697                "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
    9798                MNT_RESTORING, bigfile_fname);
     
    101102    if (system(command)) {
    102103        log_OS_error("Warning - command failed");
    103         paranoid_free(command);
    104         paranoid_free(bigfile_fname);
     104        mr_free(command);
     105        mr_free(bigfile_fname);
    105106        return (1);
    106107    } else {
    107         paranoid_free(command);
     108        mr_free(command);
    108109        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
    109110            log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum");
    110             paranoid_free(bigfile_fname);
     111            mr_free(bigfile_fname);
    111112            return (1);
    112113        } else {
    113             getline(&original_cksum, &n, fin);
     114            mr_getline(&original_cksum, &n, fin);
    114115            paranoid_fclose(fin);
    115116            for (i = strlen(original_cksum);
     
    128129        retval++;
    129130    }
    130     paranoid_free(original_cksum);
    131     paranoid_free(checksum);
     131    mr_free(original_cksum);
     132    mr_free(checksum);
    132133
    133134    if (retval) {
     
    138139        paranoid_fclose(fout);
    139140    }
    140     paranoid_free(bigfile_fname);
     141    mr_free(bigfile_fname);
    141142
    142143    return (retval);
     
    181182                       noof_biggiefiles);
    182183    for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
    183         asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1);
     184        mr_asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1);
    184185        log_msg(1, tmp);
    185186        update_progress_form(tmp);
    186         paranoid_free(tmp);
     187        mr_free(tmp);
    187188        res = compare_a_biggiefile(bkpinfo, bigfileno);
    188189        retval += res;
     
    232233    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    233234    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    234     asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d",
     235    mr_asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d",
    235236            current_tarball_number);
    236237
    237238    noof_lines = count_lines_in_file(filelist_name);
    238     paranoid_free(filelist_name);
     239    mr_free(filelist_name);
    239240
    240241    if (strstr(tarball_fname, ".bz2")) {
    241         asprintf(&compressor_exe, "bzip2");
     242        mr_asprintf(&compressor_exe, "bzip2");
    242243    } else if (strstr(tarball_fname, ".lzo")) {
    243         asprintf(&compressor_exe, "lzop");
     244        mr_asprintf(&compressor_exe, "lzop");
    244245    } else {
    245246        compressor_exe = NULL;
     
    247248
    248249    if (use_star) {
    249         asprintf(&archiver_exe, "star -bz");
    250     } else {
    251         asprintf(&archiver_exe, "afio");
     250        mr_asprintf(&archiver_exe, "star -bz");
     251    } else {
     252        mr_asprintf(&archiver_exe, "afio");
    252253    }
    253254
     
    257258            fatal_error("(compare_a_tarball) Compression program missing");
    258259        }
    259         paranoid_free(tmp);
     260        mr_free(tmp);
    260261
    261262        if (use_star) {
     
    266267        } else {
    267268            tmp = compressor_exe;
    268             asprintf(&compressor_exe, "-P %s -Z", tmp);
    269             paranoid_free(tmp);
     269            mr_asprintf(&compressor_exe, "-P %s -Z", tmp);
     270            mr_free(tmp);
    270271        }
    271272    }
     
    278279#endif
    279280
    280     asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number);
     281    mr_asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number);
    281282    if (use_star)               // doesn't use compressor_exe
    282283    {
    283         asprintf(&command,
     284        mr_asprintf(&command,
    284285                "%s -diff H=star file=%s >> %s 2>> %s",
    285286                archiver_exe, tarball_fname, logfile, logfile);
    286287    } else {
    287         asprintf(&command,
     288        mr_asprintf(&command,
    288289                "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
    289290                archiver_exe,
     
    292293    }
    293294#undef BUFSIZE
    294     paranoid_free(archiver_exe);
    295     paranoid_free(compressor_exe);
     295    mr_free(archiver_exe);
     296    mr_free(compressor_exe);
    296297
    297298    res = system(command);
     
    300301        log_OS_error(command);
    301302    }
    302     paranoid_free(command);
     303    mr_free(command);
    303304
    304305    if (length_of_file(logfile) > 5) {
    305         asprintf(&command,
     306        mr_asprintf(&command,
    306307                "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vx \"dev/.*\" >> /tmp/changed.txt",
    307308                logfile);
    308309        system(command);
    309         paranoid_free(command);
     310        mr_free(command);
    310311        archiver_errors = count_lines_in_file(logfile);
    311312    } else {
     
    314315
    315316    if (archiver_errors) {
    316         asprintf(&tmp,
     317        mr_asprintf(&tmp,
    317318                "Differences found while processing fileset #%d       ",
    318319                current_tarball_number);
    319320        log_msg(1, tmp);
    320         paranoid_free(tmp);
     321        mr_free(tmp);
    321322    }
    322323    unlink(logfile);
    323     paranoid_free(logfile);
     324    mr_free(logfile);
    324325    return (retval);
    325326}
     
    353354
    354355    max_val = atol(tmp);
    355     paranoid_free(tmp);
    356 
    357     asprintf(&progress_str, _("Comparing with %s #%d "),
     356    mr_free(tmp);
     357
     358    mr_asprintf(&progress_str, _("Comparing with %s #%d "),
    358359            bkpinfo->backup_media_string,
    359360            g_current_media_number);
     
    369370        insist_on_this_cd_number(bkpinfo, g_current_media_number);
    370371        update_progress_form(progress_str);
    371         asprintf(&tarball_fname,
     372        mr_asprintf(&tarball_fname,
    372373                MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
    373374
    374375        if (!does_file_exist(tarball_fname)) {
    375             paranoid_free(tarball_fname);
    376             asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
     376            mr_free(tarball_fname);
     377            mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
    377378                    current_tarball_number);
    378379        }
    379380        if (!does_file_exist(tarball_fname)) {
    380             paranoid_free(tarball_fname);
    381             asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.",
     381            mr_free(tarball_fname);
     382            mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.",
    382383                    current_tarball_number);
    383384        }
    384385        if (!does_file_exist(tarball_fname)) {
    385             paranoid_free(tarball_fname);
    386             asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
     386            mr_free(tarball_fname);
     387            mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
    387388                    current_tarball_number);
    388389        }
    389390        if (!does_file_exist(tarball_fname)) {
    390             paranoid_free(tarball_fname);
    391             asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.",
     391            mr_free(tarball_fname);
     392            mr_asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.",
    392393                    current_tarball_number);
    393394        }
     
    398399                == 0) {
    399400                log_msg(2, "OK, I think I'm done with tarballs...");
    400                 paranoid_free(tarball_fname);
     401                mr_free(tarball_fname);
    401402                break;
    402403            }
    403404            log_msg(2, "OK, I think it's time for another CD...");
    404405            g_current_media_number++;
    405             paranoid_free(progress_str);
    406             asprintf(&progress_str, _("Comparing with %s #%d "),
     406            mr_free(progress_str);
     407            mr_asprintf(&progress_str, _("Comparing with %s #%d "),
    407408                    bkpinfo->backup_media_string,
    408409                    g_current_media_number);
     
    410411        } else {
    411412            res = compare_a_tarball(tarball_fname, current_tarball_number);
    412             paranoid_free(tarball_fname);
     413            mr_free(tarball_fname);
    413414
    414415            g_current_progress++;
     
    416417        }
    417418    }
    418     paranoid_free(progress_str);
     419    mr_free(progress_str);
    419420    close_progress_form();
    420421
     
    470471    noof_changed_files = count_lines_in_file("/tmp/changed.txt");
    471472    if (noof_changed_files) {
    472         asprintf(&tmp, _("%ld files do not match the backup            "),
     473        mr_asprintf(&tmp, _("%ld files do not match the backup            "),
    473474                noof_changed_files);
    474475        //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
    475476        log_to_screen(tmp);
    476         paranoid_free(tmp);
    477 
    478         asprintf(&command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
     477        mr_free(tmp);
     478
     479        mr_asprintf(&command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
    479480        paranoid_system(command);
    480         paranoid_free(command);
    481     } else {
    482         asprintf(&tmp, _("All files match the backup                     "));
     481        mr_free(command);
     482    } else {
     483        mr_asprintf(&tmp, _("All files match the backup                     "));
    483484        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    484485        log_to_screen(tmp);
    485         paranoid_free(tmp);
    486     }
    487 
    488     paranoid_free(cwd);
    489     paranoid_free(new);
     486        mr_free(tmp);
     487    }
     488
     489    mr_free(cwd);
     490    mr_free(new);
    490491
    491492    return (resA + resB);
     
    573574        } else {
    574575            q = count_lines_in_file("/tmp/changed.files");
    575             asprintf(&tmp, _("%ld significant difference%s found."), q,
     576            mr_asprintf(&tmp, _("%ld significant difference%s found."), q,
    576577                    (q != 1) ? "s" : "");
    577578            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    578579            log_to_screen(tmp);
    579             paranoid_free(tmp);
    580 
    581             asprintf(&tmp,
     580            mr_free(tmp);
     581
     582            mr_asprintf(&tmp,
    582583                   _("Type 'less /tmp/changed.files' for a list of non-matching files"));
    583584            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    584585            log_to_screen(tmp);
    585             paranoid_free(tmp);
     586            mr_free(tmp);
    586587
    587588            log_msg(2, "calling popup_changelist_from_file()");
     
    624625    chdir(bkpinfo->restore_path);
    625626
    626     asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     627    mr_asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    627628            bkpinfo->restore_path);
    628629    run_program_and_log_output(command, FALSE);
    629     paranoid_free(command);
     630    mr_free(command);
    630631    mvaddstr_and_log_it(g_currentY,
    631632                        0, _("Verifying archives against filesystem"));
     
    633634    if (bkpinfo->disaster_recovery
    634635        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    635         paranoid_free(bkpinfo->media_device);
     636        mr_free(bkpinfo->media_device);
    636637        // last_line_of_file allocates the string
    637638        bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    638639    } else {
    639         paranoid_free(bkpinfo->media_device);
     640        mr_free(bkpinfo->media_device);
    640641        // find_cdrom_device allocates the string
    641642        bkpinfo->media_device = find_cdrom_device(FALSE);
     
    653654
    654655    mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    655     paranoid_free(dir);
     656    mr_free(dir);
    656657    return (res);
    657658}
     
    684685    getcwd(dir, MAX_STR_LEN);
    685686    chdir(bkpinfo->restore_path);
    686     asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     687    mr_asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    687688            bkpinfo->restore_path);
    688689    run_program_and_log_output(command, FALSE);
    689     paranoid_free(command);
     690    mr_free(command);
    690691
    691692    mvaddstr_and_log_it(g_currentY,
     
    698699        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    699700    }
    700     paranoid_free(dir);
     701    mr_free(dir);
    701702    return (res);
    702703}
Note: See TracChangeset for help on using the changeset viewer.