Changeset 3191 in MondoRescue


Ignore:
Timestamp:
Sep 25, 2013, 8:55:45 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Lots of memory management backports from 3.1 to 3.2 - still not finished, nor working ATM. the common subdir was done during travel, so this is essentially a backup !
Location:
branches/3.2
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi/mindi

    r3184 r3191  
    376376    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd     # Slackware
    377377    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd
     378    [ ! -e "$KEYDIR" ] && KEYDIR=/lib/kbd
    378379    [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share
    379380    [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole
     
    423424        LogFile "INFO: Gentoo-style config detected."
    424425        keyfile=/etc/conf.d/keymaps
     426    elif [ -e "/etc/X11/xorg.conf.d/00-keyboard.conf" ] ; then
     427        LogFile "INFO: X11-style config detected."
     428        keyfile=/etc/X11/xorg.conf.d/00-keyboard.conf
    425429    else
    426430        LogFile "Searching for rc.config ..."
     
    442446    [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'`        # Slackware
    443447    [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | grep -v '^#' | tr -d '"' |cut -d'=' -f2`     # Gentoo & ArchLinux
     448    [ ! "$locale" ] && locale=`grep -E 'XkbLayout' "$keyfile" | grep -v '^#' | awk '{print $3}' | tr -d '"'`        #  Fedora 19
    444449    LogFile "INFO: locale=$locale"
    445450    #
     
    707712    local lcMagicExt2fs="EXT2-fs: blocksize too small for device."
    708713    local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device."
    709     local lcMagicInitfs="<6>checking if image is initramfs...|<6>Unpacking initramfs...|<6>Trying to unpack rootfs image as initramfs"
     714    local lcMagicInitfs="<6>checking if image is initramfs...|[<]6[>]Unpacking initramfs...|<6>Trying to unpack rootfs image as initramfs"
    710715
    711716    # local variables
     
    23512356        if [ "$?" -eq "0" ] ; then
    23522357            # Used by ia64
    2353             fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep -E '[2-9]+[.][0-9]+[.][0-9]+[^\@]*@'`
     2358            fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
    23542359        else
    2355             fkern_ver=`strings $fname 2> /dev/null | grep -E '[2-9]+[.][0-9]+[.][0-9]+[^\@]*@'`
     2360            fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"`
    23562361        fi
    23572362        echo "$fkern_ver"
  • branches/3.2/mondo/src/common/libmondo-archive.c

    r3185 r3191  
    6464extern bool g_cd_recovery;
    6565extern char *g_mondo_home;
    66 /*
    67 extern char *g_tmpfs_mountpt;
    68 */
    69 extern char *g_serial_string;
     66
     67/**
     68 * The serial string (used to differentiate between backups) of the current backup.
     69 */
     70char *g_serial_string = NULL;
     71
    7072extern char *g_getfacl;
    7173extern char *g_getfattr;
     
    200202
    201203    if (!does_file_exist(filelist)) {
    202         mr_asprintf(tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    203         log_to_screen(tmp);
    204         paranoid_free(tmp);
     204        log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist);
    205205        return (1);
    206206    }
     
    208208    mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    209209    if (system(tmp)) {
    210         paranoid_free(tmp);
     210        mr_free(tmp);
    211211        fatal_error("Unable to write tarball to scratchdir");
    212212    }
    213213    paranoid_free(tmp);
    214214
    215     mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s",
    216             filelist, fname);
     215    mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s", filelist, fname);
    217216    if (bkpinfo->use_lzo) {
     217        mr_free(command);
    218218        fatal_error("Can't use lzop");
    219219    }
     
    235235            res = 0;
    236236        }
    237         paranoid_free(tmp);
     237        mr_free(tmp);
    238238
    239239        if (res) {
     
    251251        }
    252252    }
    253     paranoid_free(command);
     253    mr_free(command);
    254254
    255255    retval += res;
     
    307307
    308308    if (!does_file_exist(filelist)) {
    309         mr_asprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
    310                 filelist);
    311         log_to_screen(tmp);
    312         paranoid_free(tmp);
     309        log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist);
    313310        return (1);
    314311    }
    315312    mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    316313    if (system(tmp)) {
    317         paranoid_free(tmp);
     314        mr_free(tmp);
    318315        fatal_error("Unable to write tarball to scratchdir");
    319316    }
    320     paranoid_free(tmp);
     317    mr_free(tmp);
    321318
    322319
     
    324321        mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
    325322        //       -b %ld, TAPE_BLOCK_SIZE
    326         mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
    327                 bkpinfo->compression_level);
     323        mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level);
    328324        if (does_file_exist(tmp)) {
    329325            mr_strcat(zipparams, " -E %s",tmp);
     
    331327            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
    332328        }
    333         paranoid_free(tmp);
     329        mr_free(tmp);
    334330    } else {
    335331        mr_asprintf(zipparams, "");
    336332    }
    337 
    338 //  make_hole_for_file(fname);
    339333
    340334    if (!does_file_exist(bkpinfo->tmpdir)) {
     
    346340        fatal_error("scratchdir not found");
    347341    }
    348     mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
    349             fname, bkpinfo->zip_suffix);
     342    mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname, bkpinfo->zip_suffix);
    350343    paranoid_system(command);
    351     paranoid_free(command);
    352 
    353     mr_asprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
    354             TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
    355     paranoid_free(zipparams);
     344    mr_free(command);
     345
     346    mr_asprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
     347    mr_free(zipparams);
    356348
    357349    mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname);
    358350    if (system(tmp)) {
    359         paranoid_free(tmp);
     351        mr_free(tmp);
    360352        fatal_error("Unable to write tarball to scratchdir");
    361353    }
    362     paranoid_free(tmp);
     354    mr_free(tmp);
    363355
    364356    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     
    406398{
    407399    int retval = 0, res = 0;
    408     char *tmp;
     400    char *tmp = NULL;
    409401
    410402    assert(bkpinfo != NULL);
    411403    set_g_cdrom_and_g_dvd_to_bkpinfo_value();
    412     malloc_string(tmp);
    413404    if (bkpinfo->backup_media_type == dvd) {
    414405#ifdef DVDRWFORMAT
     
    431422    }
    432423
    433 /*
    434       sprintf(tmp, "wc -l %s/archives/filelist.full > %s/archives/filelist.count",bkpinfo->scratchdir, bkpinfo->scratchdir);
    435       if (run_program_and_log_output(tmp, 2))
    436         { fatal_error("Failed to count filelist.full"); }
    437 */
    438     sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
     424    mr_asprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
    439425    if (run_program_and_log_output(tmp, 2)) {
     426        mr_free(tmp);
    440427        fatal_error("Failed to gzip filelist.full");
    441428    }
    442     sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
    443             bkpinfo->tmpdir);
     429    mr_free(tmp);
     430
     431    mr_asprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    444432    if (run_program_and_log_output(tmp, 2)) {
     433        mr_free(tmp);
    445434        fatal_error("Failed to copy to tmpdir");
    446435    }
     436    mr_free(tmp);
    447437
    448438    copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists
     
    464454    }
    465455    retval += do_that_initial_phase();  // prepare
    466     sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
     456    mr_asprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
    467457    run_program_and_log_output(tmp, 1);
     458    mr_free(tmp);
     459
    468460    retval += make_those_afios_phase(); // backup regular files
    469461    retval += make_those_slices_phase();    // backup BIG files
     
    473465        sleep(2);
    474466    }
    475     paranoid_free(tmp);
    476467    return (retval);
    477468}
     
    514505    char *use_lzo_sz = NULL;
    515506    char *use_gzip_sz = NULL;
     507    char *use_lzma_sz = NULL;
    516508    char *use_comp_sz = NULL;
    517509    char *use_star_sz = NULL;
     
    542534    assert(bkpinfo != NULL);
    543535
    544     mvaddstr_and_log_it(g_currentY, 0,
    545                         "Calling MINDI to create boot+data disks");
     536    mvaddstr_and_log_it(g_currentY, 0, "Calling MINDI to create boot+data disks");
    546537    open_evalcall_form("Calling MINDI to create boot+data disks");
    547538    mr_asprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
     
    550541        mr_asprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
    551542        if (!does_file_exist(tmp)) {
    552             fatal_error
    553                 ("Cannot find filelist.full, so I cannot count its lines");
     543            mr_free(tmp);
     544            fatal_error ("Cannot find filelist.full, so I cannot count its lines");
    554545        }
    555546    }
     
    571562            }
    572563        }
    573         paranoid_free(ntapedev);
     564        mr_free(ntapedev);
    574565        mr_asprintf(tape_device, "%s", bkpinfo->media_device);
    575566    } else {
     
    586577    } else {
    587578        mr_asprintf(use_gzip_sz, "no");
     579    }
     580    if (bkpinfo->use_lzma) {
     581        mr_asprintf(use_lzma_sz, "yes");
     582    } else {
     583        mr_asprintf(use_lzma_sz, "no");
    588584    }
    589585    if (bkpinfo->use_star) {
     
    660656            ch = 'U';
    661657        if (bkpinfo->boot_loader != '\0') {
    662             mr_asprintf(tmp, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader);
    663             log_msg(2, tmp);
    664             mr_free(tmp);
     658            log_msg(2, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader);
    665659        } else {
    666660            bkpinfo->boot_loader = ch;
    667661        }
    668662        if (bkpinfo->boot_device[0] != '\0') {
    669             mr_asprintf(tmp, "User specified boot device. It is '%s'.", bkpinfo->boot_device);
    670             log_msg(2, tmp);
    671             mr_free(tmp);
     663            log_msg(2, "User specified boot device. It is '%s'.", bkpinfo->boot_device);
    672664        } else {
    673665            strcpy(bkpinfo->boot_device, bootdev);
     
    692684        mr_asprintf(bootldr_str, "LILO");
    693685        if (!does_file_exist("/etc/lilo.conf")) {
    694             fatal_error
    695                 ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
     686            fatal_error("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
    696687        }
    697688    } else if (bkpinfo->boot_loader == 'G') {
    698689        mr_asprintf(bootldr_str, "GRUB");
    699         if (!does_file_exist("/boot/grub/menu.lst")
    700             && does_file_exist("/boot/grub/grub.conf")) {
    701             run_program_and_log_output
    702                 ("ln -sf /boot/grub/grub.conf /boot/grub/menu.lst", 5);
     690        if (!does_file_exist("/boot/grub/menu.lst") && does_file_exist("/boot/grub/grub.conf")) {
     691            run_program_and_log_output("ln -sf /boot/grub/grub.conf /boot/grub/menu.lst", 5);
    703692        }
    704693        if ((!does_file_exist("/boot/grub/menu.lst")) && (!does_file_exist("/boot/grub/grub.cfg")) && (!does_file_exist("/boot/grub2/grub.cfg"))) {
    705             fatal_error
    706                 ("The de facto standard location for your boot loader's config file is /boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg but I cannot find it there. What is wrong with your Linux distribution?");
     694            fatal_error("The de facto standard location for your boot loader's config file is /boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg but I cannot find it there. What is wrong with your Linux distribution?");
    707695        }
    708696        mr_asprintf(bootldr_ver, "%s", call_program_and_get_last_line_of_output("grub --version"));
     
    710698        mr_asprintf(bootldr_str, "ELILO");
    711699        /* BCO: fix it for Debian, Mandrake, ... */
    712         if (!does_file_exist("/etc/elilo.conf")
    713             && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
    714             run_program_and_log_output
    715                 ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
    716                  5);
    717         }
    718         if (!does_file_exist("/etc/elilo.conf")
    719             && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) {
    720             run_program_and_log_output
    721                 ("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf",
    722                  5);
    723         }
    724         if (!does_file_exist("/etc/elilo.conf")
    725             && does_file_exist("/boot/efi/efi/debian/elilo.conf")) {
    726             run_program_and_log_output
    727                 ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf",
    728                  5);
    729         }
    730         if (!does_file_exist("/etc/elilo.conf")
    731             && does_file_exist("/boot/efi/debian/elilo.conf")) {
    732             run_program_and_log_output
    733                 ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf",
    734                  5);
     700        if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
     701            run_program_and_log_output("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", 5);
     702        }
     703        if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) {
     704            run_program_and_log_output("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf", 5);
     705        }
     706        if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/debian/elilo.conf")) {
     707            run_program_and_log_output ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf", 5);
     708        }
     709        if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/debian/elilo.conf")) {
     710            run_program_and_log_output ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf", 5);
    735711        }
    736712        if (!does_file_exist("/etc/elilo.conf")) {
    737             fatal_error
    738                 ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
     713            fatal_error("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
    739714        }
    740715    } else if (bkpinfo->boot_loader == 'R') {
     
    753728        mr_asprintf(bootldr_str, "unknown");
    754729    }
    755     mr_asprintf(tmp, "Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device);
    756     log_to_screen(tmp);
    757     mr_free(tmp);
     730    log_to_screen("Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device);
     731
    758732    if (bootldr_ver != NULL) {
    759         mr_asprintf(tmp, "Boot loader version string: %s", bootldr_ver);
    760         log_to_screen(tmp);
    761         mr_free(tmp);
     733        log_to_screen("Boot loader version string: %s", bootldr_ver);
    762734    }
    763735
     
    799771        fatal_error("Unknown backup_media_type");
    800772    }
    801     if (bkpinfo->backup_media_type == usb) {
     773
     774    if ((bkpinfo->backup_media_type == usb) && (bkpinfo->media_device)) {
    802775        mr_asprintf(tmp2, "--usb %s", bkpinfo->media_device);
    803776    } else {
     
    808781    if (write_one_liner_data_file(tmp, value)) {
    809782        res++;
    810         log_msg(1, "%ld: Unable to write one-liner backup-media-type",
    811                 __LINE__);
     783        log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__);
    812784    }
    813785    mr_free(value);
     
    817789    if (write_one_liner_data_file(tmp, bootldr_str)) {
    818790        res++;
    819         log_msg(1, "%ld: Unable to write one-liner bootloader.name",
    820                 __LINE__);
     791        log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__);
    821792    }
    822793    mr_free(bootldr_str);
     
    865836    }
    866837
    867     estimated_total_noof_slices =
    868         size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    869     /* add netfs stuff here? */
     838    estimated_total_noof_slices = size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
     839
     840    /* TODO: add netfs stuff here? */
    870841    mr_asprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
    871842    if (system(command)) {
     
    873844        log_OS_error("Unable to make images directory");
    874845    }
    875     paranoid_free(command);
     846    mr_free(command);
    876847    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    877848    update_evalcall_form(3);
     
    890861            use_lzo_sz,         // parameter #8
    891862            cd_recovery_sz,     // parameter #9
    892             bkpinfo->image_devs,    // parameter #10
     863            (bkpinfo->image_devs == NULL) ? "\"\"" : bkpinfo->image_devs,   // parameter #10
    893864            broken_bios_sz,     // parameter #11
    894865            last_filelist_number,   // parameter #12 (STRING)
     
    900871            bkpinfo->internal_tape_block_size,  // parameter #18 (LONG)
    901872            bkpinfo->differential,  // parameter #19 (INT)
    902             use_gzip_sz);       // parameter #20 (STRING)
     873            use_gzip_sz,        // parameter #19 (STRING)
     874            use_lzma_sz,        // parameter #20 (STRING)
     875            value,              // parameter #21 (STRING)
     876            MONDO_LOGFILE);
    903877
    904878    mr_free(last_filelist_number);
     
    906880    mr_free(use_lzo_sz);
    907881    mr_free(use_gzip_sz);
     882    mr_free(use_lzma_sz);
    908883    mr_free(use_star_sz);
    909884    mr_free(use_comp_sz);
     
    913888    mr_free(tape_size_sz);
    914889
     890    /* This parameter is always the last one and optional */
    915891    if (bkpinfo->nonbootable_backup) {
    916892        mr_strcat(command, " NONBOOTABLE");
     
    929905    if (!res) {
    930906        log_to_screen("Boot+data disks were created OK");
    931         mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso",
    932                 bkpinfo->scratchdir, MINDI_CACHE);
     907        mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso", bkpinfo->scratchdir, MINDI_CACHE);
    933908        log_msg(2, command);
    934909        run_program_and_log_output(command, FALSE);
    935         paranoid_free(command);
     910        mr_free(command);
    936911
    937912        if (bkpinfo->nonbootable_backup) {
    938             mr_asprintf(command, "cp -f %s/all.tar.gz %s/images",
    939                     bkpinfo->tmpdir, bkpinfo->scratchdir);
     913            mr_asprintf(command, "cp -f %s/all.tar.gz %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir);
    940914            if (system(command)) {
    941                 paranoid_free(command);
     915                mr_free(command);
    942916                fatal_error("Unable to create temporary all tarball");
    943917            }
    944             paranoid_free(command);
     918            mr_free(command);
    945919        }
    946920        /* For USB we already have everything on the key */
     
    948922            mr_asprintf(command, "rm -rf %s/images", bkpinfo->scratchdir);
    949923            run_program_and_log_output(command, FALSE);
    950             paranoid_free(command);
     924            mr_free(command);
    951925        } else {
    952             mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
    953                 bkpinfo->tmpdir);
     926            mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir);
    954927            if (system(tmp)) {
    955928                fatal_error("Cannot find all.tar.gz in tmpdir");
     
    966939        mr_asprintf(command, "grep 'Fatal error' /var/log/mindi.log");
    967940        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    968         paranoid_free(command);
     941        mr_free(command);
    969942
    970943        if (strlen(tmp) > 1) {
     
    1017990void *create_afio_files_in_background(void *inbuf)
    1018991{
    1019     long int archiving_set_no;
    1020     char *archiving_filelist_fname;
    1021     char *archiving_afioball_fname;
     992    long int archiving_set_no = 0L;
     993    char *archiving_filelist_fname = NULL;
     994    char *archiving_afioball_fname = NULL;
    1022995    char *curr_xattr_list_fname = NULL;
    1023     char *curr_acl_list_fname;
    1024 
    1025     char *tmp;
     996    char *curr_acl_list_fname = NULL;
     997
     998    char *tmp = NULL;
    1026999    int res = 0, retval = 0;
    10271000    int *p_archival_threads_running;
     
    10311004    int this_thread_no = g_current_thread_no++;
    10321005
    1033     malloc_string(curr_xattr_list_fname);
    1034     malloc_string(curr_acl_list_fname);
    1035     malloc_string(archiving_filelist_fname);
    1036     malloc_string(archiving_afioball_fname);
    1037     malloc_string(tmp);
    10381006    p_last_set_archived = (int *) inbuf;
    10391007    p_archival_threads_running = (int *) (inbuf + 4);
     
    10411009    p_list_of_fileset_flags = (char *) (inbuf + 12);
    10421010
    1043     sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1044             bkpinfo->tmpdir, 0L);
    1045     for (archiving_set_no = 0L; does_file_exist(archiving_filelist_fname);
    1046          sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1047                  bkpinfo->tmpdir, archiving_set_no)) {
     1011    mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L);
     1012
     1013    while (does_file_exist(archiving_filelist_fname)) {
    10481014        if (g_exiting) {
     1015            mr_free(archiving_filelist_fname);
    10491016            fatal_error("Execution run aborted (pthread)");
    10501017        }
    10511018        if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
    1052             fatal_error
    1053                 ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
     1019            mr_free(archiving_filelist_fname);
     1020            fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
    10541021        }
    10551022        if (!semaphore_p()) {
    10561023            log_msg(3, "P sem failed (pid=%d)", (int) getpid());
     1024            mr_free(archiving_filelist_fname);
    10571025            fatal_error("Cannot get semaphore P");
    10581026        }
     
    10621030        *p_next_set_to_archive = *p_next_set_to_archive + 1;
    10631031        if (!semaphore_v()) {
     1032            mr_free(archiving_filelist_fname);
    10641033            fatal_error("Cannot get semaphore V");
    10651034        }
    10661035
    10671036        /* backup this set of files */
    1068         sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
    1069                 bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
    1070         sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1071                 bkpinfo->tmpdir, archiving_set_no);
     1037        mr_asprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
     1038        mr_free(archiving_filelist_fname);
     1039        mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    10721040        if (!does_file_exist(archiving_filelist_fname)) {
    1073             log_msg(3,
    1074                     "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
    1075                     FORTY_SPACES, getpid(), this_thread_no,
    1076                     archiving_set_no);
     1041            log_msg(3, "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
     1042            mr_free(archiving_afioball_fname);
    10771043            break;
    10781044        }
    10791045
    1080         sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
    1081                 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
     1046        mr_asprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
    10821047        if (does_file_exist(tmp)) {
    1083             log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES,
    1084                     getpid(), this_thread_no);
     1048            log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no);
    10851049            while (does_file_exist(tmp)) {
    10861050                sleep(1);
     
    10881052            log_msg(4, "[%d] - continuing", getpid());
    10891053        }
    1090 
    1091         log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
    1092                 this_thread_no, archiving_set_no);
     1054        mr_free(tmp);
     1055
     1056        log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
     1057
    10931058        if (g_getfattr) {
    1094             sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    1095                 bkpinfo->tmpdir, archiving_set_no);
     1059            mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    10961060            get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
     1061            mr_free(curr_xattr_list_fname);
    10971062        }
    10981063        if (g_getfacl) {
    1099             sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    1100                 bkpinfo->tmpdir, archiving_set_no);
     1064            mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
    11011065            get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
    1102         }
    1103 
    1104         log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
    1105                 this_thread_no, archiving_set_no);
    1106         res =
    1107             archive_this_fileset(archiving_filelist_fname,
    1108                                  archiving_afioball_fname,
    1109                                  archiving_set_no);
     1066            mr_free(curr_acl_list_fname);
     1067        }
     1068
     1069        log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
     1070        res = archive_this_fileset(archiving_filelist_fname, archiving_afioball_fname, archiving_set_no);
     1071        mr_free(archiving_afioball_fname);
     1072
    11101073        retval += res;
    11111074
    11121075        if (res) {
    1113             sprintf(tmp,
    1114                     "Errors occurred while archiving set %ld. Please review logs.",
    1115                     archiving_set_no);
    1116             log_to_screen(tmp);
    1117         }
     1076            log_to_screen("Errors occurred while archiving set %ld. Please review logs.", archiving_set_no);
     1077        }
     1078
    11181079        if (!semaphore_p()) {
     1080            mr_free(archiving_filelist_fname);
    11191081            fatal_error("Cannot get semaphore P");
    11201082        }
     
    11271089
    11281090        if (!semaphore_v()) {
     1091            mr_free(archiving_filelist_fname);
    11291092            fatal_error("Cannot get semaphore V");
    11301093        }
    1131         log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
    1132                 this_thread_no, archiving_set_no);
     1094        log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no);
    11331095        archiving_set_no++;
    1134     }
     1096
     1097        mr_free(archiving_filelist_fname);
     1098        mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no);
     1099    }
     1100    mr_free(archiving_filelist_fname);
     1101
    11351102    if (!semaphore_p()) {
    11361103        fatal_error("Cannot get semaphore P");
     
    11401107        fatal_error("Cannot get semaphore V");
    11411108    }
    1142     log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
    1143             this_thread_no);
    1144     paranoid_free(archiving_filelist_fname);
    1145     paranoid_free(archiving_afioball_fname);
    1146     paranoid_free(curr_xattr_list_fname);
    1147     paranoid_free(curr_acl_list_fname);
    1148     paranoid_free(tmp);
     1109    log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no);
    11491110    pthread_exit(NULL);
    11501111}
     
    12281189
    12291190    /*@ buffers *********************************** */
    1230     char *command, *tmpfile, *data_disks_file;
     1191    char *command = NULL;
     1192    char *tmpfile = NULL;
     1193    char *data_disks_file = NULL;
    12311194
    12321195    assert(bkpinfo != NULL);
    1233     malloc_string(command);
    1234     malloc_string(tmpfile);
    1235     malloc_string(data_disks_file);
    1236     sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
    1237 
    1238     snprintf(g_serial_string, MAX_STR_LEN - 8, "%s",
    1239              call_program_and_get_last_line_of_output("dd \
    1240 if=/dev/urandom bs=16 count=1 2> /dev/null | \
    1241 hexdump | tr -s ' ' '0' | head -n1"));
     1196    mr_asprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
     1197
     1198    snprintf(g_serial_string, MAX_STR_LEN - 8, "%s", call_program_and_get_last_line_of_output("dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump | tr -s ' ' '0' | head -n1"));
    12421199    strip_spaces(g_serial_string);
    12431200    strcat(g_serial_string, "...word.");
     
    12451202    assert(strlen(g_serial_string) < MAX_STR_LEN);
    12461203
    1247     sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
     1204    mr_asprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
    12481205    if (write_one_liner_data_file(tmpfile, g_serial_string)) {
    12491206        log_msg(1, "%ld: Failed to write serial string", __LINE__);
    12501207    }
     1208    mr_free(tmpfile);
    12511209
    12521210    mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
     
    12691227        }
    12701228    }
    1271 
    1272     sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
    1273             bkpinfo->netfs_remote_dir, bkpinfo->prefix);
     1229    mr_free(data_disks_file);
     1230
     1231    mr_asprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix);
    12741232    paranoid_system(command);
     1233    mr_free(command);
     1234
    12751235    wipe_archives(bkpinfo->scratchdir);
    12761236    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    12811241                                     BLK_START_OF_BACKUP);
    12821242    }
    1283     paranoid_free(command);
    1284     paranoid_free(tmpfile);
    1285     paranoid_free(data_disks_file);
    12861243    return (retval);
    12871244}
     
    13561313
    13571314    /*@ buffers ********************************************** */
    1358     char *storing_filelist_fname;
    1359     char *storing_afioball_fname;
     1315    char *storing_filelist_fname = NULL;
     1316    char *storing_afioball_fname = NULL;
    13601317    char *tmp = NULL;
    13611318    char *media_usage_comment = NULL;
     
    13741331    assert(bkpinfo != NULL);
    13751332    malloc_string(result_str);
    1376     malloc_string(curr_xattr_list_fname);
    1377     malloc_string(curr_acl_list_fname);
    1378     malloc_string(storing_filelist_fname);
    1379     malloc_string(storing_afioball_fname);
    1380     transfer_block =
    1381         malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
    1382     memset((void *) transfer_block, 0,
    1383            sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1333    transfer_block = malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1334    memset((void *) transfer_block, 0, sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
    13841335    p_last_set_archived = (int *) transfer_block;
    13851336    p_archival_threads_running = (int *) (transfer_block + 4);
    13861337    p_next_set_to_archive = (int *) (transfer_block + 8);
    13871338    p_list_of_fileset_flags = (char *) (transfer_block + 12);
    1388     memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
    1389            (void *) bkpinfo, sizeof(struct s_bkpinfo));
     1339    memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), (void *) bkpinfo, sizeof(struct s_bkpinfo));
    13901340    pvp = &vp;
    13911341    vp = (void *) result_str;
     
    13991349                       "Please wait. This may take a couple of hours.",
    14001350                       "Working...",
    1401                        get_last_filelist_number() + 1);
     1351                       (long)get_last_filelist_number() + 1L);
    14021352
    14031353    log_msg(5, "We're gonna party like it's your birthday.");
     
    14381388            if (!get_bit_N_of_array
    14391389                (p_list_of_fileset_flags, storing_set_no)) {
    1440             misc_counter_that_is_not_important =
    1441                 (misc_counter_that_is_not_important + 1) % 5;
     1390            misc_counter_that_is_not_important = (misc_counter_that_is_not_important + 1) % 5;
    14421391            /* BCO the media_usage_comment is not really initialized there !
    14431392            if (!misc_counter_that_is_not_important) {
     
    14461395            */
    14471396            sleep(1);
    1448             } else
     1397            } else {
    14491398                // store set N
    1450             {
    1451                 sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
    1452                         bkpinfo->tmpdir, storing_set_no);
    1453                 sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
    1454                         bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
     1399                mr_asprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
     1400                mr_asprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
    14551401                if (g_getfattr) {
    1456                     sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    1457                         bkpinfo->tmpdir, storing_set_no);
     1402                    mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    14581403                }
    14591404                if (g_getfacl) {
    1460                     sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
    1461                         bkpinfo->tmpdir, storing_set_no);
     1405                    mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no);
    14621406                }
    14631407
     
    14701414                    sleep(5);
    14711415                }
    1472                 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
    14731416                /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
    14741417                if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    14751418                    register_in_tape_catalog(fileset, storing_set_no, -1,
    14761419                                         storing_afioball_fname);
    1477                     maintain_collection_of_recent_archives(bkpinfo->tmpdir,
    1478                                                        storing_afioball_fname);
     1420                    maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname);
    14791421                    log_it("Writing EXAT files");
    14801422                    res +=
     
    15101452                retval += res;
    15111453                g_current_progress++;
     1454                mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
    15121455                update_progress_form(media_usage_comment);
    15131456                mr_free(media_usage_comment);
    15141457                if (res) {
    1515                     mr_asprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
    1516                         storing_set_no);
    1517                     log_to_screen(tmp);
    1518                     paranoid_free(tmp);
    1519                     fatal_error
    1520                         ("Is your hard disk full? If not, please send the author the logfile.");
     1458                    log_to_screen("Failed to add archive %ld's files to CD dir\n", storing_set_no);
     1459                    fatal_error("Is your hard disk full? If not, please send the author the logfile.");
    15211460                }
    15221461                storing_set_no++;
    15231462                //      sleep(2);
     1463                if (g_getfacl) {
     1464                    mr_free(curr_acl_list_fname);
     1465                }
     1466                if (g_getfattr) {
     1467                    mr_free(curr_xattr_list_fname);
     1468                }
     1469                mr_free(storing_filelist_fname);
     1470                mr_free(storing_afioball_fname);
    15241471        }
    15251472    }
     
    15401487    }
    15411488    log_to_screen(tmp);
    1542     paranoid_free(tmp);
     1489    mr_free(tmp);
    15431490
    15441491    paranoid_free(transfer_block);
    15451492    paranoid_free(result_str);
    1546     paranoid_free(storing_filelist_fname);
    1547     paranoid_free(storing_afioball_fname);
    1548     paranoid_free(curr_xattr_list_fname);
    1549     paranoid_free(curr_acl_list_fname);
    15501493    return (retval);
    15511494}
     
    15981541    mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir);
    15991542    run_program_and_log_output(tmp, FALSE);
    1600     paranoid_free(tmp);
     1543    mr_free(tmp);
    16011544    if (chdir(bkpinfo->scratchdir)) {
    16021545        // FIXME
     
    16081551    log_msg(1, message_to_screen);
    16091552
    1610     mr_asprintf(tmp1, "%s1", bkpinfo->media_device);
     1553    if (bkpinfo->media_device) {
     1554        mr_asprintf(tmp1, "%s1", bkpinfo->media_device);
     1555    } else {
     1556        mr_asprintf(tmp1, "");
     1557    }
    16111558    if (is_this_device_mounted(tmp1)) {
    16121559        log_msg(1, "USB device mounted. Remounting it at the right place");
    16131560        mr_asprintf(tmp, "umount %s", tmp1);
    16141561        run_program_and_log_output(tmp, FALSE);
    1615         paranoid_free(tmp);
    1616     }
    1617     paranoid_free(tmp1);
     1562        mr_free(tmp);
     1563    }
     1564    mr_free(tmp1);
    16181565
    16191566    log_msg(1, "Mounting USB device.");
     
    16211568    mr_asprintf(tmp, "mkdir -p %s", tmp1);
    16221569    run_program_and_log_output(tmp, FALSE);
    1623     paranoid_free(tmp);
     1570    mr_free(tmp);
     1571
    16241572
    16251573    /* Mindi always create one single parition on the USB dev */
    16261574    mr_asprintf(tmp, "mount %s1 %s", bkpinfo->media_device, tmp1);
    16271575    run_program_and_log_output(tmp, FALSE);
    1628     paranoid_free(tmp);
     1576    mr_free(tmp);
    16291577
    16301578    if (bkpinfo->nonbootable_backup) {
     
    16421590        }
    16431591        log_to_screen(result_sz);
    1644         paranoid_free(result_sz);
    1645         paranoid_free(tmp);
     1592        mr_free(result_sz);
     1593        mr_free(tmp);
    16461594        retval += res;
    16471595
     
    16491597        mr_asprintf(tmp,"mkdir %s/archive", bkpinfo->scratchdir);
    16501598        run_program_and_log_output(tmp, FALSE);
    1651         paranoid_free(tmp);
     1599        mr_free(tmp);
    16521600    }
    16531601    paranoid_free(message_to_screen);
     
    16571605        mr_asprintf(tmp, "umount %s1", bkpinfo->media_device);
    16581606        run_program_and_log_output(tmp, FALSE);
    1659         paranoid_free(tmp);
     1607        mr_free(tmp);
    16601608    }
    16611609
     
    16951643
    16961644    /*@ buffers ****************************************** */
    1697     char *tmp;
     1645    char *tmp = NULL;
     1646    char *tmp2 = NULL;
    16981647    char *old_pwd;
    16991648    char *result_sz = NULL;
    17001649    char *message_to_screen = NULL;
    17011650    char *sz_blank_disk = NULL;
    1702     char *fnam;
    1703     char *tmp2;
    1704     char *tmp3;
     1651    char *fnam = NULL;
     1652    char *tmp3 = NULL;
    17051653    char *isofs_cmd = NULL;
    17061654    char *full_isofs_cmd = NULL;
     
    17101658    malloc_string(old_pwd);
    17111659    malloc_string(fnam);
    1712     tmp = malloc(1200);
    1713     tmp2 = malloc(1200);
    1714     tmp3 = malloc(1200);
    17151660    assert(bkpinfo != NULL);
    17161661    assert_string_is_neither_NULL_nor_zerolength(destfile);
    17171662
    1718     sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
    1719     sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
     1663    /* Copy the files needed by isolinux in the right dir */
     1664    mr_asprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
     1665    mr_asprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
    17201666    if (does_file_exist(tmp)) {
    1721         sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
     1667        mr_asprintf(tmp3, "cp -f %s %s", tmp, tmp2);
    17221668        paranoid_system(tmp3);
     1669        mr_free(tmp3);
    17231670    }
    17241671    if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
    1725         sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
     1672        mr_asprintf(tmp3, "cp -f %s %s", tmp2, tmp);
    17261673        paranoid_system(tmp3);
    1727     }
    1728     free(tmp2);
    1729     free(tmp3);
    1730     tmp2 = NULL;
    1731     tmp3 = NULL;
     1674        mr_free(tmp3);
     1675    }
     1676    mr_free(tmp2);
     1677    mr_free(tmp3);
    17321678    if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
    17331679        popup_and_OK("Please insert new media and press Enter.");
    17341680    }
    17351681
    1736     log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
    1737             bkpinfo->scratchdir, destfile);
     1682    log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", bkpinfo->scratchdir, destfile);
    17381683    tmp2 = getcwd(old_pwd, MAX_STR_LEN - 1);
    1739     sprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir);
     1684    if (! tmp2) {
     1685        //FIXME
     1686    }
     1687    mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir);
    17401688    run_program_and_log_output(tmp, FALSE);
     1689    mr_free(tmp);
     1690
    17411691    if (chdir(bkpinfo->scratchdir)) {
    17421692        // FIXME
     
    17441694
    17451695    if (bkpinfo->call_before_iso[0] != '\0') {
    1746         mr_asprintf(message_to_screen, "Running pre-ISO call for CD#%d",
    1747                 g_current_media_number);
    1748         res =
    1749             eval_call_to_make_ISO(bkpinfo->call_before_iso,
    1750                                   destfile, g_current_media_number,
    1751                                   MONDO_LOGFILE, message_to_screen);
     1696        mr_asprintf(message_to_screen, "Running pre-ISO call for CD#%d", g_current_media_number);
     1697        res = eval_call_to_make_ISO(bkpinfo->call_before_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    17521698        if (res) {
    17531699            mr_strcat(message_to_screen, "...failed");
     
    17631709    if (bkpinfo->call_make_iso[0] != '\0') {
    17641710        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    1765         sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    17661711        mds = media_descriptor_string(bkpinfo->backup_media_type);
    17671712        mr_asprintf(message_to_screen, "Making an ISO (%s #%d)", mds, g_current_media_number);
     
    17741719        } else {
    17751720            res =
    1776                 eval_call_to_make_ISO(bkpinfo->call_make_iso,
    1777                                       bkpinfo->scratchdir,
    1778                                       g_current_media_number,
    1779                                       MONDO_LOGFILE, message_to_screen);
     1721                eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    17801722            if (res) {
    17811723                log_to_screen("%s...failed to write", message_to_screen);
    17821724            } else {
    17831725                log_to_screen("%s...OK", message_to_screen);
    1784                 sprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
     1726                mr_asprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
    17851727                if (!run_program_and_log_output(tmp, 1)) {
    17861728                    log_to_screen
    17871729                        ("Despite nonfatal errors, growisofs confirms the write was successful.");
    17881730                }
     1731                mr_free(tmp);
    17891732            }
    17901733            retval += res;
    17911734#ifdef DVDRWFORMAT
    1792             sprintf(tmp,
    1793                     "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
    1794                     MONDO_LOGFILE);
     1735            mr_asprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE);
    17951736            if (g_backup_media_type == dvd
    17961737                && (res || !run_program_and_log_output(tmp, 1))) {
     
    18001741                /* reset error counter before trying to blank DVD */
    18011742                retval -= res;
    1802                 paranoid_system("sync");
     1743                sync();
    18031744                pause_for_N_seconds(5, "Letting DVD drive settle");
    18041745
     
    18101751                }
    18111752                pause_for_N_seconds(5, "Letting DVD drive settle");
    1812                 mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device);
     1753                if (bkpinfo->media_device) {
     1754                    mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device);
     1755                } else {
     1756                    mr_asprintf(sz_blank_disk, "dvd+rw-format");
     1757                }
    18131758                log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
    1814                 res =
    1815                     run_external_binary_with_percentage_indicator_NEW
    1816                     ("Blanking DVD disk", sz_blank_disk);
     1759                res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    18171760                if (res) {
    1818                     log_to_screen
    1819                         ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
    1820                     pause_for_N_seconds(5,
    1821                                         "Letting DVD drive settle... and trying again.");
    1822                     res =
    1823                         run_external_binary_with_percentage_indicator_NEW
    1824                         ("Blanking DVD disk", sz_blank_disk);
     1761                    log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
     1762                    pause_for_N_seconds(5, "Letting DVD drive settle... and trying again.");
     1763                    res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk);
    18251764                    if (res) {
    18261765                        log_to_screen("Format failed a second time.");
     
    18381777                }
    18391778                pause_for_N_seconds(5, "Letting DVD drive settle");
    1840                 res =
    1841                     eval_call_to_make_ISO(bkpinfo->call_make_iso,
    1842                                           bkpinfo->scratchdir,
    1843                                           g_current_media_number,
    1844                                           MONDO_LOGFILE,
    1845                                           message_to_screen);
     1779                res = eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    18461780                retval += res;
    18471781                if (!bkpinfo->please_dont_eject) {
     
    18561790                }
    18571791            }
     1792            mr_free(tmp);
    18581793#endif
    18591794            if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
     
    18761811            log_msg(1, "Making nonbootable backup");
    18771812            mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS);
    1878             res = eval_call_to_make_ISO(full_isofs_cmd,
    1879                                       destfile, g_current_media_number,
    1880                                       MONDO_LOGFILE, message_to_screen);
     1813            res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    18811814            mr_free(full_isofs_cmd);
    18821815        } else {
     
    18881821
    18891822
    1890             log_msg(1, "make_cd_use_lilo is actually %d",
    1891                     bkpinfo->make_cd_use_lilo);
     1823            log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo);
    18921824            if (bkpinfo->make_cd_use_lilo) {
    18931825                log_msg(1, "make_cd_use_lilo = TRUE");
     
    18951827                log_msg(1, "IA64 --> elilo");
    18961828                mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_ELILO);
    1897                 res = eval_call_to_make_ISO(full_isofs_cmd,
    1898                                             destfile,
    1899                                             g_current_media_number,
    1900                                             MONDO_LOGFILE,
    1901                                             message_to_screen);
     1829                res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    19021830                mr_free(full_isofs_cmd);
    19031831#else
    19041832                log_msg(1, "Non-ia64 --> lilo");
    19051833                mr_asprintf(full_isofs_cmd, "%s%s-b images/mindi-bootroot.2880.img -c boot.cat -o '_ISO_' -J -V _CD#_ .",isofs_cmd,MONDO_MKISOFS);
    1906                 res =
    1907                     // FIXME: fixed boot size probably wrong. lilo to be removed
    1908                     eval_call_to_make_ISO(full_isofs_cmd,
    1909                                           destfile, g_current_media_number,
    1910                                           MONDO_LOGFILE,
    1911                                           message_to_screen);
     1834                // FIXME: fixed boot size probably wrong. lilo to be removed
     1835                res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    19121836                mr_free(full_isofs_cmd);
    19131837#endif
     
    19161840                log_msg(1, "Isolinux");
    19171841                mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_SYSLINUX);
    1918                 res =
    1919                     eval_call_to_make_ISO(full_isofs_cmd,
    1920                                           destfile, g_current_media_number,
    1921                                           MONDO_LOGFILE,
    1922                                           message_to_screen);
     1842                res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    19231843                mr_free(full_isofs_cmd);
    19241844            }
     
    19401860        || bkpinfo->backup_media_type == cdrw) {
    19411861        if (is_this_device_mounted(bkpinfo->media_device)) {
    1942             log_msg(2,
    1943                     "Warning - %s mounted. I'm unmounting it before I burn to it.",
    1944                     bkpinfo->media_device);
    1945             sprintf(tmp, "umount %s", bkpinfo->media_device);
     1862            log_msg(2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device);
     1863            mr_asprintf(tmp, "umount %s", bkpinfo->media_device);
    19461864            run_program_and_log_output(tmp, FALSE);
     1865            mr_free(tmp);
    19471866        }
    19481867    }
     
    19541873        mr_free(mds);
    19551874        pause_and_ask_for_cdr(2, &cd_is_mountable);
    1956         res =
    1957             eval_call_to_make_ISO(bkpinfo->call_burn_iso,
    1958                                   destfile, g_current_media_number,
    1959                                   MONDO_LOGFILE, message_to_screen);
     1875        res = eval_call_to_make_ISO(bkpinfo->call_burn_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    19601876        if (res) {
    19611877            mr_strcat(message_to_screen, "...failed");
     
    19731889        mr_asprintf(message_to_screen, "Running post-ISO call (%s #%d)", mds, g_current_media_number);
    19741890        mr_free(mds);
    1975         res =
    1976             eval_call_to_make_ISO(bkpinfo->call_after_iso,
    1977                                   destfile, g_current_media_number,
    1978                                   MONDO_LOGFILE, message_to_screen);
     1891        res = eval_call_to_make_ISO(bkpinfo->call_after_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen);
    19791892        if (res) {
    19801893            mr_strcat(message_to_screen, "...failed");
     
    20441957
    20451958    /*@ pointers ******************************************* */
    2046     FILE *fin;
     1959    FILE *fin = NULL;
    20471960    char *p;
    20481961    char *q;
     
    20501963    /*@ buffers ******************************************** */
    20511964    char *tmp = NULL;
    2052     char *bigfile_fname;
     1965    char *bigfile_fname = NULL;
    20531966    char *sz_devfile = NULL;
    20541967    char *ntfsprog_fifo = NULL;
     
    20861999    log_to_screen(tmp);
    20872000    noof_biggie_files = count_lines_in_file(biggielist_fname);
    2088     open_progress_form("Backing up big files", tmp,
    2089                        "Please wait. This may take some time.", "",
    2090                        estimated_total_noof_slices);
    2091     paranoid_free(tmp);
     2001    open_progress_form("Backing up big files", tmp, "Please wait. This may take some time.", "", estimated_total_noof_slices);
     2002    mr_free(tmp);
    20922003
    20932004    if (!(fin = fopen(biggielist_fname, "r"))) {
     
    21212032            log_msg(2, "bigfile_fname = %s", bigfile_fname);
    21222033            use_ntfsprog = FALSE;
    2123             if (!strncmp(bigfile_fname, "/dev/", 5)
    2124                 && is_dev_an_NTFS_dev(bigfile_fname)) {
     2034            if (!strncmp(bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname)) {
    21252035                use_ntfsprog = TRUE;
    2126                 log_msg(2,
    2127                         "Calling ntfsclone in background because %s is an NTFS partition",
    2128                         bigfile_fname);
    2129                 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir,
    2130                         (int) (random() % 32768),
    2131                         (int) (random() % 32768));
     2036                log_msg(2, "Calling ntfsclone in background because %s is an NTFS partition", bigfile_fname);
     2037                mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
    21322038                mkfifo(sz_devfile, 0x770);
    21332039                ntfsprog_fifo = sz_devfile;
     
    21372043                    fatal_error("Fork failure");
    21382044                case 0:
    2139                     log_msg(2,
    2140                             "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
    2141                             bigfile_fname, sz_devfile);
     2045                    log_msg(2, "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", bigfile_fname, sz_devfile);
    21422046                    res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
    21432047                    /* BCO/BERLIOS Does the child need to unalocate memory as well ?
    2144                     paranoid_free(bigfile_fname);
     2048                    mr_free(bigfile_fname);
    21452049                    mr_free(sz_devfile);
    21462050                    */
     
    21482052                    break;
    21492053                default:
    2150                     log_msg(2,
    2151                             "feed_into_ntfsprog() called in background --- pid=%ld",
    2152                             (long int) (pid));
     2054                    log_msg(2, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
    21532055                }
    21542056            }
     
    21602062            // Whether partition or biggiefile, just do your thang :-)
    21612063            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    2162                 write_header_block_to_stream(biggie_fsize, bigfile_fname,
    2163                                              use_ntfsprog ?
    2164                                              BLK_START_A_PIHBIGGIE :
    2165                                              BLK_START_A_NORMBIGGIE);
    2166             }
    2167             res =
    2168                 slice_up_file_etc(bigfile_fname,
    2169                                   ntfsprog_fifo, biggie_file_number,
    2170                                   noof_biggie_files, use_ntfsprog);
     2064                write_header_block_to_stream(biggie_fsize, bigfile_fname, use_ntfsprog ?  BLK_START_A_PIHBIGGIE : BLK_START_A_NORMBIGGIE);
     2065            }
     2066            res = slice_up_file_etc(bigfile_fname, ntfsprog_fifo, biggie_file_number, noof_biggie_files, use_ntfsprog);
    21712067
    21722068            /* Free it here as ntfsprog_fifo is not used anymore */
     
    21972093            }
    21982094        }
    2199 #ifndef _XWIN
    22002095        if (!g_text_mode) {
    22012096            newtDrawRootText(0, g_noof_rows - 2, tmp);
    22022097            newtRefresh();
    22032098        }
    2204 #endif
    2205         paranoid_free(tmp);
    2206     }
     2099        mr_free(tmp);
     2100    }
     2101    mr_free(bigfile_fname);
     2102
    22072103    log_msg(1, "Finished backing up bigfiles");
    22082104    log_msg(1, "estimated slices = %ld; actual slices = %ld",
     
    22102106    close_progress_form();
    22112107    paranoid_fclose(fin);
    2212     paranoid_free(bigfile_fname);
    22132108    return (retval);
    22142109}
     
    22712166        retval += res;
    22722167        if (res) {
    2273             mr_asprintf(tmp, "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no);
    2274             log_to_screen(tmp);
    2275             mr_free(tmp);
    2276         }
    2277 
    2278         mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
     2168            log_to_screen("Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no);
     2169        }
    22792170
    22802171        /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
     
    23192210        retval += res;
    23202211        g_current_progress++;
     2212
     2213        mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
    23212214        update_progress_form(media_usage_comment);
    23222215        mr_free(media_usage_comment);
    23232216
    23242217        if (res) {
    2325             mr_asprintf(tmp, "Failed to add archive %ld's files to CD dir\n", curr_set_no);
    2326             log_to_screen(tmp);
    2327             mr_free(tmp);
    2328             fatal_error
    2329                 ("Is your hard disk is full? If not, please send the author the logfile.");
     2218            log_to_screen("Failed to add archive %ld's files to CD dir\n", curr_set_no);
     2219            fatal_error("Is your hard disk is full? If not, please send the author the logfile.");
    23302220        }
    23312221        mr_free(curr_filelist_fname);
     
    24282318    }
    24292319
    2430     mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
    2431             biggielist);
     2320    mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
    24322321    paranoid_system(command);
    24332322    mr_free(command);
     
    24432332    if (g_getfattr) {
    24442333        get_fattr_list(biggielist, xattr_fname);
    2445         mr_asprintf(command, "cp %s %s/archives/", xattr_fname,
    2446             bkpinfo->scratchdir);
     2334        mr_asprintf(command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
    24472335        paranoid_system(command);
    24482336        mr_free(command);
     
    27332621    /*@ buffers ********************************************* */
    27342622    char *tmp = NULL;
    2735     char *cdrom_dev;
    2736     char *cdrw_dev;
     2623    char *cdrom_dev = NULL;
     2624    char *cdrw_dev = NULL;
    27372625    char *our_serial_str = NULL;
    27382626    bool ok_go_ahead_burn_it;
     
    27402628    int attempt_to_mount_returned_this = 999;
    27412629    char *mtpt = NULL;
    2742     char *szcdno;
    2743     char *szserfname;
    2744     char *szunmount;
     2630    char *szcdno = NULL;
     2631    char *szserfname = NULL;
     2632    char *szunmount = NULL;
    27452633    char *mds = NULL;
    27462634
    27472635    malloc_string(cdrom_dev);
    27482636    malloc_string(cdrw_dev);
    2749     malloc_string(szcdno);
    2750     malloc_string(szserfname);
    2751     malloc_string(szunmount);
    2752     malloc_string(mtpt);
    27532637
    27542638    mds = media_descriptor_string(g_backup_media_type);
    2755     mr_asprintf(tmp, "I am about to burn %s #%d", mds, g_current_media_number);
     2639    log_to_screen("I am about to burn %s #%d", mds, g_current_media_number);
    27562640    mr_free(mds);
    2757     log_to_screen(tmp);
    2758     mr_free(tmp);
    27592641    if (g_current_media_number < ask_for_one_if_more_than_this) {
    27602642        return;
    27612643    }
    27622644    log_to_screen("Scanning CD-ROM drive...");
    2763     sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);
     2645    mr_asprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);
    27642646    make_hole_for_dir(mtpt);
    27652647
     
    27672649    ok_go_ahead_burn_it = TRUE;
    27682650    if (!find_cdrom_device(cdrom_dev, FALSE)) {
    2769 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
    2770       log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
    2771       retract_CD_tray_and_defeat_autorun();
    2772 */
     2651        /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
     2652        log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
     2653        retract_CD_tray_and_defeat_autorun();
     2654        */
    27732655        mr_asprintf(tmp, "umount %s", cdrom_dev);
    27742656        run_program_and_log_output(tmp, 1);
    2775         sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
    2776         sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
    2777         sprintf(szunmount, "umount %s", mtpt);
     2657        mr_asprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
     2658        mr_asprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
     2659        mr_asprintf(szunmount, "umount %s", mtpt);
    27782660        cd_number = -1;
    27792661        mr_asprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
     
    27812663        attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1);
    27822664        mr_free(tmp);
     2665
    27832666        if (attempt_to_mount_returned_this) {
    27842667            log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
    27852668            log_to_screen("If there's a CD/DVD in the drive, it's blank.");
    2786             /*
    2787                if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
    2788                {
    2789                ok_go_ahead_burn_it = FALSE;
    2790                log_to_screen("There isn't a writable CD/DVD in the drive.");
    2791                }
    2792                else
    2793                {
    2794                log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
    2795                }
    2796              */
    2797         } else if (!does_file_exist(szcdno)
    2798                    || !does_file_exist(szserfname)) {
     2669        } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) {
    27992670            mds = media_descriptor_string(g_backup_media_type);
    2800             log_to_screen
    2801                 ("%s has data on it but it's probably not a Mondo CD.", mds);
     2671            log_to_screen("%s has data on it but it's probably not a Mondo CD.", mds);
    28022672            mr_free(mds);
    28032673        } else {
     
    28092679            mr_asprintf(tmp, "cat %s 2> /dev/null", szserfname);
    28102680            mr_free(our_serial_str);
    2811             mr_asprintf(our_serial_str, "%s",
    2812                    call_program_and_get_last_line_of_output(tmp));
     2681            mr_asprintf(our_serial_str, "%s", call_program_and_get_last_line_of_output(tmp));
    28132682            mr_free(tmp);
    28142683            // FIXME - should be able to use last_line_of_file(), surely?
    28152684        }
     2685        mr_free(szcdno);
     2686        mr_free(szserfname);
     2687
    28162688        run_program_and_log_output(szunmount, 1);
     2689        mr_free(szunmount);
     2690
    28172691        log_msg(2, "paafcd: cd_number = %d", cd_number);
    2818         log_msg(2, "our serial str = %s; g_serial_string = %s",
    2819                 our_serial_str, g_serial_string);
     2692        log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string);
    28202693        if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
    28212694            mds = media_descriptor_string(g_backup_media_type);
     
    28492722        }
    28502723        mds = media_descriptor_string(g_backup_media_type);
    2851         mr_asprintf(tmp, "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    2852                 mds, g_current_media_number, mds);
     2724        mr_asprintf(tmp, "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.", mds, g_current_media_number, mds);
    28532725        mr_free(mds);
    28542726
     
    28612733
    28622734    mds = media_descriptor_string(g_backup_media_type);
    2863     log_msg(2,
    2864             "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds);
     2735    log_msg(2, "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds);
    28652736
    28662737    log_to_screen("Proceeding w/ %s in drive.", mds);
     
    28692740    paranoid_free(cdrom_dev);
    28702741    paranoid_free(cdrw_dev);
    2871     paranoid_free(mtpt);
    2872     paranoid_free(szcdno);
    2873     paranoid_free(szserfname);
    2874     paranoid_free(szunmount);
     2742    mr_free(mtpt);
    28752743    if (pmountable) {
    28762744        if (attempt_to_mount_returned_this) {
     
    28822750
    28832751}
    2884 
    2885 
    2886 
    2887 
    2888 
    2889 
    28902752
    28912753
     
    29172779
    29182780/* @} - end of utilityGroup */
    2919 
    2920 
    2921 
    2922 
    2923 
    2924 
    29252781
    29262782
     
    29452801 */
    29462802int
    2947 slice_up_file_etc(char *biggie_filename,
    2948                   char *ntfsprog_fifo, long biggie_file_number,
    2949                   long noof_biggie_files, bool use_ntfsprog)
    2950 {
     2803slice_up_file_etc(char *biggie_filename, char *ntfsprog_fifo, long biggie_file_number, long noof_biggie_files, bool use_ntfsprog) {
    29512804
    29522805    /*@ buffers ************************************************** */
    29532806    char *tmp = NULL;
    2954     char *checksum_line, *command;
    2955     char *tempblock;
     2807    char *checksum_line = NULL;
     2808    char *command = NULL;
     2809    char *tempblock = NULL;
    29562810    char *curr_slice_fname_uncompressed = NULL;
    29572811    char *curr_slice_fname_compressed = NULL;
    29582812    char *file_to_archive = NULL;
    2959     char *file_to_openin;
     2813    char *file_to_openin = NULL;
    29602814    /*@ pointers ************************************************** */
    2961     char *pB;
    2962     FILE *fin = NULL, *fout = NULL;
     2815    char *pB = NULL;
     2816    FILE *fin = NULL;
     2817    FILE *fout = NULL;
    29632818
    29642819    /*@ bool ****************************************************** */
     
    29662821
    29672822    /*@ long ****************************************************** */
    2968     size_t blksize = 0;
    2969     long slice_num = 0;
    2970     long i;
    2971     long optimal_set_size;
    2972     bool should_I_compress_slices;
     2823    size_t blksize = (size_t)0;
     2824    long slice_num = 0L;
     2825    long i = 0L;
     2826    bool should_I_compress_slices = TRUE;
    29732827    char *suffix = NULL;                // for compressed slices
    29742828
     
    29832837    /*@ structures ************************************************** */
    29842838    struct s_filename_and_lstat_info biggiestruct;
    2985 //  struct stat statbuf;
    29862839
    29872840    assert(bkpinfo != NULL);
    29882841    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    2989     malloc_string(checksum_line);
    29902842
    29912843    biggiestruct.for_backward_compatibility = '\n';
    29922844    biggiestruct.use_ntfsprog = use_ntfsprog;
    2993     optimal_set_size = bkpinfo->optimal_set_size;
    2994     if (is_this_file_compressed(biggie_filename)
    2995         || bkpinfo->compression_level == 0) {
     2845    if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0) {
    29962846        mr_asprintf(suffix, "%s", "");
    2997         //      log_it("%s is indeed compressed :-)", filename);
    29982847        should_I_compress_slices = FALSE;
    29992848    } else {
     
    30022851    }
    30032852
    3004     if (optimal_set_size < 999) {
     2853    if (bkpinfo->optimal_set_size < 999L) {
    30052854        fatal_error("bkpinfo->optimal_set_size is insanely small");
    30062855    }
     2856
    30072857    if (ntfsprog_fifo) {
    30082858        file_to_openin = ntfsprog_fifo;
    3009         strcpy(checksum_line, "IGNORE");
    3010         log_msg(2,
    3011                 "Not calculating checksum for %s: it would take too long",
    3012                 biggie_filename);
     2859        mr_asprintf(checksum_line, "IGNORE");
     2860        log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename);
    30132861        if ( !find_home_of_exe("ntfsresize")) {
    30142862            fatal_error("ntfsresize not found");
     
    30202868        log_it("res of it = %s", tmp);
    30212869        totallength = (off_t)atoll(tmp);
    3022         paranoid_free(tmp);
     2870        mr_free(tmp);
    30232871    } else {
    30242872        file_to_openin = biggie_filename;
     
    30342882        }
    30352883        mr_free(command);
    3036         tmp = fgets(checksum_line, MAX_STR_LEN, fin);
     2884        mr_getline(checksum_line, fin);
    30372885        pclose(fin);
    30382886        totallength = length_of_file (biggie_filename);
     
    30482896    }
    30492897    strcpy(biggiestruct.checksum, checksum_line);
     2898    mr_free(checksum_line);
    30502899
    30512900    mr_asprintf(tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     
    30532902    if (fout == NULL) {
    30542903        log_msg(1, "Unable to open and write to %s\n", tmp);
    3055         paranoid_free(tmp);
     2904        mr_free(tmp);
    30562905        mr_free(suffix);
    30572906        return (1);
    30582907    }
    3059     paranoid_free(tmp);
     2908    mr_free(tmp);
    30602909
    30612910    res = fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
     
    30632912        paranoid_fclose(fout);
    30642913    }
    3065     log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
    3066             file_to_openin);
     2914    log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin);
    30672915    if (!(fin = fopen(file_to_openin, "r"))) {
    30682916        log_OS_error("Unable to openin biggie_filename");
    3069         mr_asprintf(tmp, "Cannot archive bigfile '%s': not found", biggie_filename);
    3070         log_to_screen(tmp);
    3071         paranoid_free(tmp);
    3072 
    3073         paranoid_free(checksum_line);
     2917        log_to_screen("Cannot archive bigfile '%s': not found", biggie_filename);
     2918
    30742919        mr_free(suffix);
    30752920        return (1);
     
    30942939        mr_asprintf(tmp, "%s", percent_media_full_comment());
    30952940        update_progress_form(tmp);
    3096         paranoid_free(tmp);
     2941        mr_free(tmp);
    30972942
    30982943        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
     
    31012946            return (1);
    31022947        }
    3103         if ((i == bkpinfo->optimal_set_size / 256)
    3104             && (totalread < 1.1 * totallength)) {
    3105             for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
     2948        if ((i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength)) {
     2949            for (i = 0L; i < bkpinfo->optimal_set_size / 256; i++) {
    31062950                blksize = fread(tempblock, 1, 256 * 1024, fin);
    31072951                if (blksize > 0) {
     
    31122956                }
    31132957            }
     2958            mr_free(tempblock);
    31142959        } else {
    3115             i = 0;
     2960            i = 0L;
    31162961        }
    31172962        paranoid_fclose(fout);
    3118         if (i > 0)              // length_of_file (curr_slice_fname_uncompressed)
     2963        if (i > 0L)             // length_of_file (curr_slice_fname_uncompressed)
    31192964        {
    31202965            if (!does_file_exist(curr_slice_fname_uncompressed)) {
    3121                 log_msg(2,
    3122                         "Warning - '%s' doesn't exist. How can I compress slice?",
    3123                         curr_slice_fname_uncompressed);
     2966                log_msg(2, "Warning - '%s' doesn't exist. How can I compress slice?", curr_slice_fname_uncompressed);
    31242967            }
    31252968            if (should_I_compress_slices && bkpinfo->compression_level > 0) {
     
    31412984                log_msg(2, "Failed to compress the slice");
    31422985            }
    3143             if (bkpinfo->use_lzo
    3144                 && strcmp(curr_slice_fname_compressed,
    3145                           curr_slice_fname_uncompressed)) {
     2986            if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed)) {
    31462987                unlink(curr_slice_fname_uncompressed);
    31472988            }
     
    31492990                mr_asprintf(tmp, "Problem with slice # %ld", slice_num);
    31502991            } else {
    3151                 mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK          ", biggie_filename, biggie_file_number + 1,
    3152                         slice_num);
    3153             }
    3154 #ifndef _XWIN
     2992                mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK          ", biggie_filename, biggie_file_number + 1, slice_num);
     2993            }
    31552994            if (!g_text_mode) {
    31562995                newtDrawRootText(0, g_noof_rows - 2, tmp);
     
    31592998                log_msg(2, tmp);
    31602999            }
    3161 #else
    3162             log_msg(2, tmp);
    3163 #endif
    3164             paranoid_free(tmp);
     3000            mr_free(tmp);
    31653001
    31663002            mr_asprintf(file_to_archive, "%s", curr_slice_fname_compressed);
     
    31783014
    31793015        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    3180             register_in_tape_catalog(biggieslice, biggie_file_number,
    3181                                      slice_num, file_to_archive);
    3182             maintain_collection_of_recent_archives(bkpinfo->tmpdir,
    3183                                                    file_to_archive);
     3016            register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive);
     3017            maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive);
    31843018            res = move_files_to_stream(file_to_archive, NULL);
    31853019        } else {
     
    31903024        retval += res;
    31913025        if (res) {
    3192             mr_asprintf(tmp, "Failed to add slice %ld of bigfile %ld to scratchdir", slice_num, biggie_file_number + 1);
    3193             log_to_screen(tmp);
    3194             paranoid_free(tmp);
    3195             fatal_error
    3196                 ("Hard disk full. You should have bought a bigger one.");
    3197         }
    3198     }
    3199     mr_free(tempblock);
     3026            log_to_screen("Failed to add slice %ld of bigfile %ld to scratchdir", slice_num, biggie_file_number + 1);
     3027            fatal_error("Hard disk full. You should have bought a bigger one.");
     3028        }
     3029    }
    32003030    mr_free(suffix);
    32013031    paranoid_fclose(fin);
     
    32073037    }
    32083038    log_msg(1, tmp);
    3209     paranoid_free(tmp);
    3210 
    3211     paranoid_free(checksum_line);
     3039    mr_free(tmp);
     3040
    32123041    return (retval);
    32133042}
     
    32883117    log_msg(2, tmp);
    32893118    center_string(tmp, 80);
    3290 #ifndef _XWIN
    32913119    if (!g_text_mode) {
    32923120        newtPushHelpLine(tmp);
    32933121    }
    3294 #endif
    32953122    res = write_iso_and_go_on(TRUE);
    3296 #ifndef _XWIN
    32973123    if (!g_text_mode) {
    32983124        newtPopHelpLine();
    32993125    }
    3300 #endif
    33013126    log_msg(2, "Returning from writing final ISO (res=%d)", res);
    33023127    paranoid_free(tmp);
     
    33273152
    33283153    /*@ buffers ***************************************************** */
    3329     char *tmp;
    3330     char *cdno_fname;
    3331     char *lastcd_fname;
    3332     char *isofile;
     3154    char *tmp = NULL;
     3155    char *tmp1 = NULL;
     3156    char *cdno_fname = NULL;
     3157    char *lastcd_fname = NULL;
     3158    char *isofile = NULL;
    33333159    char *mds = NULL;
    33343160
     
    33413167
    33423168    malloc_string(tmp);
    3343     malloc_string(cdno_fname);
    3344     malloc_string(lastcd_fname);
    3345     malloc_string(isofile);
    33463169
    33473170    assert(bkpinfo != NULL);
     
    33573180    /* label the ISO with its number */
    33583181
    3359     sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
     3182    mr_asprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
    33603183    fout = fopen(cdno_fname, "w");
     3184    mr_free(cdno_fname);
     3185
    33613186    fprintf(fout, "%d", g_current_media_number);
    33623187    paranoid_fclose(fout);
    33633188
    3364     sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home,
    3365             bkpinfo->scratchdir);
    3366     if (run_program_and_log_output(tmp, FALSE)) {
     3189    mr_asprintf(tmp1, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir);
     3190    if (run_program_and_log_output(tmp1, FALSE)) {
    33673191        log_msg(2, "Warning - unable to copy autorun to scratchdir");
    33683192    }
     3193    mr_free(tmp1);
    33693194
    33703195    /* last CD or not? Label accordingly */
    3371     sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
     3196    mr_asprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    33723197    if (last_cd) {
    33733198        unlink(lastcd_fname);
     
    33803205        paranoid_fclose(fout);
    33813206    }
     3207    mr_free(lastcd_fname);
     3208
    33823209    if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) {
    3383         sprintf(tmp,
    3384                 "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
    3385                 (long) space_occupied_by_cd(bkpinfo->scratchdir),
    3386                 (long) bkpinfo->media_size);
    3387         log_to_screen(tmp);
    3388     }
    3389     sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
     3210        log_to_screen("Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",(long) space_occupied_by_cd(bkpinfo->scratchdir),(long) bkpinfo->media_size);
     3211    }
     3212    mr_asprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
    33903213            bkpinfo->netfs_remote_dir, bkpinfo->prefix,
    33913214            g_current_media_number);
     
    34023225            {
    34033226                log_msg(3, "*Sigh* Mike, I hate your computer.");
     3227                // if it can't be found then force pausing
    34043228                bkpinfo->manual_cd_tray = TRUE;
    3405             }                   // if it can't be found then force pausing
    3406             else {
     3229            } else {
    34073230                log_msg(3, "Great. Found Mike's CD-ROM drive.");
    34083231            }
     
    34103233        if (bkpinfo->verify_data && !res) {
    34113234            mds = media_descriptor_string(g_backup_media_type);
    3412             log_to_screen
    3413                 ("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds);
     3235            log_to_screen("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds);
    34143236            mr_free(mds);
    34153237            if (chdir("/")) {
     
    34283250        } else {
    34293251            mds = media_descriptor_string(bkpinfo->backup_media_type);
    3430             sprintf(tmp, "Failed to create %s #%d. Retry?", mds, g_current_media_number);
     3252            mr_asprintf(tmp1, "Failed to create %s #%d. Retry?", mds, g_current_media_number);
    34313253            mr_free(mds);
    3432             res = ask_me_yes_or_no(tmp);
     3254            res = ask_me_yes_or_no(tmp1);
     3255            mr_free(tmp1);
     3256
    34333257            if (!res) {
    34343258                if (ask_me_yes_or_no("Abort the backup?")) {
     
    34433267        }
    34443268    }
     3269    mr_free(isofile);
     3270
    34453271    g_current_media_number++;
    34463272    wipe_archives(bkpinfo->scratchdir);
    3447     sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
    3448             bkpinfo->scratchdir, bkpinfo->scratchdir);
    3449     if (system(tmp)) {
    3450         log_msg
    3451             (2,
    3452              "Error occurred when I tried to delete the redundant IMGs and GZs");
    3453     }
     3273    mr_asprintf(tmp1, "rm -Rf %s/images/*gz %s/images/*data*img", bkpinfo->scratchdir, bkpinfo->scratchdir);
     3274    if (system(tmp1)) {
     3275        log_msg(2, "Error occurred when I tried to delete the redundant IMGs and GZs");
     3276    }
     3277    mr_free(tmp1);
    34543278
    34553279    if (last_cd) {
     
    34613285    bkpinfo->verify_data = orig_vfy_flag_val;
    34623286    paranoid_free(tmp);
    3463     paranoid_free(cdno_fname);
    3464     paranoid_free(lastcd_fname);
    3465     paranoid_free(isofile);
    34663287    return (0);
    34673288}
     
    35323353            if (res) {
    35333354                mds = media_descriptor_string(bkpinfo->backup_media_type);
    3534                 mr_asprintf(tmp, "Warnings/errors were reported while checking %s #%d", mds, g_current_media_number);
     3355                log_to_screen("Warnings/errors were reported while checking %s #%d", mds, g_current_media_number);
    35353356                mr_free(mds);
    3536                 log_to_screen(tmp);
    3537                 mr_free(tmp);
    35383357
    35393358            }
  • branches/3.2/mondo/src/common/libmondo-cli.c

    r3185 r3191  
    9797    for (i = 0; i < 128; i++) {
    9898        if (flag_set[i]) {
    99             mr_asprintf(tmp, "-%c %s", i, flag_val[i]);
    100             log_msg(3, tmp);
    101             mr_free(tmp);
     99            log_msg(3, "-%c %s", i, flag_val[i]);
    102100        }
    103101    }
     
    150148    char *tmp = NULL;
    151149    char *tmp1 = NULL;
     150    char *tmp2 = NULL;
    152151    char *psz = NULL;
    153152    char *p = NULL;
     
    208207            log_msg(1, "Using star instead of afio");
    209208        } else {
    210             fatal_error
    211                 ("Neither afio nor star is installed. Please install at least one.");
     209            fatal_error("Neither afio nor star is installed. Please install at least one.");
    212210        }
    213211    }
     
    219217        }
    220218        if (!find_home_of_exe("star")) {
    221             fatal_error
    222                 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
     219            fatal_error("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
    223220        }
    224221    }
     
    234231
    235232    if (flag_set['I']) {
    236         if (bkpinfo->include_paths[0] == '-') {
     233        if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') {
    237234            retval++;
    238235            log_to_screen("Please supply a sensible value with '-I'\n");
     
    268265            }
    269266        }
    270         paranoid_free(tmp1);
     267        mr_free(tmp1);
    271268        mr_make_devlist_from_pathlist(flag_val['I'], 'I');
    272269        log_msg(4, "Finished with the -I option");
    273270    }
    274271
    275     if (g_kernel_version >= 2.6 && !flag_set['d']
    276         && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
    277         fatal_error
    278             ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
     272    if (g_kernel_version >= 2.6 && !flag_set['d'] && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
     273        fatal_error("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
    279274    }
    280275
     
    283278        if (flag_set['I']) {
    284279            retval++;
    285             log_to_screen
    286                 ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
     280            log_to_screen("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
    287281        }
    288282        bkpinfo->make_filelist = FALSE;
    289         strcpy(bkpinfo->include_paths, flag_val['J']);
     283        mr_asprintf(bkpinfo->include_paths, "%s", flag_val['J']);
    290284    }
    291285
    292286    if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
    293         if (!flag_set['r'] && g_kernel_version <= 2.5
    294             && strstr(flag_val['d'], "/dev/")) {
    295             fatal_error
    296                 ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
    297         }
    298         if (flag_set['r'] && g_kernel_version <= 2.5
    299             && !strstr(flag_val['d'], "/dev/")) {
    300             fatal_error
    301                 ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
     287        if (!flag_set['r'] && g_kernel_version <= 2.5 && strstr(flag_val['d'], "/dev/")) {
     288            fatal_error("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
     289        }
     290        if (flag_set['r'] && g_kernel_version <= 2.5 && !strstr(flag_val['d'], "/dev/")) {
     291            fatal_error("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
    302292        }
    303293        if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
    304             log_to_screen
    305                 ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
    306         }
    307 
    308         if (system("which cdrecord > /dev/null 2> /dev/null")
    309             && system("which dvdrecord > /dev/null 2> /dev/null")) {
    310             fatal_error
    311                 ("Please install dvdrecord/cdrecord and try again.");
     294            log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
     295        }
     296
     297        if (system("which cdrecord > /dev/null 2> /dev/null") && system("which dvdrecord > /dev/null 2> /dev/null")) {
     298            fatal_error("Please install dvdrecord/cdrecord and try again.");
    312299        }
    313300        if (flag_set['C']) {
    314301            bkpinfo->cdrw_speed = atoi(flag_val['C']);
    315302            if (bkpinfo->cdrw_speed < 1) {
    316                 fatal_error
    317                     ("You specified a silly speed for a CD-R[W] drive");
     303                fatal_error("You specified a silly speed for a CD-R[W] drive");
    318304            }
    319305            if (!flag_set['L']) {
    320                 log_to_screen
    321                     ("You must use -L with -C. Therefore I am setting it for you.");
     306                log_to_screen("You must use -L with -C. Therefore I am setting it for you.");
    322307                flag_set['L'] = 1;
    323308                flag_val['L'][0] = '\0';
     
    326311            log_msg(3, "flag_val['c'] = %s", flag_val['c']);
    327312            log_msg(3, "flag_val['w'] = %s", flag_val['w']);
    328 //    log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
    329313            if (flag_set['c']) {
    330314                bkpinfo->cdrw_speed = atoi(flag_val['c']);
     
    336320
    337321            if (bkpinfo->cdrw_speed < 1) {
    338                 fatal_error
    339                     ("You specified a silly speed for a CD-R[W] drive");
     322                fatal_error("You specified a silly speed for a CD-R[W] drive");
    340323            }
    341324        }
     
    345328        log_it("Hmm! No tape drive specified. Let's see what we can do.");
    346329        if (find_tape_device_and_size(flag_val['d'], tmp)) {
    347             fatal_error
    348                 ("Tape device not specified. I couldn't find it either.");
     330            fatal_error("Tape device not specified. I couldn't find it either.");
    349331        }
    350332        flag_set['d'] = TRUE;
    351         sprintf(tmp,
    352                 "You didn't specify a tape streamer device. I'm assuming %s",
    353                 flag_val['d']);
    354         log_to_screen(tmp);
     333        log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']);
    355334    }
    356335
     
    358337    {
    359338        if (! flag_set['d']) {
    360             fatal_error
    361                 ("You need to specify a device file with -d for bootable USB device usage");
     339            fatal_error("You need to specify a device file with -d for bootable USB device usage");
    362340        }
    363341        if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
     
    369347    {
    370348        if (flag_set['m']) {
    371             fatal_error
    372                 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
     349            fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
    373350        }
    374351        if (!flag_set['d']) {
     
    379356        }
    380357        if (strchr(flag_val['d'], ',')) {
    381             fatal_error
    382                 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
     358            fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
    383359        }
    384360        if (! bkpinfo->restore_data) {
    385361            if (!find_home_of_exe("growisofs")) {
    386                 fatal_error
    387                     ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
     362                fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    388363            }
    389364            if (!find_home_of_exe("dvd+rw-format")) {
    390                 fatal_error
    391                     ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
     365                fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    392366            }
    393367            if (!flag_set['s']) {
    394368                sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE);    // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    395369                strcat(flag_val['s'], "m");
    396                 log_to_screen
    397                     ("You did not specify a size (-s) for DVD. I'm guessing %s.",
    398                     flag_val['s']);
     370                log_to_screen("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']);
    399371                flag_set['s'] = 1;
    400372            }
    401373        }
    402 /*
    403       if (flag_set['Z']) {
    404       bkpinfo->blank_dvd_first = TRUE;
    405       }
    406 */
    407374    }
    408375
    409376    if (flag_set['t'] || flag_set['u']) {   /* tape size */
    410377        if (strchr(flag_val['d'], ',')) {
    411             fatal_error
    412                 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
     378            fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
    413379        }
    414380        if ((flag_set['O']) && (! bkpinfo->restore_data)) {
    415381            if (flag_set['s']) {
    416382                if (flag_set['t']) {
    417                     fatal_error
    418                         ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
     383                    fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
    419384                }
    420385                if (process_the_s_switch(flag_val['s'])) {
     
    440405
    441406    if (flag_set['n']) {
    442         strncpy(bkpinfo->netfs_mount, flag_val['n'], MAX_STR_LEN);
     407        mr_free(bkpinfo->netfs_mount);
     408        mr_asprintf(bkpinfo->netfs_mount, "%s", flag_val['n']);
    443409        if (!flag_set['d']) {
    444             strncpy(bkpinfo->netfs_remote_dir, "/", MAX_STR_LEN);
     410            mr_free(bkpinfo->netfs_remote_dir);
     411            mr_asprintf(bkpinfo->netfs_remote_dir, "/");
    445412        }
    446413        /* test for protocol */
     
    473440        /* Store the 2 values */
    474441        /*  using memmove instead of strcpy as per #584 */
    475         memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN);
     442        /* memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN); */
     443        bkpinfo->netfs_mount = p;
    476444
    477445        /* test if we specified a user */
     
    479447        if (p != NULL) {
    480448            /* User found. Store the 2 values */
     449            bkpinfo->netfs_user = bkpinfo->netfs_mount;
    481450            p++;
    482451            /* new netfs mount */
    483             strcpy(tmp,p);
     452            mr_asprintf(bkpinfo->netfs_mount, "%s", p);
     453            /* now that user is computed, create the right value by removing end of string */
    484454            p--;
    485455            *p = '\0';
    486             mr_asprintf(q,"%s",bkpinfo->netfs_mount);
    487             bkpinfo->netfs_user = q;
    488             strcpy(bkpinfo->netfs_mount,tmp);
    489         }
    490         sprintf(tmp, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user,
    491                 bkpinfo->netfs_mount);
    492         strncpy(bkpinfo->isodir,
    493                 call_program_and_get_last_line_of_output(tmp),
    494                 MAX_STR_LEN / 4);
     456        }
     457        mr_asprintf(tmp1, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount);
     458        strncpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp), MAX_STR_LEN / 4);
     459        mr_free(tmp1);
     460
    495461        if (strlen(bkpinfo->isodir) < 3) {
    496462            log_to_screen("Network share is not mounted. Trying to mount it for you.\n");
    497463            if (bkpinfo->netfs_user) {
    498464                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
    499                     sprintf(tmp, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
     465                    mr_asprintf(tmp1, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
    500466                } else if (strstr(bkpinfo->netfs_proto, "smbfs")) {
    501                     sprintf(tmp, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user);
     467                    mr_asprintf(tmp1, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user);
    502468                } else if (strstr(bkpinfo->netfs_proto, "nfs")) {
    503                     sprintf(tmp, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
     469                    mr_asprintf(tmp1, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
    504470                } else {
    505471                    log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto);
     
    508474            } else {
    509475                if (strstr(bkpinfo->netfs_proto, "sshfs")) {
    510                     sprintf(tmp, "sshfs %s", bkpinfo->netfs_mount);
     476                    mr_asprintf(tmp1, "sshfs %s", bkpinfo->netfs_mount);
    511477                } else if (strstr(bkpinfo->netfs_proto, "smbfs")) {
    512                     sprintf(tmp, "mount -t cifs %s", bkpinfo->netfs_mount);
     478                    mr_asprintf(tmp1, "mount -t cifs %s", bkpinfo->netfs_mount);
    513479                } else if (strstr(bkpinfo->netfs_proto, "nfs")) {
    514                     sprintf(tmp, "mount %s", bkpinfo->netfs_mount);
     480                    mr_asprintf(tmp1, "mount %s", bkpinfo->netfs_mount);
    515481                } else {
    516482                    log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto);
     
    518484                }
    519485            }
    520             if (system(tmp)) {
     486            i = system(tmp1);
     487            mr_free(tmp1);
     488
     489            if (i) {
    521490                log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
    522491                retval++;
    523492            } else {
    524493                if (bkpinfo->netfs_user) {
    525                     sprintf(tmp, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user,
    526                         bkpinfo->netfs_mount);
     494                    mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount);
    527495                } else {
    528                     sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
     496                    mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
    529497                }
    530                 strncpy(bkpinfo->isodir,
    531                         call_program_and_get_last_line_of_output(tmp),
    532                         MAX_STR_LEN / 4);
     498                strncpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp), MAX_STR_LEN / 4);
    533499                if (strlen(bkpinfo->isodir) < 3) {
    534500                    retval++;
     
    624590            }
    625591        }
    626         paranoid_free(tmp1);
     592        mr_free(tmp1);
    627593
    628594        mr_make_devlist_from_pathlist(flag_val['E'], 'E');
     
    668634        log_msg(1, "Internal tape block size is now %ld bytes", itbs);
    669635        if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
    670             fatal_error
    671                 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
     636            fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
    672637        }
    673638        bkpinfo->internal_tape_block_size = itbs;
     
    678643//      bkpinfo->differential = atoi (flag_val['D']);
    679644        if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
    680             fatal_error
    681                 ("The D option should be between 1 and 9 inclusive");
     645            fatal_error("The D option should be between 1 and 9 inclusive");
    682646        }
    683647    }
     
    702666            && !does_file_exist(bkpinfo->kernel_path)) {
    703667            retval++;
    704             sprintf(tmp,
    705                     "You specified kernel '%s', which does not exist\n",
    706                     bkpinfo->kernel_path);
    707             log_to_screen(tmp);
     668            log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path);
    708669        }
    709670    }
     
    723684            }
    724685        } else if (flag_set['n']) {
    725             strncpy(bkpinfo->netfs_remote_dir, flag_val['d'], MAX_STR_LEN);
     686            mr_free(bkpinfo->netfs_remote_dir);
     687            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
    726688        } else {                /* backup device (if tape/CD-R/CD-RW) */
    727689            strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
     
    732694        mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir);
    733695        if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
    734             sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
     696            mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
    735697        } else {
    736             sprintf(tmp, "echo hi > %s", tmp1);
    737         }
    738         if (run_program_and_log_output(tmp, 2)) {
    739             retval++;
    740             sprintf(tmp,
    741                     "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
    742                     bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);
    743             log_to_screen(tmp);
     698            mr_asprintf(tmp2, "echo hi > %s", tmp1);
     699        }
     700        i = run_program_and_log_output(tmp2, 2);
     701        mr_free(tmp2);
     702
     703        if (i) {
     704            retval++;
     705            log_to_screen("Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);
    744706        }
    745707        unlink(tmp1);
    746         paranoid_free(tmp1);
    747     }
    748 
    749     if (!flag_set['d']
    750         && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
     708        mr_free(tmp1);
     709    }
     710
     711    if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
    751712        if (g_kernel_version >= 2.6) {
    752713            if (popup_and_get_string
     
    769730        retval++;
    770731        log_to_screen("Please specify the backup device/directory.\n");
    771         fatal_error
    772             ("You didn't use -d to specify the backup device/directory.");
     732        fatal_error("You didn't use -d to specify the backup device/directory.");
    773733    }
    774734
     
    781741    if (flag_set['S']) {
    782742        setup_scratchdir(flag_val['S']);
    783         sprintf(tmp, "touch %s/.foo.dat", bkpinfo->scratchdir);
    784         if (run_program_and_log_output(tmp, 1)) {
    785             retval++;
     743        mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->scratchdir);
     744        if (run_program_and_log_output(tmp1, 1)) {
     745            retval++;
     746            mr_free(tmp1);
    786747            log_to_screen("Please specify a scratchdir which I can write to. :)");
    787748            fatal_error("I cannot write to the scratchdir you specified.");
    788749        }
    789         sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->scratchdir, bkpinfo->scratchdir);
    790         if (run_program_and_log_output(tmp, 1)) {
    791             retval++;
     750        mr_free(tmp1);
     751
     752        mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->scratchdir, bkpinfo->scratchdir);
     753        if (run_program_and_log_output(tmp1, 1)) {
     754            retval++;
     755            mr_free(tmp1);
    792756            log_to_screen("Please don't specify a SAMBA or VFAT or NFS scratchdir.");
    793757            fatal_error("I cannot write to the scratchdir you specified.");
    794758        }
     759        mr_free(tmp1);
    795760    }
    796761
    797762    if (flag_set['T']) {
    798763        setup_tmpdir(flag_val['T']);
    799         sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir);
    800         if (run_program_and_log_output(tmp, 1)) {
     764        mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir);
     765        i = run_program_and_log_output(tmp1, 1);
     766        mr_free(tmp1);
     767
     768        if (i) {
    801769            retval++;
    802770            log_to_screen("Please specify a tempdir which I can write to. :)");
    803771            fatal_error("I cannot write to the tempdir you specified.");
    804772        }
    805         sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
    806         if (run_program_and_log_output(tmp, 1)) {
     773        mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
     774        i = run_program_and_log_output(tmp1, 1);
     775        mr_free(tmp1);
     776
     777        if (i) {
    807778            retval++;
    808779            log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
     
    833804#  endif
    834805#endif
    835         if (!strchr
    836             (BOOT_LOADER_CHARS,
    837              (bkpinfo->boot_loader = flag_val['l'][0]))) {
    838             log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
    839                     bkpinfo->boot_loader, bkpinfo->boot_loader);
    840             fatal_error
    841                 ("Please specify GRUB, LILO, ELILO  or RAW with the -l switch");
     806        if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) {
     807            log_msg(1, "%c? What is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader);
     808            fatal_error("Please specify GRUB, LILO, ELILO  or RAW with the -l switch");
    842809        }
    843810#undef BOOT_LOADER_CHARS
     
    845812
    846813    if (flag_set['f']) {
    847         strncpy(bkpinfo->boot_device,
    848                 resolve_softlinks_to_get_to_actual_device_file(flag_val
    849                                                                ['f']),
    850                 MAX_STR_LEN / 4);
     814        strncpy(bkpinfo->boot_device, resolve_softlinks_to_get_to_actual_device_file(flag_val['f']),MAX_STR_LEN / 4);
    851815    }
    852816
     
    866830        if (run_program_and_log_output("which lzop", 2)) {
    867831            retval++;
    868             log_to_screen
    869                 ("Please install LZOP. You can't use '-L' until you do.\n");
     832            log_to_screen("Please install LZOP. You can't use '-L' until you do.\n");
    870833        }
    871834    }
     
    880843        if (run_program_and_log_output("which gzip", 2)) {
    881844            retval++;
    882             log_to_screen
    883                 ("Please install gzip. You can't use '-G' until you do.\n");
     845            log_to_screen("Please install gzip. You can't use '-G' until you do.\n");
     846        }
     847    }
     848
     849    if ((flag_set['Y']) && (! bkpinfo->restore_data)) {
     850        bkpinfo->use_lzma = TRUE;
     851        if (run_program_and_log_output("which lzma", 2)) {
     852            retval++;
     853            log_to_screen("Please install lzma. You can't use '-Y' until you do.\n");
    884854        }
    885855    }
     
    897867    if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
    898868        bkpinfo->make_cd_use_lilo = TRUE;
    899         log_to_screen
    900             ("Your kernel appears not to support vfat filesystems. I am therefore");
    901         log_to_screen
    902             ("using LILO instead of SYSLINUX as the media boot loader.");
     869        log_to_screen("Your kernel appears not to support vfat filesystems. I am therefore");
     870        log_to_screen("using LILO instead of SYSLINUX as the media boot loader.");
    903871    }
    904872    if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
    905873        bkpinfo->make_cd_use_lilo = TRUE;
    906874#ifdef __IA32__
    907         log_to_screen
    908             ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
    909         log_to_screen
    910             ("your boot loader. I shall therefore use LILO instead.");
     875        log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
     876        log_to_screen("your boot loader. I shall therefore use LILO instead.");
    911877#endif
    912878#ifdef __IA64__
    913         log_to_screen
    914             ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
     879        log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
    915880        log_to_screen("environment correctly. Please install it.");
    916881        fatal_error("Aborting");
     
    932897
    933898    if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
    934             fatal_error
    935                 ("The -Z switch is only valid in restore mode");
     899            fatal_error("The -Z switch is only valid in restore mode");
    936900    }
    937901
     
    973937 * @return The number of problems with the command line (0 for success).
    974938 */
    975 int
    976 retrieve_switches_from_command_line(int argc, char *argv[],
    977                                     char flag_val[128][MAX_STR_LEN],
    978                                     bool flag_set[128])
     939int retrieve_switches_from_command_line(int argc, char *argv[], char flag_val[128][MAX_STR_LEN], bool flag_set[128])
    979940{
    980941    /*@ ints ** */
    981942    int opt = 0;
    982     char *tmp = NULL;
    983943    int i = 0;
    984944    int len;
     
    994954        flag_set[i] = FALSE;
    995955    }
    996     while ((opt =
    997             getopt(argc, argv, MONDO_OPTIONS))
    998            != -1) {
     956    while ((opt = getopt(argc, argv, MONDO_OPTIONS)) != -1) {
    999957        if (opt == '?') {
    1000958            bad_switches = TRUE;
    1001             /*log_it("Invalid option: %c\n",optopt); */
    1002959        } else {
    1003960            if (flag_set[opt]) {
    1004961                bad_switches = TRUE;
    1005                 mr_asprintf(tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]);
    1006                 log_to_screen(tmp);
    1007                 paranoid_free(tmp);
     962                log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]);
    1008963            } else {
    1009964                flag_set[opt] = TRUE;
     
    1019974                        if (strchr(flag_val[opt], '/')
    1020975                            && flag_val[opt][0] != '/') {
    1021                             mr_asprintf(tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
    1022                             log_to_screen(tmp);
    1023                             paranoid_free(tmp);
     976                            log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
    1024977                            bad_switches = TRUE;
    1025978                        }
     
    1032985    for (i = optind; i < argc; i++) {
    1033986        bad_switches = TRUE;
    1034         mr_asprintf(tmp, "Invalid arg -- %s\n", argv[i]);
    1035         log_to_screen(tmp);
    1036         paranoid_free(tmp);
     987        log_to_screen("Invalid arg -- %s\n", argv[i]);
    1037988    }
    1038989    return (bad_switches);
     
    10971048    mr_strcat(tmp, " signal received from OS");
    10981049    log_to_screen(tmp);
    1099     paranoid_free(tmp);
     1050    mr_free(tmp);
    11001051
    11011052    log_to_screen(tmp2);
    1102     paranoid_free(tmp2);
     1053    mr_free(tmp2);
    11031054    if (sig == SIGABRT) {
    11041055        sleep(10);
     
    11081059    free_MR_global_filenames();
    11091060
    1110     fatal_error
    1111         ("MondoRescue is terminating in response to a signal from the OS");
     1061    fatal_error("MondoRescue is terminating in response to a signal from the OS");
    11121062    finish(254);                // just in case
    11131063}
     
    11221072void set_signals(int on)
    11231073{
    1124     int signals[] =
    1125         { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
     1074    int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
    11261075    int i;
    11271076
  • branches/3.2/mondo/src/common/libmondo-devices-EXT.h

    r3154 r3191  
    1616extern int find_device_in_mountlist(struct mountlist_itself *mountlist,
    1717                                    char *device);
    18 extern int mount_CDROM_here(char *device, char *mountpoint);
     18extern int mount_CDROM_here(char *device, const char *mountpoint);
    1919extern long long size_of_specific_device_in_mountlist(struct
    2020                                                      mountlist_itself
     
    5757extern int inject_device(char *dev);
    5858extern bool does_nonMS_partition_exist(void);
    59 extern char *resolve_softlinks_to_get_to_actual_device_file(char
    60                                                             *incoming);
     59extern char *resolve_softlinks_to_get_to_actual_device_file(char *incoming);
    6160
    6261extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value();
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3185 r3191  
    2121#include "libmondo-stream-EXT.h"
    2222
     23extern void mr_strip_spaces(char *);
     24
    2325#include <sys/types.h>
    2426#ifdef __FreeBSD__
     
    127129{
    128130    char *tmp = NULL;
    129     char *comment;
    130131    bool is_this_a_ramdisk = FALSE;
    131132
    132     malloc_string(comment);
    133133    mr_asprintf(tmp, "%s", where_is_root_mounted());
    134     sprintf(comment, "root is mounted at %s\n", tmp);
    135     log_msg(0, comment);
    136     log_msg(0,
    137             "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().",
    138             tmp);
     134    log_msg(0, "root is mounted at %s\n", tmp);
     135    log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp);
    139136
    140137#ifdef __FreeBSD__
     
    156153    if (is_this_a_ramdisk) {
    157154        if (!does_file_exist("/THIS-IS-A-RAMDISK")) {
    158             log_to_screen
    159                 ("Using /dev/root is stupid of you but I'll forgive you.");
     155            log_to_screen("Using /dev/root is stupid of you but I'll forgive you.");
    160156            is_this_a_ramdisk = FALSE;
    161157        }
     
    164160        is_this_a_ramdisk = TRUE;
    165161    }
    166     paranoid_free(comment);
    167     log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
     162
     163    log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE");
    168164    return (is_this_a_ramdisk);
    169165}
     
    229225int eject_device(char *dev)
    230226{
    231     char *command;
     227    char *command = NULL;
    232228    int res1 = 0, res2 = 0;
    233229
    234     malloc_string(command);
     230    if (dev == NULL) {
     231        return (1);
     232    }
    235233
    236234    if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
    237235        && g_backup_media_type != udev) {
    238         sprintf(command, "mt -f %s offline", dev);
     236        mr_asprintf(command, "mt -f %s offline", dev);
    239237        res1 = run_program_and_log_output(command, 1);
     238        mr_free(command);
    240239    } else {
    241240        res1 = 0;
     
    244243#ifdef __FreeBSD__
    245244    if (strstr(dev, "acd")) {
    246         sprintf(command, "cdcontrol -f %s eject", dev);
     245        mr_asprintf(command, "cdcontrol -f %s eject", dev);
    247246    } else {
    248         sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",
    249                 dev);
     247        mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
    250248    }
    251249#else
    252     sprintf(command, "eject %s", dev);
     250    mr_asprintf(command, "eject %s", dev);
    253251#endif
    254252
    255253    log_msg(3, "Ejecting %s", dev);
    256254    res2 = run_program_and_log_output(command, 1);
    257     paranoid_free(command);
     255    mr_free(command);
    258256    if (res1 && res2) {
    259257        return (1);
     
    270268int inject_device(char *dev)
    271269{
    272     char *command;
     270    char *command = NULL;
    273271    int i;
    274272
    275     malloc_string(command);
    276 
     273    if (dev == NULL) {
     274        return (1);
     275    }
    277276
    278277#ifdef __FreeBSD__
    279278    if (strstr(dev, "acd")) {
    280         sprintf(command, "cdcontrol -f %s close", dev);
     279        mr_asprintf(command, "cdcontrol -f %s close", dev);
    281280    } else {
    282         sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",
    283                 dev);
     281        mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
    284282    }
    285283#else
    286     sprintf(command, "eject -t %s", dev);
     284    mr_asprintf(command, "eject -t %s", dev);
    287285#endif
    288286    i = run_program_and_log_output(command, FALSE);
    289     paranoid_free(command);
     287    mr_free(command);
    290288    return (i);
    291289}
     
    301299
    302300    /*@ buffers *********************************************************** */
    303     char *tmp;
     301    char *tmp = NULL;
    304302    bool ret;
    305303
    306     malloc_string(tmp);
    307304    assert_string_is_neither_NULL_nor_zerolength(device);
    308305
    309     sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
     306    mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
    310307
    311308    if (system(tmp)) {
     
    314311        ret = TRUE;
    315312    }
    316     paranoid_free(tmp);
     313    mr_free(tmp);
    317314    return (ret);
    318315}
     
    345342{
    346343    /*@ buffers **************************************************** */
    347     char *program;
    348     char *incoming;
     344    char *program = NULL;
     345    char *incoming = NULL;
    349346    char *searchstr = NULL;
    350     char *tmp;
    351     char *p;
    352347
    353348    /*@ ints ******************************************************* */
     
    356351    /*@ pointers *************************************************** */
    357352    FILE *fin;
    358 
    359353
    360354    /*@ end vars *************************************************** */
     
    362356    assert(partno >= 0 && partno < 999);
    363357
    364     malloc_string(program);
    365     malloc_string(incoming);
    366358    malloc_string(searchstr);
    367     malloc_string(tmp);
    368359
    369360#ifdef __FreeBSD__
    370361    // We assume here that this is running from mondorestore. (It is.)
    371     sprintf(program, "ls %s %s >/dev/null 2>&1", drive,
    372             build_partition_name(tmp, drive, partno));
    373     return system(program);
    374 #else
    375     tmp[0] = '\0';
    376 #endif
    377 
    378     sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
     362    mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno));
     363    res = system(program);
     364    mr_free(program);
     365    return(res);
     366#endif
     367
     368    mr_asprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
    379369    fin = popen(program, "r");
    380370    if (!fin) {
    381371        log_it("program=%s", program);
    382372        log_OS_error("Cannot popen-in program");
     373        mr_free(program);
    383374        return (0);
    384375    }
     376    mr_free(program);
     377
    385378    (void) build_partition_name(searchstr, drive, partno);
    386379    strcat(searchstr, " ");
    387     for (res = 0; !res && (p = fgets(incoming, MAX_STR_LEN - 1, fin));) {
     380    for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
    388381        if (strstr(incoming, searchstr)) {
    389382            res = 1;
    390383        }
    391     }
     384        mr_free(incoming);
     385    }
     386    mr_free(incoming);
     387
    392388    if (pclose(fin)) {
    393389        log_OS_error("Cannot pclose fin");
    394390    }
    395     paranoid_free(program);
    396     paranoid_free(incoming);
    397391    paranoid_free(searchstr);
    398     paranoid_free(tmp);
    399392    return (res);
    400393}
     
    413406{
    414407    /*@ buffers **************************************************** */
    415     char *command;
     408    char *command = NULL;
    416409
    417410    /*@ end vars *************************************************** */
     
    421414    assert_string_is_neither_NULL_nor_zerolength(str);
    422415
    423     malloc_string(command);
    424     sprintf(command,
    425             "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    426             dev, str);
     416    /* For UEFI detection, this should be extended to count=2 */
     417    mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str);
    427418    i = system(command);
    428     paranoid_free(command);
     419    mr_free(command);
    429420    if (i) {
    430421        return (FALSE);
     
    444435{
    445436    /*@ buffers **************************************************** */
    446     char *command;
     437    char *command = NULL;
    447438    /*@ end vars *************************************************** */
    448439    int i;
    449440
    450     malloc_string(command);
    451     sprintf(command,
    452             "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    453             dev, n, str);
     441    mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str);
    454442    i = system(command);
    455     paranoid_free(command);
     443    mr_free(command);
    456444    if (i) {
    457445        return (FALSE);
     
    466454 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has
    467455 * not been specified, call find_cdrom_device() to find it.
    468  * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.
    469456 * @param mountpoint Where to mount the CD-ROM.
    470457 * @return 0 for success, nonzero for failure.
    471458 * @see mount_CDROM_here
    472459 */
    473 int find_and_mount_actual_cd(char *mountpoint)
    474 {
     460int find_and_mount_actual_cd(char *mountpoint) {
     461
    475462    /*@ buffers ***************************************************** */
    476463
    477464    /*@ int's  ****************************************************** */
    478465    int res;
    479     char *dev;
     466    char *dev = NULL;
    480467
    481468    /*@ end vars **************************************************** */
     
    532519{
    533520    /*@ buffers ************************ */
    534     char *comment;
    535521    char *tmp = NULL;
    536522    char *cdr_exe = NULL;
    537     char *command;
    538 
    539     malloc_string(comment);
    540     malloc_string(command);
     523    char *command = NULL;
     524
    541525    if (g_cdrw_drive_is_here[0]) {
    542526        strcpy(cdrw_device, g_cdrw_drive_is_here);
    543527        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    544         paranoid_free(comment);
    545         paranoid_free(command);
    546528        return (0);
    547529    }
    548530    if (g_backup_media_type == dvd) {
    549         log_msg(1,
    550                 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    551         paranoid_free(comment);
    552         paranoid_free(command);
     531        log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    553532        return (1);
    554533    }
     
    560539    }
    561540    if (find_home_of_exe(cdr_exe)) {
    562         sprintf(command,
    563                 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1",
    564                 cdr_exe);
     541        mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe);
    565542        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     543        mr_free(command);
    566544    }
    567545    if ((tmp == NULL) || (strlen(tmp) < 2)) {
    568         paranoid_free(comment);
    569546        mr_free(tmp);
    570547        mr_free(cdr_exe);
    571         paranoid_free(command);
    572548        return 1;
    573549    } else {
    574550        strcpy(cdrw_device, tmp);
    575         sprintf(comment, "Found CDRW device - %s", cdrw_device);
    576         log_it(comment);
     551        log_it("Found CDRW device - %s", cdrw_device);
    577552        strcpy(g_cdrw_drive_is_here, cdrw_device);
    578         paranoid_free(comment);
    579553        mr_free(tmp);
    580554        mr_free(cdr_exe);
    581         paranoid_free(command);
    582555        return (0);
    583556    }
    584557}
    585 
    586 
    587558
    588559
     
    609580
    610581    /*@ buffers ***************************************************** */
    611     char *tmp;
     582    char *tmp = NULL;
    612583    char *tmp1 = NULL;
    613584    char *cdr_exe = NULL;
    614585    char *phrase_one;
    615     char *phrase_two;
    616     char *command;
    617     char *dvd_last_resort;
    618     char *mountpoint;
     586    char *phrase_two = NULL;
     587    char *command = NULL;
     588#ifndef __FreeBSD__
     589    char *dvd_last_resort = NULL;
     590#endif
     591    char *mountpoint = NULL;
    619592    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
    620593
     
    622595    malloc_string(tmp);
    623596    malloc_string(phrase_one);
    624     malloc_string(phrase_two);
    625     malloc_string(command);
    626     malloc_string(dvd_last_resort);
    627597    malloc_string(mountpoint);
    628598
    629599    output[0] = '\0';
    630600    phrase_one[0] = '\0';
    631     phrase_two[0] = '\0';
    632     dvd_last_resort[0] = '\0';
    633601
    634602    /*@ end vars **************************************************** */
     
    642610    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
    643611        strcpy(output, the_last_place_i_found_it);
    644         log_msg(3,
    645                 "find_cdrom_device() --- returning last found location - '%s'",
    646                 output);
     612        log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
    647613        retval = 0;
    648614        goto end_of_find_cdrom_device;
     
    671637    }
    672638
    673     sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
     639    mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
    674640    fin = popen(command, "r");
    675641    if (!fin) {
     
    677643        log_OS_error("Cannot popen command");
    678644        mr_free(cdr_exe);
     645        mr_free(command);
    679646        return (1);
    680647    }
     648    mr_free(command);
     649
    681650    for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL);
    682651         tmp1 = fgets(tmp, MAX_STR_LEN, fin)) {
     
    696665                        }
    697666                        *q = '\0';
    698                         strcpy(phrase_two, p);
     667                        mr_asprintf(phrase_two, "%s", p);
    699668                    }
    700669                }
     
    705674
    706675#ifndef __FreeBSD__
    707     if (strlen(phrase_two) == 0) {
     676    if (!phrase_two || strlen(phrase_two) == 0) {
    708677        log_msg(4, "Not running phase two. String is empty.");
    709678    } else {
    710         sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
     679        mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
    711680        fin = popen(command, "r");
     681        mr_free(command);
     682
    712683        if (!fin) {
    713684            log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
     
    721692                        *p = '\0';
    722693                        if (strstr(tmp, "DVD")) {
    723                             sprintf(dvd_last_resort, "/dev/%s", tmp);
    724                             log_msg(4,
    725                                     "Ignoring '%s' because it's a DVD drive",
    726                                     tmp);
     694                            mr_free(dvd_last_resort);
     695                            mr_asprintf(dvd_last_resort, "/dev/%s", tmp);
     696                            log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
    727697                        } else {
    728698                            sprintf(output, "/dev/%s", tmp);
     
    775745#else
    776746    if (!found_it && strlen(dvd_last_resort) > 0) {
    777         log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
    778                 dvd_last_resort);
     747        log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
    779748        strcpy(output, dvd_last_resort);
    780749        found_it = TRUE;
    781750    }
    782751    if (found_it) {
    783         sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
    784                 strrchr(output, '/') + 1);
     752        sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1);
    785753        if (system(tmp) == 0) {
    786             log_msg(4,
    787                     "%s is not right. It's being SCSI-emulated. Continuing.",
    788                     output);
     754            log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    789755            found_it = FALSE;
    790756            output[0] = '\0';
     
    852818                found_it = FALSE;
    853819            } else {
    854                 sprintf(command, "umount %s", output);
     820                mr_asprintf(command, "umount %s", output);
    855821                paranoid_system(command);
     822                mr_free(command);
     823
    856824                log_msg(4, "I'm confident the Mondo CD is in %s", output);
    857825            }
     
    872840    }
    873841
    874     sprintf(command,
    875             "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
    876             cdr_exe, g_cdrw_drive_is_here);
     842    mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here);
     843
    877844    log_msg(1, "command=%s", command);
    878845    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command));
     846    mr_free(command);
     847
    879848    if (strlen(tmp1) > 0) {
    880849        strcpy(output, tmp1);
     
    888857
    889858  end_of_find_cdrom_device:
     859    mr_free(cdr_exe);
     860    mr_free(phrase_two);
     861    mr_free(dvd_last_resort);
     862
    890863    paranoid_free(tmp);
    891     mr_free(cdr_exe);
    892864    paranoid_free(phrase_one);
    893     paranoid_free(phrase_two);
    894     paranoid_free(command);
    895     paranoid_free(dvd_last_resort);
    896865    paranoid_free(mountpoint);
    897866    return (retval);
     
    899868
    900869
    901 
    902 
    903 
    904870int find_dvd_device(char *output, bool try_to_mount)
    905871{
    906     char *command;
    907872    char *tmp;
    908873    int retval = 0, devno = -1;
    909 
    910     malloc_string(command);
    911     malloc_string(tmp);
    912874
    913875    if (g_dvd_drive_is_here[0]) {
     
    917879    }
    918880
    919     sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     881    malloc_string(tmp);
     882    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
    920883    log_msg(5, "tmp = '%s'", tmp);
    921     if (!tmp[0])
    922         sprintf(tmp, "%s", call_program_and_get_last_line_of_output
    923                 ("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")
    924             );
     884    if (!tmp[0]) {
     885        mr_free(tmp);
     886        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     887    }
    925888    if (tmp[0]) {
    926889        devno = atoi(tmp) - 1;
    927890    }
     891    mr_free(tmp);
     892
    928893    if (devno >= 0) {
    929894        retval = 0;
     
    936901    }
    937902
    938     if (try_to_mount) {
    939         log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    940     }
    941903    return (retval);
    942904}
     
    10531015{
    10541016    char *good_formats = NULL;
    1055     char *command;
    1056     char *format_sz;
     1017    char *command = NULL;
     1018    char *format_sz = NULL;
    10571019    char *p;
    10581020
     
    10601022    int retval;
    10611023    malloc_string(good_formats);
    1062     malloc_string(command);
    1063     malloc_string(format_sz);
    10641024
    10651025    assert_string_is_neither_NULL_nor_zerolength(format);
    10661026
    1067     sprintf(format_sz, "%s ", format);
     1027    mr_asprintf(format_sz, "%s ", format);
    10681028
    10691029#ifdef __FreeBSD__
    1070     sprintf(command,
    1071             "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
     1030    mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
    10721031#else
    1073     sprintf(command,
    1074             "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
     1032    mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
    10751033#endif
    10761034
    10771035    pin = popen(command, "r");
     1036    mr_free(command);
     1037
    10781038    if (!pin) {
    10791039        log_OS_error("Unable to read good formats");
     
    10941054    }
    10951055    paranoid_free(good_formats);
    1096     paranoid_free(command);
    1097     paranoid_free(format_sz);
     1056    mr_free(format_sz);
     1057
    10981058    return (retval);
    10991059}
     
    11141074
    11151075    /*@ buffers ***************************************************** */
    1116     char *incoming;
     1076    char *incoming = NULL;
    11171077    char *device_with_tab = NULL;
    11181078    char *device_with_space = NULL;
     
    11281088    /*@ end vars **************************************************** */
    11291089
    1130     malloc_string(incoming);
    1131     assert(device_raw != NULL);
    1132 //  assert_string_is_neither_NULL_nor_zerolength(device_raw);
     1090    if (device_raw == NULL) {
     1091        return(FALSE);
     1092    }
     1093
    11331094    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
    11341095        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     
    11531114        return(FALSE);
    11541115    }
    1155     for (tmp = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (tmp != NULL);
    1156          tmp = fgets(incoming, MAX_STR_LEN - 1, fin)) {
    1157         if (strstr(incoming, device_with_space) //> incoming
    1158             || strstr(incoming, device_with_tab))   // > incoming)
    1159         {
     1116
     1117    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     1118        if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) {
    11601119            paranoid_pclose(fin);
    1161             paranoid_free(incoming);
     1120            mr_free(incoming);
    11621121            return(TRUE);
    11631122        }
    1164     }
     1123        mr_free(incoming);
     1124    }
     1125    mr_free(incoming);
    11651126    mr_free(device_with_tab);
    11661127    paranoid_pclose(fin);
     
    11721133    }
    11731134    mr_free(tmp);
    1174     paranoid_free(incoming);
    11751135    return(retval);
    11761136}
     
    11891149    char command[MAX_STR_LEN];
    11901150    int vndev = 2;
    1191     if (atoi
    1192         (call_program_and_get_last_line_of_output
    1193          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1151    if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
    11941152        do {
    11951153            sprintf(mddevice, "vn%ic", vndev++);
     
    12231181int kick_vn(char *dname)
    12241182{
    1225     char command[MAX_STR_LEN];
     1183    char *command = NULL;
     1184    int res = 0;
    12261185
    12271186    if (strncmp(dname, "/dev/", 5) == 0) {
     
    12291188    }
    12301189
    1231     if (atoi
    1232         (call_program_and_get_last_line_of_output
    1233          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
    1234         sprintf(command, "vnconfig -d %s", dname);
    1235         return system(command);
     1190    if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1191        mr_asprintf(command, "vnconfig -d %s", dname);
    12361192    } else {
    1237         sprintf(command, "mdconfig -d -u %s", dname);
    1238         return system(command);
    1239     }
    1240      /*NOTREACHED*/ return 255;
     1193        mr_asprintf(command, "mdconfig -d -u %s", dname);
     1194    }
     1195    res = system(command);
     1196    mr_free(command);
     1197    return(res);
    12411198}
    12421199#endif
     
    12521209{
    12531210    /*@ buffer ****************************************************** */
    1254     char *command;
     1211    char *command = NULL;
    12551212    int retval;
    12561213
    1257     malloc_string(command);
    12581214    assert_string_is_neither_NULL_nor_zerolength(device);
    12591215    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     
    12631219        return(1);
    12641220    }
    1265     log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device,
    1266             mountpoint);
     1221    log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
    12671222
    12681223#ifdef __FreeBSD__
    1269     sprintf(command, "mount_vfat %s %s 2>> %s",
    1270             device, mountpoint, MONDO_LOGFILE);
     1224    mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
    12711225
    12721226#else
    1273     sprintf(command, "mount %s -t vfat %s 2>> %s",
    1274             device, mountpoint, MONDO_LOGFILE);
     1227    mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
    12751228#endif
    12761229
     
    12781231    retval = system(command);
    12791232    log_msg(1, "system(%s) returned %d", command, retval);
    1280 
    1281     paranoid_free(command);
     1233    mr_free(command);
     1234
    12821235    return (retval);
    12831236}
     
    12891242 * @return 0 for success, nonzero for failure.
    12901243 */
    1291 int mount_CDROM_here(char *device, char *mountpoint)
     1244int mount_CDROM_here(char *device, const char *mountpoint)
    12921245{
    12931246    /*@ buffer ****************************************************** */
     
    13271280
    13281281    }
    1329     log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
    1330             mountpoint);
     1282    log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
    13311283    /*@ end vars *************************************************** */
    13321284
     
    13451297    retval = system(command);
    13461298    log_msg(1, "system(%s) returned %d", command, retval);
    1347     paranoid_free(command);
     1299    mr_free(command);
    13481300
    13491301    return (retval);
     
    13621314int mount_media()
    13631315{
    1364 char *mount_cmd;
     1316char *mount_cmd = NULL;
    13651317char *mountdir = NULL;
    13661318int i, res;
    13671319#ifdef __FreeBSD__
    1368 char mdd[32];
    1369 char *mddev = mdd;
    1370 #endif
    1371 
    1372 malloc_string(mount_cmd);
    1373 assert(bkpinfo != NULL);
    1374 
    1375     if (bkpinfo->backup_media_type == tape
    1376         || bkpinfo->backup_media_type == udev) {
     1320    char mdd[32];
     1321    char *mddev = mdd;
     1322#endif
     1323
     1324    if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
    13771325        log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
    1378         paranoid_free(mount_cmd);
    13791326        return 0;
    13801327    }
     
    13821329    if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
    13831330        log_msg(2, "mount_media() - media already mounted. Fair enough.");
    1384         paranoid_free(mount_cmd);
    13851331        return (0);
    13861332    }
     
    13891335        log_msg(2, "Mounting for Network thingy");
    13901336        log_msg(2, "isodir = %s", bkpinfo->isodir);
    1391         if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    1392             && am_I_in_disaster_recovery_mode()) {
     1337        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
    13931338            strcpy(bkpinfo->isodir, "/tmp/isodir");
    13941339            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    13951340        }
    13961341#ifdef __FreeBSD__
    1397         sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
     1342        mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
    13981343            bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
    13991344        mddev = make_vn(mount_cmd);
    1400         sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     1345        mr_free(mount_cmd);
     1346
     1347        mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    14011348#else
    1402         sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
    1403             bkpinfo->isodir, bkpinfo->netfs_remote_dir,
    1404             bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1349        mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    14051350#endif
    14061351
     
    14121357        }
    14131358#ifdef __FreeBSD__
    1414         sprintf(mount_cmd, "%s/%s-%d.iso", mountdir,
    1415             bkpinfo->prefix, g_current_media_number);
     1359        mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
    14161360        mddev = make_vn(mount_cmd);
    1417         sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     1361        mr_free(mount_cmd);
     1362
     1363        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    14181364#else
    1419         sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
    1420             mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1365        mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    14211366#endif
    14221367        mr_free(mountdir);
    14231368    } else if (bkpinfo->backup_media_type == usb) {
    1424         sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
     1369        mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
    14251370    } else if (strstr(bkpinfo->media_device, "/dev/")) {
    14261371#ifdef __FreeBSD__
    1427         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    1428         MNT_CDROM);
     1372        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
    14291373#else
    1430         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    1431         bkpinfo->media_device, MNT_CDROM);
     1374        mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
    14321375#endif
    14331376    } else {
     
    14411384
    14421385#ifdef __FreeBSD__
    1443     sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    1444         MNT_CDROM);
     1386        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
    14451387#else
    1446     sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    1447         bkpinfo->media_device, MNT_CDROM);
     1388        mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
    14481389#endif
    14491390    }
     
    14571398            log_msg(2, "Failed to mount device.");
    14581399            sleep(5);
    1459             run_program_and_log_output("sync", FALSE);
    1460         }
    1461     }
     1400            sync();
     1401        }
     1402    }
     1403    mr_free(mount_cmd);
    14621404
    14631405    if (res) {
     
    14661408        log_msg(2, "Mounted media drive OK");
    14671409    }
    1468     paranoid_free(mount_cmd);
    14691410    return (res);
    14701411}
     
    14961437
    14971438    /*@ buffers ********************************************************* */
    1498     char *tmp;
     1439    char *tmp = NULL;
    14991440    char *mds = NULL;
    1500     char *request;
     1441    char *request = NULL;
    15011442
    15021443    assert(bkpinfo != NULL);
     
    15101451        return;
    15111452    }
    1512     if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
    1513         || bkpinfo->backup_media_type == netfs) {
     1453    mr_asprintf(tmp, "mkdir -p " MNT_CDROM);
     1454    run_program_and_log_output(tmp, 5);
     1455    mr_free(tmp);
     1456
     1457    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
    15141458        g_ISO_restore_mode = TRUE;
    15151459    }
    1516     malloc_string(tmp);
    1517     malloc_string(request);
    1518     sprintf(tmp, "mkdir -p " MNT_CDROM);
    1519     run_program_and_log_output(tmp, 5);
    15201460    if ((res = what_number_cd_is_this()) != cd_number_i_want) {
    1521         log_msg(3, "Currently, we hold %d but we want %d", res,
    1522                 cd_number_i_want);
     1461        log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
    15231462
    15241463        /* Now we need to umount the current media to have the next mounted after */
     
    15291468
    15301469        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1531         sprintf(tmp, "Insisting on %s #%d", mds, cd_number_i_want);
    1532         sprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
     1470        log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
     1471        mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
    15331472        mr_free(mds);
    1534         log_msg(3, tmp);
     1473
    15351474        while (what_number_cd_is_this() != cd_number_i_want) {
    1536             paranoid_system("sync");
     1475            sync();
    15371476            if (is_this_device_mounted(MNT_CDROM)) {
    15381477                res =
     
    15561495                inject_device(bkpinfo->media_device);
    15571496            }
    1558             paranoid_system("sync");
    1559         }
     1497            sync();
     1498        }
     1499        mr_free(request);
     1500
    15601501        log_msg(1, "Thankyou. Proceeding...");
    15611502        g_current_media_number = cd_number_i_want;
    15621503    }
    1563     paranoid_free(tmp);
    1564     paranoid_free(request);
    15651504}
    15661505
     
    16761615    log_msg(5, "Running: %s", command);
    16771616    mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    1678     paranoid_free(command);
     1617    mr_free(command);
    16791618
    16801619    mount_cnt = atoi(mounted_file_system);
    16811620    log_msg (5, "mount_cnt: %d", mount_cnt);
    1682     paranoid_free(mounted_file_system);
     1621    mr_free(mounted_file_system);
    16831622
    16841623    for (i=mount_cnt; i > 0; i--) {
     
    16861625        log_msg(5, "Running: %s", command);
    16871626        mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    1688         paranoid_free(command);
     1627        mr_free(command);
    16891628
    16901629        log_msg (5, "mounted_file_system: %s", mounted_file_system);
    16911630        if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
    16921631            log_msg (4, "Could not get the list of mounted file systems");
    1693             paranoid_free(mounted_file_system);
     1632            mr_free(mounted_file_system);
    16941633            mr_free(token);
    16951634            return (1);
     
    17191658        mr_free(mounted_file_system);
    17201659    }
    1721     /********
    1722     * DSFptr = DSF_Head;
    1723     * while (DSFptr != NULL) {
    1724     * printf ("Dev: %s  MP: %s  Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
    1725     * DSFptr = DSFptr->next;
    1726     * }
    1727     ********/
    17281660    return (0);
    17291661}
     
    17731705    log_msg(5, "  Executing: %s", command);
    17741706    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1775     paranoid_free(command);
     1707    mr_free(command);
    17761708
    17771709    log_msg(5, "  Return value: %s", tmp);
    17781710    c = atoi(tmp);
    1779     paranoid_free(tmp);
     1711    mr_free(tmp);
    17801712
    17811713    if (!c) {
     
    17991731    log_msg(5, "Executing: %s", command);
    18001732    mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
    1801     paranoid_free(command);
     1733    mr_free(command);
    18021734    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
    18031735    if (!strlen(partition_list)) {
     
    18621794        log_msg(4, "Processing partition: %s", partitions[i]);
    18631795        /* See if it's swap. If it is, ignore it. */
    1864         mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    1865           ndsf, partitions[i]);
     1796        mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
    18661797        log_msg(5, "  Running: %s", command);
    18671798        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1868         paranoid_free(command);
     1799        mr_free(command);
     1800
    18691801        log_msg(5, "  Return value: %s", tmp);
    18701802        c = strlen(tmp);
    1871         paranoid_free(tmp);
     1803        mr_free(tmp);
     1804
    18721805        if (c) {
    18731806            log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
    18741807            continue;
    18751808        }
     1809
    18761810        /* It's not swap. See if we can find the mount point from the mount command. */
    18771811        mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    18781812        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1879         paranoid_free(command);
     1813        mr_free(command);
     1814
    18801815        if (strlen(tmp)) {
    18811816            log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
    18821817            if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
    18831818                log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
    1884                 paranoid_free(tmp);
     1819                mr_free(tmp);
    18851820                return (1);
    18861821            }
    18871822            DSFptr->check = 1;
    1888             paranoid_free(tmp);
     1823            mr_free(tmp);
    18891824            continue;
    18901825        }
    1891         paranoid_free(tmp);
     1826        mr_free(tmp);
     1827
    18921828        /* It's not swap and it's not mounted. See if it's LVM */
    18931829        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
     1830
    18941831        /* Check for LVM */
    18951832        mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]);
    18961833        log_msg(5, "  Running: %s", command);
    18971834        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1898         paranoid_free(command);
     1835        mr_free(command);
     1836
    18991837        if (strlen(tmp)) {
    19001838            log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
     
    19031841            log_msg(5, "  Running: %s", command);
    19041842            strcpy(VG, call_program_and_get_last_line_of_output(command));
    1905             paranoid_free(command);
     1843            mr_free(command);
     1844
    19061845            log_msg(4, "  Volume Group: %s", VG);
    19071846            if (strlen(VG)) {
     
    19111850                log_msg(5, "  Running: %s", command);
    19121851                mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1913                 paranoid_free(command);
     1852                mr_free(command);
     1853
    19141854                log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    19151855                lastpos = 0;
     
    19181858                    if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    19191859                        log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    1920                         paranoid_free(tmp);
     1860                        mr_free(tmp);
    19211861                        mr_free(token);
    19221862                        return (1);
     
    19291869                 * any of the Logical Volumes on the Volume Group.
    19301870                 *******/
    1931                 paranoid_free(mount_list);
     1871                mr_free(mount_list);
    19321872
    19331873                mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    19341874                log_msg (5, "Running: %s", command);
    19351875                mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1936                 paranoid_free(command);
     1876                mr_free(command);
    19371877                log_msg(4, "  Software raid device list: %s", mount_list);
    19381878                lastpos = 0;
     
    19401880                    mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    19411881                    log_msg (5, "Running: %s", command);
    1942                     paranoid_free(tmp);
     1882                    mr_free(tmp);
    19431883                    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1944                     paranoid_free(command);
     1884                    mr_free(command);
    19451885                    log_msg(4, "Number of Software raid device: %s", tmp);
    19461886                    if (atoi(tmp)) {
     
    19481888                        if ((DSFptr = find_device_in_list(token)) == NULL) {
    19491889                            log_msg (4, "Can't find device %s in mounted file systems list", token);
    1950                             paranoid_free(tmp);
     1890                            mr_free(tmp);
    19511891                            mr_free(token);
    19521892                            return (1);
     
    19591899            } else {
    19601900                log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    1961                 paranoid_free(tmp);
     1901                mr_free(tmp);
    19621902                return (1);
    19631903            }
    1964             paranoid_free(tmp);
     1904            mr_free(tmp);
    19651905            continue;
    19661906        } else {
    19671907            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
    19681908        }
    1969         paranoid_free(tmp);
     1909        mr_free(tmp);
     1910
    19701911        /********
    19711912         * It's not swap, mounted, or LVM. See if it's used in a software raid device.
     
    19751916        log_msg(4, "  Running: %s", command);
    19761917        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1977         paranoid_free(command);
     1918        mr_free(command);
     1919
    19781920        if (!strlen(tmp)) {
    19791921            log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
    1980             paranoid_free(tmp);
     1922            mr_free(tmp);
    19811923            continue;
    19821924        }
    19831925        log_msg (5, "  UUID: %s", tmp);
     1926
    19841927        /* Get the Software raid device list */
    19851928        mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    19861929        log_msg (5, "  Running: %s", command);
    19871930        mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1988         paranoid_free(command);
     1931        mr_free(command);
     1932
    19891933        log_msg(4, "  Software raid device list: %s", mount_list);
    19901934        /* Loop through the software raid device list to see if we can find the partition */
     
    19931937            mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    19941938            log_msg(4, "  Running: %s", command);
    1995             paranoid_free(tmp);
     1939            mr_free(tmp);
    19961940            mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1997             paranoid_free(command);
     1941            mr_free(command);
     1942
    19981943            if (!atoi(tmp)) {
    19991944                log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
     
    20011946                if ((DSFptr = find_device_in_list(token)) == NULL) {
    20021947                    log_msg (4, "Can't find device %s in mounted file systems list", token);
    2003                     paranoid_free(tmp);
     1948                    mr_free(tmp);
    20041949                    mr_free(token);
    20051950                    return (1);
     
    20101955            mr_free(token);
    20111956        }
    2012         paranoid_free(tmp);
    2013         paranoid_free(mount_list);
     1957        mr_free(tmp);
     1958        mr_free(mount_list);
    20141959    }
    20151960
     
    20471992    return (0);
    20481993}
    2049 
    2050 
    2051 
    20521994
    20531995
     
    20992041            log_to_screen("Archiving only the following file systems on %s:", token);
    21002042            log_to_screen("==> %s", mounted_on_dsf);
    2101             strcpy(bkpinfo->include_paths, "/");
     2043            mr_free(bkpinfo->include_paths);
     2044            mr_asprintf(bkpinfo->include_paths, "%s", "/");
    21022045            if (strlen(not_mounted_on_dsf)) {
    21032046                log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
     
    21362079            mr_asprintf(tmp,"|%s|",bkpinfo->include_paths);
    21372080            if (strstr(tmp,tmp2) == NULL) {
    2138                 strcat(bkpinfo->include_paths,tmp1);
     2081                mr_strcat(bkpinfo->include_paths, "%s", tmp1);
    21392082            }
    21402083            mr_free(tmp1);
     
    21812124    char *q = NULL;
    21822125    char p[16*MAX_STR_LEN];
    2183     char *sz_size;
    2184     char *command;
     2126    char *sz_size = NULL;
     2127    char *command = NULL;
    21852128    char *compression_type = NULL;
    2186     char *comment;
    2187     char *prompt;
     2129    char *comment = NULL;
    21882130    int i;
    21892131    FILE *fin;
    21902132
    2191     malloc_string(sz_size);
    2192     malloc_string(command);
    2193     malloc_string(comment);
    2194     malloc_string(prompt);
    21952133    malloc_string(tmp1);
    21962134    assert(bkpinfo != NULL);
    2197     sz_size[0] = '\0';
    21982135    bkpinfo->nonbootable_backup = FALSE;
    21992136
     
    22322169        setup_scratchdir(tmp);
    22332170    }
    2234     log_msg(3, "media type = %s",
    2235             bkptype_to_string(bkpinfo->backup_media_type));
     2171    log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    22362172    bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    2237     bkpinfo->compression_level =
    2238         (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
    2239     bkpinfo->use_lzo =
    2240         (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
     2173    bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     2174    bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
    22412175    mvaddstr_and_log_it(2, 0, " ");
    22422176
     
    22532187        if (archiving_to_media) {
    22542188            if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
    2255                 if (ask_me_yes_or_no
    2256                     ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
    2257                 {
     2189                if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {
    22582190                    bkpinfo->manual_cd_tray = TRUE;
    22592191                }
     
    22632195                finish(1);
    22642196            }
    2265             if ((bkpinfo->compression_level =
    2266                 which_compression_level()) == -1) {
     2197
     2198            if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    22672199                log_to_screen("User has chosen not to backup the PC");
    22682200                finish(1);
    22692201            }
    22702202            mds = media_descriptor_string(bkpinfo->backup_media_type);
    2271             sprintf(comment, "What speed is your %s (re)writer?", mds);
     2203            mr_asprintf(comment, "What speed is your %s (re)writer?", mds);
    22722204            if (bkpinfo->backup_media_type == dvd) {
    22732205                find_dvd_device(bkpinfo->media_device, FALSE);
    22742206                strcpy(tmp1, "1");
    2275                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2207                mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    22762208                log_msg(1, "Setting to DVD defaults");
    22772209            } else {
    22782210                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    22792211                strcpy(tmp1, "4");
    2280                 strcpy(sz_size, "650");
     2212                mr_asprintf(sz_size, "%d", 650);
    22812213                log_msg(1, "Setting to CD defaults");
    22822214            }
     
    22842216                if (!popup_and_get_string("Speed", comment, tmp1, 4)) {
    22852217                    log_to_screen("User has chosen not to backup the PC");
     2218                    mr_free(comment);
    22862219                    finish(1);
    22872220                }
    22882221            }
     2222            mr_free(comment);
    22892223            bkpinfo->cdrw_speed = atoi(tmp1);   // if DVD then this shouldn't ever be used anyway :)
    22902224
    2291             sprintf(comment,
    2292                     "How much data (in Megabytes) will each %s store?", mds);
     2225            strcpy(tmp1, sz_size);
     2226            mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);
    22932227            mr_free(mds);
    2294             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     2228            if (!popup_and_get_string("Size", comment, tmp1, 5)) {
    22952229                log_to_screen("User has chosen not to backup the PC");
    22962230                finish(1);
    22972231            }
     2232            mr_asprintf(sz_size, "%s", tmp1);
    22982233            bkpinfo->media_size = atoi(sz_size);
     2234
    22992235            if (bkpinfo->media_size <= 0) {
    23002236                log_to_screen("User has chosen not to backup the PC");
     
    23082244        if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
    23092245            strcpy(bkpinfo->media_device, "/dev/cdrom");
    2310             log_msg(2, "CD-ROM device assumed to be at %s",
    2311                     bkpinfo->media_device);
    2312         } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))
    2313                    || bkpinfo->backup_media_type == dvd) {
     2246            log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
     2247        } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))  || bkpinfo->backup_media_type == dvd) {
    23142248            if (!bkpinfo->media_device[0]) {
    23152249                strcpy(bkpinfo->media_device, "/dev/cdrom");
    23162250            }                   // just for the heck of it :)
    2317             log_msg(1, "bkpinfo->media_device = %s",
    2318                     bkpinfo->media_device);
    2319             if (bkpinfo->backup_media_type == dvd
    2320                 || find_cdrom_device(bkpinfo->media_device, FALSE)) {
    2321                 log_msg(1, "bkpinfo->media_device = %s",
    2322                         bkpinfo->media_device);
    2323                 sprintf(comment,
    2324                         "Please specify your %s drive's /dev entry", mds);
    2325                 if (!popup_and_get_string
    2326                     ("Device?", comment, bkpinfo->media_device,
    2327                      MAX_STR_LEN / 4)) {
     2251            log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     2252            if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) {
     2253                log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     2254                mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
     2255                if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) {
    23282256                    log_to_screen("User has chosen not to backup the PC");
    23292257                    finish(1);
     
    23992327            } else {
    24002328                if (does_file_exist("/tmp/mondo-restore.cfg")) {
    2401                     read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
    2402                                  bkpinfo->media_device);
     2329                    read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device);
    24032330                }
    24042331            }
     
    24552382                finish(1);
    24562383            }
    2457             if ((bkpinfo->compression_level =
    2458                  which_compression_level()) == -1) {
     2384            if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    24592385                log_to_screen("User has chosen not to backup the PC");
    24602386                finish(1);
     
    24682394        /* Never try to eject a NETFS device */
    24692395        bkpinfo->please_dont_eject = TRUE;
     2396        /*  Force NFS to be the protocol by default */
     2397        if (bkpinfo->netfs_proto == NULL) {
     2398            mr_asprintf(bkpinfo->netfs_proto, "nfs");
     2399        }
    24702400
    24712401        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
    2472         if (!bkpinfo->netfs_mount[0]) {
    2473             strcpy(bkpinfo->netfs_mount,
    2474                    call_program_and_get_last_line_of_output
    2475                    ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     2402        if (!bkpinfo->netfs_mount == NULL) {
     2403            mr_asprintf(bkpinfo->netfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
    24762404        }
    24772405#ifdef __FreeBSD__
     
    24842412                ("Network shared dir.",
    24852413                 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)",
    2486                  bkpinfo->netfs_mount, MAX_STR_LEN / 4)) {
     2414                 p, MAX_STR_LEN / 4)) {
    24872415                log_to_screen("User has chosen not to backup the PC");
    24882416                finish(1);
    24892417            }
     2418            mr_free(bkpinfo->netfs_mount);
     2419            mr_asprintf(bkpinfo->netfs_mount, "%s", p;
    24902420            if (!bkpinfo->restore_data) {
    24912421                if ((compression_type = which_compression_type()) == NULL) {
     
    24932423                    finish(1);
    24942424                }
    2495                 if ((bkpinfo->compression_level =
    2496                     which_compression_level()) == -1) {
     2425
     2426                if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    24972427                    log_to_screen("User has chosen not to backup the PC");
    24982428                    finish(1);
     
    25012431            // check whether already mounted - we better remove
    25022432            // surrounding spaces and trailing '/' for this
    2503             strip_spaces(bkpinfo->netfs_mount);
     2433            mr_strip_spaces(bkpinfo->netfs_mount);
    25042434            if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
    25052435                bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
     
    25132443                strcpy(tmp1,bkpinfo->netfs_mount);
    25142444            }
    2515             sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
     2445            mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
    25162446            strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
     2447            mr_free(command);
    25172448
    25182449            if (!bkpinfo->restore_data) {
    2519                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    2520                 sprintf(comment,
    2521                     "How much data (in Megabytes) will each media store?");
    2522                 if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     2450                mr_sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);   // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2451                mr_asprintf(comment, "How much data (in Megabytes) will each media store?");
     2452                strcpy(tmp1, sz_size);
     2453                mr_free(sz_size);
     2454                if (!popup_and_get_string("Size", comment, tmp1, 5)) {
    25232455                    log_to_screen("User has chosen not to backup the PC");
    25242456                    finish(1);
    25252457                }
     2458                mr_free(comment);
     2459                mr_asprintf(sz_size, "%s", tmp1);
    25262460            } else {
    2527                 strcpy(sz_size, "0");
     2461                mr_asprintf(sz_size, "0");
    25282462            }
    25292463            bkpinfo->media_size = atoi(sz_size);
     2464            mr_free(sz_size);
     2465
    25302466            if (bkpinfo->media_size < 0) {
    25312467                log_to_screen("User has chosen not to backup the PC");
     
    25332469            }
    25342470        }
    2535         /*  Force NFS to be the protocol by default */
    2536         if (bkpinfo->netfs_proto == NULL) {
    2537             mr_asprintf(bkpinfo->netfs_proto, "nfs");
    2538         }
    25392471        if (bkpinfo->disaster_recovery) {
    2540             sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
     2472            mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
    25412473            paranoid_system(command);
     2474            mr_free(command);
     2475
    25422476        }
    25432477        strcpy(tmp1, bkpinfo->netfs_proto);
    2544         if (!popup_and_get_string
    2545             ("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",
    2546              tmp1, MAX_STR_LEN)) {
     2478        if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) {
    25472479            log_to_screen("User has chosen not to backup the PC");
    25482480            finish(1);
     
    25502482        mr_free(bkpinfo->netfs_proto);
    25512483        mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1);
    2552         if (!popup_and_get_string
    2553             ("Network share", "Which remote share should I mount?",
    2554              bkpinfo->netfs_mount, MAX_STR_LEN)) {
     2484
     2485        strcpy(tmp1, bkpinfo->netfs_mount);
     2486        if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) {
    25552487            log_to_screen("User has chosen not to backup the PC");
    25562488            finish(1);
    25572489        }
     2490        mr_free(bkpinfo->netfs_mount);
     2491        mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1);
    25582492
    25592493        if (bkpinfo->netfs_user) {
     
    25622496            strcpy(tmp1, "");
    25632497        }
    2564         if (!popup_and_get_string
    2565             ("Network user", "Which user should I use if any ?",
    2566              tmp1, MAX_STR_LEN)) {
     2498        if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1)) {
    25672499            log_to_screen("User has chosen not to backup the PC");
    25682500            finish(1);
     
    25752507        /* Initiate bkpinfo isodir path from running environment if mount already done */
    25762508        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    2577             strcpy(bkpinfo->isodir,
    2578                    call_program_and_get_last_line_of_output
    2579                    ("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
     2509            strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
    25802510        } else {
    25812511            sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
    2582             sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     2512            mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
    25832513            run_program_and_log_output(command, 5);
     2514            mr_free(command);
    25842515
    25852516            if (bkpinfo->restore_data) {
     
    26152546        }
    26162547        if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
    2617             popup_and_OK
    2618                 ("Please mount that partition before you try to backup to or restore from it.");
     2548            popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
    26192549            finish(1);
    26202550        }
     
    26402570        log_msg(3, "prefix set to %s", bkpinfo->prefix);
    26412571
    2642         log_msg(3, "Just set netfs_remote_dir to %s",
    2643                 bkpinfo->netfs_remote_dir);
     2572        log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
    26442573        log_msg(3, "isodir is still %s", bkpinfo->isodir);
    26452574        break;
     
    26592588                    finish(1);
    26602589                }
    2661                 if ((bkpinfo->compression_level =
    2662                      which_compression_level()) == -1) {
     2590                if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    26632591                    log_to_screen("User has chosen not to backup the PC");
    26642592                    finish(1);
    26652593                }
    2666                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2594                sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    26672595                if (!popup_and_get_string
    26682596                    ("ISO size.",
    26692597                     "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.",
    2670                      sz_size, 16)) {
     2598                     tmp1, 16)) {
    26712599                    log_to_screen("User has chosen not to backup the PC");
    26722600                    finish(1);
    26732601                }
    2674                 bkpinfo->media_size = atoi(sz_size);
     2602                bkpinfo->media_size = atoi(tmp1);
    26752603            } else {
    26762604                bkpinfo->media_size = 650;
     
    27232651                finish(1);
    27242652            }
    2725             if (does_string_exist_in_boot_block
    2726                 (bkpinfo->boot_device, "LILO")) {
     2653            if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
    27272654                i = 'L';
    27282655            } else
    2729                 if (does_string_exist_in_boot_block
    2730                     (bkpinfo->boot_device, "ELILO")) {
     2656                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
    27312657                i = 'E';
    27322658            } else
    2733                 if (does_string_exist_in_boot_block
    2734                     (bkpinfo->boot_device, "GRUB")) {
     2659                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
    27352660                i = 'G';
    27362661            } else {
     
    27392664#endif
    27402665            if (i == 'U') {
    2741                 if (ask_me_yes_or_no
    2742                     ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
    2743                 {
     2666                if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {
    27442667                    i = 'R';    // raw
    27452668                } else {
    2746                     log_to_screen
    2747                         ("I cannot find your boot loader. Please run mondoarchive with parameters.");
     2669                    log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
    27482670                    finish(1);
    27492671                }
     
    27512673        }
    27522674        bkpinfo->boot_loader = i;
    2753         strcpy(bkpinfo->include_paths, "/");
     2675
     2676        mr_free(bkpinfo->include_paths);
     2677        strcpy(tmp1, "/");
    27542678        if (!popup_and_get_string
    27552679            ("Backup paths",
    27562680             "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).",
    2757              bkpinfo->include_paths, MAX_STR_LEN)) {
     2681             tmp1, MAX_STR_LEN)) {
    27582682            log_to_screen("User has chosen not to backup the PC");
    27592683            finish(1);
    27602684        }
     2685        mr_asprintf(bkpinfo->include_paths, "%s", tmp1);
     2686
    27612687        tmp = list_of_NETFS_mounts_only();
    27622688        if (strlen(tmp) > 2) {
     
    28152741        if (ask_me_yes_or_no("Do you want to backup extended attributes?")) {
    28162742            if (find_home_of_exe("getfattr")) {
     2743                mr_free(g_getfattr);
    28172744                mr_asprintf(g_getfattr,"getfattr");
    28182745            }
    28192746            if (find_home_of_exe("getfacl")) {
     2747                mr_free(g_getfacl);
    28202748                mr_asprintf(g_getfacl,"getfacl");
    28212749            }
     
    28352763            strcpy(bkpinfo->zip_exe, "gzip");
    28362764            strcpy(bkpinfo->zip_suffix, "gz");
    2837         //} else if (strcmp(compression_type,"lzma") == 0) {
     2765        } else if (strcmp(compression_type,"lzma") == 0) {
    28382766            //strcpy(bkpinfo->zip_exe, "xy");
    28392767            //strcpy(bkpinfo->zip_suffix, "xy");
     
    28492777            ("Will you want to verify your backups after Mondo has created them?");
    28502778
    2851 #ifndef __FreeBSD__
    2852         if (!ask_me_yes_or_no
    2853             ("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."))
    2854 #endif
    2855         {
    2856             strcpy(bkpinfo->kernel_path, "FAILSAFE");
    2857         }
    2858 
    28592779        if (!ask_me_yes_or_no
    28602780            ("Are you sure you want to proceed? Hit 'no' to abort.")) {
     
    28752795#else
    28762796    if (bkpinfo->backup_media_type == netfs) {
    2877         log_msg(3, "I think the Remote mount is mounted at %s",
    2878                 bkpinfo->isodir);
     2797        log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
    28792798    }
    28802799    log_it("isodir = %s", bkpinfo->isodir);
    2881     log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     2800    if (bkpinfo->netfs_mount) {
     2801        log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     2802    }
     2803    if (bkpinfo->netfs_user) {
     2804        log_it("netfs_user = '%s'", bkpinfo->netfs_user);
     2805    }
    28822806    if (bkpinfo->netfs_proto) {
    28832807        log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
    2884     }
    2885     if (bkpinfo->netfs_user) {
    2886         log_it("netfs_user = '%s'", bkpinfo->netfs_user);
    28872808    }
    28882809#endif
     
    28912812    log_it("media size = %ld", bkpinfo->media_size);
    28922813    log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    2893     log_it("prefix = %s", bkpinfo->prefix);
     2814    if (bkpinfo->prefix) {
     2815        log_it("prefix = %s", bkpinfo->prefix);
     2816    }
    28942817    log_it("compression = %ld", bkpinfo->compression_level);
    28952818    log_it("exclude_path = %s", bkpinfo->exclude_paths);
     
    28972820
    28982821    /* Handle devices passed in bkpinfo and print result */
    2899     /*  the mr_make_devlist_from_pathlist function appends 
    2900      *  to the *_paths variables so copy before */
     2822    /*  the mr_make_devlist_from_pathlist function appends
     2823    /*  to the *_paths variables so copy before */
    29012824    mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
    29022825    mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
     
    29042827    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
    29052828    log_it("tmpdir = '%s'", bkpinfo->tmpdir);
    2906     log_it("image_devs = '%s'", bkpinfo->image_devs);
    2907     log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device,
    2908            bkpinfo->boot_loader);
     2829    if (bkpinfo->image_devs) {
     2830        log_it("image_devs = '%s'", bkpinfo->image_devs);
     2831    }
     2832    log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
    29092833    if (bkpinfo->media_size < 0) {
    29102834        if (archiving_to_media) {
     
    29172841    paranoid_free(sz_size);
    29182842    paranoid_free(tmp1);
    2919     paranoid_free(command);
    2920     paranoid_free(comment);
    2921     paranoid_free(prompt);
    29222843    return (0);
    29232844}
     
    31703091
    31713092    malloc_string(current_drive);
     3093
     3094    /* UEFI is not supported here - but should be managed as a BIOS/UEFI option not a Boot Loader one per se */
    31723095
    31733096#ifdef __IA64__
  • branches/3.2/mondo/src/common/libmondo-fifo.c

    r3185 r3191  
    8585    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
    8686    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
    87     paranoid_system("sync");
     87    sync();
    8888    for (bufsize = wise_upper_limit, res = -1;
    8989         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
    90         mr_asprintf(tmp,
    91                 "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
    92                 internal_tape_block_size, bufsize, 'm');
     90        mr_asprintf(tmp,"dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c", internal_tape_block_size, bufsize, 'm');
    9391        res = run_program_and_log_output(tmp, 2);
    9492        mr_free(tmp);
     
    9694    if (!res) {
    9795        bufsize++;
    98         mr_asprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
    99         log_to_screen(tmp);
    100         mr_free(tmp);
     96        log_to_screen(tmp, "Negotiated max buffer of %d MB ", bufsize);
    10197    } else {
    10298        bufsize = 0;
     
    166162        return;
    167163    }
    168     paranoid_system("sync");
     164    sync();
    169165    mr_asprintf(command, "ps %s | grep -F \"%s\" | grep -Fv grep | awk '{print $2;}' | grep -v PID | head -1", ps_options, g_sz_call_to_buffer);
    170166    log_msg(2, "kill_buffer() --- command = %s", command);
  • branches/3.2/mondo/src/common/libmondo-filelist.c

    r3185 r3191  
    8686
    8787    /*@ pointers ********************** */
    88     char *ptr;
     88    char *ptr = NULL;
    8989    FILE *fout;
    9090
     
    116116    mr_free(tempfile);
    117117
    118     log_it(bkpinfo->image_devs);
    119 
    120     ptr = bkpinfo->image_devs;
    121 
    122     malloc_string(dev);
    123     while (ptr && *ptr) {
    124         strcpy(dev, ptr);
    125         log_it("Examining imagedev %s", dev);
    126         for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
    127         dev[i] = '\0';
    128         if (!strlen(dev)) {
    129             continue;
    130         }
    131         fprintf(fout, "%s\n", dev);
    132         log_it("Adding '%s' to biggielist", dev);
    133         if ((ptr = strchr(ptr, ' '))) {
    134             ptr++;
     118    if (bkpinfo->image_devs) {
     119        log_it("image_devs : %s", bkpinfo->image_devs);
     120
     121        ptr = bkpinfo->image_devs;
     122
     123        while (ptr && *ptr) {
     124            mr_asprintf(dev, "%s", ptr);
     125            log_it("Examining imagedev %s", dev);
     126            for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     127            dev[i] = '\0';
     128            if (!strlen(dev)) {
     129                mr_free(dev);
     130                continue;
     131            }
     132            fprintf(fout, "%s\n", dev);
     133            log_it("Adding '%s' to biggielist", dev);
     134            if ((ptr = strchr(ptr, ' '))) {
     135                ptr++;
     136            }
     137            mr_free(dev);
    135138        }
    136139    }
     
    138141    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    139142
    140     paranoid_free(dev);
    141143    return (retval);
    142144}
     
    158160
    159161    mr_asprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);
    160 
    161162    mr_asprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    162163    retval = system(command);
     
    331332
    332333    if (curr_set_no == 0) {
    333         mr_asprintf(tmp, "Only one fileset. Fine.");
     334        log_msg(1, "Only one fileset. Fine.");
    334335    } else {
    335         mr_asprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    336     }
    337     log_msg(1, tmp);
    338     mr_free(tmp);
     336        log_msg(1, "Filelist divided into %ld sets", curr_set_no + 1);
     337    }
    339338    close_evalcall_form();
    340339    /* This is to work around an obscure bug in Newt; open a form, close it,
     
    342341       then update_progress_form() won't show the "time taken / time remaining"
    343342       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    344 #ifndef _XWIN
    345343    if (!g_text_mode) {
    346344        open_progress_form("", "", "", "", 100);
     
    349347        newtPopWindow();
    350348    }
    351 #endif
    352349    return (err ? 0 : curr_set_no + 1);
    353350}
     
    410407int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
    411408{
    412     FILE *pattr;
    413     char *tmp;
    414     char *p;
     409    FILE *pattr = NULL;
     410    char *tmp = NULL;
    415411
    416412    pattr = popen(syscall, "r");
     
    424420        return (2);
    425421    }
    426     malloc_string(tmp);
    427     for (p = fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr) && (p != NULL);
    428          p = fgets(tmp, MAX_STR_LEN, pattr)) {
     422    for (mr_getline(tmp, pattr); !feof(pattr); mr_getline(tmp, pattr)) {
    429423        fputs(tmp, pout);
    430     }
     424        mr_free(tmp);
     425    }
     426    mr_free(tmp);
    431427    paranoid_pclose(pattr);
    432     paranoid_free(tmp);
    433428    return (0);
    434429}
     
    439434                 char *auxlist_fname)
    440435{
    441     FILE *fin;
    442     FILE *pout;
     436    FILE *fin = NULL;
     437    FILE *pout = NULL;
    443438    char *pout_command = NULL;
    444     char *syscall;
    445     char *file_to_analyze;
     439    char *syscall = NULL;
     440    char *file_to_analyze = NULL;
    446441    char *strtmp = NULL;
    447442    char *tmp = NULL;
    448     char *p = NULL;
    449443    int i;
    450444
     
    462456    mr_free(pout_command);
    463457
    464     malloc_string(file_to_analyze);
    465     for (p = fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin) && (p != NULL);
    466          p = fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     458    for (mr_getline(file_to_analyze, fin); !feof(fin); mr_getline(file_to_analyze, fin)) {
    467459        i = strlen(file_to_analyze);
    468460        if (i > 0 && file_to_analyze[i - 1] < 32) {
     
    472464        tmp = mr_stresc(file_to_analyze, "'", '\\', '\'');
    473465        mr_asprintf(syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp);    // " MONDO_LOGFILE);
    474         paranoid_free(tmp);
     466        mr_free(tmp);
    475467        log_msg(20,"calling %s\n",syscall);
    476468        call_exe_and_pipe_output_to_fd(syscall, pout);
    477         paranoid_free(syscall);
    478     }
     469        mr_free(syscall);
     470        mr_free(file_to_analyze);
     471    }
     472    mr_free(file_to_analyze);
    479473    paranoid_fclose(fin);
    480474    paranoid_pclose(pout);
    481     paranoid_free(file_to_analyze);
    482475    return (0);
    483476}
     
    522515    char *syscall_pin = NULL;
    523516    char *syscall_pout = NULL;
    524     char *incoming;
    525     char *current_subset_file, *current_master_file;
     517    char *incoming = NULL;
     518    char *current_subset_file = NULL;
     519    char *current_master_file = NULL;
    526520    char *masklist = NULL;
    527521    int retval = 0;
    528522    int i;
    529     char *p, *q, *r;
     523    char *p, *q;
    530524    char *tmp = NULL;
    531525    FILE *pin, *pout, *faclin;
    532526
    533     log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
    534             original_exat_fname, executable);
     527    log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable);
    535528    if (!orig_msklist || !orig_msklist[0]
    536529        || !does_file_exist(orig_msklist)) {
     
    552545    }
    553546    if (length_of_file(original_exat_fname) <= 0) {
    554         log_msg(1,
    555                 "original_exat_fname %s is empty or missing, so no need to set EXAT list",
    556                 original_exat_fname);
     547        log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname);
    557548        return (0);
    558549    }
    559     malloc_string(incoming);
    560     malloc_string(current_subset_file);
    561     malloc_string(current_master_file);
    562550    mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir);
    563551    mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist);
     
    566554
    567555    sort_file(masklist);
    568     current_subset_file[0] = current_master_file[0] = '\0';
    569556
    570557    mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
     
    599586//  printf("Hi there. Starting the loop\n");
    600587
    601     r = fgets(current_subset_file, MAX_STR_LEN, faclin);
    602     r = fgets(incoming, MAX_STR_LEN, pin);
    603     while (!feof(pin) && !feof(faclin) && (r != NULL)) {
    604 //      printf("incoming = %s", incoming);
    605 
    606         strcpy(current_master_file, incoming + 8);
     588    mr_getline(current_subset_file, faclin);
     589    mr_getline(incoming, pin);
     590    while (!feof(pin) && !feof(faclin)) {
     591        mr_asprintf(current_master_file, "%s", incoming + 8);
    607592
    608593        p = current_subset_file;
     
    632617        if (i < 0) {            // read another subset file in.
    633618            log_msg(my_depth, "Reading next subset line in\n\n");
    634             r = fgets(current_subset_file, MAX_STR_LEN, faclin);
     619            mr_free(current_subset_file);
     620            mr_getline(current_subset_file, faclin);
    635621            continue;
    636622        }
     
    639625            fputs(incoming, pout);
    640626        }
    641         r = fgets(incoming, MAX_STR_LEN, pin);
     627        mr_free(incoming);
     628        mr_getline(incoming, pin);
    642629        if (!i) {
    643630            log_msg(my_depth, "Copying master %s", q);
    644631        }
    645 //      if (!i) { printf("Match --- %s\n", q); }
    646632
    647633        while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
    648634            if (!i) {
    649 
    650 //    printf("%s", incoming);
    651 
    652635                fputs(incoming, pout);
    653636            }
    654             r = fgets(incoming, MAX_STR_LEN, pin);
     637            mr_free(incoming);
     638            mr_getline(incoming, pin);
    655639        }
    656640        if (!i) {
    657             r = fgets(current_subset_file, MAX_STR_LEN, faclin);
    658         }
    659     }
    660     while (!feof(pin)) {
    661         r = fgets(incoming, MAX_STR_LEN, pin);
    662     }
     641            mr_free(current_subset_file);
     642            mr_getline(current_subset_file, faclin);
     643        }
     644        mr_free(current_master_file);
     645    }
     646    mr_free(current_subset_file);
     647    mr_free(incoming);
    663648    fclose(faclin);
    664649    pclose(pin);
    665650    pclose(pout);
    666651
    667 //  printf("OK, loop is done\n");
    668 
    669652    unlink(masklist);
    670653    mr_free(masklist);
    671654
    672     paranoid_free(current_subset_file);
    673     paranoid_free(current_master_file);
    674     paranoid_free(incoming);
    675655    return (retval);
    676656}
     
    770750    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    771751
    772 /* walk across tree if necessary */
     752    /* walk across tree if necessary */
    773753    node = startnode;
    774754    char_to_add = string_to_add[0];
     
    779759    }
    780760
    781 /* walk down tree if appropriate */
     761    /* walk down tree if appropriate */
    782762    if (node->down != NULL && node->ch == char_to_add) {
    783763        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     
    793773    }
    794774
    795 /* add here */
     775    /* add here */
    796776    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
    797777        log_to_screen("failed to malloc");
     
    864844    /*@ buffers **************************************************** */
    865845    char *command_to_open_fname = NULL;
    866     char fname[MAX_STR_LEN];
    867     char tmp[MAX_STR_LEN];
     846    char *fname = NULL;
     847    char *tmp = NULL;
    868848    char *tmp1 = NULL;
    869849    int pos_in_fname;
     
    911891
    912892    open_evalcall_form("Loading filelist from disk");
    913     for (tmp1 = fgets(fname, MAX_STR_LEN, pin); !feof(pin);
    914          tmp1 = fgets(fname, MAX_STR_LEN, pin)) {
    915         if (((fname[strlen(fname) - 1] == 13) || (fname[strlen(fname) - 1] == 10)) && (strlen(fname) > 0)) {
     893    for (mr_getline(fname, pin); !feof(pin); mr_getline(fname, pin)) {
     894        if ((strlen(fname) > 0) && (fname[strlen(fname) - 1] == 13 || fname[strlen(fname) - 1] == 10)) {
    916895            fname[strlen(fname) - 1] = '\0';
    917896        }
    918 //      strip_spaces (fname);
    919897        if (!strlen(fname)) {
     898            mr_free(fname);
    920899            continue;
    921900        }
     
    924903                continue;
    925904            }
    926             strcpy(tmp, fname);
     905            mr_asprintf(tmp, "%s", fname);
    927906            tmp[pos_in_fname] = '\0';
    928907            if (strlen(tmp)) {
    929908                add_string_at_node(filelist, tmp);
    930909            }
     910            mr_free(tmp);
    931911        }
    932912        add_string_at_node(filelist, fname);
     913
    933914        if (!(++lino % 1111)) {
    934915            percentage = (int) (lino * 100 / lines_in_filelist);
    935916            update_evalcall_form(percentage);
    936917        }
    937     }
     918        mr_free(fname);
     919    }
     920    mr_free(fname);
     921
    938922    paranoid_pclose(pin);
    939923    close_evalcall_form();
     
    12971281
    12981282
    1299 
    1300 
    13011283/**
    13021284 * Number of entries in the skeleton filelist.
     
    13141296 * @bug Return value should be @c void.
    13151297 */
    1316 int open_and_list_dir(char *dir1, char *sth, FILE * fout,
    1317                       time_t time_of_last_full_backup)
    1318 {
     1298int open_and_list_dir(char *dir1, char *sth, FILE * fout, time_t time_of_last_full_backup) {
     1299
    13191300    const char delims[] = "|";
    13201301
     
    13231304    struct stat statbuf;
    13241305    char *new;
    1325     char *tmp;
     1306    char *tmp = NULL;
    13261307    char *dir = NULL;
    13271308    static int percentage = 0;
    1328     char *skip_these;
     1309    char *skip_these = NULL;
    13291310    char *new_with_pipe;
    13301311    char *strtmp = NULL;
    13311312    char *token = NULL;
    13321313    char *find_excludes = NULL;
    1333     static char *name_of_evalcall_form;
     1314    char *name_of_evalcall_form = NULL;
     1315    char *find_skeleton_marker = NULL;
    13341316    int i;
    13351317    int lastpos = 0;
     
    13381320    static int counter = 0;
    13391321    static int uberctr = 0;
    1340     static char *find_skeleton_marker;
    1341     static long skeleton_lino = 0;
    1342     static time_t last_time = 0;
     1322    static long skeleton_lino = 0L;
     1323    static time_t last_time = (time_t)0;
    13431324    time_t this_time;
    13441325
     
    13551336
    13561337    if (!depth) {
    1357         malloc_string(name_of_evalcall_form);
    1358         malloc_string(find_skeleton_marker);
    13591338        while((token = mr_strtok(sth, delims, &lastpos)) != NULL) {
    13601339          mr_strcat(find_excludes," -path %s -prune -o", token);
     
    13751354        mr_asprintf(strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
    13761355#endif
    1377         paranoid_free(find_excludes);
     1356        mr_free(find_excludes);
     1357
    13781358        log_msg(5, "find command = %s", strtmp);
    13791359        paranoid_system(strtmp);
    1380         paranoid_free(strtmp);
     1360        mr_free(strtmp);
     1361
    13811362        mr_asprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    1382         g_skeleton_entries =
    1383             1 + atol(call_program_and_get_last_line_of_output(tmp));
    1384         paranoid_free(tmp);
    1385         sprintf(name_of_evalcall_form, "Making catalog of %s", dir1);
     1363        g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp));
     1364        mr_free(tmp);
     1365
     1366        mr_asprintf(name_of_evalcall_form, "Making catalog of %s", dir1);
    13861367        open_evalcall_form(name_of_evalcall_form);
    1387         find_skeleton_marker[0] = '\0';
     1368        mr_free(name_of_evalcall_form);
     1369
    13881370        skeleton_lino = 1;
    13891371        log_msg(5, "entries = %ld", g_skeleton_entries);
     
    13911373    } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
    13921374    {
    1393         sprintf(find_skeleton_marker,
    1394                 "grep -Fv '%s' %s > %s.new 2> /dev/null", dir,
    1395                 g_skeleton_filelist, g_skeleton_filelist);
    1396 //    log_msg(0, "fsm = %s", find_skeleton_marker);
     1375        mr_asprintf(find_skeleton_marker, "grep -Fv '%s' %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist);
    13971376        if (!system(find_skeleton_marker)) {
    13981377            percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
    13991378            skeleton_lino++;
    1400 //        log_msg(5, "Found %s", dir);
    1401 //        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
    1402             sprintf(find_skeleton_marker, "mv -f %s.new %s",
    1403                     g_skeleton_filelist, g_skeleton_filelist);
    1404 //        log_msg(6, "fsm = %s", find_skeleton_marker);
     1379            mr_free(find_skeleton_marker);
     1380
     1381            mr_asprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist);
    14051382            paranoid_system(find_skeleton_marker);
    14061383            time(&this_time);
    14071384            if (this_time != last_time) {
    14081385                last_time = this_time;
    1409 #ifndef _XWIN
    14101386                if (!g_text_mode) {
    14111387                    int cols, rows;
     
    14151391                    mr_free(tmp);
    14161392                }
    1417 #endif
    14181393                update_evalcall_form(percentage);
    14191394            }
    14201395        }
     1396        mr_free(find_skeleton_marker);
    14211397    }
    14221398
     
    14301406        mr_asprintf(tmp,"opendir %s", dir1);
    14311407        log_OS_error(tmp);
    1432         paranoid_free(tmp);
     1408        mr_free(tmp);
    14331409    } else if (strstr(skip_these, new_with_pipe)) {
    14341410        log_msg(10, "Found dir ***%s**** excluded", dir1);
     
    14441420                mr_asprintf(new,"%s%s",dir1,dit->d_name);
    14451421            }
    1446             paranoid_free(new_with_pipe);
     1422            mr_free(new_with_pipe);
    14471423            mr_asprintf(new_with_pipe, "|%s|", new);
    14481424            if (strstr(skip_these, new_with_pipe)) {
    14491425                fprintf(fout, "%s\n", new);
    14501426                log_msg(10, "Found child dir ***%s**** excluded", new);
    1451                 paranoid_free(new_with_pipe);
     1427                mr_free(new_with_pipe);
    14521428            } else {
    1453                 paranoid_free(new_with_pipe);
     1429                mr_free(new_with_pipe);
    14541430                if (!lstat(new, &statbuf)) {
    14551431                    if (!S_ISLNK(statbuf.st_mode)
    14561432                        && S_ISDIR(statbuf.st_mode)) {
    14571433                        log_msg(10, "Found child dir ***%s**** parsed", new);
    1458                         open_and_list_dir(new, skip_these, fout,
    1459                                           time_of_last_full_backup);
     1434                        open_and_list_dir(new, skip_these, fout, time_of_last_full_backup);
    14601435                    } else {
    1461                         if (time_of_last_full_backup == 0
    1462                             || time_of_last_full_backup <
    1463                             statbuf.st_ctime) {
     1436                        if (time_of_last_full_backup == 0 || time_of_last_full_backup < statbuf.st_ctime) {
    14641437                            log_msg(10, "Found child file ***%s**** parsed", new);
    14651438                            fprintf(fout, "%s\n", new);
     
    14681441                                uberctr++;
    14691442                                mr_asprintf(tmp, " %c ", special_dot_char(uberctr));
    1470 #ifndef _XWIN
    14711443                                if (!g_text_mode) {
    1472                                     newtDrawRootText(77, g_noof_rows - 3,
    1473                                                      tmp);
     1444                                    newtDrawRootText(77, g_noof_rows - 3, tmp);
    14741445                                    newtRefresh();
    14751446                                }
    1476 #endif
    1477                                 paranoid_free(tmp);
     1447                                mr_free(tmp);
    14781448                            }
    14791449                        }
     
    14811451                }
    14821452            }
    1483             paranoid_free(new);
    1484         }
    1485     }
    1486     paranoid_free(new_with_pipe);
    1487     paranoid_free(skip_these);
     1453            mr_free(new);
     1454        }
     1455    }
     1456    mr_free(new_with_pipe);
     1457    mr_free(skip_these);
    14881458    mr_free(dir);
    14891459
     
    14961466    if (!depth) {
    14971467        close_evalcall_form();
    1498         paranoid_free(name_of_evalcall_form);
    1499         paranoid_free(find_skeleton_marker);
    15001468        unlink(g_skeleton_filelist);
    15011469        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
     
    15251493    char *p, *q;
    15261494    char *sz_datefile;
    1527     char *sz_filelist, *tmp;
     1495    char *sz_filelist;
    15281496    char *exclude_paths = NULL;
    15291497    FILE *fout;
     
    15341502    char *tmp2 = NULL;
    15351503
    1536     malloc_string(tmp);
    1537     malloc_string(g_skeleton_filelist);
    15381504    mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    15391505    if (!include_paths && !userdef_filelist) {
    1540         fatal_error
    1541             ("Please supply either include_paths or userdef_filelist");
    1542     }
    1543 // make hole for filelist
     1506        fatal_error("Please supply either include_paths or userdef_filelist");
     1507    }
     1508    // make hole for filelist
    15441509    mr_asprintf(command, "mkdir -p %s/archives", scratchdir);
    15451510    paranoid_system(command);
     
    15571522        // backup last known good datefile just in case :)
    15581523        if (does_file_exist(sz_datefile)) {
    1559             mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile,
    1560                     sz_datefile);
     1524            mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    15611525            paranoid_system(command);
    15621526            mr_free(command);
     
    15671531                                  ("date +%s"));
    15681532    } else if (lstat(sz_datefile, &statbuf)) {
    1569         log_msg(2,
    1570                 "Warning - unable to find date of previous backup. Full backup instead.");
     1533        log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    15711534        differential = 0;
    15721535        time_of_last_full_backup = 0;
     
    15791542// use user-specified filelist (if specified)
    15801543    if (userdef_filelist) {
    1581         log_msg(1,
    1582                 "Using the user-specified filelist - %s - instead of calculating one",
    1583                 userdef_filelist);
     1544        log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    15841545        mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    15851546        if (run_program_and_log_output(command, 3)) {
     
    15891550        mr_free(command);
    15901551    } else {
    1591         log_msg(2, "include_paths = '%s'", include_paths);
     1552        if (include_paths) {
     1553            log_msg(2, "include_paths = '%s'", include_paths);
     1554        }
    15921555        log_msg(1, "Calculating filelist");
    15931556        mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
     
    15971560            log_msg(2, "Found windows FS: %s",tmp2);
    15981561            mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
    1599             paranoid_free(tmp2);
     1562            mr_free(tmp2);
    16001563            mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
    16011564            log_msg(2, "Found windows files: %s",tmp2);
    16021565        }
    1603         paranoid_free(tmp1);
     1566        mr_free(tmp1);
    16041567
    16051568        mr_asprintf(exclude_paths, MONDO_CACHE"|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/run|/dev/shm|"MINDI_CACHE, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     
    16071570            mr_strcat(exclude_paths,"|%s",excp);
    16081571        }
    1609         paranoid_free(tmp2);
     1572        mr_free(tmp2);
    16101573
    16111574        log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1612         log_msg(2,
    1613                 "Generating skeleton filelist so that we can track our progress");
    1614         sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
     1575        log_msg(2, "Generating skeleton filelist so that we can track our progress");
     1576        mr_asprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
    16151577        make_hole_for_file(g_skeleton_filelist);
     1578
    16161579        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    16171580        log_msg(2, "Opening out filelist to %s", sz_filelist);
     
    16191582            fatal_error("Cannot openout to sz_filelist");
    16201583        }
    1621         if (strlen(include_paths) == 0) {
     1584        if ((include_paths != NULL) && (strlen(include_paths) == 0)) {
    16221585            log_msg(1, "Including only '/' in %s", sz_filelist);
    16231586            open_and_list_dir("/", exclude_paths, fout,
     
    16371600            }
    16381601        }
     1602        mr_free(exclude_paths);
    16391603        paranoid_fclose(fout);
    16401604    }
     
    16541618    paranoid_free(sz_filelist);
    16551619    log_msg(2, "Freeing variables");
    1656     paranoid_free(exclude_paths);
    1657     paranoid_free(tmp);
    1658     paranoid_free(g_skeleton_filelist);
     1620    mr_free(g_skeleton_filelist);
    16591621    log_msg(2, "Exiting");
    16601622    return (0);
    16611623}
     1624
    16621625
    16631626/**
     
    16801643
    16811644    assert(bkpinfo != NULL);
    1682     log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
    1683            bkpinfo->scratchdir);
     1645    log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    16841646    if (bkpinfo->make_filelist) {
    16851647        mvaddstr_and_log_it(g_currentY, 0,
     
    17921754    FILE *fin;
    17931755    FILE *fout;
    1794     char *fname;
    1795     char *tmp;
    1796     size_t len = 0;             // Scrub's patch doesn't work without that
    1797 
    1798 //  log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1799     malloc_string(fname);
    1800     malloc_string(tmp);
     1756    char *fname = NULL;
     1757    char *tmp = NULL;
     1758
    18011759    log_msg(5, "starting");
    18021760    log_msg(5, "needles_list_fname = %s", needles_list_fname);
     
    18091767    }
    18101768    while (!feof(fin)) {
    1811 //      fscanf(fin, "%s\n", fname);
    1812         len = MAX_STR_LEN - 1;
    1813         if (getline(&fname, &len, fin)) {
    1814             // FIXME
    1815         }
     1769        mr_getline(fname, fin);
    18161770        if (!use_star) {
    18171771            if (fname[0] == '/') {
    1818                 strcpy(tmp, fname);
     1772                mr_asprintf(tmp, "%s", fname);
    18191773            } else {
    1820                 tmp[0] = '/';
    1821                 strcpy(tmp + 1, fname);
     1774                mr_asprintf(tmp, "/%s", fname);
    18221775            }
    1823             strcpy(fname, tmp);
     1776            mr_free(fname);
     1777            fname = tmp;
    18241778        }
    18251779        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
     
    18321786            if (found_node->selected) {
    18331787                if (fname[0] == '/') {
    1834                     strcpy(tmp, fname + 1);
    1835                     strcpy(fname, tmp);
     1788                    mr_asprintf(tmp, "%s", fname + 1);
     1789                    mr_free(fname);
     1790                    fname = tmp;
    18361791                }
    18371792                log_msg(5, "Found '%s'", fname);
    1838                 turn_wildcard_chars_into_literal_chars(tmp, fname);
    1839                 fprintf(fout, "%s\n", tmp);
     1793                tmp = mr_stresc(fname, "[]*?", '\\', "'");
     1794                mr_free(fname);
     1795                fname = tmp;
     1796                fprintf(fout, "%s\n", fname);
    18401797                retval++;
    18411798            }
    18421799        }
     1800        mr_free(fname);
    18431801    }
    18441802    paranoid_fclose(fout);
    18451803    paranoid_fclose(fin);
    1846     paranoid_free(fname);
    1847     paranoid_free(tmp);
    18481804    return (retval);
    18491805}
    1850 
    1851 
    1852 
    18531806
    18541807
     
    18651818                                  char *list_of_files_fname, bool flag_em)
    18661819{
    1867     FILE *fin;
    1868     char *tmp;
    1869     char *p;
    1870     struct s_node *nod;
    1871 
    1872     malloc_string(tmp);
     1820    FILE *fin = NULL;
     1821    char *tmp = NULL;
     1822    struct s_node *nod = NULL;
     1823
    18731824    log_msg(3, "Adding %s to filelist", list_of_files_fname);
    18741825    if (!(fin = fopen(list_of_files_fname, "r"))) {
     
    18761827        return (1);
    18771828    }
    1878     for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL);
    1879          p = fgets(tmp, MAX_STR_LEN, fin)) {
     1829    for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    18801830        if (!tmp[0]) {
     1831            mr_free(tmp);
    18811832            continue;
    18821833        }
    1883         if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
    1884             && strlen(tmp) > 0) {
     1834        if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)) {
    18851835            tmp[strlen(tmp) - 1] = '\0';
    18861836        }
    18871837        log_msg(2, "tmp = '%s'", tmp);
    18881838        if (!tmp[0]) {
     1839            mr_free(tmp);
    18891840            continue;
    18901841        }
     
    19001851            log_msg(5, "Flagged '%s'", tmp);
    19011852        }
    1902     }
     1853        mr_free(tmp);
     1854    }
     1855    mr_free(tmp);
    19031856    paranoid_fclose(fin);
    1904     paranoid_free(tmp);
    19051857    return (0);
    19061858}
  • branches/3.2/mondo/src/common/libmondo-files-EXT.h

    r2904 r3191  
    4141
    4242
    43 extern int make_hole_for_dir(char *outdir_fname);
     43extern int make_hole_for_dir(const char *outdir_fname);
    4444
    4545extern long size_of_partition_in_mountlist_K(char *tmpdir, char *dev);
  • branches/3.2/mondo/src/common/libmondo-files.c

    r3150 r3191  
    4747    /*@ buffers ***************************************************** */
    4848    static char output[MAX_STR_LEN];
    49     char command[MAX_STR_LEN * 2];
    50     char tmp[MAX_STR_LEN];
     49    char *command = NULL;
    5150
    5251    /*@ pointers **************************************************** */
    53     char *p;
     52    char *p = NULL;
    5453    char *q;
    5554    FILE *fin;
     
    6362    assert_string_is_neither_NULL_nor_zerolength(filename);
    6463    if (does_file_exist(filename)) {
    65         sprintf(command, "md5sum \"%s\"", filename);
     64        mr_asprintf(command, "md5sum \"%s\"", filename);
    6665        fin = popen(command, "r");
    6766        if (fin) {
     
    7372            paranoid_pclose(fin);
    7473        }
     74        mr_free(command);
    7575    } else {
    76         sprintf(tmp, "File '%s' not found; cannot calc checksum",
    77                 filename);
    78         log_it(tmp);
     76        log_it("File '%s' not found; cannot calc checksum", filename);
    7977    }
    8078    if (p) {
     
    130128
    131129    /*@ buffers ***************************************************** */
    132     char command[MAX_STR_LEN * 2];
    133     char incoming[MAX_STR_LEN];
    134     char tmp[MAX_STR_LEN];
    135     char *q;
     130    char *command = NULL;
     131    char *incoming = NULL;
    136132
    137133    /*@ long ******************************************************** */
     
    141137    FILE *fin;
    142138
    143     /*@ initialize [0] to null ******************************************** */
    144     incoming[0] = '\0';
    145 
    146139    assert_string_is_neither_NULL_nor_zerolength(filename);
    147140    if (!does_file_exist(filename)) {
    148         sprintf(tmp,
    149                 "%s does not exist, so I cannot found the number of lines in it",
    150                 filename);
    151         log_it(tmp);
     141        log_it("%s does not exist, so I cannot found the number of lines in it", filename);
    152142        return (0);
    153143    }
    154     sprintf(command, "cat %s | wc -l", filename);
     144    mr_asprintf(command, "cat %s | wc -l", filename);
    155145    if (!does_file_exist(filename)) {
     146        mr_free(command);
    156147        return (-1);
    157148    }
    158149    fin = popen(command, "r");
     150    mr_free(command);
     151
    159152    if (fin) {
    160153        if (feof(fin)) {
    161154            noof_lines = 0;
    162155        } else {
    163             q = fgets(incoming, MAX_STR_LEN - 1, fin);
    164             if (!q) {
    165                 // FIXME
    166             }
    167             while (strlen(incoming) > 0 && (q != NULL)
    168                    && incoming[strlen(incoming) - 1] < 32) {
     156            mr_getline(incoming, fin);
     157            while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) {
    169158                incoming[strlen(incoming) - 1] = '\0';
    170159            }
    171160            noof_lines = atol(incoming);
     161            mr_free(incoming);
    172162        }
    173163        paranoid_pclose(fin);
     
    215205void exclude_nonexistent_files(char *inout)
    216206{
    217     char infname[MAX_STR_LEN];
    218     char outfname[MAX_STR_LEN];
    219     char tmp[MAX_STR_LEN];
    220     char incoming[MAX_STR_LEN];
    221     char *q;
     207    char *infname = NULL;
     208    char *outfname = NULL;
     209    char *tmp = NULL;
     210    char *incoming = NULL;
    222211
    223212    /*@ int ********************************************************* */
     
    231220
    232221    assert_string_is_neither_NULL_nor_zerolength(inout);
    233     sprintf(infname, "%s.in", inout);
    234     sprintf(outfname, "%s", inout);
    235     sprintf(tmp, "cp -f %s %s", inout, infname);
     222    mr_asprintf(infname, "%s.in", inout);
     223    mr_asprintf(tmp, "cp -f %s %s", inout, infname);
    236224    run_program_and_log_output(tmp, FALSE);
     225    mr_free(tmp);
     226
    237227    if (!(fin = fopen(infname, "r"))) {
    238228        log_OS_error("Unable to openin infname");
     229        mr_free(infname);
    239230        return;
    240231    }
     232
     233    mr_asprintf(outfname, "%s", inout);
    241234    if (!(fout = fopen(outfname, "w"))) {
    242235        log_OS_error("Unable to openout outfname");
     236        mr_free(infname);
     237        mr_free(outfname);
    243238        return;
    244239    }
    245     for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL);
    246          q = fgets(incoming, MAX_STR_LEN, fin)) {
     240    mr_free(outfname);
     241
     242    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    247243        i = strlen(incoming) - 1;
    248244        if (i >= 0 && incoming[i] < 32) {
     
    252248            fprintf(fout, "%s\n", incoming);
    253249        } else {
    254             sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
    255             log_it(tmp);
    256         }
    257     }
     250            log_it("Excluding '%s'-nonexistent\n", incoming);
     251        }
     252        mr_free(incoming);
     253    }
     254    mr_free(incoming);
     255
    258256    paranoid_fclose(fout);
    259257    paranoid_fclose(fin);
    260258    unlink(infname);
    261 }
    262 
    263 
    264 
    265 
    266 
    267 
    268 
     259    mr_free(infname);
     260}
    269261
    270262
     
    278270int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    279271{
    280     char tmp[MAX_STR_LEN];
    281     char *command;
     272    char *tmp = NULL;
     273    char *command = NULL;
    282274
    283275    if (!kernel[0]) {
    284         strcpy(kernel,
    285                call_program_and_get_last_line_of_output
    286                ("mindi --findkernel 2> /dev/null"));
     276        strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null"));
    287277    }
    288278    // If we didn't get anything back, check whether mindi raised a fatal error
    289279    if (!kernel[0]) {
    290         malloc_string(command);
    291         strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
    292         strcpy(tmp, call_program_and_get_last_line_of_output(command));
     280        mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log");
     281        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    293282        if (strlen(tmp) > 1) {
    294283            popup_and_OK(tmp);
     284            mr_free(tmp);
     285            mr_free(command);
    295286            fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'.");
    296287        }
    297         paranoid_free(command);
     288        mr_free(tmp);
     289        mr_free(command);
    298290    }
    299291    log_it("Calling Mindi with kernel path of '%s'", kernel);
     
    310302                ("Kernel not found. Please specify with the '-k' flag.");
    311303        }
    312         sprintf(tmp, "User says kernel is at %s", kernel);
    313         log_it(tmp);
     304        log_it("User says kernel is at %s", kernel);
    314305    }
    315306    return (0);
    316307}
    317 
    318 
    319 
    320 
    321308
    322309
     
    334321    /*@ buffers ********************* */
    335322    static char output[MAX_STR_LEN];
    336     char *incoming;
    337     char *command;
    338 
    339     malloc_string(incoming);
    340     malloc_string(command);
    341     incoming[0] = '\0';
     323    char *incoming = NULL;
     324    char *command = NULL;
     325
    342326    /*@******************************* */
    343327
    344328    assert_string_is_neither_NULL_nor_zerolength(fname);
    345     sprintf(command, "which %s 2> /dev/null", fname);
    346     strcpy(incoming, call_program_and_get_last_line_of_output(command));
     329    mr_asprintf(command, "which %s 2> /dev/null", fname);
     330    mr_asprintf(incoming, call_program_and_get_last_line_of_output(command));
     331    mr_free(command);
     332
    347333    if (incoming[0] == '\0') {
    348334        if (system("which file > /dev/null 2> /dev/null")) {
    349             paranoid_free(incoming);
    350             paranoid_free(command);
     335            mr_free(incoming);
    351336            output[0] = '\0';
    352337            return (NULL);      // forget it :)
    353338        }
    354         sprintf(command,
    355                 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
    356                 incoming);
    357         strcpy(incoming,
    358                call_program_and_get_last_line_of_output(command));
    359     }
    360     if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    361     {
    362         sprintf(command, "dirname %s 2> /dev/null", incoming);
    363         strcpy(incoming,
    364                call_program_and_get_last_line_of_output(command));
     339        mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
     340        mr_free(incomig);
     341
     342        mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command));
     343        mr_free(command);
     344    }
     345    if (incoming[0] == '\0') {
     346        mr_asprintf(command, "dirname %s 2> /dev/null", incoming);
     347        mr_free(incoming);
     348
     349        mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command));
     350        mr_free(command);
    365351    }
    366352    strcpy(output, incoming);
    367353    if (output[0] != '\0' && does_file_exist(output)) {
    368         log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
    369                 incoming);
     354        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming);
    370355    } else {
    371356        output[0] = '\0';
    372357        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
    373358    }
    374     paranoid_free(incoming);
    375     paranoid_free(command);
     359    mr_free(incoming);
    376360    if (!output[0]) {
    377361        return (NULL);
     
    382366
    383367
    384 
    385 
    386 
    387 
    388 
    389 
    390368/**
    391369 * Get the last sequence of digits surrounded by non-digits in the first 32k of
     
    421399    for (; len > 0 && isdigit(datablock[len - 1]); len--);
    422400    trackno = atoi(datablock + len);
    423     /*
    424        sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    425        log_it(tmp);
    426      */
    427401    return (trackno);
    428402}
     
    444418
    445419    /*@ buffers ***************************************************** */
    446     char tmp[MAX_STR_LEN];
    447     char lastline[MAX_STR_LEN];
    448     char command[MAX_STR_LEN];
     420    char *lastline = NULL;
     421    char *command = NULL;
    449422    /*@ pointers **************************************************** */
    450     char *p;
     423    char *p = NULL;
    451424
    452425    /*@ int's ******************************************************* */
    453     int i;
    454 
    455     for (i = NOOF_ERR_LINES - 1;
    456          i >= 0 && !strstr(err_log_lines[i], "% Done")
    457          && !strstr(err_log_lines[i], "% done"); i--);
     426    int i = 0;
     427
     428    for (i = NOOF_ERR_LINES - 1; i >= 0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--);
    458429    if (i < 0) {
    459         sprintf(command,
    460                 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
    461                 filename, '%');
    462         strcpy(lastline,
    463                call_program_and_get_last_line_of_output(command));
     430        mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
     431        mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command));
     432        mr_free(command);
    464433        if (!lastline[0]) {
     434            mr_free(lastline);
    465435            return (0);
    466436        }
    467437    } else {
    468         strcpy(lastline, err_log_lines[i]);
     438        mr_asprintf(lastline, "%s", err_log_lines[i]);
    469439    }
    470440
     
    472442    if (p) {
    473443        *p = '\0';
    474     }
    475 //  log_msg(2, "lastline='%s', ", p, lastline);
    476     if (!p) {
     444    } else {
     445        mr_free(lastline);
    477446        return (0);
    478447    }
    479     *p = '\0';
    480     for (p--; *p != ' ' && p != lastline; p--);
     448
     449    for (p--; isdigit(*p) && p != lastline; p--);
    481450    if (p != lastline) {
    482451        p++;
    483452    }
    484453    i = atoi(p);
    485 
    486     sprintf(tmp, "'%s' --> %d", p, i);
    487 //     log_to_screen(tmp);
    488 
     454    mr_free(lastline);
    489455    return (i);
    490456}
     
    504470    /*@ buffers ***************************************************** */
    505471    static char output[MAX_STR_LEN];
    506     static char command[MAX_STR_LEN * 2];
    507     static char tmp[MAX_STR_LEN];
    508     char *p = NULL;
     472    char *command = NULL;
    509473
    510474    /*@ pointers **************************************************** */
     
    514478
    515479    if (!does_file_exist(filename)) {
    516         sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
    517                 filename);
    518         log_it(tmp);
     480        log_it("Tring to get last line of nonexistent file (%s)", filename);
    519481        output[0] = '\0';
    520482        return (output);
    521483    }
    522     sprintf(command, "tail -n1 %s", filename);
     484    mr_asprintf(command, "tail -n1 %s", filename);
    523485    fin = popen(command, "r");
     486    mr_free(command);
    524487    p = fgets(output, MAX_STR_LEN, fin);
    525488    if (p == NULL) {
     
    564527 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.
    565528 */
    566 int
    567 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
    568 {
     529int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) {
    569530    /*@ pointers **************************************************** */
    570531    FILE *fin;
     
    577538
    578539    /*@ buffer ****************************************************** */
    579     char stub_fname[1000];
    580     char curr_fname[1000];
    581     char curr_cksum[1000];
    582     char tmp[1000];
    583     char *q;
     540    char *stub_fname = NULL;
     541    char *curr_fname = NULL;
     542    char *curr_cksum = NULL;
     543    char *tmp = NULL;
    584544
    585545    /*@ long [long] ************************************************* */
     
    595555    start_time = get_time();
    596556    filelist_length = length_of_file(filelist);
    597     sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    598     log_it(tmp);
     557    log_it("filelist = %s; cksumlist = %s", filelist, cksumlist);
     558
    599559    fin = fopen(filelist, "r");
    600560    if (fin == NULL) {
     
    610570        return (1);
    611571    }
    612     for (q = fgets(stub_fname, 999, fin); !feof(fin) && (q != NULL);
    613          q = fgets(stub_fname, 999, fin)) {
     572    for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) {
    614573        if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
    615574            stub_fname[i] = '\0';
    616575        }
    617         sprintf(tmp, "%s%s", comppath, stub_fname);
    618         strcpy(curr_fname, tmp + 1);
    619         strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
     576        mr_asprintf(tmp, "%s%s", comppath, stub_fname);
     577        mr_free(stub_fname);
     578
     579        mr_asprintf(curr_fname, "%s", tmp + 1);
     580        mr_free(tmp);
     581
     582        mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname));
    620583        fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
     584        mr_free(curr_cksum);
     585
    621586        if (counter++ > 12) {
    622587            current_time = get_time();
    623588            counter = 0;
     589            /* BERLIOS: 37 really ? */
    624590            curr_fname[37] = '\0';
    625591            curr_pos = ftello(fin) / 1024;
    626592            percentage = (int) (curr_pos * 100 / filelist_length);
    627593            time_taken = current_time - start_time;
    628             if (percentage == 0) {
    629                 /*              printf("%0d%% done      \r",percentage); */
    630             } else {
    631                 time_remaining =
    632                     time_taken * 100 / (long) (percentage) - time_taken;
    633                 sprintf(tmp,
    634                         "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    635                         percentage, (int) (time_taken / 60),
    636                         (int) (time_taken % 60),
    637                         (int) (time_remaining / 60),
    638                         (int) (time_remaining % 60), curr_fname);
    639                 log_to_screen(tmp);
     594            if (percentage != 0) {
     595                time_remaining = time_taken * 100 / (long) (percentage) - time_taken;
     596                log_to_screen("%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);
    640597            }
    641598            sync();
    642599        }
    643     }
     600        mr_free(curr_fname);
     601    }
     602    mr_free(stub_fname);
     603
    644604    paranoid_fclose(fout);
    645605    paranoid_fclose(fin);
     
    654614 * @return The return value of @c mkdir.
    655615 */
    656 int make_hole_for_dir(char *outdir_fname)
    657 {
    658     char tmp[MAX_STR_LEN * 2];
     616int make_hole_for_dir(const char *outdir_fname)
     617{
     618    char *tmp = NULL;
    659619    int res = 0;
    660620
    661621    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    662     sprintf(tmp, "mkdir -p %s", outdir_fname);
     622    mr_asprintf(tmp, "mkdir -p %s", outdir_fname);
    663623    res = system(tmp);
     624    mr_free(tmp);
    664625    return (res);
    665626}
     
    675636{
    676637    /*@ buffer ****************************************************** */
    677     char command[MAX_STR_LEN * 2];
     638    char *command = NULL;
    678639
    679640    /*@ int  ******************************************************** */
     
    685646    assert(!strstr(outfile_fname, MNT_CDROM));
    686647    assert(!strstr(outfile_fname, "/dev/cdrom"));
    687     sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     648    mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    688649    res += system(command);
    689     sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     650    mr_free(command);
     651
     652    mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    690653    res += system(command);
    691     sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     654    mr_free(command);
     655
     656    mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    692657    res += system(command);
     658    mr_free(command);
     659
    693660    unlink(outfile_fname);
    694661    return (0);
    695662}
    696 
    697 
    698663
    699664
     
    713678
    714679    /*@ buffers **************************************************** */
    715     char incoming[MAX_STR_LEN];
    716     char *p = NULL;
     680    char *incoming = NULL;
    717681
    718682    /*@ end vars *************************************************** */
     
    725689        return (0);
    726690    }
    727     p = fgets(incoming, MAX_STR_LEN - 1, fin);
    728     while (!feof(fin) && (p != NULL)) {
     691    mr_getline(incoming, fin);
     692    while (!feof(fin)) {
    729693        if (strstr(incoming, wildcard)) {
    730694            matches++;
    731695        }
    732         p = fgets(incoming, MAX_STR_LEN - 1, fin);
    733     }
     696        mr_free(incoming);
     697        mr_getline(incoming, fin);
     698    }
     699    mr_free(incoming);
    734700    paranoid_fclose(fin);
    735701    return (matches);
     
    746712long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    747713{
    748     char command[MAX_STR_LEN];
    749     char mountlist[MAX_STR_LEN];
    750     char sz_res[MAX_STR_LEN];
     714    char *command = NULL;
     715    char *mountlist = NULL;
     716    char *sz_res = NULL;
    751717    long file_len_K;
    752718
    753     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    754     sprintf(command,
    755             "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'",
    756             dev, tmpdir);
     719    mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir);
     720    mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);
     721    mr_free(mountlist);
     722
    757723    log_it(command);
    758     strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     724    mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command));
    759725    file_len_K = atol(sz_res);
    760726    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     727    mr_free(sz_res);
     728    mr_free(command);
     729
    761730    return (file_len_K);
    762731}
     
    770739{
    771740    /*@ buffers ***************************************************** */
    772     char *fname;
    773     char *biggielist;
    774     char *comment;
    775     char *tmp;
    776     char *q;
    777     char *command;
     741    char *fname = NULL;
     742    char *biggielist = NULL;
     743    char *tmp = NULL;
     744    char *command = NULL;
    778745
    779746    /*@ long ******************************************************** */
     
    786753    /*@ end vars *************************************************** */
    787754
    788     malloc_string(fname);
    789     malloc_string(biggielist);
    790     malloc_string(comment);
    791     malloc_string(tmp);
    792     malloc_string(command);
    793755    log_it("Calculating size of all biggiefiles (in total)");
    794     sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     756    mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    795757    log_it("biggielist = %s", biggielist);
    796     if (!(fin = fopen(biggielist, "r"))) {
    797         log_OS_error
    798             ("Cannot open biggielist. OK, so estimate is based on filesets only.");
     758    fin = fopen(biggielist, "r");
     759    mr_free(biggielist);
     760
     761    if (!(fin)) {
     762        log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only.");
    799763    } else {
    800764        log_msg(4, "Reading it...");
    801         for (q = fgets(fname, MAX_STR_LEN, fin); !feof(fin) && (q != NULL);
    802              q = fgets(fname, MAX_STR_LEN, fin)) {
     765        for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) {
    803766            if (fname[strlen(fname) - 1] <= 32) {
    804767                fname[strlen(fname) - 1] = '\0';
     
    807770                if (is_dev_an_NTFS_dev(fname)) {
    808771                    if ( !find_home_of_exe("ntfsresize")) {
     772                        mr_free(tmp);
     773                        mr_free(fname);
    809774                        fatal_error("ntfsresize not found");
    810775                    }
    811                     sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     776                    mr_free(tmp);
     777
     778                    mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    812779                    log_it("command = %s", command);
    813                     strcpy (tmp, call_program_and_get_last_line_of_output(command));
     780                    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     781                    mr_free(command);
     782
    814783                    log_it("res of it = %s", tmp);
    815784                    file_len_K = atoll(tmp) / 1024L;
     785                    mr_free(tmp);
    816786                } else {
    817787                    file_len_K = get_phys_size_of_drive(fname) * 1024L;
     
    825795                log_msg(4, "%s --> %ld K", fname, file_len_K);
    826796            }
    827             sprintf(comment,
    828                     "After adding %s, scratchL+%ld now equals %ld", fname,
    829                     file_len_K, scratchL);
    830             log_msg(4, comment);
     797            log_msg(4, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL);
    831798            if (feof(fin)) {
    832799                break;
    833800            }
    834         }
     801            mr_free(fname);
     802        }
     803        mr_free(fname);
    835804    }
    836805    log_it("Closing...");
    837806    paranoid_fclose(fin);
    838807    log_it("Finished calculating total size of all biggiefiles");
    839     paranoid_free(fname);
    840     paranoid_free(biggielist);
    841     paranoid_free(comment);
    842     paranoid_free(tmp);
    843     paranoid_free(command);
    844808    return (scratchL);
    845809}
     
    854818{
    855819    /*@ buffer ****************************************************** */
    856     char tmp[MAX_STR_LEN];
    857     char command[MAX_STR_LEN * 2];
     820    char *tmp = NULL;
     821    char *command = NULL;
    858822    long long llres;
    859823    /*@ pointers **************************************************** */
     
    863827    /*@ end vars *************************************************** */
    864828
    865     sprintf(command, "du -sk %s", mountpt);
     829    mr_asprintf(command, "du -sk %s", mountpt);
    866830    errno = 0;
    867831    fin = popen(command, "r");
     
    870834      llres = 0;
    871835    } else {
    872       p = fgets(tmp, MAX_STR_LEN, fin);
     836      mr_getline(tmp, fin);
    873837      paranoid_pclose(fin);
    874838      p = strchr(tmp, '\t');
     
    880844        llres += (int) (*p - '0');
    881845      }
    882     }
     846      mr_free(tmp);
     847    }
     848    mr_free(command);
    883849
    884850    return (llres);
     
    928894{
    929895    /*@ buffers *** */
    930     char command[MAX_STR_LEN * 2];
    931     char errorstr[MAX_STR_LEN];
    932 
    933 
    934     sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    935     sprintf(errorstr,
    936             "Please install '%s'. I cannot find it on your system.",
    937             fname);
    938     if (system(command)) {
    939         log_to_screen(errorstr);
    940         log_to_screen
    941             ("There may be hyperlink at http://www.mondorescue.org/downloads.shtml which");
     896    char *command = NULL;
     897    int res = 0;
     898
     899    mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname);
     900    res = system(command);
     901    mr_free(command);
     902
     903    if (res) {
     904        log_to_screen("Please install '%s'. I cannot find it on your system.", fname);
     905        log_to_screen("There may be hyperlink at http://www.mondorescue.org which");
    942906        log_to_screen("will take you to the relevant (missing) package.");
    943907        return (1);
     
    10381002{
    10391003    /*@ Char buffers ** */
    1040     char command[MAX_STR_LEN * 2];
    1041     char tmp[MAX_STR_LEN];
     1004    char *command = NULL;
     1005    char *tmp = NULL;
    10421006    char old_pwd[MAX_STR_LEN];
    1043 
    1044     mvaddstr_and_log_it(g_currentY, 0,
    1045                         "Copying Mondo's core files to the scratch directory");
     1007    int res = 0;
     1008
     1009    mvaddstr_and_log_it(g_currentY, 0, "Copying Mondo's core files to the scratch directory");
    10461010
    10471011    log_msg(4, "g_mondo_home='%s'", g_mondo_home);
     
    10491013        find_and_store_mondoarchives_home(g_mondo_home);
    10501014    }
    1051     sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    1052             bkpinfo->scratchdir);
     1015    mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir);
    10531016
    10541017    log_msg(4, "command = %s", command);
    1055     if (run_program_and_log_output(command, 1)) {
     1018    res = run_program_and_log_output(command, 1);
     1019    mr_free(command);
     1020
     1021    if (res) {
    10561022        fatal_error("Failed to copy Mondo's stuff to scratchdir");
    10571023    }
    10581024
    1059     sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     1025    mr_asprintf(tmp, "%s/payload.tgz", g_mondo_home);
    10601026    if (does_file_exist(tmp)) {
    1061         log_it("Untarring payload %s to scratchdir %s", tmp,
    1062                bkpinfo->scratchdir);
     1027        log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir);
    10631028        if (getcwd(old_pwd, MAX_STR_LEN - 1)) {
    10641029            // FIXME
     
    10671032            // FIXME
    10681033        }
    1069         sprintf(command, "tar -zxvf %s", tmp);
    1070         if (run_program_and_log_output(command, FALSE)) {
     1034        mr_asprintf(command, "tar -zxvf %s", tmp);
     1035        res = run_program_and_log_output(command, FALSE);
     1036        if (res) {
     1037            mr_free(command);
     1038            mr_free(tmp);
    10711039            fatal_error("Failed to untar payload");
    10721040        }
     1041        mr_free(command);
    10731042        if (chdir(old_pwd)) {
    10741043            // FIXME
    10751044        }
    10761045    }
    1077 
    1078     sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    1079             bkpinfo->scratchdir);
     1046    mr_free(tmp);
     1047
     1048    mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    10801049
    10811050    if (run_program_and_log_output(command, FALSE)) {
    10821051        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    10831052    }
    1084 
    1085     strcpy(tmp,
    1086           call_program_and_get_last_line_of_output("which mondorestore"));
     1053    mr_free(command);
     1054
     1055    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("which mondorestore"));
    10871056    if (!tmp[0]) {
    1088         fatal_error
    1089             ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    1090     }
    1091     sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    1092     if (run_program_and_log_output(command, FALSE)) {
     1057        mr_free(tmp);
     1058        fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
     1059    }
     1060
     1061    mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1062    mr_free(tmp);
     1063    res = run_program_and_log_output(command, FALSE);
     1064    if (res) {
     1065        mr_free(command);
    10931066        fatal_error("Failed to copy mondorestore to tmpdir");
    10941067    }
    1095 
    1096     sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1068    mr_free(command);
     1069
     1070    mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    10971071    paranoid_system(command);
     1072    mr_free(command);
    10981073
    10991074    if (bkpinfo->postnuke_tarball[0]) {
    1100         sprintf(command, "cp -f %s %s/post-nuke.tgz",
    1101                 bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    1102         if (run_program_and_log_output(command, FALSE)) {
     1075        mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
     1076        res = run_program_and_log_output(command, FALSE);
     1077        mr_free(command);
     1078
     1079        if (res) {
    11031080            fatal_error("Unable to copy post-nuke tarball to tmpdir");
    11041081        }
    11051082    }
    1106 
    11071083
    11081084    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    11251101
    11261102    /*@ buffers ******** */
    1127     char netfs_dev[MAX_STR_LEN];
    1128     char netfs_mount[MAX_STR_LEN];
    1129     char netfs_client_hwaddr[MAX_STR_LEN];
    1130     char netfs_client_ipaddr[MAX_STR_LEN];
    1131     char netfs_client_netmask[MAX_STR_LEN];
    1132     char netfs_client_broadcast[MAX_STR_LEN];
    1133     char netfs_client_defgw[MAX_STR_LEN];
    1134     char netfs_server_ipaddr[MAX_STR_LEN];
    1135     char tmp[MAX_STR_LEN];
    1136     char command[MAX_STR_LEN * 2];
     1103    char *netfs_dev = NULL;
     1104    char *netfs_client_hwaddr = NULL;
     1105    char *netfs_mount = NULL;
     1106    char *netfs_client_ipaddr = NULL;
     1107    char *netfs_client_netmask = NULL;
     1108    char *netfs_client_broadcast = NULL;
     1109    char *netfs_client_defgw = NULL;
     1110    char *netfs_server_ipaddr = NULL;
     1111    char *tmp = NULL;
     1112    char *command = NULL;
    11371113
    11381114    /*@ pointers ***** */
    11391115    char *p;
    11401116
     1117    if (! bkpinfo->netfs_mount) {
     1118        fatal_error("No netfs_mount found !");
     1119    }
     1120
    11411121    log_it("Storing Network configuration");
    1142     strcpy(tmp, bkpinfo->netfs_mount);
     1122    mr_asprintf(tmp, "%s", bkpinfo->netfs_mount);
    11431123    p = strchr(tmp, ':');
    11441124    if (!p) {
    1145         fatal_error
    1146             ("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
     1125        fatal_error("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
    11471126    }
    11481127    *(p++) = '\0';
    1149     strcpy(netfs_server_ipaddr, tmp);
    1150     strcpy(netfs_mount, p);
     1128    mr_asprintf(netfs_server_ipaddr, "%s", tmp);
     1129    mr_asprintf(netfs_mount, "%s", p);
     1130    mr_free(tmp);
    11511131
    11521132    /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
    1153     sprintf(command,
    1154             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1155     strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));
    1156     sprintf(command,
    1157             "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);
    1158     strcpy(netfs_client_hwaddr, call_program_and_get_last_line_of_output(command));
    1159     sprintf(command,
    1160             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1161     strcpy(netfs_client_ipaddr,
    1162           call_program_and_get_last_line_of_output(command));
    1163     sprintf(command,
    1164             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1165     strcpy(netfs_client_netmask,
    1166           call_program_and_get_last_line_of_output(command));
    1167     sprintf(command,
    1168             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    1169     strcpy(netfs_client_broadcast,
    1170           call_program_and_get_last_line_of_output(command));
    1171     sprintf(command,
    1172             "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    1173     strcpy(netfs_client_defgw,
    1174           call_program_and_get_last_line_of_output(command));
    1175     sprintf(tmp,
    1176             "netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s",
    1177             netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount);
     1133    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
     1134    mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1135    mr_free(command);
     1136
     1137    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
     1138    mr_asprintf(netfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));
     1139    mr_free(command);
     1140
     1141    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
     1142    mr_asprintf(netfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));
     1143    mr_free(command);
     1144
     1145    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
     1146    mr_asprintf(netfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));
     1147    mr_free(command);
     1148
     1149    mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");
     1150    mr_asprintf(netfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));
     1151    mr_free(command);
     1152
     1153    mr_asprintf(command, "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);
     1154    mr_asprintf(netfs_client_hwaddr, "%s" call_program_and_get_last_line_of_output(command));
     1155    mr_free(command);
     1156
     1157    log_it("netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s", netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount);
    11781158    if (strlen(netfs_dev) < 2) {
    1179         fatal_error
    1180             ("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");
    1181     }
     1159        fatal_error("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");
     1160    }
     1161
    11821162    /********
    1183     * If the Network device that found above is a bonded device,
     1163    * If the Network device found above is a bonded device,
    11841164    * we need to replace it with an ethN device or the
    11851165    * networking will not start during an Network restore.
     
    11911171    if (!strncmp(netfs_dev, "bond", 4) || !strncmp(netfs_dev, "alb", 3) || !strncmp(netfs_dev, "aft", 3)) {
    11921172        log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", netfs_dev);
    1193         sprintf(command,
    1194                 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);
    1195         strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));
     1173        mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);
     1174        mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1175        mr_free(command);
    11961176        log_to_screen("Replacing it with %s\n", netfs_dev);
    11971177    }
    11981178
    1199     sprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);
     1179    mr_asprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);
    12001180    write_one_liner_data_file(tmp, netfs_dev);
     1181    mr_free(netfs_dev);
     1182    mr_free(tmp);
     1183
     1184    mr_asprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir);
     1185    write_one_liner_data_file(tmp, netfs_client_hwaddr);
     1186    mr_free(netfs_client_hwaddr);
     1187    mr_free(tmp);
     1188
     1189    mr_asprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1190    write_one_liner_data_file(tmp, netfs_client_ipaddr);
     1191    mr_free(netfs_client_ipaddr);
     1192    mr_free(tmp);
     1193
     1194    mr_asprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir);
     1195    write_one_liner_data_file(tmp, netfs_client_netmask);
     1196    mr_free(netfs_client_netmask);
     1197    mr_free(tmp);
     1198
     1199    mr_asprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
     1200    write_one_liner_data_file(tmp, netfs_client_broadcast);
     1201    mr_free(netfs_client_broadcast);
     1202    mr_free(tmp);
     1203
     1204    mr_asprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir);
     1205    write_one_liner_data_file(tmp, netfs_client_defgw);
     1206    mr_free(netfs_client_defgw);
     1207    mr_free(tmp);
     1208
     1209    mr_asprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1210    write_one_liner_data_file(tmp, netfs_server_ipaddr);
     1211    mr_free(netfs_server_ipaddr);
     1212    mr_free(tmp);
     1213
     1214    mr_asprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1215    write_one_liner_data_file(tmp, bkpinfo->netfs_mount);
     1216    mr_free(tmp);
     1217
     1218    if (bkpinfo->netfs_user) {
     1219        mr_asprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir);
     1220        write_one_liner_data_file(tmp, bkpinfo->netfs_user);
     1221        mr_free(tmp);
     1222    }
     1223    mr_asprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir);
     1224    write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir);
     1225    mr_free(tmp);
     1226
     1227    mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     1228    write_one_liner_data_file(tmp, bkpinfo->prefix);
     1229    mr_free(tmp);
    12011230
    12021231    sprintf(tmp, "%s/NETFS-PROTO", bkpinfo->tmpdir);
    12031232    write_one_liner_data_file(tmp, bkpinfo->netfs_proto);
    1204 
    1205     sprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir);
    1206     write_one_liner_data_file(tmp, netfs_client_hwaddr);
    1207     sprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    1208     write_one_liner_data_file(tmp, netfs_client_ipaddr);
    1209     sprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir);
    1210     write_one_liner_data_file(tmp, netfs_client_netmask);
    1211     sprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
    1212     write_one_liner_data_file(tmp, netfs_client_broadcast);
    1213     sprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir);
    1214     write_one_liner_data_file(tmp, netfs_client_defgw);
    1215     sprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir);
    1216     write_one_liner_data_file(tmp, netfs_server_ipaddr);
    1217     sprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir);
    1218     write_one_liner_data_file(tmp, bkpinfo->netfs_mount);
    1219     if (bkpinfo->netfs_user) {
    1220         sprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir);
    1221         write_one_liner_data_file(tmp, bkpinfo->netfs_user);
    1222     }
    1223     sprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir);
    1224     write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir);
    1225     sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    1226     write_one_liner_data_file(tmp, bkpinfo->prefix);
     1233    mr_free(tmp);
     1234
     1235
    12271236    log_it("Finished storing Network configuration");
    12281237}
    1229 
    1230 
    1231 
    1232 
    12331238
    12341239
     
    12531258{
    12541259    /*@ buffers *************** */
    1255     char tmp[MAX_STR_LEN];
     1260    char *tmp = NULL;
    12561261    char *mds = NULL;
    12571262
     
    12651270
    12661271    log_it("Estimating number of media required...");
    1267     scratchLL =
    1268         (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size)
    1269         + (long long) (size_of_all_biggiefiles_K());
     1272    scratchLL = (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) + (long long) (size_of_all_biggiefiles_K());
    12701273    scratchLL = (scratchLL / 1024) / bkpinfo->media_size;
    12711274    scratchLL++;
     
    12741277    } else if (bkpinfo->use_gzip) {
    12751278        scratchLL = (scratchLL * 2) / 3;
     1279    } else if (bkpinfo->use_lzma) {
     1280        scratchLL = (scratchLL * 2) / 3;
    12761281    } else {
    12771282        scratchLL = scratchLL / 2;
     
    12821287    if (scratchLL <= 1) {
    12831288        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1284         sprintf(tmp,
    1285                 "Your backup will probably occupy a single %s. Maybe two.", mds);
     1289        mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
    12861290        mr_free(mds);
    12871291    } else if (scratchLL > 4) {
    1288         sprintf(tmp,
    1289                 "Your backup will occupy one meeeeellion media! (maybe %s)",
    1290                 number_to_text((int) (scratchLL + 1)));
     1292        mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));
    12911293    } else {
    1292         sprintf(tmp, "Your backup will occupy approximately %s media.",
    1293                 number_to_text((int) (scratchLL + 1)));
    1294     }
    1295     if (!bkpinfo->image_devs[0] && (scratchLL < 50)) {
     1294        mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));
     1295    }
     1296    if (scratchLL < 50) {
    12961297        log_to_screen(tmp);
    12971298    }
    1298 }
    1299 
    1300 
    1301 /**
    1302  * Get the last suffix of @p instr.
    1303  * If @p instr was "httpd.log.gz", we would return "gz".
    1304  * @param instr The filename to get the suffix of.
    1305  * @return The suffix (without a dot), or "" if none.
    1306  * @note The returned string points to static storage that will be overwritten with each call.
    1307  */
    1308 char *sz_last_suffix(char *instr)
    1309 {
    1310     static char outstr[MAX_STR_LEN];
    1311     char *p;
    1312 
    1313     p = strrchr(instr, '.');
    1314     if (!p) {
    1315         outstr[0] = '\0';
    1316     } else {
    1317         strcpy(outstr, p);
    1318     }
    1319     return (outstr);
     1299    mr_free(tmp);
    13201300}
    13211301
     
    13291309bool is_this_file_compressed(char *filename)
    13301310{
    1331     char do_not_compress_these[MAX_STR_LEN];
    1332     char tmp[MAX_STR_LEN];
     1311    char *do_not_compress_these = NULL;
     1312    char *tmp = NULL;
    13331313    char *p;
    13341314    char *q = NULL;
     
    13391319    }
    13401320
    1341     sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1321    mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
    13421322    if (!does_file_exist(tmp)) {
     1323        mr_free(tmp);
    13431324        return (FALSE);
    13441325    }
    13451326    /* BERLIOS: This is just plain WRONG !! */
    1346     strcpy(do_not_compress_these,last_line_of_file(tmp));
     1327    mr_asprintf(do_not_compress_these,"%s", last_line_of_file(tmp));
     1328    mr_free(tmp);
    13471329
    13481330    for (p = do_not_compress_these; p != NULL; p++) {
    1349         strcpy(tmp, p);
     1331        mr_asprintf(tmp, "%s", p);
    13501332        if (strchr(tmp, ' ')) {
    13511333            *(strchr(tmp, ' ')) = '\0';
    13521334        }
    13531335        if (!strcmp(q, tmp)) {
     1336            mr_free(tmp);
     1337            mr_free(do_not_compress_these);
    13541338            return (TRUE);
    13551339        }
     
    13571341            break;
    13581342        }
    1359     }
     1343        mr_free(tmp);
     1344    }
     1345    mr_free(do_not_compress_these);
    13601346    return (FALSE);
    13611347}
  • branches/3.2/mondo/src/common/libmondo-files.h

    r2904 r3191  
    4242
    4343
    44 int make_hole_for_dir(char *outdir_fname);
     44int make_hole_for_dir(const char *outdir_fname);
    4545long size_of_partition_in_mountlist_K(char *tmpdir, char *dev);
    4646int read_one_liner_data_file(char *fname, char *contents);
  • branches/3.2/mondo/src/common/libmondo-fork.c

    r3185 r3191  
    88#include "my-stuff.h"
    99#include "mr_mem.h"
     10#include "mr_str.h"
    1011#include "mondostructures.h"
    1112#include "libmondo-fork.h"
     
    3839    /*@ buffers ***************************************************** */
    3940    static char result[MAX_STR_LEN];
    40     char *tmp;
    41     char *p;
     41    char *tmp = NULL;
    4242
    4343    /*@ pointers **************************************************** */
    44     FILE *fin;
     44    FILE *fin = NULL;
     45    int res = 0;
    4546
    4647    /*@ initialize data ********************************************* */
    47     malloc_string(tmp);
    4848    result[0] = '\0';
    49     tmp[0] = '\0';
    5049
    5150    /*@******************************************************************** */
     
    5352    assert_string_is_neither_NULL_nor_zerolength(call);
    5453    if ((fin = popen(call, "r"))) {
    55         for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL);
    56              p = fgets(tmp, MAX_STR_LEN, fin)) {
     54        for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    5755            if (strlen(tmp) > 1) {
    5856                strcpy(result, tmp);
    5957            }
     58            mr_free(tmp);
    6059        }
    6160        paranoid_pclose(fin);
    6261    } else {
    63         log_OS_error("Unable to popen call");
     62        log_OS_error("Unable to open resulting file");
    6463    }
    6564    strip_spaces(result);
    66     paranoid_free(tmp);
    67     return (result);
    68 }
    69 
    70 
    71 
    72 
     65    mr_free(tmp);
     66    return(result);
     67}
    7368
    7469
     
    8681 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs).
    8782 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number.
    88  * @param logstub Unused.
    8983 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog.
    9084 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure).
    91  * @bug @p logstub is unused.
    9285 */
    9386int
     
    10194
    10295    /*@ buffers      *** */
    103     char *midway_call, *ultimate_call, *tmp, *command, *incoming,
    104         *old_stderr, *cd_number_str;
    105     char *p;
     96    char *midway_call = NULL;
     97    char *ultimate_call = NULL;
     98    char *tmp = NULL;
     99       
     100    char *cd_number_str = NULL;
     101    char *command = NULL;
     102    char *p= NULL;
    106103    char *tmp1 = NULL;
     104    char *tmp2 = NULL;
    107105
    108106/*@***********   End Variables ***************************************/
     
    110108    log_msg(3, "Starting");
    111109    assert(bkpinfo != NULL);
    112     // BERLIOS: doesn't work even if the string is correct !
    113     //assert_string_is_neither_NULL_nor_zerolength(basic_call);
    114110    assert_string_is_neither_NULL_nor_zerolength(isofile);
    115     assert_string_is_neither_NULL_nor_zerolength(logstub);
     111
    116112    if (!(midway_call = malloc(1200))) {
    117113        fatal_error("Cannot malloc midway_call");
     
    123119        fatal_error("Cannot malloc tmp");
    124120    }
    125     if (!(command = malloc(1200))) {
    126         fatal_error("Cannot malloc command");
    127     }
    128     malloc_string(incoming);
    129     malloc_string(old_stderr);
    130     malloc_string(cd_number_str);
    131 
    132     incoming[0] = '\0';
    133     old_stderr[0] = '\0';
    134121
    135122    if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
     
    139126    }
    140127
    141     sprintf(cd_number_str, "%d", cd_no);
     128    mr_asprintf(cd_number_str, "%d", cd_no);
    142129    resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_");
     130    log_msg(4, "basic call = '%s'", tmp1);
     131    mr_free(tmp1);
     132
    143133    resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
     134    log_msg(4, "midway_call = '%s'", midway_call);
     135    mr_free(cd_number_str);
     136
    144137    resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
    145     log_msg(4, "basic call = '%s'", tmp1);
    146     log_msg(4, "midway_call = '%s'", midway_call);
    147     log_msg(4, "tmp = '%s'", tmp);
    148138    log_msg(4, "ultimate call = '%s'", ultimate_call);
    149     sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
    150 
    151     log_to_screen
    152         ("Please be patient. Do not be alarmed by on-screen inactivity.");
    153     log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
    154             what_i_am_doing);
    155     strcpy(tmp, command);
     139    mr_asprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
     140
     141    log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity.");
     142    log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing);
    156143    if (bkpinfo->manual_cd_tray) {
    157         p = strstr(tmp, "2>>");
     144        mr_asprintf(tmp2, "%s", command);
     145        p = strstr(tmp2, "2>>");
    158146        if (p) {
    159147            sprintf(p, "   ");
     
    161149                p++;
    162150            }
    163             for (; *p != ' '; p++) {
     151            for (; (*p != ' ') && (*p != '\0'); p++) {
    164152                *p = ' ';
    165153            }
    166154        }
    167         strcpy(command, tmp);
    168 #ifndef _XWIN
     155        mr_free(command);
     156        command = tmp2;
    169157        if (!g_text_mode) {
    170158            newtSuspend();
    171159        }
    172 #endif
    173160        log_msg(1, "command = '%s'", command);
    174161        retval += system(command);
     
    177164        }
    178165        if (retval) {
    179             log_msg(2, "Basic call '%s' returned an error.", tmp1);
    180             popup_and_OK("Press ENTER to continue.");
    181             popup_and_OK
    182                 ("mkisofs and/or cdrecord returned an error. CD was not created");
     166            popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created");
    183167        }
    184168    }
     
    186170    else {
    187171        log_msg(3, "command = '%s'", command);
    188 //      yes_this_is_a_goto:
    189         retval =
    190             run_external_binary_with_percentage_indicator_NEW
    191             (what_i_am_doing, command);
    192     }
    193 
    194     mr_free(tmp1);
     172        retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
     173    }
     174    mr_free(command);
    195175    paranoid_free(midway_call);
    196176    paranoid_free(ultimate_call);
    197177    paranoid_free(tmp);
    198     paranoid_free(command);
    199     paranoid_free(incoming);
    200     paranoid_free(old_stderr);
    201     paranoid_free(cd_number_str);
    202178    return (retval);
    203179}
     
    232208    log_msg(1, "command = '%s'", command);
    233209    if (!g_text_mode) {
    234         retval = run_external_binary_with_percentage_indicator_NEW
    235             (what_i_am_doing, command);
     210        retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
    236211    } else {
    237212        retval += system(command);
     
    277252        return (1);
    278253    }
    279 //  if (debug_level == TRUE) { debug_level=5; }
    280 
    281     //  assert_string_is_neither_NULL_nor_zerolength(program);
    282254
    283255    if (debug_level <= g_loglevel) {
     
    322294                }
    323295            }
    324             /* end of patch */
    325296            strip_spaces(incoming);
    326297            if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
     
    342313        }
    343314    }
    344 //  else
    345 //    { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); }
    346315    return (res);
    347316}
     
    368337
    369338    /*@ buffers **************************************************** */
    370     char *tmp = NULL;
    371339    char *command = NULL;
    372     char lockfile[MAX_STR_LEN];
     340    char *lockfile = NULL;
    373341
    374342    /*@ end vars *************************************************** */
     
    376344    assert_string_is_neither_NULL_nor_zerolength(basic_call);
    377345
    378     sprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
    379 
    380     mr_asprintf(command,
    381             "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
    382             lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
     346    mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
     347
     348    mr_asprintf(command, "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
    383349    open_evalcall_form(what_i_am_doing);
    384     mr_asprintf(tmp, "Executing %s", basic_call);
    385     log_msg(2, tmp);
    386     mr_free(tmp);
     350    log_msg(2, "Executing %s", basic_call);
    387351
    388352    if (!(fin = popen(command, "r"))) {
    389353        log_OS_error("Unable to popen-in command");
    390         mr_asprintf(tmp, "Failed utterly to call '%s'", command);
    391         log_to_screen(tmp);
    392         mr_free(tmp);
     354        log_to_screen("Failed utterly to call '%s'", command);
    393355        mr_free(command);
     356        mr_free(lockfile);
    394357        return (1);
    395358    }
     359
    396360    if (!does_file_exist(lockfile)) {
    397361        log_to_screen("Waiting for '%s' to start",command);
     
    401365    }
    402366    mr_free(command);
    403 #ifdef _XWIN
    404     /* This only can update when newline goes into the file,
    405        but it's *much* prettier/faster on Qt. */
    406     while (does_file_exist(lockfile)) {
    407         while (!feof(fin)) {
    408             /* TODO: Dead and wrong code */
    409             if (!fgets(tmp, 512, fin))
    410                 break;
    411             log_to_screen(tmp);
    412         }
    413         usleep(500000);
    414     }
    415 #else
    416     /* This works on Newt, and it gives quicker updates. */
     367
    417368    for (; does_file_exist(lockfile); sleep(1)) {
    418369        log_file_end_to_screen(MONDO_LOGFILE, "");
    419370        update_evalcall_form(1);
    420371    }
    421 #endif
     372
    422373    /* Evaluate the status returned by pclose to get the exit code of the called program. */
    423374    errno = 0;
     
    434385    close_evalcall_form();
    435386    unlink(lockfile);
     387    mr_free(lockfile);
     388
    436389    return (retval);
    437390}
     
    453406// if dir=='w' then copy from orig to archived
    454407// if dir=='r' then copy from archived to orig
    455     char *tmp;
    456     char *buf;
    457     char filestr[MAX_STR_LEN];
     408    char *tmp = NULL;
     409    char *tmp1 = NULL;
     410    char *buf = NULL;
     411    char *filestr = NULL;
    458412    long int bytes_to_be_read, bytes_read_in, bytes_written_out =
    459413        0, bufcap, subsliceno = 0;
     
    465419
    466420    log_msg(5, "Opening.");
    467     if (!(tmp = malloc(tmpcap))) {
    468         fatal_error("Failed to malloc() tmp");
    469     }
    470     tmp[0] = '\0';
     421
    471422    bufcap = 256L * 1024L;
    472423    if (!(buf = malloc(bufcap))) {
     
    477428        fin = f_orig;
    478429        fout = f_archived;
    479         sprintf(tmp, "%-64s", PIMP_START_SZ);
     430        mr_asprintf(tmp, "%-64s", PIMP_START_SZ);
    480431        if (fwrite(tmp, 1, 64, fout) != 64) {
     432            mr_free(tmp);
    481433            fatal_error("Can't write the introductory block");
    482434        }
     435        mr_free(tmp);
     436
    483437        while (1) {
    484438            bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
     
    486440                break;
    487441            }
    488             sprintf(tmp, "%-64ld", bytes_read_in);
     442            mr_asprintf(tmp, "%-64ld", bytes_read_in);
    489443            if (fwrite(tmp, 1, 64, fout) != 64) {
     444                mr_free(tmp);
    490445                fatal_error("Cannot write introductory block");
    491446            }
     447            mr_free(tmp);
     448
    492449            log_msg(7,
    493450                    "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
    494451                    subsliceno, bytes_read_in, bytes_to_be_read);
    495452            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    496             sprintf(tmp, "%-64ld", subsliceno);
     453            mr_asprintf(tmp, "%-64ld", subsliceno);
    497454            if (fwrite(tmp, 1, 64, fout) != 64) {
     455                mr_free(tmp);
    498456                fatal_error("Cannot write post-thingy block");
    499457            }
     458            mr_free(tmp);
    500459            log_msg(7, "Subslice #%d written OK", subsliceno);
    501460            subsliceno++;
    502461        }
    503         sprintf(tmp, "%-64ld", 0L);
     462        mr_asprintf(tmp, "%-64ld", 0L);
    504463        if (fwrite(tmp, 1, 64L, fout) != 64L) {
     464            mr_free(tmp);
    505465            fatal_error("Cannot write final introductory block");
    506466        }
     467        mr_free(tmp);
     468
     469        mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
     470        if (fwrite(tmp, 1, 64, fout) != 64) {
     471            mr_free(tmp);
     472            fatal_error("Can't write the final block");
     473        }
     474        mr_free(tmp);
    507475    } else {
    508476        fin = f_archived;
    509477        fout = f_orig;
    510         if (fread(tmp, 1, 64L, fin) != 64L) {
     478        if (!(tmp1 = malloc(tmpcap))) {
     479            fatal_error("Failed to malloc() tmp");
     480        }
     481        if (fread(tmp1, 1, 64L, fin) != 64L) {
     482            mr_free(tmp1);
    511483            fatal_error("Cannot read the introductory block");
    512484        }
    513         log_msg(5, "tmp is %s", tmp);
    514         if (!strstr(tmp, PIMP_START_SZ)) {
     485        log_msg(5, "tmp1 is %s", tmp1);
     486        if (!strstr(tmp1, PIMP_START_SZ)) {
     487            mr_free(tmp1);
    515488            fatal_error("Can't find intro blk");
    516489        }
    517         if (fread(tmp, 1, 64L, fin) != 64L) {
     490        if (fread(tmp1, 1, 64L, fin) != 64L) {
     491            mr_free(tmp1);
    518492            fatal_error("Cannot read introductory blk");
    519493        }
    520         bytes_to_be_read = atol(tmp);
     494        bytes_to_be_read = atol(tmp1);
    521495        while (bytes_to_be_read > 0) {
    522             log_msg(7, "subslice#%ld, bytes=%ld", subsliceno,
    523                     bytes_to_be_read);
     496            log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read);
    524497            bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
    525498            if (bytes_read_in != bytes_to_be_read) {
    526                 fatal_error
    527                     ("Danger, WIll Robinson. Failed to read whole subvol from archives.");
     499                mr_free(tmp1);
     500                fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives.");
    528501            }
    529502            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    530             if (fread(tmp, 1, 64, fin) != 64) {
     503            if (fread(tmp1, 1, 64, fin) != 64) {
     504                mr_free(tmp1);
    531505                fatal_error("Cannot read post-thingy block");
    532506            }
    533             if (atol(tmp) != subsliceno) {
    534                 log_msg(1, "Wanted subslice %ld but got %ld ('%s')",
    535                         subsliceno, atol(tmp), tmp);
     507            if (atol(tmp1) != subsliceno) {
     508                log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1);
    536509            }
    537510            log_msg(7, "Subslice #%ld read OK", subsliceno);
    538511            subsliceno++;
    539             if (fread(tmp, 1, 64, fin) != 64) {
     512            if (fread(tmp1, 1, 64, fin) != 64) {
     513                mr_free(tmp1);
    540514                fatal_error("Cannot read introductory block");
    541515            }
    542             bytes_to_be_read = atol(tmp);
    543         }
    544     }
    545 
    546 //  log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in);
     516            bytes_to_be_read = atol(tmp1);
     517        }
     518    }
    547519
    548520    if (direction == 'w') {
    549         sprintf(tmp, "%-64s", PIMP_END_SZ);
     521        mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
    550522        if (fwrite(tmp, 1, 64, fout) != 64) {
     523            mr_free(tmp);
    551524            fatal_error("Can't write the final block");
    552525        }
     526        mr_free(tmp);
    553527    } else {
    554         log_msg(1, "tmpA is %s", tmp);
    555         if (!strstr(tmp, PIMP_END_SZ)) {
    556             if (fread(tmp, 1, 64, fin) != 64) {
     528        log_msg(1, "tmpA is %s", tmp1);
     529        if (!strstr(tmp1, PIMP_END_SZ)) {
     530            if (fread(tmp1, 1, 64, fin) != 64) {
     531                mr_free(tmp1);
    557532                fatal_error("Can't read the final block");
    558533            }
    559             log_msg(5, "tmpB is %s", tmp);
    560             if (!strstr(tmp, PIMP_END_SZ)) {
    561                 sprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);
     534            log_msg(5, "tmpB is %s", tmp1);
     535            if (!strstr(tmp1, PIMP_END_SZ)) {
     536                mr_asprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);
    562537                ftmp = fopen(filestr, "w");
    563                 bytes_read_in = fread(tmp, 1, 64, fin);
     538                mr_free(filestr);
     539
     540                bytes_read_in = fread(tmp1, 1, 64, fin);
    564541                log_msg(1, "bytes_read_in = %ld", bytes_read_in);
    565 //      if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); }
     542
    566543                if (fwrite(tmp, 1, bytes_read_in, ftmp)) {
    567544                    fatal_error("Can't fwrite here");
    568545                }
    569                 sprintf(tmp, "I am here - %lld", (long long)ftello(fin));
    570 //    log_msg(0, tmp);
     546
     547                mr_asprintf(tmp, "I am here - %lld", (long long)ftello(fin));
    571548                if (fread(tmp, 1, tmpcap, fin)) {
     549                    mr_free(tmp);
    572550                    fatal_error("Can't fread here");
    573551                }
    574552                log_msg(0, "tmp = '%s'", tmp);
    575553                if (fwrite(tmp, 1, tmpcap, ftmp)) {
     554                    mr_free(tmp);
    576555                    fatal_error("Can't fwrite there");
    577556                }
    578557                fclose(ftmp);
     558                mr_free(tmp);
    579559                fatal_error("Missing terminating block");
    580560            }
    581561        }
    582562    }
     563    mr_free(tmp1);
    583564
    584565    paranoid_free(buf);
    585     paranoid_free(tmp);
    586566    log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
    587567    return (retval);
     
    601581// BACKUP
    602582    int res = -1;
    603     char*command;
     583    char *command = NULL;
    604584
    605585    if (!does_file_exist(input_device)) {
     
    609589        fatal_error("ntfsclone not found");
    610590    }
    611     malloc_string(command);
    612     sprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
     591    mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
    613592    res = run_program_and_log_output(command, 5);
    614     paranoid_free(command);
     593    mr_free(command);
     594
    615595    unlink(output_fname);
    616596    return (res);
     
    638618
    639619
    640 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd)
    641 {
     620int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) {
    642621
    643622    /*@ int *************************************************************** */
     
    650629
    651630    /*@ buffers *********************************************************** */
    652     char *command;
    653     char *title;
     631    char *command = NULL;
    654632    /*@ pointers ********************************************************** */
    655633    static int chldres = 0;
     
    662640    *pchild_result = 999;
    663641
    664     malloc_string(title);
    665     malloc_string(command);
    666     strcpy(title, tt);
    667     sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
     642    mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
    668643    log_msg(3, "command = '%s'", command);
    669     if ((res =
    670          pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit,
    671                         (void *) command))) {
     644    if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) {
    672645        fatal_error("Unable to create an archival thread");
    673646    }
    674647
    675648    log_msg(8, "Parent running");
    676     open_evalcall_form(title);
     649    open_evalcall_form(tt);
     650
    677651    for (sleep(1); command[0] != '\0'; sleep(1)) {
    678652        pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
    679         if (pcno <= 0 || pcno > 100) {
    680             log_msg(8, "Weird pc#");
     653        if (pcno < 0 || pcno > 100) {
     654            log_msg(8, "Weird pc# %d", pcno);
    681655            continue;
    682656        }
     
    684658        if (pcno <= 5 && last_pcno >= 40) {
    685659            close_evalcall_form();
    686             strcpy(title, "Verifying...");
    687             open_evalcall_form(title);
     660            open_evalcall_form("Verifying...");
    688661        }
    689662        if (counter++ >= 5) {
     
    694667        update_evalcall_form(percentage);
    695668    }
     669    mr_free(command);
     670
    696671    log_file_end_to_screen(MONDO_LOGFILE, "");
    697672    close_evalcall_form();
     
    703678    }
    704679    log_msg(3, "Parent res = %d", res);
    705     paranoid_free(command);
    706     paranoid_free(title);
    707680    return (res);
    708681}
    709 
    710 
    711682
    712683
     
    721692// RESTORE
    722693    int res = -1;
    723     char *command;
     694    char *command = NULL;
    724695
    725696    if ( !find_home_of_exe("ntfsclone")) {
    726697        fatal_error("ntfsclone not found");
    727698    }
    728     malloc_string(command);
    729     sprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
     699    mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
    730700    res = run_program_and_log_output(command, 5);
    731     paranoid_free(command);
     701    mr_free(command);
    732702    return (res);
    733703}
  • branches/3.2/mondo/src/common/libmondo-gui-EXT.h

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

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

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

    r3185 r3191  
    5959    char tmp = NULL;
    6060    char device[MAX_STR_LEN];
    61     char mountpoint[MAX_STR_LEN];
    6261
    6362    char *flaws_str = NULL;
     
    10099                continue;
    101100            }
    102             strcpy(mountpoint, mountlist->el[pos].mountpoint);
    103101            /* is it too big? */
    104102            if (curr_part_no > 'h') {
     
    176174
    177175        build_partition_name(device, drive, curr_part_no);
    178         strcpy(mountpoint, mountlist->el[pos].mountpoint);
    179176        if (pos > 0 && !npos) {
    180177            /* gap in the partition list? */
     
    260257                    continue;
    261258                }
    262                 strcpy(mountpoint, mountlist->el[pos].mountpoint);
    263259                /* is it too big? */
    264260                if (curr_part_no > 'h') {
     
    327323        if (amount_allocated > physical_drive_size) {
    328324            // Used to be +1, but what if you're 1 MB too high?
    329             mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    330                     amount_allocated - physical_drive_size, drive);
     325            mr_asprintf(tmp, " %ld MB over-allocated on %s.",amount_allocated - physical_drive_size, drive);
    331326            log_it(tmp);
    332327
     
    348343
    349344    /* Over-allocated the disk? Unallocated space on disk? */
    350     if (amount_allocated < physical_drive_size - 1) {   /* NOT AN ERROR, JUST A WARNING :-) */
    351         mr_asprintf(tmp, " %ld MB unallocated on %s.",
    352                 physical_drive_size - amount_allocated, drive);
     345    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
     346    {
     347        mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive);
     348        log_it(tmp);
     349        mr_strcat(flaws_str, "%s", tmp);
     350        mr_free(tmp);
     351        res++;
     352    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
     353        mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive);
    353354        log_it(tmp);
    354355        mr_strcat(flaws_str, "%s", tmp);
     
    405406            goto endoffunc;
    406407        } else {
    407             mr_asprintf(tmp, " %s (dm) will be setup later on", drive);
    408             log_it(tmp);
    409             mr_free(tmp);
     408            log_it(" %s (dm) will be setup later on", drive);
    410409        }
    411410    } else {
    412         mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
    413         log_it(tmp);
    414         mr_free(tmp);
     411        log_it("%s is %ld MB", drive, physical_drive_size);
    415412    }
    416413
     
    432429            } else if (curr_part_no > 5
    433430                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    434                 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive,
    435                         prev_part_no, curr_part_no);
     431                mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, prev_part_no, curr_part_no);
    436432                log_it(tmp);
    437433                mr_strcat(flaws_str, "%s", tmp);
     
    443439        part_table_fmt = which_partition_format(drive);
    444440        /* no spare primary partitions to help accommodate the logical(s)? */
    445         if ((curr_part_no >= 5 && prev_part_no == 4)
    446             && (strcmp(part_table_fmt, "MBR") == 0)) {
     441        if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt, "MBR") == 0)) {
    447442            mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive);
    448443            log_it(tmp);
     
    451446            res++;
    452447        }
     448        mr_free(part_table_fmt);
     449
    453450        /* does partition /dev/hdNX exist more than once in the mountlist? */
    454451        for (i = 0, device_copies = 0;
     
    459456        }
    460457        if (device_copies > 1) {
    461             mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies),
    462                     device);
     458            mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
    463459            if (!strstr(flaws_str, tmp)) {
    464460                log_it(tmp);
     
    504500    /* Over-allocated the disk? Unallocated space on disk? */
    505501    if (amount_allocated > physical_drive_size + 1) {
    506         mr_asprintf(tmp, " %ld MB over-allocated on %s.",
    507                 amount_allocated - physical_drive_size, drive);
     502        mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive);
    508503        log_it(tmp);
    509504        mr_strcat(flaws_str, "%s", tmp);
     
    511506        res++;
    512507    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    513         mr_asprintf(tmp, " %ld MB unallocated on %s.",
    514                 physical_drive_size - amount_allocated, drive);
     508        mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive);
    515509        log_it(tmp);
    516510        mr_strcat(flaws_str, "%s", tmp);
     
    570564            (drivelist->el[i].device,
    571565             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
    572             mr_asprintf(tmp, " Not evaluating %s (I don't know how yet)", drivelist->el[i].device);
    573             log_it(tmp);
    574             paranoid_free(tmp);
     566            log_it(" Not evaluating %s (I don't know how yet)", drivelist->el[i].device);
    575567        } else {
    576568            log_msg(8, "Evaluating drive #%d (%s) within mountlist", i, drivelist->el[i].device);
     
    582574            log_msg(8,"Adding: %s to flaws_str", tmp);
    583575            mr_strcat(flaws_str, "%s", tmp);
    584             paranoid_free(tmp);
     576            mr_free(tmp);
    585577        }
    586578    }
     
    602594            mr_strcat(flaws_str, "%s", tmp);
    603595            log_msg(8,"Adding: %s to flaws_str", tmp);
    604             paranoid_free(tmp);
    605         }
    606         paranoid_free(curr_mountpoint);
     596            mr_free(tmp);
     597        }
     598        mr_free(curr_mountpoint);
    607599    }
    608600
     
    669661        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    670662            log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);
    671             paranoid_free(drive);
     663            mr_free(drive);
    672664            continue;
    673665        }
     
    676668        if (size == 0) {
    677669            log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive);
    678             paranoid_free(drive);
     670            mr_free(drive);
    679671            continue;
    680672        }
     
    684676        /* memory allocation */
    685677        truncdrive = truncate_to_drive_name(drive);
    686         paranoid_free(drive);
     678        mr_free(drive);
    687679
    688680        log_msg(8, "drive truncated to %s", truncdrive);
     
    733725    int used_by = 0;
    734726
    735     /*@ buffers ********************************************************* */
    736     char *tmp = NULL;
    737 
    738727    assert(output_list != NULL);
    739728    assert(mountlist != NULL);
     
    745734    for (i = 0; i < mountlist->entries; i++) {
    746735        if (strstr(mountlist->el[i].mountpoint, "raid")) {
    747             used_by =
    748                 which_raid_device_is_using_this_partition(raidlist,
    749                                                           mountlist->el[i].
    750                                                           device);
     736            used_by = which_raid_device_is_using_this_partition(raidlist, mountlist->el[i].device);
    751737            if (used_by < 0) {
    752738                memcpy((void *) &output_list->el[items++],
    753739                       (void *) &mountlist->el[i],
    754740                       sizeof(struct mountlist_line));
    755                 mr_asprintf(tmp, "%s is available; user may choose to add it to raid device", output_list->el[items - 1].device);
    756                 log_it(tmp);
    757                 paranoid_free(tmp);
     741                log_it("%s is available; user may choose to add it to raid device", output_list->el[items - 1].device);
    758742            }
    759743        }
     
    810794    char *tmp = NULL;
    811795    char *p = NULL;
    812     char *q = NULL;
    813796
    814797    int items = 0;
     
    824807        return (1);
    825808    }
    826     malloc_string(incoming);
    827809    malloc_string(siz);
    828     q = fgets(incoming, MAX_STR_LEN - 1, fin);
    829810    log_it("Loading mountlist...");
    830     while (!feof(fin) && (q != NULL)) {
     811    mr_getline(incoming, fin);
     812    while (!feof(fin)) {
    831813#if linux
    832         res = sscanf(incoming,
    833                "%s %s %s %s %s",
    834                mountlist->el[items].device,
    835                mountlist->el[items].mountpoint,
    836                mountlist->el[items].format,
    837                siz, mountlist->el[items].label);
     814        res = sscanf(incoming, "%s %s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz, mountlist->el[items].label);
    838815        if (res < 5) {
    839816            /* no label found */
     
    842819        }
    843820#elif __FreeBSD__
    844         res = sscanf(incoming,
    845                "%s %s %s %s",
    846                mountlist->el[items].device,
    847                mountlist->el[items].mountpoint,
    848                mountlist->el[items].format, siz);
     821        res = sscanf(incoming, "%s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz);
    849822        strcpy(mountlist->el[items].label,"");
    850823#endif
     
    859832            !strcmp(mountlist->el[items].device, "devpts")
    860833            ) {
    861             log_msg(1,
    862                     "Ignoring %s in mountlist - not loading that line :) ",
    863                     mountlist->el[items].device);
    864             q = fgets(incoming, MAX_STR_LEN - 1, fin);
     834            log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device);
     835            mr_free(incoming);
     836            mr_getline(incoming, fin);
    865837            continue;
    866838        }
     
    874846            if (j < items) {
    875847                strcat(mountlist->el[items].device, "_dup");
    876                 mr_asprintf(tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
    877                 log_it(tmp);
    878                 paranoid_free(tmp);
     848                log_it("Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device);
    879849            }
    880850            mr_asprintf(tmp, "%s", mountlist->el[items].device);
     
    887857                    *(p + 2) = *(p + 3);
    888858                }
    889                 log_it("It was %s; it is now %s",
    890                        mountlist->el[items].device, tmp);
     859                log_it("It was %s; it is now %s", mountlist->el[items].device, tmp);
    891860                strcpy(mountlist->el[items].device, tmp);
    892861            }
    893862            paranoid_free(tmp);
    894863
    895             log_it("%s %s %s %lld %s",
    896                      mountlist->el[items].device,
    897                      mountlist->el[items].mountpoint,
    898                      mountlist->el[items].format,
    899                      mountlist->el[items].size,
    900                      mountlist->el[items].label);
     864            log_it("%s %s %s %lld %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, mountlist->el[items].size, mountlist->el[items].label);
    901865            items++;
    902866            if (items >= MAX_MOUNTLIST_ENTRIES) {
     
    905869            }
    906870        }
    907         q = fgets(incoming, MAX_STR_LEN - 1, fin);
    908     }
     871        mr_free(incoming);
     872        mr_getline(incoming, fin);
     873    }
     874    mr_free(incoming);
    909875    paranoid_fclose(fin);
    910876    mountlist->entries = items;
     
    913879    log_it("%d entries in mountlist", items);
    914880
    915     paranoid_free(incoming);
    916881    paranoid_free(siz);
    917882    return (0);
     
    10501015
    10511016    mountlist->el[b].size = size;
    1052     paranoid_free(device);
    1053     paranoid_free(mountpoint);
    1054     paranoid_free(format);
     1017    mr_free(device);
     1018    mr_free(mountpoint);
     1019    mr_free(format);
    10551020}
    10561021
  • branches/3.2/mondo/src/common/libmondo-raid.c

    r3185 r3191  
    335335#ifdef __FreeBSD__
    336336    int i, j;
     337    char *org = NULL;
    337338
    338339    fprintf(fout, "\nvolume %s\n", raidrec->volname);
    339340    for (i = 0; i < raidrec->plexes; ++i) {
    340         char org[24];
    341341        switch (raidrec->plex[i].raidlevel) {
    342342        case -1:
    343             strcpy(org, "concat");
     343            mr_asprintf(org, "concat");
    344344            break;
    345345        case 0:
    346             strcpy(org, "striped");
     346            mr_asprintf(org, "striped");
    347347            break;
    348348        case 5:
    349             strcpy(org, "raid5");
     349            mr_asprintf(org, "raid5");
    350350            break;
    351351        }
    352352        fprintf(fout, "  plex org %s", org);
     353        mr_free(org);
     354
    353355        if (raidrec->plex[i].raidlevel != -1) {
    354356            fprintf(fout, " %ik", raidrec->plex[i].stripesize);
     
    357359
    358360        for (j = 0; j < raidrec->plex[i].subdisks; ++j) {
    359             fprintf(fout, "    sd drive %s size 0\n",
    360                     raidrec->plex[i].sd[j].which_device);
     361            fprintf(fout, "    sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device);
    361362        }
    362363    }
     
    427428int get_next_raidtab_line(FILE * fin, char *label, char *value)
    428429{
    429     char *incoming;
     430    char *incoming = NULL;
    430431    char *p;
    431     char *q;
    432 
    433     malloc_string(incoming);
     432
    434433    assert(fin != NULL);
    435434    assert(label != NULL);
     
    438437    label[0] = value[0] = '\0';
    439438    if (feof(fin)) {
    440         paranoid_free(incoming);
    441439        return (1);
    442440    }
    443     for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL);
    444          q = fgets(incoming, MAX_STR_LEN - 1, fin)) {
    445         strip_spaces(incoming);
     441    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     442        mr_strip_spaces(incoming);
    446443        p = strchr(incoming, ' ');
    447444        if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
     445            mr_free(incoming);
    448446            continue;
    449447        }
     
    454452        strcpy(label, incoming);
    455453        strcpy(value, p);
    456         paranoid_free(incoming);
     454        mr_free(incoming);
    457455        return (0);
    458456    }
     457    mr_free(incoming);
    459458    return (1);
    460459}
     
    473472{
    474473    FILE *fin;
    475     char *tmp1 = NULL;
    476474    int items;
    477475
     
    504502
    505503            if (get_option_state(argc, argv, "hotspare")) {
    506                 strcpy(raidlist->spares.el[raidlist->spares.entries].name,
    507                        drivename);
    508                 strcpy(raidlist->spares.el[raidlist->spares.entries].
    509                        device, devname);
     504                strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename);
     505                strcpy(raidlist->spares.el[raidlist->spares.entries].  device, devname);
    510506                raidlist->spares.el[raidlist->spares.entries].index =
    511507                    raidlist->disks.entries;
    512508                raidlist->spares.entries++;
    513509            } else {
    514                 strcpy(raidlist->disks.el[raidlist->disks.entries].name,
    515                        drivename);
    516                 strcpy(raidlist->disks.el[raidlist->disks.entries].device,
    517                        devname);
     510                strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename);
     511                strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname);
    518512                raidlist->disks.el[raidlist->disks.entries].index =
    519513                    raidlist->disks.entries;
     
    587581    fclose(fin);
    588582    log_it("Raidtab loaded successfully.");
    589     mr_asprintf(tmp1, "%d RAID devices in raidtab", raidlist->entries);
    590     log_it(tmp1);
    591     mr_free(tmp1);
     583    log_it("%d RAID devices in raidtab", raidlist->entries);
    592584    return (0);
    593585}
     
    596588#else
    597589
    598 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
    599                                char *fname)
    600 {
    601     FILE *fin;
    602     char *label;
    603     char *value;
     590int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) {
     591
     592    FILE *fin = NULL;
     593    char *label = NULL;
     594    char *value = NULL;
    604595    int items;
    605596    int v;
     
    680671
    681672    /*@ add mallocs * */
    682     char *tmp = NULL;
    683673    char *labelB;
    684674    char *valueB;
     
    739729        }
    740730        if (!disklist) {
    741             mr_asprintf(tmp, "Ignoring '%s %s' pair of disk %s", labelB, valueB, label);
    742             log_it(tmp);
    743             mr_free(tmp);
     731            log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label);
    744732        } else {
    745733            index = atoi(valueB);
     
    811799    static char *argv[64];
    812800    char **ap;
    813     char *q;
    814     char *line = (char *) malloc(MAX_STR_LEN);
    815 
    816     if (!line)
    817         errx(1,
    818              "unable to allocate %i bytes of memory for `char *line' at %s:%i",
    819              MAX_STR_LEN, __FILE__, __LINE__);
    820     q = fgets(line, MAX_STR_LEN, f);
    821     if (feof(f) && (q != NULL)) {
     801    char *line = NULL;
     802
     803    mr_getline(line, f);
     804    if (feof(f)) {
    822805        log_it("[GNVCL] Uh... I reached the EOF.");
    823806        return 0;
     
    830813            cnt++;
    831814        }
     815    mr_free(line);
    832816
    833817    if (strchr(argv[cnt - 1], '\n')) {
     
    11191103            while((token = mr_strtok (string, delims, &lastpos))) {
    11201104                if ((pos = strstr(token, "("))) {
    1121                     type = *(pos+1);
     1105                    type = *(pos+1);
    11221106                } else {
    1123                     type = ' ';
     1107                    type = ' ';
    11241108                }
    11251109                pos = strstr(token, "[");
     
    11271111                switch(type) {
    11281112                case ' ': // normal data disks
    1129                     raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
    1130                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1131                     strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
    1132                     mr_free(strtmp);
    1133                     raidlist->el[raidlist->entries].data_disks.entries++;
    1134                     break;
     1113                    raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
     1114                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1115                    strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
     1116                    mr_free(strtmp);
     1117                    raidlist->el[raidlist->entries].data_disks.entries++;
     1118                    break;
    11351119                case 'S': // spare disks
    1136                     raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
    1137                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1138                     strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
    1139                     mr_free(strtmp);
    1140                     raidlist->el[raidlist->entries].spare_disks.entries++;
    1141                     break;
     1120                    raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
     1121                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1122                    strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
     1123                    mr_free(strtmp);
     1124                    raidlist->el[raidlist->entries].spare_disks.entries++;
     1125                    break;
    11421126                case 'F': // failed disks
    1143                     raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
    1144                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1145                     strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
    1146                     mr_free(strtmp);
    1147                     raidlist->el[raidlist->entries].failed_disks.entries++;
    1148                     log_it("At least one failed disk found in RAID array.\n");
    1149                     break;
     1127                    raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
     1128                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1129                    strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
     1130                    mr_free(strtmp);
     1131                    raidlist->el[raidlist->entries].failed_disks.entries++;
     1132                    log_it("At least one failed disk found in RAID array.\n");
     1133                    break;
    11501134                default: // error
    1151                     log_msg(1, "Unknown device type '%c'\n", type);
    1152                     mr_free(string);
    1153                     mr_free(token);
    1154                     return 1;
    1155                     break;
     1135                    log_msg(1, "Unknown device type '%c'\n", type);
     1136                    mr_free(string);
     1137                    mr_free(token);
     1138                    return 1;
     1139                    break;
    11561140                }
    11571141                mr_free(token);
     
    11621146            for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
    11631147                if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) {
    1164                     index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;
     1148                    index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;
    11651149                }
    11661150            }
    11671151            if (index_min > 0) {
    11681152                for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
    1169                     raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min;   
     1153                    raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min;   
    11701154                }
    11711155            }
     
    11731157            for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
    11741158                if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) {
    1175                     index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;
     1159                    index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;
    11761160                }
    11771161            }
    11781162            if (index_min > 0) {
    11791163                for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
    1180                     raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 
     1164                        raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 
    11811165                }
    11821166            }
     
    11841168            for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
    11851169                if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) {
    1186                     index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;
     1170                    index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;
    11871171                }
    11881172            }
    11891173            if (index_min > 0) {
    11901174                for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
    1191                     raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min;   
     1175                        raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min;   
    11921176                }
    11931177            }
     
    12051189            } else {
    12061190                while (*pos != ' ') {
    1207                     pos -= 1;
    1208                     if (pos < string) {
    1209                             log_it("String underflow!\n");
    1210                             mr_free(string);
    1211                             return 1;
    1212                     }
     1191                    pos -= 1;
     1192                    if (pos < string) {
     1193                        log_it("String underflow!\n");
     1194                        mr_free(string);
     1195                        return 1;
     1196                    }
    12131197                }
    12141198                raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1);
     
    12241208            if (!(pos = strchr(string, '\%'))) {
    12251209                if (strcasestr(string, "delayed")) {
    1226                     raidlist->el[raidlist->entries].progress = -1;  // delayed (therefore, stuck at 0%)
     1210                    raidlist->el[raidlist->entries].progress = -1;  // delayed (therefore, stuck at 0%)
    12271211                } else {
    1228                     raidlist->el[raidlist->entries].progress = 999; // not found
     1212                    raidlist->el[raidlist->entries].progress = 999; // not found
    12291213                }
    12301214            } else {
    12311215                while (*pos != ' ') {
    1232                     pos -= 1;
    1233                     if (pos < string) {
    1234                         printf("ERROR: String underflow!\n");
    1235                             mr_free(string);
    1236                             return 1;
    1237                     }
     1216                    pos -= 1;
     1217                    if (pos < string) {
     1218                        printf("ERROR: String underflow!\n");
     1219                        mr_free(string);
     1220                        return 1;
     1221                    }
    12381222                }
    12391223                raidlist->el[raidlist->entries].progress = atoi(pos);
    12401224            }
    12411225            break;
    1242         default: // error or IN PROGRESS
     1226        default: // error or IN PROGRESS
    12431227            if (raidlist->el[raidlist->entries].progress != -1 &&
    12441228                raidlist->el[raidlist->entries].progress != 999) {
     
    12461230            }
    12471231            break;
    1248         }
    1249         row++;
     1232        }
     1233    row++;
    12501234    }
    12511235    // free string
  • branches/3.2/mondo/src/common/libmondo-stream.c

    r3185 r3191  
    138138    }
    139139    sleep(1);
    140     paranoid_system("sync");
     140    sync();
    141141    sleep(1);
    142142    paranoid_pclose(g_tape_stream);
    143143    log_it("closein_tape() -- leaving");
    144 /*
    145   for(i=0; i < g_tapecatalog->entries; i++)
    146     {
    147       log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);
    148     }
    149 */
    150144    if (!bkpinfo->please_dont_eject) {
    151145        eject_device(bkpinfo->media_device);
     
    183177
    184178    sleep(1);
    185     paranoid_system("sync");
     179    sync();
    186180    sleep(1);
    187181    log_it("closeout_tape() -- entering");
     
    228222               g_tapecatalog->el[i].tape_posK);
    229223    }
    230     //  if (!bkpinfo->please_dont_eject)
    231     //    { eject_device(bkpinfo->media_device); }
    232224    paranoid_free(blk);
    233225    paranoid_free(g_tapecatalog);
     
    266258    char tmp[MAX_STR_LEN];
    267259    char *command = NULL;
    268     char cdr_exe[MAX_STR_LEN];
     260    char *cdr_exe = NULL;
    269261    int res;
    270262
     
    272264    dev[0] = siz[0] = '\0';
    273265    if (find_home_of_exe("cdrecord")) {
    274         strcpy(cdr_exe, "cdrecord");
    275     } else {
    276         strcpy(cdr_exe, "dvdrecord");
    277     }
    278     mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    279             cdr_exe);
    280     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     266        mr_asprintf(cdr_exe, "cdrecord");
     267    } else {
     268        mr_asprintf(cdr_exe, "dvdrecord");
     269    }
     270    mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe);
     271    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    281272    mr_free(command);
    282273
    283274    if (atoi(tmp) != 1) {
    284         log_it
    285             ("Either too few or too many tape streamers for me to detect...");
     275        log_it("Either too few or too many tape streamers for me to detect...");
    286276        strcpy(dev, VANILLA_SCSI_TAPE);
     277        mr_free(tmp);
     278        mr_free(cdr_exe);
    287279        return 1;
    288280    }
    289     mr_asprintf(command,
    290             "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",
    291             cdr_exe);
    292     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     281    mr_free(tmp);
     282
     283    mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", cdr_exe);
     284    mr_asprintf(tmp, "%s", all_program_and_get_last_line_of_output(command));
    293285    mr_free(command);
    294286
    295287    if (strlen(tmp) < 2) {
    296288        log_it("Could not find tape device");
     289        mr_free(cdr_exe);
     290        mr_free(tmp);
    297291        return 1;
    298292    }
    299     mr_asprintf(command,
    300             "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1",
    301             cdr_exe);
    302     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     293    mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe);
     294    mr_free(cdr_exe);
     295
     296    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    303297    mr_free(command);
    304298
     
    306300    dev[strlen(dev) - 1] = '\0';
    307301    strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     302    mr_free(tmp);
     303
    308304    res = 0;
    309305    if (!mt_says_tape_exists(dev)) {
     
    324320    }
    325321
    326     log_it("At this point, dev = %s and res = %d", dev, res);
    327 
    328     strcpy(tmp, call_program_and_get_last_line_of_output("\
    329 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    330 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
    331 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
     322    if (dev) {
     323        log_it("At this point, dev = %s and res = %d", dev, res);
     324    } else {
     325        log_it("At this point, dev is NULL and res = %d", dev, res);
     326    }
     327
     328    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
    332329
    333330    if (mt_says_tape_exists(dev)) {
     
    335332    } else {
    336333        log_it("Turning %s", dev);
    337         strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
     334        mr_free(tmp);
     335        mr_asprintf(tmp, "%s", (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    338336        sprintf(dev, "/dev/os%s", tmp);
    339337        log_it("...into %s", dev);
     
    355353        siz[0] = '\0';
    356354        log_it("Warning - size of tape unknown");
    357         return (0);
    358355    } else {
    359356        strcpy(siz, tmp);
    360         return (0);
    361     }
    362 }
    363 
    364 
    365 
    366 
     357    }
     358    mr_free(tmp);
     359    return (0);
     360}
    367361
    368362
     
    479473    log_it("Insisting on tape #%d", tapeno);
    480474    if (g_current_media_number != tapeno) {
    481         mr_asprintf(tmp,
    482                 "When the tape drive goes quiet, please insert volume %d in this series.",
    483                 tapeno);
     475        mr_asprintf(tmp, "When the tape drive goes quiet, please insert volume %d in this series.", tapeno);
    484476        popup_and_OK(tmp);
    485477        mr_free(tmp);
     
    614606    int res;
    615607
     608    if (bkpinfo->media_device == NULL) {
     609        return(1);
     610    }
     611
    616612    if (strncmp(bkpinfo->media_device, "/dev/", 5)) {
    617         log_msg(1,
    618                 "Not using 'mt setblk'. This isn't an actual /dev entry.");
     613        log_msg(1, "Not using 'mt setblk'. This isn't an actual /dev entry.");
    619614        return (0);
    620615    }
     
    687682    int res = 0;
    688683
     684    if (bkpinfo->media_device == NULL) {
     685        return(1);
     686    }
     687
    689688    log_it("Skipping OBDR headers");
    690689    mr_asprintf(command, "mt -f %s rewind",bkpinfo->media_device);
     
    712711    char *command = NULL;
    713712    int res = 0;
     713
     714    if (bkpinfo->media_device == NULL) {
     715        return(1);
     716    }
    714717
    715718    log_it("Creating OBDR headers");
     
    780783    /*@ end vars *************************************************** */
    781784
    782     assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
    783     if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
    784         fatal_error("Cannot alloc mem for tape catalog");
    785     }
     785    g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
    786786    g_tapecatalog->entries = 0;
    787787    g_tape_posK = 0;
     
    800800        if (bkpinfo->media_device == NULL) {
    801801            log_it("Not able to skip OBDR - Restore will have to be done manually");
     802            return (1);
    802803        }
    803804        set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
     
    808809    make_hole_for_file(outfname);
    809810
    810 //  start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
    811811    log_it("Opening IN tape");
    812     if (!
    813         (g_tape_stream =
    814          open_device_via_buffer(bkpinfo->media_device, 'r',
    815                                 bkpinfo->internal_tape_block_size))) {
     812    if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) {
    816813        log_OS_error(g_tape_fifo);
    817814        log_to_screen("Cannot openin stream device");
     
    821818    log_to_screen("Reading stream");
    822819    log_it("stream device = '%s'", bkpinfo->media_device);
    823 /* skip data disks */
     820    /* skip data disks */
    824821    open_evalcall_form("Skipping data disks on stream");
    825822    log_to_screen("Skipping data disks on stream");
     
    874871        // FIXME
    875872    }
    876     mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null",
    877             outfname);
     873    mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", outfname);
    878874    paranoid_system(tmp);
    879875    mr_free(tmp);
     
    903899    /*@ end vars *************************************************** */
    904900
     901    if (cddev == NULL) {
     902        log_to_screen("Failed to openout NULL cddev");
     903        return (1);
     904    }
    905905    /*  add 'dummy' if testing */
    906906    mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
     
    942942    return (0);
    943943}
    944 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
    945     fatal_error("Cannot alloc mem for tape catalog");
    946 }
     944if (bkpinfo->media_device == NULL) {
     945    log_it("Unable to openout NULL device");
     946    return(1);
     947}
     948g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
    947949g_tapecatalog->entries = 0;
    948950g_tape_posK = 0;
     
    954956}
    955957log_it("Opening OUT tape");
    956 if (!
    957     (g_tape_stream =
    958      open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) {
     958if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) {
    959959    log_OS_error(g_tape_fifo);
    960960    log_to_screen("Cannot openin stream device");
     
    969969/**
    970970 * Copy a file from the opened stream (CD or tape) to @p outfile.
    971  * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used.
    972971 * @param outfile The file to write to.
    973972 * @param size The size of the file in the input stream.
     
    10311030{
    10321031    /*@ buffers ***************************************************** */
    1033     char *tmp = NULL;
    10341032    char *datablock;
    10351033    char *temp_fname;
    10361034    char *temp_cksum;
    10371035    char *actual_cksum = NULL;
    1038 //  char *pA, *pB;
    10391036
    10401037    /*@ int ********************************************************* */
     
    10781075    }
    10791076    if (orig_size != temp_size && orig_size != -1) {
    1080         mr_asprintf(tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10);
    1081         log_to_screen(tmp);
    1082         mr_free(tmp);
     1077        log_to_screen("output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10);
    10831078    }
    10841079    if (ctrl_chr != BLK_START_FILE) {
     
    11511146    }
    11521147    if (strcmp(temp_cksum, actual_cksum)) {
    1153         mr_asprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
    1154                 temp_cksum);
    1155         log_to_screen(tmp);
    1156         mr_free(tmp);
    1157 
    1158         mr_asprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
    1159                 (long) orig_size >> 10);
    1160         log_to_screen(tmp);
    1161         mr_free(tmp);
    1162 
     1148        log_to_screen("actual cksum=%s; recorded cksum=%s", actual_cksum, temp_cksum);
     1149        log_to_screen("%s (%ld K) is corrupt on tape", temp_fname, (long) orig_size >> 10);
    11631150        retval++;
    11641151    }
     
    12041191        g_tape_posK += fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
    12051192    }
    1206 /*  memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */
    1207 /*  for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */
    12081193    memcpy((char *) plen, tempblock + 7001, sizeof(long long));
    12091194    if (strcmp(tempblock + 6000 + *pcontrol_char, STR_HEADER)) {
     
    12111196    }
    12121197    strcpy(filename, tempblock + 1000);
    1213 /*  strcpy(cksum,tempblock+5555);*/
    1214 /*  log_it( "%s  (reading) fname=%s, filesize=%ld K",
    1215        marker_to_string (*pcontrol_char), filename,
    1216        (long) ((*plen) >> 10));
    1217 */
    12181198    if (*pcontrol_char == BLK_ABORTED_BACKUP) {
    12191199        log_to_screen("I can't verify an aborted backup.");
     
    13631343    while (ctrl_chr != BLK_START_FILE) {
    13641344        res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr);
     1345        if (res) {
     1346            //FIXME
     1347        }
    13651348        if (ctrl_chr == BLK_START_FILE) {
    13661349            break;
     
    13831366    }
    13841367    while (strcmp(pA, pB)) {
    1385         log_msg(6, "Skipping %s (it's not %s)", temp_fname,
    1386                 the_file_I_was_reading);
     1368        log_msg(6, "Skipping %s (it's not %s)", temp_fname, the_file_I_was_reading);
    13871369        for (size = temp_size; size > 0; size -= bytes_to_write) {
    13881370            bytes_to_write =
     
    14211403        }
    14221404    }
    1423     log_msg(2, "Reading %s (it matches %s)", temp_fname,
    1424             the_file_I_was_reading);
     1405    log_msg(2, "Reading %s (it matches %s)", temp_fname, the_file_I_was_reading);
    14251406    paranoid_free(temp_fname);
    14261407    paranoid_free(datablock);
     
    14441425    /*@ end vars *************************************************** */
    14451426
     1427    if (bkpinfo->media_device == NULL) {
     1428        log_it("Unable to open in from NULL device");
     1429        return (1);
     1430    }
     1431
    14461432    paranoid_pclose(g_tape_stream);
    14471433    sync();
     
    14511437    insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
    14521438    log_it("Opening IN the next tape");
    1453     if (!
    1454         (g_tape_stream =
    1455          open_device_via_buffer(bkpinfo->media_device, 'r',
    1456                                 bkpinfo->internal_tape_block_size))) {
     1439    if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) {
    14571440        log_OS_error(g_tape_fifo);
    14581441        log_to_screen("Cannot openin stream device");
     
    14871470    char *command = NULL;
    14881471
     1472    if (bkpinfo->media_device == NULL) {
     1473        log_it("Unable to open out from NULL device");
     1474        return (1);
     1475    }
     1476
    14891477    paranoid_pclose(g_tape_stream);
    1490     paranoid_system("sync");
    1491     paranoid_system("sync");
    1492     paranoid_system("sync");
     1478    sync();
     1479    sync();
     1480    sync();
    14931481    log_it("New tape requested.");
    14941482    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
    14951483    if (bkpinfo->backup_media_type == cdstream) {
    1496         mr_asprintf(command,
    1497                 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    1498                 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
    1499                 MONDO_LOGFILE);
     1484        mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, MONDO_LOGFILE);
    15001485        log_it("Opening OUT to next CD with the command");
    15011486        log_it(command);
     
    15101495    } else {
    15111496        log_it("Opening OUT to next tape");
    1512         if (!
    1513             (g_tape_stream =
    1514              open_device_via_buffer(bkpinfo->media_device, 'w',
    1515                                     bkpinfo->internal_tape_block_size))) {
     1497        if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) {
    15161498            log_OS_error(g_tape_fifo);
    15171499            log_to_screen("Cannot openin stream device");
     
    15841566    /*@ pointers *************************************************** */
    15851567    FILE *fin;
    1586     char *tmp = NULL;
    15871568
    15881569    /*@ long ******************************************************* */
     
    16021583    log_it("Data disks = %s", fname);
    16031584    if (!does_file_exist(fname)) {
    1604         mr_asprintf(tmp, "Cannot find %s", fname);
    1605         log_to_screen(tmp);
    1606         mr_free(tmp);
     1585        log_to_screen("Cannot find %s", fname);
    16071586        return (1);
    16081587    }
     
    16471626{
    16481627    /*@ buffers **************************************************** */
    1649     char *tmp = NULL;
    16501628    char datablock[TAPE_BLOCK_SIZE];
    16511629    char *checksum = NULL;
     
    17001678        p++;
    17011679    }
    1702     mr_asprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
    1703             (long) filesize >> 10);
    1704     log_it(tmp);
    1705     mr_free(tmp);
     1680    log_it("Writing file '%s' to tape (%ld KB)", p, (long) filesize >> 10);
    17061681    write_header_block_to_stream(filesize, infile_basename,
    17071682                                 BLK_START_FILE);
     
    17751750    /*@ buffers **************************************************** */
    17761751    char tempblock[TAPE_BLOCK_SIZE];
    1777     char *tmp = NULL;
    17781752    char *p;
    17791753
     
    17941768    }
    17951769    if (!g_tape_stream) {
    1796         log_to_screen
    1797             ("You're not backing up to tape. Why write a tape header?");
     1770        log_to_screen("You're not backing up to tape. Why write a tape header?");
    17981771        return (1);
    17991772    }
     
    18051778    memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t));
    18061779    strcpy(tempblock + 1000, filename);
    1807     g_tape_posK +=
    1808         fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
    1809                g_tape_stream) / 1024;
    1810     mr_asprintf(tmp, "%s (fname=%s, size=%ld K)",
    1811             marker_to_string(control_char), p,
    1812             (long) length_of_incoming_file >> 10);
    1813     log_msg(6, tmp);
    1814     mr_free(tmp);
     1780    g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
     1781    log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string(control_char), p, (long) length_of_incoming_file >> 10);
    18151782    return (0);
    18161783}
     
    18321799void wrong_marker(int should_be, int it_is)
    18331800{
    1834     /*@ buffer ***************************************************** */
    1835     char *tmp = NULL;
    1836 
    1837 
    1838     /*@ end vars *************************************************** */
    1839     mr_asprintf(tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is));
    1840     log_to_screen(tmp);
    1841     mr_free(tmp);
     1801    log_to_screen("Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is));
    18421802}
    18431803
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3185 r3191  
    5151    if (c && strncmp(c, "/disc", 5) == 0) {
    5252        /* yup it's devfs, return the "part" path */
     53        /* This strcpy is safe */
    5354        strcpy(c + 1, "part");
    5455        p = c + 5;
     
    6566    }
    6667    sprintf(p, "%d", partno);
    67     return (partition);
    68 }
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
     68    return(partition);
     69}
    8070
    8171
     
    118108
    119109
    120 
    121 
    122 inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)
    123 {
    124     char *p, *q;
    125 
    126     for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {
    127         if (strchr("[]*?", *p)) {
    128             *(q++) = '\\';
    129         }
    130     }
    131     *q = *p;                    // for the final '\0'
    132 }
    133 
    134 
    135 
    136110/**
    137111 * Add commas every third place in @p input.
     
    155129        tmp[j - 6] = ',';
    156130        strcpy(tmp + j - 5, pos_w_commas + j - 6);
    157 //      tmp[j-2] = ',';
    158 //      strcpy(tmp+j-1, pos_w_commas+j-3);
    159131        strcpy(pos_w_commas, tmp);
    160132    }
     
    170142    return (output);
    171143}
    172 
    173 
    174 
    175 
    176 
    177 
    178 
    179144
    180145
     
    217182    long outval;
    218183    int i;
    219     char *tmp;
     184    char *tmp = NULL;
    220185    char ch;
    221186
     
    228193        fatal_error("Please use integers only. No decimal points.");
    229194    }
    230     malloc_string(tmp);
    231     strcpy(tmp, incoming);
     195
     196    mr_asprintf(tmp, "%s", incoming);
    232197    i = (int) strlen(tmp);
    233198    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     
    238203    tmp[i] = '\0';
    239204    outval = atol(tmp);
     205    mr_free(tmp);
     206
    240207    if (ch == 'g' || ch == 'G') {
    241208        outval = outval * 1024;
     
    253220        fatal_error("Integer overflow.");
    254221    } else if (ch != 'm' && ch != 'M') {
    255         sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')",
    256                 incoming, ch);
     222        mr_asprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch);
    257223        fatal_error(tmp);
    258224    }
    259     paranoid_free(tmp);
    260225    return (outval);
    261226}
     
    516481
    517482    input = malloc(2000);
    518     // BERLIOS: seems to cause invalid errors
    519     //assert_string_is_neither_NULL_nor_zerolength(ip);
    520     assert_string_is_neither_NULL_nor_zerolength(token);
    521483    assert(value != NULL);
    522484
     
    557519    /*@ buffers **************************************************** */
    558520    static char output[MAX_STR_LEN];
    559     static char suffix[MAX_STR_LEN];
     521    char *suffix = NULL;
    560522
    561523    /*@ end vars *************************************************** */
     
    563525    assert_string_is_neither_NULL_nor_zerolength(path);
    564526    if (s[0] != '\0') {
    565         sprintf(suffix, ".%s", s);
     527        mr_asprintf(suffix, ".%s", s);
    566528    } else {
    567         suffix[0] = '\0';
    568     }
    569     sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
    570             suffix);
     529        mr_asprintf(suffix, "");
     530    }
     531    sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, suffix);
     532    mr_free(suffix);
    571533    return (output);
    572534}
     
    646608    numA = atol(stringA + start_of_numbers_in_A);
    647609    numB = atol(stringB + start_of_numbers_in_B);
    648     /*
    649        sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
    650        log_to_screen(tmp);
    651      */
    652610    return ((int) (numA - numB));
    653611}
     
    775733    in_out[i] = '\0';
    776734    paranoid_free(tmp);
    777 /*  for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */
    778735}
    779736
     
    909866 * @return The severity (1-3).
    910867 */
    911 int severity_of_difference(char *fn, char *out_reason)
    912 {
    913     int sev;
    914     char *reason;
    915     char *filename;
    916 
    917     malloc_string(reason);
    918     malloc_string(filename);
    919 // out_reason might be null on purpose, so don't bomb if it is :) OK?
     868int severity_of_difference(char *fn, char *out_reason) {
     869
     870    int sev = 3;
     871    char *reason = NULL;
     872    char *filename = NULL;
     873
     874    // out_reason might be null on purpose, so don't bomb if it is :) OK?
    920875    assert_string_is_neither_NULL_nor_zerolength(fn);
    921876    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
    922         strcpy(filename, fn + strlen(MNT_RESTORING));
     877        mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING));
    923878    } else if (fn[0] != '/') {
    924         sprintf(filename, "/%s", fn);
     879        mr_asprintf(filename, "/%s", fn);
    925880    } else {
    926         strcpy(filename, fn);
    927     }
    928 
    929     sev = 3;
    930     sprintf(reason,
    931             "Changed since backup. Consider running a differential backup in a day or two.");
     881        mr_asprintf(filename, "%s", fn);
     882    }
     883
     884    mr_asprintf(reason, "Changed since backup. Consider running a differential backup in a day or two.");
     885
    932886    if (!strncmp(filename, "/var/", 5)) {
    933887        sev = 2;
    934         sprintf(reason,
    935                 "/var's contents will change regularly, inevitably.");
     888        mr_free(reason);
     889        mr_asprintf(reason, "/var's contents will change regularly, inevitably.");
    936890    }
    937891    if (!strncmp(filename, "/home", 5)) {
    938892        sev = 2;
    939         sprintf(reason,
    940                 "It's in your /home directory. Therefore, it is important.");
     893        mr_free(reason);
     894        mr_asprintf(reason, "It's in your /home directory. Therefore, it is important.");
    941895    }
    942896    if (!strncmp(filename, "/usr/", 5)) {
    943897        sev = 3;
    944         sprintf(reason,
    945                 "You may have installed/removed software during the backup.");
     898        mr_free(reason);
     899        mr_asprintf(reason, "You may have installed/removed software during the backup.");
    946900    }
    947901    if (!strncmp(filename, "/etc/", 5)) {
    948902        sev = 3;
    949         sprintf(reason,
    950                 "Do not edit config files while backing up your PC.");
     903        mr_free(reason);
     904        mr_asprintf(reason, "Do not edit config files while backing up your PC.");
    951905    }
    952906    if (!strcmp(filename, "/etc/adjtime")
    953907        || !strcmp(filename, "/etc/mtab")) {
    954908        sev = 1;
    955         sprintf(reason, "This file changes all the time. It's OK.");
     909        mr_free(reason);
     910        mr_asprintf(reason, "This file changes all the time. It's OK.");
    956911    }
    957912    if (!strncmp(filename, "/root/", 6)) {
    958913        sev = 3;
    959         sprintf(reason, "Were you compiling/editing something in /root?");
     914        mr_free(reason);
     915        mr_asprintf(reason, "Were you compiling/editing something in /root?");
    960916    }
    961917    if (!strncmp(filename, "/root/.", 7)) {
    962918        sev = 2;
    963         sprintf(reason, "Temp or 'dot' files changed in /root.");
     919        mr_free(reason);
     920        mr_asprintf(reason, "Temp or 'dot' files changed in /root.");
    964921    }
    965922    if (!strncmp(filename, "/var/lib/", 9)) {
    966923        sev = 2;
    967         sprintf(reason, "Did you add/remove software during backing?");
     924        mr_free(reason);
     925        mr_asprintf(reason, "Did you add/remove software during backing?");
    968926    }
    969927    if (!strncmp(filename, "/var/lib/rpm", 12)) {
    970928        sev = 3;
    971         sprintf(reason, "Did you add/remove software during backing?");
     929        mr_free(reason);
     930        mr_asprintf(reason, "Did you add/remove software during backing?");
    972931    }
    973932    if (!strncmp(filename, "/var/lib/slocate", 16)) {
    974933        sev = 1;
    975         sprintf(reason,
    976                 "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
     934        mr_free(reason);
     935        mr_asprintf(reason, "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
    977936    }
    978937    if (!strncmp(filename, "/var/log/", 9)
     
    980939        || !strcmp(filename + strlen(filename) - 4, ".log")) {
    981940        sev = 1;
    982         sprintf(reason,
    983                 "Log files change frequently as the computer runs. Fret not.");
     941        mr_free(reason);
     942        mr_asprintf(reason, "Log files change frequently as the computer runs. Fret not.");
    984943    }
    985944    if (!strncmp(filename, "/var/spool", 10)) {
    986945        sev = 1;
    987         sprintf(reason,
    988                 "Background processes or printers were active. This does not affect the integrity of your backup.");
     946        mr_free(reason);
     947        mr_asprintf(reason, "Background processes or printers were active. This does not affect the integrity of your backup.");
    989948    }
    990949    if (!strncmp(filename, "/var/spool/mail", 10)) {
    991950        sev = 2;
    992         sprintf(reason, "Mail was sent/received during backup.");
     951        mr_free(reason);
     952        mr_asprintf(reason, "Mail was sent/received during backup.");
    993953    }
    994954    if (filename[strlen(filename) - 1] == '~') {
    995955        sev = 1;
    996         sprintf(reason,
    997                 "Backup copy of another file which was modified recently.");
     956        mr_free(reason);
     957        mr_asprintf(reason, "Backup copy of another file which was modified recently.");
    998958    }
    999959    if (strstr(filename, "cache")) {
    1000960        sev = 1;
    1001         sprintf(reason,
    1002                 "Part of a cache of data. Caches change from time to time. Don't worry.");
     961        mr_free(reason);
     962        mr_asprintf(reason, "Part of a cache of data. Caches change from time to time. Don't worry.");
    1003963    }
    1004964    if (!strncmp(filename, "/var/run/", 9)
     
    1007967        || strstr(filename, "/.Xauthority")) {
    1008968        sev = 1;
    1009         sprintf(reason,
    1010                 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
     969        mr_free(reason);
     970        mr_asprintf(reason, "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
    1011971    }
    1012972    if (out_reason) {
    1013973        strcpy(out_reason, reason);
    1014974    }
    1015     paranoid_free(filename);
    1016     paranoid_free(reason);
     975    mr_free(filename);
     976    mr_free(reason);
    1017977    return (sev);
    1018978}
     
    10641024    /*@ buffers ******************************************* */
    10651025    static char outstr[MAX_STR_LEN];
    1066     char *pos_w_commas, *tmp;
     1026    char *pos_w_commas = NULL;
    10671027    char *mds = NULL;
     1028    char *tmp = NULL;
    10681029
    10691030    assert(bkpinfo != NULL);
    1070     malloc_string(pos_w_commas);
    1071     malloc_string(tmp);
    1072     sprintf(tmp, "%lld", g_tape_posK);
    1073     strcpy(pos_w_commas, commarize(tmp));
    1074 
    1075 
    1076 
    1077     if (bkpinfo->media_size <= 0)
    1078 //    { fatal_error( "percentage_media_full_comment() - unknown media size"); }
    1079     {
    1080         sprintf(outstr, "Volume %d: %s kilobytes archived so far",
    1081                 g_current_media_number, pos_w_commas);
     1031
     1032    if (bkpinfo->media_size <= 0) {
     1033        mr_asprintf(tmp, "%lld", g_tape_posK);
     1034        mr_asprintf(pos_w_commas, "%s", commarize(tmp));
     1035        mr_free(tmp);
     1036        sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
     1037        mr_free(pos_w_commas);
    10821038        return (outstr);
    10831039    }
    10841040
    1085 /* update screen */
     1041    /* update screen */
    10861042    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    10871043        percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size);
     
    10911047        sprintf(outstr, "Volume %d: [", g_current_media_number);
    10921048    } else {
    1093         percentage =
    1094             (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size);
     1049        percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size);
    10951050        mds = media_descriptor_string(bkpinfo->backup_media_type);
    10961051        sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     
    11051060    j = (int) strlen(outstr);
    11061061    sprintf(outstr + j, "] %d%% used", percentage);
    1107     paranoid_free(pos_w_commas);
    1108     paranoid_free(tmp);
    11091062    return (outstr);
    11101063}
  • branches/3.2/mondo/src/common/libmondo-tools.c

    r3185 r3191  
    3030
    3131extern int g_tape_buffer_size_MB;
    32 extern char *g_serial_string;
    3332extern bool g_text_mode;
    3433extern int g_currentY;
    3534extern int g_current_media_number;
    3635extern char *MONDO_LOGFILE;
     36extern char *g_serial_string;
    3737
    3838/* Reference to global bkpinfo */
     
    113113        return;
    114114    }
    115 #ifndef _XWIN
    116115    if (!g_text_mode)
    117116        newtSuspend();
    118 #endif
    119117    printf("ASSERTION FAILED: `%s'\n", exp);
    120118    printf("\tat %s:%d in %s\n\n", file, line, function);
     
    163161    getchar();                  // skip \n
    164162
    165 #ifndef _XWIN
    166163    if (!g_text_mode)
    167164        newtResume();
    168 #endif
    169165}
    170166
     
    175171void clean_up_KDE_desktop_if_necessary(void)
    176172{
    177     char *tmp;
    178 
    179     malloc_string(tmp);
    180     strcpy(tmp,
    181            "for i in `find /root /home -maxdepth 2 -type d -name Desktop`; do \
    182 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
    183 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
    184 else { print $0;};}' $file.old  > $file ; fi ; done");
     173    char *tmp = NULL;
     174
     175    mr_asprintf(tmp, "for i in `find /root /home -maxdepth 2 -type d -name Desktop -maxdepth 2`; do file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } else { print $0;};}' $file.old  > $file ; fi ; done");
    185176    run_program_and_log_output(tmp, 5);
    186     paranoid_free(tmp);
     177    mr_free(tmp);
    187178}
    188179
     
    232223double get_kernel_version(void)
    233224{
    234     char *p, tmp[200];
     225    char *p = NULL;
     226    char *tmp = NULL;
    235227    double d;
    236228#ifdef __FreeBSD__
     
    238230    d = 5.2;                    // :-)
    239231#else
    240     strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
     232    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));
    241233    p = strchr(tmp, '.');
    242234    if (p) {
     
    249241        }
    250242    }
    251 //  log_msg(1, "tmp = '%s'", tmp);
    252243    d = atof(tmp);
     244    mr_free(tmp);
    253245#endif
    254246    log_msg(1, "g_kernel_version = %f", d);
     
    257249
    258250
    259 
    260 
    261 
    262251/**
    263252 * Get the current time.
     
    268257    return (long) time((void *) 0);
    269258}
    270 
    271 
    272 
    273 
    274 
    275259
    276260
     
    368352    char *mondo_mkisofs_sz = NULL;
    369353    char *command = NULL;
    370     char *mtpt;
    371     char *hostname;
     354    char *hostname = NULL;
    372355    char *isofs_cmd = NULL;
    373356    char *ip_address = NULL;
    374357    int retval = 0;
    375358    char *colon;
    376     char *cdr_exe;
     359    char *cdr_exe = NULL;
    377360    char *tmp = NULL;
    378     char call_before_iso_user[MAX_STR_LEN] = "\0";
    379     /*
    380     long avm = 0;
    381     int rdsiz_MB;
    382     */
     361    char *p = NULL;
     362    char *call_before_iso_user = NULL;
    383363    char *iso_dev = NULL;
    384364    char *iso_mnt = NULL;
     
    387367
    388368    assert(bkpinfo != NULL);
    389     malloc_string(mtpt);
    390     malloc_string(hostname);
    391     malloc_string(cdr_exe);
     369
    392370    bkpinfo->optimal_set_size =
    393371        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
     
    400378        }
    401379        log_msg(1, "Tape");
     380        if (bkpinfo->media_device == NULL) {
     381            return(1);
     382        }
    402383        mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    403384        log_msg(1, "tmp = '%s'", tmp);
     
    429410        strcpy(bkpinfo->zip_exe, "gzip");
    430411        strcpy(bkpinfo->zip_suffix, "gz");
     412    } else if (bkpinfo->use_lzma) {
     413        strcpy(bkpinfo->zip_exe, "lzma");
     414        strcpy(bkpinfo->zip_suffix, "lzma");
    431415    } else if (bkpinfo->compression_level != 0) {
    432416        strcpy(bkpinfo->zip_exe, "bzip2");
     
    440424    if (bkpinfo->backup_media_type == dvd) {
    441425        if (find_home_of_exe("growisofs")) {
    442             strcpy(cdr_exe, "growisofs");
     426            mr_asprintf(cdr_exe, "growisofs");
    443427        }                       // unlikely to be used
    444428        else {
     
    462446    }
    463447#endif
    464         else
    465         {
     448        else {
    466449            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    467450        }
    468451        if (bkpinfo->manual_cd_tray) {
    469             paranoid_free(mondo_mkisofs_sz);
    470452            fatal_error("Manual CD tray + DVD not supported yet.");
    471453            // -m isn't supported by growisofs, BTW...
     
    475457                    mondo_mkisofs_sz,
    476458                    "", bkpinfo->media_device);
    477             paranoid_free(mondo_mkisofs_sz);
    478         }
     459        }
     460        mr_free(mondo_mkisofs_sz);
    479461        if (getenv ("SUDO_COMMAND")) {
    480462            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     
    486468            mr_free(command);
    487469        }
    488         log_msg(2, "call_make_iso (DVD res) is ... %s",
    489                 bkpinfo->call_make_iso);
     470        log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
    490471    }                           // end of DVD code
    491472
     
    504485        }
    505486        if (find_home_of_exe("cdrecord")) {
    506             strcpy(cdr_exe, "cdrecord");
     487            mr_asprintf(cdr_exe, "cdrecord");
    507488        } else if (find_home_of_exe("dvdrecord")) {
    508             strcpy(cdr_exe, "dvdrecord");
     489            mr_asprintf(cdr_exe, "dvdrecord");
    509490        } else {
    510491            fatal_error("Please install either cdrecord or dvdrecord.");
     
    544525                        mondo_mkisofs_sz, bkpinfo->tmpdir);
    545526                } else {
    546                 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
    547                 sprintf (bkpinfo->call_before_iso,
    548                                     "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )",
    549                         mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     527                mr_asprintf(call_before_iso_user, "%s", bkpinfo->call_before_iso);
     528                sprintf(bkpinfo->call_before_iso, "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     529                mr_free(call_before_iso_user);
    550530            }
    551531            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
    552             sprintf(bkpinfo->call_make_iso,
    553                     "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS,
    554                     cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
    555                     extra_cdrom_params, bkpinfo->media_device,
    556                     bkpinfo->cdrw_speed, bkpinfo->tmpdir);
     532            sprintf(bkpinfo->call_make_iso, "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    557533        } else {
    558             sprintf(bkpinfo->call_make_iso,
    559                     "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    560                     mondo_mkisofs_sz, cdr_exe,
    561                     (bkpinfo->please_dont_eject) ? " " : "-eject",
    562                     extra_cdrom_params, bkpinfo->media_device,
    563                     bkpinfo->cdrw_speed);
    564         }
    565         paranoid_free(mondo_mkisofs_sz);
    566         paranoid_free(extra_cdrom_params);
     534            sprintf(bkpinfo->call_make_iso, "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", mondo_mkisofs_sz, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed);
     535        }
     536        mr_free(cdr_exe);
     537        mr_free(mondo_mkisofs_sz);
     538        mr_free(extra_cdrom_params);
    567539    }                           // end of CD code
    568540
     
    577549
    578550        log_it("isodir = %s", bkpinfo->isodir);
    579         mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
    580                 bkpinfo->isodir);
     551        mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    581552        log_it("command = %s", command);
    582         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    583553        mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
     554        log_it("res of it = %s", iso_dev);
    584555        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    585         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     556        write_one_liner_data_file(tmp, iso_dev);
    586557        mr_free(tmp);
    587558        mr_free(command);
     
    591562
    592563        log_it("command = %s", command);
    593         log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    594564        mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
     565        log_it("res of it = %s", iso_mnt);
    595566        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    596         write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
     567        write_one_liner_data_file(tmp, iso_mnt);
    597568        mr_free(tmp);
    598569        mr_free(command);
     
    612583            }
    613584        }
     585        mr_free(iso_mnt);
    614586        mr_free(iso_tmp);
    615         mr_free(iso_mnt);
    616587
    617588        mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     
    632603
    633604    if (bkpinfo->backup_media_type == netfs) {
    634         strcpy(hostname, bkpinfo->netfs_mount);
     605        if (bkpinfo->netfs_mount) {
     606            mr_asprintf(hostname, "%s", bkpinfo->netfs_mount);
     607        } else {
     608            log_it("netfs_mount is NULL");
     609            retval++;
     610            mr_asprintf(hostname, "");
     611        }
    635612        colon = strchr(hostname, ':');
    636613        if (!colon) {
     
    651628            }
    652629            if (!hent) {
    653                 log_it("Can't resolve Network mount (%s): %s", hostname,
    654                        hstrerror(h_errno));
     630                log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno));
    655631                retval++;
    656632            } else {
     
    658634                mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':'));
    659635                strcpy(bkpinfo->netfs_mount, ip_address);
    660                 paranoid_free(ip_address);
     636                mr_free(ip_address);
    661637            }
    662638        }
     639        mr_free(hostname);
    663640        store_netfs_config();
    664641    }
     
    668645        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
    669646    }
    670     if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
    671         log_it("tmpdir or scratchdir are blank/missing");
    672         retval++;
    673     }
    674     if (bkpinfo->include_paths[0] == '\0') {
    675         //      fatal_error ("Why no backup path?");
    676         strcpy(bkpinfo->include_paths, "/");
    677     }
    678     chmod(bkpinfo->scratchdir, 0700);
     647    if (bkpinfo->include_paths == NULL) {
     648        mr_asprintf(bkpinfo->include_paths, "/");
     649    }
    679650    g_backup_media_type = bkpinfo->backup_media_type;
    680     paranoid_free(mtpt);
    681     paranoid_free(hostname);
    682     paranoid_free(cdr_exe);
    683651    return (retval);
    684652}
     
    704672    if (bkpinfo->disaster_recovery) {
    705673        if (!does_nonMS_partition_exist()) {
    706             fatal_error
    707                 ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     674            fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    708675        }
    709676    }
     
    713680    paranoid_free(tmp);
    714681    if (find_and_store_mondoarchives_home(g_mondo_home)) {
    715         fprintf(stderr,
    716                 "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
     682        fprintf(stderr, "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
    717683        res++;
    718684        return (res);
     
    723689    }
    724690    g_current_media_number = 1;
    725     bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] = '\0';
     691    bkpinfo->postnuke_tarball[0] = '\0';
    726692    return (res);
    727693}
     
    772738    if (p == NULL) {
    773739        log_it("Failed to create global tmp directory %s for Mondo.",tmp);
     740        mr_free(tmp);
    774741        finish(-1);
    775742    }
     743    mr_free(tmp);
     744
    776745    strcpy(bkpinfo->tmpdir,p);
    777     paranoid_free(tmp);
     746    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    778747
    779748    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     
    817786    }
    818787    strcpy(bkpinfo->scratchdir,p);
     788    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    819789    paranoid_free(tmp);
    820790
     
    832802{
    833803    int i;
    834 
    835     log_msg(1, "Hi");
     804    log_msg(1, "Initializing bkpinfo");
     805
    836806    assert(bkpinfo != NULL);
    837807    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     
    847817    bkpinfo->use_lzo = FALSE;
    848818    bkpinfo->use_gzip = FALSE;
    849     bkpinfo->do_not_compress_these[0] = '\0';
     819    bkpinfo->use_lzma = FALSE;
    850820    bkpinfo->verify_data = FALSE;
    851821    bkpinfo->backup_data = FALSE;
     
    853823    bkpinfo->use_star = FALSE;
    854824    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    855     bkpinfo->disaster_recovery =
    856         (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     825   
     826/*  We need tmpdir as early as possible for further function calls */
     827    bkpinfo->tmpdir = NULL;         // Really setup after
     828    setup_tmpdir(NULL);
     829    setup_scratchdir(NULL);
     830
     831    bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode();
    857832    if (bkpinfo->disaster_recovery) {
    858833        strcpy(bkpinfo->isodir, "/");
     
    861836    }
    862837    strcpy(bkpinfo->prefix, STD_PREFIX);
    863     setup_tmpdir(NULL);
    864     setup_scratchdir(NULL);
    865 
    866838    bkpinfo->optimal_set_size = 0;
    867     strcpy(bkpinfo->include_paths, "/");
     839    bkpinfo->backup_media_type = none;
    868840    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
    869     bkpinfo->include_paths[0] = '\0';
     841    bkpinfo->exclude_paths = NULL;
     842    bkpinfo->include_paths = NULL;
    870843    bkpinfo->exclude_devs = NULL;
    871844    bkpinfo->restore_path[0] = '\0';
     
    879852    bkpinfo->netfs_user = NULL;
    880853    bkpinfo->netfs_remote_dir[0] = '\0';
    881     bkpinfo->exclude_paths = NULL;
     854    bkpinfo->postnuke_tarball[0] = '\0';
    882855    bkpinfo->subdir = NULL;
    883     bkpinfo->postnuke_tarball[0] = '\0';
    884856    bkpinfo->wipe_media_first = FALSE;
    885857    bkpinfo->differential = 0;
     
    894866
    895867
    896 
    897 
    898868/**
    899869 * Get the remaining free space (in MB) on @p partition.
     
    916886    mr_free(command);
    917887
    918     mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    919             partition);
     888    mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    920889    mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command));
    921890    mr_free(command);
     
    957926    if (system("which mkfs.vfat 2> /dev/null 1> /dev/null")
    958927        && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) {
    959         log_it
    960             ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
    961         run_program_and_log_output
    962             ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    963     }
    964     mr_asprintf(tmp, "%s",
    965            call_program_and_get_last_line_of_output
    966            ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     928        log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
     929        run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
     930    }
     931    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    967932    if (atol(tmp) < 35000) {
    968933        retval++;
     
    970935    }
    971936    if (atol(tmp) < 66000) {
    972         log_to_screen
    973             ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     937        log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    974938    }
    975939    mr_free(tmp);
     
    1026990        whine_if_not_found("cmp");
    1027991    }
    1028     run_program_and_log_output
    1029         ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1030     mr_asprintf(tmp, "%s",
    1031            call_program_and_get_last_line_of_output
    1032            ("mount | grep -E \"cdr(om|w)\""));
     992    run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
     993    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));
    1033994    if (strcmp("", tmp)) {
    1034995        if (strstr(tmp, "autofs")) {
     
    11041065    /*@ buffer ****************************************************** */
    11051066    char *command = NULL;
    1106     char *tmp = NULL;
    11071067
    11081068    /*@ end vars *************************************************** */
     
    11111071    assert_string_is_neither_NULL_nor_zerolength(label);
    11121072    if (!does_file_exist(config_file)) {
    1113         mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file",
    1114                 config_file);
    1115         log_to_screen(tmp);
    1116         mr_free(tmp);
    1117 
     1073        log_to_screen("(read_cfg_var) Cannot find %s config file", config_file);
    11181074        value[0] = '\0';
    11191075        return (1);
     
    11271083        mr_free(command);
    11281084
     1085        log_msg(4, "Configuration item %s is %s", label, value);
    11291086        if (strlen(value) == 0) {
    11301087            return (1);
     
    12421199 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    12431200 */
    1244 void mount_boot_if_necessary()
    1245 {
     1201void mount_boot_if_necessary() {
    12461202    char *tmp = NULL;
    12471203    char *command = NULL;
     
    12511207    g_boot_mountpt[0] = '\0';
    12521208    log_msg(4, "Done. Great. Seeting command to something");
    1253     mr_asprintf(command, "%s",
    1254            "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1209    mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    12551210    log_msg(4, "Cool. Command = '%s'", command);
    12561211    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     
    12581213
    12591214    log_msg(4, "tmp = '%s'", tmp);
    1260     if (tmp[0]) {
    1261         log_it("/boot is at %s according to /etc/fstab", tmp);
    1262         mr_asprintf(command, "mount | grep -Ew '/boot'");
    1263         mr_free(tmp);
    1264         mr_asprintf(tmp, call_program_and_get_last_line_of_output(command));
    1265         mr_free(command);
    1266 
    1267         if (!strcmp(tmp,"")) {
    1268             if (((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")) != NULL)) {
    1269                 if (!run_program_and_log_output("mount /boot", 5)) {
    1270                     strcpy(g_boot_mountpt, "/boot");
    1271                     log_msg(1, "Mounted /boot");
    1272                 } else {
    1273                     log_it("...ignored cos it's a label or uuid :-)");
     1215    log_it("/boot is at %s according to /etc/fstab", tmp);
     1216    mr_asprintf(command, "mount | grep -Ew '/boot'");
     1217    mr_free(tmp);
     1218
     1219    mr_asprintf(tmp, call_program_and_get_last_line_of_output(command));
     1220    mr_free(command);
     1221
     1222    if (!strcmp(tmp,"")) {
     1223        if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) {
     1224            if (!run_program_and_log_output("mount /boot", 5)) {
     1225                strcpy(g_boot_mountpt, "/boot");
     1226                log_msg(1, "Mounted /boot");
     1227            } else {
     1228                log_it("...ignored cos it's a label or uuid :-)");
     1229            }
     1230        } else {
     1231            mr_asprintf(command, "mount | grep -E '^%s'", tmp);
     1232            log_msg(3, "command = %s", command);
     1233            if (run_program_and_log_output(command, 5)) {
     1234                strcpy(g_boot_mountpt, tmp);
     1235                mr_free(tmp);
     1236                log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
     1237
     1238                mr_asprintf(tmp, "mount %s", g_boot_mountpt);
     1239                if (run_program_and_log_output(tmp, 5)) {
     1240                    g_boot_mountpt[0] = '\0';
     1241                    log_msg(1, "Plan B");
     1242                    if (!run_program_and_log_output("mount /boot", 5)) {
     1243                        strcpy(g_boot_mountpt, "/boot");
     1244                        log_msg(1, "Plan B worked");
     1245                    } else {
     1246                        log_msg(1,
     1247                            "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1248                    }
    12741249                }
    1275             } else {
    1276                 mr_asprintf(command, "mount | grep -E '^%s'", tmp);
    1277                 log_msg(3, "command = %s", command);
    1278                 if (run_program_and_log_output(command, 5)) {
    1279                     strcpy(g_boot_mountpt, tmp);
    1280                     mr_free(tmp);
    1281                     mr_asprintf(tmp,
    1282                             "%s (your /boot partition) is not mounted. I'll mount it before backing up",
    1283                             g_boot_mountpt);
    1284                     log_it(tmp);
    1285                     mr_free(tmp);
    1286 
    1287                     mr_asprintf(tmp, "mount %s", g_boot_mountpt);
    1288                     if (run_program_and_log_output(tmp, 5)) {
    1289                         g_boot_mountpt[0] = '\0';
    1290                         log_msg(1, "Plan B");
    1291                         if (!run_program_and_log_output("mount /boot", 5)) {
    1292                             strcpy(g_boot_mountpt, "/boot");
    1293                             log_msg(1, "Plan B worked");
    1294                         } else {
    1295                             log_msg(1,
    1296                                 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
    1297                         }
    1298                     }
    1299                     mr_free(tmp);
    1300                 }
    1301                 mr_free(command);
    13021250            }
    1303         }
    1304     }
     1251            mr_free(command);
     1252        }
     1253    }
     1254    mr_free(tmp);
    13051255    log_msg(1, "Ended sub");
    13061256}
     
    13401290    char *command = NULL;
    13411291    char *tempfile = NULL;
    1342     char *tmp = NULL;
    13431292
    13441293
     
    13481297    assert(value != NULL);
    13491298    if (!does_file_exist(config_file)) {
    1350         mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file",
    1351                 config_file);
    1352         log_to_screen(tmp);
    1353         mr_free(tmp);
     1299        log_to_screen("(write_cfg_file) Cannot find %s config file", config_file);
    13541300        return (1);
    13551301    }
    13561302    mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
    13571303    if (does_file_exist(config_file)) {
    1358         mr_asprintf(command, "grep -vE '^%s .*$' %s > %s",
    1359                 label, config_file, tempfile);
     1304        mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);
    13601305        paranoid_system(command);
    13611306        mr_free(command);
     
    13781323 * information to the logfile.
    13791324 */
    1380 void standard_log_debug_msg(int debug_level, const char *szFile,
    1381                             const char *szFunction, int nLine,
    1382                             const char *fmt, ...)
    1383 {
     1325void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) {
     1326
    13841327    va_list args;
    1385     int i;
    13861328    static int depth = 0;
    13871329    FILE *fout;
     
    13961338        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
    13971339            return;
    1398         }       // fatal_error("Failed to openout to logfile - sheesh..."); }
     1340        }
    13991341
    14001342        // add tabs to distinguish log levels
    14011343        if (debug_level > 0) {
    1402             for (i = 1; i < debug_level; i++)
    1403                 fprintf(fout, "\t");
     1344            fprintf(fout, "DBG%d: ", debug_level);
    14041345            if (getpid() == g_main_pid)
    14051346                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
     
    14081349            else
    14091350                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
     1351        } else {
     1352            fprintf(fout, "INFO: ");
    14101353        }
    14111354        va_start(args, fmt);
     
    14131356        va_end(args);
    14141357
    1415         // do not slow down the progran if standard debug level
    1416         // must be enabled: if no flush, the log won't be up-to-date if there
    1417         // is a segfault
    1418         //if (g_dwDebugLevel != 1)
    1419 
    14201358        fprintf(fout, "\n");
    14211359        paranoid_fclose(fout);
     
    14301368                       ...) = standard_log_debug_msg;
    14311369
    1432 
    1433 /**
    1434  * If @p y, malloc @p x, else free @p x.
    1435  * @bug This function seems orphaned. Please remove.
    1436  */
    1437 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }
    14381370
    14391371/**
     
    14461378        malloc_string(g_boot_mountpt);
    14471379        malloc_string(g_mondo_home);
    1448         /*
    1449         malloc_string(g_tmpfs_mountpt);
    1450         */
    14511380        malloc_string(g_serial_string);
    14521381        malloc_string(g_magicdev_command);
     
    14541383        paranoid_free(g_boot_mountpt);
    14551384        paranoid_free(g_mondo_home);
    1456         /*
    1457         paranoid_free(g_tmpfs_mountpt);
    1458         */
    1459         paranoid_free(g_serial_string);
    14601385        paranoid_free(g_magicdev_command);
    14611386
    1462     }
    1463 
    1464     /*
    1465        char**list_of_arrays[] = {
    1466        &g_boot_mountpt,
    1467        &g_mondo_home,
    1468        &g_tmpfs_mountpt,
    1469        &g_serial_string,
    1470        &g_magicdev_command,
    1471        NULL};
    1472 
    1473        char**ppcurr;
    1474        int i;
    1475 
    1476        for(i=0;list_of_arrays[i];i++)
    1477        {
    1478        log_msg(5, "Allocating %d", i);
    1479        ppcurr = list_of_arrays[i];
    1480        if (mal)
    1481        { *ppcurr = malloc(MAX_STR_LEN); }
    1482        else
    1483        {
    1484        if (*ppcurr)
    1485        {
    1486        free(*ppcurr);
    1487        }
    1488        }
    1489        }
    1490        log_msg(5, "Returning");
    1491      */
     1387        mr_free(g_serial_string);
     1388    }
    14921389}
    14931390
     
    15181415void stop_magicdev_if_necessary()
    15191416{
    1520     strcpy(g_magicdev_command,
    1521            call_program_and_get_last_line_of_output
    1522            ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1417    strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
    15231418    if (g_magicdev_command[0]) {
    15241419        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
  • branches/3.2/mondo/src/common/libmondo-verify.c

    r3185 r3191  
    5555    assert(bkpinfo != NULL);
    5656    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    57     sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno,
    58             bkpinfo->zip_suffix);
     57    sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno, bkpinfo->zip_suffix);
    5958    if (!does_file_exist(output)) {
    60         sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno,
    61                 bkpinfo->zip_suffix);
     59        sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno, bkpinfo->zip_suffix);
    6260    }
    6361    return (output);
     
    8078{
    8179    /*@ buffer ********************************************************** */
    82     char *command;
    83     char *afio_found_changes;
     80    char *command = NULL;
     81    char *afio_found_changes = NULL;
    8482
    8583    /*@ int ************************************************************* */
     
    8987    long afio_diffs = 0;
    9088
    91     command = malloc(2000);
    92     afio_found_changes = malloc(500);
    9389    assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname);
    9490    assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname);
    9591    assert_string_is_neither_NULL_nor_zerolength(stderr_fname);
    9692
    97     sprintf(afio_found_changes, "%s.afio", ignorefiles_fname);
    98     paranoid_system("sync");
    99 
    100 /*  sprintf (command,
    101        "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s",
    102        stderr_fname, afio_found_changes);
    103 */
     93    mr_asprintf(afio_found_changes, "%s.afio", ignorefiles_fname);
     94    sync();
    10495
    10596    log_msg(1, "Now scanning log file for 'afio: ' stuff");
    106     sprintf(command,
    107             "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s",
    108             stderr_fname, afio_found_changes);
     97    mr_asprintf(command, "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes);
    10998    log_msg(2, command);
    11099    res = system(command);
     100    mr_free(command);
     101
    111102    if (res) {
    112103        log_msg(2, "Warning - failed to think");
     
    114105
    115106    log_msg(1, "Now scanning log file for 'star: ' stuff");
    116     sprintf(command,
    117             "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s",
    118             stderr_fname, afio_found_changes);
     107    mr_asprintf(command, "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes);
    119108    log_msg(2, command);
    120109    res = system(command);
     110    mr_free(command);
     111
    121112    if (res) {
    122113        log_msg(2, "Warning - failed to think");
    123114    }
    124 //  exclude_nonexistent_files (afio_found_changes);
    125115    afio_diffs = count_lines_in_file(afio_found_changes);
    126     sprintf(command,
    127             "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",
    128             ignorefiles_fname, afio_found_changes, afio_found_changes,
    129             changedfiles_fname);
     116    mr_asprintf(command, "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", ignorefiles_fname, afio_found_changes, afio_found_changes, changedfiles_fname);
     117    mr_free(afio_found_changes);
    130118    log_msg(2, command);
    131119    paranoid_system(command);
    132     paranoid_free(command);
    133     paranoid_free(afio_found_changes);
     120    mr_free(command);
    134121    return (afio_diffs);
    135122}
     
    151138
    152139    /*@ buffers ********************************************************* */
    153     char *tmp;
     140    char *tmp = NULL;
    154141    char *mds = NULL;
    155142
     
    162149    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    163150    assert(bkpinfo != NULL);
    164     malloc_string(tmp);
    165151
    166152    for (set_number = 0;
     
    175161    if (g_last_afioball_number != set_number - 1) {
    176162        if (set_number == 0) {
    177             log_msg(1,
    178                     "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
     163            log_msg(1, "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more");
    179164        } else {
    180165            retval++;
    181             sprintf(tmp, "Warning - missing set(s) between %d and %d\n",
    182                     g_last_afioball_number, set_number - 1);
    183             log_to_screen(tmp);
     166            log_to_screen("Warning - missing set(s) between %d and %d\n", g_last_afioball_number, set_number - 1);
    184167        }
    185168    }
    186169    mds = media_descriptor_string(bkpinfo->backup_media_type);
    187     sprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number);
     170    mr_asprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number);
    188171    mr_free(mds);
    189172
    190173    open_evalcall_form(tmp);
     174    mr_free(tmp);
    191175
    192176    for (total_sets = set_number;
     
    208192    g_last_afioball_number = set_number - 1;
    209193    close_evalcall_form();
    210     paranoid_free(tmp);
    211194    return (retval);
    212195}
     
    227210
    228211    /*@ buffer ********************************************************** */
    229     char *tmp;
    230     char *mountpoint;
    231 //  char ca, cb;
    232     char *command;
     212    char *tmp = NULL;
     213    char *mountpoint = NULL;
     214    char *command = NULL;
    233215    char *mds = NULL;
    234     char *sz_exe;
     216    char *sz_exe = NULL;
    235217    static char *bufblkA = NULL;
    236218    static char *bufblkB = NULL;
     
    252234    FILE *fin;
    253235    int retval = 0;
    254 //  long long outlen;
    255 
    256     malloc_string(tmp);
    257     malloc_string(mountpoint);
    258     malloc_string(command);
    259     malloc_string(sz_exe);
     236
    260237    if (!bufblkA) {
    261238        if (!(bufblkA = malloc(maxbufsize))) {
     
    274251    if (bkpinfo->compression_level > 0) {
    275252        if (bkpinfo->use_lzo) {
    276             strcpy(sz_exe, "lzop");
     253            mr_asprintf(sz_exe, "lzop");
    277254        } else if (bkpinfo->use_gzip) {
    278             strcpy(sz_exe, "gzip");
     255            mr_asprintf(sz_exe, "gzip");
     256        } else if (bkpinfo->use_lzma) {
     257            mr_asprintf(sz_exe, "lzma");
    279258        } else {
    280             strcpy(sz_exe, "bzip2");
    281         }
    282     } else {
    283         sz_exe[0] = '\0';
     259            mr_asprintf(sz_exe, "bzip2");
     260        }
    284261    }
    285262
    286263    log_it("before vsbf");
    287264    mds = media_descriptor_string(bkpinfo->backup_media_type);
    288     sprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number);
     265    mr_asprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number);
    289266    mr_free(mds);
    290267
    291268    open_evalcall_form(tmp);
     269    mr_free(tmp);
     270
    292271    log_it("after vsbf");
    293     sprintf(mountpoint, "%s/archives", mtpt);
     272    mr_asprintf(mountpoint, "%s/archives", mtpt);
    294273    if (last_bigfile_num == -1) {
    295274        bigfile_num = 0;
     
    302281        slice_num = last_slice_num + 1;
    303282    }
    304     while (does_file_exist
    305            (slice_fname
    306             (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
     283    while (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
    307284           ||
    308            does_file_exist(slice_fname
    309                            (bigfile_num, slice_num, mountpoint, ""))) {
     285           does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
    310286        // handle slices until end of CD
    311287        if (slice_num == 0) {
    312             log_msg(2, "ISO=%d  bigfile=%ld --START--",
    313                     g_current_media_number, bigfile_num);
    314             if (!
    315                 (fin =
    316                  fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""),
    317                        "r"))) {
     288            log_msg(2, "ISO=%d  bigfile=%ld --START--", g_current_media_number, bigfile_num);
     289            if (! (fin = fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), "r"))) {
    318290                log_msg(2, "Cannot open bigfile's info file");
    319291            } else {
    320                 if (fread
    321                     ((void *) &biggiestruct, 1, sizeof(biggiestruct),
    322                      fin) < sizeof(biggiestruct)) {
     292                if (fread ((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) {
    323293                    log_msg(2, "Unable to get biggiestruct");
    324294                }
    325295                paranoid_fclose(fin);
    326296            }
    327             sprintf(tmp, "%s/%s", bkpinfo->restore_path,
    328                     biggiestruct.filename);
    329             log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
    330             if (!(forig = fopen(tmp, "r"))) {
    331                 log_msg(2, "Failed to open bigfile. Darn.");
    332                 log_to_screen("%s/%s not found on live filesystem",
    333                             bkpinfo->restore_path,
    334                             biggiestruct.filename);
    335                 mr_asprintf(mds, "echo \"%s/%s not found\" >> %s/biggies.changed",
    336                             bkpinfo->restore_path,
    337                             biggiestruct.filename,
    338                             bkpinfo->tmpdir);
    339                 paranoid_system(mds);
    340                 paranoid_free(mds);
    341 
    342                 bigfile_num++;
    343                 slice_num = 0;
    344                 retval++;
     297            if (bkpinfo->restore_path) {
     298                mr_asprintf(tmp, "%s/%s", bkpinfo->restore_path, biggiestruct.filename);
     299                log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
     300                forig = fopen(tmp, "r");
     301                mr_free(tmp);
     302   
     303                if (!forig) {
     304                    log_msg(2, "Failed to open bigfile. Darn.");
     305                    log_to_screen("%s/%s not found on live filesystem", bkpinfo->restore_path, biggiestruct.filename);
     306                    mr_asprintf(tmp, "echo \"%s/%s not found\" >> %s/biggies.changed", bkpinfo->restore_path, biggiestruct.filename, bkpinfo->tmpdir);
     307                    paranoid_system(tmp);
     308                    mr_free(tmp);
     309
     310                    bigfile_num++;
     311                    slice_num = 0;
     312                    retval++;
     313                } else {
     314                    slice_num++;
     315                }
    345316            } else {
    346                 slice_num++;
     317                log_it("Unable to open bigfile as restore_path is NULL");
    347318            }
    348319        } else if (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, "")) &&
     
    354325            slice_num = 0;
    355326        } else {
    356             log_msg(2, "ISO=%d  bigfile=%ld  slice=%ld",
    357                     g_current_media_number, bigfile_num, slice_num);
    358             if (!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
    359                 sprintf(command, "%s -dc %s 2>> %s",
    360                         sz_exe,
    361                         slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix),
    362                         MONDO_LOGFILE);
     327            log_msg(2, "ISO=%d  bigfile=%ld  slice=%ld", g_current_media_number, bigfile_num, slice_num);
     328            if ((!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) && (sz_exe != NULL)) {
     329                mr_asprintf(command, "%s -dc %s 2>> %s", sz_exe, slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), MONDO_LOGFILE);
    363330            } else {
    364                 sprintf(command, "cat %s 2>> %s",
    365                         slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE);
     331                mr_asprintf(command, "cat %s 2>> %s", slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE);
    366332            }
    367             if ((pin = popen(command, "r"))) {
     333            pin = popen(command, "r");
     334            mr_free(command);
     335            if (pin) {
    368336                res = 0;
    369337                while (!feof(pin)) {
     
    404372        }
    405373    }
     374    mr_free(mountpoint);
     375    mr_free(sz_exe);
     376
    406377    last_bigfile_num = bigfile_num;
    407378    last_slice_num = slice_num - 1;
     
    416387        paranoid_free(bufblkB);
    417388    }
    418     paranoid_free(tmp);
    419     paranoid_free(command);
    420     paranoid_free(sz_exe);
    421     paranoid_free(mountpoint);
    422389    return (0);
    423390}
     
    442409{
    443410    /*@ buffers ********************************************************* */
    444     char *command;
    445     char *outlog;
    446     char *tmp;
    447     char *p;
     411    char *command = NULL;
     412    char *outlog = NULL;
     413    char *tmp = NULL;
     414    char *p = NULL;
    448415
    449416    /*@ pointers ******************************************************* */
     
    462429
    463430    log_it("Verifying fileset '%s'", tarball_fname);
    464     /*  chdir("/"); */
    465     sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
    466 /* if programmer forgot to say which compression thingy to use then find out */
    467     if (strstr(tarball_fname, ".lzo")
    468         && strcmp(bkpinfo->zip_suffix, "lzo")) {
     431    mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir);
     432    /* if programmer forgot to say which compression thingy to use then find out */
     433    if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) {
    469434        log_msg(2, "OK, I'm going to start using lzop.");
    470435        strcpy(bkpinfo->zip_exe, "lzop");
     
    472437        bkpinfo->use_lzo = TRUE;
    473438        bkpinfo->use_gzip = FALSE;
    474     }
    475     if (strstr(tarball_fname, ".gz")
    476         && strcmp(bkpinfo->zip_suffix, "gz")) {
     439        bkpinfo->use_lzma = FALSE;
     440    }
     441    if (strstr(tarball_fname, ".gz") && strcmp(bkpinfo->zip_suffix, "gz")) {
    477442        log_msg(2, "OK, I'm going to start using gzip.");
    478443        strcpy(bkpinfo->zip_exe, "gzip");
     
    480445        bkpinfo->use_lzo = FALSE;
    481446        bkpinfo->use_gzip = TRUE;
    482     }
    483     if (strstr(tarball_fname, ".bz2")
    484         && strcmp(bkpinfo->zip_suffix, "bz2")) {
     447        bkpinfo->use_lzma = FALSE;
     448    }
     449    if (strstr(tarball_fname, ".bz2") && strcmp(bkpinfo->zip_suffix, "bz2")) {
    485450        log_msg(2, "OK, I'm going to start using bzip2.");
    486451        strcpy(bkpinfo->zip_exe, "bzip2");
     
    488453        bkpinfo->use_lzo = FALSE;
    489454        bkpinfo->use_gzip = FALSE;
     455        bkpinfo->use_lzma = FALSE;
     456    }
     457    if (strstr(tarball_fname, ".lzma") && strcmp(bkpinfo->zip_suffix, "lzma")) {
     458        log_msg(2, "OK, I'm going to start using lzma.");
     459        strcpy(bkpinfo->zip_exe, "lzma");
     460        strcpy(bkpinfo->zip_suffix, "lzma");
     461        bkpinfo->use_lzo = FALSE;
     462        bkpinfo->use_gzip = FALSE;
     463        bkpinfo->use_lzma = TRUE;
     464    }
     465    if (bkpinfo->zip_exe == NULL) {
     466        strcpy(bkpinfo->zip_exe, "none");
     467    }
     468    if (bkpinfo->zip_suffix == NULL) {
     469        strcpy(bkpinfo->zip_suffix, "");
    490470    }
    491471    unlink(outlog);
     
    493473        bkpinfo->use_star = TRUE;
    494474        if (strstr(tarball_fname, ".bz2"))
    495             sprintf(command,
    496                     "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",
    497                     tarball_fname,
    498                     (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,
    499                     outlog);
     475            mr_asprintf(command, "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", tarball_fname, (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, outlog);
    500476    } else {
    501477        bkpinfo->use_star = FALSE;
    502         sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s",
    503                 bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     478        /* Here we suppose that there is always a compression program called */
     479        if (bkpinfo->zip_exe) {
     480            mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog);
     481        } else {
     482            mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog);
     483        }
    504484    }
    505485    log_msg(6, "command=%s", command);
    506486    paranoid_system(command);
     487    mr_free(command);
     488
    507489    if (length_of_file(outlog) < 10) {
    508         sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);
     490        mr_asprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);
    509491    } else {
    510         sprintf(command, "cut -d: -f%d %s | sort -u",
    511                 (bkpinfo->use_star) ? 1 : 2, outlog);
     492        mr_asprintf(command, "cut -d: -f%d %s | sort -u", (bkpinfo->use_star) ? 1 : 2, outlog);
    512493        pin = popen(command, "r");
    513494        if (pin) {
    514             for (p = fgets(tmp, MAX_STR_LEN, pin); !feof(pin) && (p != NULL);
    515                  p = fgets(tmp, MAX_STR_LEN, pin)) {
     495            for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) {
    516496                if (bkpinfo->use_star) {
    517497                    if (!strstr(tmp, "diffopts=")) {
    518                         while (strlen(tmp) > 0
    519                                && tmp[strlen(tmp) - 1] < 32) {
     498                        while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) {
    520499                            tmp[strlen(tmp) - 1] = '\0';
    521500                        }
    522501                        if (strchr(tmp, '/')) {
    523502                            if (!diffs) {
    524                                 log_msg(0, "'%s' - differences found",
    525                                         tarball_fname);
     503                                log_msg(0, "'%s' - differences found", tarball_fname);
    526504                            }
    527                             log_msg(0, "star: /%s",
    528                                     strip_afio_output_line(tmp));
     505                            log_msg(0, "star: /%s", strip_afio_output_line(tmp));
    529506                            diffs++;
    530507                        }
     
    532509                } else {
    533510                    if (!diffs) {
    534                         log_msg(0, "'%s' - differences found",
    535                                 tarball_fname);
     511                        log_msg(0, "'%s' - differences found", tarball_fname);
    536512                    }
    537513                    log_msg(0, "afio: /%s", strip_afio_output_line(tmp));
    538514                    diffs++;
    539515                }
     516                mr_free(tmp);
    540517            }
     518            mr_free(tmp);
    541519            paranoid_pclose(pin);
    542520        } else {
     
    544522        }
    545523    }
    546     /*  chdir(old_pwd); */
    547     //  sprintf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE);
    548     //  paranoid_system (tmp);
    549     //  unlink ("/tmp/mondo-verify.err");
    550     paranoid_free(command);
    551     paranoid_free(outlog);
    552     paranoid_free(tmp);
     524    mr_free(command);
     525    mr_free(outlog);
    553526    return (0);
    554527}
     
    604577
    605578    /*@ buffers ********************************************************** */
    606     char *tmp;
    607     char *tarball_fname;
     579    char *tmp = NULL;
     580    char *tarball_fname = NULL;
    608581
    609582    /*@ pointers ********************************************************* */
    610583    char *p;
    611584
    612     malloc_string(tmp);
    613     malloc_string(tarball_fname);
    614585    assert(bkpinfo != NULL);
    615586    assert_string_is_neither_NULL_nor_zerolength(orig_fname);
     
    621592        p++;
    622593    }
    623     sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     594    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    624595    paranoid_system(tmp);
    625     sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
    626     sprintf(tmp, "Temporarily copying file from tape to '%s'",
    627             tarball_fname);
    628 /*  log_it(tmp); */
     596    mr_free(tmp);
     597
     598    mr_asprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p);
    629599    read_file_from_stream_to_file(tarball_fname, size);
    630600    res = verify_a_tarball(tarball_fname);
    631601    if (res) {
    632         sprintf(tmp,
    633                 "Afioball '%s' no longer matches your live filesystem", p);
    634         log_msg(0, tmp);
     602        log_msg(0, "Afioball '%s' no longer matches your live filesystem", p);
    635603        retval++;
    636604    }
    637605    unlink(tarball_fname);
    638     paranoid_free(tmp);
    639     paranoid_free(tarball_fname);
     606    mr_free(tarball_fname);
    640607    return (retval);
    641608}
     
    660627
    661628    /*@ char ************************************************************ */
    662     char *test_file;
    663     char *biggie_cksum;
    664     char *orig_cksum;
    665     char *tmp;
    666     char *slice_fnam;
     629    char *test_file = NULL;
     630    char *biggie_cksum = NULL;
     631    char *orig_cksum = NULL;
     632    char *tmp = NULL;
     633    char *slice_fnam = NULL;
    667634
    668635    /*@ pointers ******************************************************** */
     
    672639    long long slice_siz;
    673640
    674     malloc_string(test_file);
    675     malloc_string(biggie_cksum);
    676     malloc_string(orig_cksum);
    677     malloc_string(tmp);
    678641    malloc_string(slice_fnam);
    679642    assert(bkpinfo != NULL);
     
    686649        p++;
    687650    }
    688     sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
    689     sprintf(tmp,
    690             "Temporarily copying biggiefile %s's slices from tape to '%s'",
    691             p, test_file);
    692 /*  log_it(tmp); */
     651    mr_asprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
    693652    for (res =
    694653         read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
    695654         ctrl_chr != BLK_STOP_A_BIGGIE;
    696655         res =
    697          read_header_block_from_stream(&slice_siz, slice_fnam,
    698                                        &ctrl_chr)) {
     656         read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) {
    699657        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
    700658            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
     
    703661        unlink(test_file);
    704662        res =
    705             read_header_block_from_stream(&slice_siz, slice_fnam,
    706                                           &ctrl_chr);
     663            read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
    707664        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
    708665            log_msg(2, "test_file = %s", test_file);
     
    712669        retval += res;
    713670    }
    714     strcpy(biggie_cksum, slice_fnam);
     671    mr_asprintf(biggie_cksum, "%s", slice_fnam);
    715672    if (biggie_cksum[0] != '\0') {
    716         strcpy(orig_cksum, calc_checksum_of_file(biggie_fname));
     673        mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname));
    717674        if (strcmp(biggie_cksum, orig_cksum)) {
    718             sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum,
    719                     orig_cksum);
    720             log_msg(2, tmp);
    721             sprintf(tmp, "%s has changed on live filesystem",
    722                     biggie_fname);
    723             log_to_screen(tmp);
    724             sprintf(tmp, "echo \"%s\" >> %s/biggies.changed",
    725                     biggie_fname, bkpinfo->tmpdir);
     675            log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum);
     676            log_to_screen("%s has changed on live filesystem", biggie_fname);
     677
     678            mr_asprintf(tmp, "echo \"%s\" >> %s/biggies.changed", biggie_fname, bkpinfo->tmpdir);
    726679            paranoid_system(tmp);
    727         }
    728     }
    729     paranoid_free(test_file);
    730     paranoid_free(biggie_cksum);
    731     paranoid_free(orig_cksum);
    732     paranoid_free(tmp);
     680            mr_free(tmp);
     681        }
     682        mr_free(orig_cksum);
     683    }
     684    mr_free(biggie_cksum);
     685    mr_free(test_file);
    733686    paranoid_free(slice_fnam);
    734687    return (retval);
     
    739692 * Verify all afioballs from the opened tape/CD stream.
    740693 * @param bkpinfo The backup information structure. Fields used:
    741  * - @c bkpinfo->restore_path
    742694 * - @c bkpinfo->tmpdir
    743695 *
     
    754706
    755707    /*@ buffers ***************************************************** */
    756     char *tmp;
     708    char *tmp = NULL;
    757709    char *fname;
    758710    char *curr_xattr_list_fname;
     
    763715
    764716    assert(bkpinfo != NULL);
    765     malloc_string(tmp);
    766717    malloc_string(fname);
    767718    malloc_string(curr_xattr_list_fname);
     
    816767            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    817768        }
    818         sprintf(tmp, "Verifying fileset #%ld", current_afioball_number);
    819         /*log_it(tmp); */
     769        mr_asprintf(tmp, "Verifying fileset #%ld", current_afioball_number);
    820770        update_progress_form(tmp);
     771        mr_free(tmp);
     772
    821773        res = verify_an_afioball_from_stream(fname, size);
    822774        if (res) {
    823             sprintf(tmp, "Afioball %ld differs from live filesystem",
    824                     current_afioball_number);
    825             log_to_screen(tmp);
     775            log_to_screen("Afioball %ld differs from live filesystem", current_afioball_number);
    826776        }
    827777        retval += res;
     
    835785    log_msg(1, "All done with afioballs");
    836786    close_progress_form();
    837     paranoid_free(tmp);
    838787    paranoid_free(fname);
    839788    paranoid_free(curr_xattr_list_fname);
     
    863812
    864813    /*@ buffers ******************************************************** */
    865     char *tmp;
    866     char *orig_fname, *logical_fname;
    867     char *comment;
    868     char *curr_xattr_list_fname;
    869     char *curr_acl_list_fname;
     814    char *orig_fname;
     815    char *logical_fname = NULL;
     816    char *comment = NULL;
     817    char *curr_xattr_list_fname = NULL;
     818    char *curr_acl_list_fname = NULL;
    870819    /*@ pointers ******************************************************* */
    871820    char *p;
     
    875824
    876825    assert(bkpinfo != NULL);
    877     malloc_string(tmp);
    878826    malloc_string(orig_fname);
    879     malloc_string(logical_fname);
    880     malloc_string(comment);
    881827    malloc_string(curr_xattr_list_fname);
    882828    malloc_string(curr_acl_list_fname);
     
    890836            bkpinfo->tmpdir);
    891837    }
    892     sprintf(comment, "Verifying all bigfiles.");
     838    mr_asprintf(comment, "Verifying all bigfiles.");
    893839    log_to_screen(comment);
    894     sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
    895 //  noof_biggiefiles = count_lines_in_file (tmp); // pointless
    896840    res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
    897841    if (ctrl_chr != BLK_START_BIGGIEFILES) {
     
    911855                       "Please wait. This may take some time.", "",
    912856                       noof_biggiefiles);
     857    mr_free(comment);
     858
    913859    for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
    914860         ctrl_chr != BLK_STOP_BIGGIEFILES;
     
    925871            p++;
    926872        }
    927         sprintf(comment, "Verifying bigfile #%ld (%ld K)",
    928                 current_biggiefile_number, (long) size >> 10);
     873        mr_asprintf(comment, "Verifying bigfile #%ld (%ld K)", current_biggiefile_number, (long) size >> 10);
    929874        update_progress_form(comment);
    930         sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
    931         res =
    932             verify_a_biggiefile_from_stream(logical_fname, size);
    933         retval += res;
     875        mr_free(comment);
     876
     877        if (bkpinfo->restore_path) {
     878            mr_asprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname);
     879            res = verify_a_biggiefile_from_stream(logical_fname, size);
     880            mr_free(logical_fname);
     881            retval += res;
     882        } else {
     883            log_it("Unable to verify bigfile as restore_path is NULL");
     884        }
     885
    934886        current_biggiefile_number++;
    935887        g_current_progress++;
     
    937889    close_progress_form();
    938890    paranoid_free(orig_fname);
    939     paranoid_free(logical_fname);
    940891    paranoid_free(curr_xattr_list_fname);
    941892    paranoid_free(curr_acl_list_fname);
    942     paranoid_free(comment);
    943     paranoid_free(tmp);
    944893    return (retval);
    945894}
     
    951900 * Verify the USB device
    952901 * @param bkpinfo The backup information structure. Fields used:
    953  * - @c bkpinfo->isodir
    954902 * - @c bkpinfo->media_device
    955903 * - @c bkpinfo->tmpdir
     
    981929    assert(bkpinfo != NULL);
    982930
     931    if (bkpinfo->media_device == NULL) {
     932        return(1);
     933    }
     934
    983935    mr_asprintf(fname, "%s1", bkpinfo->media_device);
    984936    if (is_this_device_mounted(fname)) {
     
    1032984#endif
    1033985    {
    1034         mr_asprintf(tmp, "%s failed; unable to unmount USB device\n", tmp1);
    1035         log_to_screen(tmp);
    1036         paranoid_free(tmp);
     986        log_to_screen("%s failed; unable to unmount USB device\n", tmp1);
    1037987        retval++;
    1038988    } else {
    1039989        log_msg(2, "OK, I've unmounted the USB device\n");
    1040990    }
    1041     paranoid_free(tmp1);
    1042     paranoid_free(mountpoint);
     991    mr_free(tmp1);
     992    mr_free(mountpoint);
    1043993    return (retval);
    1044994}
     
    10661016
    10671017    /*@ buffers ******************************************************** */
    1068     char *mountpoint;
    1069     char *command;
    1070     char *tmp;
    1071     char *fname;
     1018    char *mountpoint = NULL;
     1019    char *command = NULL;
     1020    char *tmp = NULL;
     1021    char *fname = NULL;
    10721022#ifdef __FreeBSD__
    10731023    char mdd[32];
     
    10791029#endif
    10801030
    1081     command = malloc(2000);
    1082     malloc_string(mountpoint);
    1083     malloc_string(tmp);
    1084     malloc_string(fname);
    1085 
    10861031    assert(bkpinfo != NULL);
    10871032
    1088     sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
    1089     sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir,
    1090             bkpinfo->prefix, g_current_media_number);
     1033    if (bkpinfo->media_device == NULL) {
     1034        return(1);
     1035    }
     1036
     1037    mr_asprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir);
     1038    if (((bkpinfo->isodir == NULL) && (bkpinfo->netfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) {
     1039        fatal_error("No iso filename preparation possible");
     1040    }
     1041    if (bkpinfo->netfs_remote_dir) {
     1042        // NETFS
     1043        mr_asprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
     1044    } else {
     1045        // ISO
     1046        mr_asprintf(fname, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
     1047    }
    10911048
    10921049    mkdir(mountpoint, 1777);
    10931050    sync();
    10941051    if (!does_file_exist(fname)) {
    1095         sprintf(tmp,
    1096                 "%s not found; assuming you backed up to CD; verifying CD...",
    1097                 fname);
    1098         log_msg(2, tmp);
     1052        log_msg(2, "%s not found; assuming you backed up to CD; verifying CD...", fname);
    10991053        if (bkpinfo->manual_cd_tray) {
    11001054            popup_and_OK("Please push CD tray closed.");
     
    11021056        if (find_and_mount_actual_cd(mountpoint)) {
    11031057            log_to_screen("failed to mount actual CD");
     1058            mr_free(mountpoint);
     1059            mr_free(fname);
    11041060            return (1);
    11051061        }
    11061062    } else {
    1107         sprintf(tmp, "%s found; verifying ISO...", fname);
     1063        log_msg(2, "%s found; verifying ISO...", fname);
    11081064#ifdef __FreeBSD__
    11091065        ret = 0;
     
    11111067        mddevice = make_vn(fname);
    11121068        if (ret) {
    1113             sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",
    1114                     fname);
    1115             log_to_screen(tmp);
     1069            log_to_screen("make_vn of %s failed; unable to verify ISO\n", fname);
     1070            mr_free(mountpoint);
     1071            mr_free(fname);
    11161072            return (1);
    11171073        }
    1118         sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
     1074        mr_asprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);
    11191075#else
    1120         sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname,
    1121                 mountpoint);
     1076        mr_asprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname, mountpoint);
    11221077#endif
    11231078        if (run_program_and_log_output(command, FALSE)) {
    1124             sprintf(tmp, "%s failed; unable to mount ISO image\n",
    1125                     command);
    1126             log_to_screen(tmp);
     1079            log_to_screen("%s failed; unable to mount ISO image\n", command);
     1080            mr_free(mountpoint);
     1081            mr_free(command);
     1082            mr_free(fname);
    11271083            return (1);
    11281084        }
     1085        mr_free(command);
    11291086    }
    11301087    log_msg(2, "OK, I've mounted the ISO/CD\n");
    1131     sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
     1088    mr_asprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);
    11321089    if (!does_file_exist(tmp)) {
    11331090        log_msg
     
    11411098*/
    11421099    }
     1100    mr_free(tmp);
     1101
    11431102    verify_afioballs_on_CD(mountpoint);
    11441103    log_it("before verify_all_slices");
     
    11471106#ifdef __FreeBSD__
    11481107    ret = 0;
    1149     sprintf(command, "umount -d %s", mountpoint);
     1108    mr_asprintf(command, "umount -d %s", mountpoint);
    11501109    ret += system(command);
    11511110    ret += kick_vn(mddevice);
    1152     if (ret)
     1111    if (ret) {
    11531112#else
    1154     sprintf(command, "umount -d %s", mountpoint);
    1155     if (system(command))
     1113    mr_asprintf(command, "umount -d %s", mountpoint);
     1114    if (system(command)) {
    11561115#endif
    1157     {
    1158         sprintf(tmp, "%s failed; unable to unmount ISO image\n", command);
    1159         log_to_screen(tmp);
     1116        log_to_screen("%s failed; unable to unmount ISO image\n", command);
     1117
    11601118        retval++;
    11611119    } else {
    11621120        log_msg(2, "OK, I've unmounted the ISO file\n");
    11631121    }
     1122    mr_free(mountpoint);
     1123    mr_free(command);
     1124
    11641125    if (!does_file_exist(fname)) {
    1165         sprintf(command, "umount -d %s", bkpinfo->media_device);
     1126        mr_asprintf(command, "umount -d %s", bkpinfo->media_device);
    11661127        run_program_and_log_output(command, 2);
    1167         if (!bkpinfo->please_dont_eject
    1168             && eject_device(bkpinfo->media_device)) {
     1128        mr_free(command);
     1129
     1130        if (!bkpinfo->please_dont_eject && eject_device(bkpinfo->media_device)) {
    11691131            log_msg(2, "Failed to eject CD-ROM drive");
    11701132        }
    11711133    }
    1172     paranoid_free(command);
    1173     paranoid_free(mountpoint);
    1174     paranoid_free(tmp);
    1175     paranoid_free(fname);
     1134    mr_free(fname);
    11761135    return (retval);
    11771136}
     
    11911150
    11921151    /*@ buffers ******************************************************** */
    1193     char tmp[MAX_STR_LEN];
    1194     char changed_files_fname[MAX_STR_LEN];
     1152    char *tmp = NULL;
     1153    char *changed_files_fname = NULL;
    11951154
    11961155    /*@ long *********************************************************** */
     
    12061165    retval += verify_biggiefiles_from_stream();
    12071166/* find the final blocks */
    1208     paranoid_system("sync");
     1167    sync();
    12091168    sleep(2);
    12101169    closein_tape();
    12111170/* close tape; exit */
    12121171//  fclose(g_tape_stream); <-- not needed; is handled by closein_tape()
    1213     sprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
     1172    mr_asprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
    12141173    paranoid_system(tmp);
    1215     sprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir);
    1216     sprintf(tmp,
    1217             "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$'  > %s",
    1218             (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE,
    1219             changed_files_fname);
     1174    mr_free(tmp);
     1175
     1176    mr_asprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir);
     1177    mr_asprintf(tmp, "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$'  > %s", (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE, changed_files_fname);
    12201178    log_msg(2, "Running command to derive list of changed files");
    12211179    log_msg(2, tmp);
    12221180    if (system(tmp)) {
    1223         if (does_file_exist(changed_files_fname)
    1224             && length_of_file(changed_files_fname) > 2) {
    1225             log_to_screen
    1226                 ("Warning - unable to check logfile to derive list of changed files");
     1181        if (does_file_exist(changed_files_fname) && length_of_file(changed_files_fname) > 2) {
     1182            log_to_screen("Warning - unable to check logfile to derive list of changed files");
    12271183        } else {
    1228             log_to_screen
    1229                 ("No differences found. Therefore, no 'changed.files' text file.");
    1230         }
    1231     }
    1232     sprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname);
     1184            log_to_screen("No differences found. Therefore, no 'changed.files' text file.");
     1185        }
     1186    }
     1187    mr_free(tmp);
     1188
     1189    mr_asprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname);
    12331190    paranoid_system(tmp);
     1191    mr_free(tmp);
    12341192
    12351193    diffs = count_lines_in_file(changed_files_fname);
    12361194    if (diffs > 0) {
    1237         sprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname,
    1238                 MONDO_CACHE);
     1195        mr_asprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname, MONDO_CACHE);
    12391196        run_program_and_log_output(tmp, FALSE);
    1240         sprintf(tmp,
    1241                 "%ld files differed from live filesystem; type less %s or less %s/changed.files to see",
    1242                 diffs, changed_files_fname, MONDO_CACHE);
    1243         log_msg(0, tmp);
     1197        mr_free(tmp);
     1198
     1199        log_msg(0, "%ld files differed from live filesystem; type less %s or less %s/changed.files to see", diffs, changed_files_fname, MONDO_CACHE);
    12441200        log_to_screen("See "MONDO_CACHE"/changed.files for a list of nonmatching files.");
    12451201        log_to_screen("The files probably changed on filesystem, not on backup media.");
    1246         //      retval++;
    1247     }
     1202    }
     1203    mr_free(changed_files_fname);
    12481204    return (retval);
    12491205}
  • branches/3.2/mondo/src/common/mondostructures.h

    r3150 r3191  
    412412    bool use_gzip;
    413413
    414   /**
    415    * A filename containing a list of extensions, one per line, to not
    416    * compress. If this is set to "", afio will still exclude a set of well-known
    417    * compressed files from compression, but biggiefiles that are compressed
    418    * will be recompressed again.
    419    */
    420     char do_not_compress_these[MAX_STR_LEN / 2];
     414/**
     415   * If TRUE, then use @c lzma to compress data.
     416   * This is used mainly in estimates. The backup/restore may or may
     417   * not work if you do not set this. You should also set @p zip_exe
     418   * and @p zip_suffix.
     419   */
     420    bool use_lzma;
    421421
    422422  /**
     
    492492   */
    493493    t_bkptype backup_media_type;
    494 //  bool blank_dvd_first;
    495494
    496495  /**
     
    506505   * If you do nothing, "/" will be used.
    507506   */
    508     char include_paths[MAX_STR_LEN*4];
     507    char *include_paths;
    509508
    510509  /**
     
    560559   * address form. (Domain names will be resolved in post_param_configuration().)
    561560   */
    562     char netfs_mount[MAX_STR_LEN];
     561    char *netfs_mount;
    563562
    564563  /**
     
    566565   * the backups in.
    567566   */
    568     char netfs_remote_dir[MAX_STR_LEN];
     567    char *netfs_remote_dir;
    569568
    570569  /**
     
    674673   */
    675674    bool expanded;
    676 };
    677 
    678 
    679 
    680 /**
    681  * A structure to wrap a FIFO device for writing to a tape/CD stream.
    682  * @bug Is this structure used (w/the move to a standalone @c buffer and all)?
    683  */
    684 struct s_wrapfifo {
    685         /**
    686      * The device we write to or read from (a FIFO).
    687      */
    688     char public_device[MAX_STR_LEN / 4];
    689 
    690         /**
    691      * The actual device that data from the FIFO should be buffered and written to.
    692      */
    693     char private_device[MAX_STR_LEN / 4];
    694 
    695         /**
    696      * A buffer for holding data read from the FIFO.
    697      */
    698     char internal_buffer_IN_fifo[MAX_STR_LEN / 4];
    699 
    700         /**
    701      * A buffer for holding data to be written to the FIFO.
    702      */
    703     char internal_buffer_OUT_fifo[MAX_STR_LEN / 4];
    704 
    705         /**
    706      * If TRUE, then we're writing directly to the tape streamer; if FALSE, we're writing to the FIFO.
    707      */
    708     bool writing_to_private_device;
    709675};
    710676
  • branches/3.2/mondo/src/common/newt-specific.c

    r3185 r3191  
    9797    extern int g_current_media_number;
    9898    pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
    99     long g_maximum_progress = 999;  ///< The maximum amount of progress (100%) for the currently opened progress form.
     99    long g_maximum_progress = 999L; ///< The maximum amount of progress (100%) for the currently opened progress form.
    100100    long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
    101     long g_start_time = 0;      ///< The time (in seconds since the epoch) that the progress form was opened.
     101    long g_start_time = 0L;     ///< The time (in seconds since the epoch) that the progress form was opened.
    102102    bool g_text_mode = TRUE;    ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface.
    103     char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN],  ///< ... @bug Unneeded w/current XMondo.
    104      g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.
    105     bool g_called_by_xmondo = FALSE;    ///< @bug Unneeded w/current XMondo.
    106103    char *g_selfmounted_isodir; ///< Holds the NETFS mountpoint if mounted via mondoarchive.
    107104
    108105/* @} - end of globalGroup */
    109 
    110 //int g_fd_in=-1, g_fd_out=-1;
    111106
    112107    void popup_and_OK(char *);
     
    125120
    126121        /*@ buffers ********************************************************** */
    127         int i;
    128         char *p;
     122        int i = 0;
     123        char *tmp = NULL;
    129124
    130125        assert_string_is_neither_NULL_nor_zerolength(prompt);
     
    136131        }
    137132        if (g_text_mode) {
    138 
    139             char *tmp;
    140             tmp = malloc(MAX_NEWT_COMMENT_LEN);
    141 
    142133            while (1) {
    143                 paranoid_system("sync");
    144                 printf
    145                     ("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ",
    146                      prompt);
    147                 p= fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    148                 if (!p) {
    149                     //FIXME
    150                 }
     134                sync();
     135                printf("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", prompt);
     136                mr_getline(tmp, stdin);
    151137                if (tmp[strlen(tmp) - 1] == '\n')
    152138                    tmp[strlen(tmp) - 1] = '\0';
     
    157143                }
    158144                if (strstr("yesYES", tmp)) {
    159                     paranoid_free(tmp);
     145                    mr_free(tmp);
    160146                    return (TRUE);
    161147                } else if (strstr("NOno", tmp)) {
    162                     paranoid_free(tmp);
     148                    mr_free(tmp);
    163149                    return (FALSE);
    164150                } else {
    165                     paranoid_system("sync");
    166                     printf
    167                         ("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
     151                    sync();
     152                    printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n");
    168153                }
    169154            }
     
    183168
    184169        /*@ buffer *********************************************************** */
    185         char *tmp;
    186         char *p;
     170        char *tmp = NULL;
    187171        int i;
    188172
     
    193177            finish(1);
    194178        }
    195         tmp = malloc(MAX_NEWT_COMMENT_LEN);
     179
    196180        if (g_text_mode) {
    197             paranoid_system("sync");
    198             printf
    199                 ("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ",
    200                  prompt);
    201             p = fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin);
    202             if (!p) {
    203                 // FIXME
    204             }
     181            sync();
     182            printf("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", prompt);
     183            mr_getline(tmp, stdin);
    205184            if (tmp[strlen(tmp) - 1] == '\n')
    206185                tmp[strlen(tmp) - 1] = '\0';
     
    211190            }
    212191            if (strstr("okOKOkYESyes", tmp)) {
    213                 paranoid_free(tmp);
     192                mr_free(tmp);
    214193                return (TRUE);
    215194            } else {
    216                 paranoid_free(tmp);
     195                mr_free(tmp);
    217196                return (FALSE);
    218197            }
    219198        } else {
    220             paranoid_free(tmp);
    221199            return (popup_with_buttons(prompt, " Okay ", "Cancel"));
    222200        }
     
    264242        }
    265243        if (g_current_progress == -999) {
    266             log_msg(2,
    267                     "Trying to close the progress form when it ain't open!");
     244            log_msg(2, "Trying to close the progress form when it ain't open!");
    268245            return;
    269246        }
     
    301278        mr_asprintf(tmp1,"kill `%s`", tmp);
    302279        run_program_and_log_output(tmp1, TRUE);
    303         paranoid_free(tmp1);
    304     }
    305     paranoid_free(tmp);
     280        mr_free(tmp1);
     281    }
     282    mr_free(tmp);
    306283}
    307284
     
    312289 * @note This function never returns.
    313290 */
    314     void
    315      fatal_error(char *error_string) {
     291void fatal_error(char *error_string) {
     292
    316293        /*@ buffers ***************************************************** */
    317         char fatalstr[MAX_NEWT_COMMENT_LEN] =
    318             "-------FATAL ERROR---------";
    319         char *tmp;
    320         char *command;
     294        char *command = NULL;
    321295        static bool already_exiting = FALSE;
    322296
    323297        /*@ end vars **************************************************** */
    324298
    325         malloc_string(command);
    326         tmp = malloc(MAX_NEWT_COMMENT_LEN);
    327299        set_signals(FALSE);     // link to external func
    328300        g_exiting = TRUE;
     
    332304            log_msg(2, "mastermind %d is exiting", (int) getpid());
    333305            kill(g_main_pid, SIGTERM);
    334             paranoid_free(tmp);
    335306            finish(1);
    336307        }
     
    340311                log_msg(2, "non-m/m %d is exiting", (int) getpid());
    341312                kill(g_main_pid, SIGTERM);
    342                 paranoid_free(tmp);
    343313                finish(1);
    344314            }
     
    348318        if (already_exiting) {
    349319            log_msg(3, "...I'm already exiting. Give me time, Julian!");
    350             paranoid_free(tmp);
    351320            finish(1);
    352321        }
     
    359328        kill_anything_like_this("ntfsclone");
    360329        sync();
    361         /*
    362         sprintf(tmp, "umount %s", g_tmpfs_mountpt);
    363         for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {
    364             log_msg(2, "Waiting for child processes to terminate");
    365             sleep(1);
    366             run_program_and_log_output(tmp, 5);
    367         }
    368         */
    369330
    370331        if (chdir("/")) {
     
    372333        }
    373334        if (g_selfmounted_isodir) {
    374             sprintf(command, "umount -d %s", g_selfmounted_isodir);
     335            mr_asprintf(command, "umount -d %s", g_selfmounted_isodir);
    375336            run_program_and_log_output(command, 5);
    376             sprintf(command, "rmdir %s", g_selfmounted_isodir);
     337            mr_free(command);
     338            mr_asprintf(command, "rmdir %s", g_selfmounted_isodir);
    377339            run_program_and_log_output(command, 5);
     340            mr_free(command);
    378341        }
    379342
    380343        if (!g_text_mode) {
    381             log_msg(0, fatalstr);
     344            log_msg(0, "-------FATAL ERROR---------");
    382345            log_msg(0, error_string);
    383             //      popup_and_OK (error_string);
    384             newtFinished();
    385346        }
    386347
    387348        printf("---FATALERROR--- %s\n", error_string);
    388         printf
    389                 ("If you require technical support, please contact the mailing list.\n");
     349        printf("If you require technical support, please contact the mailing list.\n");
    390350        printf("See http://www.mondorescue.org for details.\n");
    391         printf
    392                 ("The list's members can help you, if you attach that file to your e-mail.\n");
     351        printf("The list's members can help you, if you attach that file to your e-mail.\n");
    393352        printf("Log file: %s\n", MONDO_LOGFILE);
    394353        printf("Mondo has aborted.\n");
     
    396355            log_msg(3, "FYI - g_main_pid is blank");
    397356        }
    398         paranoid_free(tmp);
    399         paranoid_free(command);
    400357        finish(254);
    401358    }
     
    420377 * @note This function never returns.
    421378 */
    422     void
    423      finish(int signal) {
     379void finish(int signal) {
     380
    424381        char *command = NULL;
    425 
    426         /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
    427 
    428         /* newtPopHelpLine(); */
    429382
    430383        /*  Before removing dir, make sure we're out of them */
     
    436389            mr_asprintf(command, "umount -d %s", g_selfmounted_isodir);
    437390            run_program_and_log_output(command, 1);
    438             paranoid_free(command);
     391            mr_free(command);
     392
    439393            mr_asprintf(command, "rmdir %s", g_selfmounted_isodir);
    440394            run_program_and_log_output(command, 1);
    441             paranoid_free(command);
    442         }
     395            mr_free(command);
     396        }
     397        if (bkpinfo->tmpdir) {
     398            log_msg(8,"tempdir is %s",bkpinfo->tmpdir);
     399            if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {
     400                log_msg(8,"erasing tempdir %s",bkpinfo->tmpdir);
     401                mr_asprintf(command, "rm -Rf %s", bkpinfo->tmpdir);
     402                paranoid_system(command);
     403                mr_free(command);
     404            }
     405        }
     406        if (bkpinfo->scratchdir) {
     407            log_msg(8,"scratchdir is %s", bkpinfo->scratchdir);
     408            if (strstr(bkpinfo->scratchdir ,"mondo.scratch.") != NULL) {
     409                log_msg(8,"erasing scratchdir %s",bkpinfo->scratchdir);
     410                mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir);
     411                paranoid_system(command);
     412                mr_free(command);
     413            }
     414        }
     415        /* Free all allocated strings in bkpinfo */
     416        mr_free(bkpinfo->netfs_user);
     417        mr_free(bkpinfo->netfs_proto);
     418        mr_free(bkpinfo->exclude_devs);
     419        mr_free(bkpinfo->exclude_paths);
     420        mr_free(bkpinfo->subdir);
     421        /* Then free the structure */
     422        paranoid_free(bkpinfo);
     423
     424        free_libmondo_global_strings();
     425        free_newt_stuff();
    443426        if (!g_text_mode) {
    444427            if (does_file_exist("/THIS-IS-A-RAMDISK")) {
     
    452435        printf("Execution run ended; result=%d\n", signal);
    453436        printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
    454         if (bkpinfo->tmpdir) {
    455             log_msg(8,"tempdir is %s",bkpinfo->tmpdir);
    456             if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {
    457                 log_msg(8,"erasing tempdir %s",bkpinfo->tmpdir);
    458                 mr_asprintf(command, "rm -Rf %s", bkpinfo->tmpdir);
    459                 paranoid_system(command);
    460                 mr_free(command);
    461             }
    462         }
    463         if (bkpinfo->scratchdir) {
    464             log_msg(8,"scratchdir is %s", bkpinfo->scratchdir);
    465             if (strstr(bkpinfo->scratchdir ,"mondo.scratch.") != NULL) {
    466                 log_msg(8,"erasing scratchdir %s",bkpinfo->scratchdir);
    467                 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir);
    468                 paranoid_system(command);
    469                 mr_free(command);
    470             }
    471         }
    472         /* Free all allocated strings in bkpinfo */
    473         mr_free(bkpinfo->netfs_user);
    474         mr_free(bkpinfo->netfs_proto);
    475         mr_free(bkpinfo->exclude_devs);
    476         mr_free(bkpinfo->exclude_paths);
    477         mr_free(bkpinfo->subdir);
    478 
    479         /* Then free the structure */
    480         paranoid_free(bkpinfo);
    481         free_libmondo_global_strings();
    482         free_newt_stuff();
    483437        exit(signal);
    484438    }
    485 
    486 
    487 
    488439
    489440
     
    494445 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression.
    495446 */
    496     void
    497      log_file_end_to_screen(char *filename, char *grep_for_me) {
     447void log_file_end_to_screen(char *filename, char *grep_for_me) {
    498448
    499449        /*@ buffers ********************************************************** */
     
    515465        }
    516466        if (grep_for_me[0] != '\0') {
    517             mr_asprintf(command, "grep '%s' %s | tail -n%d",
    518                     grep_for_me, filename, g_noof_log_lines);
    519         } else {
    520             mr_asprintf(command, "tail -n%d %s", g_noof_log_lines,
    521                     filename);
     467            mr_asprintf(command, "grep '%s' %s | tail -n%d", grep_for_me, filename, g_noof_log_lines);
     468        } else {
     469            mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, filename);
    522470        }
    523471        fin = popen(command, "r");
     
    557505 * @note The message is also written to the logfile.
    558506 */
    559     void
    560      log_to_screen(const char *fmt, ...) {
     507void log_to_screen(const char *fmt, ...) {
    561508
    562509        /*@ int ************************************************************** */
     
    614561 * @param output The string to write.
    615562 */
    616     void
    617      mvaddstr_and_log_it(int y, int x, char *output) {
     563void mvaddstr_and_log_it(int y, int x, char *output) {
     564
    618565        assert_string_is_neither_NULL_nor_zerolength(output);
    619566        log_msg(0, output);
     
    633580 * @param ttl The title to use for the evalcall form.
    634581 */
    635     void
    636      open_evalcall_form(char *ttl) {
     582void open_evalcall_form(char *ttl) {
    637583
    638584        /*@ buffers ********************************************************* */
    639         char *title;
    640         char *tmp;
     585        char *tmp = NULL;
    641586
    642587        /*@ initialize ****************************************************** */
    643588        g_isoform_old_progress = -1;
    644589        g_mysterious_dot_counter = 0;
    645         malloc_string(title);
     590
     591        assert(ttl != NULL);
    646592        malloc_string(tmp);
    647 
    648         assert(ttl != NULL);
    649         strcpy(title, ttl);
    650         strcpy(g_isoform_header_str, title);
    651 //  center_string (title, 80);
     593        strcpy(g_isoform_header_str, ttl);
    652594        if (g_text_mode) {
    653             log_msg(0, title);
    654         } else {
    655             strcpy(tmp, title);
     595            log_msg(0, ttl);
     596        } else {
     597            strcpy(tmp, ttl);
    656598            center_string(tmp, 80);
    657599            newtPushHelpLine(tmp);
     
    664606            g_isoform_header = newtLabel(1, 1, g_isoform_header_str);
    665607            g_isoform_scale = newtScale(3, 3, 34, 100);
    666             //      newtOpenWindow (20, 6, 40, 7, title);      // "Please Wait");
    667             newtCenteredWindow(40, 7, title);
     608            newtCenteredWindow(40, 7, ttl);
    668609            g_isoform_main = newtForm(NULL, NULL, 0);
    669610            g_isoform_timeline = newtLabel(1, 5, "                    ");
     
    677618        update_evalcall_form(0);
    678619        paranoid_free(tmp);
    679         paranoid_free(title);
    680620    }
    681621
     
    691631 * @param max_val The maximum amount of progress (number of filesets, etc.)
    692632 */
    693     void
    694      open_progress_form(char *title, char *b1, char *b2, char *b3,
    695                         long max_val) {
     633void open_progress_form(char *title, char *b1, char *b2, char *b3, long max_val) {
    696634
    697635        /*@ buffers ********************************************************* */
    698636        char *b1c;
    699         char *blurb1;
    700         char *blurb2;
    701         char *blurb3;
     637        char *blurb1 = NULL;
     638        char *blurb2 = NULL;
     639        char *blurb3 = NULL;
    702640
    703641        /*@ initialize ****************************************************** */
     
    705643
    706644        malloc_string(b1c);
    707         malloc_string(blurb1);
    708         malloc_string(blurb2);
    709         malloc_string(blurb3);
    710645
    711646        assert(title != NULL);
     
    714649        assert(b3 != NULL);
    715650
    716         strcpy(blurb1, b1);
    717         strcpy(blurb2, b2);
    718         strcpy(blurb3, b3);
     651        mr_asprintf(blurb1,  "%s", b1);
     652        mr_asprintf(blurb2,  "%s", b2);
     653        mr_asprintf(blurb3,  "%s", b3);
     654
    719655        strcpy(b1c, b1);
    720656        center_string(b1c, 80);
     
    737673            g_blurb2 = newtLabel(2, 2, blurb3);
    738674            g_blurb3 = newtLabel(2, 4, blurb2);
    739             //      newtOpenWindow (10, 4, 60, 11, title);
    740675            newtCenteredWindow(60, 11, title);
    741             g_scale = newtScale(3, 6, 54, g_maximum_progress);
     676            g_scale = newtScale(3, 6, 54, (long long)g_maximum_progress);
    742677            g_progressForm = newtForm(NULL, NULL, 0);
    743678            g_percentline = newtLabel(10, 9, "                       ");
    744679            g_timeline = newtLabel(10, 8, "                    ");
    745             newtFormAddComponents(g_progressForm, g_percentline,
    746                                   g_timeline, g_scale, g_blurb1, g_blurb3,
    747                                   g_blurb2, NULL);
     680            newtFormAddComponents(g_progressForm, g_percentline, g_timeline, g_scale, g_blurb1, g_blurb3, g_blurb2, NULL);
    748681            newtPushHelpLine(b1c);
    749682            newtDrawForm(g_progressForm);
     
    752685        update_progress_form_full(blurb1, blurb2, blurb3);
    753686        paranoid_free(b1c);
    754         paranoid_free(blurb1);
    755         paranoid_free(blurb2);
    756         paranoid_free(blurb3);
     687        mr_free(blurb1);
     688        mr_free(blurb2);
     689        mr_free(blurb3);
    757690    }
    758691
     
    761694 * @param prompt The message.
    762695 */
    763     void
    764      popup_and_OK(char *prompt) {
     696void popup_and_OK(char *prompt) {
     697
    765698        char ch;
    766699
     
    769702        log_msg(0, prompt);
    770703        if (g_text_mode) {
    771             printf
    772                 ("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ",
    773                  prompt);
     704            printf("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", prompt);
    774705            while (((ch = getchar()) != '\n') && (ch != EOF));
    775706        } else {
     
    786717 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    787718 */
    788     bool popup_and_get_string(char *title, char *b, char *output,
    789                               int maxsize) {
     719    bool popup_and_get_string(char *title, char *b, char *output, int maxsize) {
    790720
    791721        /*@ newt ************************************************************ */
     
    801731
    802732        /*@ buffers ********************************************************** */
    803         char *blurb;
     733        char *blurb = NULL;
    804734        char *p;
    805         char *original_contents;
    806 
    807         blurb = malloc(MAX_NEWT_COMMENT_LEN);
    808         original_contents = malloc(MAX_NEWT_COMMENT_LEN);
     735        char *original_contents = NULL;
     736
    809737        assert_string_is_neither_NULL_nor_zerolength(title);
    810738        assert(b != NULL);
     
    812740
    813741        if (g_text_mode) {
    814             printf
    815                 ("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n-->  ",
    816                  title, b);
     742            printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n-->  ", title, b);
    817743            p = fgets(output, maxsize, stdin);
    818744            if (!p) {
     
    821747            if (output[strlen(output) - 1] == '\n')
    822748                output[strlen(output) - 1] = '\0';
    823             paranoid_free(blurb);
    824             paranoid_free(original_contents);
    825749            return (TRUE);
    826750        }
     751       
     752        blurb = malloc(MAX_NEWT_COMMENT_LEN);
    827753        strcpy(blurb, b);
    828754        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
    829         strcpy(original_contents, output);
     755        mr_asprintf(original_contents, "%s", output);
    830756        output[0] = '\0';
    831         type_here =
    832             newtEntry(2, newtTextboxGetNumLines(text) + 2,
    833                       original_contents, 50,
     757        type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, original_contents, 50,
    834758#ifdef __cplusplus
    835759                      0, NEWT_FLAG_RETURNEXIT
     
    840764        b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, "  OK  ");
    841765        b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel");
    842         //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
    843766        newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
    844767        myForm = newtForm(NULL, NULL, 0);
     
    851774        newtFormDestroy(myForm);
    852775        newtPopWindow();
     776        paranoid_free(blurb);
     777
    853778        if (b_res == b_2) {
    854779            strcpy(output, original_contents);
    855             paranoid_free(blurb);
    856             paranoid_free(original_contents);
     780            mr_free(original_contents);
    857781            return (FALSE);
    858782        } else {
    859             paranoid_free(blurb);
    860             paranoid_free(original_contents);
     783            mr_free(original_contents);
    861784            return (TRUE);
    862785        }
     
    871794 * @return TRUE if @p button1 was pushed, FALSE otherwise.
    872795 */
    873     bool popup_with_buttons(char *p, char *button1, char *button2) {
     796bool popup_with_buttons(char *p, char *button1, char *button2) {
    874797
    875798        /*@ buffers *********************************************************** */
    876         char *prompt;
    877         char *q;
     799        char *prompt = NULL;
    878800
    879801        /*@ newt ************************************************************** */
     
    887809        assert(button1 != NULL);
    888810        assert(button2 != NULL);
    889         prompt = malloc(MAX_NEWT_COMMENT_LEN);
    890811        if (g_text_mode) {
    891812            if (strlen(button2) == 0) {
     
    894815                printf("%s (%s or %s) --> ", p, button1, button2);
    895816            }
    896             for (prompt[0] = '\0';
    897                  strcmp(prompt, button1) && (strlen(button2) == 0
    898                                           || strcmp(prompt, button2));) {
     817            mr_getline(prompt, stdin);
     818            while (strcmp(prompt, button1) && (strlen(button2) == 0 || strcmp(prompt, button2))) {
    899819                printf("--> ");
    900                 q = fgets(prompt, MAX_NEWT_COMMENT_LEN, stdin);
    901                 if (!q) {
    902                     // FIXME
    903                 }
     820                mr_free(prompt);
     821                mr_getline(prompt, stdin);
    904822            }
    905823            if (!strcmp(prompt, button1)) {
    906                 paranoid_free(prompt);
     824                mr_free(prompt);
    907825                return (TRUE);
    908826            } else {
    909                 paranoid_free(prompt);
     827                mr_free(prompt);
    910828                return (FALSE);
    911829            }
    912830        }
    913831
     832        prompt = malloc(MAX_NEWT_COMMENT_LEN);
    914833        strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1);
    915834        prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0';
    916835        text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0);
    917         b_1 =
    918             newtButton(20 -
    919                        ((button2[0] !=
    920                          '\0') ? strlen(button1) +
    921                         2 : strlen(button1) / 2),
    922                        newtTextboxGetNumLines(text) + 3, button1);
     836        b_1 = newtButton(20 - ((button2[0] != '\0') ? strlen(button1) + 2 : strlen(button1) / 2), newtTextboxGetNumLines(text) + 3, button1);
    923837        if (button2[0] != '\0') {
    924             b_2 =
    925                 newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
     838            b_2 = newtButton(24, newtTextboxGetNumLines(text) + 3, button2);
    926839        } else {
    927840            b_2 = NULL;
    928841        }
    929         //  newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");
    930842        newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert");
    931843        myForm = newtForm(NULL, NULL, 0);
     
    953865 * on the screen.
    954866 */
    955     void
    956      refresh_log_screen() {
     867void refresh_log_screen() {
    957868
    958869        /*@ int *********************************************************** */
     
    981892 * only allocate some memory.
    982893 */
    983     void
    984      setup_newt_stuff() {
     894void setup_newt_stuff() {
    985895
    986896        /*@ int *********************************************************** */
     
    991901            newtInit();
    992902            newtCls();
    993             newtPushHelpLine
    994                 ("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed.");
    995             /*  newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */
     903            newtPushHelpLine("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed.");
    996904            newtDrawRootText(18, 0, WELCOME_STRING);
    997905            newtRefresh();
     
    1000908        }
    1001909
    1002         err_log_lines =
    1003             (char **) malloc(sizeof(char *) * g_noof_log_lines);
    1004         if (!err_log_lines) {
    1005             fatal_error("Out of memory");
    1006         }
     910        err_log_lines = (char **) mr_malloc(sizeof(char *) * g_noof_log_lines);
    1007911
    1008912        for (i = 0; i < g_noof_log_lines; i++) {
    1009             err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN);
    1010             if (!err_log_lines[i]) {
    1011                 fatal_error("Out of memory");
    1012             }
     913            err_log_lines[i] = (char *) mr_malloc(MAX_NEWT_COMMENT_LEN);
    1013914        }
    1014915
     
    1024925 * @param denom The denomenator of the ratio.
    1025926 */
    1026     void
    1027      update_evalcall_form_ratio(int num, int denom) {
     927void update_evalcall_form_ratio(int num, int denom) {
    1028928
    1029929        /*@ long ************************************************************ */
    1030         long current_time = 0;
    1031         long time_taken = 0;
    1032         long time_total_est = 0;
    1033         long time_remaining = 0;
     930        long current_time = 0L;
     931        long time_taken = 0L;
     932        long time_total_est = 0L;
     933        long time_remaining = 0L;
    1034934
    1035935        /*@ buffers ********************************************************** */
    1036         char *timeline_str;
     936        char *timeline_str = NULL;
    1037937        char *pcline_str = NULL;
    1038938        char *taskprogress = NULL;
     
    1043943        int j = 0;
    1044944
    1045         malloc_string(timeline_str);
    1046         timeline_str[0] = '\0';
    1047 //  log_it("update_eval_call_form called");
    1048945        if (num * 100 < denom) {
    1049946            percentage = 1;
     
    1058955            time_remaining = time_total_est - time_taken;
    1059956        } else {
    1060             time_remaining = 0;
     957            time_remaining = 0L;
    1061958        }
    1062959        if (!g_text_mode) {
     
    1069966            || percentage > g_isoform_old_progress) {
    1070967            g_isoform_old_progress = percentage;
    1071             sprintf(timeline_str,
    1072                     "%2ld:%02ld taken            %2ld:%02ld remaining",
    1073                     (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60,
    1074                     (long) time_remaining % 60);
     968            mr_asprintf(timeline_str, "%2ld:%02ld taken            %2ld:%02ld remaining", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60);
    1075969            if (percentage < 3) {
    1076970                mr_asprintf(pcline_str, " Working");
     
    1083977                mr_strcat(pcline_str, " %c", special_dot_char(g_mysterious_dot_counter));
    1084978            } else {
    1085                 mr_asprintf(pcline_str, " %3d%% done              %3d%% to go",
    1086                         percentage, 100 - percentage);
     979                mr_asprintf(pcline_str, " %3d%% done              %3d%% to go", percentage, 100 - percentage);
    1087980            }
    1088981            if (g_text_mode) {
     
    1095988                }
    1096989                if (percentage >= 3) {
    1097                     mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage,
    1098                             (long) time_remaining / 60, (long) time_remaining % 60);
    1099                     printf("---evalcall---1--- %s\n",
    1100                            g_isoform_header_str);
     990                    mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60);
     991                    printf("---evalcall---1--- %s\n", g_isoform_header_str);
    1101992                    printf("---evalcall---2--- %s\n", taskprogress);
    1102993                    printf("---evalcall---E---\n");
    1103994                }
    1104                 paranoid_free(taskprogress);
     995                mr_free(taskprogress);
    1105996            } else {
    1106                 newtScaleSet(g_isoform_scale,
    1107                              (unsigned long long) percentage);
     997                newtScaleSet(g_isoform_scale, (unsigned long long) percentage);
    1108998                if (g_isoform_pcline) {
    1109999                    newtLabelSetText(g_isoform_pcline, pcline_str);
     
    11131003                }
    11141004            }
    1115             paranoid_free(pcline_str);
     1005            mr_free(pcline_str);
     1006            mr_free(timeline_str);
    11161007        }
    11171008        if (!g_text_mode) {
    1118 //      log_it("refreshing");
    11191009            newtDrawForm(g_isoform_main);
    11201010            newtRefresh();
    11211011        }
    1122         paranoid_free(timeline_str);
    11231012    }
    11241013
     
    11291018 * @param curr The current amount of progress (percentage) in the evalcall form.
    11301019 */
    1131     void
    1132      update_evalcall_form(int curr) {
     1020void update_evalcall_form(int curr) {
     1021
    11331022        update_evalcall_form_ratio(curr, 100);
    1134     }
     1023}
    11351024
    11361025
     
    11411030 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same.
    11421031 */
    1143     void
    1144      update_progress_form(char *blurb3) {
    1145         /*  log_it("update_progress_form --- called"); */
     1032void update_progress_form(char *blurb3) {
     1033
    11461034        if (g_current_progress == -999) {
    1147             /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */
    11481035            return;
    11491036        }
    11501037        strcpy(g_blurb_str_2, blurb3);
    1151         update_progress_form_full(g_blurb_str_1, g_blurb_str_2,
    1152                                   g_blurb_str_3);
    1153     }
     1038        update_progress_form_full(g_blurb_str_1, g_blurb_str_2, g_blurb_str_3);
     1039}
    11541040
    11551041
     
    11601046 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same.
    11611047 */
    1162     void
    1163      update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {
     1048void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) {
     1049
    11641050        /*@ long ***************************************************** */
    11651051        long current_time = 0L;
     
    11731059
    11741060        /*@ buffers *************************************************** */
    1175         char *percentline_str;
    1176         char *timeline_str;
     1061        char *percentline_str = NULL;
     1062        char *timeline_str = NULL;
    11771063        char *taskprogress = NULL;
    1178         char *tmp;
    1179 
    1180 //  log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3);
    1181         percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1182         timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1183         malloc_string(tmp);
     1064
    11841065        if (!g_text_mode) {
    11851066            assert(blurb1 != NULL);
     
    11891070        }
    11901071
    1191         percentline_str[0] = '\0';
    1192 
    11931072        current_time = get_time();
    11941073        time_taken = current_time - g_start_time;
     
    11971076        } else {
    11981077            if (g_current_progress > g_maximum_progress) {
    1199                 sprintf(tmp,
    1200                         "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    1201                         blurb1, blurb2, blurb3, g_current_progress,
    1202                         g_maximum_progress);
    1203                 log_msg(0, tmp);
     1078                log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress);
    12041079                g_current_progress = g_maximum_progress;
    12051080            }
    1206             percentage =
    1207                 (int) ((g_current_progress * 100L) / g_maximum_progress);
     1081            percentage = (int) ((g_current_progress * 100L) / g_maximum_progress);
    12081082        }
    12091083        if (percentage < 1) {
     
    12141088        }
    12151089        if (g_current_progress) {
    1216             time_total_est =
    1217                 time_taken * (long) g_maximum_progress /
    1218                 (long) (g_current_progress);
     1090            time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress;
    12191091            time_remaining = time_total_est - time_taken;
    12201092        } else {
     
    12221094        }
    12231095        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1224         sprintf(timeline_str,
    1225                 "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    1226                 (long) time_taken / 60, time_taken % 60, time_remaining / 60,
    1227                 time_remaining % 60);
    1228         sprintf(percentline_str, " %3d%% done                 %3d%% to go",
    1229                 percentage, 100 - percentage);
    1230 
    12311096        if (g_text_mode) {
    12321097            printf("---progress-form---1--- %s\n", blurb1);
     
    12441109                log_msg(2, "percentage = %d", percentage);
    12451110            }
    1246             mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage,
    1247                             (long) time_remaining / 60, (long) time_remaining % 60);
     1111            mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60);
    12481112            printf("---progress-form---4--- %s\n", taskprogress);
    12491113            paranoid_free(taskprogress);
    12501114        } else {
     1115            mr_asprintf(timeline_str, "%2ld:%02ld taken               %2ld:%02ld remaining  ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60);
     1116            mr_asprintf(percentline_str, " %3d%% done                 %3d%% to go", percentage, 100 - percentage);
     1117
    12511118            center_string(blurb1, 54);
    12521119            center_string(blurb2, 54);
     
    12651132                newtLabelSetText(g_timeline, timeline_str);
    12661133            }
     1134            mr_free(timeline_str);
     1135
    12671136            if (g_percentline) {
    12681137                newtLabelSetText(g_percentline, percentline_str);
    12691138            }
     1139            mr_free(percentline_str);
     1140
    12701141            newtDrawForm(g_progressForm);
    12711142            newtRefresh();
    12721143        }
    1273         paranoid_free(percentline_str);
    1274         paranoid_free(timeline_str);
    1275         paranoid_free(tmp);
    1276     }
    1277 
    1278 
    1279 
    1280 
    1281 
    1282 
    1283 
    1284 
    1285 
    1286 
    1287 
    1288 
     1144    }
    12891145
    12901146
     
    12971153 * @return The backup type chosen, or @c none if the user chose "Exit to shell".
    12981154 */
    1299     t_bkptype which_backup_media_type(bool restoring) {
     1155t_bkptype which_backup_media_type(bool restoring) {
    13001156
    13011157        /*@ char ************************************************************ */
     
    13041160
    13051161        /*@ newt ************************************************************ */
    1306         char *title_sz;
    1307         char *minimsg_sz;
    1308         static t_bkptype possible_bkptypes[] =
    1309             { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso };
    1310         static char *possible_responses[] =
    1311             { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev",
    1312 "netfs", "iso", NULL };
    1313         char *outstr;
    1314         char *p;
     1162        char *title_sz = NULL;
     1163        char *minimsg_sz = NULL;
     1164        static t_bkptype possible_bkptypes[] = { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso };
     1165        static char *possible_responses[] = { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "netfs", "iso", NULL };
     1166        char *outstr = NULL;
    13151167        t_bkptype backup_type;
    13161168        int i;
     
    13271179        newtComponent myForm;
    13281180
    1329         title_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1330         minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);
    1331         outstr = malloc(MAX_NEWT_COMMENT_LEN);
    13321181        if (g_text_mode) {
    13331182            for (backup_type = none; backup_type == none;) {
     
    13381187                }
    13391188                printf(")\n--> ");
    1340                 p = fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin);
    1341                 if (!p) {
    1342                     // FIXME
    1343                 }
    1344                 strip_spaces(outstr);
     1189                mr_getline(outstr, stdin);
     1190                mr_strip_spaces(outstr);
    13451191                for (i = 0; possible_responses[i]; i++) {
    13461192                    if (!strcmp(possible_responses[i], outstr)) {
     
    13481194                    }
    13491195                }
    1350             }
    1351             paranoid_free(title_sz);
    1352             paranoid_free(minimsg_sz);
    1353             paranoid_free(outstr);
     1196                mr_free(outstr);
     1197            }
    13541198            return (backup_type);
    13551199        }
    13561200        newtDrawRootText(18, 0, WELCOME_STRING);
    13571201        if (restoring) {
    1358             strcpy(title_sz,
    1359                    "Please choose the backup media from which you want to read data.");
    1360             strcpy(minimsg_sz, "Read from:");
    1361         } else {
    1362             strcpy(title_sz,
    1363                    "Please choose the backup media to which you want to archive data.");
    1364             strcpy(minimsg_sz, "Backup to:");
     1202            mr_asprintf(title_sz, "Please choose the backup media from which you want to read data.");
     1203            mr_asprintf(minimsg_sz, "Read from:");
     1204        } else {
     1205            mr_asprintf(title_sz, "Please choose the backup media to which you want to archive data.");
     1206            mr_asprintf(minimsg_sz, "Backup to:");
    13651207        }
    13661208        newtPushHelpLine(title_sz);
    1367         //  newtOpenWindow (23, 3, 34, 17, minimsg_sz);
    13681209        newtCenteredWindow(34, 17, minimsg_sz);
    13691210        b1 = newtButton(1, 1, "CD-R disks ");
     
    13991240        }
    14001241        newtPopHelpLine();
    1401         paranoid_free(title_sz);
    1402         paranoid_free(minimsg_sz);
    1403         paranoid_free(outstr);
     1242        mr_free(title_sz);
     1243        mr_free(minimsg_sz);
    14041244        return (output);
    14051245    }
     
    14231263        newtComponent b2;
    14241264        newtComponent b3;
    1425         //newtComponent b4;
     1265        newtComponent b4;
    14261266        newtComponent b5;
    14271267        newtComponent b_res;
     
    14351275        b2 = newtButton(18, 1, "gzip");
    14361276        b3 = newtButton(4, 5, "lzo");
    1437         //b4 = newtButton(18, 5, "lzma");
     1277        b4 = newtButton(18, 5, "lzma");
    14381278        b5 = newtButton(4, 9, "         Exit        ");
    14391279        myForm = newtForm(NULL, NULL, 0);
     
    14481288        } else if (b_res == b3) {
    14491289            mr_asprintf(output, "%s", "lzo");
    1450         //} else if (b_res == b4) {
    1451             //mr_asprintf(output, "%s", "lzma");
     1290        } else if (b_res == b4) {
     1291            mr_asprintf(output, "%s", "lzma");
    14521292        }
    14531293        newtPopHelpLine();
     
    14611301 * @return The compression level (0-9) chosen, or -1 for "Exit".
    14621302 */
    1463     int
    1464      which_compression_level() {
     1303int which_compression_level() {
    14651304
    14661305        /*@ char ************************************************************ */
     
    14791318
    14801319        newtDrawRootText(18, 0, WELCOME_STRING);
    1481         newtPushHelpLine
    1482             ("   Please specify the level of compression that you want.");
    1483         //  newtOpenWindow (23, 3, 34, 13, "How much compression?");
     1320        newtPushHelpLine("   Please specify the level of compression that you want.");
    14841321        newtCenteredWindow(34, 13, "How much compression?");
    14851322        b1 = newtButton(4, 1, "Maximum (9)");
     
    15181355 * @param source_file The file containing a list of filenames to load into @p filelist.
    15191356 */
    1520     int load_filelist_into_array(struct s_filelist *filelist,
    1521                                  char *source_file) {
     1357int load_filelist_into_array(struct s_filelist *filelist, char *source_file) {
     1358
    15221359        int i;
    15231360        int j = 0;
    15241361        bool done;
    1525         char *tmp;
    1526         char *p;
     1362        char *tmp = NULL;
    15271363        char *tmp1 = NULL;
    15281364        FILE *fin, *fout;
     
    15431379        if (!(fout = fopen(tmp1, "a"))) {
    15441380            log_msg(2, "Can't write to %s", tmp1);
     1381            mr_free(tmp1);
    15451382            return(1);
    15461383            }
    15471384
    1548         malloc_string(tmp);
    15491385        log_msg(2, "Loading %s", source_file);
    1550         for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM;
    1551              filelist->entries++) {
    1552           god_i_hate_gotos:
     1386        for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; ) {
     1387            mr_free(tmp);
    15531388            if (feof(fin)) {
    15541389                break;
    15551390            }
    1556             p = fgets(tmp, MAX_NEWT_COMMENT_LEN, fin);
    1557             if (!p) {
    1558                 // FIXME
    1559             }
     1391            mr_getline(tmp, fin);
    15601392            i = (int) strlen(tmp);
    15611393            if (i < 2) {
    1562                 goto god_i_hate_gotos;
     1394                continue;
    15631395            }
    15641396            if (tmp[i - 1] < 32) {
     
    15661398            }
    15671399            if (i < 2) {
    1568                 goto god_i_hate_gotos;
     1400                continue;
    15691401            }
    15701402            if (!does_file_exist(tmp) && !feof(fin)) {
    15711403                j++;
    15721404                fprintf(fout, "%s\n", tmp);
    1573 
    1574                 goto god_i_hate_gotos;
    1575             }
    1576             filelist->el[filelist->entries].severity =
    1577                 severity_of_difference(tmp, NULL);
     1405                continue;
     1406            }
     1407            filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL);
    15781408            strcpy(filelist->el[filelist->entries].filename, tmp);
    15791409            if (feof(fin)) {
    15801410                break;
    15811411            }
    1582         }
     1412            filelist->entries++;
     1413        }
     1414        mr_free(tmp);
    15831415        paranoid_fclose(fin);
    15841416        paranoid_fclose(fout);
     
    15861418            log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1);
    15871419        }
    1588         paranoid_free(tmp1);
     1420        mr_free(tmp1);
    15891421        if (filelist->entries >= ARBITRARY_MAXIMUM) {
    15901422            log_to_screen("Arbitrary limits suck, man!");
    1591             paranoid_free(tmp);
    15921423            return (1);
    15931424        }
     
    16171448            }
    16181449        }
    1619         paranoid_free(tmp);
    16201450        log_it("leaving");
    16211451        return (0);
    16221452    }
    1623 
    16241453
    16251454
     
    16301459 * @note The returned value points to static storage that will be overwritten with each call.
    16311460 */
    1632     char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
     1461char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
    16331462        static char comment[100];
    16341463        char *tmp = NULL;
    16351464
    1636         log_it("entering");
     1465        log_msg(8, "entering");
    16371466        assert(flentry != NULL);
    16381467        if (flentry->severity == 0) {
     
    16481477        mr_strcat(tmp, flentry->filename);
    16491478        strncpy(comment, tmp, 99);
    1650         paranoid_free(tmp);
     1479        mr_free(tmp);
    16511480
    16521481        log_it("leaving");
    16531482        return (comment);
    16541483    }
    1655 
    1656 
    1657 
    16581484
    16591485
     
    16631489 * @param source_file The file containing a list of changed files.
    16641490 */
    1665     void popup_changelist_from_file(char *source_file) {
    1666         char *reason;
     1491void popup_changelist_from_file(char *source_file) {
     1492
     1493        char *reason = NULL;
    16671494        newtComponent myForm;
    16681495        newtComponent bClose;
     
    16851512
    16861513        /*@ buffers ********************************************************* */
    1687         char *tmp;
    1688         char *differ_sz;
     1514        char *tmp = NULL;
     1515        char *differ_sz = NULL;
    16891516
    16901517        struct s_filelist *filelist;
    1691         malloc_string(reason);
    1692         tmp = malloc(5000);
    1693         malloc_string(differ_sz);
    16941518        assert_string_is_neither_NULL_nor_zerolength(source_file);
    16951519        if (g_text_mode) {
    16961520            log_msg(2, "Text mode. Therefore, no popup list.");
    1697             goto free_to_go;
     1521            return;
    16981522        }
    16991523        log_msg(2, "Examining file %s", source_file);
     
    17021526        if (lng < 1) {
    17031527            log_msg(2, "No lines in file. Therefore, no popup list.");
    1704             paranoid_free(reason);
    1705             goto free_to_go;
     1528            return;
    17061529        } else if (lng >= ARBITRARY_MAXIMUM) {
    17071530            log_msg(2, "Too many files differ for me to list.");
    1708             goto free_to_go;
     1531            return;
    17091532        }
    17101533
     
    17151538
    17161539        if (load_filelist_into_array(filelist, source_file)) {
    1717             log_msg(2, "Can't open %s; therefore, cannot popup list",
    1718                     source_file);
    1719             paranoid_free(reason);
     1540            log_msg(2, "Can't open %s; therefore, cannot popup list", source_file);
    17201541            return;
    17211542        }
    1722         log_msg(2, "%d files loaded into filelist array",
    1723                 filelist->entries);
     1543        log_msg(2, "%d files loaded into filelist array", filelist->entries);
    17241544        for (i = 0; i < filelist->entries; i++) {
    17251545            keylist[i] = (void *) i;
     
    17301550                                   keylist[i]);
    17311551        }
    1732         sprintf(differ_sz,
    1733                 "  %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
    1734                 i);
     1552        mr_asprintf(differ_sz, "  %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i);
    17351553        newtPushHelpLine(differ_sz);
     1554        mr_free(differ_sz);
     1555
    17361556        bClose = newtCompactButton(10, 15, " Close  ");
    17371557        bSelect = newtCompactButton(30, 15, " Select ");
    1738         sprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
     1558        mr_asprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
    17391559        headerMsg = newtLabel(2, 1, tmp);
     1560        mr_free(tmp);
     1561
    17401562        newtOpenWindow(5, 4, 70, 16, "Non-matching files");
    17411563        myForm = newtForm(NULL, NULL, 0);
    1742         newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
    1743                               bSelect, NULL);
     1564        newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, bSelect, NULL);
     1565
    17441566        while (!finished) {
    17451567            b_res = newtRunForm(myForm);
     
    17561578                    currline = i;
    17571579                    if (filelist->entries > 0) {
    1758                         severity_of_difference(filelist->el[currline].
    1759                                                filename, reason);
    1760                         sprintf(tmp, "%s --- %s",
    1761                                 filelist->el[currline].filename, reason);
     1580                        malloc_string(reason);
     1581                        severity_of_difference(filelist->el[currline].  filename, &reason);
     1582                        mr_asprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason);
     1583
    17621584                        popup_and_OK(tmp);
     1585                        mr_free(tmp);
     1586                        paranoid_free(reason);
    17631587                    }
    17641588                }
     
    17681592        newtPopWindow();
    17691593        newtPopHelpLine();
    1770       free_to_go:
    1771         paranoid_free(reason);
    1772         paranoid_free(tmp);
    1773         paranoid_free(differ_sz);
    17741594        return;
    17751595    }
  • branches/3.2/mondo/src/include/my-stuff.h

    r3138 r3191  
    7777 * The location where mindi media images are stored.
    7878 */
    79 #define MINDI_CACHE "/var/cache/mindi"
     79#define MINDI_CACHE_REL "var/cache/mindi"   /* Should be coherent with mindi */
     80#define MINDI_CACHE "/"MINDI_CACHE_REL
    8081
    8182/**
     
    8889 */
    8990#define MDSTAT_FILE "/proc/mdstat"
     91
     92#ifdef __FreeBSD__
     93#define CMDLINE "/tmp/cmdline"
     94#else
     95// Default Linux
     96#define CMDLINE "/proc/cmdline"
     97#endif
    9098
    9199#undef assert
  • branches/3.2/mondo/src/lib/mr_err.c

    r1422 r3191  
    1616#include <stdio.h>
    1717#include <stdlib.h>
     18#include "mr_msg.h"
    1819
    1920/* Pointer to the right cleanup function provided by each main */
    20 extern void (*mr_cleanup)(void);
     21extern void (*mr_cleanup)(int);
    2122
    2223/*
     
    2627
    2728    if (mr_cleanup != NULL) {
    28         mr_cleanup();
     29        mr_cleanup(errorcode);
    2930    }
    3031    if (message != NULL) {
    3132        fprintf(stderr,"%s\n",message);
    3233    }
     34    mr_msg_close();
    3335    exit(errorcode);
    3436}
Note: See TracChangeset for help on using the changeset viewer.