Changeset 1110 in MondoRescue


Ignore:
Timestamp:
Feb 8, 2007, 1:37:30 AM (17 years ago)
Author:
Bruno Cornec
Message:

Improve memory management for libmondo-filelist.c (trunk merge begining)

File:
1 edited

Legend:

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

    r1107 r1110  
    1010#include "my-stuff.h"
    1111#include "mondostructures.h"
    12 #include "lib-common-externs.h"
    1312#include "libmondo-filelist.h"
    1413#include "libmondo-string-EXT.h"
    1514#include "libmondo-files-EXT.h"
    1615#include "libmondo-fork-EXT.h"
    17 #include "libmondo-gui-EXT.h"
     16#include "newt-specific-EXT.h"
    1817#include "libmondo-tools-EXT.h"
    1918#include "mr_str.h"
     
    6867extern char *g_getfattr;
    6968
    70 
    71 
    7269/**
    7370 * @addtogroup filelistGroup
     
    8986    char *filelist;
    9087    char *tempfile;
    91     char *cksumlist;
    92     char *tmp;
    9388    long noof_sets;
    9489
     
    10095    int i, retval = 0;
    10196
    102     malloc_string(dev);
    103     malloc_string(filelist);
    104     malloc_string(tempfile);
    105     malloc_string(cksumlist);
    106     malloc_string(tmp);
    107     mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets");
    108 
    109     log_to_screen("Dividing filelist into sets. Please wait.");
     97    mvaddstr_and_log_it(g_currentY, 0, _("Dividing filelist into sets"));
     98
     99    log_to_screen(_("Dividing filelist into sets. Please wait."));
    110100    i = 0;
    111     sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    112     sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
     101    mr_asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    113102    if (!does_file_exist(filelist)) {
    114103        log_it("filelist %s not found", filelist);
     
    119108        chop_filelist(filelist, bkpinfo->tmpdir,
    120109                      bkpinfo->optimal_set_size);
     110    mr_free(filelist);
     111
    121112    estimate_noof_media_required(bkpinfo, noof_sets);   // for cosmetic purposes
    122113
    123     sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
     114    mr_asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
    124115    if (!(fout = fopen(tempfile, "a"))) {
    125116        log_OS_error("Cannot append to biggielist");
    126117        retval++;
    127         goto end_of_func;
    128     }
     118    }
     119    mr_free(tempfile);
    129120    log_it(bkpinfo->image_devs);
    130121
     
    132123
    133124    while (ptr && *ptr) {
    134         strcpy(dev, ptr);
     125        mr_asprintf(&dev, ptr);
    135126        log_it("Examining imagedev %s", dev);
    136127        for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     
    141132        fprintf(fout, "%s\n", dev);
    142133        log_it("Adding '%s' to biggielist", dev);
     134        mr_free(dev);
     135
    143136        if ((ptr = strchr(ptr, ' '))) {
    144137            ptr++;
     
    148141    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    149142
    150   end_of_func:
    151     mr_free(filelist);
    152     mr_free(tempfile);
    153     mr_free(cksumlist);
    154     mr_free(dev);
    155     mr_free(tmp);
    156143    return (retval);
    157144}
     
    166153
    167154    mr_msg(1, "Sorting file %s", orig_fname);
    168     malloc_string(tmp_fname);
    169     malloc_string(command);
    170     sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768),
    171             (int) (random() % 32768), (int) (random() % 32768));
     155    mr_asprintf(&tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768),
     156             (int) (random() % 32768), (int) (random() % 32768));
    172157
    173158    if (!does_file_exist(orig_fname)) {
     
    175160    }                           // no sense in trying to sort an empty file
    176161
    177     sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
    178             MONDO_LOGFILE);
     162    mr_asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
     163             MONDO_LOGFILE);
    179164    retval = system(command);
     165    mr_free(command);
     166
    180167    if (retval) {
    181168        mr_msg(2, "Failed to sort %s - oh dear", orig_fname);
     
    183170        mr_msg(2, "Sorted %s --> %s OK. Copying it back to %s now",
    184171                orig_fname, tmp_fname, orig_fname);
    185         sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
     172        mr_asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname);
    186173        retval += run_program_and_log_output(command, 2);
     174        mr_free(command);
     175
    187176        if (retval) {
    188177            mr_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname,
     
    193182    }
    194183    mr_free(tmp_fname);
    195     mr_free(command);
    196184    mr_msg(1, "Finished sorting file %s", orig_fname);
    197185    return (retval);
    198186}
    199 
    200187
    201188
     
    223210    /*@ int **************************************** */
    224211    int i;
     212    size_t n = 0;
    225213    long curr_set_no;
    226214
     
    228216    char *outfname;
    229217    char *biggie_fname;
    230     char *incoming;
     218    char *incoming = NULL;
    231219    char *tmp;
    232     char *acl_fname;
    233     char *xattr_fname;
    234220
    235221    /*@ pointers *********************************** */
     
    242228    int err = 0;
    243229
    244     malloc_string(outfname);
    245     malloc_string(biggie_fname);
    246     incoming = mr_malloc(MAX_STR_LEN * 2);
    247     malloc_string(tmp);
    248     malloc_string(acl_fname);
    249     malloc_string(xattr_fname);
    250230
    251231    assert_string_is_neither_NULL_nor_zerolength(filelist);
     
    267247    curr_set_no = 0;
    268248    curr_set_size = 0;
    269     sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
    270     sprintf(biggie_fname, "%s/biggielist.txt", outdir);
     249    mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no);
     250    mr_asprintf(&biggie_fname, "%s/biggielist.txt", outdir);
    271251    log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
    272252    if (!(fbig = fopen(biggie_fname, "w"))) {
     
    280260        goto end_of_func;
    281261    }
    282     (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     262    mr_getline(&incoming, &n, fin);
    283263    while (!feof(fin)) {
    284264        lino++;
     
    286266        if (i < 0) {
    287267            i = 0;
    288         }
    289         if (i > MAX_STR_LEN - 1) {
    290             incoming[MAX_STR_LEN - 30] = '\0';
    291             mr_msg(1, "Warning - truncating file %s's name", incoming);
    292             err++;
    293268        }
    294269        if (incoming[i] < 32) {
     
    312287                paranoid_fclose(fout);
    313288                sort_file(outfname);
     289                mr_free(outfname);
     290
    314291                curr_set_no++;
    315292                curr_set_size = 0;
    316                 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     293                mr_asprintf(&outfname, "%s/filelist.%ld", outdir,
     294                         curr_set_no);
    317295                if (!(fout = fopen(outfname, "w"))) {
    318296                    log_OS_error("Unable to openout outfname");
     
    320298                    goto end_of_func;
    321299                }
    322                 sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);
    323300                update_evalcall_form((int) (lino * 100 / noof_lines));
    324                 /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
    325301            }
    326302        }
    327         (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     303        mr_getline(&incoming, &n, fin);
    328304    }
    329305    paranoid_fclose(fin);
     
    338314    sort_file(outfname);
    339315    sort_file(biggie_fname);
    340     sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
    341     sprintf(tmp, "%ld", curr_set_no);
     316    mr_free(biggie_fname);
     317    mr_free(outfname);
     318
     319    mr_asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir);
     320    mr_asprintf(&tmp, "%ld", curr_set_no);
    342321    if (write_one_liner_data_file(outfname, tmp)) {
    343322        log_OS_error
     
    345324        err = 1;
    346325    }
     326    mr_free(outfname);
     327    mr_free(tmp);
     328
    347329    if (curr_set_no == 0) {
    348         sprintf(tmp, "Only one fileset. Fine.");
     330        mr_asprintf(&tmp, "Only one fileset. Fine.");
    349331    } else {
    350         sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
     332        mr_asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    351333    }
    352334    mr_msg(1, tmp);
     335    mr_free(tmp);
    353336    close_evalcall_form();
    354337    /* This is to work around an obscure bug in Newt; open a form, close it,
     
    365348#endif
    366349  end_of_func:
    367     mr_free(outfname);
    368     mr_free(biggie_fname);
    369     mr_free(incoming);
    370     mr_free(tmp);
    371     mr_free(acl_fname);
    372     mr_free(xattr_fname);
    373350    return (err ? 0 : curr_set_no + 1);
    374351}
    375 
    376 
    377 
    378352
    379353
     
    397371    if (depth == 0) {
    398372        open_evalcall_form("Freeing memory");
    399         log_to_screen("Freeing memory formerly occupied by filelist");
     373        log_to_screen(_("Freeing memory formerly occupied by filelist"));
    400374    }
    401375    depth++;
     
    420394    }
    421395    filelist->ch = '\0';
    422     mr_free((void*) filelist);
     396    mr_free((void *)filelist);
    423397    depth--;
    424398    if (depth == 0) {
     
    432406{
    433407    FILE *pattr;
    434     char *tmp;
     408    char *tmp = NULL;
     409    size_t n = 0;
     410
    435411    pattr = popen(sys_call, "r");
    436412    if (!pattr) {
     
    443419        return (2);
    444420    }
    445     malloc_string(tmp);
    446     for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
    447          fgets(tmp, MAX_STR_LEN, pattr)) {
     421    for (mr_getline(&tmp, &n, pattr); !feof(pattr); mr_getline(&tmp, &n, pattr)) {
    448422        fputs(tmp, pout);
    449423    }
     
    452426    return (0);
    453427}
    454 
    455428
    456429
     
    462435    char *pout_command;
    463436    char *sys_call;
    464     char *file_to_analyze;
     437    char *file_to_analyze = NULL;
    465438    char *strtmp = NULL;
    466439    int i;
     440    size_t n = 0;
    467441
    468442    if (!(fin = fopen(filelist, "r"))) {
     
    470444        return (1);
    471445    }
    472     malloc_string(pout_command);
    473     sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
     446    mr_asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname);
    474447    if (!(pout = popen(pout_command, "w"))) {
    475448        mr_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
     
    478451        return (4);
    479452    }
    480     malloc_string(file_to_analyze);
    481     for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
    482          fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     453    mr_free(pout_command);
     454
     455    for (mr_getline(&file_to_analyze, &n, fin); !feof(fin);
     456         mr_getline(&file_to_analyze, &n, fin)) {
    483457        i = strlen(file_to_analyze);
    484458        if (i > 0 && file_to_analyze[i - 1] < 32) {
     
    486460        }
    487461        mr_msg(8, "Analyzing %s", file_to_analyze);
    488         asprintf(&strtmp, syscall_sprintf, mr_stresc(file_to_analyze, "`$\\\"", '\\'));
    489         asprintf(&sys_call, "%s 2>> /dev/null", strtmp);    // " MONDO_LOGFILE);
     462        /* BERLIOS : to be checked */
     463        mr_asprintf(&strtmp, syscall_sprintf, mr_stresc(file_to_analyze, "`$\\\"", '\\'));
     464        mr_asprintf(&sys_call, "%s 2>> /dev/null", strtmp);
    490465        mr_free(strtmp);
    491466        call_exe_and_pipe_output_to_fd(sys_call, pout);
     
    495470    paranoid_pclose(pout);
    496471    mr_free(file_to_analyze);
    497     mr_free(pout_command);
    498472    return (0);
    499473}
     
    502476int get_acl_list(char *filelist, char *facl_fname)
    503477{
    504     char *command;
     478    char *command = NULL;
    505479    int retval = 0;
    506480
    507481    if (g_getfacl != NULL) {
    508         malloc_string(command);
    509         sprintf(command, "touch %s", facl_fname);
     482        mr_asprintf(&command, "touch %s", facl_fname);
    510483        run_program_and_log_output(command, 8);
    511 //      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    512         sprintf(command,
    513                 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s",
    514                 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
     484        mr_free(command);
     485
     486        mr_asprintf(&command,
     487                 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s",
     488                 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
    515489        iamhere(command);
    516490        retval = system(command);
     
    523497int get_fattr_list(char *filelist, char *fattr_fname)
    524498{
    525     char *command;
     499    char *command = NULL;
    526500    int retval = 0;
    527501
    528502    if (g_getfattr != NULL) {
    529         malloc_string(command);
    530         sprintf(command, "touch %s", fattr_fname);
     503        mr_asprintf(&command, "touch %s", fattr_fname);
    531504        run_program_and_log_output(command, 8);
    532505        mr_free(command);
    533 //      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
     506
    534507        retval =
    535508            gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"",
     
    544517{
    545518    const int my_depth = 8;
    546     char *command, *syscall_pin, *syscall_pout, *incoming;
    547     char *current_subset_file, *current_master_file, *masklist;
     519    char *command, *syscall_pin, *syscall_pout;
     520    char *incoming = NULL;
     521    char *current_subset_file = NULL;
     522    char *current_master_file, *masklist;
    548523    int retval = 0;
    549524    int i;
     525    size_t n = 0;
    550526    char *p, *q;
    551527    FILE *pin, *pout, *faclin;
    552528
    553     malloc_string(command);
    554529    mr_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
    555530            original_exat_fname, executable);
     
    558533        mr_msg(1,
    559534                "No masklist provided. I shall therefore set ALL attributes.");
    560         sprintf(command, "gzip -dc %s | %s --restore - 2>> %s",
    561                 original_exat_fname, executable, MONDO_LOGFILE);
     535        mr_asprintf(&command, "gzip -dc %s | %s --restore - 2>> %s",
     536                 original_exat_fname, executable, MONDO_LOGFILE);
    562537        mr_msg(1, "command = %s", command);
    563538        retval = system(command);
     
    570545                "original_exat_fname %s is empty or missing, so no need to set EXAT list",
    571546                original_exat_fname);
    572         mr_free(command);
    573547        return (0);
    574548    }
    575     malloc_string(incoming);
    576     malloc_string(masklist);
    577     malloc_string(current_subset_file);
    578     malloc_string(current_master_file);
    579     malloc_string(syscall_pin);
    580     malloc_string(syscall_pout);
    581     sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768),
    582             (int) (random() % 32768));
    583     sprintf(command, "cp -f %s %s", orig_msklist, masklist);
     549    mr_asprintf(&masklist, "/tmp/%d.%d.mask", (int) (random() % 32768),
     550             (int) (random() % 32768));
     551
     552    mr_asprintf(&command, "cp -f %s %s", orig_msklist, masklist);
    584553    run_program_and_log_output(command, 1);
     554    mr_free(command);
     555
    585556    sort_file(masklist);
    586     current_subset_file[0] = current_master_file[0] = '\0';
    587     sprintf(syscall_pin, "gzip -dc %s", original_exat_fname);
    588     sprintf(syscall_pout, "%s --restore - 2>> %s", executable,
    589             MONDO_LOGFILE);
     557    mr_asprintf(&syscall_pin, "gzip -dc %s", original_exat_fname);
     558    mr_asprintf(&syscall_pout, "%s --restore - 2>> %s", executable,
     559             MONDO_LOGFILE);
    590560
    591561    mr_msg(1, "syscall_pin = %s", syscall_pin);
     
    596566        return (1);
    597567    }
     568    mr_free(syscall_pout);
     569
    598570    pin = popen(syscall_pin, "r");
    599571    if (!pin) {
     
    602574        return (1);
    603575    }
     576    mr_free(syscall_pin);
     577
    604578    faclin = fopen(masklist, "r");
    605579    if (!faclin) {
     
    611585//  printf("Hi there. Starting the loop\n");
    612586
    613     fgets(current_subset_file, MAX_STR_LEN, faclin);
    614     fgets(incoming, MAX_STR_LEN, pin);
     587    mr_getline(&current_subset_file, &n, faclin);
     588    mr_getline(&incoming, &n, pin);
    615589    while (!feof(pin) && !feof(faclin)) {
    616590//      printf("incoming = %s", incoming);
    617591
    618         strcpy(current_master_file, incoming + 8);
     592        mr_asprintf(&current_master_file, incoming + 8);
    619593
    620594        p = current_subset_file;
     
    644618        if (i < 0) {            // read another subset file in.
    645619            mr_msg(my_depth, "Reading next subset line in\n\n");
    646             fgets(current_subset_file, MAX_STR_LEN, faclin);
     620            mr_getline(&current_subset_file, &n, faclin);
    647621            continue;
    648622        }
     
    651625            fputs(incoming, pout);
    652626        }
    653         fgets(incoming, MAX_STR_LEN, pin);
     627        mr_getline(&incoming, &n, pin);
    654628        if (!i) {
    655629            mr_msg(my_depth, "Copying master %s", q);
     
    664638                fputs(incoming, pout);
    665639            }
    666             fgets(incoming, MAX_STR_LEN, pin);
     640            mr_getline(&incoming, &n, pin);
    667641        }
    668642        if (!i) {
    669             fgets(current_subset_file, MAX_STR_LEN, faclin);
    670         }
    671     }
     643            mr_getline(&current_subset_file, &n, faclin);
     644        }
     645        mr_free(current_master_file);
     646    }
     647    mr_free(current_subset_file);
     648
    672649    while (!feof(pin)) {
    673         fgets(incoming, MAX_STR_LEN, pin);
    674     }
     650        mr_getline(&incoming, &n, pin);
     651    }
     652    mr_free(incoming);
    675653    fclose(faclin);
    676654    pclose(pin);
     
    680658
    681659    unlink(masklist);
    682     mr_free(current_subset_file);
    683     mr_free(current_master_file);
    684     mr_free(syscall_pout);
    685     mr_free(syscall_pin);
    686660    mr_free(masklist);
    687     mr_free(incoming);
    688     mr_free(command);
     661
    689662    return (retval);
    690663}
     
    724697    /*@ buffers ***************************************************** */
    725698    char val_sz[MAX_STR_LEN];
    726     char cfg_fname[MAX_STR_LEN];
    727 /*  char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */
     699    char *cfg_fname = NULL;
    728700
    729701    /*@ long ******************************************************** */
    730     int val_i;
     702    int val_i = 0;
    731703
    732704    /*@ end vars **************************************************** */
     
    734706    assert(bkpinfo != NULL);
    735707
    736     sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
     708    mr_asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
    737709    read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
    738710    val_i = atoi(val_sz);
     
    740712        val_i = 500;
    741713    }
     714    mr_free(cfg_fname);
    742715    return (val_i);
    743716}
     
    751724 * @bug I don't understand this function. Would someone care to explain it?
    752725 */
     726
    753727int add_string_at_node(struct s_node *startnode, char *string_to_add)
    754728{
    755729
    756 
    757     /*@ int ******************************************************** */
    758730    int noof_chars;
    759731    int i;
    760732    int res;
    761733
    762     /*@ sturctures ************************************************* */
    763734    struct s_node *node, *newnode;
    764735
    765     /*@ char  ****************************************************** */
    766736    char char_to_add;
    767 
    768     /*@ bools ****************************************************** */
    769737
    770738    const bool sosodef = FALSE;
     
    780748    }
    781749
    782     noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    783 
    784 /* walk across tree if necessary */
     750    noof_chars = strlen(string_to_add) + 1; // we include the '\0'
     751
     752    // walk across tree if necessary
    785753    node = startnode;
    786754    char_to_add = string_to_add[0];
     
    791759    }
    792760
    793 /* walk down tree if appropriate */
     761    // walk down tree if appropriate
    794762    if (node->down != NULL && node->ch == char_to_add) {
    795763        mr_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     
    805773    }
    806774
    807 /* add here */
     775    // add here
    808776    newnode = (struct s_node *) mr_malloc(sizeof(struct s_node));
    809777    if (char_to_add < node->ch) // add to the left of node
     
    829797        return (0);
    830798    }
    831 // add the rest
     799    // add the rest
    832800    mr_msg(6, "Adding remaining chars ('%s')", string_to_add + 1);
    833801    for (i = 1; i < noof_chars; i++) {
     
    848816
    849817
    850 
    851 
    852818/**
    853819 * Load a filelist into a <tt>struct s_node</tt>.
     
    859825{
    860826
    861     /*@ structures ************************************************* */
    862     struct s_node *filelist;
    863 
    864     /*@ pointers *************************************************** */
    865     FILE *pin;
    866 
    867     /*@ buffers **************************************************** */
    868     char command_to_open_fname[MAX_STR_LEN];
    869     char fname[MAX_STR_LEN];
    870     char tmp[MAX_STR_LEN];
    871     int pos_in_fname;
    872     /*@ int ******************************************************** */
    873     int percentage;
    874 
    875     /*@ long ******************************************************* */
    876     long lines_in_filelist;
    877     long lino = 0;
    878     /*@ end vars *************************************************** */
     827    struct s_node *filelist = NULL;
     828    FILE *pin = NULL;
     829    char *command_to_open_fname = NULL;
     830    char *fname = NULL;
     831    char *tmp = NULL;
     832    char *tmp1 = NULL;
     833    int pos_in_fname = 0;
     834    size_t n = 0;
     835    int percentage = 0;
     836
     837    long lines_in_filelist = 0L;
     838    long lino = 0L;
    879839
    880840    assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
     
    883843        fatal_error("filelist does not exist -- cannot load it");
    884844    }
    885     log_to_screen("Loading filelist");
    886     sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
    887     sprintf(tmp, "zcat %s | wc -l", filelist_fname);
     845    log_to_screen(_("Loading filelist"));
     846    mr_asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname);
     847    mr_asprintf(&tmp, "zcat %s | wc -l", filelist_fname);
    888848    mr_msg(6, "tmp = %s", tmp);
    889849    lines_in_filelist =
    890850        atol(call_program_and_get_last_line_of_output(tmp));
    891851    if (lines_in_filelist < 3) {
    892         log_to_screen("Warning - surprisingly short filelist.");
     852        log_to_screen(_("Warning - surprisingly short filelist."));
    893853    }
    894854    g_original_noof_lines_in_filelist = lines_in_filelist;
     
    905865        return (NULL);
    906866    }
    907     open_evalcall_form("Loading filelist from disk");
    908     for (fgets(fname, MAX_STR_LEN, pin); !feof(pin);
    909          fgets(fname, MAX_STR_LEN, pin)) {
     867    mr_free(command_to_open_fname);
     868
     869    open_evalcall_form(_("Loading filelist from disk"));
     870    for (mr_getline(&fname, &n, pin); !feof(pin); mr_getline(&fname, &n, pin)) {
    910871        if ((fname[strlen(fname) - 1] == 13
    911872             || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
    912873            fname[strlen(fname) - 1] = '\0';
    913874        }
    914 //      strip_spaces (fname);
    915875        if (!strlen(fname)) {
    916876            continue;
     
    920880                continue;
    921881            }
    922             strcpy(tmp, fname);
     882            mr_asprintf(&tmp, fname);
    923883            tmp[pos_in_fname] = '\0';
    924884            if (strlen(tmp)) {
    925885                add_string_at_node(filelist, tmp);
    926886            }
     887            mr_free(tmp);
    927888        }
    928889        add_string_at_node(filelist, fname);
     
    932893        }
    933894    }
     895    mr_free(fname);
    934896    paranoid_pclose(pin);
    935897    close_evalcall_form();
     
    976938
    977939
    978 
    979 
    980940/**
    981941 * Reset the filelist to the state it was when it was loaded. This does not
     
    992952
    993953
    994 
    995954/**
    996955 * Save a filelist tree structure to disk.
     
    1022981    assert(outfname != NULL);   // will be zerolength if save_filelist() is called by itself
    1023982    if (depth == 0) {
    1024         log_to_screen("Saving filelist");
     983        log_to_screen(_("Saving filelist"));
    1025984        if (!(fout = fopen(outfname, "w"))) {
    1026985            fatal_error("Cannot openout/save filelist");
    1027986        }
    1028987        lines_in_filelist = g_original_noof_lines_in_filelist;  /* set by load_filelist() */
    1029         open_evalcall_form("Saving selection to disk");
     988        open_evalcall_form(_("Saving selection to disk"));
    1030989    }
    1031990    for (node = filelist; node != NULL; node = node->right) {
     
    10561015
    10571016
    1058 
    10591017/**
    10601018 * Toggle all root dirs on.
     
    11241082    /*@ buffers **************************************************** */
    11251083    static char current_filename[MAX_STR_LEN];
    1126 
    1127 /*  char tmp[MAX_STR_LEN+2]; */
    11281084
    11291085    /*@ end vars *************************************************** */
     
    11791135}
    11801136
     1137
    11811138/**
    11821139 * Toggle whether a path is selected.
     
    11991156    /*@ buffers ***************************************************** */
    12001157    static char current_filename[MAX_STR_LEN];
    1201     char tmp[MAX_STR_LEN + 2];
    12021158
    12031159    /*@ end vars *************************************************** */
     
    12221178                    || current_filename[j] == '\0') {
    12231179                    node->selected = on_or_off;
    1224                     sprintf(tmp, "%s is now %s\n", current_filename,
    1225                             (on_or_off ? "ON" : "OFF"));
    12261180                }
    12271181            }
     
    12591213    }
    12601214}
    1261 
    1262 
    1263 
    1264 
    1265 
    12661215
    12671216
     
    12991248    if (bkpinfo->make_filelist) {
    13001249        mvaddstr_and_log_it(g_currentY, 0,
    1301                             "Making catalog of files to be backed up");
     1250                            _("Making catalog of files to be backed up"));
    13021251    } else {
    13031252        mvaddstr_and_log_it(g_currentY, 0,
    1304                             "Using supplied catalog of files to be backed up");
     1253                            _("Using supplied catalog of files to be backed up"));
    13051254    }
    13061255
     
    13221271    if (res) {
    13231272        log_OS_error("Call to mondo_makefilelist failed");
    1324         mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1273        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    13251274    } else {
    1326         mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1275        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    13271276    }
    13281277    return (res);
     
    13431292{
    13441293    const char delims[] = " ";
    1345 
    1346     DIR *dip;
    1347     struct dirent *dit;
     1294    DIR *dip = NULL;
     1295    struct dirent *dit = NULL;
     1296
    13481297    struct stat statbuf;
    13491298    char new[MAX_STR_LEN];
    1350     char *tmp;
    1351     char *sth_B;
     1299    char *tmp = NULL;
     1300    char *sth_B = NULL;
    13521301    static int percentage = 0;
    1353     char *ith_B;
    1354     char *skip_these;
    1355     char *new_with_spaces;
    1356     char *strtmp;
    1357     char *token;
    1358     char *find_excludes;
    1359     static char *name_of_evalcall_form;
    1360     int i;
     1302    char *ith_B = NULL;
     1303    char *skip_these = NULL;
     1304    char *new_with_spaces = NULL;
     1305    static char *name_of_evalcall_form = NULL;
     1306    int i = 0;
     1307    char *strtmp = NULL;
     1308    char *token = NULL;
     1309    char *find_excludes = NULL;
    13611310    int lastpos = 0;
    13621311    static int depth = 0;
    1363     char *p;
     1312    char *p = NULL;
    13641313    static int counter = 0;
    13651314    static int uberctr = 0;
    1366     static char *find_skeleton_marker;
     1315    static char *find_skeleton_marker = NULL;
    13671316    static long skeleton_lino = 0;
    13681317    static time_t last_time = 0;
     
    15231472
    15241473
    1525 
    15261474/**
    15271475 * Get the next entry in the space-separated list in @p incoming.
     
    15351483{
    15361484    static char sz_res[MAX_STR_LEN];
    1537     char *p;
     1485    char *p = NULL;
    15381486    bool in_quotes = FALSE;
    15391487
     
    15491497    return (sz_res);
    15501498}
    1551 
    15521499
    15531500
     
    15701517{
    15711518    char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d";
    1572     char *p, *q;
    1573     char sz_datefile[80];
    1574     char *sz_filelist, *exclude_paths, *tmp;
    1575     int i;
    1576     FILE *fout;
    1577     char *command;
     1519    char *p = NULL;
     1520    char *q = NULL;
     1521
     1522    char *tmp1 = NULL;
     1523    char *tmp2 = NULL;
     1524    char *sz_datefile = NULL;
     1525    char *sz_filelist = NULL;
     1526    char *exclude_paths = NULL;
     1527    int i = 0;
     1528    FILE *fout = NULL;
     1529    char *command = NULL;
    15781530    time_t time_of_last_full_backup = 0;
    15791531    struct stat statbuf;
    15801532
    1581     malloc_string(command);
    1582     malloc_string(tmp);
    1583     malloc_string(sz_filelist);
     1533    malloc_string(sz_datefile);
     1534    malloc_string(exclude_paths);
    15841535    malloc_string(g_skeleton_filelist);
    1585     exclude_paths = mr_malloc(1000);
    1586     mr_msg(3, "Trying to write test string to exclude_paths");
    1587     strcpy(exclude_paths, "/blah /froo");
    1588     mr_msg(3, "...Success!");
    1589     sprintf(sz_datefile, sz_datefile_wildcard, 0);
     1536    // The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
     1537    mr_asprintf(&sz_datefile, sz_datefile_wildcard, 0);
    15901538    if (!include_paths && !userdef_filelist) {
    15911539        fatal_error
     
    15931541    }
    15941542// make hole for filelist
    1595     sprintf(command, "mkdir -p %s/archives", scratchdir);
     1543    mr_asprintf(&command, "mkdir -p %s/archives", scratchdir);
    15961544    paranoid_system(command);
    1597     sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1545    mr_free(command);
     1546
     1547    mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    15981548    make_hole_for_file(sz_filelist);
    15991549
    16001550    if (differential == 0) {
    16011551        // restore last good datefile if it exists
    1602         sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1552        mr_asprintf(&command, "cp -f %s.aborted %s", sz_datefile,
     1553                 sz_datefile);
    16031554        run_program_and_log_output(command, 3);
     1555        mr_free(command);
     1556
    16041557        // backup last known good datefile just in case :)
    16051558        if (does_file_exist(sz_datefile)) {
    1606             sprintf(command, "mv -f %s %s.aborted", sz_datefile,
    1607                     sz_datefile);
     1559            mr_asprintf(&command, "mv -f %s %s.aborted", sz_datefile,
     1560                     sz_datefile);
    16081561            paranoid_system(command);
     1562            mr_free(command);
    16091563        }
    16101564        make_hole_for_file(sz_datefile);
     
    16211575        mr_msg(2, "Differential backup. Yay.");
    16221576    }
     1577    mr_free(sz_datefile);
    16231578
    16241579// use user-specified filelist (if specified)
     
    16271582                "Using the user-specified filelist - %s - instead of calculating one",
    16281583                userdef_filelist);
    1629         sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1584        mr_asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist);
    16301585        if (run_program_and_log_output(command, 3)) {
    16311586            fatal_error("Failed to copy user-specified filelist");
    16321587        }
     1588        mr_free(command);
    16331589    } else {
    16341590        mr_msg(2, "include_paths = '%s'", include_paths);
     
    16671623        }
    16681624        paranoid_fclose(fout);
     1625        mr_free(exclude_paths);
    16691626    }
    16701627    mr_msg(2, "Copying new filelist to scratchdir");
    1671     sprintf(command, "mkdir -p %s/archives", scratchdir);
     1628    mr_asprintf(&command, "mkdir -p %s/archives", scratchdir);
    16721629    paranoid_system(command);
    1673     sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
     1630    mr_free(command);
     1631
     1632    mr_asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
    16741633    paranoid_system(command);
    1675     sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
     1634    mr_free(command);
     1635
     1636    mr_asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir);
    16761637    paranoid_system(command);
    1677     mr_msg(2, "Freeing variables");
     1638    mr_free(command);
    16781639    mr_free(sz_filelist);
    1679     mr_free(command);
    1680     mr_free(exclude_paths);
    1681     mr_free(tmp);
    16821640    mr_free(g_skeleton_filelist);
    16831641    mr_msg(2, "Exiting");
    16841642    return (0);
    16851643}
    1686 
    1687 
    16881644
    16891645
     
    17501706
    17511707
    1752 
    17531708/**
    17541709 * Write all entries in @p needles_list_fname which are also in
     
    17681723    FILE *fin;
    17691724    FILE *fout;
    1770     char *fname;
     1725    char *fname = NULL;
    17711726    char *tmp;
    17721727    size_t len = 0;             // Scrub's patch doesn't work without that
    17731728
    1774 //  mr_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1775     malloc_string(fname);
    1776     malloc_string(tmp);
    17771729    mr_msg(5, "starting");
    17781730    mr_msg(5, "needles_list_fname = %s", needles_list_fname);
     
    17851737    }
    17861738    while (!feof(fin)) {
    1787 //      fscanf(fin, "%s\n", fname);
    1788         len = MAX_STR_LEN - 1;
    1789         getline(&fname, &len, fin); // patch by Scrub
     1739        mr_getline(&fname, &len, fin);
    17901740        if (!use_star) {
    17911741            if (fname[0] == '/') {
    1792                 strcpy(tmp, fname);
     1742                mr_asprintf(&tmp, fname);
    17931743            } else {
    1794                 tmp[0] = '/';
    1795                 strcpy(tmp + 1, fname);
     1744                mr_asprintf(&tmp, "/%s", fname);
    17961745            }
    1797             strcpy(fname, tmp);
     1746            mr_free(fname);
     1747            fname = tmp;
    17981748        }
    17991749        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
    18001750            fname[strlen(fname) - 1] = '\0';
    18011751        }
    1802 
    1803 /*
    1804       if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }
    1805       if (strlen(fname)==0) { continue; }
    1806       sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
    1807       system(temporary_string);
    1808 */
    18091752
    18101753        mr_msg(5, "Looking for '%s'", fname);
     
    18121755        if (found_node) {
    18131756            if (found_node->selected) {
    1814 //              if (use_star)
    18151757                if (fname[0] == '/') {
    1816                     strcpy(tmp, fname + 1);
    1817                     strcpy(fname, tmp);
     1758                    mr_asprintf(&tmp, fname + 1);
     1759                    mr_free(fname);
     1760                    fname = tmp;
    18181761                }
    18191762                mr_msg(5, "Found '%s'", fname);
    18201763                turn_wildcard_chars_into_literal_chars(tmp, fname);
    18211764                fprintf(fout, "%s\n", tmp);
     1765                mr_free(tmp);
    18221766                retval++;
    18231767            }
    18241768        }
     1769        mr_free(fname);
    18251770    }
    18261771    paranoid_fclose(fout);
    18271772    paranoid_fclose(fin);
    1828     mr_free(fname);
    1829     mr_free(tmp);
    18301773    return (retval);
    18311774}
    1832 
    1833 
    1834 
    1835 
    18361775
    18371776
     
    18481787{
    18491788    FILE *fin;
    1850     char *tmp;
     1789    char *tmp = NULL;
     1790    size_t n = 0;
    18511791    struct s_node *nod;
    18521792
    1853     malloc_string(tmp);
    18541793    mr_msg(3, "Adding %s to filelist", list_of_files_fname);
    18551794    if (!(fin = fopen(list_of_files_fname, "r"))) {
     
    18571796        return (1);
    18581797    }
    1859     for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    1860          fgets(tmp, MAX_STR_LEN, fin)) {
     1798    for (mr_getline(&tmp, &n, fin); !feof(fin); mr_getline(&tmp, &n, fin)) {
    18611799        if (!tmp[0]) {
    18621800            continue;
Note: See TracChangeset for help on using the changeset viewer.