Changeset 2357 in MondoRescue


Ignore:
Timestamp:
Aug 29, 2009, 3:22:10 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Some more fgets => mr_getline transformations
  • XWIN define is gone
Location:
branches/2.2.10
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-archive.c

    r2351 r2357  
    227227        log_msg(5, "command='%s'", command);
    228228        res = system(command);
    229         mr_asprintf(tmp, "%s", last_line_of_file(MONDO_LOGFILE));
     229        tmp = last_line_of_file(MONDO_LOGFILE);
    230230        log_msg(1, "res=%d; tmp='%s'", res, tmp);
    231231        if (bkpinfo->use_star && (res == 254 || res == 65024)
     
    558558
    559559    mr_asprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
    560     mr_asprintf(last_filelist_number, "%s", last_line_of_file(tmp));
     560    last_filelist_number = last_line_of_file(tmp);
    561561    mr_free(tmp);
    562562
     
    20342034            res = slice_up_file_etc(bigfile_fname, ntfsprog_fifo, biggie_file_number, noof_biggie_files, use_ntfsprog);
    20352035            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    2036                 write_header_block_to_stream((off_t)0, calc_checksum_of_file(bigfile_fname), BLK_STOP_A_BIGGIE);
     2036                tmp = calc_checksum_of_file(bigfile_fname);
     2037                write_header_block_to_stream((off_t)0, tmp, BLK_STOP_A_BIGGIE);
     2038                mr_free(tmp);
    20372039            }
    20382040            retval += res;
     
    20492051        }
    20502052        mr_free(bigfile_fname);
    2051 #ifndef _XWIN
    20522053        if (!g_text_mode) {
    20532054            newtDrawRootText(0, g_noof_rows - 2, tmp);
    20542055            newtRefresh();
    20552056        }
    2056 #endif
    20572057        mr_free(tmp);
    20582058    }
     
    26542654            mr_free(mds);
    26552655
    2656             cd_number = atoi(last_line_of_file(szcdno));
     2656            tmp = last_line_of_file(szcdno);
     2657            cd_number = atoi(tmp);
     2658            mr_free(tmp);
     2659
    26572660            mr_asprintf(tmp, "cat %s 2> /dev/null", szserfname);
    26582661            mr_free(our_serial_str);
     
    29822985                mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK          ", biggie_filename, biggie_file_number + 1, slice_num);
    29832986            }
    2984 #ifndef _XWIN
    29852987            if (!g_text_mode) {
    29862988                newtDrawRootText(0, g_noof_rows - 2, tmp);
     
    29892991                log_msg(2, tmp);
    29902992            }
    2991 #else
    2992             log_msg(2, tmp);
    2993 #endif
    29942993            mr_free(tmp);
    29952994
     
    31113110    log_msg(2, tmp);
    31123111    center_string(tmp, 80);
    3113 #ifndef _XWIN
    31143112    if (!g_text_mode) {
    31153113        newtPushHelpLine(tmp);
    31163114    }
    3117 #endif
    31183115    res = write_iso_and_go_on(TRUE);
    3119 #ifndef _XWIN
    31203116    if (!g_text_mode) {
    31213117        newtPopHelpLine();
    31223118    }
    3123 #endif
    31243119    log_msg(2, "Returning from writing final ISO (res=%d)", res);
    31253120    paranoid_free(tmp);
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2351 r2357  
    21852185        mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    21862186        mr_asprintf(mountdev, "%s%s", call_program_and_get_last_line_of_output(tmp), "/archives/THIS-CD-NUMBER");
    2187         cd_number = atoi(last_line_of_file(mountdev));
     2187        mr_free(tmp);
     2188
     2189        tmp = last_line_of_file(mountdev);
     2190        cd_number = atoi(tmp);
     2191        mr_free(tmp);
    21882192        mr_free(mountdev);
    2189         mr_free(tmp);
    2190 
    21912193        return (cd_number);
    21922194    }
     
    22102212    mr_free(mountdev);
    22112213
    2212     cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
     2214    tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER");
     2215    cd_number = atoi(tmp);
     2216    mr_free(tmp);
    22132217    return (cd_number);
    22142218}
  • branches/2.2.10/mondo/src/common/libmondo-filelist.c

    r2351 r2357  
    346346       then update_progress_form() won't show the "time taken / time remaining"
    347347       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    348 #ifndef _XWIN
    349348    if (!g_text_mode) {
    350349        open_progress_form("", "", "", "", 100);
     
    353352        newtPopWindow();
    354353    }
    355 #endif
    356354    return (err ? 0 : curr_set_no + 1);
    357355}
     
    471469        tmp = mr_stresc(file_to_analyze, "`$\\\"(){}[]'*?&|!#~", '\\');
    472470        mr_asprintf(strtmp, syscall_sprintf, tmp);
    473         paranoid_free(tmp);
     471        mr_free(tmp);
     472
    474473        mr_asprintf(syscall, "%s 2>> /dev/null", strtmp);   // " MONDO_LOGFILE);
    475474        mr_free(strtmp);
     475
    476476        call_exe_and_pipe_output_to_fd(syscall, pout);
    477477        mr_free(syscall);
     
    927927        }
    928928        add_string_at_node(filelist, fname);
    929         mr_free(fname);
    930929
    931930        if (!(++lino % 1111)) {
     
    933932            update_evalcall_form(percentage);
    934933        }
     934        mr_free(fname);
    935935    }
    936936    mr_free(fname);
     
    14141414            if (this_time != last_time) {
    14151415                last_time = this_time;
    1416 #ifndef _XWIN
    14171416                if (!g_text_mode) {
    14181417                    mr_asprintf(tmp, "Reading %-68s", dir);
     
    14201419                    mr_free(tmp);
    14211420                }
    1422 #endif
    14231421                update_evalcall_form(percentage);
    14241422            }
     
    14681466                                counter = 0;
    14691467                                uberctr++;
    1470 #ifndef _XWIN
    14711468                                mr_asprintf(tmp, " %c ", special_dot_char(uberctr));
    14721469                                if (!g_text_mode) {
     
    14751472                                }
    14761473                                mr_free(tmp);
    1477 #endif
    14781474                            }
    14791475                        }
  • branches/2.2.10/mondo/src/common/libmondo-files.c

    r2341 r2357  
    4646{
    4747    /*@ buffers ***************************************************** */
    48     static char output[MAX_STR_LEN];
     48    char *output = NULL;
    4949    char *command = NULL;
    5050
    5151    /*@ pointers **************************************************** */
    52     char *p;
     52    char *p = NULL;
    5353    FILE *fin;
    54 
    55     /*@ initialize pointers ***************************************** */
    56 
    57     p = output;
    5854
    5955    /*@************************************************************** */
     
    6460        fin = popen(command, "r");
    6561        if (fin) {
    66             (void) fgets(output, MAX_STR_LEN, fin);
     62            mr_getline(output, fin);
    6763            p = strchr(output, ' ');
     64            if (p != NULL) {
     65                *p = '\0';
     66            } else {
     67                mr_free(output);
     68                mr_asprintf(output, "");
     69            }
    6870            paranoid_pclose(fin);
    6971        }
     
    7173    } else {
    7274        log_it("File '%s' not found; cannot calc checksum", filename);
    73     }
    74     if (p) {
    75         *p = '\0';
     75        mr_asprintf(output, "");
    7676    }
    7777    return (output);
     
    125125    /*@ buffers ***************************************************** */
    126126    char *command = NULL;
    127     char incoming[MAX_STR_LEN];
     127    char *incoming = NULL;
    128128
    129129    /*@ long ******************************************************** */
     
    132132    /*@ pointers **************************************************** */
    133133    FILE *fin;
    134 
    135     /*@ initialize [0] to null ******************************************** */
    136     incoming[0] = '\0';
    137134
    138135    assert_string_is_neither_NULL_nor_zerolength(filename);
     
    152149            noof_lines = 0;
    153150        } else {
    154             (void) fgets(incoming, MAX_STR_LEN - 1, fin);
    155             while (strlen(incoming) > 0
    156                    && incoming[strlen(incoming) - 1] < 32) {
     151            mr_getline(incoming, fin);
     152            while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) {
    157153                incoming[strlen(incoming) - 1] = '\0';
    158154            }
    159155            noof_lines = atol(incoming);
     156            mr_free(incoming);
    160157        }
    161158        paranoid_pclose(fin);
     
    206203    char *outfname = NULL;
    207204    char *tmp = NULL;
    208     char incoming[MAX_STR_LEN];
     205    char *incoming = NULL;
    209206
    210207    /*@ int ********************************************************* */
     
    236233    mr_free(outfname);
    237234
    238     for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    239          fgets(incoming, MAX_STR_LEN, fin)) {
     235    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    240236        i = strlen(incoming) - 1;
    241237        if (i >= 0 && incoming[i] < 32) {
     
    247243            log_it("Excluding '%s'-nonexistent\n", incoming);
    248244        }
    249     }
     245        mr_free(incoming);
     246    }
     247    mr_free(incoming);
     248
    250249    paranoid_fclose(fout);
    251250    paranoid_fclose(fin);
     
    470469{
    471470    /*@ buffers ***************************************************** */
    472     static char output[MAX_STR_LEN];
     471    char *output = NULL;
    473472    char *command = NULL;
    474473
     
    480479    if (!does_file_exist(filename)) {
    481480        log_it("Tring to get last line of nonexistent file (%s)", filename);
    482         output[0] = '\0';
     481        mr_asprintf(output, "");
    483482        return (output);
    484483    }
     
    487486    mr_free(command);
    488487
    489     (void) fgets(output, MAX_STR_LEN, fin);
     488    mr_getline(output, fin);
    490489    paranoid_pclose(fin);
    491490    while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
     
    526525 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.
    527526 */
    528 int
    529 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
    530 {
     527int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) {
    531528    /*@ pointers **************************************************** */
    532529    FILE *fin;
     
    539536
    540537    /*@ buffer ****************************************************** */
    541     char stub_fname[1000];
    542     char curr_fname[1000];
     538    char *stub_fname = NULL;
     539    char *curr_fname = NULL;
    543540    char *curr_cksum = NULL;
    544541    char *tmp = NULL;
     
    571568        return (1);
    572569    }
    573     for (fgets(stub_fname, 999, fin); !feof(fin);
    574          fgets(stub_fname, 999, fin)) {
     570    for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) {
    575571        if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
    576572            stub_fname[i] = '\0';
    577573        }
    578574        mr_asprintf(tmp, "%s%s", comppath, stub_fname);
    579         strcpy(curr_fname, tmp + 1);
     575        mr_free(stub_fname);
     576
     577        mr_asprintf(curr_fname, "%s", tmp + 1);
    580578        mr_free(tmp);
    581579
     
    587585            current_time = get_time();
    588586            counter = 0;
     587            /* BERLIOS: 37 really ? */
    589588            curr_fname[37] = '\0';
    590589            curr_pos = ftello(fin) / 1024;
    591590            percentage = (int) (curr_pos * 100 / filelist_length);
    592591            time_taken = current_time - start_time;
    593             if (percentage == 0) {
    594                 /*              printf("%0d%% done      \r",percentage); */
    595             } else {
     592            if (percentage != 0) {
    596593                time_remaining = time_taken * 100 / (long) (percentage) - time_taken;
    597594                log_to_screen("%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);
     
    599596            sync();
    600597        }
    601     }
     598        mr_free(curr_fname);
     599    }
     600    mr_free(stub_fname);
     601
    602602    paranoid_fclose(fout);
    603603    paranoid_fclose(fin);
     
    678678
    679679    /*@ buffers **************************************************** */
    680     char incoming[MAX_STR_LEN];
     680    char *incoming = NULL;
    681681
    682682    /*@ end vars *************************************************** */
     
    689689        return (0);
    690690    }
    691     (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     691    mr_getline(incoming, fin);
    692692    while (!feof(fin)) {
    693693        if (strstr(incoming, wildcard)) {
    694694            matches++;
    695695        }
    696         (void) fgets(incoming, MAX_STR_LEN - 1, fin);
    697     }
     696        mr_free(incoming);
     697        mr_getline(incoming, fin);
     698    }
     699    mr_free(incoming);
    698700    paranoid_fclose(fin);
    699701    return (matches);
     
    737739{
    738740    /*@ buffers ***************************************************** */
    739     char *fname;
     741    char *fname = NULL;
    740742    char *biggielist = NULL;
    741743    char *tmp = NULL;
     
    751753    /*@ end vars *************************************************** */
    752754
    753     malloc_string(fname);
    754755    log_it("Calculating size of all biggiefiles (in total)");
    755756    mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     
    762763    } else {
    763764        log_msg(4, "Reading it...");
    764         for (fgets(fname, MAX_STR_LEN, fin); !feof(fin);
    765              fgets(fname, MAX_STR_LEN, fin)) {
     765        for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) {
    766766            if (fname[strlen(fname) - 1] <= 32) {
    767767                fname[strlen(fname) - 1] = '\0';
     
    772772                    if (!tmp) {
    773773                        mr_free(tmp);
     774                        mr_free(fname);
    774775                        fatal_error("ntfsresize not found");
    775776                    }
     
    799800                break;
    800801            }
    801         }
     802            mr_free(fname);
     803        }
     804        mr_free(fname);
    802805    }
    803806    log_it("Closing...");
    804807    paranoid_fclose(fin);
    805808    log_it("Finished calculating total size of all biggiefiles");
    806     paranoid_free(fname);
    807809    return (scratchL);
    808810}
     
    817819{
    818820    /*@ buffer ****************************************************** */
    819     char tmp[MAX_STR_LEN];
     821    char *tmp = NULL;
    820822    char *command = NULL;
    821823    long long llres;
     
    833835      llres = 0;
    834836    } else {
    835       (void) fgets(tmp, MAX_STR_LEN, fin);
     837      mr_getline(tmp, fin);
    836838      paranoid_pclose(fin);
    837839      p = strchr(tmp, '\t');
     
    843845        llres += (int) (*p - '0');
    844846      }
     847      mr_free(tmp);
    845848    }
    846849    mr_free(command);
     
    12891292    }
    12901293    /* BERLIOS: This is just plain WRONG !! */
    1291     mr_asprintf(do_not_compress_these, "%s", last_line_of_file(tmp));
     1294    do_not_compress_these = last_line_of_file(tmp);
    12921295    mr_free(tmp);
    12931296
  • branches/2.2.10/mondo/src/common/libmondo-fork.c

    r2339 r2357  
    3838    /*@ buffers ***************************************************** */
    3939    static char result[512];
    40     char *tmp;
     40    char *tmp = NULL;
    4141
    4242    /*@ pointers **************************************************** */
     
    4444
    4545    /*@ initialize data ********************************************* */
    46     malloc_string(tmp);
    4746    result[0] = '\0';
    48     tmp[0] = '\0';
    4947
    5048    /*@******************************************************************** */
     
    5250    assert_string_is_neither_NULL_nor_zerolength(call);
    5351    if ((fin = popen(call, "r"))) {
    54         for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    55              fgets(tmp, MAX_STR_LEN, fin)) {
     52        for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    5653            if (strlen(tmp) > 1) {
    57                 strcpy(result, tmp);
    58             }
    59         }
     54                strncpy(result, 511, tmp);
     55            }
     56            mr_free(tmp);
     57        }
     58        mr_free(tmp);
    6059        paranoid_pclose(fin);
    6160    } else {
     
    6362    }
    6463    strip_spaces(result);
    65     paranoid_free(tmp);
    6664    return (result);
    6765}
     
    163161        mr_free(command);
    164162        command = tmp2;
    165 #ifndef _XWIN
    166163        if (!g_text_mode) {
    167164            newtSuspend();
    168165        }
    169 #endif
    170166        log_msg(1, "command = '%s'", command);
    171167        retval += system(command);
     
    294290    fin = fopen(tmp1, "r");
    295291    if (fin) {
    296         for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    297              fgets(incoming, MAX_STR_LEN, fin)) {
     292        for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); fgets(incoming, MAX_STR_LEN, fin)) {
    298293            p = incoming;
    299294            while (p && *p) {
     
    304299            }
    305300            strip_spaces(incoming);
    306             if ((res == 0 && log_if_success)
    307                 || (res != 0 && log_if_failure)) {
     301            if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
    308302                log_msg(0, incoming);
    309303            }
     
    375369        }
    376370    }
    377 #ifdef _XWIN
    378     /* This only can update when newline goes into the file,
    379        but it's *much* prettier/faster on Qt. */
    380     while (does_file_exist(lockfile)) {
    381         while (!feof(fin)) {
    382             if (!fgets(tmp1, 512, fin))
    383                 break;
    384             log_to_screen(tmp1);
    385         }
    386         usleep(500000);
    387     }
    388 #else
    389     /* This works on Newt, and it gives quicker updates. */
     371
    390372    for (; does_file_exist(lockfile); sleep(1)) {
    391373        log_file_end_to_screen(MONDO_LOGFILE, "");
    392374        update_evalcall_form(1);
    393375    }
    394 #endif
     376
    395377    /* Evaluate the status returned by pclose to get the exit code of the called program. */
    396378    errno = 0;
  • branches/2.2.10/mondo/src/common/libmondo-gui-EXT.h

    r541 r2357  
    11/* libmondo-gui-EXT.h */
    22
    3 #ifdef _XWIN
    4 #include "X-specific-EXT.h"
    5 #else
    63#include "newt-specific-EXT.h"
    7 #endif
  • branches/2.2.10/mondo/src/common/libmondo-gui.c

    r541 r2357  
    99 */
    1010
    11 #ifdef _XWIN
    12 #include "X-specific.c"
    13 #else
    1411#include "newt-specific.c"
    15 #endif
  • branches/2.2.10/mondo/src/common/libmondo-gui.h

    r541 r2357  
    33 */
    44
    5 #ifdef _XWIN
    6 #include "X-specific.h"
    7 #else
    85#include "newt-specific.h"
    9 #endif
  • branches/2.2.10/mondo/src/common/libmondo-mountlist.c

    r2352 r2357  
    821821        return (1);
    822822    }
    823     malloc_string(incoming);
    824823    malloc_string(siz);
    825     (void) fgets(incoming, MAX_STR_LEN - 1, fin);
    826824    log_it("Loading mountlist...");
     825    mr_getline(incoming, fin);
    827826    while (!feof(fin)) {
    828827#if linux
    829         res = sscanf(incoming,
    830                "%s %s %s %s %s",
    831                mountlist->el[items].device,
    832                mountlist->el[items].mountpoint,
    833                mountlist->el[items].format,
    834                siz, mountlist->el[items].label);
     828        res = sscanf(incoming, "%s %s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz, mountlist->el[items].label);
    835829        if (res < 5) {
    836830            /* no label found */
     
    839833        }
    840834#elif __FreeBSD__
    841         res = sscanf(incoming,
    842                "%s %s %s %s",
    843                mountlist->el[items].device,
    844                mountlist->el[items].mountpoint,
    845                mountlist->el[items].format, siz);
     835        res = sscanf(incoming, "%s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz);
    846836        strcpy(mountlist->el[items].label,"");
    847837#endif
     
    854844            !strcmp(mountlist->el[items].device, "devpts")
    855845            ) {
    856             log_msg(1,
    857                     "Ignoring %s in mountlist - not loading that line :) ",
    858                     mountlist->el[items].device);
    859             (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     846            log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device);
     847            mr_free(incoming);
     848            mr_getline(incoming, fin);
    860849            continue;
    861850        }
     
    880869                    *(p + 2) = *(p + 3);
    881870                }
    882                 log_it("It was %s; it is now %s",
    883                        mountlist->el[items].device, tmp);
     871                log_it("It was %s; it is now %s", mountlist->el[items].device, tmp);
    884872                strcpy(mountlist->el[items].device, tmp);
    885873            }
    886874            paranoid_free(tmp);
    887875
    888             log_it("%s %s %s %lld %s",
    889                      mountlist->el[items].device,
    890                      mountlist->el[items].mountpoint,
    891                      mountlist->el[items].format,
    892                      mountlist->el[items].size,
    893                      mountlist->el[items].label);
     876            log_it("%s %s %s %lld %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, mountlist->el[items].size, mountlist->el[items].label);
    894877            items++;
    895878            if (items >= MAX_MOUNTLIST_ENTRIES) {
     
    898881            }
    899882        }
    900         (void) fgets(incoming, MAX_STR_LEN - 1, fin);
    901     }
     883        mr_free(incoming);
     884        mr_getline(incoming, fin);
     885    }
     886    mr_free(incoming);
    902887    paranoid_fclose(fin);
    903888    mountlist->entries = items;
     
    906891    log_it("%d entries in mountlist", items);
    907892
    908     paranoid_free(incoming);
    909893    paranoid_free(siz);
    910894    return (0);
  • branches/2.2.10/mondo/src/common/libmondo-raid.c

    r2334 r2357  
    427427int get_next_raidtab_line(FILE * fin, char *label, char *value)
    428428{
    429     char *incoming;
     429    char *incoming = NULL;
    430430    char *p;
    431431
    432     malloc_string(incoming);
    433432    assert(fin != NULL);
    434433    assert(label != NULL);
     
    437436    label[0] = value[0] = '\0';
    438437    if (feof(fin)) {
    439         paranoid_free(incoming);
    440438        return (1);
    441439    }
    442     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    443          fgets(incoming, MAX_STR_LEN - 1, fin)) {
    444         strip_spaces(incoming);
     440    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     441        mr_strip_spaces(incoming);
    445442        p = strchr(incoming, ' ');
    446443        if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
     444            mr_free(incoming);
    447445            continue;
    448446        }
     
    453451        strcpy(label, incoming);
    454452        strcpy(value, p);
    455         paranoid_free(incoming);
     453        mr_free(incoming);
    456454        return (0);
    457455    }
     456    mr_free(incoming);
    458457    return (1);
    459458}
     
    805804    static char *argv[64];
    806805    char **ap;
    807     char *line = (char *) malloc(MAX_STR_LEN);
    808     if (!line)
    809         errx(1,
    810              "unable to allocate %i bytes of memory for `char *line' at %s:%i",
    811              MAX_STR_LEN, __FILE__, __LINE__);
    812     (void) fgets(line, MAX_STR_LEN, f);
     806    char *line = NULL;
     807
     808    mr_getline(line, f);
    813809    if (feof(f)) {
    814810        log_it("[GNVCL] Uh... I reached the EOF.");
     
    822818            cnt++;
    823819        }
     820    mr_free(line);
    824821
    825822    if (strchr(argv[cnt - 1], '\n')) {
  • branches/2.2.10/mondo/src/common/libmondo-tools.c

    r2338 r2357  
    108108        return;
    109109    }
    110 #ifndef _XWIN
    111110    if (!g_text_mode)
    112111        newtSuspend();
    113 #endif
    114112    printf("ASSERTION FAILED: `%s'\n", exp);
    115113    printf("\tat %s:%d in %s\n\n", file, line, function);
     
    158156    getchar();                  // skip \n
    159157
    160 #ifndef _XWIN
    161158    if (!g_text_mode)
    162159        newtResume();
    163 #endif
    164160}
    165161
     
    344340        output[i - 1] = '\0';
    345341    }
    346     if (g_text_mode
    347         /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
     342    if (g_text_mode) {
    348343        printf("%s\n", output);
    349344    }
  • branches/2.2.10/mondo/src/common/libmondo-verify.c

    r2338 r2357  
    411411    char *command = NULL;
    412412    char *outlog = NULL;
    413     char *tmp;
    414     //  char *p;
     413    char *tmp = NULL;
    415414
    416415    /*@ pointers ******************************************************* */
     
    422421
    423422
    424     malloc_string(tmp);
    425423    assert(bkpinfo != NULL);
    426424    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
     
    499497        pin = popen(command, "r");
    500498        if (pin) {
    501             for (fgets(tmp, MAX_STR_LEN, pin); !feof(pin);
    502                  fgets(tmp, MAX_STR_LEN, pin)) {
     499            for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) {
    503500                if (bkpinfo->use_star) {
    504501                    if (!strstr(tmp, "diffopts=")) {
    505                         while (strlen(tmp) > 0
    506                                && tmp[strlen(tmp) - 1] < 32) {
     502                        while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) {
    507503                            tmp[strlen(tmp) - 1] = '\0';
    508504                        }
    509505                        if (strchr(tmp, '/')) {
    510506                            if (!diffs) {
    511                                 log_msg(0, "'%s' - differences found",
    512                                         tarball_fname);
     507                                log_msg(0, "'%s' - differences found", tarball_fname);
    513508                            }
    514                             log_msg(0, "star: /%s",
    515                                     strip_afio_output_line(tmp));
     509                            log_msg(0, "star: /%s", strip_afio_output_line(tmp));
    516510                            diffs++;
    517511                        }
     
    519513                } else {
    520514                    if (!diffs) {
    521                         log_msg(0, "'%s' - differences found",
    522                                 tarball_fname);
     515                        log_msg(0, "'%s' - differences found", tarball_fname);
    523516                    }
    524517                    log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
    525518                    diffs++;
    526519                }
     520                mr_free(tmp);
    527521            }
     522            mr_free(tmp);
    528523            paranoid_pclose(pin);
    529524        } else {
     
    533528    mr_free(command);
    534529    mr_free(outlog);
    535     paranoid_free(tmp);
    536530    return (0);
    537531}
     
    681675    mr_asprintf(biggie_cksum, "%s", slice_fnam);
    682676    if (biggie_cksum[0] != '\0') {
    683         mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname));
     677        orig_cksum = calc_checksum_of_file(biggie_fname);
    684678        if (strcmp(biggie_cksum, orig_cksum)) {
    685679            log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum);
     
    690684            mr_free(tmp);
    691685        }
     686        mr_free(orig_cksum);
    692687    }
    693688    mr_free(biggie_cksum);
    694689    mr_free(test_file);
    695     mr_free(orig_cksum);
    696690    paranoid_free(slice_fnam);
    697691    return (retval);
  • branches/2.2.10/mondo/src/common/newt-specific.c

    r2340 r2357  
    124124        /*@ buffers ********************************************************** */
    125125        int i;
     126        char *tmp;
    126127
    127128         assert_string_is_neither_NULL_nor_zerolength(prompt);
    128129
    129130        if (g_text_mode) {
    130 
    131             char *tmp;
    132             tmp = malloc(MAX_NEWT_COMMENT_LEN);
    133 
    134131            while (1) {
    135132                system("sync");
    136                 printf
    137                     ("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ",
    138                      prompt);
    139                 (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     133                printf("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", prompt);
     134                mr_getline(tmp, stdin);
    140135                if (tmp[strlen(tmp) - 1] == '\n')
    141136                    tmp[strlen(tmp) - 1] = '\0';
     
    146141                }
    147142                if (strstr("yesYES", tmp)) {
    148                     paranoid_free(tmp);
     143                    mr_free(tmp);
    149144                    return (TRUE);
    150145                } else if (strstr("NOno", tmp)) {
    151                     paranoid_free(tmp);
     146                    mr_free(tmp);
    152147                    return (FALSE);
    153148                } else {
    154149                    system("sync");
    155                     printf
    156                         ("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
     150                    printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
    157151                }
    158152            }
     
    172166
    173167        /*@ buffer *********************************************************** */
    174         char *tmp;
     168        char *tmp = NULL;
    175169        int i;
    176170
    177         tmp = malloc(MAX_NEWT_COMMENT_LEN);
    178171        assert_string_is_neither_NULL_nor_zerolength(prompt);
     172
    179173        if (g_text_mode) {
    180174            system("sync");
    181             printf
    182                 ("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ",
    183                  prompt);
    184             (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
     175            printf("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", prompt);
     176            mr_getline(tmp, stdin);
    185177            if (tmp[strlen(tmp) - 1] == '\n')
    186178                tmp[strlen(tmp) - 1] = '\0';
     
    191183            }
    192184            if (strstr("okOKOkYESyes", tmp)) {
    193                 paranoid_free(tmp);
     185                mr_free(tmp);
    194186                return (TRUE);
    195187            } else {
    196                 paranoid_free(tmp);
     188                mr_free(tmp);
    197189                return (FALSE);
    198190            }
    199191        } else {
    200             paranoid_free(tmp);
    201192            return (popup_with_buttons(prompt, " Okay ", "Cancel"));
    202193        }
     
    431422 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
    432423 */
    433     void
    434      log_file_end_to_screen(char *filename, char *grep_for_me) {
     424void log_file_end_to_screen(char *filename, char *grep_for_me) {
    435425
    436426        /*@ buffers ********************************************************** */
     
    462452                for (err_log_lines[i][0] = '\0';
    463453                     strlen(err_log_lines[i]) < 2 && !feof(fin);) {
    464                     (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
    465                                  fin);
     454                    (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN, fin);
    466455                    /* Commented to make valgrind happy and avoid crash
    467456                    strip_spaces(err_log_lines[i]);
     
    787776
    788777        /*@ buffers *********************************************************** */
    789         char *prompt;
     778        char *prompt = NULL;
    790779
    791780        /*@ newt ************************************************************** */
     
    799788        assert(button1 != NULL);
    800789        assert(button2 != NULL);
    801         prompt = malloc(MAX_NEWT_COMMENT_LEN);
    802790        if (g_text_mode) {
    803791            if (strlen(button2) == 0) {
     
    806794                printf("%s (%s or %s) --> ", p, button1, button2);
    807795            }
    808             for (prompt[0] = '\0';
    809                  strcmp(prompt, button1) && (strlen(button2) == 0
    810                                           || strcmp(prompt, button2));) {
     796            mr_getline(prompt, stdin);
     797            while (strcmp(prompt, button1) && (strlen(button2) == 0 || strcmp(prompt, button2))) {
    811798                printf("--> ");
    812                 (void) fgets(prompt, MAX_NEWT_COMMENT_LEN, stdin);
     799                mr_free(prompt);
     800                mr_getline(prompt, stdin);
    813801            }
    814802            if (!strcmp(prompt, button1)) {
    815                 paranoid_free(prompt);
     803                mr_free(prompt);
    816804                return (TRUE);
    817805            } else {
    818                 paranoid_free(prompt);
     806                mr_free(prompt);
    819807                return (FALSE);
    820808            }
    821809        }
    822810
     811        prompt = malloc(MAX_NEWT_COMMENT_LEN);
    823812        strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1);
    824813        prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0';
     
    11661155            { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
    11671156"nfs", "iso", NULL };
    1168         char *outstr;
     1157        char *outstr = NULL;
    11691158        t_bkptype backup_type;
    11701159        int i;
     
    11811170        newtComponent myForm;
    11821171
    1183         outstr = malloc(MAX_NEWT_COMMENT_LEN);
    11841172        if (g_text_mode) {
    11851173            for (backup_type = none; backup_type == none;) {
     
    11901178                }
    11911179                printf(")\n--> ");
    1192                 (void) fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
    1193                 strip_spaces(outstr);
     1180                mr_getline(outstr, stdin);
     1181                mr_strip_spaces(outstr);
    11941182                for (i = 0; possible_responses[i]; i++) {
    11951183                    if (!strcmp(possible_responses[i], outstr)) {
     
    11971185                    }
    11981186                }
    1199             }
    1200             paranoid_free(outstr);
     1187                mr_free(outstr);
     1188            }
    12011189            return (backup_type);
    12021190        }
     
    13191307        int j = 0;
    13201308        bool done;
    1321         char *tmp;
     1309        char *tmp = NULL;
    13221310        char *tmp1 = NULL;
    13231311        FILE *fin, *fout;
     
    13381326        if (!(fout = fopen(tmp1, "a"))) {
    13391327            log_msg(2, "Can't write to %s", tmp1);
     1328            mr_free(tmp1);
    13401329            return(1);
    13411330            }
    13421331
    1343         malloc_string(tmp);
    13441332        log_msg(2, "Loading %s", source_file);
    1345         for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
    1346              filelist->entries++) {
     1333        for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; filelist->entries++) {
    13471334          god_i_hate_gotos:
     1335            if (tmp != NULL) {
     1336                mr_free(tmp);
     1337            }
    13481338            if (feof(fin)) {
    13491339                break;
    13501340            }
    1351             (void) fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
     1341            mr_getline(tmp, fin);
    13521342            i = (int) strlen(tmp);
    13531343            if (i < 2) {
     
    13661356                goto god_i_hate_gotos;
    13671357            }
    1368             filelist->el[filelist->entries].severity =
    1369                 severity_of_difference(tmp, NULL);
     1358            filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL);
    13701359            strcpy(filelist->el[filelist->entries].filename, tmp);
    13711360            if (feof(fin)) {
     
    13731362            }
    13741363        }
     1364        mr_free(tmp);
    13751365        paranoid_fclose(fin);
    13761366        paranoid_fclose(fout);
     
    13781368            log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1);
    13791369        }
    1380         paranoid_free(tmp1);
     1370        mr_free(tmp1);
    13811371        if (filelist->entries >= ARBITRARY_MAXIMUM) {
    13821372            log_to_screen("Arbitrary limits suck, man!");
    1383             paranoid_free(tmp);
    13841373            return (1);
    13851374        }
     
    14091398            }
    14101399        }
    1411         paranoid_free(tmp);
    14121400        log_it("leaving");
    14131401        return (0);
  • branches/2.2.10/mondo/src/mondorestore/mondo-prep.c

    r2334 r2357  
    188188{
    189189    /**  buffers **********************************************/
    190     char *tmp;
     190    char *tmp = NULL;
    191191    char *tmp1 = NULL;
    192     char *incoming;
     192    char *incoming = NULL;
    193193    char *command;
    194194    char *lvscan_sz = NULL;
     
    225225    }
    226226
    227     malloc_string(tmp);
    228     malloc_string(incoming);
    229227    command = malloc(1024);
    230228
     
    271269    log_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff...");
    272270    rewind(fin);
    273     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) {
     271    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    274272        fgetpos(fin, &orig_pos);
    275273        if (incoming[0] != '#') {
     274            mr_free(incoming);
    276275            continue;
    277276        }
     
    284283        if ((p = strstr(incoming, "vgcreate"))) {
    285284            // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    286             for (fgets(tmp, MAX_STR_LEN - 1, fin); !feof(fin); fgets(tmp, MAX_STR_LEN - 1, fin)) {
     285            for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    287286                if (tmp[0] == '#') {
    288287                    fsetpos(fin, &orig_pos);
     
    290289                } else {
    291290                    fgetpos(fin, &orig_pos);
    292                     strcat(incoming, tmp);
     291                    mr_strcat(incoming, tmp);
    293292                }
    294             }
     293                mr_free(tmp);
     294            }
     295            mr_free(tmp);
     296
    295297            for (q = incoming; *q != '\0'; q++) {
    296298                if (*q < 32) {
     
    298300                }
    299301            }
    300             strcpy(tmp, p + strlen("vgcreate") + 1);
     302            mr_asprintf(tmp, "%s", p + strlen("vgcreate") + 1);
    301303            for (q = tmp; *q > 32; q++);
    302304            *q = '\0';
    303305            log_msg(1, "Deleting old entries at /dev/%s", tmp);
    304306            mr_asprintf(tmp1, "rm -Rf /dev/%s", tmp);
     307            mr_free(tmp);
     308
    305309            run_program_and_log_output(tmp1, 1);
    306310            mr_free(tmp1);
     
    308312            run_program_and_log_output(vgscan_sz, 1);
    309313            run_program_and_log_output(pvscan_sz, 1);
    310             log_msg(3,
    311                     "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'",
    312                     incoming);
     314            log_msg(3, "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", incoming);
    313315        }
    314316        for (p = incoming + 1; *p == ' '; p++);
     317        mr_free(incoming);
     318
    315319        strcpy(command, p);
    316320        for (p = command; *p != '\0'; p++);
     
    330334            if (strstr(command, "lvm lvcreate"))
    331335                lvmversion = 2;
    332             log_it("%s... so I'll get creative.", tmp);
    333336            if (lvmversion == 2) {
    334337                mr_asprintf(tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);
    335                 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
     338                mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(tmp1));
    336339                mr_free(tmp1);
    337340            } else {
    338341                mr_asprintf(tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);
    339                 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
     342                mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(tmp1));
    340343                mr_free(tmp1);
    341344            }
     
    343346            extents = atol(p);
    344347            log_msg(5, "p='%s' --> extents=%ld", p, extents);
     348            mr_free(tmp);
     349
    345350            p = strstr(command, "-L");
    346351            if (!p) {
     
    395400        sleep(1);
    396401    }
     402    mr_free(incoming);
    397403    mr_free(vgscan_sz);
    398404    mr_free(pvscan_sz);
     
    401407    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    402408    }
    403     paranoid_free(tmp);
    404     paranoid_free(incoming);
    405409    paranoid_free(command);
    406410    system("sync");
     
    440444
    441445    /** buffers **********************************************************/
    442     char *incoming;
     446    char *incoming = NULL;
    443447
    444448    /** pointers *********************************************************/
     
    450454    /** end **************************************************************/
    451455
    452     malloc_string(incoming);
    453456    assert(new_mountlist != NULL);
    454457    assert(old_mountlist != NULL);
    455458
    456459#ifdef __FreeBSD__
    457     log_to_screen
    458         ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
     460    log_to_screen("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
    459461    return (1);
    460462#endif
     
    472474                finish(1);
    473475            }
    474             for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    475                  && !strstr(incoming, old_mountlist->el[lino].device);
    476                  fgets(incoming, MAX_STR_LEN - 1, fin));
     476            mr_getline(incoming, fin);
     477            while (feof(fin) && !strstr(incoming, old_mountlist->el[lino].device)) {
     478                mr_free(incoming);
     479                mr_getline(incoming, fin);
     480            }
     481            mr_free(incoming);
     482           
    477483            if (!feof(fin)) {
    478484                log_it("Investigating %s", old_mountlist->el[lino].device);
    479485
    480                 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
    481                      && !strstr(incoming, "raiddev");
    482                      fgets(incoming, MAX_STR_LEN - 1, fin)) {
    483                     if (strstr(incoming, OSSWAP("device", "drive"))
    484                         && !strchr(incoming, '#')) {
    485                         for (p = incoming + strlen(incoming);
    486                              *(p - 1) <= 32; p--);
     486                for (mr_getline(incoming, fin); !feof(fin) && !strstr(incoming, "raiddev"); mr_getline(incoming, fin)) {
     487                    if (strstr(incoming, OSSWAP("device", "drive")) && !strchr(incoming, '#')) {
     488                        for (p = incoming + strlen(incoming); *(p - 1) <= 32; p--);
    487489                        *p = '\0';
    488490                        for (p--; p > incoming && *(p - 1) > 32; p--);
     491
    489492                        log_it("Extrapolating %s", p);
    490493
    491                         for (j = 0;
    492                              j < new_mountlist->entries
    493                              && strcmp(new_mountlist->el[j].device, p);
    494                              j++);
     494                        for (j = 0; j < new_mountlist->entries && strcmp(new_mountlist->el[j].device, p); j++);
    495495                        if (j >= new_mountlist->entries) {
    496                             strcpy(new_mountlist->
    497                                    el[new_mountlist->entries].device, p);
    498                             strcpy(new_mountlist->
    499                                    el[new_mountlist->entries].mountpoint,
    500                                    "raid");
    501                             strcpy(new_mountlist->
    502                                    el[new_mountlist->entries].format,
    503                                    "raid");
    504                             new_mountlist->el[new_mountlist->entries].
    505                                 size = old_mountlist->el[lino].size;
     496                            strcpy(new_mountlist->el[new_mountlist->entries].device, p);
     497                            strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, "raid");
     498                            strcpy(new_mountlist->el[new_mountlist->entries].format, "raid");
     499                            new_mountlist->el[new_mountlist->entries].size = old_mountlist->el[lino].size;
    506500                            new_mountlist->entries++;
    507501                        } else {
    508502                            log_it("Not adding %s to mountlist: it's already there", p);
    509503                        }
     504                        mr_free(incoming);
    510505                    }
    511506                }
     507                mr_free(incoming);
    512508            }
    513509            paranoid_fclose(fin);
     
    656652#ifdef __FreeBSD__
    657653    static bool vinum_started_yet = FALSE;
     654    char *line = NULL;
     655    char *status;
    658656#endif
    659657
     
    710708        if (vinum_started_yet) {
    711709            FILE *fin;
    712             char line[MAX_STR_LEN];
    713710
    714711            log_to_screen("Initializing Vinum device %s (this may take a *long* time)", device);
     
    723720
    724721            fin = fopen("/tmp/plexes", "r");
    725             while (fgets(line, MAX_STR_LEN - 1, fin)) {
     722            /* BERLIOS: doesn't work */
     723            while (mr_getline(line, fin)) {
    726724                if (strchr(line, '\n'))
    727725                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
     
    740738                    mr_free(tmp);
    741739
    742                     char status[MAX_STR_LEN / 4];
    743                     fgets(status, MAX_STR_LEN / 4 - 1, pin);
     740                    mr_getline(status, pin);
    744741                    pclose(pin);
    745742
    746743                    if (!strcmp(status, "up")) {
     744                        mr_free(status);
    747745                        break;  /* it's done */
    748746                    }
    749747                    update_evalcall_form(atoi(status));
    750748                    usleep(250000);
     749                    mr_free(status);
    751750                }
    752751                close_evalcall_form();
    753             }
     752                mr_free(line);
     753            }
     754            mr_free(line);
    754755            fclose(fin);
    755756            unlink("/tmp/plexes");
     
    17211722        fput_string_one_char_at_a_time(pout_to_fdisk, output);
    17221723        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    1723         mr_asprintf(tmp, "%s", last_line_of_file(FDISK_LOG));
     1724        tmp = last_line_of_file(FDISK_LOG);
    17241725        if (strstr(tmp, " (m ")) {
    17251726            log_msg(1, "Successfully created partition %d on %s", partno, drive);
     
    19121913    char *output = NULL;
    19131914    char *tmp = NULL;
     1915    char *tmp1 = NULL;
    19141916    char *partcode = NULL;
    19151917
     
    19811983            res = 0;
    19821984            fput_string_one_char_at_a_time(pout_to_fdisk, "t\n");
    1983             if (partno > 1
    1984                 || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
     1985            tmp1 = last_line_of_file(FDISK_LOG);
     1986            if (partno > 1 || strstr(tmp1, " (1-4)")) {
    19851987                log_msg(5, "Specifying partno (%d) - yay", partno);
    19861988                mr_asprintf(tmp, "%d\n", partno);
     
    19881990                mr_free(tmp);
    19891991
    1990                 log_msg(5, "A - last line = '%s'",
    1991                         last_line_of_file(FDISK_LOG));
    1992             }
     1992                mr_free(tmp1);
     1993                tmp1 = last_line_of_file(FDISK_LOG);
     1994                log_msg(5, "A - last line = '%s'", tmp1);
     1995            }
     1996            mr_free(tmp1);
    19931997
    19941998            mr_asprintf(tmp, "%s\n", partcode);
     
    19962000            mr_free(tmp);
    19972001
    1998             log_msg(5, "B - last line = '%s'",
    1999                     last_line_of_file(FDISK_LOG));
     2002            tmp1 = last_line_of_file(FDISK_LOG);
     2003            log_msg(5, "B - last line = '%s'", tmp1);
     2004            mr_free(tmp1);
     2005
    20002006            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    2001             log_msg(5, "C - last line = '%s'",
    2002                     last_line_of_file(FDISK_LOG));
    2003 
    2004             mr_asprintf(tmp, "%s", last_line_of_file(FDISK_LOG));
    2005             if (!strstr(tmp, " (m ")) {
    2006                 log_msg(1, "last line = '%s'; part type set failed", tmp);
     2007            tmp1 = last_line_of_file(FDISK_LOG);
     2008            log_msg(5, "C - last line = '%s'", tmp1);
     2009            mr_free(tmp1);
     2010
     2011            tmp1 = last_line_of_file(FDISK_LOG);
     2012            if (!strstr(tmp1, " (m ")) {
     2013                log_msg(1, "last line = '%s'; part type set failed", tmp1);
    20072014                res++;
    20082015                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    20092016            }
    2010             mr_free(tmp);
     2017            mr_free(tmp1);
    20112018
    20122019            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    20132020        } else {
    20142021            mr_asprintf(output, "t\n%d\n%s\nw\n", partno, partcode);
    2015             mr_asprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
    2016                     MONDO_LOGFILE, MONDO_LOGFILE);
     2022            mr_asprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE);
    20172023            log_msg(5, "output = '%s'", output);
    20182024            log_msg(5, "partno=%d; partcode=%s", partno, partcode);
     
    21572163    /** int *************************************************************/
    21582164    int retval = 0;
     2165
     2166    /** char ************************************************************/
     2167    char *incoming = NULL;
    21592168#ifndef __FreeBSD__
     2169    char *dev;
     2170    char *p;
    21602171    int res;
    21612172#endif
    21622173
    2163     /** char ************************************************************/
    2164     char *incoming;
    2165 #ifndef __FreeBSD__
    2166     char *dev;
    2167 #endif
    21682174    /** pointers ********************************************************/
    2169 #ifndef __FreeBSD__
    2170     char *p;
    2171 #endif
    21722175    FILE *fin;
    21732176    int i;
     
    21752178    /** end ****************************************************************/
    21762179
    2177     malloc_string(dev);
    2178     malloc_string(incoming);
    21792180    assert(mountlist != NULL);
    21802181
    21812182    for (i = 0; i < 3; i++) {
    21822183#ifdef __FreeBSD__
    2183         fin =
    2184             popen
    2185             ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2",
    2186              "r");
     2184        fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r");
    21872185        if (!fin) {
    2188             paranoid_free(dev);
    2189             paranoid_free(incoming);
    21902186            return (1);
    21912187        }
    2192         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2193              fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2188        for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    21942189            retval += stop_raid_device(incoming);
    2195         }
     2190            mr_free(incoming);
     2191        }
     2192        mr_free(incoming);
    21962193#else
    21972194        fin = fopen("/proc/mdstat", "r");
    21982195        if (!fin) {
    21992196            log_OS_error("/proc/mdstat");
    2200             paranoid_free(dev);
    2201             paranoid_free(incoming);
    22022197            return (1);
    22032198        }
    2204         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2205              fgets(incoming, MAX_STR_LEN - 1, fin)) {
    2206             for (p = incoming;
    2207                  *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
    2208                                 || !isdigit(*(p + 2))); p++);
     2199        for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     2200            for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++);
    22092201            if (*p != '\0') {
    2210                 sprintf(dev, "/dev/%s", p);
     2202                mr_asprintf(dev, "/dev/%s", p);
    22112203                for (p = dev; *p > 32; p++);
    22122204                *p = '\0';
    22132205                res = stop_raid_device(dev);
    2214             }
    2215         }
     2206                mr_free(dev);
     2207            }
     2208            mr_free(incoming);
     2209        }
     2210        mr_free(incoming);
    22162211#endif
    22172212    }
     
    22202215        log_msg(1, "Warning - unable to stop some RAID devices");
    22212216    }
    2222     paranoid_free(dev);
    2223     paranoid_free(incoming);
    22242217    system("sync");
    22252218    system("sync");
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-compare.c

    r2338 r2357  
    670670    mr_free(bkpinfo->media_device);
    671671    if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    672         mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     672        bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    673673    } else {
    674674        bkpinfo->media_device = find_cdrom_device(FALSE);
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-newt.c

    r2356 r2357  
    533533
    534534    system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    535     mr_asprintf(personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt"));
     535    personalities = last_line_of_file("/tmp/raid-personalities.txt");
    536536    mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities);
    537537    mr_free(personalities);
     
    22912291    if (does_file_exist("/tmp/NFS-SERVER-PATH")) {
    22922292        mr_free(idev);
    2293         mr_asprintf(idev, "%s", last_line_of_file("/tmp/NFS-SERVER-MOUNT"));
     2293        idev = last_line_of_file("/tmp/NFS-SERVER-MOUNT");
    22942294        mr_asprintf(isodir_format, "nfs");
    22952295        mr_free(isodir_path);
    2296         mr_asprintf(isodir_path, "%s", last_line_of_file("/tmp/NFS-SERVER-PATH"));
     2296        isodir_path = last_line_of_file("/tmp/NFS-SERVER-PATH");
    22972297    }
    22982298
     
    28612861  /** char *************************************************************/
    28622862    char output = '\0';
    2863     char tmp[MAX_STR_LEN];
     2863    char *tmp = NULL;
    28642864
    28652865  /** newt *************************************************************/
     
    28732873
    28742874    if (g_text_mode) {
    2875         for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
    2876             printf
    2877                 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
    2878             fgets(tmp, MAX_STR_LEN - 1, stdin);
     2875        while (!strchr("AICE", output)) {
     2876            printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ");
     2877            mr_getline(tmp, stdin);
     2878            output = tmp[0];
     2879            free(tmp);
    28792880        }
    28802881        return (output);
    28812882    }
    28822883
    2883     newtPushHelpLine
    2884         ("   Do you want to 'nuke' your system, restore interactively, or just compare?");
     2884    newtPushHelpLine("   Do you want to 'nuke' your system, restore interactively, or just compare?");
    28852885    newtOpenWindow(24, 3, 32, 17, "How should I restore?");
    28862886    b1 = newtButton(7, 1, "Automatically");
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c

    r2351 r2357  
    107107* @ingroup restoreUtilityGroup
    108108*/
    109 void ask_about_these_imagedevs(char *infname, char *outfname)
    110 {
     109void ask_about_these_imagedevs(char *infname, char *outfname) {
     110
    111111FILE *fin;
    112112FILE *fout;
    113 /************************************************************************
    114 * allocate memory regions. test and set  -sab 16 feb 2003              *
    115 ************************************************************************/
    116 char *incoming_ptr;
    117 char *question_ptr = NULL;
    118 
    119 char incoming[MAX_STR_LEN] = "\0";
     113char *incoming = NULL;
     114char *question = NULL;
    120115
    121116assert_string_is_neither_NULL_nor_zerolength(infname);
    122117assert_string_is_neither_NULL_nor_zerolength(outfname);
    123118
    124 incoming_ptr = malloc(sizeof(incoming));
    125 if (incoming_ptr == NULL) {
    126 fprintf(stderr, "Out of Memory\n");
    127 exit(EXIT_FAILURE);
    128 }
    129 
    130 memset(incoming_ptr, '\0', sizeof(incoming));
    131 
    132119if (!(fin = fopen(infname, "r"))) {
    133 fatal_error("Cannot openin infname");
     120    fatal_error("Cannot openin infname");
    134121}
    135122if (!(fout = fopen(outfname, "w"))) {
    136 fatal_error("Cannot openin outfname");
    137 }
    138 for (fgets(incoming_ptr, MAX_STR_LEN, fin);
    139  !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    140 strip_spaces(incoming_ptr);
    141 
    142 if (incoming[0] == '\0') {
    143     continue;
    144 }
    145 
    146 mr_asprintf(question_ptr, "Should I restore the image of %s ?", incoming_ptr);
    147 
    148 if (ask_me_yes_or_no(question_ptr)) {
    149     fprintf(fout, "%s\n", incoming_ptr);
    150 }
    151 }
    152 
    153 /*** free memory ***********/
    154 paranoid_free(incoming_ptr);
    155 incoming_ptr = NULL;
    156 mr_free(question_ptr);
     123    fatal_error("Cannot openin outfname");
     124}
     125for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     126    mr_strip_spaces(incoming);
     127
     128    if (incoming[0] == '\0') {
     129        mr_free(incoming);
     130        continue;
     131    }
     132
     133    mr_asprintf(question, "Should I restore the image of %s ?", incoming);
     134   
     135    if (ask_me_yes_or_no(question)) {
     136        fprintf(fout, "%s\n", incoming);
     137    }
     138    mr_free(incoming);
     139}
     140mr_free(incoming);
     141mr_free(question);
    157142paranoid_fclose(fout);
    158143paranoid_fclose(fin);
     
    619604        mr_free(bkpinfo->media_device);
    620605        if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    621             mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     606            bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    622607        } else {
    623608            bkpinfo->media_device = find_cdrom_device(TRUE);
     
    11191104char *command = NULL;
    11201105char *tmp;
     1106char *tmp1 = NULL;
    11211107int res = 0;
    11221108pid_t pid;
     
    12601246    if (g_text_mode) {
    12611247        printf("Restore which directory? --> ");
    1262         fgets(tmp, sizeof(tmp), stdin);
    1263         toggle_path_selection(filelist, tmp, TRUE);
    1264         if (strlen(tmp) == 0) {
     1248        mr_getline(tmp1, stdin);
     1249        toggle_path_selection(filelist, tmp1, TRUE);
     1250        if (strlen(tmp1) == 0) {
    12651251            res = 1;
    12661252        } else {
    12671253            res = 0;
    12681254        }
     1255        mr_free(tmp1);
    12691256    } else {
    12701257        res = edit_filelist(filelist);
     
    19381925    FILE *fin;
    19391926    FILE *fout;
    1940   /** malloc **/
    1941     char *incoming;
     1927    char *incoming = NULL;
    19421928
    19431929    assert_string_is_neither_NULL_nor_zerolength(output_file);
    19441930    assert_string_is_neither_NULL_nor_zerolength(input_file);
    1945     malloc_string(incoming);
    19461931
    19471932    if (!(fin = fopen(input_file, "r"))) {
     
    19521937        fatal_error("cannot open output_file");
    19531938    }
    1954     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    1955          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1939    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    19561940        if (strncmp(incoming, "etc/adjtime", 11)
    19571941            && strncmp(incoming, "etc/mtab", 8)
     
    19621946            && strncmp(incoming, "var/", 4))
    19631947            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
    1964     }
     1948        mr_free(incoming);
     1949    }
     1950    mr_free(incoming);
    19651951    paranoid_fclose(fout);
    19661952    paranoid_fclose(fin);
    1967     paranoid_free(incoming);
    19681953}
    19691954
  • branches/2.2.10/tools/quality

    r2334 r2357  
    2828
    2929# How many sprintf/strcat/strcpy vs asprintf are they
    30 for s in asprintf mr_asprintf sprintf snprintf strcat strncat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free paranoid_system mr_system assert; do
     30for s in asprintf mr_asprintf sprintf snprintf strcat strncat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline ARBITRARY_MAXIMUM MAX_TAPECATALOG_ENTRIES MAX_MOUNTLIST_ENTRIES MAXIMUM_RAID_DEVS MAXIMUM_ADDITIONAL_RAID_VARS MAXIMUM_DISKS_PER_RAID_DEV MAX_TAPECAT_FNAME_LEN MAX_NOOF_MEDIA MAX_NEWT_COMMENT_LEN MAX_NOOF_SETS_HERE MAX_STR_LEN getcwd goto free mr_free paranoid_free paranoid_system mr_system assert; do
    3131    echo "mondorescue $s usage : "
    3232    tot=0
Note: See TracChangeset for help on using the changeset viewer.