Changeset 1113 in MondoRescue


Ignore:
Timestamp:
Feb 8, 2007, 3:08:10 AM (17 years ago)
Author:
Bruno Cornec
Message:

Memory management improvements again for libmondo-fork.c & libmondo-files.c

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

Legend:

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

    r684 r1113  
    77extern unsigned int updcrcr(unsigned int crc, unsigned int c);
    88extern char *calc_checksum_of_file(char *filename);
    9 extern char *calc_file_ugly_minichecksum(char *curr_fname);
    109extern long count_lines_in_file(char *filename);
    1110extern bool does_file_exist(char *filename);
     
    1716extern char *last_line_of_file(char *filename);
    1817extern off_t length_of_file(char *filename);
    19 extern int make_checksum_list_file(char *filelist, char *cksumlist,
    20                                    char *comppath);
    2118extern int make_hole_for_file(char *outfile_fname);
    2219extern void make_list_of_files_to_ignore(char *ignorefiles_fname,
  • branches/stable/mondo/src/common/libmondo-files.c

    r1107 r1113  
    1313#include "libmondo-files.h"
    1414
    15 #include "lib-common-externs.h"
    16 
    1715#include "libmondo-tools-EXT.h"
    18 #include "libmondo-gui-EXT.h"
     16#include "newt-specific-EXT.h"
    1917#include "libmondo-devices-EXT.h"
    2018#include "libmondo-fork-EXT.h"
    2119#include "libmondo-string-EXT.h"
     20#include "mr_mem.h"
    2221
    2322#include "mr_file.h"
     
    4544    /*@ buffers ***************************************************** */
    4645    static char output[MAX_STR_LEN];
    47     char command[MAX_STR_LEN * 2];
    48     char tmp[MAX_STR_LEN];
     46
     47    char *command = NULL;
     48    char *tmp = NULL;
     49    size_t n = 0;
    4950
    5051    /*@ pointers **************************************************** */
     
    5960
    6061    assert_string_is_neither_NULL_nor_zerolength(filename);
     62
    6163    if (does_file_exist(filename)) {
    62         sprintf(command, "md5sum \"%s\"", filename);
     64        mr_asprintf(&command, "md5sum \"%s\"", filename);
    6365        fin = popen(command, "r");
     66        mr_free(command);
     67
    6468        if (fin) {
    6569            (void) fgets(output, MAX_STR_LEN, fin);
     
    6872        }
    6973    } else {
    70         sprintf(tmp, "File '%s' not found; cannot calc checksum",
     74        mr_asprintf(&tmp, "File '%s' not found; cannot calc checksum",
    7175                filename);
    7276        log_it(tmp);
     77        mr_free(tmp);
    7378    }
    7479    if (p) {
     
    124129
    125130    /*@ buffers ***************************************************** */
    126     char command[MAX_STR_LEN * 2];
    127     char incoming[MAX_STR_LEN];
    128     char tmp[MAX_STR_LEN];
     131    char *command = NULL;
     132    char *incoming = NULL;
     133    char *tmp = NULL;
    129134
    130135    /*@ long ******************************************************** */
    131136    long noof_lines = -1L;
    132137
     138    /*@ int ******************************************************** */
     139    size_t n = 0;
     140
    133141    /*@ pointers **************************************************** */
    134142    FILE *fin;
    135143
    136     /*@ initialize [0] to null ******************************************** */
    137     incoming[0] = '\0';
    138 
    139144    assert_string_is_neither_NULL_nor_zerolength(filename);
    140145    if (!does_file_exist(filename)) {
    141         sprintf(tmp,
     146        mr_asprintf(&tmp,
    142147                "%s does not exist, so I cannot found the number of lines in it",
    143148                filename);
    144149        log_it(tmp);
     150        mr_free(tmp);
    145151        return (0);
    146152    }
    147     sprintf(command, "cat %s | wc -l", filename);
     153    mr_asprintf(&command, "cat %s | wc -l", filename);
    148154    if (!does_file_exist(filename)) {
    149155        return (-1);
    150156    }
    151157    fin = popen(command, "r");
     158    mr_free(command);
     159
    152160    if (fin) {
    153161        if (feof(fin)) {
    154162            noof_lines = 0;
    155163        } else {
    156             (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     164            mr_getline(&incoming, &n, fin);
    157165            while (strlen(incoming) > 0
    158166                   && incoming[strlen(incoming) - 1] < 32) {
     
    160168            }
    161169            noof_lines = atol(incoming);
     170            mr_free(incoming);
    162171        }
    163172        paranoid_pclose(fin);
     
    181190
    182191    assert(filename != NULL);
    183     //  assert_string_is_neither_NULL_nor_zerolength(filename);
     192
    184193    if (lstat(filename, &buf)) {
    185194        mr_msg(20, "%s does not exist", filename);
     
    192201
    193202
    194 
    195 
    196 
    197 
    198203/**
    199204 * Modify @p inout (a file containing a list of files) to only contain files
     
    212217    /*@ int ********************************************************* */
    213218    int i;
     219    size_t n = 0;
    214220
    215221    /*@ pointers **************************************************** */
     
    220226
    221227    assert_string_is_neither_NULL_nor_zerolength(inout);
    222     sprintf(infname, "%s.in", inout);
    223     sprintf(outfname, "%s", inout);
    224     sprintf(tmp, "cp -f %s %s", inout, infname);
     228
     229    mr_asprintf(&infname, "%s.in", inout);
     230
     231    mr_asprintf(&tmp, "cp -f %s %s", inout, infname);
    225232    run_program_and_log_output(tmp, FALSE);
     233    mr_free(tmp);
     234
    226235    if (!(fin = fopen(infname, "r"))) {
    227236        log_OS_error("Unable to openin infname");
     237        mr_free(infname);
    228238        return;
    229239    }
     240
     241    mr_asprintf(&outfname, "%s", inout);
    230242    if (!(fout = fopen(outfname, "w"))) {
    231243        log_OS_error("Unable to openout outfname");
     244        mr_free(infname);
     245        mr_free(outfname);
    232246        return;
    233247    }
    234     for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    235          fgets(incoming, MAX_STR_LEN, fin)) {
     248    mr_free(outfname);
     249
     250    for (mr_getline(&incoming, &n, fin); !feof(fin);
     251         mr_getline(&incoming, &n, fin)) {
    236252        i = strlen(incoming) - 1;
    237253        if (i >= 0 && incoming[i] < 32) {
     
    241257            fprintf(fout, "%s\n", incoming);
    242258        } else {
    243             sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
     259            mr_asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming);
    244260            log_it(tmp);
    245         }
    246     }
     261            mr_free(tmp);
     262        }
     263    }
     264    mr_free(incoming);
    247265    paranoid_fclose(fout);
    248266    paranoid_fclose(fin);
    249267    unlink(infname);
    250 }
    251 
    252 
    253 
    254 
    255 
    256 
    257 
     268    mr_free(infname);
     269}
    258270
    259271
     
    267279int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    268280{
    269     char tmp[MAX_STR_LEN];
    270     char *command;
    271 
     281    char *tmp = NULL;
     282    char *command = NULL;
     283
     284    malloc_string(tmp);
    272285    if (!kernel[0]) {
    273286        strcpy(kernel,
     
    277290    // If we didn't get anything back, check whether mindi raised a fatal error
    278291    if (!kernel[0]) {
    279         malloc_string(command);
    280         strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
     292        mr_asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
    281293        strcpy(tmp, call_program_and_get_last_line_of_output(command));
    282294        if (strlen(tmp) > 1) {
     
    299311                ("Kernel not found. Please specify with the '-k' flag.");
    300312        }
    301         sprintf(tmp, "User says kernel is at %s", kernel);
    302         log_it(tmp);
     313        log_it("User says kernel is at %s", kernel);
    303314    }
    304315    return (0);
    305316}
    306 
    307 
    308 
    309 
    310317
    311318
     
    324331    static char output[MAX_STR_LEN];
    325332    char *incoming;
    326     char *command;
     333    char *command = NULL;
    327334
    328335    malloc_string(incoming);
    329     malloc_string(command);
    330336    incoming[0] = '\0';
    331337    /*@******************************* */
    332338
    333339    assert_string_is_neither_NULL_nor_zerolength(fname);
    334     sprintf(command, "which %s 2> /dev/null", fname);
     340
     341    mr_asprintf(&command, "which %s 2> /dev/null", fname);
    335342    strcpy(incoming, call_program_and_get_last_line_of_output(command));
     343    mr_free(command);
     344
    336345    if (incoming[0] == '\0') {
    337346        if (system("which file > /dev/null 2> /dev/null")) {
     
    341350            return (NULL);      // forget it :)
    342351        }
    343         sprintf(command,
     352        mr_asprintf(&command,
    344353                "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
    345354                incoming);
    346355        strcpy(incoming,
    347356               call_program_and_get_last_line_of_output(command));
     357        mr_free(command);
    348358    }
    349359    if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    350360    {
    351         sprintf(command, "dirname %s 2> /dev/null", incoming);
     361        mr_asprintf(&command, "dirname %s 2> /dev/null", incoming);
    352362        strcpy(incoming,
    353363               call_program_and_get_last_line_of_output(command));
     364        mr_free(command);
    354365    }
    355366    strcpy(output, incoming);
     
    362373    }
    363374    mr_free(incoming);
    364     mr_free(command);
    365375    if (!output[0]) {
    366376        return (NULL);
     
    371381
    372382
    373 
    374 
    375 
    376 
    377 
    378 
    379383/**
    380384 * Get the last sequence of digits surrounded by non-digits in the first 32k of
     
    397401
    398402    assert_string_is_neither_NULL_nor_zerolength(logfile);
     403
    399404    if (!(fin = fopen(logfile, "r"))) {
    400405        log_OS_error("Unable to open logfile");
     
    410415    for (; len > 0 && isdigit(datablock[len - 1]); len--);
    411416    trackno = atoi(datablock + len);
    412     /*
    413        sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    414        log_it(tmp);
    415      */
    416417    return (trackno);
    417418}
    418 
    419 
    420 
    421 
    422 
    423419
    424420
     
    432428{
    433429
    434     /*@ buffers ***************************************************** */
    435     char tmp[MAX_STR_LEN];
    436     char lastline[MAX_STR_LEN];
    437     char command[MAX_STR_LEN];
    438     /*@ pointers **************************************************** */
    439     char *p;
    440 
    441     /*@ int's ******************************************************* */
     430    char *lastline = NULL;
     431    char *command = NULL;
     432    char *p = NULL;
    442433    int i;
    443434
     435    malloc_string(lastline);
    444436    for (i = NOOF_ERR_LINES - 1;
    445437         i >= 0 && !strstr(err_log_lines[i], "% Done")
    446438         && !strstr(err_log_lines[i], "% done"); i--);
    447439    if (i < 0) {
    448         sprintf(command,
     440        mr_asprintf(&command,
    449441                "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
    450442                filename, '%');
    451443        strcpy(lastline,
    452444               call_program_and_get_last_line_of_output(command));
     445        mr_free(command);
    453446        if (!lastline[0]) {
    454447            return (0);
     
    462455        *p = '\0';
    463456    }
    464 //  mr_msg(2, "lastline='%s', ", p, lastline);
    465457    if (!p) {
    466458        return (0);
     
    473465    i = atoi(p);
    474466
    475     sprintf(tmp, "'%s' --> %d", p, i);
    476 //     log_to_screen(tmp);
    477 
    478467    return (i);
    479468}
    480 
    481 
    482 
    483469
    484470
     
    493479    /*@ buffers ***************************************************** */
    494480    static char output[MAX_STR_LEN];
    495     static char command[MAX_STR_LEN * 2];
    496     static char tmp[MAX_STR_LEN];
     481    char *command = NULL;
     482    char *tmp = NULL;
    497483
    498484    /*@ pointers **************************************************** */
    499485    FILE *fin;
     486    size_t n = 0;
    500487
    501488    /*@ end vars **************************************************** */
    502489
    503490    if (!does_file_exist(filename)) {
    504         sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
     491        mr_asprintf(&tmp, _("Tring to get last line of nonexistent file (%s)"),
    505492                filename);
    506493        log_it(tmp);
     494        mr_free(tmp);
    507495        output[0] = '\0';
    508496        return (output);
    509497    }
    510     sprintf(command, "tail -n1 %s", filename);
     498    mr_asprintf(&command, "tail -n1 %s", filename);
    511499    fin = popen(command, "r");
     500    mr_free(command);
     501
    512502    (void) fgets(output, MAX_STR_LEN, fin);
    513503    paranoid_pclose(fin);
     
    517507    return (output);
    518508}
     509
    519510
    520511/**
     
    544535
    545536
    546 
    547 /**
    548  * ?????
    549  * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.
    550  */
    551 int
    552 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
    553 {
    554     /*@ pointers **************************************************** */
    555     FILE *fin;
    556     FILE *fout;
    557 
    558     /*@ int   ******************************************************* */
    559     int percentage;
    560     int i;
    561     int counter = 0;
    562 
    563     /*@ buffer ****************************************************** */
    564     char stub_fname[1000];
    565     char curr_fname[1000];
    566     char curr_cksum[1000];
    567     char tmp[1000];
    568 
    569     /*@ long [long] ************************************************* */
    570     off_t filelist_length;
    571     off_t curr_pos;
    572     long start_time;
    573     long current_time;
    574     long time_taken;
    575     long time_remaining;
    576 
    577     /*@ end vars *************************************************** */
    578 
    579     start_time = get_time();
    580     filelist_length = length_of_file(filelist);
    581     sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    582     log_it(tmp);
    583     fin = fopen(filelist, "r");
    584     if (fin == NULL) {
    585         log_OS_error("Unable to fopen-in filelist");
    586         log_to_screen("Can't open filelist");
    587         return (1);
    588     }
    589     fout = fopen(cksumlist, "w");
    590     if (fout == NULL) {
    591         log_OS_error("Unable to openout cksumlist");
    592         paranoid_fclose(fin);
    593         log_to_screen("Can't open checksum list");
    594         return (1);
    595     }
    596     for (fgets(stub_fname, 999, fin); !feof(fin);
    597          fgets(stub_fname, 999, fin)) {
    598         if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
    599             stub_fname[i] = '\0';
    600         }
    601         sprintf(tmp, "%s%s", comppath, stub_fname);
    602         strcpy(curr_fname, tmp + 1);
    603         strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
    604         fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
    605         if (counter++ > 12) {
    606             current_time = get_time();
    607             counter = 0;
    608             curr_fname[37] = '\0';
    609             curr_pos = ftello(fin) / 1024;
    610             percentage = (int) (curr_pos * 100 / filelist_length);
    611             time_taken = current_time - start_time;
    612             if (percentage == 0) {
    613                 /*              printf("%0d%% done      \r",percentage); */
    614             } else {
    615                 time_remaining =
    616                     time_taken * 100 / (long) (percentage) - time_taken;
    617                 sprintf(tmp,
    618                         "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    619                         percentage, (int) (time_taken / 60),
    620                         (int) (time_taken % 60),
    621                         (int) (time_remaining / 60),
    622                         (int) (time_remaining % 60), curr_fname);
    623                 log_to_screen(tmp);
    624             }
    625             sync();
    626         }
    627     }
    628     paranoid_fclose(fout);
    629     paranoid_fclose(fin);
    630     log_it("Done.");
    631     return (0);
    632 }
    633 
    634 
    635537/**
    636538 * Create the directory @p outdir_fname and all parent directories. Equivalent to <tt>mkdir -p</tt>.
     
    638540 * @return The return value of @c mkdir.
    639541 */
     542/* BERLIOS: This function shouldn't call system at all */
    640543int make_hole_for_dir(char *outdir_fname)
    641544{
    642     char tmp[MAX_STR_LEN * 2];
     545    char *tmp;
    643546    int res = 0;
    644547
    645548    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    646     sprintf(tmp, "mkdir -p %s", outdir_fname);
     549    mr_asprintf(&tmp, "mkdir -p %s", outdir_fname);
    647550    res = system(tmp);
     551    mr_free(tmp);
    648552    return (res);
    649553}
     
    656560 * @bug Return value unnecessary.
    657561 */
     562/* BERLIOS: This function shouldn't call system at all */
    658563int make_hole_for_file(char *outfile_fname)
    659564{
    660565    /*@ buffer ****************************************************** */
    661     char command[MAX_STR_LEN * 2];
     566    char *command;
    662567
    663568    /*@ int  ******************************************************** */
     
    669574    assert(!strstr(outfile_fname, MNT_CDROM));
    670575    assert(!strstr(outfile_fname, "/dev/cdrom"));
    671     sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     576
     577    mr_asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    672578    res += system(command);
    673     sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     579    mr_free(command);
     580
     581    mr_asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    674582    res += system(command);
    675     sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     583    mr_free(command);
     584
     585    mr_asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    676586    res += system(command);
     587    mr_free(command);
    677588    unlink(outfile_fname);
    678589    return (0);
    679590}
    680 
    681 
    682591
    683592
     
    697606
    698607    /*@ buffers **************************************************** */
    699     char incoming[MAX_STR_LEN];
    700 
     608    char *incoming = NULL;
     609
     610    size_t n = 0;
    701611    /*@ end vars *************************************************** */
    702612
     
    708618        return (0);
    709619    }
    710     (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     620    mr_getline(&incoming, &n, fin);
    711621    while (!feof(fin)) {
    712622        if (strstr(incoming, wildcard)) {
    713623            matches++;
    714624        }
    715         (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     625        mr_getline(&incoming, &n, fin);
    716626    }
    717627    paranoid_fclose(fin);
     628    mr_free(incoming);
    718629    return (matches);
    719630}
    720 
    721 
    722631
    723632
     
    731640void register_pid(pid_t pid, char *name_str)
    732641{
    733     char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1];
     642    char *tmp = NULL;
     643    char *lockfile_fname = NULL;
    734644    int res;
     645    size_t n = 0;
    735646    FILE *fin;
    736647
    737     sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);
     648    mr_asprintf(&lockfile_fname, "/var/run/monitas-%s.pid", name_str);
    738649    if (!pid) {
    739650        log_it("Unregistering PID");
     
    741652            log_it("Error unregistering PID");
    742653        }
     654        mr_free(lockfile_fname);
    743655        return;
    744656    }
    745657    if (does_file_exist(lockfile_fname)) {
    746         tmp[0] = '\0';
    747658        if ((fin = fopen(lockfile_fname, "r"))) {
    748             (void) fgets(tmp, MAX_STR_LEN, fin);
     659            mr_getline(&tmp, &n, fin);
    749660            paranoid_fclose(fin);
    750661        } else {
     
    752663        }
    753664        pid = (pid_t) atol(tmp);
    754         sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
     665        mr_free(tmp);
     666
     667        mr_asprintf(&tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
    755668        res = system(tmp);
     669        mr_free(tmp);
    756670        if (!res) {
    757671            log_it
     
    760674        }
    761675    }
    762     sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
     676    mr_asprintf(&tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
    763677            lockfile_fname);
     678    mr_free(lockfile_fname);
     679
    764680    if (system(tmp)) {
    765681        fatal_error("Cannot register PID");
    766682    }
    767 }
    768 
     683    mr_free(tmp);
     684    return;
     685}
    769686
    770687
     
    777694long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    778695{
    779     char command[MAX_STR_LEN];
    780     char mountlist[MAX_STR_LEN];
    781     char sz_res[MAX_STR_LEN];
    782     long file_len_K;
    783 
    784     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    785     sprintf(command,
    786             "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'",
     696    char *command = NULL;
     697    char *sz_res = NULL;
     698    long file_len_K = 0L;
     699
     700    malloc_string(sz_res);
     701    mr_asprintf(&command,
     702            "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'",
    787703            dev, tmpdir);
    788704    log_it(command);
     
    790706    file_len_K = atol(sz_res);
    791707    mr_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     708    mr_free(command);
     709    mr_free(sz_res);
    792710    return (file_len_K);
    793711}
     712
    794713
    795714/**
     
    800719long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo)
    801720{
    802     /*@ buffers ***************************************************** */
    803     char *fname;
    804     char *biggielist;
    805     char *comment;
    806     char *tmp;
    807     char *command;
     721    char *fname = NULL;
     722    char *biggielist = NULL;
     723    char *comment = NULL;
     724    char *tmp = NULL;
     725    char *command = NULL;
    808726
    809727    /*@ long ******************************************************** */
    810     long scratchL = 0;
    811     long file_len_K;
     728    long scratchL = 0L;
     729    long file_len_K = 0L;
    812730
    813731    /*@ pointers *************************************************** */
    814732    FILE *fin = NULL;
     733    size_t n = 0;
    815734
    816735    /*@ end vars *************************************************** */
    817736
    818     malloc_string(fname);
    819     malloc_string(biggielist);
    820     malloc_string(comment);
    821737    malloc_string(tmp);
    822     malloc_string(command);
    823738    log_it("Calculating size of all biggiefiles (in total)");
    824     sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     739    mr_asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    825740    log_it("biggielist = %s", biggielist);
    826741    if (!(fin = fopen(biggielist, "r"))) {
     
    829744    } else {
    830745        mr_msg(4, "Reading it...");
    831         for (fgets(fname, MAX_STR_LEN, fin); !feof(fin);
    832              fgets(fname, MAX_STR_LEN, fin)) {
     746        for (mr_getline(&fname, &n, fin); !feof(fin);
     747             mr_getline(&fname, &n, fin)) {
    833748            if (fname[strlen(fname) - 1] <= 32) {
    834749                fname[strlen(fname) - 1] = '\0';
     
    839754                        fatal_error("ntfsresize not found");
    840755                    }
    841                     sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     756                    mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    842757                    log_it("command = %s", command);
    843758                    strcpy (tmp, call_program_and_get_last_line_of_output(command));
     759                    mr_free(command);
     760
    844761                    log_it("res of it = %s", tmp);
    845762                    file_len_K = atoll(tmp) / 1024L;
     
    855772                mr_msg(4, "%s --> %ld K", fname, file_len_K);
    856773            }
    857             sprintf(comment,
     774            mr_asprintf(&comment,
    858775                    "After adding %s, scratchL+%ld now equals %ld", fname,
    859776                    file_len_K, scratchL);
    860777            mr_msg(4, comment);
     778            mr_free(comment);
     779
    861780            if (feof(fin)) {
    862781                break;
    863782            }
    864783        }
    865     }
     784        mr_free(fname);
     785    }
     786    mr_free(biggielist);
     787
    866788    log_it("Closing...");
    867789    paranoid_fclose(fin);
    868790    log_it("Finished calculating total size of all biggiefiles");
    869     mr_free(fname);
    870     mr_free(biggielist);
    871     mr_free(comment);
    872791    mr_free(tmp);
    873     mr_free(command);
    874792    return (scratchL);
    875793}
     
    884802{
    885803    /*@ buffer ****************************************************** */
    886     char tmp[MAX_STR_LEN];
    887     char command[MAX_STR_LEN * 2];
     804    char *tmp = NULL;
     805    char *command = NULL;
    888806    long long llres;
     807    size_t n = 0;
    889808    /*@ pointers **************************************************** */
    890     char *p;
    891     FILE *fin;
     809    char *p = NULL;
     810    FILE *fin = NULL;
    892811
    893812    /*@ end vars *************************************************** */
    894813
    895     sprintf(command, "du -sk %s", mountpt);
     814    mr_asprintf(&command, "du -sk %s", mountpt);
    896815    errno = 0;
    897816    fin = popen(command, "r");
     
    900819      llres = 0;
    901820    } else {
    902       (void) fgets(tmp, MAX_STR_LEN, fin);
    903       paranoid_pclose(fin);
    904       p = strchr(tmp, '\t');
    905       if (p) {
    906         *p = '\0';
    907       }
    908       for (p = tmp, llres = 0; *p != '\0'; p++) {
    909         llres *= 10;
    910         llres += (int) (*p - '0');
    911       }
    912     }
    913 
     821        mr_getline(&tmp, &n, fin);
     822        paranoid_pclose(fin);
     823        p = strchr(tmp, '\t');
     824        if (p) {
     825            *p = '\0';
     826        }
     827        for (p = tmp, llres = 0; *p != '\0'; p++) {
     828            llres *= 10;
     829            llres += (int) (*p - '0');
     830        }
     831    }
     832
     833    mr_free(command);
     834    mr_free(tmp);
    914835    return (llres);
    915836}
     
    931852}
    932853
     854
    933855/**
    934856 * Update a reverse CRC checksum to include another character.
     
    947869
    948870
    949 
    950 
    951871/**
    952872 * Check for an executable on the user's system; write a message to the
     
    958878{
    959879    /*@ buffers *** */
    960     char command[MAX_STR_LEN * 2];
    961     char errorstr[MAX_STR_LEN];
    962 
    963 
    964     sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    965     sprintf(errorstr,
    966             "Please install '%s'. I cannot find it on your system.",
     880    char *command;
     881    char *errorstr;
     882    int res = 0;
     883
     884
     885    mr_asprintf(&command, "which %s > /dev/null 2> /dev/null", fname);
     886    res = system(command);
     887    mr_free(command);
     888
     889    if (res) {
     890        mr_asprintf(&errorstr,
     891            _("Please install '%s'. I cannot find it on your system."),
    967892            fname);
    968     if (system(command)) {
    969893        log_to_screen(errorstr);
     894        mr_free(errorstr);
    970895        log_to_screen
    971             ("There may be hyperlink at http://www.mondorescue.com which");
    972         log_to_screen("will take you to the relevant (missing) package.");
     896            (_("There may be an hyperlink at http://www.mondorescue.org which"));
     897        log_to_screen(_("will take you to the relevant (missing) package."));
    973898        return (1);
    974899    } else {
     
    976901    }
    977902}
    978 
    979 
    980 
    981 
    982903
    983904
     
    1012933
    1013934
    1014 
    1015935/**
    1016936 * Read @p fname into @p contents.
     
    1045965    return (res);
    1046966}
    1047 
    1048 
    1049 
    1050 
    1051 
    1052 
    1053 
    1054967
    1055968
     
    1067980{
    1068981    /*@ Char buffers ** */
    1069     char command[MAX_STR_LEN * 2];
     982    char *command = NULL;
    1070983    char tmp[MAX_STR_LEN];
    1071984    char old_pwd[MAX_STR_LEN];
     
    1074987                        "Copying Mondo's core files to the scratch directory");
    1075988
     989    /* BERLIOS: Why do we need to do it here as well ? */
    1076990    mr_msg(4, "g_mondo_home='%s'", g_mondo_home);
    1077991    if (strlen(g_mondo_home) < 2) {
    1078992        find_and_store_mondoarchives_home(g_mondo_home);
    1079993    }
    1080     sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
     994    mr_asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    1081995            bkpinfo->scratchdir);
    1082996
     
    1085999        fatal_error("Failed to copy Mondo's stuff to scratchdir");
    10861000    }
     1001    mr_free(command);
     1002
     1003    /* i18n */
     1004    mr_asprintf(&command, CP_BIN " --parents /usr/share/locale/*/LC_MESSAGES/mondo.mo %s",bkpinfo->scratchdir);
     1005    mr_msg(4, "command = %s", command);
     1006    run_program_and_log_output(command, 1);
     1007    mr_free(command);
    10871008
    10881009    sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     
    10921013        (void) getcwd(old_pwd, MAX_STR_LEN - 1);
    10931014        chdir(bkpinfo->scratchdir);
    1094         sprintf(command, "tar -zxvf %s", tmp);
     1015        mr_asprintf(&command, "tar -zxvf %s", tmp);
    10951016        if (run_program_and_log_output(command, FALSE)) {
    10961017            fatal_error("Failed to untar payload");
    10971018        }
     1019        mr_free(command);
    10981020        chdir(old_pwd);
    10991021    }
    11001022
    1101     sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
     1023    mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    11021024            bkpinfo->scratchdir);
    11031025
     
    11051027        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    11061028    }
    1107 
    1108     strcpy(tmp,
    1109            call_program_and_get_last_line_of_output("which mondorestore"));
    1110     if (!tmp[0]) {
     1029    mr_free(command);
     1030
     1031    tmp = call_program_and_get_last_line_of_output("which mondorestore");
     1032    if (!tmp) {
    11111033        fatal_error
    11121034            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    11131035    }
    1114     sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1036    mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    11151037    if (run_program_and_log_output(command, FALSE)) {
    11161038        fatal_error("Failed to copy mondorestore to tmpdir");
    11171039    }
    1118 
    1119     sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1040    mr_free(command);
     1041
     1042    mr_asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    11201043    paranoid_system(command);
     1044    mr_free(command);
    11211045
    11221046    if (bkpinfo->postnuke_tarball[0]) {
    1123         sprintf(command, "cp -f %s %s/post-nuke.tgz",
     1047        mr_asprintf(&command, "cp -f %s %s/post-nuke.tgz",
    11241048                bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    11251049        if (run_program_and_log_output(command, FALSE)) {
    11261050            fatal_error("Unable to copy post-nuke tarball to tmpdir");
    11271051        }
    1128     }
    1129 
     1052        mr_free(command);
     1053    }
    11301054
    11311055    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    11321056}
    1133 
    1134 
    1135 
    11361057
    11371058
     
    11561077    char nfs_client_defgw[MAX_STR_LEN];
    11571078    char nfs_server_ipaddr[MAX_STR_LEN];
    1158     char tmp[MAX_STR_LEN];
    1159     char command[MAX_STR_LEN * 2];
     1079    char *tmp = NULL;
     1080    char *command = NULL;
    11601081
    11611082    FILE *fd1 = NULL;
     
    11651086
    11661087    log_it("Storing NFS configuration");
    1167     strcpy(tmp, bkpinfo->nfs_mount);
     1088    mr_asprintf(&tmp, bkpinfo->nfs_mount);
    11681089    p = strchr(tmp, ':');
    11691090    if (!p) {
     
    11731094    *(p++) = '\0';
    11741095    strcpy(nfs_server_ipaddr, tmp);
     1096    mr_free(tmp);
     1097
    11751098    strcpy(nfs_mount, p);
    11761099    /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
    1177     sprintf(command,
     1100    mr_asprintf(&command,
    11781101            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    11791102    strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
    1180     sprintf(command,
     1103    mr_free(command);
     1104
     1105    mr_asprintf(&command,
    11811106            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    11821107    strcpy(nfs_client_ipaddr,
    11831108           call_program_and_get_last_line_of_output(command));
    1184     sprintf(command,
     1109    mr_free(command);
     1110
     1111    mr_asprintf(&command,
    11851112            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    11861113    strcpy(nfs_client_netmask,
    11871114           call_program_and_get_last_line_of_output(command));
    1188     sprintf(command,
     1115    mr_free(command);
     1116
     1117    mr_asprintf(&command,
    11891118            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    11901119    strcpy(nfs_client_broadcast,
    11911120           call_program_and_get_last_line_of_output(command));
    1192     sprintf(command,
     1121    mr_free(command);
     1122
     1123    mr_asprintf(&command,
    11931124            "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    11941125    strcpy(nfs_client_defgw,
    11951126           call_program_and_get_last_line_of_output(command));
    1196     sprintf(tmp,
    1197             "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s",
    1198             nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount);
     1127    mr_free(command);
     1128
     1129    mr_asprintf(&tmp,
     1130            "nfs_client_ipaddr=%s; nfs_client_netmask=%s; nfs_server_ipaddr=%s; nfs_mount=%s; nfs_client_defgw=%s;  ",
     1131            nfs_client_ipaddr, nfs_client_netmask, nfs_server_ipaddr, nfs_mount, nfs_client_defgw);
     1132    log_it(tmp);
     1133    mr_free(tmp);
     1134
    11991135    if (strlen(nfs_dev) < 2) {
    12001136        fatal_error
     
    12121148    if (!strncmp(nfs_dev, "bond", 4)) {
    12131149        log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev);
    1214         sprintf(command,
     1150        mr_asprintf(&command,
    12151151                "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);
    12161152        strcpy(mac_addr, call_program_and_get_last_line_of_output(command));
    1217         sprintf(command,
     1153        mr_free(command);
     1154
     1155        mr_asprintf(&command,
    12181156                "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);
    12191157        strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
     1158        mr_free(command);
     1159
    12201160        log_to_screen("Replacing it with %s\n", nfs_dev);
    12211161    }
    12221162
    12231163    fd1 = mr_fopen(MONDORESTORECFG, "a");
    1224 
    12251164    mr_fprintf(fd1, "nfs-dev %s\n", nfs_dev);
    12261165    mr_fprintf(fd1, "nfs-client-ipaddr %s\n", nfs_client_ipaddr);
     
    12361175    log_it("Finished storing NFS configuration");
    12371176}
    1238 
    1239 
    1240 
    1241 
    12421177
    12431178
     
    12621197{
    12631198    /*@ buffers *************** */
    1264     char tmp[MAX_STR_LEN];
     1199    char *tmp = NULL;
    12651200
    12661201    /*@ long long ************* */
     
    12891224    }
    12901225    if (scratchLL <= 1) {
    1291         sprintf(tmp,
    1292                 "Your backup will probably occupy a single %s. Maybe two.",
    1293                 media_descriptor_string(bkpinfo->backup_media_type));
    1294     } else if (scratchLL > 4) {
    1295         sprintf(tmp,
    1296                 "Your backup will occupy one meeeeellion media! (maybe %s)",
    1297                 number_to_text((int) (scratchLL + 1)));
     1226        mr_asprintf(&tmp,
     1227                _("Your backup will probably occupy a single %s. Maybe two."),
     1228                bkpinfo->backup_media_string);
    12981229    } else {
    1299         sprintf(tmp, "Your backup will occupy approximately %s media.",
     1230        mr_asprintf(&tmp, _("Your backup will occupy approximately %s media."),
    13001231                number_to_text((int) (scratchLL + 1)));
    13011232    }
     
    13031234        log_to_screen(tmp);
    13041235    }
    1305 }
    1306 
    1307 
    1308 /**
    1309  * Get the last suffix of @p instr.
    1310  * If @p instr was "httpd.log.gz", we would return "gz".
    1311  * @param instr The filename to get the suffix of.
    1312  * @return The suffix (without a dot), or "" if none.
    1313  * @note The returned string points to static storage that will be overwritten with each call.
    1314  */
    1315 char *sz_last_suffix(char *instr)
    1316 {
    1317     static char outstr[MAX_STR_LEN];
    1318     char *p;
    1319 
    1320     p = strrchr(instr, '.');
    1321     if (!p) {
    1322         outstr[0] = '\0';
    1323     } else {
    1324         strcpy(outstr, p);
    1325     }
    1326     return (outstr);
     1236    mr_free(tmp);
     1237    return;
    13271238}
    13281239
     
    13361247bool is_this_file_compressed(char *filename)
    13371248{
    1338     char do_not_compress_these[MAX_STR_LEN];
    1339     char tmp[MAX_STR_LEN];
    1340     char *p;
    1341 
    1342     sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1249    char *do_not_compress_these = NULL;
     1250    char *tmp = NULL;
     1251    char *p = NULL;
     1252
     1253    malloc_string(do_not_compress_these);
     1254    mr_asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    13431255    if (!does_file_exist(tmp)) {
     1256        mr_free(tmp);
    13441257        return (FALSE);
    13451258    }
    1346     strcpy(do_not_compress_these, last_line_of_file(tmp));
     1259    mr_free(tmp);
     1260
     1261    strcpy(do_not_compress_these,last_line_of_file(tmp));
    13471262    for (p = do_not_compress_these; p != NULL; p++) {
    1348         strcpy(tmp, p);
     1263        mr_asprintf(&tmp, p);
    13491264        if (strchr(tmp, ' ')) {
    13501265            *(strchr(tmp, ' ')) = '\0';
    13511266        }
    1352         if (!strcmp(sz_last_suffix(filename), tmp)) {   /*printf("MATCH\n"); */
     1267        if (!strcmp(sz_last_suffix(filename), tmp)) {
     1268            mr_free(do_not_compress_these);
     1269            mr_free(tmp);
    13531270            return (TRUE);
    13541271        }
     1272        mr_free(tmp);
     1273
    13551274        if (!(p = strchr(p, ' '))) {
    13561275            break;
    13571276        }
    13581277    }
     1278    mr_free(do_not_compress_these);
    13591279    return (FALSE);
    13601280}
    1361 
    13621281
    13631282
     
    13751294
    13761295
    1377 
    1378 
    13791296/**
    13801297 * Create a small script that mounts /boot, calls @c grub-install, and syncs the disks.
     
    13841301int make_grub_install_scriptlet(char *outfile)
    13851302{
    1386     FILE *fout;
    1387     char *tmp;
     1303    FILE *fout = NULL;
     1304    char *tmp = NULL;
    13881305    int retval = 0;
    13891306
    1390     malloc_string(tmp);
    13911307    if ((fout = fopen(outfile, "w"))) {
    13921308        fprintf(fout,
     
    13941310        paranoid_fclose(fout);
    13951311        mr_msg(2, "Created %s", outfile);
    1396         sprintf(tmp, "chmod +x %s", outfile);
     1312        mr_asprintf(&tmp, "chmod +x %s", outfile);
    13971313        paranoid_system(tmp);
     1314        mr_free(tmp);
     1315
    13981316        retval = 0;
    13991317    } else {
    14001318        retval = 1;
    14011319    }
    1402     mr_free(tmp);
    14031320    return (retval);
    14041321}
  • branches/stable/mondo/src/common/libmondo-files.h

    r684 r1113  
    99unsigned int updcrcr(unsigned int crc, unsigned int c);
    1010char *calc_checksum_of_file(char *filename);
    11 char *calc_file_ugly_minichecksum(char *curr_fname);
    12 char *calc_file_ugly_minichecksum(char *curr_fname);
    1311long count_lines_in_file(char *filename);
    1412bool does_file_exist(char *filename);
     
    2018char *last_line_of_file(char *filename);
    2119off_t length_of_file(char *filename);
    22 int make_checksum_list_file(char *filelist, char *cksumlist,
    23                             char *comppath);
    2420int make_hole_for_file(char *outfile_fname);
    2521void make_list_of_files_to_ignore(char *ignorefiles_fname,
  • branches/stable/mondo/src/common/libmondo-fork.c

    r1107 r1113  
    1 /* libmondo-fork.c
    2    $Id$
    3 */
    4 
    5 
     1/* libmondo-fork.c - subroutines for handling forking/pthreads/etc.
     2 * $Id$
     3 */
    64#include "my-stuff.h"
    75#include "mr_mem.h"
     
    97#include "libmondo-fork.h"
    108#include "libmondo-string-EXT.h"
    11 #include "libmondo-gui-EXT.h"
     9#include "newt-specific-EXT.h"
    1210#include "libmondo-files-EXT.h"
    1311#include "libmondo-tools-EXT.h"
    14 #include "lib-common-externs.h"
     12#include "mr_mem.h"
    1513
    1614/*@unused@*/
     
    9694
    9795    /*@ buffers      *** */
    98     char *midway_call, *ultimate_call, *tmp, *command, *incoming,
    99         *old_stderr, *cd_number_str;
    100     char *p;
     96    char *midway_call, *ultimate_call, *tmp;
     97    char *p = NULL;
     98    char *cd_number_str = NULL;
     99    char *command = NULL;
     100   
    101101
    102102/*@***********   End Variables ***************************************/
     
    107107    assert_string_is_neither_NULL_nor_zerolength(isofile);
    108108    assert_string_is_neither_NULL_nor_zerolength(logstub);
     109
    109110    midway_call = mr_malloc(1200);
    110111    ultimate_call = mr_malloc(1200);
    111112    tmp = mr_malloc(1200);
    112     command = mr_malloc(1200);
    113     malloc_string(incoming);
    114     malloc_string(old_stderr);
    115     malloc_string(cd_number_str);
    116 
    117     incoming[0] = '\0';
    118     old_stderr[0] = '\0';
    119 
    120     sprintf(cd_number_str, "%d", cd_no);
     113
     114    mr_asprintf(&cd_number_str, "%d", cd_no);
    121115    resolve_naff_tokens(midway_call, basic_call, isofile, "_ISO_");
    122116    resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
     117    mr_free(cd_number_str);
     118
    123119    resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
    124120    mr_msg(4, "basic call = '%s'", basic_call);
     
    126122    mr_msg(4, "tmp = '%s'", tmp);
    127123    mr_msg(4, "ultimate call = '%s'", ultimate_call);
    128     sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
     124    mr_asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
    129125
    130126    log_to_screen
    131         ("Please be patient. Do not be alarmed by on-screen inactivity.");
     127        (_("Please be patient. Do not be alarmed by on-screen inactivity."));
    132128    mr_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
    133129            what_i_am_doing);
    134     strcpy(tmp, command);
    135130    if (bkpinfo->manual_cd_tray) {
    136         p = strstr(tmp, "2>>");
     131        /* Find everything after a 2>> and remove it */
     132        p = strstr(command, "2>>");
    137133        if (p) {
    138             sprintf(p, "   ");
    139             while (*p == ' ') {
    140                 p++;
    141             }
    142             for (; *p != ' '; p++) {
     134            for (; *p != ' ' && *p != '\0'; p++) {
    143135                *p = ' ';
    144136            }
    145137        }
    146         strcpy(command, tmp);
    147138#ifndef _XWIN
    148139        if (!g_text_mode) {
     
    157148        if (retval) {
    158149            mr_msg(2, "Basic call '%s' returned an error.", basic_call);
    159             popup_and_OK("Press ENTER to continue.");
     150            popup_and_OK(_("Press ENTER to continue."));
    160151            popup_and_OK
    161                 ("mkisofs and/or cdrecord returned an error. CD was not created");
     152                (_("mkisofs and/or cdrecord returned an error. CD was not created"));
    162153        }
    163154    }
     
    170161            (what_i_am_doing, command);
    171162    }
     163    mr_free(command);
    172164
    173165    mr_free(midway_call);
    174166    mr_free(ultimate_call);
    175167    mr_free(tmp);
    176     mr_free(command);
    177     mr_free(incoming);
    178     mr_free(old_stderr);
    179     mr_free(cd_number_str);
    180 /*
    181   if (bkpinfo->backup_media_type == dvd && !bkpinfo->please_dont_eject_when_restoring)
    182     {
    183       mr_msg(3, "Ejecting DVD device");
    184       eject_device(bkpinfo->media_device);
    185     }
    186 */
    187168    return (retval);
    188169}
    189 
    190 
    191170
    192171
     
    200179{
    201180    /*@ buffer ****************************************************** */
    202     char callstr[MAX_STR_LEN * 2];
    203     char incoming[MAX_STR_LEN * 2];
    204     char tmp[MAX_STR_LEN * 2];
    205     char initial_label[MAX_STR_LEN * 2];
     181    char *callstr = NULL;
     182    char *incoming = NULL;
    206183
    207184    /*@ int ********************************************************* */
    208     int res;
     185    int res = 0;
     186    size_t n = 0;
    209187    int i;
    210188    int len;
     
    223201        return (1);
    224202    }
    225 //  if (debug_level == TRUE) { debug_level=5; }
    226 
    227     //  assert_string_is_neither_NULL_nor_zerolength(program);
    228203
    229204    if (debug_level <= g_loglevel) {
     
    231206        log_if_failure = TRUE;
    232207    }
    233     sprintf(callstr,
     208    mr_asprintf(&callstr,
    234209            "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err",
    235210            program);
     
    260235                "--------------------------------start of output-----------------------------");
    261236    }
     237    mr_free(callstr);
     238
    262239    if (log_if_failure
    263240        &&
     
    270247    fin = fopen("/tmp/mondo-run-prog-thing.tmp", "r");
    271248    if (fin) {
    272         for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    273              fgets(incoming, MAX_STR_LEN, fin)) {
     249        for (mr_getline(&incoming, &n, fin); !feof(fin);
     250             mr_getline(&incoming, &n, fin)) {
    274251            /* patch by Heiko Schlittermann */
    275252            p = incoming;
     
    287264            }
    288265        }
     266        mr_free(incoming);
    289267        paranoid_fclose(fin);
    290268    }
     
    303281    return (res);
    304282}
    305 
    306283
    307284
     
    325302
    326303    /*@ buffers **************************************************** */
    327     char tmp[MAX_STR_LEN * 2];
    328     char command[MAX_STR_LEN * 2];
    329     char lockfile[MAX_STR_LEN];
     304    char *tmp = NULL;
     305    char *command = NULL;
     306    char *lockfile = NULL;
    330307
    331308    /*@ end vars *************************************************** */
     
    333310    assert_string_is_neither_NULL_nor_zerolength(basic_call);
    334311
    335     sprintf(lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
     312    mr_asprintf(&lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
    336313    mkstemp(lockfile);
    337     sprintf(command,
     314    mr_asprintf(&command,
    338315            "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
    339316            lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
    340317    open_evalcall_form(what_i_am_doing);
    341     sprintf(tmp, "Executing %s", basic_call);
     318    mr_asprintf(&tmp, "Executing %s", basic_call);
    342319    mr_msg(2, tmp);
     320    mr_free(tmp);
     321
    343322    if (!(fin = popen(command, "r"))) {
    344323        log_OS_error("Unable to popen-in command");
    345         sprintf(tmp, "Failed utterly to call '%s'", command);
     324        mr_asprintf(&tmp, _("Failed utterly to call '%s'"), command);
    346325        log_to_screen(tmp);
     326        mr_free(tmp);
     327        mr_free(lockfile);
     328        mr_free(command);
    347329        return (1);
    348330    }
     331    mr_free(command);
     332
    349333    if (!does_file_exist(lockfile)) {
    350         log_to_screen("Waiting for external binary to start");
     334        log_to_screen(_("Waiting for external binary to start"));
    351335        for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
    352336            mr_msg(3, "Waiting for lockfile %s to exist", lockfile);
     
    375359    res = pclose(fin);
    376360    /* Log actual pclose errors. */
    377     if (errno) mr_msg(5, "pclose err: %d", errno);
     361    if (errno) {
     362        mr_msg(5, "pclose err: %d", errno);
     363    }
    378364    /* Check if we have a valid status. If we do, extract the called program's exit code. */
    379365    /* If we don't, highlight this fact by returning -1. */
     
    385371    close_evalcall_form();
    386372    unlink(lockfile);
     373    mr_free(lockfile);
     374
    387375    return (retval);
    388376}
    389377
    390378
    391 
    392 
    393379/**
    394  * Apparently unused. @bug This has a purpose, but what?
     380 * Apparently used. @bug This has a purpose, but what?
    395381 */
    396382#define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8"
     
    404390// if dir=='w' then copy from orig to archived
    405391// if dir=='r' then copy from archived to orig
    406     char *tmp;
    407     char *buf;
     392    char *tmp = NULL;
     393    char *buf = NULL;
    408394    long int bytes_to_be_read, bytes_read_in, bytes_written_out =
    409395        0, bufcap, subsliceno = 0;
    410396    int retval = 0;
    411     FILE *fin;
    412     FILE *fout;
    413     FILE *ftmp;
     397    FILE *fin = NULL;
     398    FILE *fout = NULL;
     399    FILE *ftmp = NULL;
    414400
    415401    mr_msg(5, "Opening.");
     
    526512}
    527513
    528 
    529 
    530 
    531514/**
    532515 * Feed @p input_device through ntfsclone to @p output_fname.
     
    539522// BACKUP
    540523    int res = -1;
    541     char*command;
     524    char *command = NULL;
    542525
    543526    if (!does_file_exist(input_device)) {
     
    547530        fatal_error("ntfsclone not found");
    548531    }
    549     malloc_string(command);
    550     sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
     532    mr_asprintf(&command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
    551533    res = run_program_and_log_output(command, 5);
    552534    mr_free(command);
     535
    553536    unlink(output_fname);
    554537    return (res);
     
    556539
    557540
    558 
    559 
    560 
    561541int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd)
    562542{
    563543
    564     /*@ int *************************************************************** */
    565544    int res = 0;
    566545    int percentage = 0;
     
    569548    int last_pcno = 0;
    570549
    571     /*@ buffers *********************************************************** */
    572     char *command;
     550    char *command = NULL;
    573551    char *tempfile;
    574552    char *title;
     
    577555
    578556    malloc_string(title);
    579     malloc_string(command);
    580557    malloc_string(tempfile);
    581558    assert_string_is_neither_NULL_nor_zerolength(cmd);
     
    586563           call_program_and_get_last_line_of_output
    587564           ("mktemp -q /tmp/mondo.XXXXXXXX"));
    588     sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     565    mr_asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    589566            tempfile);
    590567    mr_msg(3, command);
     
    592569    if (!(pin = popen(command, "r"))) {
    593570        log_OS_error("fmt err");
     571        mr_free(command);
    594572        return (1);
    595573    }
     574    mr_free(command);
     575
    596576    maxpc = 100;
    597577// OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD
     
    618598    }
    619599    unlink(tempfile);
    620     mr_free(command);
    621600    mr_free(tempfile);
    622601    mr_free(title);
    623602    return (res);
    624603}
    625 
    626 
    627604
    628605
     
    643620    pthread_exit((void *) (&res));
    644621}
    645 
    646 
    647622
    648623
     
    659634
    660635    /*@ buffers *********************************************************** */
    661     char *command;
     636    char *command = NULL;
    662637    char *title;
    663638    /*@ pointers ********************************************************** */
     
    672647
    673648    malloc_string(title);
    674     malloc_string(command);
    675649    strcpy(title, tt);
    676     sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
     650    mr_asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE);
    677651    mr_msg(3, "command = '%s'", command);
    678652    if ((res =
     
    703677        update_evalcall_form(percentage);
    704678    }
     679    mr_free(command);
     680
    705681    log_file_end_to_screen(MONDO_LOGFILE, "");
    706682    close_evalcall_form();
     
    712688    }
    713689    mr_msg(3, "Parent res = %d", res);
    714     mr_free(command);
    715690    mr_free(title);
    716691    return (res);
    717692}
    718 
    719 
    720693
    721694
     
    730703// RESTORE
    731704    int res = -1;
    732     char *command;
     705    char *command = NULL;
    733706
    734707    if ( !find_home_of_exe("ntfsclone")) {
    735708        fatal_error("ntfsclone not found");
    736709    }
    737     malloc_string(command);
    738     sprintf(command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo);
     710    mr_asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo);
    739711    res = run_program_and_log_output(command, 5);
    740712    mr_free(command);
  • branches/stable/mondo/src/common/libmondo.h

    r541 r1113  
    99#include "libmondo-files-EXT.h"
    1010#include "libmondo-fork-EXT.h"
    11 #include "libmondo-gui-EXT.h"
     11#include "newt-specific-EXT.h"
    1212#include "libmondo-mountlist-EXT.h"
    1313#include "libmondo-raid-EXT.h"
  • branches/stable/mondo/src/common/mondostructures.h

    r1063 r1113  
    11/***************************************************************************
    2                           mondostructures.h  -  description
    3                              -------------------
    4     begin                : Fri Apr 19 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    10 /***************************************************************************
    11  *                                                                         *
    12  *   This program is free software; you can redistribute it and/or modify  *
    13  *   it under the terms of the GNU General Public License as published by  *
    14  *   the Free Software Foundation; either version 2 of the License, or     *
    15  *   (at your option) any later version.                                   *
    16  *                                                                         *
    17  ***************************************************************************/
    18 
    19 
    20 /**
     2 * $Id$
     3 *
    214 * @file
    225 * The header file defining all of Mondo's structures.
     
    247
    258
    26 /** @def MAX_NOOF_MEDIA The maximum number of media that can be used in any one backup. */
    27 
    28 ///* So we can override it in config.h: */
     9/* @def MAX_NOOF_MEDIA The maximum number of media that can be used in any one backup. */
     10
     11/* So we can override it in config.h: */
    2912//#ifndef MAX_NOOF_MEDIA
    3013#define MAX_NOOF_MEDIA 50
     
    489472    t_bkptype backup_media_type;
    490473//  bool blank_dvd_first;
     474
     475  /**
     476   * The string corresponding to the media type
     477   */
     478    char backup_media_string[64];
    491479
    492480  /**
Note: See TracChangeset for help on using the changeset viewer.