Changeset 171 in MondoRescue


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
Files:
27 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));) {
  • trunk/mondo/mondo/mondoarchive/main.c

    r170 r171  
    1 /***************************************************************************
    2                           main.c  -  description
    3                              -------------------
    4     begin                : Fri Apr 19 16:40:35 EDT 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    10 /***************************************************************************
     1/*
     2 * $Id$
    113 *                                                                         *
    124 *   This program is free software; you can redistribute it and/or modify  *
     
    157 *   (at your option) any later version.                                   *
    168 *                                                                         *
    17  ***************************************************************************/
    18 
    19 /** change log ****** MONDO-DEVEL
    20 
    21 
    22 12/10
    23 - disable stopping/starting of autofs
    24 
    25 10/01
    26 - update g_erase_tmpdir_and_scratchdir to delete user-specified tmpdir, scratchdir
    27 
    28 06/19
    29 - added AUX_VER
    30 
    31 06/14/2004
    32 - use mondorescue.iso, not mindi.iso
    33 
    34 02/10/2004
    35 - tell users where BusyBox's sources are
    36 
    37 11/14/2003
    38 - cleaned up logging at end#
    39 
    40 10/23
    41 - don't try to test-read tape ... That's already
    42   handled by post_param_configuration()
    43  
    44 10/19
    45 - if your PATH var is too long, abort
    46 
    47 09/23
    48 - added some comments
    49 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
    50   and free_libmondo_global_strings() - which are in libmondo-tools.c
    51 - better magicdev support
    52 
    53 
    54 09/16
    55 - delete /var/log/partimagehack-debug.log at start of main()
    56 
    57 09/15
    58 - added askbootloader
    59 
    60 09/09
    61 - if your tape is weird, I'll pause between backup and verify
    62 - fixed silly bug in main() - re: say_at_end
    63 
    64 01/01 - 08/31
    65 - call 'dmesg -n1' at start, to shut the kernel logger up
    66 - moved g_erase_tmpdir_and_scratchdir to common/newt-specific.c
    67 - added 'don't panic' msg to start of logfile
    68 - added 'nice(20)' to main()
    69 - added lots of assert()'s and log_OS_error()'s
    70 - clean-up (Hugo)
    71 - make post_param_configuration() setup g_erase_tmpdir_and_scratchdir
    72 - if --version then print & exit quickly
    73 - re-run g_erase_tmpdir_and_scratchdir via system() at very end
    74 
    75 Year: 2002
    76 - if user goes root with 'su' instead of 'su -' then
    77   workaround it by setting PATH correctly
    78 - wipe mondoarchive.log at very beginning
    79 - cleaned up code
    80 - if changed.files.N exists then copy to changes.files for display
    81 - run_program_and_log_output() now takes boolean operator to specify
    82   whether it will log its activities in the event of _success_
    83 - added popup list of changed files
    84 - removed 'beta-quality' warnings
    85 - if kernel not found and mondo in graphics mode then popup and ask
    86   for kernel path+filename
    87 - fixed tmp[] 'too small' bug
    88 - unmount and eject CD at end of verify cycle
    89 - moved interactively_obtain...() to libmondo-stream.c
    90 - wrote stuff to autodetect tape+cdrw+etc.
    91 - renamed from main.c to mondo-archive.c
    92 - fore+after warnings that this code is beta-quality
    93 - abort if running from ramdisk
    94 - remount floppy at end & unmount at start if Mandrake
    95 - took out #debug stuff
    96 - add 2> /dev/null to 'find' command
    97 - add support for bkpinfo->nonbootable_backup
    98 - add main function begin comment and debug conditional
    99   compilation - Stan Benoit
    100 - add debug statements to build a run tree. Stan Benoit
    101 **** end change log **********/
    102 
    103 
    104 /**
    105  * @file
     9 ***************************************************************************
    10610 * The main file for mondoarchive.
    10711 */
     
    11115#include <pthread.h>
    11216#endif
    113 //#include <config.h>
    114 //#include "../../config.h"
    11517#include <stdio.h>
    11618#include <stdlib.h>
     
    14143extern char *g_tmpfs_mountpt;
    14244extern char *g_erase_tmpdir_and_scratchdir;
    143 extern char *g_cdrw_drive_is_here;
    144 static char *g_cdrom_drive_is_here = NULL;
    145 static char *g_dvd_drive_is_here = NULL;
    14645extern double g_kernel_version;
    14746
     
    211110        ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
    212111    unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
    213     //  stop_autofs_if_necessary(); // for Xandros users
    214112    mount_boot_if_necessary();  // for Gentoo users with non-mounted /boot partitions
    215113    clean_up_KDE_desktop_if_necessary();    // delete various misc ~/.* files that get in the way
    216114}
    217 
    218115
    219116
     
    223120void distro_specific_kludges_at_end_of_mondoarchive()
    224121{
    225 //  char tmp[500];
    226122    log_msg(2, "Restarting magicdev if necessary");
    227123    sync();
    228124    restart_magicdev_if_necessary();    // for RH+Gnome users
    229125
    230     log_msg(2, "Restarting autofs if necessary");
    231     sync();
    232     //  restart_autofs_if_necessary(); // for Xandros users
    233 
    234126    log_msg(2, "Restarting supermounts if necessary");
    235127    sync();
     
    239131    sync();
    240132    unmount_boot_if_necessary();    // for Gentoo users
    241 
    242 //  log_msg( 2, "Cleaning up KDE desktop");
    243 //  clean_up_KDE_desktop_if_necessary();
    244133}
    245 
    246 
    247 /*-----------------------------------------------------------*/
    248 
    249134
    250135
     
    257142    struct s_bkpinfo *bkpinfo;
    258143    char *tmp;
    259     int res, retval;
    260     char *say_at_end;
     144    int res = 0;
     145    int retval = 0;
     146    char *say_at_end = NULL;
    261147
    262148/* Make sure I'm root; abort if not */
     
    277163
    278164    malloc_libmondo_global_strings();
    279     malloc_string(tmp);
    280     malloc_string(say_at_end);
    281 
    282     res = 0;
    283     retval = 0;
     165
    284166    diffs = 0;
    285     say_at_end[0] = '\0';
    286167    unlink("/var/log/partimagehack-debug.log");
    287168    printf("Initializing...\n");
     
    292173
    293174/* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    294     strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
    295     tmp[MAX_STR_LEN - 1] = '\0';
    296     if (strlen(tmp) >= MAX_STR_LEN - 33) {
    297         fatal_error
    298             ("Your PATH environmental variable is too long. Please shorten it.");
    299     }
    300     strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
     175    asprintf(&tmp, "/sbin:/usr/sbin:%s:/usr/local/sbin", getenv("PATH"));
    301176    setenv("PATH", tmp, 1);
     177    paranoid_free(tmp);
    302178
    303179/* Add the ARCH environment variable for ia64 purposes */
    304     strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
    305     tmp[MAX_STR_LEN - 1] = '\0';
    306     setenv("ARCH", tmp, 1);
     180    setenv("ARCH", get_architecture(), 1);
    307181
    308182    unlink(MONDO_LOGFILE);
     
    339213    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
    340214        g_loglevel = 10;
    341 //      chdir("/tmp");
    342215        g_text_mode = TRUE;
    343216        setup_newt_stuff();
     
    351224        turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    352225        printf("in=%s; out=%s\n", argv[2], tmp);
     226        paranoid_free(tmp);
    353227        finish(1);
    354228    }
     
    368242    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
    369243        g_loglevel = 10;
    370 //      chdir("/tmp");
    371244        g_text_mode = TRUE;
    372245        setup_newt_stuff();
     
    378251        g_text_mode = TRUE;
    379252        setup_newt_stuff();
    380         if (find_cdrw_device(tmp)) {
     253        if ((tmp = find_cdrw_device()) == NULL) {
    381254            printf("Failed to find CDR-RW drive\n");
    382255        } else {
    383256            printf("CD-RW is at %s\n", tmp);
    384257        }
    385         tmp[0] = '\0';
    386         if (find_cdrom_device(tmp, atoi(argv[2]))) {
     258        paranoid_free(tmp);
     259
     260        if ((tmp = find_cdrom_device(FALSE)) == NULL) {
    387261            printf("Failed to find CD-ROM drive\n");
    388262        } else {
    389263            printf("CD-ROM is at %s\n", tmp);
    390264        }
     265        paranoid_free(tmp);
    391266        finish(0);
    392267    }
     
    396271        g_text_mode = TRUE;
    397272        setup_newt_stuff();
    398         if (find_dvd_device(tmp, atoi(argv[2]))) {
     273        if ((tmp = find_dvd_device()) == NULL) {
    399274            printf("Failed to find DVD drive\n");
    400275        } else {
    401276            printf("DVD is at %s\n", tmp);
    402277        }
     278        paranoid_free(tmp);
    403279        finish(0);
    404280    }
     
    451327    log_to_screen
    452328        ("BusyBox's sources are available from http://www.busybox.net");
    453     sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
    454             bkpinfo->scratchdir);
    455329
    456330    /* If we're meant to backup then backup */
    457331    if (bkpinfo->backup_data) {
    458 /*
    459       log_to_screen("INFERNAL PORPOISES");
    460       res = archive_this_fileset_with_star(bkpinfo, "/tmp/filelist.0", "/tmp/0.star.bz2", 0);
    461       log_to_screen("atfws returned %d", res);
    462       finish(0);
    463 */
    464332        res = backup_data(bkpinfo);
    465333        retval += res;
    466334        if (res) {
    467             strcat(say_at_end,
     335            asprintf(&say_at_end,
    468336                   "Data archived. Please check the logs, just as a precaution. ");
    469337        } else {
    470             strcat(say_at_end, "Data archived OK. ");
     338            asprintf(&say_at_end, "Data archived OK. ");
    471339        }
    472340    }
     
    476344        res = verify_data(bkpinfo);
    477345        if (res < 0) {
    478             sprintf(tmp, "%d difference%c found.", -res,
     346            asprintf(&say_at_end, "%d difference%c found.", -res,
    479347                    (-res != 1) ? 's' : ' ');
    480             strcat(say_at_end, tmp);
    481             log_to_screen(tmp);
    482348            res = 0;
    483349        }
     
    485351    }
    486352
    487 /* Offer to write floppy disk images to physical disks */
     353    /* Offer to write floppy disk images to physical disks */
    488354    if (bkpinfo->backup_data && !g_skip_floppies) {
    489355        res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
    490356        retval += res;
    491 //      res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
    492 //      retval += res;
    493     }
    494 
    495 /* Report result of entire operation (success? errors?) */
    496     if (!retval) {
     357    }
     358
     359    /* Report result of entire operation (success? errors?) */
     360    if (retval == 0) {
    497361        mvaddstr_and_log_it(g_currentY++, 0,
    498362                            "Backup and/or verify ran to completion. Everything appears to be fine.");
     
    523387    }
    524388    log_to_screen(say_at_end);
    525     sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     389    paranoid_free(say_at_end);
     390
     391    asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    526392    run_program_and_log_output(tmp, TRUE);
     393    paranoid_free(tmp);
     394
     395    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     396            bkpinfo->scratchdir);
    527397    run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
    528398
     
    531401    system("rm -f /var/cache/mondo-archive/last-backup.aborted");
    532402    system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
    533     if (!retval) {
     403    if (retval == 0) {
    534404        printf("Mondoarchive ran OK.\n");
    535405    } else {
     
    542412    system(g_erase_tmpdir_and_scratchdir);
    543413    free_libmondo_global_strings();
    544     paranoid_free(say_at_end);
    545     paranoid_free(tmp);
    546414    paranoid_free(bkpinfo);
    547415
    548416    unlink("/tmp/filelist.full");
    549417    unlink("/tmp/filelist.full.gz");
    550 
    551     if (!g_cdrom_drive_is_here) {
    552         log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
    553     }
    554     if (!g_dvd_drive_is_here) {
    555         log_msg(10, "FYI, g_dvd_drive_is_here was never used");
    556     }
    557418
    558419    run_program_and_log_output("date", 1);
  • trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h

    r59 r171  
    55extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    66extern int process_switches(struct s_bkpinfo *bkpinfo,
    7                             char flag_val[128][MAX_STR_LEN],
     7                            char *flag_val[128],
    88                            bool flag_set[128]);
    99extern int retrieve_switches_from_command_line(int argc, char *argv[],
    1010                                               char
    11                                                flag_val[128][MAX_STR_LEN],
     11                                               *flag_val[128],
    1212                                               bool flag_set[128]);
    1313extern void help_screen();
  • trunk/mondo/mondo/mondoarchive/mondo-cli.c

    r146 r171  
    11/***************************************************************************
    2 mondo-cli.c
    3 -------------------
    4 begin                : Fri Apr 19 16:40:35 EDT 2002
    5 copyright        : (C) 2002 Mondo  Hugo Rabson
    6 email                : Hugo Rabson <hugorabson@msn.com>
    7 edited by            : by Stan Benoit 4/2002
    8 email                : troff@nakedsoul.org
    9 cvsid                : $Id$
    10  ***************************************************************************/
    11 
    12 /***************************************************************************
    13  *                                                                         *
    14  *   This program is free software; you can redistribute it and/or modify  *
    15  *   it under the terms of the GNU General Public License as published by  *
    16  *   the Free Software Foundation; either version 2 of the License, or     *
    17  *   (at your option) any later version.                                   *
    18  *                                                                         *
    19  ***************************************************************************/
    20 
    21 /***************************************************************************
    22 UPDATE LOG
    23 
    24 
    25 08/04
    26 - if user specifies a dumb -T value, abort
    27 
    28 07/22
    29 - handle -Q sensibly (don't abort if only -Q supplied)
    30 
    31 07/17
    32 - better checking of NFS dir's validity
    33 
    34 06/19
    35 - added AUX_VER
    36 
    37 04/17
    38 - added '-b' support
    39 04/03
    40 - added star support
    41 
    42 02/06
    43 - fixed "Please give /dev entry" error msg
    44 
    45 01/20/2004
    46 - added 2.6.x-kernel "device = /dev/...." support to param reader
    47 - better handling of SCSI and /dev entries
    48 - touch /boot/boot.b if necessary
    49 
    50 09/26/2003
    51 - typo in command-line handling of 'r'
    52 
    53 09/25
    54 - added DVD write support
    55 
    56 09/24
    57 - if tape backup (-t) but user doesn't specify tape drive then
    58   make an educated guess using find_tape_device_and_size()
    59 
    60 09/18
    61 - insist on partimagehack being present if -x found
    62 
    63 09/16
    64 - added support for multiple -I's and -E's in call to mondoarchive
    65 - the '-D' flag doesn't take a value now
    66 
    67 07/14
    68 - fatal error if -E too short
    69 
    70 05/14
    71 - if 'n' and user doesn't have rights to write to output dir
    72   then error out
    73 
    74 05/05
    75 - added Joshua Oreman's FreeBSD patches
    76 
    77 05/04
    78 - added Herman Kuster's multi-level bkp patch
    79 
    80 05/02
    81 - write errors to screen, not just to log
    82 
    83 04/25
    84 - added lots of assert()'s and log_OS_error()'s
    85 
    86 04/21
    87 - line 570 --- resolve boot device if softlink
    88 
    89 04/08
    90 - changed a bunch of fprintf(stderr,...)'s to log_it()'s
    91 - fixed final / removal in retrieve_switches_from_command_line()
    92 
    93 04/04
    94 - added -e
    95 
    96 03/15
    97 - reject relative paths if -d flag (Alessandro Polverini)
    98 
    99 01/02/2003
    100 - added -J flag (to let user specify incoming filelist)
    101 
    102 12/13/2002
    103 - various strcpy() calls replaced with strncpy() calls
    104 
    105 12/10
    106 - added g_loglevel
    107 
    108 11/25
    109 - line 614 --- if commmand-line param ends in '/' then drop that '/'
    110 
    111 11/19
    112 - rewrote finish() to kill processes more softly
    113 - if user calls with '-l RAW' then
    114 
    115 09/01 - 09/30
    116 - added -N to let user exclude all NFS-related mounts and devices
    117 - run_program_and_log_output() now takes boolean operator to specify
    118   whether it will log its activities in the event of _success_
    119 
    120 08/01 - 08/31
    121 - if no device specified when backing up to tape streamer then assume /dev/st0
    122 - abort if tape user specifies tape size (just for testing porpoises)
    123 - tape users no longer need to specify tape size
    124 - added some comments
    125 - added bkpinfo->backup_media_type
    126 - renamed from mondo-archive.c to mondo-cli.c
    127 
    128 07/01 - 07/31
    129 - better check for mkfs.vfat
    130 - more sanity-checking for -d flag
    131 - if isodir does not exist then abort
    132 - removed "the rest are..." comment from log
    133 - do not permit '-H' and '-t' in the same command line
    134 - if not '-o' then insist on vfat-friendly kernel
    135 
    136 06/01 - 06/30
    137 - added signal-trapping
    138 - added '-W' (won't make bootable CD or floppies) flag
    139 - added missing 'j++' to -s switch's code
    140 - expanded -s switch
    141 - added -u switch
    142 - if dvdrecord exists and cdrecord doesn't then use
    143   dvdrecord instead of cdrecord
    144 
    145 04/01 - 04/30
    146 - if CD-ROM is supermounted then unmount, run, and remount
    147 - replace MONDO_VERSION #define with VERSION from ../config.h
    148 - if CD-ROM is mounted at start then abort
    149 - improved homedir-locating code
    150 - improved "backup will occupy N CD's" calculation a bit
    151 - added -m (manual CD tray) flag
    152 
    153 
    154 *******************************************************************/
    155 
    156 /**
    157  * @file
     2 * $Id$
     3 *
    1584 * Functions for handling command-line arguments passed to mondoarchive.
    1595 */
     
    18026extern bool g_skip_floppies;    ///< Whether to skip the creation of boot disks
    18127extern char g_startdir[MAX_STR_LEN];    ///< ????? @bug ?????
    182 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];
    18328extern char g_tmpfs_mountpt[MAX_STR_LEN];
    18429extern bool g_sigpipe;
     
    24590    /*@ buffers *************** */
    24691    char *tmp;
    247     char flag_val[128][MAX_STR_LEN];
     92    char *flag_val[128];
    24893    bool flag_set[128];
    24994
    250     malloc_string(tmp);
    25195    sensibly_set_tmpdir_and_scratchdir(bkpinfo);
     96
    25297    for (i = 0; i < 128; i++) {
    253         flag_val[i][0] = '\0';
     98        flag_val[i] = NULL;
    25499        flag_set[i] = FALSE;
    255100    }
    256     //  strcpy (bkpinfo->tmpdir, "/root/images/mondo");
    257     //  strcpy (bkpinfo->scratchdir, "/home");
    258101    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    259102        bkpinfo->media_size[j] = 650;
     
    275118    for (i = 0; i < 128; i++) {
    276119        if (flag_set[i]) {
    277             sprintf(tmp, "-%c %s", i, flag_val[i]);
     120            asprintf(&tmp, "-%c %s", i, flag_val[i]);
    278121            log_msg(3, tmp);
     122            paranoid_free(tmp);
    279123        }
    280124    }
    281125//    }
    282     sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
     126    asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
    283127    paranoid_system(tmp);
    284     sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
     128    paranoid_free(tmp);
     129
     130    asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
    285131    paranoid_system(tmp);
     132    paranoid_free(tmp);
     133
    286134    sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld",
    287135            random() % 32767);
    288136    sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
    289137            "/mondo.scratch.%ld", random() % 32767);
    290     sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     138
     139    asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    291140    paranoid_system(tmp);
    292     sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
     141    paranoid_free(tmp);
     142
     143    asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
    293144    paranoid_system(tmp);
     145    paranoid_free(tmp);
     146
    294147    if (bkpinfo->nfs_mount[0] != '\0') {
    295148        store_nfs_config(bkpinfo);
    296149    }
    297     paranoid_free(tmp);
    298150    return (retval);
    299151}
    300 
    301 
    302152
    303153
     
    312162{
    313163    int j;
    314     char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
     164    char *tmp;
     165    char *p;
     166    char *q;
     167    char *comment;
    315168
    316169    assert(bkpinfo != NULL);
     
    320173    for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
    321174         j++, p = strchr(p, ',') + 1) {
    322         strncpy(tmp, p, MAX_STR_LEN);
    323         *(strchr(tmp, ',')) = '\0';
     175        asprintf(&tmp, p);
     176        q = strchr(tmp, ',');
     177        if (q != NULL) {
     178            *q = '\0';
     179        }
    324180        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
    325         sprintf(comment, "media_size[%d] = %ld", j,
     181        paranoid_free(tmp);
     182
     183        asprintf(&comment, "media_size[%d] = %ld", j,
    326184                bkpinfo->media_size[j]);
    327185        log_msg(3, comment);
     186        paranoid_free(comment);
    328187    }
    329188    for (; j <= MAX_NOOF_MEDIA; j++) {
    330189        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
    331190    }
    332 //      bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
    333191    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    334192        if (bkpinfo->media_size[j] <= 0) {
     
    339197    return (0);
    340198}
    341 
    342199
    343200
     
    354211int
    355212process_switches(struct s_bkpinfo *bkpinfo,
    356                  char flag_val[128][MAX_STR_LEN], bool flag_set[128])
     213                 char *flag_val[128], bool flag_set[128])
    357214{
    358215
     
    364221    /*@ buffers ** */
    365222    char *tmp;
     223    char *tmp2;
    366224    char *psz;
    367225
     
    374232    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    375233
    376 /* compulsory */
     234    /* compulsory */
    377235    i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
    378236        flag_set['t'] + flag_set['u'] + flag_set['r'] +
     
    502360                    ("You must use -L with -C. Therefore I am setting it for you.");
    503361                flag_set['L'] = 1;
    504                 flag_val['L'][0] = '\0';
     362                flag_val['L'] = NULL;
    505363            }
    506364        } else {
    507365            log_msg(3, "flag_val['c'] = %s", flag_val['c']);
    508366            log_msg(3, "flag_val['w'] = %s", flag_val['w']);
    509 //    log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
    510367            if (flag_set['c']) {
    511368                bkpinfo->cdrw_speed = atoi(flag_val['c']);
     
    546403        }
    547404        if (!flag_set['d']) {
    548             if (!find_dvd_device(flag_val['d'], FALSE)) {
     405            if ((flag_val['d'] = find_dvd_device()) != NULL) {
    549406                flag_set['d'] = TRUE;
    550407                log_to_screen("I guess DVD drive is at %s", flag_val['d']);
     
    564421        }
    565422        if (!flag_set['s']) {
    566             sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE);    // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    567             strcat(flag_val['s'], "m");
     423            asprintf(&flag_val['s'], "%dm", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    568424            log_to_screen
    569425                ("You did not specify a size (-s) for DVD. I'm guessing %s.",
     
    571427            flag_set['s'] = 1;
    572428        }
    573 /*
    574       if (flag_set['Z']) {
    575       bkpinfo->blank_dvd_first = TRUE;
    576       }
    577 */
    578429    }
    579430
     
    612463    }
    613464    if (flag_set['n']) {
    614         strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
     465        asprintf(&tmp, flag_val['n']);
     466        bkpinfo->nfs_mount = tmp;
    615467        if (!flag_set['d']) {
    616             strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
     468            asprintf(&tmp, "/");
     469            bkpinfo->nfs_remote_dir = tmp;
    617470        }
    618471        asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
    619472                bkpinfo->nfs_mount);
    620         strncpy(bkpinfo->isodir,
    621                 call_program_and_get_last_line_of_output(tmp),
    622                 MAX_STR_LEN / 4);
     473        asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp));
     474        bkpinfo->isodir = tmp2;
    623475        paranoid_free(tmp);
    624476
     
    714566    }
    715567    if (flag_set['x']) {
    716         strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
     568        asprintf(&tmp, flag_val['x']);
     569        bkpinfo->image_devs = tmp;
    717570        if (run_program_and_log_output("which partimagehack", 2)) {
    718571            fatal_error("Please install partimagehack RPM/tarball.");
     
    723576    }
    724577    if (flag_set['k']) {
    725         strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
    726         if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
    727             strcpy(bkpinfo->kernel_path, "FAILSAFE");
    728         }
    729         if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
    730             && !does_file_exist(bkpinfo->kernel_path)) {
    731             retval++;
    732             asprintf(&tmp,
     578        if (strcasecmp(flag_val['k'], "FAILSAFE")) {
     579            asprintf(&tmp, "FAILSAFE");
     580            bkpinfo->kernel_path = tmp;
     581
     582            if (!does_file_exist(bkpinfo->kernel_path)) {
     583                retval++;
     584                asprintf(&tmp,
    733585                    "You specified kernel '%s', which does not exist\n",
    734586                    bkpinfo->kernel_path);
    735             log_to_screen(tmp);
    736             paranoid_free(tmp);
     587                log_to_screen(tmp);
     588                paranoid_free(tmp);
     589            }
     590        } else {
     591            asprintf(&tmp, flag_val['k']);
     592            bkpinfo->kernel_path = tmp;
    737593        }
    738594    }
    739595    if (flag_set['p']) {
    740         strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
     596        asprintf(&tmp, bkpinfo->prefix);
     597        bkpinfo->prefix = tmp;
    741598    }
    742599
     
    744601    if (flag_set['d']) {        /* backup directory (if ISO/NFS) */
    745602        if (flag_set['i']) {
    746             strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
     603            asprintf(&tmp, flag_val['d']);
     604            bkpinfo->isodir = tmp;
    747605            asprintf(&tmp, "ls -l %s", bkpinfo->isodir);
    748606            if (run_program_and_log_output(tmp, FALSE)) {
     
    752610            paranoid_free(tmp);
    753611        } else if (flag_set['n']) {
    754             strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
     612            asprintf(&tmp, flag_val['d']);
     613            bkpinfo->nfs_remote_dir = tmp;
    755614        } else {                /* backup device (if tape/CD-R/CD-RW) */
    756615
    757             strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
     616            paranoid_alloc(bkpinfo->media_device, flag_val['d']);
    758617        }
    759618    }
     
    782641                log_to_screen("User opted to cancel.");
    783642            }
    784         } else if (find_cdrw_device(bkpinfo->media_device)) {
     643        } else if ((tmp = find_cdrw_device()) ==  NULL) {
     644            paranoid_free(bkpinfo->media_device);
     645            bkpinfo->media_device = tmp;
    785646            retval++;
    786647            log_to_screen
     
    788649        } else {
    789650            flag_set['d'] = TRUE;
    790             strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
     651            asprintf(&flag_val['d'], bkpinfo->media_device);
    791652        }
    792653    }
     
    805666    }
    806667    if (flag_set['S']) {
    807         sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
     668        asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'],
    808669                random() % 32768);
     670        bkpinfo->scratchdir = tmp;
    809671    }
    810672    if (flag_set['T']) {
    811         sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
     673        asprintf(&tmp, "%s/tmp.mondo.%ld", flag_val['T'],
    812674                random() % 32768);
     675        bkpinfo->tmpdir = tmp;
    813676        asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']);
    814677        if (run_program_and_log_output(tmp, 1)) {
     
    831694    }
    832695    if (flag_set['A']) {
    833         strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
     696        asprintf(&tmp, flag_val['A']);
     697        bkpinfo->call_after_iso = tmp;
    834698    }
    835699    if (flag_set['B']) {
    836         strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
     700        asprintf(&tmp, flag_val['B']);
     701        bkpinfo->call_before_iso = tmp;
    837702    }
    838703    if (flag_set['F']) {
     
    864729    if (flag_set['f']) {
    865730        tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
    866         strncpy(bkpinfo->boot_device, tmp,
    867                 MAX_STR_LEN / 4);
     731        bkpinfo->boot_device = tmp;
    868732    }
    869733    if (flag_set['Q']) {
     
    880744
    881745    if (flag_set['P']) {
    882         strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
     746        asprintf(&tmp, flag_val['P']);
     747        bkpinfo->postnuke_tarball = tmp;
    883748    }
    884749    if (flag_set['L']) {
     
    894759        &&
    895760        !run_program_and_log_output
    896         ("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) {
     761        ("grep -i suse /etc/issue.net | grep 64", TRUE)) {
    897762        bkpinfo->make_cd_use_lilo = TRUE;
    898763        log_to_screen
     
    963828int
    964829retrieve_switches_from_command_line(int argc, char *argv[],
    965                                     char flag_val[128][MAX_STR_LEN],
     830                                    char *flag_val[128],
    966831                                    bool flag_set[128])
    967832{
    968833    /*@ ints ** */
    969834    int opt = 0;
    970     char tmp[MAX_STR_LEN];
     835    char *tmp;
    971836    int i = 0;
    972837    int len;
     
    979844
    980845    for (i = 0; i < 128; i++) {
    981         flag_val[i][0] = '\0';
     846        flag_val[i] = NULL;
    982847        flag_set[i] = FALSE;
    983848    }
     
    992857            if (flag_set[optopt]) {
    993858                bad_switches = TRUE;
    994                 sprintf(tmp, "Switch -%c previously defined as %s\n", opt,
     859                asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
    995860                        flag_val[i]);
    996861                log_to_screen(tmp);
     862                paranoid_free(tmp);
    997863            } else {
    998864                flag_set[opt] = TRUE;
     
    1008874                        if (strchr(flag_val[opt], '/')
    1009875                            && flag_val[opt][0] != '/') {
    1010                             sprintf(tmp,
     876                            asprintf(&tmp,
    1011877                                    "-%c flag --- must be absolute path --- '%s' isn't absolute",
    1012878                                    opt, flag_val[opt]);
    1013879                            log_to_screen(tmp);
     880                            paranoid_free(tmp);
    1014881                            bad_switches = TRUE;
    1015882                        }
    1016883                    }
    1017                     strcpy(flag_val[opt], optarg);
     884                    asprintf(&flag_val[opt], optarg);
    1018885                }
    1019886            }
     
    1022889    for (i = optind; i < argc; i++) {
    1023890        bad_switches = TRUE;
    1024         sprintf(tmp, "Invalid arg -- %s\n", argv[i]);
     891        asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
    1025892        log_to_screen(tmp);
     893        paranoid_free(tmp);
    1026894    }
    1027895    return (bad_switches);
     
    1047915void terminate_daemon(int sig)
    1048916{
    1049     char tmp[64];
    1050     char tmp2[MAX_STR_LEN];
    1051     //  char command[512];
    1052     //  pid_t pid;
     917    char *tmp;
     918    char *tmp2;
    1053919
    1054920    switch (sig) {
    1055921    case SIGINT:
    1056         sprintf(tmp, "SIGINT");
    1057         strcpy(tmp2, "You interrupted me :-)");
     922        asprintf(&tmp, "SIGINT signal received from OS");
     923        asprintf(&tmp2, "You interrupted me :-)");
    1058924        break;
    1059925    case SIGKILL:
    1060         sprintf(tmp, "SIGKILL");
    1061         strcpy(tmp2,
     926        asprintf(&tmp, "SIGKILL signal received from OS");
     927        asprintf(&tmp2,
    1062928               "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
    1063929        break;
    1064930    case SIGTERM:
    1065         sprintf(tmp, "SIGTERM");
    1066         strcpy(tmp2, "Got terminate signal");
     931        asprintf(&tmp, "SIGTERM signal received from OS");
     932        asprintf(&tmp2, "Got terminate signal");
    1067933        break;
    1068934    case SIGHUP:
    1069         sprintf(tmp, "SIGHUP");
    1070         strcpy(tmp2, "Hangup on line");
     935        asprintf(&tmp, "SIGHUP signal received from OS");
     936        asprintf(&tmp2, "Hangup on line");
    1071937        break;
    1072938    case SIGSEGV:
    1073         sprintf(tmp, "SIGSEGV");
    1074         strcpy(tmp2,
     939        asprintf(&tmp, "SIGSEGV signal received from OS");
     940        asprintf(&tmp2,
    1075941               "Internal programming error. Please send a backtrace as well as your log.");
    1076942        break;
    1077943    case SIGPIPE:
    1078         sprintf(tmp, "SIGPIPE");
    1079         strcpy(tmp2, "Pipe was broken");
     944        asprintf(&tmp, "SIGPIPE signal received from OS");
     945        asprintf(&tmp2, "Pipe was broken");
    1080946        break;
    1081947    case SIGABRT:
    1082         sprintf(tmp, "SIGABRT");
    1083         sprintf(tmp2,
     948        asprintf(&tmp, "SIGABRT signal received from OS");
     949        asprintf(&tmp2,
    1084950                "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
    1085951        break;
    1086952    default:
    1087         sprintf(tmp, "(Unknown)");
    1088     }
    1089 
    1090     strcat(tmp, " signal received from OS");
     953        asprintf(&tmp, "(Unknown)");
     954        asprintf(&tmp2, "(Unknown)");
     955    }
     956
    1091957    log_to_screen(tmp);
    1092958    log_to_screen(tmp2);
     959    paranoid_free(tmp);
     960    paranoid_free(tmp2);
    1093961    if (sig == SIGABRT) {
    1094962        sleep(10);
     
    1099967    finish(254);                // just in case
    1100968}
    1101 
    1102 
    1103969
    1104970
     
    1122988    }
    1123989}
    1124 
    1125 
    1126990
    1127991
  • trunk/mondo/mondo/mondoarchive/mondo-cli.h

    r59 r171  
    77int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    88int process_switches(struct s_bkpinfo *bkpinfo,
    9                      char flag_val[128][MAX_STR_LEN], bool flag_set[128]);
     9                     char *flag_val[128], bool flag_set[128]);
    1010int retrieve_switches_from_command_line(int argc, char *argv[],
    11                                         char flag_val[128][MAX_STR_LEN],
     11                                        char *flag_val[128],
    1212                                        bool flag_set[128]);
    1313void help_screen();
  • trunk/mondo/mondo/mondorestore/mondo-restore.c

    r146 r171  
    12921292    }
    12931293    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    1294     log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
    1295     if (!bkpinfo->media_device[0]) {
     1294    if (bkpinfo->media_device == NULL) {
    12961295        log_msg(2, "Warning - failed to find media dev");
     1296    } else {
     1297        log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
    12971298    }
    12981299
     
    13301331    }
    13311332    run_program_and_log_output("umount " MNT_CDROM, FALSE);
    1332     if (!bkpinfo->please_dont_eject) {
     1333    if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device != NULL)) {
    13331334        eject_device(bkpinfo->media_device);
    13341335    }
     
    31003101    unlink(datadisks_fname);
    31013102    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    3102     retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
     3103    retval = load_mountlist(&the_mountlist, g_mountlist_fname);
    31033104
    31043105
  • trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c

    r142 r171  
    684684
    685685  /** needs malloc **/
    686     char *dir, *command;
     686    char *dir, *command, *tmp;
    687687
    688688    assert(bkpinfo != NULL);
     
    700700    if (bkpinfo->disaster_recovery
    701701        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    702         strcpy(bkpinfo->media_device,
     702        asprintf(&tmp,
    703703               last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    704     } else {
    705         find_cdrom_device(bkpinfo->media_device, FALSE);
     704        paranoid_free(bkpinfo->media_device);
     705        bkpinfo->media_device = tmp;
     706    } else {
     707        paranoid_free(bkpinfo->media_device);
     708        bkpinfo->media_device = find_cdrom_device(FALSE);
    706709    }
    707710    res = verify_tape_backups(bkpinfo);
  • trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r149 r171  
    202202   * allocate memory regions. test and set  -sab 16 feb 2003              *
    203203   ************************************************************************/
    204     char *incoming_ptr;
    205     char *question_ptr;
    206 
    207     char incoming[MAX_STR_LEN];
    208     char question[MAX_STR_LEN];
     204    char *incoming;
     205    char *question;
     206
     207    size_t n = 0;
    209208
    210209    assert_string_is_neither_NULL_nor_zerolength(infname);
    211210    assert_string_is_neither_NULL_nor_zerolength(outfname);
    212211
    213     incoming_ptr = malloc(sizeof(incoming));
    214     if (incoming_ptr == NULL) {
    215         fprintf(stderr, "Out of Memory\n");
    216         exit(EXIT_FAILURE);
    217     }
    218 
    219     question_ptr = malloc(sizeof(question));
    220     if (question_ptr == NULL) {
    221         fprintf(stderr, "Out of Memory\n");
    222         exit(EXIT_FAILURE);
    223     }
    224 
    225     memset(incoming_ptr, '\0', sizeof(incoming));
    226     memset(question_ptr, '\0', sizeof(question));
    227 
    228 
    229 
    230212    if (!(fin = fopen(infname, "r"))) {
    231213        fatal_error("Cannot openin infname");
     
    234216        fatal_error("Cannot openin outfname");
    235217    }
    236     for (fgets(incoming_ptr, MAX_STR_LEN, fin);
    237          !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    238         strip_spaces(incoming_ptr);
     218    for (getline(&incoming, &n, fin);
     219         !feof(fin); getline(&incoming, &n, fin)) {
     220        strip_spaces(incoming);
    239221
    240222        if (incoming[0] == '\0') {
     
    242224        }
    243225
    244         sprintf(question_ptr,
    245                 "Should I restore the image of %s ?", incoming_ptr);
    246 
    247         if (ask_me_yes_or_no(question_ptr)) {
    248             fprintf(fout, "%s\n", incoming_ptr);
     226        asprintf(&question,
     227                "Should I restore the image of %s ?", incoming);
     228
     229        if (ask_me_yes_or_no(question)) {
     230            fprintf(fout, "%s\n", incoming);
    249231        }
    250232    }
    251233
    252234  /*** free memory ***********/
    253     paranoid_free(incoming_ptr);
    254     incoming_ptr = NULL;
    255     paranoid_free(question_ptr);
    256     question_ptr = NULL;
     235    paranoid_free(incoming);
     236    paranoid_free(question);
    257237
    258238
     
    705685int mount_cdrom(struct s_bkpinfo *bkpinfo)
    706686{
    707     char *mount_cmd;
     687    char *mount_cmd, *tmp;
    708688    int i, res;
    709689#ifdef __FreeBSD__
     
    773753        if (bkpinfo->disaster_recovery
    774754            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    775             strcpy(bkpinfo->media_device,
     755            paranoid_free(bkpinfo->media_device);
     756            asprintf(&tmp,
    776757                   last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     758            bkpinfo->media_device = tmp;
    777759        } else {
    778             find_cdrom_device(bkpinfo->media_device, TRUE);
     760            paranoid_free(bkpinfo->media_device);
     761            bkpinfo->media_device = find_cdrom_device(TRUE);
    779762        }
    780763
     
    10611044    if (bkpinfo->disaster_recovery) {
    10621045        if (bkpinfo->backup_media_type == cdstream) {
    1063             sprintf(bkpinfo->media_device, "/dev/cdrom");
    1064 //          bkpinfo->media_size[0] = -1;
     1046            paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    10651047            bkpinfo->media_size[0] = 1999 * 1024;
    10661048            bkpinfo->media_size[1] = 650;   /* good guess */
    10671049        } else if (bkpinfo->backup_media_type == tape
    10681050                   || bkpinfo->backup_media_type == udev) {
    1069             if (read_cfg_var(cfg_file, "media-dev", value)) {
     1051            if (read_cfg_var(cfg_file, "media-dev", bkpinfo->media_device)) {
    10701052                fatal_error("Cannot get tape device name from cfg file");
    10711053            }
    1072             strcpy(bkpinfo->media_device, value);
    10731054            read_cfg_var(cfg_file, "media-size", value);
    10741055            bkpinfo->media_size[1] = atol(value);
     
    10771058            log_msg(2, tmp);
    10781059        } else {
    1079             strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     1060            paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    10801061            bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
    10811062            bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     
    12001181                            "Unable to mount isodir. Perhaps this is really a CD backup?");
    12011182                    bkpinfo->backup_media_type = cdr;
    1202                     strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
     1183                    paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    12031184                    bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    12041185                    if (mount_cdrom(bkpinfo)) {
     
    23872368    char *mounted_cfgf_path;
    23882369    char *tmp;
     2370    char *sav;
    23892371    char *mountpt;
    23902372    char *ramdisk_fname;
     
    24912473
    24922474            if (strlen(bkpinfo->media_device) == 0) {
    2493                 strcpy(bkpinfo->media_device, "/dev/st0");
    2494                 log_msg(2, "media_device is blank; assuming %s");
    2495             }
    2496             strcpy(tmp, bkpinfo->media_device);
     2475                paranoid_alloc(bkpinfo->media_device, "/dev/st0");
     2476                log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
     2477            }
     2478            asprintf(&sav,bkpinfo->media_device);
    24972479            if (extract_cfg_file_and_mountlist_from_tape_dev
    24982480                (bkpinfo->media_device)) {
    2499                 strcpy(bkpinfo->media_device, "/dev/st0");
     2481                paranoid_alloc(bkpinfo->media_device, "/dev/st0");
    25002482                if (extract_cfg_file_and_mountlist_from_tape_dev
    25012483                    (bkpinfo->media_device)) {
    2502                     strcpy(bkpinfo->media_device, "/dev/osst0");
     2484                    paranoid_alloc(bkpinfo->media_device, "/dev/osst0");
    25032485                    if (extract_cfg_file_and_mountlist_from_tape_dev
    25042486                        (bkpinfo->media_device)) {
    2505                         strcpy(bkpinfo->media_device, "/dev/ht0");
     2487                        paranoid_alloc(bkpinfo->media_device, "/dev/ht0");
    25062488                        if (extract_cfg_file_and_mountlist_from_tape_dev
    25072489                            (bkpinfo->media_device)) {
    25082490                            log_msg(3,
    25092491                                    "I tried lots of devices but none worked.");
    2510                             strcpy(bkpinfo->media_device, tmp);
     2492                            paranoid_alloc(bkpinfo->media_device, sav);
    25112493                        }
    25122494                    }
    25132495                }
    25142496            }
     2497            paranoid_free(sav);
    25152498
    25162499            if (!does_file_exist("tmp/mondo-restore.cfg")) {
Note: See TracChangeset for help on using the changeset viewer.