Changeset 171 in MondoRescue for trunk/mondo/mondo/common


Ignore:
Timestamp:
Dec 8, 2005, 5:20:29 PM (18 years ago)
Author:
bcornec
Message:

memory management continues:

  • mondoarchive handled completely
  • bkpinfo, begining of dyn. alloc.
  • lot of changes around memory everywhere

=> even if it compiles, i'm pretty sure it doesn't work yet (even not tried)

Location:
trunk/mondo/mondo/common
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-archive.c

    r168 r171  
    298298    /*@ buffers ******************************************************** */
    299299    char *command;
    300     char *zipparams;
     300    char *zipparams = NULL;
    301301    char *tmp, *tmp1;
    302302
     
    325325
    326326
    327         if (bkpinfo->compression_level > 0) {
     327    if (bkpinfo->compression_level > 0) {
    328328        asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    329329        //       -b %ld, TAPE_BLOCK_SIZE
     
    333333            asprintf(&tmp1, "%s -E %s", zipparams, tmp);
    334334            paranoid_free(zipparams)
    335                 zipparams = tmp1;
     335            zipparams = tmp1;
    336336        } else {
    337             asprintf(&zipparams, "");
     337            asprintf(&zipparams, " ");
    338338            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
    339339        }
    340340        paranoid_free(tmp)
    341341    } else {
    342         asprintf(&zipparams, "");
     342        asprintf(&zipparams, " ");
    343343    }
    344344
     
    582582    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    583583        asprintf(&tape_size_sz, "%ld", bkpinfo->media_size[1]);
    584         asprintf(&tape_device, "%s", bkpinfo->media_device);
     584        asprintf(&tape_device, bkpinfo->media_device);
    585585    } else {
    586         asprintf(&tape_size_sz, "");
    587         asprintf(&tape_device, "");
     586        asprintf(&tape_size_sz, " ");
     587        asprintf(&tape_device, " ");
    588588    }
    589589    if (bkpinfo->use_lzo) {
     
    825825        asprintf(&tmp, " NONBOOTABLE");
    826826    } else {
    827         asprintf(&tmp, "");
     827        asprintf(&tmp, " ");
    828828    }
    829829
     
    20072007                       "Please wait. This may take some time.", "",
    20082008                       estimated_total_noof_slices);
     2009    paranoid_free(tmp);
     2010
    20092011    if (!(fin = fopen(biggielist_fname, "r"))) {
    20102012        log_OS_error("Unable to openin biggielist");
     
    20782080                                    noof_biggie_files, use_partimagehack);
    20792081            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    2080                 write_header_block_to_stream(0,
    2081                                              calc_checksum_of_file
    2082                                              (bigfile_fname),
    2083                                              BLK_STOP_A_BIGGIE);
     2082                tmp = calc_checksum_of_file(bigfile_fname);
     2083                write_header_block_to_stream(0, tmp, BLK_STOP_A_BIGGIE);
     2084                paranoid_free(tmp);
    20842085            }
    20852086            retval += res;
     
    20902091                p = bigfile_fname;
    20912092            }
    2092             paranoid_free(tmp);
    20932093            if (res) {
    20942094                asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
     
    27722772/**
    27732773 * Make sure the user has a valid CD-R(W) in the CD drive.
    2774  * @param cdrw_dev Set to the CD-R(W) device checked.
     2774 * @param cdrw_device Set to the CD-R(W) device checked.
    27752775 * @param keep_looping If TRUE, keep pestering user until they insist
    27762776 * or insert a correct CD; if FALSE, only check once.
    27772777 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
    27782778 */
    2779 int
    2780 interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev, bool keep_looping)
     2779char *interrogate_disk_currently_in_cdrw_drive()
    27812780{
    2782     int res = 0;
    2783     char *bkp;
    27842781    char *cdrecord;
    2785 
    2786     asprintf(&bkp, "%s", cdrw_dev);
    2787     if (find_cdrw_device(cdrw_dev)) {
    2788         strcpy(cdrw_dev, bkp);
    2789     } else {
     2782    char *cdrw_device;
     2783
     2784    if ((cdrw_device = find_cdrw_device()) != NULL) {
    27902785        if (!system("which cdrecord > /dev/null 2> /dev/null")) {
    2791             asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     2786            asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device);
    27922787        } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
    2793             asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
     2788            asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device);
    27942789        } else {
    2795             asprintf(&cdrecord, "%s", "");
    2796             log_msg(2, "Oh well. I guess I'll just pray then.");
     2790            asprintf(&cdrecord, " ");
     2791            log_msg(2, "Found no cdrecord nor dvdrecord in path.");
    27972792        }
    27982793        if (cdrecord[0]) {
    2799             if (!keep_looping) {
    28002794                retract_CD_tray_and_defeat_autorun();
    2801                 res = run_program_and_log_output(cdrecord, 5);
    2802             } else {
    2803                 while ((res = run_program_and_log_output(cdrecord, 5))) {
    2804                     retract_CD_tray_and_defeat_autorun();
    2805                     if (ask_me_yes_or_no
    2806                         ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
    2807                     {
    2808                         log_msg(1, "Well, he insisted...");
    2809                         break;
    2810                     }
    2811                 }
    2812             }
     2795                run_program_and_log_output(cdrecord, 5);
    28132796        }
    28142797        paranoid_free(cdrecord);
    28152798    }
    2816     paranoid_free(bkp);
    2817 //  retract_CD_tray_and_defeat_autorun();
    2818     return (res);
     2799    return(cdrw_device);
    28192800}
    28202801
     
    28342815    char *szmsg;
    28352816    char *cdrom_dev;
    2836     char *cdrw_dev;
     2817    char *cdrw_device = NULL;
    28372818    char *our_serial_str;
    28382819    bool ok_go_ahead_burn_it;
     
    28442825    char *szunmount;
    28452826
    2846     malloc_string(cdrom_dev);
    2847     malloc_string(cdrw_dev);
    2848 
    28492827    asprintf(&szmsg, "I am about to burn %s #%d",
    28502828             media_descriptor_string(g_backup_media_type),
     
    28622840  gotos_make_me_puke:
    28632841    ok_go_ahead_burn_it = TRUE;
    2864     if (!find_cdrom_device(cdrom_dev, FALSE)) {
     2842    cdrom_dev = find_cdrom_device(FALSE);
     2843    if (cdrom_dev != NULL) {
    28652844/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    28662845      log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
     
    28802859            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
    28812860            asprintf(&our_serial_str, "%s", "");
    2882             /*
    2883                if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    2884                {
    2885                ok_go_ahead_burn_it = FALSE;
    2886                log_to_screen("There isn't a writable CD/DVD in the drive.");
    2887                }
    2888                else
    2889                {
    2890                log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
    2891                }
    2892              */
    28932861        } else if (!does_file_exist(szcdno)
    28942862                   || !does_file_exist(szserfname)) {
     
    29382906                "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
    29392907                media_descriptor_string(g_backup_media_type));
    2940         if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
     2908        if ((cdrw_device = interrogate_disk_currently_in_cdrw_drive(cdrw_device)) != NULL) {
    29412909            ok_go_ahead_burn_it = FALSE;
    29422910            log_to_screen("There isn't a writable %s in the drive.",
    29432911                          media_descriptor_string(g_backup_media_type));
    29442912        }
     2913        paranoid_free(cdrw_device);
    29452914    }
    29462915    paranoid_free(mtpt);
     
    29672936        log_msg(2, "paafcd: OK, going ahead and burning it.");
    29682937    }
     2938    paranoid_free(cdrom_dev);
    29692939
    29702940    log_msg(2,
     
    29742944    log_to_screen("Proceeding w/ %s in drive.",
    29752945                  media_descriptor_string(g_backup_media_type));
    2976     paranoid_free(cdrom_dev);
    2977     paranoid_free(cdrw_dev);
    29782946    if (pmountable) {
    29792947        if (attempt_to_mount_returned_this) {
     
    34973465            && (bkpinfo->backup_media_type == cdr
    34983466                || bkpinfo->backup_media_type == cdrw)) {
    3499             if (find_cdrom_device(tmp, FALSE))  // make sure find_cdrom_device() finds, records CD-R's loc
     3467            if ((tmp = find_cdrom_device(FALSE)) == NULL)   // make sure find_cdrom_device() finds, records CD-R's loc
    35003468            {
    35013469                log_msg(3, "*Sigh* Mike, I hate your computer.");
     
    35043472            else {
    35053473                log_msg(3, "Great. Found Mike's CD-ROM drive.");
     3474                paranoid_free(tmp);
    35063475            }
    35073476        }
     
    35943563                            "Verifying archives against live filesystem");
    35953564        if (bkpinfo->backup_media_type == cdstream) {
    3596             strcpy(bkpinfo->media_device, "/dev/cdrom");
     3565            paranoid_alloc(bkpinfo->media_device,
     3566                            "/dev/cdrom");
    35973567        }
    35983568        verify_tape_backups(bkpinfo);
     
    36083578        g_current_media_number = cdno;
    36093579        if (bkpinfo->backup_media_type != iso) {
    3610             find_cdrom_device(bkpinfo->media_device, FALSE);    // replace 0,0,0 with /dev/cdrom
     3580            paranoid_free(bkpinfo->media_device);
     3581            bkpinfo->media_device = find_cdrom_device(FALSE);
    36113582        }
    36123583        chdir("/");
     
    36473618
    36483619        run_program_and_log_output("umount " MNT_CDROM, FALSE);
    3649 //        if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
    3650 //{
    36513620        eject_device(bkpinfo->media_device);
    3652 //}
    36533621    }
    36543622    diffs = count_lines_in_file("/tmp/changed.files");
  • trunk/mondo/mondo/common/libmondo-devices-EXT.h

    r146 r171  
    99extern int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo,
    1010                                    char *mountpoint);
    11 extern int find_cdrom_device(char *output, bool try_to_mount);
    12 extern int find_dvd_device(char *output, bool try_to_mount);
     11extern char *find_cdrom_device(bool try_to_mount);
     12extern char *find_dvd_device(void);
    1313extern long get_phys_size_of_drive(char *drive);
    1414extern bool is_this_a_valid_disk_format(char *format);
     
    1616extern int find_device_in_mountlist(struct mountlist_itself *mountlist,
    1717                                    char *device);
    18 extern int mount_CDROM_here(char *device, char *mountpoint);
    1918extern long long size_of_specific_device_in_mountlist(struct
    2019                                                      mountlist_itself
     
    2827
    2928
    30 extern int find_cdrw_device(char *cdrw_device);
     29extern char *find_cdrw_device(void);
    3130
    3231
  • trunk/mondo/mondo/common/libmondo-devices.c

    r162 r171  
    1 /* libmondo-devices.c                 Subroutines for handling devices
    2    $Id$
    3 */
    4 
     1/* $Id$
     2 * Subroutines for handling devices
     3 */
    54/**
    65 * @file
     
    4342extern char *g_selfmounted_isodir;
    4443
    45 static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";
    46 static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";
    47 static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";
     44static char *g_cdrw_drive_is_here = NULL;
     45static char *g_cdrom_drive_is_here = NULL;
     46static char *g_dvd_drive_is_here = NULL;
    4847
    4948
     
    6160void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo)
    6261{
    63     strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
    64     strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
     62    if (bkpinfo->media_device != NULL) {
     63        paranoid_free(g_cdrom_drive_is_here);
     64        asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device);    // just in case
     65    }
     66    if (bkpinfo->media_device != NULL) {
     67        paranoid_free(g_dvd_drive_is_here);
     68        asprintf(&g_dvd_drive_is_here, bkpinfo->media_device);  // just in case
     69    }
    6570}
    6671
     
    152157 * @ingroup stringGroup
    153158 */
    154 static char *bkptype_to_string(t_bkptype bt)
    155 {
    156     static char *output = NULL;
     159char *bkptype_to_string(t_bkptype bt)
     160{
     161    char *output = NULL;
    157162
    158163    paranoid_free(output);
     
    319324    /*@ ints ******************************************************* */
    320325    int res = 0;
    321     int n = 0;
     326    size_t n = 0;
    322327
    323328    /*@ pointers *************************************************** */
     
    432437 * @see mount_CDROM_here
    433438 */
    434 int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)
     439bool find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)
    435440{
    436441    /*@ buffers ***************************************************** */
    437442
    438443    /*@ int's  ****************************************************** */
    439     int res;
    440     char *dev;
     444    bool res = TRUE;
     445    char *dev = NULL;
    441446
    442447    /*@ end vars **************************************************** */
    443448
    444     malloc_string(dev);
    445449    assert(bkpinfo != NULL);
    446450    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    447451
    448452    if (g_backup_media_type == dvd) {
    449         strcpy(dev, g_dvd_drive_is_here);
    450         if (!dev[0]) {
    451             find_dvd_device(dev, FALSE);
    452         }
    453     } else {
    454         strcpy(dev, g_cdrom_drive_is_here);
    455         if (!dev[0]) {
    456             find_cdrom_device(dev, FALSE);
     453        if (g_dvd_drive_is_here != NULL) {
     454            asprintf(&dev, g_dvd_drive_is_here);
     455        } else {
     456            dev = find_dvd_device();
     457        }
     458    } else {
     459        if (g_cdrom_drive_is_here != NULL) {
     460            asprintf(&dev, g_cdrom_drive_is_here);
     461        } else {
     462            dev = find_cdrom_device(FALSE);
    457463        }
    458464    }
     
    462468    }
    463469
    464     if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
     470    if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) {
    465471        if (!popup_and_get_string
    466472            ("CD-ROM device", "Please enter your CD-ROM's /dev device",
    467473             dev, MAX_STR_LEN / 4)) {
    468             res = 1;
     474            res = FALSE;
    469475        } else {
    470476            res = mount_CDROM_here(dev, mountpoint);
     
    477483    }
    478484    paranoid_free(dev);
    479     return (res);
     485    return(res);
    480486}
    481487
     
    483489/**
    484490 * Locate a CD-R/W writer's SCSI node.
    485  * @param cdrw_device SCSI node will be placed here.
    486  * @return 0 for success, nonzero for failure.
    487  */
    488 int find_cdrw_device(char *cdrw_device)
     491 * @param cdrw_device SCSI node will be placed here. Caller needs to free it.
     492 * @return the cdrw device or NULL if not found
     493 */
     494char *find_cdrw_device(void)
    489495{
    490496    /*@ buffers ************************ */
     
    493499    char *cdr_exe;
    494500    char *command;
    495 
    496     if (g_cdrw_drive_is_here[0]) {
    497         strcpy(cdrw_device, g_cdrw_drive_is_here);
     501    char *cdrw_device;
     502
     503    if (g_cdrw_drive_is_here != NULL) {
     504        asprintf(&cdrw_device, g_cdrw_drive_is_here);
    498505        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    499         return (0);
     506        return(cdrw_device);
    500507    }
    501508    if (g_backup_media_type == dvd) {
    502509        log_msg(1,
    503510                "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    504         return (1);
     511        return(NULL);
    505512    }
    506513    run_program_and_log_output("insmod ide-scsi", -1);
     
    517524        paranoid_free(command);
    518525    } else {
    519         asprintf(&tmp, "");
     526        asprintf(&tmp, " ");
    520527    }
    521528    paranoid_free(cdr_exe);
     
    523530    if (strlen(tmp) < 2) {
    524531        paranoid_free(tmp);
    525         return 1;
    526     } else {
    527         strcpy(cdrw_device, tmp);
    528         paranoid_free(tmp);
     532        return(NULL);
     533    } else {
     534        cdrw_device = tmp;
    529535
    530536        asprintf(&comment, "Found CDRW device - %s", cdrw_device);
     
    532538        paranoid_free(comment);
    533539
    534         strcpy(g_cdrw_drive_is_here, cdrw_device);
    535         return (0);
     540        paranoid_free(g_cdrw_drive_is_here);
     541        asprintf(&g_cdrw_drive_is_here, cdrw_device);
     542        return(cdrw_device);
    536543    }
    537544}
     
    542549 * Several different methods may be used to find the device, including
    543550 * calling @c cdrecord, searching @c dmesg, and trial-and-error.
    544  * @param output Where to put the located /dev entry.
     551 * @param output Where to put the located /dev entry. Needs to be freed by the caller.
    545552 * @param try_to_mount Whether to mount the CD as part of the test; if mount
    546553 * fails then return failure.
    547  * @return 0 for success, nonzero for failure.
    548  */
    549 int find_cdrom_device(char *output, bool try_to_mount)
     554 * @return output if success or NULL otherwise.
     555 */
     556char *find_cdrom_device(bool try_to_mount)
    550557{
    551558    /*@ pointers **************************************************** */
     
    554561    char *q;
    555562    char *r;
    556     int n = 0;
    557     int retval = 0;
     563    char *output = NULL;
     564    size_t n = 0;
    558565
    559566    /*@ bool's ****************************************************** */
     
    571578    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
    572579
    573     /*@ intialize *************************************************** */
    574 
    575     output[0] = '\0';
    576 
    577580    /*@ end vars **************************************************** */
    578581
    579     if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
    580         strcpy(output, g_cdrom_drive_is_here);
     582    if ((g_cdrom_drive_is_here != NULL) && !isdigit(g_cdrom_drive_is_here[0])) {
     583        asprintf(&output, g_cdrom_drive_is_here);
    581584        log_msg(3, "Been there, done that. Returning %s", output);
    582         return(0);
     585        return(output);
    583586    }
    584587    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
    585         strcpy(output, the_last_place_i_found_it);
     588        asprintf(&output, the_last_place_i_found_it);
    586589        log_msg(3,
    587590                "find_cdrom_device() --- returning last found location - '%s'",
    588591                output);
    589         return(0);
     592        return(output);
    590593    }
    591594
     
    596599    }
    597600    if (!find_home_of_exe(cdr_exe)) {
    598         strcpy(output, "/dev/cdrom");
     601        asprintf(&output, "/dev/cdrom");
    599602        log_msg(4, "Can't find cdrecord; assuming %s", output);
    600603        if (!does_device_exist(output)) {
    601604            log_msg(4, "That didn't work. Sorry.");
    602605            paranoid_free(cdr_exe);
    603             return(1);
     606            paranoid_free(output);
     607            return(NULL);
    604608        } else {
    605609            paranoid_free(cdr_exe);
    606             return(0);
     610            return(output);
    607611        }
    608612    }
     
    615619        paranoid_free(cdr_exe);
    616620        paranoid_free(command);
    617         return (1);
     621        return (NULL);
    618622    }
    619623    paranoid_free(command);
     
    672676                                    tmp);
    673677                        } else {
    674                             sprintf(output, "/dev/%s", tmp);
     678                            asprintf(&output, "/dev/%s", tmp);
    675679                            found_it = TRUE;
    676680                        }
     
    713717                                {
    714718                                    paranoid_free(cdr_exe);
    715                                     return(1);
     719                                    return(NULL);
    716720                                }
    717721                            }
     
    727731            log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
    728732                    dvd_last_resort);
    729             strcpy(output, dvd_last_resort);
     733            paranoid_free(output);
     734            asprintf(&output, dvd_last_resort);
    730735            found_it = TRUE;
    731736        }
     
    741746                    output);
    742747            found_it = FALSE;
    743             output[0] = '\0';
     748            paranoid_free(output);
    744749        }
    745750        paranoid_free(tmp);
     
    749754        log_msg(4, "(find_cdrom_device) --> '%s'", output);
    750755        if (!does_device_exist(output)) {
     756            log_msg(4, "OK, I was wrong, I haven't found it... yet.");
    751757            found_it = FALSE;
    752             log_msg(4, "OK, I was wrong, I haven't found it... yet.");
     758            paranoid_free(output);
    753759        }
    754760    }
     
    784790                                    {
    785791                                        paranoid_free(cdr_exe);
    786                                         return(1);
     792                                        return(NULL);
    787793                                    }
    788794                                }
     
    800806
    801807    if (found_it && try_to_mount) {
    802         if (mount_CDROM_here(output, mountpoint)) {
     808        if (! mount_CDROM_here(output, mountpoint)) {
    803809            log_msg(4, "[Cardigans] I've changed my mind");
    804810            found_it = FALSE;
     811            paranoid_free(output);
    805812        } else {
    806813            asprintf(&tmp, "%s/archives", mountpoint);
     
    808815                log_msg(4, "[Cardigans] I'll take it back");
    809816                found_it = FALSE;
     817                paranoid_free(output);
    810818            } else {
    811819                asprintf(&command, "umount %s", output);
     
    823831        if (!does_file_exist(output)) {
    824832            log_msg(3, "I still haven't found it.");
    825             return (1);
     833            paranoid_free(output);
     834            return(NULL);
    826835        }
    827836        log_msg(3, "(find_cdrom_device) --> '%s'", output);
    828837        strcpy(the_last_place_i_found_it, output);
    829         strcpy(g_cdrom_drive_is_here, output);
    830         return(0);
     838        paranoid_free(g_cdrom_drive_is_here);
     839        asprintf(&g_cdrom_drive_is_here, output);
     840        return(output);
    831841    }
    832842
     
    834844            "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
    835845            cdr_exe, g_cdrw_drive_is_here);
     846    paranoid_free(cdr_exe);
     847
    836848    log_msg(1, "command=%s", command);
    837849    asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     
    839851
    840852    if (tmp[0]) {
    841         strcpy(output, tmp);
     853        output = tmp;
    842854        log_msg(4, "Finally found it at %s", output);
    843         retval = 0;
    844     } else {
     855    } else {
     856        paranoid_free(tmp);
     857        paranoid_free(output);
    845858        log_msg(4, "Still couldn't find it.");
    846         retval = 1;
    847     }
    848     paranoid_free(tmp);
    849     paranoid_free(cdr_exe);
    850     return (retval);
    851 }
    852 
    853 
    854 int find_dvd_device(char *output, bool try_to_mount)
     859    }
     860    return(output);
     861}
     862
     863
     864char *find_dvd_device()
    855865{
    856866    char *tmp;
    857867    int retval = 0, devno = -1;
    858 
    859     if (g_dvd_drive_is_here[0]) {
    860         strcpy(output, g_dvd_drive_is_here);
     868    char *output = NULL;
     869
     870    if (g_dvd_drive_is_here != NULL) {
     871        asprintf(&output, g_dvd_drive_is_here);
    861872        log_msg(3, "Been there, done that. Returning %s", output);
    862         return (0);
     873        return (output);
    863874    }
    864875
     
    880891    if (devno >= 0) {
    881892        retval = 0;
    882         sprintf(output, "/dev/scd%d", devno);
    883         strcpy(g_dvd_drive_is_here, output);
     893        asprintf(&output, "/dev/scd%d", devno);
     894        paranoid_free(g_dvd_drive_is_here);
     895        asprintf(&g_dvd_drive_is_here, output);
    884896        log_msg(2, "I think DVD is at %s", output);
    885897    } else {
    886898        log_msg(2, "I cannot find DVD");
    887         retval = 1;
    888     }
    889 
    890     if (try_to_mount) {
    891         log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    892     }
    893     return (retval);
     899    }
     900
     901    return(output);
    894902}
    895903
     
    10641072    char *device_with_space;
    10651073    char *tmp;
    1066     int n = 0;
     1074    size_t n = 0;
    10671075
    10681076#ifdef __FreeBSD__
     
    12121220 * @param device The device (or file if g_ISO_restore_mode) to mount.
    12131221 * @param mountpoint The place to mount it.
    1214  * @return 0 for success, nonzero for failure.
    1215  */
    1216 int mount_CDROM_here(char *device, char *mountpoint)
     1222 * @return TRUE for success, FALSE for failure.
     1223 */
     1224bool mount_CDROM_here(char *device, char *mountpoint)
    12171225{
    12181226    /*@ buffer ****************************************************** */
     
    12251233    make_hole_for_dir(mountpoint);
    12261234    if (isdigit(device[0])) {
    1227         find_cdrom_device(device, FALSE);
     1235        paranoid_free(device);
     1236        device = find_cdrom_device(FALSE);
    12281237    }
    12291238    if (g_ISO_restore_mode) {
     
    12381247            fatal_error(command);
    12391248        }
    1240         strcpy(device, dev);
    1241         paranoid_free(dev);
     1249        paranoid_free(device);
     1250        device = dev;
    12421251#endif
    12431252    }
     
    12631272    paranoid_free(command);
    12641273
    1265     return (retval);
     1274    if (retval == 0) {
     1275        return(TRUE);
     1276    } else {
     1277        return(FALSE);
     1278    }
    12661279}
    12671280
     
    13311344        }
    13321345        log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
    1333         if (mount_CDROM_here(tmp, MNT_CDROM)) {
     1346        if (! mount_CDROM_here(tmp, MNT_CDROM)) {
    13341347            fatal_error("Mommy!");
    13351348        }
     
    14661479                    media_descriptor_string(bkpinfo->backup_media_type));
    14671480            if (bkpinfo->backup_media_type == dvd) {
    1468                 find_dvd_device(bkpinfo->media_device, FALSE);
     1481                paranoid_free(bkpinfo->media_device);
     1482                bkpinfo->media_device = find_dvd_device();
    14691483                asprintf(&tmp, "1");
    14701484                asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE);    // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    14711485                log_msg(1, "Setting to DVD defaults");
    14721486            } else {
    1473                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
     1487                paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_CDROM );
    14741488                asprintf(&tmp, "4");
    14751489                asprintf(&sz_size, "650");
     
    15081522    case cdstream:
    15091523        if (bkpinfo->disaster_recovery) {
    1510             strcpy(bkpinfo->media_device, "/dev/cdrom");
     1524            paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    15111525            log_msg(2, "CD-ROM device assumed to be at %s",
    15121526                    bkpinfo->media_device);
    15131527        } else if (bkpinfo->restore_data
    15141528                   || bkpinfo->backup_media_type == dvd) {
    1515             if (!bkpinfo->media_device[0]) {
    1516                 strcpy(bkpinfo->media_device, "/dev/cdrom");
     1529            if (bkpinfo->media_device == NULL) {
     1530                paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    15171531            }                   // just for the heck of it :)
    15181532            log_msg(1, "bkpinfo->media_device = %s",
    15191533                    bkpinfo->media_device);
    1520             if (bkpinfo->backup_media_type == dvd
    1521                 || find_cdrom_device(bkpinfo->media_device, FALSE)) {
     1534            if ((bkpinfo->backup_media_type == dvd)
     1535                || ((tmp = find_cdrom_device(FALSE)) != NULL)) {
     1536                paranoid_free(bkpinfo->media_device);
     1537                bkpinfo->media_device = tmp;
    15221538                log_msg(1, "bkpinfo->media_device = %s",
    15231539                        bkpinfo->media_device);
     
    15381554                    bkpinfo->media_device);
    15391555        } else {
    1540             if (find_cdrw_device(bkpinfo->media_device)) {
    1541                 bkpinfo->media_device[0] = '\0';
    1542             }
    1543             if (bkpinfo->media_device[0]) {
     1556            paranoid_free(bkpinfo->media_device);
     1557            bkpinfo->media_device = find_cdrw_device();
     1558            if (bkpinfo->media_device != NULL) {
    15441559                asprintf(&tmp,
    15451560                        "I think I've found your %s burner at SCSI node %s; am I right on the money?",
     
    15481563                        bkpinfo->media_device);
    15491564                if (!ask_me_yes_or_no(tmp)) {
    1550                     bkpinfo->media_device[0] = '\0';
     1565                    paranoid_free(bkpinfo->media_device);
    15511566                }
    15521567                paranoid_free(tmp);
    1553             }
    1554             if (!bkpinfo->media_device[0]) {
     1568            } else {
    15551569                if (g_kernel_version < 2.6) {
    15561570                    i = popup_and_get_string("Device node?",
     
    15841598    case tape:
    15851599
     1600        paranoid_free(bkpinfo->media_device);
    15861601        if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
    15871602            log_msg(3, "Ok, using vanilla scsi tape.");
    1588             strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
     1603            paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE );
    15891604            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    15901605                paranoid_fclose(fin);
    15911606            } else {
    1592                 strcpy(bkpinfo->media_device, "/dev/osst0");
    1593             }
    1594         }
    1595         if (bkpinfo->media_device[0]) {
     1607                paranoid_alloc(bkpinfo->media_device,"/dev/osst0");
     1608            }
     1609        }
     1610        if (bkpinfo->media_device != NULL) {
    15961611            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    15971612                paranoid_fclose(fin);
     
    16061621                    bkpinfo->media_device);
    16071622            if (!ask_me_yes_or_no(tmp)) {
    1608                 bkpinfo->media_device[0] = '\0';
     1623                paranoid_free(bkpinfo->media_device);
    16091624            }
    16101625            paranoid_free(tmp);
    16111626        }
    1612         if (!bkpinfo->media_device[0]) {
     1627        if (bkpinfo->media_device == NULL) {
    16131628            if (!popup_and_get_string
    16141629                ("Device name?",
     
    19071922#ifndef __FreeBSD__
    19081923        if (!ask_me_yes_or_no
    1909             ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))
    1910 #endif
    1911         {
    1912             strcpy(bkpinfo->kernel_path, "FAILSAFE");
    1913         }
     1924            ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) {
     1925            paranoid_alloc(bkpinfo->kernel_path, "FAILSAFE");
     1926        }
     1927#endif
    19141928
    19151929        if (!ask_me_yes_or_no
     
    20682082 * If @p dev cannot be read, set @p output to "".
    20692083 * @param dev The device to check for.
    2070  * @param output Set to @p dev if @p dev exists, "" otherwise.
     2084 * @param output Set to @p dev if @p dev exists, NULL otherwise. Needs to be freed by caller
    20712085 * @return TRUE if @p dev exists, FALSE if it doesn't.
    20722086 */
     
    20752089    char *command;
    20762090
     2091    paranoid_free(output);
    20772092    if (!dev || dev[0] == '\0') {
    2078         output[0] = '\0';
    20792093        return (FALSE);
    20802094    }
     
    20892103    if (!run_program_and_log_output(command, FALSE)
    20902104        && !run_program_and_log_output(command, FALSE)) {
    2091         strcpy(output, dev);
     2105        asprintf(&output, dev);
    20922106        log_msg(4, "Found it - %s", dev);
    20932107        paranoid_free(command);
    20942108        return (TRUE);
    20952109    } else {
    2096         output[0] = '\0';
    20972110        log_msg(4, "It's not %s", dev);
    20982111        paranoid_free(command);
     
    21282141    }
    21292142
    2130     asprintf(&mountdev, bkpinfo->media_device);
    2131     if (!mountdev[0]) {
     2143    if (bkpinfo->media_device == NULL) {
    21322144        log_it
    21332145            ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
    2134         find_cdrom_device(bkpinfo->media_device, FALSE);
     2146        bkpinfo->media_device = find_cdrom_device(FALSE);
    21352147    }
    21362148    if (!is_this_device_mounted(MNT_CDROM)) {
    2137         mount_CDROM_here(mountdev, MNT_CDROM);
     2149        (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM);
    21382150    }
    21392151    cd_number =
    21402152        atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    2141     paranoid_free(mountdev);
    21422153    return (cd_number);
    21432154}
     
    22432254    int count_lilos = 0;
    22442255    int count_grubs = 0;
    2245     int n = 0;
     2256    size_t n = 0;
    22462257
    22472258    /*@ end vars *************************************************** */
  • trunk/mondo/mondo/common/libmondo-devices.h

    r146 r171  
    88bool does_string_exist_in_boot_block(char *dev, char *str);
    99int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint);
    10 int find_cdrom_device(char *output, bool try_to_mount);
    11 int find_dvd_device(char *output, bool try_to_mount);
     10char *find_cdrom_device(bool try_to_mount);
     11char *find_dvd_device(void);
    1212long get_phys_size_of_drive(char *drive);
    1313bool is_this_a_valid_disk_format(char *format);
    14 int mount_CDROM_here(char *device, char *mountpoint);
    1514int find_device_in_mountlist(struct mountlist_itself *mountlist,
    1615                             char *device);
     
    2322
    2423
    25 int find_cdrw_device(char *cdrw_device);
     24char *find_cdrw_device(void);
    2625
    2726int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *,
  • trunk/mondo/mondo/common/libmondo-filelist.c

    r147 r171  
    214214    /*@ int **************************************** */
    215215    int i;
    216     int n = 0;
     216    size_t n = 0;
    217217    long curr_set_no;
    218218
     
    412412    FILE *pattr;
    413413    char *tmp = NULL;
    414     int n = 0;
     414    size_t n = 0;
    415415
    416416    pattr = popen(syscall, "r");
     
    443443    char *file_to_analyze = NULL;
    444444    int i;
    445     int n = 0;
     445    size_t n = 0;
    446446
    447447    if (!(fin = fopen(filelist, "r"))) {
     
    550550    int retval = 0;
    551551    int i;
    552     int n = 0;
     552    size_t n = 0;
    553553    char *p, *q;
    554554    FILE *pin, *pout, *faclin;
     
    859859    char *tmp;
    860860    int pos_in_fname;
    861     int n = 0;
     861    size_t n = 0;
    862862    /*@ int ******************************************************** */
    863863    int percentage;
     
    17691769        }
    17701770
    1771 /*
    1772       if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }
    1773       if (strlen(fname)==0) { continue; }
    1774       sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
    1775       system(temporary_string);
    1776 */
    1777 
    17781771        log_msg(5, "Looking for '%s'", fname);
    17791772        found_node = find_string_at_node(filelist, fname);
     
    17881781                turn_wildcard_chars_into_literal_chars(tmp, fname);
    17891782                fprintf(fout, "%s\n", tmp);
     1783                paranoid_free(tmp);
    17901784                retval++;
    17911785            }
     
    18121806    FILE *fin;
    18131807    char *tmp = NULL;
    1814     int n = 0;
     1808    size_t n = 0;
    18151809    struct s_node *nod;
    18161810
  • trunk/mondo/mondo/common/libmondo-files-EXT.h

    r59 r171  
    1717extern char *last_line_of_file(char *filename);
    1818extern long long length_of_file(char *filename);
    19 extern int make_checksum_list_file(char *filelist, char *cksumlist,
    20                                    char *comppath);
    2119extern int make_hole_for_file(char *outfile_fname);
    2220extern void make_list_of_files_to_ignore(char *ignorefiles_fname,
     
    5149extern int read_one_liner_data_file(char *fname, char *contents);
    5250extern int mode_of_file(char *fname);
     51extern void paranoid_alloc(char *alloc, char *orig);
  • trunk/mondo/mondo/common/libmondo-files.c

    r149 r171  
    1 /* libmondo-files.c                                  file manipulation
    2    $Id$
    3 .
    4 
    5 
    6 04/16/04
    7 - find_home_of_exe() really does return NULL now if file not found
    8 
    9 03/22/04
    10 - added mode_of_file()
    11 
    12 10/02/03
    13 - cleaned up grab_percentage_from_last_line_of_file()
    14 
    15 09/18
    16 - added int make_grub_install_scriptlet()
    17 
    18 09/16
    19 - cleaned up mkisofs feedback window
    20 
    21 09/12
    22 - fixed Teuton-hostile bug in size_of_all_biggiefiles_K()
    23 
    24 09/05
    25 - added size_of_partition_in_mountlist_K()
    26 - size_of_all_biggiefiles_K() now calls get_phys_size_of_drive(fname)
    27 
    28 07/02
    29 - fixed calls to popup_and_get_string()
    30 
    31 05/19
    32 - added CP_BIN
    33 
    34 05/05
    35 - added Joshua Oreman's FreeBSD patches
    36 
    37 05/04
    38 - find_home_of_exe() now returns NULL if file not found
    39 
    40 04/26
    41 - if >4 media est'd, say one meeeellion
    42 
    43 04/25
    44 - fixed minor bug in find_home_of_exe()
    45 
    46 04/24
    47 - added lots of assert()'s and log_OS_error()'s
    48 
    49 04/07
    50 - fix find_home_of_exe()
    51 - cleaned up code a bit
    52 
    53 03/27
    54 - copy_mondo_and_mindi_stuff --- if _homedir_/payload.tgz exists then untar it to CD
    55 
    56 01/14/2003
    57 - if backup media type == nfs then don't estimate no. of media reqd
    58 
    59 11/25/2002
    60 - don't log/echo estimated # of media required if >=50
    61 
    62 10/01 - 11/09
    63 - chmod uses 0x, not decimal :)
    64 - added is_this_file_compressed()
    65 - replace convoluted grep with wc (KP)
    66 
    67 09/01 - 09/30
    68 - only show "number of media" estimate if no -x
    69 - run_program_and_log_output() now takes boolean operator to specify
    70   whether it will log its activities in the event of _success_
    71 
    72 08/01 - 08/31
    73 - handle unknown media sizes
    74 - cleaned up some log_it() calls
    75 
    76 07/24
    77 - created
     1/*  $Id$
     2 * file manipulation
    783*/
    794
     
    11742{
    11843    /*@ buffers ***************************************************** */
    119     static char output[MAX_STR_LEN];
    120     char command[MAX_STR_LEN * 2];
    121     char tmp[MAX_STR_LEN];
     44    static char *output = NULL;
     45    char *command;
     46    char *tmp;
     47    size_t n = 0;
    12248
    12349    /*@ pointers **************************************************** */
     
    13258
    13359    assert_string_is_neither_NULL_nor_zerolength(filename);
     60
    13461    if (does_file_exist(filename)) {
    135         sprintf(command, "md5sum \"%s\"", filename);
     62        asprintf(&command, "md5sum \"%s\"", filename);
    13663        fin = popen(command, "r");
     64        paranoid_free(command);
     65
    13766        if (fin) {
    138             (void) fgets(output, MAX_STR_LEN, fin);
     67            (void) getline(&output, &n, fin);
    13968            p = strchr(output, ' ');
    14069            paranoid_pclose(fin);
    14170        }
    14271    } else {
    143         sprintf(tmp, "File '%s' not found; cannot calc checksum",
     72        asprintf(&tmp, "File '%s' not found; cannot calc checksum",
    14473                filename);
    14574        log_it(tmp);
     75        paranoid_free(tmp);
    14676    }
    14777    if (p) {
     
    16393
    16494    /*@ buffers ***************************************************** */
    165     static char curr_cksum[1000];
     95    char *curr_cksum;
    16696
    16797    /*@ pointers **************************************************** */
     
    170100    struct stat buf;
    171101
    172     /*@ initialize data *************************************************** */
    173     curr_cksum[0] = '\0';
    174 
    175102    /*@************************************************************** */
    176103
    177104    assert_string_is_neither_NULL_nor_zerolength(curr_fname);
    178105    if (lstat(curr_fname, &buf)) {
    179         return (curr_cksum);    // empty
    180     }
    181 
    182     sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),
     106        asprintf(&curr_cksum, "");
     107    } else {
     108        asprintf(&curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),
    183109            (long) (buf.st_mtime), (long) (buf.st_ctime));
     110    }
    184111    return (curr_cksum);
    185112}
    186 
    187113
    188114
     
    197123
    198124    /*@ buffers ***************************************************** */
    199     char command[MAX_STR_LEN * 2];
    200     char incoming[MAX_STR_LEN];
    201     char tmp[MAX_STR_LEN];
     125    char *command;
     126    char *incoming = NULL;
     127    char *tmp;
    202128
    203129    /*@ long ******************************************************** */
    204130    long noof_lines = -1L;
    205131
     132    /*@ int ******************************************************** */
     133    size_t n = 0;
     134
    206135    /*@ pointers **************************************************** */
    207136    FILE *fin;
    208137
    209     /*@ initialize [0] to null ******************************************** */
    210     incoming[0] = '\0';
    211 
    212138    assert_string_is_neither_NULL_nor_zerolength(filename);
    213139    if (!does_file_exist(filename)) {
    214         sprintf(tmp,
     140        asprintf(&tmp,
    215141                "%s does not exist, so I cannot found the number of lines in it",
    216142                filename);
    217143        log_it(tmp);
     144        paranoid_free(tmp);
    218145        return (0);
    219146    }
    220     sprintf(command, "cat %s | wc -l", filename);
     147    asprintf(&command, "cat %s | wc -l", filename);
    221148    if (!does_file_exist(filename)) {
    222149        return (-1);
    223150    }
    224151    fin = popen(command, "r");
     152    paranoid_free(command);
     153
    225154    if (fin) {
    226155        if (feof(fin)) {
    227156            noof_lines = 0;
    228157        } else {
    229             (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     158            (void) getline(&incoming, &n, fin);
    230159            while (strlen(incoming) > 0
    231160                   && incoming[strlen(incoming) - 1] < 32) {
     
    233162            }
    234163            noof_lines = atol(incoming);
     164            paranoid_free(incoming);
    235165        }
    236166        paranoid_pclose(fin);
     
    254184
    255185    assert(filename != NULL);
    256     //  assert_string_is_neither_NULL_nor_zerolength(filename);
     186
    257187    if (lstat(filename, &buf)) {
    258188        log_msg(20, "%s does not exist", filename);
     
    265195
    266196
    267 
    268 
    269 
    270 
    271197/**
    272198 * Modify @p inout (a file containing a list of files) to only contain files
     
    278204void exclude_nonexistent_files(char *inout)
    279205{
    280     char infname[MAX_STR_LEN];
    281     char outfname[MAX_STR_LEN];
    282     char tmp[MAX_STR_LEN];
    283     char incoming[MAX_STR_LEN];
     206    char *infname;
     207    char *outfname;
     208    char *tmp;
     209    char *incoming = NULL;
    284210
    285211    /*@ int ********************************************************* */
    286212    int i;
     213    size_t n = 0;
    287214
    288215    /*@ pointers **************************************************** */
     
    293220
    294221    assert_string_is_neither_NULL_nor_zerolength(inout);
    295     sprintf(infname, "%s.in", inout);
    296     sprintf(outfname, "%s", inout);
    297     sprintf(tmp, "cp -f %s %s", inout, infname);
     222
     223    asprintf(&infname, "%s.in", inout);
     224
     225    asprintf(&tmp, "cp -f %s %s", inout, infname);
    298226    run_program_and_log_output(tmp, FALSE);
     227    paranoid_free(tmp);
     228
    299229    if (!(fin = fopen(infname, "r"))) {
    300230        log_OS_error("Unable to openin infname");
     231        paranoid_free(infname);
    301232        return;
    302233    }
     234
     235    asprintf(&outfname, "%s", inout);
    303236    if (!(fout = fopen(outfname, "w"))) {
    304237        log_OS_error("Unable to openout outfname");
     238        paranoid_free(outfname);
    305239        return;
    306240    }
    307     for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    308          fgets(incoming, MAX_STR_LEN, fin)) {
     241    paranoid_free(outfname);
     242
     243    for (getline(&incoming, &n, fin); !feof(fin);
     244         getline(&incoming, &n, fin)) {
    309245        i = strlen(incoming) - 1;
    310246        if (i >= 0 && incoming[i] < 32) {
     
    314250            fprintf(fout, "%s\n", incoming);
    315251        } else {
    316             sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
     252            asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming);
    317253            log_it(tmp);
    318         }
    319     }
     254            paranoid_free(tmp);
     255        }
     256    }
     257    paranoid_free(incoming);
    320258    paranoid_fclose(fout);
    321259    paranoid_fclose(fin);
    322260    unlink(infname);
    323 }
    324 
    325 
    326 
    327 
    328 
    329 
    330 
     261    paranoid_free(infname);
     262}
    331263
    332264
     
    340272int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    341273{
    342     char tmp[MAX_STR_LEN];
     274    char *tmp;
    343275
    344276    if (!kernel[0]) {
     
    360292                ("Kernel not found. Please specify with the '-k' flag.");
    361293        }
    362         sprintf(tmp, "User says kernel is at %s", kernel);
     294        asprintf(&tmp, "User says kernel is at %s", kernel);
    363295        log_it(tmp);
     296        paranoid_free(tmp);
    364297    }
    365298    return (0);
    366299}
    367 
    368 
    369 
    370 
    371300
    372301
     
    387316    char *command;
    388317
    389     malloc_string(incoming);
    390     malloc_string(command);
    391     incoming[0] = '\0';
    392318    /*@******************************* */
    393319
    394320    assert_string_is_neither_NULL_nor_zerolength(fname);
    395     sprintf(command, "which %s 2> /dev/null", fname);
    396     strcpy(incoming, call_program_and_get_last_line_of_output(command));
     321    asprintf(&command, "which %s 2> /dev/null", fname);
     322    asprintf(&incoming, call_program_and_get_last_line_of_output(command));
     323    paranoid_free(command);
     324
    397325    if (incoming[0] == '\0') {
    398326        if (system("which file > /dev/null 2> /dev/null")) {
    399327            paranoid_free(incoming);
    400             paranoid_free(command);
    401             output[0] = '\0';
    402328            return (NULL);      // forget it :)
    403329        }
    404         sprintf(command,
     330        asprintf(&command,
    405331                "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
    406332                incoming);
    407         strcpy(incoming,
     333        paranoid_free(incoming);
     334
     335        asprintf(&incoming,
    408336               call_program_and_get_last_line_of_output(command));
     337        paranoid_free(command);
    409338    }
    410339    if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    411340    {
    412         sprintf(command, "dirname %s 2> /dev/null", incoming);
    413         strcpy(incoming,
     341        asprintf(&command, "dirname %s 2> /dev/null", incoming);
     342        paranoid_free(incoming);
     343
     344        asprintf(&incoming,
    414345               call_program_and_get_last_line_of_output(command));
     346        paranoid_free(command);
    415347    }
    416348    strcpy(output, incoming);
     349    paranoid_free(incoming);
     350
    417351    if (output[0] != '\0' && does_file_exist(output)) {
    418352        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
    419                 incoming);
     353                output);
    420354    } else {
    421355        output[0] = '\0';
    422356        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
    423357    }
    424     paranoid_free(incoming);
    425     paranoid_free(command);
    426358    if (!output[0]) {
    427359        return (NULL);
     
    432364
    433365
    434 
    435 
    436 
    437 
    438 
    439 
    440366/**
    441367 * Get the last sequence of digits surrounded by non-digits in the first 32k of
     
    458384
    459385    assert_string_is_neither_NULL_nor_zerolength(logfile);
     386
    460387    if (!(fin = fopen(logfile, "r"))) {
    461388        log_OS_error("Unable to open logfile");
     
    471398    for (; len > 0 && isdigit(datablock[len - 1]); len--);
    472399    trackno = atoi(datablock + len);
    473     /*
    474        sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    475        log_it(tmp);
    476      */
    477400    return (trackno);
    478401}
    479 
    480 
    481 
    482 
    483 
    484402
    485403
     
    494412
    495413    /*@ buffers ***************************************************** */
    496     char tmp[MAX_STR_LEN];
    497     char lastline[MAX_STR_LEN];
    498     char command[MAX_STR_LEN];
     414    char *lastline;
     415    char *command;
    499416    /*@ pointers **************************************************** */
    500417    char *p;
     
    507424         && !strstr(err_log_lines[i], "% done"); i--);
    508425    if (i < 0) {
    509         sprintf(command,
     426        asprintf(&command,
    510427                "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'",
    511428                filename, '%');
    512         strcpy(lastline,
     429        asprintf(&lastline,
    513430               call_program_and_get_last_line_of_output(command));
     431        paranoid_free(command);
    514432        if (!lastline[0]) {
     433            paranoid_free(lastline);
    515434            return (0);
    516435        }
    517436    } else {
    518         strcpy(lastline, err_log_lines[i]);
     437        asprintf(&lastline, err_log_lines[i]);
    519438    }
    520439
     
    523442        *p = '\0';
    524443    }
    525 //  log_msg(2, "lastline='%s', ", p, lastline);
    526444    if (!p) {
     445        paranoid_free(lastline);
    527446        return (0);
    528447    }
     
    533452    }
    534453    i = atoi(p);
    535 
    536     sprintf(tmp, "'%s' --> %d", p, i);
    537 //     log_to_screen(tmp);
     454    paranoid_free(lastline);
    538455
    539456    return (i);
    540457}
    541 
    542 
    543 
    544458
    545459
     
    554468    /*@ buffers ***************************************************** */
    555469    static char output[MAX_STR_LEN];
    556     static char command[MAX_STR_LEN * 2];
    557     static char tmp[MAX_STR_LEN];
     470    static char *command;
     471    static char *tmp;
    558472
    559473    /*@ pointers **************************************************** */
     
    563477
    564478    if (!does_file_exist(filename)) {
    565         sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
     479        asprintf(&tmp, "Tring to get last line of nonexistent file (%s)",
    566480                filename);
    567481        log_it(tmp);
     482        paranoid_free(tmp);
     483
    568484        output[0] = '\0';
    569485        return (output);
    570486    }
    571     sprintf(command, "tail -n1 %s", filename);
     487    asprintf(&command, "tail -n1 %s", filename);
    572488    fin = popen(command, "r");
     489    paranoid_free(command);
     490
    573491    (void) fgets(output, MAX_STR_LEN, fin);
    574492    paranoid_pclose(fin);
     
    578496    return (output);
    579497}
     498
    580499
    581500/**
     
    605524
    606525
    607 
    608 /**
    609  * ?????
    610  * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.
    611  */
    612 int
    613 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
    614 {
    615     /*@ pointers **************************************************** */
    616     FILE *fin;
    617     FILE *fout;
    618 
    619     /*@ int   ******************************************************* */
    620     int percentage;
    621     int i;
    622     int counter = 0;
    623 
    624     /*@ buffer ****************************************************** */
    625     char stub_fname[1000];
    626     char curr_fname[1000];
    627     char curr_cksum[1000];
    628     char tmp[1000];
    629 
    630     /*@ long [long] ************************************************* */
    631     long long filelist_length;
    632     long curr_pos;
    633     long start_time;
    634     long current_time;
    635     long time_taken;
    636     long time_remaining;
    637 
    638     /*@ end vars *************************************************** */
    639 
    640     start_time = get_time();
    641     filelist_length = length_of_file(filelist);
    642     sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    643     log_it(tmp);
    644     fin = fopen(filelist, "r");
    645     if (fin == NULL) {
    646         log_OS_error("Unable to fopen-in filelist");
    647         log_to_screen("Can't open filelist");
    648         return (1);
    649     }
    650     fout = fopen(cksumlist, "w");
    651     if (fout == NULL) {
    652         log_OS_error("Unable to openout cksumlist");
    653         paranoid_fclose(fin);
    654         log_to_screen("Can't open checksum list");
    655         return (1);
    656     }
    657     for (fgets(stub_fname, 999, fin); !feof(fin);
    658          fgets(stub_fname, 999, fin)) {
    659         if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
    660             stub_fname[i] = '\0';
    661         }
    662         sprintf(tmp, "%s%s", comppath, stub_fname);
    663         strcpy(curr_fname, tmp + 1);
    664         strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
    665         fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
    666         if (counter++ > 12) {
    667             current_time = get_time();
    668             counter = 0;
    669             curr_fname[37] = '\0';
    670             curr_pos = ftell(fin) / 1024;
    671             percentage = (int) (curr_pos * 100 / filelist_length);
    672             time_taken = current_time - start_time;
    673             if (percentage == 0) {
    674                 /*              printf("%0d%% done      \r",percentage); */
    675             } else {
    676                 time_remaining =
    677                     time_taken * 100 / (long) (percentage) - time_taken;
    678                 sprintf(tmp,
    679                         "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    680                         percentage, (int) (time_taken / 60),
    681                         (int) (time_taken % 60),
    682                         (int) (time_remaining / 60),
    683                         (int) (time_remaining % 60), curr_fname);
    684                 log_to_screen(tmp);
    685             }
    686             sync();
    687         }
    688     }
    689     paranoid_fclose(fout);
    690     paranoid_fclose(fin);
    691     log_it("Done.");
    692     return (0);
    693 }
    694 
    695 
    696526/**
    697527 * Create the directory @p outdir_fname and all parent directories. Equivalent to <tt>mkdir -p</tt>.
     
    702532int make_hole_for_dir(char *outdir_fname)
    703533{
    704     char tmp[MAX_STR_LEN * 2];
     534    char *tmp;
    705535    int res = 0;
    706536
    707537    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    708     sprintf(tmp, "mkdir -p %s", outdir_fname);
     538    asprintf(&tmp, "mkdir -p %s", outdir_fname);
    709539    res = system(tmp);
     540    paranoid_free(tmp);
    710541    return (res);
    711542}
     
    722553{
    723554    /*@ buffer ****************************************************** */
    724     char command[MAX_STR_LEN * 2];
     555    char *command;
    725556
    726557    /*@ int  ******************************************************** */
     
    732563    assert(!strstr(outfile_fname, MNT_CDROM));
    733564    assert(!strstr(outfile_fname, "/dev/cdrom"));
    734     sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     565
     566    asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    735567    res += system(command);
    736     sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     568    paranoid_free(command);
     569
     570    asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    737571    res += system(command);
    738     sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     572    paranoid_free(command);
     573
     574    asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    739575    res += system(command);
     576    paranoid_free(command);
    740577    unlink(outfile_fname);
    741578    return (0);
    742579}
    743 
    744 
    745580
    746581
     
    760595
    761596    /*@ buffers **************************************************** */
    762     char incoming[MAX_STR_LEN];
    763 
     597    char *incoming = NULL;
     598
     599    size_t n = 0;
    764600    /*@ end vars *************************************************** */
    765601
     
    771607        return (0);
    772608    }
    773     (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     609    (void) getline(&incoming, &n, fin);
    774610    while (!feof(fin)) {
    775611        if (strstr(incoming, wildcard)) {
    776612            matches++;
    777613        }
    778         (void) fgets(incoming, MAX_STR_LEN - 1, fin);
     614        (void) getline(&incoming, &n, fin);
    779615    }
    780616    paranoid_fclose(fin);
     617    paranoid_free(incoming);
    781618    return (matches);
    782619}
    783 
    784 
    785620
    786621
     
    794629void register_pid(pid_t pid, char *name_str)
    795630{
    796     char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1];
     631    char *tmp;
     632    char *lockfile_fname;
    797633    int res;
     634    size_t n = 0;
    798635    FILE *fin;
    799636
    800     sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);
     637    asprintf(&lockfile_fname, "/var/run/monitas-%s.pid", name_str);
    801638    if (!pid) {
    802639        log_it("Unregistering PID");
     
    804641            log_it("Error unregistering PID");
    805642        }
     643        paranoid_free(lockfile_fname);
    806644        return;
    807645    }
    808646    if (does_file_exist(lockfile_fname)) {
    809         tmp[0] = '\0';
    810647        if ((fin = fopen(lockfile_fname, "r"))) {
    811             (void) fgets(tmp, MAX_STR_LEN, fin);
     648            (void) getline(&tmp, &n, fin);
    812649            paranoid_fclose(fin);
    813650        } else {
     
    815652        }
    816653        pid = (pid_t) atol(tmp);
    817         sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
     654        paranoid_free(tmp);
     655
     656        asprintf(&tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid);
    818657        res = system(tmp);
     658        paranoid_free(tmp);
    819659        if (!res) {
    820660            log_it
     
    823663        }
    824664    }
    825     sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
     665    asprintf(&tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),
    826666            lockfile_fname);
     667    paranoid_free(lockfile_fname);
     668
    827669    if (system(tmp)) {
    828670        fatal_error("Cannot register PID");
    829671    }
    830 }
    831 
     672    paranoid_free(tmp);
     673    return;
     674}
    832675
    833676
     
    840683long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    841684{
    842     char command[MAX_STR_LEN];
    843     char mountlist[MAX_STR_LEN];
    844     char sz_res[MAX_STR_LEN];
     685    char *command;
     686    char *sz_res;
    845687    long file_len_K;
    846688
    847     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    848     sprintf(command,
    849             "cat %s/mountlist.txt | grep \"%s \" | head -n1 | awk '{print $4;}'",
    850             tmpdir, dev);
     689    asprintf(&command,
     690            "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'",
     691            dev, tmpdir);
    851692    log_it(command);
    852     strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     693    asprintf(&sz_res, call_program_and_get_last_line_of_output(command));
    853694    file_len_K = atol(sz_res);
    854695    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     696    paranoid_free(command);
     697    paranoid_free(sz_res);
    855698    return (file_len_K);
    856699}
     700
    857701
    858702/**
     
    874718    /*@ pointers *************************************************** */
    875719    FILE *fin = NULL;
     720    size_t n = 0;
    876721
    877722    /*@ end vars *************************************************** */
    878723
    879     malloc_string(fname);
    880     malloc_string(biggielist);
    881     malloc_string(comment);
    882724    log_it("Calculating size of all biggiefiles (in total)");
    883     sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     725    asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    884726    log_it("biggielist = %s", biggielist);
    885727    if (!(fin = fopen(biggielist, "r"))) {
     
    888730    } else {
    889731        log_msg(4, "Reading it...");
    890         for (fgets(fname, MAX_STR_LEN, fin); !feof(fin);
    891              fgets(fname, MAX_STR_LEN, fin)) {
     732        for (getline(&fname, &n, fin); !feof(fin);
     733             getline(&fname, &n, fin)) {
    892734            if (fname[strlen(fname) - 1] <= 32) {
    893735                fname[strlen(fname) - 1] = '\0';
     
    902744                log_msg(4, "%s --> %ld K", fname, file_len_K);
    903745            }
    904             sprintf(comment,
     746            asprintf(&comment,
    905747                    "After adding %s, scratchL+%ld now equals %ld", fname,
    906748                    file_len_K, scratchL);
    907749            log_msg(4, comment);
     750            paranoid_free(comment);
     751
    908752            if (feof(fin)) {
    909753                break;
    910754            }
    911755        }
    912     }
     756        paranoid_free(fname);
     757    }
     758    paranoid_free(biggielist);
     759
    913760    log_it("Closing...");
    914761    paranoid_fclose(fin);
    915762    log_it("Finished calculating total size of all biggiefiles");
    916     paranoid_free(fname);
    917     paranoid_free(biggielist);
    918     paranoid_free(comment);
    919763    return (scratchL);
    920764}
     765
    921766
    922767/**
     
    929774{
    930775    /*@ buffer ****************************************************** */
    931     char tmp[MAX_STR_LEN];
    932     char command[MAX_STR_LEN * 2];
     776    char *tmp = NULL;
     777    char *command;
    933778    long long llres;
     779    size_t n = 0;
    934780    /*@ pointers **************************************************** */
    935781    char *p;
     
    938784    /*@ end vars *************************************************** */
    939785
    940     sprintf(command, "du -sk %s", mountpt);
     786    asprintf(&command, "du -sk %s", mountpt);
    941787    fin = popen(command, "r");
    942     (void) fgets(tmp, MAX_STR_LEN, fin);
     788    paranoid_free(command);
     789
     790    (void) getline(&tmp, &n, fin);
    943791    paranoid_pclose(fin);
    944792    p = strchr(tmp, '\t');
     
    950798        llres += (int) (*p - '0');
    951799    }
     800    paranoid_free(tmp);
    952801    return (llres);
    953802}
     
    969818}
    970819
     820
    971821/**
    972822 * Update a reverse CRC checksum to include another character.
     
    985835
    986836
    987 
    988 
    989837/**
    990838 * Check for an executable on the user's system; write a message to the
     
    996844{
    997845    /*@ buffers *** */
    998     char command[MAX_STR_LEN * 2];
    999     char errorstr[MAX_STR_LEN];
    1000 
    1001 
    1002     sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    1003     sprintf(errorstr,
     846    char *command;
     847    char *errorstr;
     848    int res = 0;
     849
     850
     851    asprintf(&command, "which %s > /dev/null 2> /dev/null", fname);
     852    res = system(command);
     853    paranoid_free(command);
     854
     855    if (res) {
     856        asprintf(&errorstr,
    1004857            "Please install '%s'. I cannot find it on your system.",
    1005858            fname);
    1006     if (system(command)) {
    1007859        log_to_screen(errorstr);
     860        paranoid_free(errorstr);
    1008861        log_to_screen
    1009             ("There may be hyperlink at http://www.mondorescue.com which");
     862            ("There may be an hyperlink at http://www.mondorescue.org which");
    1010863        log_to_screen("will take you to the relevant (missing) package.");
    1011864        return (1);
     
    1014867    }
    1015868}
    1016 
    1017 
    1018 
    1019 
    1020869
    1021870
     
    1050899
    1051900
    1052 
    1053901/**
    1054902 * Read @p fname into @p contents.
     
    1083931    return (res);
    1084932}
    1085 
    1086 
    1087 
    1088 
    1089 
    1090 
    1091 
    1092933
    1093934
     
    1105946{
    1106947    /*@ Char buffers ** */
    1107     char command[MAX_STR_LEN * 2];
    1108     char tmp[MAX_STR_LEN];
     948    char *command;
     949    char *tmp;
    1109950    char old_pwd[MAX_STR_LEN];
    1110951
     
    1118959        g_mondo_home = find_and_store_mondoarchives_home();
    1119960    }
    1120     sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
     961    asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    1121962            bkpinfo->scratchdir);
    1122963
     
    1125966        fatal_error("Failed to copy Mondo's stuff to scratchdir");
    1126967    }
    1127 
    1128     sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     968    paranoid_free(command);
     969
     970    asprintf(&tmp, "%s/payload.tgz", g_mondo_home);
    1129971    if (does_file_exist(tmp)) {
    1130972        log_it("Untarring payload %s to scratchdir %s", tmp,
     
    1132974        (void) getcwd(old_pwd, MAX_STR_LEN - 1);
    1133975        chdir(bkpinfo->scratchdir);
    1134         sprintf(command, "tar -zxvf %s", tmp);
     976        asprintf(&command, "tar -zxvf %s", tmp);
    1135977        if (run_program_and_log_output(command, FALSE)) {
    1136978            fatal_error("Failed to untar payload");
    1137979        }
     980        paranoid_free(command);
    1138981        chdir(old_pwd);
    1139982    }
    1140 
    1141     sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
     983    paranoid_free(tmp);
     984
     985    asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    1142986            bkpinfo->scratchdir);
    1143 
    1144987    if (run_program_and_log_output(command, FALSE)) {
    1145988        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    1146989    }
    1147 
    1148     strcpy(tmp,
     990    paranoid_free(command);
     991
     992    asprintf(&tmp,
    1149993           call_program_and_get_last_line_of_output("which mondorestore"));
    1150994    if (!tmp[0]) {
     
    1152996            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    1153997    }
    1154     sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     998    asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     999    paranoid_free(tmp);
     1000
    11551001    if (run_program_and_log_output(command, FALSE)) {
    11561002        fatal_error("Failed to copy mondorestore to tmpdir");
    11571003    }
    1158 
    1159     sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1004    paranoid_free(command);
     1005
     1006    asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    11601007    paranoid_system(command);
     1008    paranoid_free(command);
    11611009
    11621010    if (bkpinfo->postnuke_tarball[0]) {
    1163         sprintf(command, "cp -f %s %s/post-nuke.tgz",
     1011        asprintf(&command, "cp -f %s %s/post-nuke.tgz",
    11641012                bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    11651013        if (run_program_and_log_output(command, FALSE)) {
    11661014            fatal_error("Unable to copy post-nuke tarball to tmpdir");
    11671015        }
    1168     }
    1169 
     1016        paranoid_free(command);
     1017    }
    11701018
    11711019    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    11721020}
    1173 
    1174 
    1175 
    11761021
    11771022
     
    11881033
    11891034    /*@ buffers ******** */
    1190     char outfile[MAX_STR_LEN];
    1191     char nfs_dev[MAX_STR_LEN];
    1192     char nfs_mount[MAX_STR_LEN];
    1193     char nfs_client_ipaddr[MAX_STR_LEN];
    1194     char nfs_client_netmask[MAX_STR_LEN];
    1195     char nfs_client_defgw[MAX_STR_LEN];
    1196     char nfs_server_ipaddr[MAX_STR_LEN];
    1197     char tmp[MAX_STR_LEN];
    1198     char command[MAX_STR_LEN * 2];
     1035    char *outfile;
     1036    char *nfs_dev;
     1037    char *nfs_mount;
     1038    char *nfs_client_ipaddr;
     1039    char *nfs_client_netmask;
     1040    char *nfs_client_defgw;
     1041    char *nfs_server_ipaddr;
     1042    char *tmp;
     1043    char *command;
    11991044
    12001045    /*@ pointers ***** */
     
    12051050
    12061051    log_it("Storing NFS configuration");
    1207     strcpy(tmp, bkpinfo->nfs_mount);
     1052    asprintf(&tmp, bkpinfo->nfs_mount);
    12081053    p = strchr(tmp, ':');
    12091054    if (!p) {
     
    12121057    }
    12131058    *(p++) = '\0';
    1214     strcpy(nfs_server_ipaddr, tmp);
    1215     strcpy(nfs_mount, p);
    1216     sprintf(command,
     1059    asprintf(&nfs_server_ipaddr, tmp);
     1060    paranoid_free(tmp);
     1061
     1062    asprintf(&nfs_mount, p);
     1063    asprintf(&command,
    12171064            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1218     strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
    1219     sprintf(command,
     1065    asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command));
     1066    paranoid_free(command);
     1067
     1068    asprintf(&command,
    12201069            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1221     strcpy(nfs_client_ipaddr,
     1070    asprintf(&nfs_client_ipaddr,
    12221071           call_program_and_get_last_line_of_output(command));
    1223     sprintf(command,
     1072    paranoid_free(command);
     1073
     1074    asprintf(&command,
    12241075            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1225     strcpy(nfs_client_netmask,
     1076    asprintf(&nfs_client_netmask,
    12261077           call_program_and_get_last_line_of_output(command));
    1227     sprintf(command,
     1078    paranoid_free(command);
     1079
     1080    asprintf(&command,
    12281081            "route | egrep '^default' | awk '{printf $2}'");
    1229     strcpy(nfs_client_defgw,
     1082    asprintf(&nfs_client_defgw,
    12301083           call_program_and_get_last_line_of_output(command));
    1231     sprintf(tmp,
    1232             "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s",
    1233             nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount);
     1084    paranoid_free(command);
     1085
     1086    asprintf(&tmp,
     1087            "nfs_client_ipaddr=%s; nfs_client_netmask=%s; nfs_server_ipaddr=%s; nfs_mount=%s; nfs_client_defgw=%s;  ",
     1088            nfs_client_ipaddr, nfs_client_netmask, nfs_server_ipaddr, nfs_mount, nfs_client_defgw);
     1089    paranoid_free(nfs_mount);
     1090    log_it(tmp);
     1091    paranoid_free(tmp);
     1092
    12341093    if (strlen(nfs_dev) < 2) {
    12351094        fatal_error
    12361095            ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified.");
    12371096    }
    1238     sprintf(outfile, "%s/start-nfs", bkpinfo->tmpdir);
    1239     sprintf(tmp, "outfile = %s", outfile);
     1097    asprintf(&outfile, "%s/start-nfs", bkpinfo->tmpdir);
     1098    asprintf(&tmp, "outfile = %s", outfile);
    12401099    log_it(tmp);
     1100    paranoid_free(tmp);
     1101
    12411102    if (!(fout = fopen(outfile, "w"))) {
    12421103        fatal_error("Cannot store NFS config");
     
    12561117//  paranoid_system ("mkdir -p /var/cache/mondo-archive 2> /dev/null");
    12571118
    1258     sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile);
     1119    asprintf(&tmp, "cp -f %s /var/cache/mondo-archive", outfile);
     1120    paranoid_free(outfile);
     1121
    12591122    run_program_and_log_output(tmp, FALSE);
    1260 
    1261     sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
     1123    paranoid_free(tmp);
     1124
     1125    asprintf(&tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
    12621126    write_one_liner_data_file(tmp, nfs_dev);
    1263 
    1264     sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1127    paranoid_free(nfs_dev);
     1128    paranoid_free(tmp);
     1129
     1130    asprintf(&tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    12651131    write_one_liner_data_file(tmp, nfs_client_ipaddr);
    1266     sprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
     1132    paranoid_free(nfs_client_ipaddr);
     1133    paranoid_free(tmp);
     1134
     1135    asprintf(&tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
    12671136    write_one_liner_data_file(tmp, nfs_client_netmask);
    1268     sprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
     1137    paranoid_free(nfs_client_netmask);
     1138    paranoid_free(tmp);
     1139
     1140    asprintf(&tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
    12691141    write_one_liner_data_file(tmp, nfs_client_defgw);
    1270     sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1142    paranoid_free(nfs_client_defgw);
     1143    paranoid_free(tmp);
     1144
     1145    asprintf(&tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
    12711146    write_one_liner_data_file(tmp, nfs_server_ipaddr);
    1272     sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1147    paranoid_free(nfs_server_ipaddr);
     1148    paranoid_free(tmp);
     1149
     1150    asprintf(&tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
    12731151    write_one_liner_data_file(tmp, bkpinfo->nfs_mount);
    1274     sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
     1152    paranoid_free(tmp);
     1153
     1154    asprintf(&tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
    12751155    write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);
    1276     sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     1156    paranoid_free(tmp);
     1157
     1158    asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    12771159    write_one_liner_data_file(tmp, bkpinfo->prefix);
     1160    paranoid_free(tmp);
     1161
    12781162    log_it("Finished storing NFS configuration");
    12791163}
    1280 
    1281 
    1282 
    1283 
    12841164
    12851165
     
    13041184{
    13051185    /*@ buffers *************** */
    1306     char tmp[MAX_STR_LEN];
     1186    char *tmp;
    13071187
    13081188    /*@ long long ************* */
     
    13291209    }
    13301210    if (scratchLL <= 1) {
    1331         sprintf(tmp,
     1211        asprintf(&tmp,
    13321212                "Your backup will probably occupy a single %s. Maybe two.",
    13331213                media_descriptor_string(bkpinfo->backup_media_type));
    13341214    } else {
    1335         sprintf(tmp, "Your backup will occupy approximately %s media.",
     1215        asprintf(&tmp, "Your backup will occupy approximately %s media.",
    13361216                number_to_text((int) (scratchLL + 1)));
    13371217    }
     
    13391219        log_to_screen(tmp);
    13401220    }
    1341 }
    1342 
    1343 
    1344 /**
    1345  * Get the last suffix of @p instr.
    1346  * If @p instr was "httpd.log.gz", we would return "gz".
    1347  * @param instr The filename to get the suffix of.
    1348  * @return The suffix (without a dot), or "" if none.
    1349  * @note The returned string points to static storage that will be overwritten with each call.
    1350  */
    1351 char *sz_last_suffix(char *instr)
    1352 {
    1353     static char outstr[MAX_STR_LEN];
    1354     char *p;
    1355 
    1356     p = strrchr(instr, '.');
    1357     if (!p) {
    1358         outstr[0] = '\0';
    1359     } else {
    1360         strcpy(outstr, p);
    1361     }
    1362     return (outstr);
     1221    paranoid_free(tmp);
     1222    return;
    13631223}
    13641224
     
    13721232bool is_this_file_compressed(char *filename)
    13731233{
    1374     char do_not_compress_these[MAX_STR_LEN];
    1375     char tmp[MAX_STR_LEN];
     1234    char *do_not_compress_these;
     1235    char *tmp;
    13761236    char *p;
    13771237
    1378     sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1238    asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    13791239    if (!does_file_exist(tmp)) {
     1240        paranoid_free(tmp);
    13801241        return (FALSE);
    13811242    }
    1382     strcpy(do_not_compress_these, last_line_of_file(tmp));
     1243    paranoid_free(tmp);
     1244
     1245    asprintf(&do_not_compress_these, last_line_of_file(tmp));
    13831246    for (p = do_not_compress_these; p != NULL; p++) {
    1384         strcpy(tmp, p);
     1247        asprintf(&tmp, p);
    13851248        if (strchr(tmp, ' ')) {
    13861249            *(strchr(tmp, ' ')) = '\0';
    13871250        }
    1388         if (!strcmp(sz_last_suffix(filename), tmp)) {   /*printf("MATCH\n"); */
     1251        if (!strcmp(strrchr(filename, '.'), tmp)) {
     1252            paranoid_free(do_not_compress_these);
     1253            paranoid_free(tmp);
    13891254            return (TRUE);
    13901255        }
     1256        paranoid_free(tmp);
     1257
    13911258        if (!(p = strchr(p, ' '))) {
    13921259            break;
    13931260        }
    13941261    }
     1262    paranoid_free(do_not_compress_these);
    13951263    return (FALSE);
    13961264}
    1397 
    13981265
    13991266
     
    14111278
    14121279
    1413 
    1414 
    14151280/**
    14161281 * Create a small script that mounts /boot, calls @c grub-install, and syncs the disks.
     
    14241289    int retval = 0;
    14251290
    1426     malloc_string(tmp);
    14271291    if ((fout = fopen(outfile, "w"))) {
    14281292        fprintf(fout,
     
    14301294        paranoid_fclose(fout);
    14311295        log_msg(2, "Created %s", outfile);
    1432         sprintf(tmp, "chmod +x %s", outfile);
     1296        asprintf(&tmp, "chmod +x %s", outfile);
    14331297        paranoid_system(tmp);
     1298        paranoid_free(tmp);
     1299
    14341300        retval = 0;
    14351301    } else {
    14361302        retval = 1;
    14371303    }
    1438     paranoid_free(tmp);
    14391304    return (retval);
    14401305}
    14411306
    14421307/* @} - end fileGroup */
     1308
     1309void paranoid_alloc(char *alloc, char *orig)
     1310{
     1311        paranoid_free(alloc);
     1312        asprintf(&alloc, orig);
     1313}
     1314
  • trunk/mondo/mondo/common/libmondo-files.h

    r59 r171  
    2020char *last_line_of_file(char *filename);
    2121long long length_of_file(char *filename);
    22 int make_checksum_list_file(char *filelist, char *cksumlist,
    23                             char *comppath);
    2422int make_hole_for_file(char *outfile_fname);
    2523void make_list_of_files_to_ignore(char *ignorefiles_fname,
     
    5149int read_one_liner_data_file(char *fname, char *contents);
    5250int mode_of_file(char *fname);
     51void paranoid_alloc(char *alloc, char *orig);
  • trunk/mondo/mondo/common/libmondo-fork.c

    r147 r171  
    3737    FILE *fin;
    3838
    39     int n = 0;
     39    size_t n = 0;
    4040
    4141    /*@******************************************************************** */
     
    192192    int res;
    193193    int i;
    194     int n = 0;
     194    size_t n = 0;
    195195    int len;
    196196    bool log_if_failure = FALSE;
  • trunk/mondo/mondo/common/libmondo-mountlist.c

    r146 r171  
    569569    assert(flaws_str_C != NULL);
    570570
    571     asprintf(&flaws_str, "");
     571    asprintf(&flaws_str, " ");
    572572
    573573    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    583583            log_it(tmp);
    584584        } else {
    585             asprintf(&tmp, "");
     585            asprintf(&tmp, " ");
    586586            // BERLIOS : tmp was NOT initialized ???
    587587            if (!evaluate_drive_within_mountlist
  • trunk/mondo/mondo/common/libmondo-stream.c

    r147 r171  
    607607                                bkpinfo->internal_tape_block_size);
    608608
    609 //  start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
    610609    log_it("Opening IN tape");
    611610    if (!
  • trunk/mondo/mondo/common/libmondo-string.c

    r122 r171  
    106106}
    107107
     108/* sout is allocated here and must be freed by the caller */
    108109
    109110inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
    110111{
    111     char *p, *q;
    112 
    113     for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {
     112    char *p;
     113    char *q = NULL;
     114    char *sav;
     115    char r;
     116    bool end = FALSE;
     117
     118    asprintf(&sav, sin);
     119    p = sav;
     120    while ((*p != '\0') && (! end)) {
    114121        if (strchr("[]*?", *p)) {
    115             *(q++) = '\\';
     122            r = *p;                 // keep the wildcard char
     123            *p = '\0';              // trunc the final string
     124            p++;                    // continue on sav
     125                                    // build the new string by recursion
     126            turn_wildcard_chars_into_literal_chars(q,p);
     127            asprintf(&sout, "%s\\%c%s", sav, r, q);
     128            paranoid_free(q);
     129            paranoid_free(sav);
     130            end = TRUE;
    116131        }
    117     }
    118     *q = *p;                    // for the final '\0'
     132        p++;
     133    }
     134    if (!end) {
     135        sout = sav;
     136    }
    119137}
    120138
     
    345363        break;
    346364    default:
    347         asprintf(&outstr, "%s", "BLK_UNKNOWN (%d)", marker);
     365        asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker);
    348366        break;
    349367    }
     
    530548        asprintf(&suffix, ".%s", s);
    531549    } else {
    532         asprintf(&suffix, "%s", "");
     550        asprintf(&suffix, "%s", " ");
    533551    }
    534552    asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno,
  • trunk/mondo/mondo/common/libmondo-tools-EXT.h

    r94 r171  
    3737extern void mount_boot_if_necessary(void);
    3838extern void unmount_boot_if_necessary(void);
    39 extern void restart_autofs_if_necessary(void);
    4039extern void malloc_libmondo_global_strings(void);
    4140extern void free_libmondo_global_strings(void);
     
    4948extern void stop_magicdev_if_necessary(void);
    5049extern void restart_magicdev_if_necessary(void);
    51 extern void stop_autofs_if_necessary(void);
    52 extern void restart_autofs_if_necessary(void);
  • trunk/mondo/mondo/common/libmondo-tools.c

    r166 r171  
    605605        log_it("isomnt: %s, %d", tmp, strlen(tmp));
    606606        if (strlen(bkpinfo->isodir) < strlen(tmp)) {
    607             asprintf(&iso_path, "");
     607            asprintf(&iso_path, " ");
    608608        } else {
    609609            asprintf(&iso_path, "%s", bkpinfo->isodir + strlen(tmp));
     
    734734    bkpinfo->manual_cd_tray = FALSE;
    735735    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    736     bkpinfo->media_device[0] = '\0';
     736    paranoid_free(bkpinfo->media_device);
    737737    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    738738        bkpinfo->media_size[i] = -1;
     
    10981098
    10991099/**
    1100  * Whether we had to stop autofs (if so, restart it at end).
    1101  */
    1102 bool g_autofs_stopped = FALSE;
    1103 
    1104 /**
    1105  * Path to the autofs initscript ("" if none exists).
    1106  */
    1107 char g_autofs_exe[MAX_STR_LEN];
    1108 
    1109 /**
    1110  * Autofs initscript in Xandros Linux distribution.
    1111  */
    1112 #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"
    1113 
    1114 /**
    1115  * Autofs initscript in most Linux distributions.
    1116  */
    1117 #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"
    1118 
    1119 /**
    1120  * If autofs is mounted, stop it (restart at end).
    1121  */
    1122 void stop_autofs_if_necessary()
    1123 {
    1124     char *tmp;
    1125 
    1126     g_autofs_exe[0] = '\0';
    1127     if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
    1128         strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
    1129     } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
    1130         strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
    1131     }
    1132 
    1133     if (!g_autofs_exe[0]) {
    1134         log_msg(3, "No autofs detected.");
    1135     } else {
    1136         log_msg(3, "%s --- autofs detected", g_autofs_exe);
    1137 // FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1138         asprintf(&tmp, "%s stop", g_autofs_exe);
    1139         if (run_program_and_log_output(tmp, 2)) {
    1140             log_it("Failed to stop autofs - I assume it wasn't running");
    1141         } else {
    1142             g_autofs_stopped = TRUE;
    1143             log_it("Stopped autofs OK");
    1144         }
    1145         paranoid_free(tmp);
    1146     }
    1147 }
    1148 
    1149 /**
    1150  * If autofs was stopped earlier, restart it.
    1151  */
    1152 void restart_autofs_if_necessary()
    1153 {
    1154     char *tmp;
    1155 
    1156     if (!g_autofs_stopped || !g_autofs_exe[0]) {
    1157         log_msg(3, "No autofs detected.");
    1158         return;
    1159     }
    1160     asprintf(&tmp, "%s start", g_autofs_exe);
    1161     if (run_program_and_log_output(tmp, 2)) {
    1162         log_it("Failed to start autofs");
    1163     } else {
    1164         g_autofs_stopped = FALSE;
    1165         log_it("Started autofs OK");
    1166     }
    1167     paranoid_free(tmp);
    1168 }
    1169 
    1170 
    1171 /**
    11721100 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    11731101 */
     
    12141142                if (run_program_and_log_output(tmp1, 5)) {
    12151143                    paranoid_free(g_boot_mountpt);
    1216                     asprintf(&g_boot_mountpt, "");
     1144                    asprintf(&g_boot_mountpt, " ");
    12171145                    log_msg(1, "Plan B");
    12181146                    if (!run_program_and_log_output("mount /boot", 5)) {
  • trunk/mondo/mondo/common/libmondo-tools.h

    r94 r171  
    4242void unmount_boot_if_necessary(void);
    4343
    44 void restart_autofs_if_necessary(void);
    4544void malloc_libmondo_global_strings(void);
    4645void free_libmondo_global_strings(void);
     
    5150void stop_magicdev_if_necessary(void);
    5251void restart_magicdev_if_necessary(void);
    53 void stop_autofs_if_necessary(void);
    54 void restart_autofs_if_necessary(void);
  • trunk/mondo/mondo/common/libmondo-verify.c

    r127 r171  
    243243        }
    244244    } else {
    245         asprintf(&sz_exe, "");
     245        asprintf(&sz_exe, " ");
    246246    }
    247247
     
    662662
    663663    if (biggie_cksum[0] != '\0') {
    664         asprintf(&orig_cksum, calc_checksum_of_file(biggie_fname));
     664        orig_cksum = calc_checksum_of_file(biggie_fname);
    665665        if (strcmp(biggie_cksum, orig_cksum)) {
    666666            asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
  • trunk/mondo/mondo/common/libmondo-verify.h

    r59 r171  
    2828extern void fatal_error(char *);
    2929extern int find_and_mount_actual_cd(struct s_bkpinfo *, char *);
    30 extern int find_cdrom_device(char *, bool);
     30extern char *find_cdrom_device(bool);
    3131extern void finish(int);
    3232extern int get_last_filelist_number(struct s_bkpinfo *);
  • trunk/mondo/mondo/common/mondostructures.h

    r122 r171  
    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.
     
    310293   * If backup_media_type is anything else, this should be blank.
    311294   */
    312     char media_device[MAX_STR_LEN / 4];
     295    char *media_device;
    313296
    314297  /**
     
    340323   * to take truncate_to_drive_name() of where_is_root_mounted().
    341324   */
    342     char boot_device[MAX_STR_LEN / 4];
     325    char *boot_device;
    343326
    344327  /**
     
    368351   * This is a useful feature, but use at your own risk.
    369352   */
    370     char image_devs[MAX_STR_LEN / 4];
     353    char *image_devs;
    371354
    372355  /**
     
    428411   * If backup_media_type is anything else, this is ignored.
    429412   */
    430     char isodir[MAX_STR_LEN / 4];
     413    char *isodir;
    431414
    432415/**
     
    435418   * If backup_media_type is anything else, this is ignored.
    436419   */
    437     char prefix[MAX_STR_LEN / 4];
     420    char *prefix;
    438421
    439422  /**
     
    442425   * As such, it needs to be at least as large as the largest CD/DVD/ISO.
    443426   */
    444     char scratchdir[MAX_STR_LEN / 4];
     427    char *scratchdir;
    445428
    446429  /**
     
    450433   * of space here.
    451434   */
    452     char tmpdir[MAX_STR_LEN / 4];
     435    char *tmpdir;
    453436
    454437  /**
     
    496479   * A command to call BEFORE making an ISO image.
    497480   */
    498     char call_before_iso[MAX_STR_LEN];
     481    char *call_before_iso;
    499482
    500483  /**
     
    511494   * A command to call AFTER making an ISO image.
    512495   */
    513     char call_after_iso[MAX_STR_LEN];
     496    char *call_after_iso;
    514497
    515498  /**
     
    517500   * included with Mindi.
    518501   */
    519     char kernel_path[MAX_STR_LEN];
     502    char *kernel_path;
    520503
    521504  /**
     
    525508   * address form. (Domain names will be resolved in post_param_configuration().)
    526509   */
    527     char nfs_mount[MAX_STR_LEN];
     510    char *nfs_mount;
    528511
    529512  /**
     
    531514   * the backups in.
    532515   */
    533     char nfs_remote_dir[MAX_STR_LEN];
     516    char *nfs_remote_dir;
    534517
    535518  /**
     
    537520   * after nuking the system. If "", do not use a post-nuke tarball.
    538521   */
    539     char postnuke_tarball[MAX_STR_LEN];
     522    char *postnuke_tarball;
    540523
    541524  /**
  • trunk/mondo/mondo/common/my-stuff.h

    r160 r171  
    11/* $Id$ */
    22
    3 #define AUX_VER "2.05_berlios"
     3#define AUX_VER "2.11"
    44#define HAVE_MALLOC 1
    55
     
    1919/* Required for the use of getline, ... */
    2020#define __USE_GNU
     21#define _GNU_SOURCE
    2122
    2223#include <stdio.h>
     
    289290 * Free @p x and set it to NULL.
    290291 */
    291 #define paranoid_free(x) {if (x != NULL) free(x); x=NULL;}
     292#define paranoid_free(x) {if ((x) != NULL) free(x); (x)=NULL;}
    292293
    293294/**
  • trunk/mondo/mondo/common/newt-specific.c

    r146 r171  
    707707        char *blurb;
    708708        char *original_contents;
    709         int n = 0;
     709        size_t n = 0;
    710710
    711711        assert_string_is_neither_NULL_nor_zerolength(title);
     
    791791                printf("%s (%s or %s) --> ", p, button1, button2);
    792792            }
    793             for (asprintf(&tmp, "");
     793            for (asprintf(&tmp, " ");
    794794                 strcmp(tmp, button1) && (strlen(button2) == 0
    795795                                          || strcmp(tmp, button2));) {
Note: See TracChangeset for help on using the changeset viewer.