Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (18 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/mondo-restore.c

    r687 r688  
    11/***************************************************************************
    2        mondo-restore.c  -  restores mondoarchive data
    3                              -------------------
    4     begin                : Fri May 19 2000
    5     copyright            : (C) 2000 by Hugo Rabson
    6     email                : Hugo Rabson <hugorabson@msn.com>
    7     cvsid                : $Id$
    8 ***************************************************************************/
    9 
    10 /***************************************************************************
    11  *                                                                         *
    12  *   This program is free software; you can redistribute it and/or modify  *
    13  *   it under the terms of the GNU General Public License as published by  *
    14  *   the Free Software Foundation; either version 2 of the License, or     *
    15  *   (at your option) any later version.                                   *
    16  *                                                                         *
    17  ***************************************************************************/
    18 
    19 /***************************************************************************
    20  *                         Change Log                                      *
    21  ***************************************************************************
    22 .
    23 
    24 
    25 07/26
    26 - workaround - if not /dev then don't call partimagehack
    27 
    28 07/21
    29 - if switch to Interactive Mode during nuke then don't nuke twice :) just once
    30 
    31 07/18
    32 - better support of users who boot from LVM CD and nuke-restore non-LVM backups
    33 
    34 07/10
    35 - when using 'star', exclude all 'not removed.' messages from log (misleading, they are)
    36 - try w/ ACLs, then w/o ACLs if star fails w/ ACLs
    37 - added ACL, xattr support for afio
    38 
    39 06/26
    40 - remove make_relevant_partition_bootable(); roll into mondo-prep.c
    41 - changed various newtDrawRootText() calls to use g_noof_rows instead of
    42   integers
    43 
    44 06/19
    45 - don't try to access biggiestruct before it is populated w/ data relating
    46   to biggiefile; instead, use control char to find out if biggiefile is
    47   to be restored w/ partimagehack or not
    48 - added AUX_VER
    49 
    50 06/15
    51 - read_cfg_file_into_bkpinfo() --- use user-supplied 'isodir' instead of
    52   archive's 'isodir' if different
    53   Conor Daly <conor.daly@met.ie>
    54 
    55 06/17
    56 - restore with partimagehack if NTFS device; dd, if non-NTFS device
    57 
    58 06/14
    59 - unmount all; remount, run grub-mr; unmount again
    60 
    61 04/09
    62 - fixed subset restoration bug introduced when I added 'star' support
    63 
    64 04/04
    65 - cleaned up restore_a_tarball_from_stream()
    66 
    67 04/03
    68 - added star support
    69 - pause for 3s between partitioning and formatting (if in Nuke Mode)
    70 
    71 03/28
    72 - check that g_mountlist_fname was correcfly set; abort if it wasn't
    73 
    74 03/25
    75 - removed dev_null code
    76 
    77 03/22/04
    78 - added mode_of_file()
    79 - added code to check for unauthorised modification of /dev/null
    80   by afio (for instance)
    81 
    82 12/27/03
    83 - check /tmp/cmdline instead of /proc/cmdline if on FreeBSD
    84 
    85 11/15
    86 - added g_fprep
    87 - "Switch to interactive mode?" msg is now more informative
    88 
    89 11/05
    90 - after 'Are you sure?' when user specifies / as restore path, set
    91   restore_path[] to "" so that files are restored to [blank]/file/name :)
    92 
    93 10/29
    94 - moved "No restoring or comparing will take place today" block
    95   up to before iso_fiddly_bits (if iso) is called - fix bug
    96   if you're in ISO Mode and you say "exit to shell"
    97 
    98 10/22
    99 - swapped calls to chmod() and chown() after restoration
    100   of big files (Jens)
    101 
    102 10/21
    103 - changed "/mnt/cdrom" to MNT_CDROM
    104 
    105 10/19
    106 - restore biggiefiles selectively from CD properly
    107 - use find_my_editor() to find pico/vi/whatever
    108 - better use of call_program_and_get_last_line_of_output() to
    109   scan /proc/cmdline
    110 
    111 10/18
    112 - don't report 'missing compressor' if no compressor used at all
    113 
    114 10/14
    115 - log afio's error messages to /var/log/mondo-archive.log
    116   when restoring :)
    117 - call vi if pico is not available
    118 
    119 10/09
    120 - better logging if fatal error (cannot openout bigfile)
    121 - better GUI feedback when restoring big files
    122 - restore_everything() now uses s_node* instead of char*
    123 - ditto restore_all_*_from_*()
    124 
    125 10/02
    126 - succinct msg instead of pop-ups, if used -H
    127 
    128 09/27
    129 - tweaked restore-time gui
    130 
    131 09/26
    132 - proper reporting of DVD/CDR/etc. type in displayed dialogs
    133 
    134 09/23
    135 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
    136   and free_libmondo_global_strings() - which are in libmondo-tools.c
    137 
    138 09/21
    139 - trying to fix "mondorestore <no params>" segfault
    140 
    141 09/18
    142 - better remounting of /
    143 - cleaned up run_grub()
    144 - sensible command-line handling in Live Mode
    145 
    146 09/17
    147 - cleaned up GRUB installer script a bit
    148 
    149 09/15
    150 - remount / as r/w if in disaster recovery mode;
    151   helps for b0rken distros
    152 
    153 09/13
    154 - major NTFS hackage
    155 
    156 09/12
    157 - changed some in-sub var decl'ns to malloc()'s
    158 
    159 09/05
    160 - don't let me run unless I'm root
    161 - finished NTFS/partimagehack support (CD only); working on tape now
    162 
    163 09/01
    164 - fixed cosmetic bug in biggiefile restore window
    165 
    166 06/01 - 08/31
    167 - added code to main() to make sure NFS
    168   (backup) share is mounted in Nuke and Compare Modes
    169 - added code to run_grub() to mount /boot before running grub-install
    170 - fixed some stray assert()'s in restore_a_biggiefile_from_stream()
    171 - fixed bugs in extract_config_file_from_ramdisk()
    172   and get_cfg_file_from_archive() which
    173   stopped fape+floppy users from being able to
    174   boot from floppy and leave floppy in drive :)
    175 - added hooks to partimage for doing imagedevs
    176 - fixed calls to popup_and_get_string()
    177 
    178 05/01 - 05/31
    179 - fixed biggiefile atime/utime dates restoration bug, I think
    180 - added misc clean-up (Steve Hindle)
    181 - fixed support for subdir-within-NFS-mount
    182 - if nuke mode fails & user reverts to interactive mode _and succeeds_,
    183   don't claim nuke mode aborted :)
    184 - unmount_all_devices() uses mountlist->el[lino].mountpt
    185   instead of mountlist->el[lino].device where possible
    186 - added Joshua Oreman's FreeBSD patches
    187 - copied missing paragraph from 1.6x's read_cfg_file_into_bkpinfo()
    188   to 1.7x's; affected tape streamer users (badly!)
    189 - cleaned up some paranoid assert()'s
    190 - use which("post-nuke") instead of find_home_of_exe("post-nuke")
    191 - fixed "Don't eject while restoring" mode
    192 - get_cfg_file_from_archive() --- also recovers mountlist.txt now :)
    193 - don't eject if 'donteject' is in kernel's command line
    194 - added 'don't panic' msg to start of log
    195 
    196 04/01 - 04/30
    197 - added text mode (cat /proc/cmdline; if textonly then text mode is on)
    198 - delete /var/lock/subsys/ * when nuking
    199 - don't resize mountlist if "noresize" present in /proc/cmdline
    200 - changed from chmod -R 1777 tmp to chmod 1777 tmp
    201 - replace newtFinished() and newtInit() with
    202   newtSuspend() and newtResume()
    203 - get_cfg_file_from_archive() returns 1 instead of aborting now
    204 - read_cfg_file_into_bkpinfo) --- if autorun CD but its config
    205   file indicates a non-CD backup media then ask, just in case
    206 - sped up restore_a_tarball_from_CD() a bit
    207 - line 4469 --- if post-nuke not found then don't run it :)
    208 - replaced "/mnt/RESTORING" with MNT_RESTORING (#define'd)
    209 - moved compare_*() into mondorestore/mondo-rstr-compare.c
    210 - moved some RAID subroutines into common/libmondo-raid.c
    211 - fixed some iso live compare problems
    212 - replaced FILELIST_FULL with g_filelist_full and FILELIST_FULL_STUB;
    213   g_filelist_full being the full path of the filelist.full text file and
    214   FILELIST_FULL_STUB being "tmp/filelist.full" (relative path);
    215 - ditto BIGGIELIST_TXT, MONDO_CFG_FILE
    216 - added lots of assert()'s and log_OS_error()'s
    217 - in Nuke Mode, check mountlist's sanity before doing anything else;
    218   if it fails sanity test, offer to revert to Interactive Mode (or abort)
    219 - copy log to /mnt/RESTORING/root at end
    220 - read_cfg_file_into_bkpinfo() --- read iso-dev and isodir if bkptype==iso
    221 - line 1701 --- delete ramdisk file after extracting config info
    222 - moved call to make_relevant_partitions_bootable() from
    223   within run_boot_loader() to within interactive_mode() and
    224   nuke_mode(), after unmounting disks
    225 - if editing fstab or *.conf, try to use pico if available
    226 - better calling of make-me-bootable
    227 - don't sort mountlist anywhere anymore except _locally_ in
    228   mount_all_devices() and unmount_all_devices()
    229 - edit fstab, grub.conf _after_ stabgrub-me if it fails
    230 - run_boot_loader() --- backup all crucial files to /etc/ *.pristine first
    231 - added iso_fiddly_bits()
    232 - fixed ISO mode support
    233 - mount_cdrom() only searches for device if NOT in disaster recovery mode
    234 - changed lost of system()'s into run_program_and_log_output()'s
    235 - don't eject if bkpinfo->please_dont_eject_when_restoring
    236 - cleaned up post-nuke handling code
    237 - always eject CD at end, unless bkpinfo->please_dont_...
    238 - misc clean-up (Tom Mortell)
    239 - afio uses -c (1024L*1024L)/TAPE_BLOCK_SIZE now
    240   instead of -c 1024
    241 
    242 01/01 - 03/31/2003
    243 - commented out sort_... line (BB)
    244 - clean-up (Stan Benoit)
    245 - added code for LVM and SW Raid (Brian Borgeson)
    246 - line 814 - added -p to 'mkdir -p tmp'
    247 - mount_cdrom() - calls find_cdrom_device() if
    248   bkpinfo->media_device is blank (to fill it)
    249 
    250 11/01 - 12/31/2002
    251 - mount_cdrom() better at handling multiple CD drives
    252 - minor clean-up in restore_a_tarball_from_CD()
    253 - if --live-from-cd then assume restoring live from CD
    254 - tweaked it to run better w/ ArkLinux
    255 - create /mnt/RESTORING/mnt/.boot.d for Gentoo users
    256   after restoring
    257 - cleaned up iso_mode(); no longer asks for NFS info 3 times
    258 - mount_cdrom() was trying to mount /mnt/isodir/%s/%d.iso;
    259   is now just %s/%d.iso
    260 - mount/unmount /boot if necessary (Gentoo)
    261 - added RAW MBR support; added run_raw_mbr() for the purpose
    262 - unmount & remount supermounts at start/end of live restore
    263 - copy /tmp/mountlist.txt to /tmp/mountlist.txt.orig at start
    264 - cleaned up string-handling in get_cfg_info_from_archives()
    265 - fixed run_grub() to call new stabgrub-me script
    266 - popup list of changed files after Compare Mode
    267 - permit mondorestore --edit-mountlist even if live mode
    268 - create a repaired copy of grub-install which is RAID-friendly;
    269   use it when initializing boot sector with run_grub()
    270 - use grub-MR instead of grub-install
    271 - fixed read_cfg_file_into_bkpinfo() to ignore cfg file's backup_media_type
    272   if user has already specified a backup media type interactively
    273 
    274 10/01 - 10/31
    275 - run_grub() will let you specify the boot device as well as edit the system
    276   files, if grub-install fails
    277 - fixed bug in fwrite() call in restore_biggiefile_from_CD()
    278 - fixed bug affecting restoration of bigfiles from CD's w/0 compression
    279 - run_grub() will run 'grub-install {boot device}' instead of
    280   'grub-install (hd0)'
    281 
    282 09/01 - 09/30
    283 - use /tmp/tmpfs/mondo.tmp instead of /tmp/mondo.tmp
    284 - initialize MOUNTLIST_FNAME at start of main()
    285 - differential-related cleanup
    286 - better handling of CD-ROM drives which aren't /dev/cdrom :)
    287 - run_program_and_log_output() now takes boolean operator to specify
    288   whether it will log its activities in the event of _success_
    289 - always load config file from archive before operating on it
    290 - moved some subroutines around; now closer to alphabetical order
    291 - changed mount.mindi to mount.bootisk
    292 - mount disks readonly if in Compare Mode
    293 - set /dev/null's permissions to 777, just in case it somehow gets mangled
    294   ...which apparently happen with some devfs-based Linux distributions
    295 - remove /var/run/ *.pid after restoring
    296 - move spurious lockfiles from /home/ * to /home/ * /.disabled
    297 - if Interactive Mode then ask user which media, etc. (i.e. catchall mode
    298   is now same as Interactive Mode)
    299 
    300 08/01 - 08/30
    301 - use data structure to store the fname, checksum, mods & perms of each bigfile
    302   ... biggiestruct :)
    303 - if a filelist is tiny (2 bytes or less) then ignore it
    304 - insist_on_this_cd_number() --- now takes 2 params, not 1
    305 - re-enabled 'g_current_media_number = 1' in restore_everything()
    306 - added same to compare_mode()
    307 - replaced lots of global char[]'s with malloc()'s
    308 - if differential backup then don't permit formatting or fdisking,
    309   whether Interactive or Nuke mode
    310 - added call to register_pid() at start of main()
    311 - if Nuke Mode & it succeeds then ask user if they have contributed yet
    312 - changed tape-size to media-size (config file)
    313 - changed using_* to backup_media_type
    314 - changed *_from_tape to *_from_stream
    315 
    316 07/01 - 07/31
    317 - added find_and_mount_actual_cdrom()
    318 - temp dir is always random
    319 - skip tarballs if they don't contain files we're looking for
    320   (used to read the whole thing & _then_ skip)
    321 - use media_size[1] instead of media_size[0]
    322 - fixed serious bug in line 1546 - should have been !=, not ==; stopped
    323   mondorestore from correctly restoring big files
    324 - bigfile piping enhancements (Philippe de Muyter)
    325 - unmount CD-ROM after restoring from live filesystem
    326 - TAPE_BLOCK_SIZE treated as %ld, not %d
    327 
    328 06/01 - 06/30
    329 - added signal-trapping
    330 - disabled 'nr-failed-disks' flag
    331 - fixed problem w/selective restore
    332 - don't change /tmp's permissions unless it doesn't exist & must be created
    333 - fixed bug in --mbr
    334 - is_file_in_list() enhanced to exclude /mnt/RESTORING or whatever
    335 - added support for uncompressed archives
    336 - --monitas-live now accepts path-to-restore_to_, not just path to restore
    337 - added some debugging/tracking code to the NFS section
    338 - various monitas-related enhancements
    339 - added --isonuke and --mbr switches
    340 - better logging in run_grub()
    341 - improved --monitas-live
    342 - mkdir -p /mnt/RESTORING/var/run/console just in case user excludes it
    343 - afio now uses 16MB buffer instead of 8MB
    344 - always use bkpinfo->media_size[0], now that -s has been expanded
    345 - popup and ask where to restore data, if restoring selectively
    346 
    347 05/01 - 05/31
    348 - add '--monitas' flag
    349 - don't run chmod -R 1777 /mnt/RESTORING/tmp before unmounting unless
    350   restoring at the time...
    351 
    352 04/01 - 04/30
    353 - delete old /tmp/filelist.full,biggielist.txt if found when restoring to
    354   live filesystem
    355 - replace MONDO_VERSION #define with VERSION from ../config.h
    356 - write fname of bigfile to screen when having trouble reading/comparing it
    357 - if restoring to live filesystem then wipe /tmp/tmpfs/ * afterwards
    358 - removed spurious finish(0) from main()
    359 
    360 03/01 - 03/31/2002
    361 - if /tmp/m*ndo-restore.cfg not found then assume live restore; restore
    362   to / instead of /mnt/RESTORING
    363 - clean up is_file_in_list() to deal with the /mnt/RESTORING/ prefix
    364 - exclude leading '/' from filelist.restore-these
    365 - if /tmp/fstab.new exists then use _it_ instead of /tmp/fstab to label
    366   ext2 or ext3 partitions
    367 - improved logging
    368 
    369 [...]
    370 
    371 07/10/2001 --- first incarnation
    372 */
    373 
     2 * $Id$
     3 */
    3744
    3755/**
     
    38111 * #include statements                                                    *
    38212 **************************************************************************/
     13#include <unistd.h>
     14
    38315#include "../common/my-stuff.h"
    38416#include "../common/mondostructures.h"
     
    44375 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
    44476 */
    445 char *g_isodir_device;
     77char *g_isodir_device = NULL;
    44678
    44779/**
    44880 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
    44981 */
    450 char *g_isodir_format;
     82char *g_isodir_format = NULL;
    45183
    45284/**
    45385 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
    45486 */
    455 char *g_biggielist_txt;
     87char *g_biggielist_txt = NULL;
    45688
    45789/**
     
    45991 * the current archive set.
    46092 */
    461 char *g_filelist_full;
     93char *g_filelist_full = NULL;
    46294
    46395/**
     
    46597 * as images, not as individual files.
    46698 */
    467 char *g_filelist_imagedevs;
     99char *g_filelist_imagedevs = NULL;
    468100
    469101/**
     
    471103 * @see g_filelist_imagedevs
    472104 */
    473 char *g_imagedevs_restthese;
     105char *g_imagedevs_restthese = NULL;
    474106
    475107/**
     
    477109 * information for this backup.
    478110 */
    479 char *g_mondo_cfg_file;
     111char *g_mondo_cfg_file = NULL;
    480112
    481113/**
     
    483115 * user's partitions and hard drives.
    484116 */
    485 char *g_mountlist_fname;
     117char *g_mountlist_fname = NULL;
    486118
    487119/**
     
    489121 * to avoid link errors.
    490122 */
    491 char *g_mondo_home;
     123char *g_mondo_home = NULL;
    492124
    493125/* @} - end of "Restore-Time Globals" in globalGroup */
    494 
    495 
    496126
    497127extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
    498128                                 char direction);
    499 
    500 
    501129
    502130/**************************************************************************
     
    508136 */
    509137#define COMPAQ_PROLIANTS_SUCK _("Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo CD/floppy in Interactive Mode.")
    510 
    511 
    512138
    513139
     
    561187
    562188
    563 
    564 
    565 
    566189/**
    567190 * Determine whether @p mountlist contains a Compaq diagnostic partition.
     
    604227    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
    605228    if (ask_me_yes_or_no
    606         (_("Would you like to reboot and use your Compaq CD to prep your hard drive?")))
     229        (_
     230         ("Would you like to reboot and use your Compaq CD to prep your hard drive?")))
    607231    {
    608         fatal_error
    609             (_("Aborting. Please reboot and prep your hard drive with your Compaq CD."));
     232        fatal_error(_
     233                    ("Aborting. Please reboot and prep your hard drive with your Compaq CD."));
    610234    }
    611235}
     
    614238 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
    615239 **************************************************************************/
    616 
    617240
    618241
     
    637260    assert(mountlist != NULL);
    638261    assert(raidlist != NULL);
    639     malloc_string(tmp);
    640262    iamhere("pre wrm");
    641263    c = which_restore_mode();
     
    644266        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    645267    } else {
    646         popup_and_OK(_("No restoring or comparing will take place today."));
     268        popup_and_OK(_
     269                     ("No restoring or comparing will take place today."));
    647270        if (is_this_device_mounted("/mnt/cdrom")) {
    648271            run_program_and_log_output("umount /mnt/cdrom", FALSE);
    649272        }
    650273        if (g_ISO_restore_mode) {
    651             sprintf(tmp, "umount %s", bkpinfo->isodir);
     274            asprintf(&tmp, "umount %s", bkpinfo->isodir);
    652275            run_program_and_log_output(tmp, FALSE);
     276            paranoid_free(tmp);
    653277        }
    654278        paranoid_MR_finish(0);
     
    677301        retval += compare_mode(bkpinfo, mountlist, raidlist);
    678302    }
    679     paranoid_free(tmp);
    680303    return (retval);
    681304}
     
    726349
    727350
    728 
    729 
    730351/**
    731352 * @addtogroup restoreGroup
     
    754375    bool restore_all;
    755376
    756   /** needs malloc **********/
    757     char *tmp;
    758     char *fstab_fname;
    759     char *old_restpath;
    760 
    761     struct s_node *filelist;
     377    char *tmp = NULL;
     378    char *tmp1 = NULL;
     379    char *fstab_fname = NULL;
     380    char *old_restpath = NULL;
     381
     382    struct s_node *filelist = NULL;
    762383
    763384    /* try to partition and format */
     
    765386    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
    766387
    767     malloc_string(tmp);
    768     malloc_string(fstab_fname);
    769     malloc_string(old_restpath);
    770388    assert(bkpinfo != NULL);
    771389    assert(mountlist != NULL);
     
    776394    if (g_text_mode) {
    777395        if (!ask_me_yes_or_no
    778             (_("Interactive Mode + textonly = experimental! Proceed anyway?")))
     396            (_
     397             ("Interactive Mode + textonly = experimental! Proceed anyway?")))
    779398        {
    780399            fatal_error("Wise move.");
     
    787406    iamhere("Done loading config file; resizing ML");
    788407#ifdef __FreeBSD__
    789     if (strstr
    790         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    791          "noresize"))
     408    tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
    792409#else
    793     if (strstr
    794         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    795          "noresize"))
     410    tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
    796411#endif
    797     {
     412    if (strstr(tmp,"noresize")) {
    798413        log_msg(1, "Not resizing mountlist.");
    799414    } else {
     
    804419        if (g_text_mode) {
    805420            save_mountlist_to_disk(mountlist, g_mountlist_fname);
    806             sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
     421            tmp1 = find_my_editor();
     422            asprintf(&tmp, "%s %s", tmp1, g_mountlist_fname);
     423            paranoid_free(tmp1);
     424
    807425            res = system(tmp);
     426            paranoid_free(tmp);
    808427            load_mountlist(mountlist, g_mountlist_fname);
    809428        } else {
     
    819438        mvaddstr_and_log_it(1, 30, _("Restoring Interactively"));
    820439        if (bkpinfo->differential) {
    821             log_to_screen(_("Because this is a differential backup, disk"));
    822             log_to_screen
    823                 (_(" partitioning and formatting will not take place."));
     440            log_to_screen(_
     441                          ("Because this is a differential backup, disk"));
     442            log_to_screen(_
     443                          (" partitioning and formatting will not take place."));
    824444            done = TRUE;
    825445        } else {
    826446            if (ask_me_yes_or_no
    827                 (_("Do you want to erase and partition your hard drives?"))) {
     447                (_
     448                 ("Do you want to erase and partition your hard drives?")))
     449            {
    828450                if (partition_table_contains_Compaq_diagnostic_partition
    829451                    (mountlist)) {
     
    836458                    if (ptn_errs) {
    837459                        log_to_screen
    838                             (_("Warning. Errors occurred during disk partitioning."));
     460                            (_
     461                             ("Warning. Errors occurred during disk partitioning."));
    839462                    }
    840463
    841                     fmt_errs = format_everything(mountlist, FALSE, raidlist);
     464                    fmt_errs =
     465                        format_everything(mountlist, FALSE, raidlist);
    842466                    if (!fmt_errs) {
    843467                        log_to_screen
    844                             (_("Errors during disk partitioning were handled OK."));
    845                         log_to_screen
    846                             (_("Partitions were formatted OK despite those errors."));
     468                            (_
     469                             ("Errors during disk partitioning were handled OK."));
     470                        log_to_screen(_
     471                                      ("Partitions were formatted OK despite those errors."));
    847472                        ptn_errs = 0;
    848473                    }
     
    854479            } else {
    855480                mvaddstr_and_log_it(g_currentY++, 0,
    856                                     _("User opted not to partition the devices"));
     481                                    _
     482                                    ("User opted not to partition the devices"));
    857483                if (ask_me_yes_or_no
    858484                    (_("Do you want to format your hard drives?"))) {
    859                     fmt_errs = format_everything(mountlist, TRUE, raidlist);
     485                    fmt_errs =
     486                        format_everything(mountlist, TRUE, raidlist);
    860487                    if (!fmt_errs) {
    861488                        done = TRUE;
     
    869496                mvaddstr_and_log_it(g_currentY++,
    870497                                    0,
    871                                     _("Errors occurred. Please repartition and format drives manually."));
     498                                    _
     499                                    ("Errors occurred. Please repartition and format drives manually."));
    872500                done = FALSE;
    873501            }
     
    875503                mvaddstr_and_log_it(g_currentY++,
    876504                                    0,
    877                                     _("Errors occurred during partitioning. Formatting, however, went OK."));
     505                                    _
     506                                    ("Errors occurred during partitioning. Formatting, however, went OK."));
    878507                done = TRUE;
    879508            }
     
    881510                if (!ask_me_yes_or_no(_("Re-edit the mountlist?"))) {
    882511                    retval++;
    883                     goto end_of_func;
     512                    iamhere("Leaving interactive_mode()");
     513                    return (retval);
    884514                }
    885515            }
     
    891521        unmount_all_devices(mountlist);
    892522        retval++;
    893         goto end_of_func;
     523        iamhere("Leaving interactive_mode()");
     524        return (retval);
    894525    }
    895526    /* restore */
    896527    if ((restore_all =
    897          ask_me_yes_or_no(_("Do you want me to restore all of your data?"))))
     528         ask_me_yes_or_no(_
     529                          ("Do you want me to restore all of your data?"))))
    898530    {
    899531        log_msg(1, "Restoring all data");
    900532        retval += restore_everything(bkpinfo, NULL);
    901     } else
    902         if ((restore_all =
     533    } else if ((restore_all =
    903534             ask_me_yes_or_no
    904535             (_("Do you want me to restore _some_ of your data?")))) {
    905         strcpy(old_restpath, bkpinfo->restore_path);
     536        old_restpath = bkpinfo->restore_path;
    906537        for (done = FALSE; !done;) {
    907538            unlink("/tmp/filelist.full");
     
    912543            if (filelist) {
    913544              gotos_suck:
    914                 strcpy(tmp, old_restpath);
    915545// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
    916546                if (popup_and_get_string
    917                     (_("Restore path"), _("Restore files to where?"), tmp,
    918                      MAX_STR_LEN / 4)) {
    919                     if (!strcmp(tmp, "/")) {
     547                    (_("Restore path"), _("Restore files to where?"), bkpinfo->restore_path)) {
     548                    if (!strcmp(bkpinfo->restore_path, "/")) {
    920549                        if (!ask_me_yes_or_no(_("Are you sure?"))) {
     550                            paranoid_free(bkpinfo->restore_path);
     551                            bkpinfo->restore_path = old_restpath;
    921552                            goto gotos_suck;
    922553                        }
    923                         tmp[0] = '\0';  // so we restore to [blank]/file/name :)
     554                        paranoid_alloc(bkpinfo->restore_path, "");  // so we restore to [blank]/file/name :)
    924555                    }
    925                     strcpy(bkpinfo->restore_path, tmp);
    926556                    log_msg(1, "Restoring subset");
    927557                    retval += restore_everything(bkpinfo, filelist);
    928558                    free_filelist(filelist);
    929559                } else {
    930                     strcpy(bkpinfo->restore_path, old_restpath);
     560                    bkpinfo->restore_path = old_restpath;
    931561                    free_filelist(filelist);
    932562                }
     
    939569            }
    940570        }
    941         strcpy(old_restpath, bkpinfo->restore_path);
    942571    } else {
    943572        mvaddstr_and_log_it(g_currentY++,
    944573                            0,
    945                             _("User opted not to restore any data.                                  "));
     574                            _
     575                            ("User opted not to restore any data.                                  "));
    946576    }
    947577    if (retval) {
    948578        mvaddstr_and_log_it(g_currentY++,
    949579                            0,
    950                             _("Errors occurred during the restore phase.            "));
     580                            _
     581                            ("Errors occurred during the restore phase.            "));
    951582    }
    952583
     
    956587        mvaddstr_and_log_it(g_currentY++,
    957588                            0,
    958                             _("User opted not to initialize the boot loader."));
     589                            _
     590                            ("User opted not to initialize the boot loader."));
    959591    }
    960592
    961593//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    962594    protect_against_braindead_sysadmins();
    963     //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    964595    retval += unmount_all_devices(mountlist);
    965596    /*  if (restore_some || restore_all || */
     
    967598        (_("Label your ext2 and ext3 partitions if necessary?"))) {
    968599        mvaddstr_and_log_it(g_currentY, 0,
    969                             _("Using e2label to label your ext2,3 partitions"));
     600                            _
     601                            ("Using e2label to label your ext2,3 partitions"));
    970602        if (does_file_exist("/tmp/fstab.new")) {
    971             strcpy(fstab_fname, "/tmp/fstab.new");
     603            asprintf(&fstab_fname, "/tmp/fstab.new");
    972604        } else {
    973             strcpy(fstab_fname, "/tmp/fstab");
    974         }
    975         sprintf(tmp,
     605            asprintf(&fstab_fname, "/tmp/fstab");
     606        }
     607        asprintf(&tmp,
    976608                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
    977609                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
    978610                MONDO_LOGFILE);
     611        paranoid_free(fstab_fname);
     612
    979613        res = system(tmp);
     614        paranoid_free(tmp);
    980615        if (res) {
    981616            log_to_screen
     
    992627        mvaddstr_and_log_it(g_currentY++,
    993628                            0,
    994                             _("Warning - errors occurred during the restore phase."));
    995     }
    996   end_of_func:
    997     paranoid_free(tmp);
    998     paranoid_free(fstab_fname);
    999     paranoid_free(old_restpath);
    1000     iamhere("Leaving interactive_mode()");
    1001     return (retval);
     629                            _
     630                            ("Warning - errors occurred during the restore phase."));
     631    }
    1002632}
    1003633
     
    1005635 *END_INTERACTIVE_MODE                                                    *
    1006636 **************************************************************************/
    1007 
    1008637
    1009638
     
    1054683    if (system("umount /tmp/isodir 2> /dev/null")) {
    1055684        log_to_screen
    1056             (_("WARNING - unable to unmount device where the ISO files are stored."));
     685            (_
     686             ("WARNING - unable to unmount device where the ISO files are stored."));
    1057687    }
    1058688//    }
     
    1065695
    1066696
    1067 /*            MONDO - saving your a$$ since Feb 18th, 2000            */
    1068 
    1069 
     697static void call_me_after_the_nuke(int retval) {
     698
     699    char *tmp = NULL;
     700    char *tmp1 = NULL;
     701
     702    if (retval) {
     703        log_to_screen(_("Errors occurred during the nuke phase."));
     704        log_to_screen(_("Please visit our website at http://www.mondorescue.org for more information."));
     705    } else {
     706#ifdef __FreeBSD__
     707        tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
     708#else
     709        tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline");
     710#endif
     711        if ((strstr(tmp1,"restore") == NULL) ||
     712            (strstr(tmp1,"RESTORE") == NULL)) {
     713                /* -H option */
     714                asprintf(&tmp,
     715                    _
     716                    (" Mondo has restored your system. Please remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information."));
     717                popup_and_OK(tmp);
     718                paranoid_free(tmp);
     719        }
     720        paranoid_free(tmp1);
     721
     722        log_to_screen(_
     723             ("Mondo has restored your system. Please remove the backup media and reboot."));
     724        log_to_screen(_
     725             ("Thank you for using Mondo Rescue."));
     726        log_to_screen(_
     727             ("Please visit our website at http://www.mondorescue.org for more information."));
     728    }
     729    g_I_have_just_nuked = TRUE;
     730    return;
     731}
    1070732
    1071733
     
    1087749    int res = 0;
    1088750    bool boot_loader_installed = FALSE;
    1089   /** malloc **/
    1090     char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
    1091         tmpC[MAX_STR_LEN];
     751    char *tmp = NULL;
     752    char tmpA[MAX_STR_LEN];
     753    char tmpB[MAX_STR_LEN];
     754    char tmpC[MAX_STR_LEN];
    1092755
    1093756    assert(bkpinfo != NULL);
     
    1100763    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
    1101764#ifdef __FreeBSD__
    1102     if (strstr
    1103         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    1104          "noresize"))
     765    tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
    1105766#else
    1106     if (strstr
    1107         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    1108          "noresize"))
     767    tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
    1109768#endif
    1110     {
     769    if (strstr(tmp,"noresize")) {
    1111770        log_msg(2, "Not resizing mountlist.");
    1112771    } else {
    1113772        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
    1114773    }
     774    paranoid_free(tmp);
     775
    1115776    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
    1116         sprintf(tmp,
    1117                 _("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"),
     777        asprintf(&tmp,
     778                _
     779                ("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"),
    1118780                tmpA, tmpB, tmpC);
    1119781        if (ask_me_yes_or_no(tmp)) {
     782            paranoid_free(tmp);
    1120783            retval = interactive_mode(bkpinfo, mountlist, raidlist);
    1121784            finish(retval);
    1122785        } else {
     786            paranoid_free(tmp);
    1123787            fatal_error("Nuke Mode aborted. ");
    1124788        }
     
    1128792    if (bkpinfo->differential) {
    1129793        log_to_screen(_("Because this is a differential backup, disk"));
    1130         log_to_screen(_("partitioning and formatting will not take place."));
     794        log_to_screen(_
     795                      ("partitioning and formatting will not take place."));
    1131796        res = 0;
    1132797    } else {
     
    1138803            g_fprep = fopen("/tmp/prep.sh", "w");
    1139804#ifdef __FreeBSD__
    1140             if (strstr
    1141                 (call_program_and_get_last_line_of_output
    1142                  ("cat /tmp/cmdline"), "nopart"))
     805            tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
    1143806#else
    1144             if (strstr
    1145                 (call_program_and_get_last_line_of_output
    1146                  ("cat /proc/cmdline"), "nopart"))
     807            tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
    1147808#endif
    1148             {
     809            if (strstr(tmp,,"nopart")) {
    1149810                log_msg(2,
    1150811                        "Not partitioning drives due to 'nopart' option.");
     
    1154815                if (res) {
    1155816                    log_to_screen
    1156                         (_("Warning. Errors occurred during partitioning."));
     817                        (_
     818                         ("Warning. Errors occurred during partitioning."));
    1157819                    res = 0;
    1158820                }
    1159821            }
     822            paranoid_free(tmp);
     823
    1160824            retval += res;
    1161825            if (!res) {
    1162826                log_to_screen(_("Preparing to format your disk(s)"));
    1163827                sleep(1);
    1164                 system("sync");
    1165                 log_to_screen(_("Please wait. This may take a few minutes."));
     828                sync();
     829                log_to_screen(_
     830                              ("Please wait. This may take a few minutes."));
    1166831                res += format_everything(mountlist, FALSE, raidlist);
    1167832            }
     
    1173838        mvaddstr_and_log_it(g_currentY++,
    1174839                            0,
    1175                             _("Failed to partition and/or format your hard drives."));
     840                            _
     841                            ("Failed to partition and/or format your hard drives."));
    1176842
    1177843        if (ask_me_yes_or_no(_("Try in interactive mode instead?"))) {
    1178844            retval = interactive_mode(bkpinfo, mountlist, raidlist);
    1179             goto after_the_nuke;
     845            call_me_after_the_nuke(retval);
    1180846        } else
    1181847            if (!ask_me_yes_or_no
    1182848                (_("Would you like to try to proceed anyway?"))) {
    1183             return (retval);
    1184         }
     849        }
     850        return(retval);
    1185851    }
    1186852    retval = mount_all_devices(mountlist, TRUE);
     
    1188854        unmount_all_devices(mountlist);
    1189855        log_to_screen
    1190             (_("Unable to mount all partitions. Sorry, I cannot proceed."));
     856            (_
     857             ("Unable to mount all partitions. Sorry, I cannot proceed."));
    1191858        return (retval);
    1192859    }
     
    1200867    protect_against_braindead_sysadmins();
    1201868//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
    1202     //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
    1203869    retval += unmount_all_devices(mountlist);
    1204870    mvaddstr_and_log_it(g_currentY,
    1205871                        0,
    1206                         _("Using e2label to label your ext2,3 partitions"));
    1207 
    1208     sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
     872                        _
     873                        ("Using e2label to label your ext2,3 partitions"));
     874
     875    asprintf(&tmp, "label-partitions-as-necessary %s < /tmp/fstab",
    1209876            g_mountlist_fname);
    1210877    res = run_program_and_log_output(tmp, TRUE);
     878    paranoid_free(tmp);
     879
    1211880    if (res) {
    1212         log_to_screen(_("label-partitions-as-necessary returned an error"));
     881        log_to_screen(_
     882                      ("label-partitions-as-necessary returned an error"));
    1213883        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    1214884    } else {
     
    1216886    }
    1217887    retval += res;
    1218 
    1219   after_the_nuke:
    1220     if (retval) {
    1221         log_to_screen(_("Errors occurred during the nuke phase."));
    1222     } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
    1223     {
    1224         log_to_screen
    1225             (_("PC was restored successfully. Thank you for using Mondo Rescue."));
    1226         log_to_screen
    1227             (_("Please visit our website at http://www.mondorescue.org for more information."));
    1228     } else {
    1229         strcpy(tmp,_(" Mondo has restored your system. Please remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information."));
    1230         if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) {
    1231             popup_and_OK(tmp);
    1232         }
    1233         log_to_screen
    1234             (_("Mondo has restored your system. Please remove the backup media and reboot."));
    1235         log_to_screen
    1236             (_("Please visit our website at http://www.mondorescue.org for more information."));
    1237     }
    1238     g_I_have_just_nuked = TRUE;
    1239 /*
    1240   if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
    1241     {
    1242       log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR");
    1243       write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr");
    1244     }
    1245 */
    1246     return (retval);
     888    call_me_after_the_nuke(retval);
     889    return(retval);
    1247890}
    1248 
    1249891/**************************************************************************
    1250892 *END_NUKE_MODE                                                           *
    1251893 **************************************************************************/
    1252 
    1253894
    1254895
     
    1263904    int retval = 0;
    1264905
    1265   /** malloc **/
    1266     char *old_restpath;
    1267 
    1268     struct mountlist_itself *mountlist;
    1269 //  static
    1270     struct raidlist_itself *raidlist;
    1271     struct s_node *filelist;
     906    char *old_restpath = NULL;
     907
     908    struct mountlist_itself *mountlist = NULL;
     909    struct raidlist_itself *raidlist = NULL;
     910    struct s_node *filelist = NULL;
    1272911
    1273912    log_msg(1, "restore_to_live_filesystem() - starting");
    1274913    assert(bkpinfo != NULL);
    1275     malloc_string(old_restpath);
     914
    1276915    mountlist = malloc(sizeof(struct mountlist_itself));
    1277916    raidlist = malloc(sizeof(struct raidlist_itself));
     917
    1278918    if (!mountlist || !raidlist) {
    1279919        fatal_error("Cannot malloc() mountlist and/or raidlist");
    1280920    }
    1281921
    1282     strcpy(bkpinfo->restore_path, "/");
     922    paranoid_alloc(bkpinfo->restore_path, "/");
    1283923    if (!g_restoring_live_from_cd) {
    1284924        popup_and_OK
    1285             (_("Please insert tape/CD/boot floppy, then hit 'OK' to continue."));
     925            (_
     926             ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."));
    1286927        sleep(1);
    1287928    }
     
    1308949    if (filelist) {
    1309950        save_filelist(filelist, "/tmp/selected-files.txt");
    1310         strcpy(old_restpath, bkpinfo->restore_path);
     951        old_restpath = bkpinfo->restore_path;
    1311952        if (popup_and_get_string(_("Restore path"),
    1312953                                 _("Restore files to where? )"),
    1313                                  bkpinfo->restore_path, MAX_STR_LEN / 4)) {
     954                                 bkpinfo->restore_path)) {
    1314955            iamhere("Restoring everything");
    1315956            retval += restore_everything(bkpinfo, filelist);
    1316             free_filelist(filelist);
    1317             strcpy(bkpinfo->restore_path, old_restpath);
    1318         } else {
    1319             free_filelist(filelist);
    1320         }
    1321         strcpy(bkpinfo->restore_path, old_restpath);
     957        }
     958        free_filelist(filelist);
     959        bkpinfo->restore_path = old_restpath;
    1322960    }
    1323961    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    1329967        eject_device(bkpinfo->media_device);
    1330968    }
    1331     paranoid_free(old_restpath);
    1332969    free(mountlist);
    1333970    free(raidlist);
     
    1358995 * @return 0 for success (or skip), nonzero for failure.
    1359996 */
    1360 int
     997char *
    1361998restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
    1362999                             long bigfileno,
    1363                              struct s_node *filelist,
    1364                              char *pathname_of_last_file_restored)
     1000                             struct s_node *filelist)
    13651001{
    1366     FILE *fin;
    1367     FILE *fout;
    1368     FILE *fbzip2;
    1369 
    1370   /** malloc ***/
    1371     char *checksum, *outfile_fname, *tmp, *bzip2_command,
    1372         *ntfsprog_command, *suffix, *sz_devfile;
    1373     char *bigblk;
    1374     char *p;
     1002    FILE *fin = NULL;
     1003    FILE *fout = NULL;
     1004    FILE *fbzip2 = NULL;
     1005    char *checksum = NULL;
     1006    char *outfile_fname = NULL;
     1007    char *tmp = NULL;
     1008    char *tmp1 = NULL;
     1009    char *tmp2 = NULL;
     1010    char *tmp3 = NULL;
     1011    char *bzip2_command = NULL;
     1012    char *bigblk = NULL;
     1013    char *pathname_of_last_file_restored = NULL;
    13751014    int retval = 0;
    13761015    int finished = FALSE;
    13771016    long sliceno;
    13781017    long siz;
    1379     char ntfsprog_fifo[MAX_STR_LEN];
     1018    long siz1;
     1019    char *ntfsprog_fifo = NULL;
    13801020    char *file_to_openout = NULL;
    13811021    struct s_filename_and_lstat_info biggiestruct;
    1382     struct utimbuf the_utime_buf, *ubuf;
     1022    struct utimbuf the_utime_buf, *ubuf = NULL;
    13831023    bool use_ntfsprog_hack = FALSE;
    13841024    pid_t pid;
    13851025    int res = 0;
    13861026    int old_loglevel;
    1387     char sz_msg[MAX_STR_LEN];
    1388     struct s_node *node;
     1027    char *sz_msg;
     1028    struct s_node *node = NULL;
    13891029
    13901030    old_loglevel = g_loglevel;
     
    13921032    assert(bkpinfo != NULL);
    13931033
    1394     malloc_string(checksum);
    1395     malloc_string(outfile_fname);
    1396     malloc_string(tmp);
    1397     malloc_string(bzip2_command);
    1398     malloc_string(ntfsprog_command);
    1399     malloc_string(suffix);
    1400     malloc_string(sz_devfile);
    1401 
    1402     pathname_of_last_file_restored[0] = '\0';
    14031034    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
    14041035        fatal_error("Cannot malloc bigblk");
    14051036    }
    14061037
    1407     if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
     1038    tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, "");
     1039    if (!(fin = fopen(tmp,"r"))) {
    14081040        log_to_screen(_("Cannot even open bigfile's info file"));
    1409         return (1);
    1410     }
     1041        paranoid_free(tmp);
     1042        return (pathname_of_last_file_restored);
     1043    }
     1044    paranoid_free(tmp);
    14111045
    14121046    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
     
    14181052    paranoid_fclose(fin);
    14191053
    1420     strcpy(checksum, biggiestruct.checksum);
     1054    asprintf(&checksum, biggiestruct.checksum);
    14211055
    14221056    if (!checksum[0]) {
    1423         sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
     1057        asprintf(&tmp, "Warning - bigfile %ld does not have a checksum",
    14241058                bigfileno + 1);
    14251059        log_msg(3, tmp);
     1060        paranoid_free(tmp);
     1061        /* BERLIOS : Useless ???
    14261062        p = checksum;
    1427     }
     1063        */
     1064    }
     1065    paranoid_free(checksum);
    14281066
    14291067    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
    14301068    {
    1431         strcpy(outfile_fname, biggiestruct.filename);
     1069        asprintf(&outfile_fname, biggiestruct.filename);
    14321070    } else {
    1433         sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1071        asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
    14341072                biggiestruct.filename);
    14351073    }
     
    14411079            log_msg(0, "Skipping %s (name isn't in filelist)",
    14421080                    biggiestruct.filename);
    1443             pathname_of_last_file_restored[0] = '\0';
    1444             return (0);
     1081            return (pathname_of_last_file_restored);
    14451082        } else if (!(node->selected)) {
    14461083            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    14471084                    biggiestruct.filename);
    1448             pathname_of_last_file_restored[0] = '\0';
    1449             return (0);
     1085            return (pathname_of_last_file_restored);
    14501086        }
    14511087    }
     
    14701106                "Calling ntfsclone in background because %s is an NTFS /dev entry",
    14711107                outfile_fname);
    1472         sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1108        asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768),
    14731109                (int) (random() % 32768));
    1474         mkfifo(sz_devfile, 0x770);
    1475         strcpy(ntfsprog_fifo, sz_devfile);
     1110        mkfifo(ntfsprog_fifo, 0x770);
     1111
    14761112        file_to_openout = ntfsprog_fifo;
    14771113        switch (pid = fork()) {
     
    14841120            res =
    14851121                feed_outfrom_ntfsprog(biggiestruct.filename,
    1486                                        ntfsprog_fifo);
     1122                                      ntfsprog_fifo);
    14871123//          log_msg(3, "CHILD - fip - exiting");
    14881124            exit(res);
     
    14931129                    (long int) (pid));
    14941130        }
     1131        // BERLIOS: Is it the right place ??
     1132        paranoid_free(ntfsprog_fifo);
    14951133    } else {
    14961134        use_ntfsprog_hack = FALSE;
    1497         ntfsprog_fifo[0] = '\0';
    14981135        file_to_openout = outfile_fname;
    14991136        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15031140    }
    15041141
    1505     sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
     1142    asprintf(&tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
    15061143            outfile_fname);
    15071144    log_msg(2, tmp);
     1145    paranoid_free(tmp);
    15081146
    15091147    /*
     
    15131151     */
    15141152
    1515     strncpy(pathname_of_last_file_restored, biggiestruct.filename,
    1516             MAX_STR_LEN - 1);
    1517     pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1153    asprintf(&pathname_of_last_file_restored, biggiestruct.filename);
    15181154
    15191155    log_msg(3, "file_to_openout = %s", file_to_openout);
    15201156    if (!(fout = fopen(file_to_openout, "w"))) {
    15211157        log_to_screen(_("Cannot openout outfile_fname - hard disk full?"));
    1522         return (1);
     1158        return (pathname_of_last_file_restored);
    15231159    }
    15241160    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself
    15251161
    15261162    for (sliceno = 1, finished = FALSE; !finished;) {
    1527         if (!does_file_exist
    1528             (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
    1529             &&
    1530             !does_file_exist(slice_fname
    1531                              (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
    1532             &&
    1533             !does_file_exist(slice_fname
    1534                              (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1163        tmp = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "");
     1164        tmp1 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo");
     1165        tmp2 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2");
     1166        if (!does_file_exist(tmp) && !does_file_exist(tmp1) &&
     1167            !does_file_exist(tmp2)) {
    15351168            log_msg(3,
    15361169                    "Cannot find a data slice or terminator slice on CD %d",
    15371170                    g_current_media_number);
    15381171            g_current_media_number++;
    1539             sprintf(tmp,
     1172            asprintf(&tmp3,
    15401173                    "Asking for %s #%d so that I may read slice #%ld\n",
    15411174                    media_descriptor_string(bkpinfo->backup_media_type),
    15421175                    g_current_media_number, sliceno);
    1543             log_msg(2, tmp);
    1544             sprintf(tmp, _("Restoring from %s #%d"),
     1176            log_msg(2, tmp3);
     1177            paranoid_free(tmp3);
     1178
     1179            asprintf(&tmp3, _("Restoring from %s #%d"),
    15451180                    media_descriptor_string(bkpinfo->backup_media_type),
    15461181                    g_current_media_number);
    1547             log_to_screen(tmp);
     1182            log_to_screen(tmp3);
     1183            paranoid_free(tmp3);
     1184
    15481185            insist_on_this_cd_number(bkpinfo, g_current_media_number);
    15491186            log_to_screen(_("Continuing to restore."));
    15501187        } else {
    1551             strcpy(tmp,
    1552                    slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
    15531188            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
    15541189                log_msg(2,
     
    15581193                continue;
    15591194            } else {
    1560                 if (does_file_exist
    1561                     (slice_fname
    1562                      (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
    1563                     strcpy(bzip2_command, "lzop");
    1564                     strcpy(suffix, "lzo");
    1565                 } else
    1566                     if (does_file_exist
    1567                         (slice_fname
    1568                          (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1569                     strcpy(bzip2_command, "bzip2");
    1570                     strcpy(suffix, "bz2");
    1571                 } else
    1572                     if (does_file_exist
    1573                         (slice_fname
    1574                          (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
    1575                     strcpy(bzip2_command, "");
    1576                     strcpy(suffix, "");
     1195                if (does_file_exist(tmp1)) {
     1196                    asprintf(&bzip2_command, "lzop -dc %s 2>> %s",tmp1, MONDO_LOGFILE);
     1197                } else if (does_file_exist(tmp2)) {
     1198                        asprintf(&bzip2_command, "bzip2 -dc %s 2>> %s",tmp2, MONDO_LOGFILE);
     1199                } else if (does_file_exist(tmp)) {
     1200                        asprintf(&bzip2_command, "");
    15771201                } else {
    15781202                    log_to_screen(_("OK, that's pretty fsck0red..."));
    1579                     return (1);
     1203                    return (pathname_of_last_file_restored);
    15801204                }
    15811205            }
    1582             if (bzip2_command[0] != '\0') {
    1583                 sprintf(bzip2_command + strlen(bzip2_command),
    1584                         " -dc %s 2>> %s",
    1585                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1586                                     suffix), MONDO_LOGFILE);
    1587             } else {
    1588                 sprintf(bzip2_command, "cat %s 2>> %s",
    1589                         slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
    1590                                     suffix), MONDO_LOGFILE);
    1591             }
    1592             sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
     1206
     1207            if (bzip2_command == NULL) {
     1208                asprintf(&bzip2_command, "cat %s 2>> %s", tmp, MONDO_LOGFILE);
     1209            }
     1210            asprintf(&tmp3, "Working on %s #%d, file #%ld, slice #%ld ",
    15931211                    media_descriptor_string(bkpinfo->backup_media_type),
    15941212                    g_current_media_number, bigfileno + 1, sliceno);
    1595             log_msg(2, tmp);
    1596 
     1213            log_msg(2, tmp3);
    15971214            if (!g_text_mode) {
    1598                 newtDrawRootText(0, g_noof_rows - 2, tmp);
     1215                newtDrawRootText(0, g_noof_rows - 2, tmp3);
    15991216                newtRefresh();
    1600                 strip_spaces(tmp);
    1601                 update_progress_form(tmp);
    1602             }
     1217                update_progress_form(tmp3);
     1218            }
     1219            paranoid_free(tmp3);
     1220
    16031221            if (!(fbzip2 = popen(bzip2_command, "r"))) {
    16041222                fatal_error("Can't run popen command");
    16051223            }
     1224            paranoid_free(bzip2_command);
     1225
    16061226            while (!feof(fbzip2)) {
    16071227                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
    16081228                if (siz > 0) {
    1609                     sprintf(sz_msg, "Read %ld from fbzip2", siz);
    1610                     siz = fwrite(bigblk, 1, siz, fout);
    1611                     sprintf(sz_msg + strlen(sz_msg),
    1612                             "; written %ld to fout", siz);
    1613 //        log_msg(2. sz_msg);
     1229                    siz1 = fwrite(bigblk, 1, siz, fout);
     1230                    asprintf(&sz_msg, "Read %ld from fbzip2; written %ld to fout", siz, siz1);
     1231                    log_it(sz_msg);
     1232                    paranoid_free(sz_msg);
    16141233                }
    16151234            }
     
    16201239            g_current_progress++;
    16211240        }
    1622     }
    1623 /*
    1624   memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
    1625   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1626   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1627   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1628   fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
    1629 */
     1241        paranoid_free(tmp);
     1242        paranoid_free(tmp1);
     1243        paranoid_free(tmp2);
     1244    }
    16301245    paranoid_fclose(fout);
    16311246    g_loglevel = old_loglevel;
     
    16331248    if (use_ntfsprog_hack) {
    16341249        log_msg(3, "Waiting for ntfsclone to finish");
    1635         sprintf(tmp,
     1250        asprintf(&tmp,
    16361251                " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    16371252        while (system(tmp) == 0) {
    16381253            sleep(1);
    16391254        }
     1255        paranoid_free(tmp);
    16401256        log_it("OK, ntfsclone has really finished");
    16411257    }
     
    16491265        utime(outfile_fname, ubuf);
    16501266    }
     1267    paranoid_free(outfile_fname);
    16511268    paranoid_free(bigblk);
    1652     paranoid_free(checksum);
    1653     paranoid_free(outfile_fname);
    1654     paranoid_free(tmp);
    1655     paranoid_free(bzip2_command);
    1656     paranoid_free(ntfsprog_command);
    1657     paranoid_free(suffix);
    1658     paranoid_free(sz_devfile);
    1659 
    1660     return (retval);
     1269
     1270    return (pathname_of_last_file_restored);
    16611271}
     1272
    16621273
    16631274/**************************************************************************
    16641275 *END_ RESTORE_A_BIGGIEFILE_FROM_CD                                       *
    16651276 **************************************************************************/
    1666 
    16671277
    16681278
     
    16741284 * @param orig_bf_fname The original filename of the biggiefile.
    16751285 * @param biggiefile_number The number of the biggiefile (starting from 0).
    1676  * @param orig_checksum Unused.
    1677  * @param biggiefile_size Unused.
    16781286 * @param filelist The node structure containing the list of files to be restored.
    16791287 * If @p orig_bf_fname is not in the list, it will be ignored.
    16801288 * @return 0 for success (or skip), nonzero for failure.
    1681  * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
    1682  */
    1683 int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
    1684                                      long long biggiefile_size, //UNUSED
     1289 */
     1290char *restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number,
    16851291                                     struct s_node *filelist,
    1686                                      int use_ntfsprog,
    1687                                      char *pathname_of_last_file_restored)
     1292                                     int use_ntfsprog)
    16881293{
    16891294    FILE *pout;
     
    16911296
    16921297  /** mallocs ********/
    1693     char *tmp;
    1694     char *command;
    1695     char *outfile_fname;
    1696     char *ntfsprog_command;
    1697     char *sz_devfile;
    1698     char *ntfsprog_fifo;
     1298    char *tmp = NULL;
     1299    char *tmp1 = NULL;
     1300    char *command = NULL;
     1301    char *outfile_fname = NULL;
     1302    char *ntfsprog_command = NULL;
     1303    char *ntfsprog_fifo = NULL;
    16991304    char *file_to_openout = NULL;
     1305    char *pathname_of_last_file_restored = NULL;
    17001306
    17011307    struct s_node *node;
     
    17141320    ubuf = &the_utime_buf;
    17151321
    1716     malloc_string(tmp);
    1717     malloc_string(ntfsprog_fifo);
    1718     malloc_string(outfile_fname);
    1719     malloc_string(command);
    1720     malloc_string(sz_devfile);
    1721     malloc_string(ntfsprog_command);
    17221322    old_loglevel = g_loglevel;
    17231323    assert(bkpinfo != NULL);
    17241324    assert(orig_bf_fname != NULL);
    1725     assert(orig_checksum != NULL);
    1726 
    1727     pathname_of_last_file_restored[0] = '\0';
     1325
    17281326    if (use_ntfsprog == BLK_START_A_PIHBIGGIE) {
    17291327        use_ntfsprog = 1;
     
    17371335    }
    17381336
    1739     strncpy(pathname_of_last_file_restored, orig_bf_fname,
    1740             MAX_STR_LEN - 1);
    1741     pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
     1337    asprintf(&pathname_of_last_file_restored, orig_bf_fname);
    17421338
    17431339    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
     
    17501346                    "Skipping big file %ld (%s) - not in biggielist subset",
    17511347                    biggiefile_number + 1, orig_bf_fname);
    1752             pathname_of_last_file_restored[0] = '\0';
     1348            pathname_of_last_file_restored = NULL;
    17531349        } else if (!(node->selected)) {
    17541350            dummy_restore = TRUE;
    17551351            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    17561352                    orig_bf_fname);
    1757             pathname_of_last_file_restored[0] = '\0';
     1353            pathname_of_last_file_restored = NULL;
    17581354        }
    17591355    }
     
    17611357    if (use_ntfsprog) {
    17621358        if (strncmp(orig_bf_fname, "/dev/", 5)) {
    1763             log_msg(1,
    1764                     "I was in error when I set use_ntfsprog to TRUE.");
     1359            log_msg(1, "I was in error when I set use_ntfsprog to TRUE.");
    17651360            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
    17661361            use_ntfsprog = FALSE;
     
    17701365    if (use_ntfsprog) {
    17711366        g_loglevel = 4;
    1772         strcpy(outfile_fname, orig_bf_fname);
     1367        asprintf(&outfile_fname, orig_bf_fname);
    17731368        use_ntfsprog_hack = TRUE;
    17741369        log_msg(2,
    17751370                "Calling ntfsclone in background because %s is a /dev entry",
    17761371                outfile_fname);
    1777         sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
     1372        asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768),
    17781373                (int) (random() % 32768));
    1779         mkfifo(sz_devfile, 0x770);
    1780         strcpy(ntfsprog_fifo, sz_devfile);
     1374        mkfifo(ntfsprog_fifo, 0x770);
     1375
    17811376        file_to_openout = ntfsprog_fifo;
    17821377        switch (pid = fork()) {
     
    17871382                    "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    17881383                    outfile_fname, ntfsprog_fifo);
    1789             res =
    1790                 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
     1384            res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
    17911385//          log_msg(3, "CHILD - fip - exiting");
    17921386            exit(res);
     
    17971391                    (long int) (pid));
    17981392        }
     1393        paranoid_free(ntfsprog_fifo);
    17991394    } else {
    18001395        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
    18011396        {
    1802             strcpy(outfile_fname, orig_bf_fname);
     1397            asprintf(&outfile_fname, orig_bf_fname);
    18031398        } else                  // biggiefile
    18041399        {
    1805             sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
     1400            asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path,
    18061401                    orig_bf_fname);
    18071402        }
    18081403        use_ntfsprog_hack = FALSE;
    1809         ntfsprog_fifo[0] = '\0';
    18101404        file_to_openout = outfile_fname;
    18111405        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    18131407            make_hole_for_file(outfile_fname);
    18141408        }
    1815         sprintf(tmp, "Reassembling big file %ld (%s)",
     1409        asprintf(&tmp1, "Reassembling big file %ld (%s)",
    18161410                biggiefile_number + 1, orig_bf_fname);
    1817         log_msg(2, tmp);
     1411        log_msg(2, tmp1);
     1412        paranoid_free(tmp1);
    18181413    }
    18191414
    18201415    if (dummy_restore) {
    1821         sprintf(outfile_fname, "/dev/null");
     1416        paranoid_free(outfile_fname);
     1417        asprintf(&outfile_fname, "/dev/null");
    18221418    }
    18231419
    18241420    if (!bkpinfo->zip_exe[0]) {
    1825         sprintf(command, "cat > \"%s\"", file_to_openout);
     1421        asprintf(&command, "cat > \"%s\"", file_to_openout);
    18261422    } else {
    1827         sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
     1423        asprintf(&command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
    18281424                file_to_openout, MONDO_LOGFILE);
    18291425    }
    1830     sprintf(tmp, "Pipe command = '%s'", command);
    1831     log_msg(3, tmp);
     1426    asprintf(&tmp1, "Pipe command = '%s'", command);
     1427    log_msg(3, tmp1);
     1428    paranoid_free(tmp1);
    18321429
    18331430    /* restore biggiefile, one slice at a time */
     
    18351432        fatal_error("Cannot pipe out");
    18361433    }
     1434    paranoid_free(command);
     1435
    18371436    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
    18381437         ctrl_chr != BLK_STOP_A_BIGGIE;
     
    18411440            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    18421441        }
    1843         sprintf(tmp, "Working on file #%ld, slice #%ld    ",
     1442        asprintf(&tmp1, "Working on file #%ld, slice #%ld    ",
    18441443                biggiefile_number + 1, current_slice_number);
    1845         log_msg(2, tmp);
     1444        log_msg(2, tmp1);
     1445
    18461446        if (!g_text_mode) {
    1847             newtDrawRootText(0, g_noof_rows - 2, tmp);
     1447            newtDrawRootText(0, g_noof_rows - 2, tmp1);
    18481448            newtRefresh();
    18491449        }
    1850         strip_spaces(tmp);
    1851         update_progress_form(tmp);
     1450        strip_spaces(tmp1);
     1451        update_progress_form(tmp1);
     1452        paranoid_free(tmp1);
     1453
    18521454        if (current_slice_number == 0) {
    18531455            res =
     
    18791481        g_current_progress++;
    18801482    }
     1483    paranoid_free(tmp);
    18811484    paranoid_pclose(pout);
    18821485
     
    18861489    if (use_ntfsprog_hack) {
    18871490        log_msg(3, "Waiting for ntfsclone to finish");
    1888         sprintf(tmp,
     1491        asprintf(&tmp,
    18891492                " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null");
    18901493        while (system(tmp) == 0) {
    18911494            sleep(1);
    1892         }
     1495        }   
     1496        paranoid_free(tmp);
    18931497        log_msg(3, "OK, ntfsclone has really finished");
    18941498    }
     
    19051509    }
    19061510
    1907     paranoid_free(tmp);
    19081511    paranoid_free(outfile_fname);
    1909     paranoid_free(command);
    1910     paranoid_free(ntfsprog_command);
    1911     paranoid_free(sz_devfile);
    1912     paranoid_free(ntfsprog_fifo);
    19131512    g_loglevel = old_loglevel;
    1914     return (retval);
     1513    return (pathname_of_last_file_restored);
    19151514}
    19161515
     
    19181517 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM                                    *
    19191518 **************************************************************************/
    1920 
    19211519
    19221520
     
    19431541  /** malloc **/
    19441542    char *command;
    1945     char *tmp;
     1543    char *tmp = NULL;
    19461544    char *filelist_name;
    1947     char *filelist_subset_fname;
    1948     char *executable;
    1949     char *temp_log;
    1950     char screen_message[100];
     1545    char *filelist_subset_fname = NULL;
     1546    char *executable = NULL;
     1547    char *temp_log = NULL;
    19511548    long matches = 0;
    19521549    bool use_star;
    1953     char *xattr_fname;
    1954     char *acl_fname;
    1955 //  char files_to_restore_this_time_fname[MAX_STR_LEN];
     1550    char *xattr_fname = NULL;
     1551    char *acl_fname = NULL;
    19561552
    19571553    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1958     malloc_string(command);
    1959     malloc_string(tmp);
    1960     malloc_string(filelist_name);
    1961     malloc_string(filelist_subset_fname);
    1962     malloc_string(executable);
    1963     malloc_string(temp_log);
    1964     malloc_string(xattr_fname);
    1965     malloc_string(acl_fname);
    19661554
    19671555    log_msg(5, "Entering");
    1968     filelist_subset_fname[0] = '\0';
    19691556    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    1970 //  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    1971     sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
     1557    asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
    19721558    run_program_and_log_output(command, 9);
    1973     sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    1974             (int) (random() % 32768));
    1975 
    1976     sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
     1559    paranoid_free(command);
     1560
     1561    asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld",
    19771562            current_tarball_number);
    19781563    if (length_of_file(filelist_name) <= 2) {
     
    19841569                "but it's non-critical. It's cosmetic. Don't worry about it.");
    19851570        retval = 0;
    1986         goto leave_sub;
     1571        log_msg(5, "Leaving");
     1572        return (retval);
    19871573    }
    19881574    if (count_lines_in_file(filelist_name) <= 0
     
    19901576        log_msg(3, "length_of_file(%s) = %llu", tarball_fname,
    19911577                length_of_file(tarball_fname));
    1992         sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
     1578        asprintf(&tmp, "Unable to restore fileset #%ld (CD I/O error)",
    19931579                current_tarball_number);
    19941580        log_to_screen(tmp);
     1581        paranoid_free(tmp);
    19951582        retval = 1;
    1996         goto leave_sub;
     1583        log_msg(5, "Leaving");
     1584        return (retval);
    19971585    }
    19981586
    19991587    if (filelist) {
    2000         sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
     1588        asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
    20011589                current_tarball_number);
    20021590        if ((matches =
     
    20051593                                             use_star))
    20061594            <= 0) {
    2007             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     1595            asprintf(&tmp, "Skipping fileset %ld", current_tarball_number);
    20081596            log_msg(1, tmp);
     1597            paranoid_free(tmp);
    20091598        } else {
    20101599            log_msg(3, "Saved fileset %ld's subset to %s",
    20111600                    current_tarball_number, filelist_subset_fname);
    20121601        }
    2013         sprintf(screen_message, "Tarball #%ld --- %ld matches",
     1602        asprintf(&tmp, "Tarball #%ld --- %ld matches",
    20141603                current_tarball_number, matches);
    2015         log_to_screen(screen_message);
     1604        log_to_screen(tmp);
     1605        paranoid_free(tmp);
    20161606    } else {
    2017         filelist_subset_fname[0] = '\0';
    2018     }
     1607        filelist_subset_fname = NULL;
     1608    }
     1609    paranoid_free(filelist_name);
    20191610
    20201611    if (filelist == NULL || matches > 0) {
    2021         sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
     1612        asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
    20221613                MNT_CDROM "/archives", current_tarball_number);
    2023         sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
     1614        asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
    20241615                current_tarball_number);
    20251616        if (strstr(tarball_fname, ".bz2")) {
    2026             strcpy(executable, "bzip2");
     1617            asprintf(&executable, "bzip2");
    20271618        } else if (strstr(tarball_fname, ".lzo")) {
    2028             strcpy(executable, "lzop");
     1619            asprintf(&executable, "lzop");
    20291620        } else {
    2030             executable[0] = '\0';
    2031         }
    2032         if (executable[0]) {
    2033             sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
     1621            executable = NULL;
     1622        }
     1623
     1624        if (executable == NULL) {
     1625            asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable);
    20341626            if (run_program_and_log_output(tmp, FALSE)) {
    20351627                log_to_screen
    2036                     (_("(compare_a_tarball) Compression program not found - oh no!"));
     1628                    (_
     1629                     ("(compare_a_tarball) Compression program not found - oh no!"));
    20371630                paranoid_MR_finish(1);
    20381631            }
    2039             strcpy(tmp, executable);
    2040             sprintf(executable, "-P %s -Z", tmp);
     1632            paranoid_free(tmp);
     1633
     1634            asprintf(&tmp, executable);
     1635            asprintf(&executable, "-P %s -Z", tmp);
     1636            paranoid_free(tmp);
    20411637        }
    20421638#ifdef __FreeBSD__
     
    20461642#endif
    20471643
    2048 //      if (strstr(tarball_fname, ".star."))
     1644        asprintf(&temp_log, "/tmp/%d.%d", (int) (random() % 32768),
     1645            (int) (random() % 32768));
     1646
    20491647        if (use_star) {
    2050             sprintf(command,
     1648            if (strstr(tarball_fname, ".bz2")) {
     1649                asprintf(&tmp, " -bz");
     1650            } else {
     1651                asprintf(&tmp, "");
     1652            }
     1653            asprintf(&command,
    20511654                    "star -x -force-remove -U " STAR_ACL_SZ
    2052                     " errctl= file=%s", tarball_fname);
    2053             if (strstr(tarball_fname, ".bz2")) {
    2054                 strcat(command, " -bz");
    2055             }
     1655                    " errctl= file=%s %s 2>> %s >> %s", tarball_fname, tmp, temp_log, temp_log);
     1656            paranoid_free(tmp);
    20561657        } else {
    2057             if (filelist_subset_fname[0] != '\0') {
    2058                 sprintf(command,
    2059                         "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
     1658            if (filelist_subset_fname != NULL) {
     1659                asprintf(&command,
     1660                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s 2>> %s >> %s",
    20601661                        TAPE_BLOCK_SIZE,
    20611662                        BUFSIZE, executable, filelist_subset_fname,
    20621663//             files_to_restore_this_time_fname,
    2063                         tarball_fname);
     1664                        tarball_fname, temp_log, temp_log);
    20641665            } else {
    2065                 sprintf(command,
    2066                         "afio -i -b %ld -c %ld -M 8m %s %s",
     1666                asprintf(&command,
     1667                        "afio -i -b %ld -c %ld -M 8m %s %s 2>> %s >> %s",
    20671668                        TAPE_BLOCK_SIZE,
    2068                         BUFSIZE, executable, tarball_fname);
    2069             }
    2070         }
     1669                        BUFSIZE, executable, tarball_fname, temp_log, temp_log);
     1670            }
     1671        }
     1672        paranoid_free(executable);
     1673
    20711674#undef BUFSIZE
    2072         sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
    2073                 temp_log);
    20741675        log_msg(1, "command = '%s'", command);
    20751676        unlink(temp_log);
     
    20831684            }
    20841685        }
     1686        paranoid_free(command);
     1687
    20851688        if (res && length_of_file(temp_log) < 5) {
    20861689            res = 0;
     
    20921695            if (res) {
    20931696                log_to_screen
    2094                     (_("Errors occurred while setting extended attributes"));
     1697                    (_
     1698                     ("Errors occurred while setting extended attributes"));
    20951699            } else {
    20961700                log_msg(1, "I set xattr OK");
     
    21031707            if (res) {
    21041708                log_to_screen
    2105                     (_("Errors occurred while setting access control lists"));
     1709                    (_
     1710                     ("Errors occurred while setting access control lists"));
    21061711            } else {
    21071712                log_msg(1, "I set ACL OK");
     
    21101715        }
    21111716        if (retval) {
    2112             sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     1717            asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    21131718            system(command);
     1719            paranoid_free(command);
    21141720            log_msg(2, "Errors occurred while processing fileset #%d",
    21151721                    current_tarball_number);
     
    21171723            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
    21181724        }
     1725        unlink(xattr_fname);
     1726        paranoid_free(xattr_fname);
    21191727    }
    21201728    if (does_file_exist("/PAUSE")) {
    21211729        popup_and_OK
    2122             (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
     1730            (_
     1731             ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
    21231732    }
    21241733    unlink(filelist_subset_fname);
    2125     unlink(xattr_fname);
    21261734    unlink(acl_fname);
    21271735    unlink(temp_log);
    21281736
    2129   leave_sub:
    2130     paranoid_free(command);
    2131     paranoid_free(tmp);
    2132     paranoid_free(filelist_name);
    21331737    paranoid_free(filelist_subset_fname);
    2134     paranoid_free(executable);
     1738    paranoid_free(acl_fname);
    21351739    paranoid_free(temp_log);
    2136     paranoid_free(xattr_fname);
    2137     paranoid_free(acl_fname);
     1740
    21381741    log_msg(5, "Leaving");
    21391742    return (retval);
     
    21721775
    21731776  /** malloc add ***/
    2174     char *tmp;
    2175     char *command;
    2176     char *afio_fname;
    2177     char *filelist_fname;
    2178     char *filelist_subset_fname;
    2179     char *executable;
     1777    char *tmp = NULL;
     1778    char *command = NULL;
     1779    char *afio_fname = NULL;
     1780    char *filelist_fname = NULL;
     1781    char *filelist_subset_fname = NULL;
     1782    char *executable = NULL;
    21801783    long matches = 0;
    21811784    bool restore_this_fileset = FALSE;
     
    21841787    assert(bkpinfo != NULL);
    21851788    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    2186     malloc_string(filelist_subset_fname);
    2187     malloc_string(filelist_fname);
    2188     malloc_string(afio_fname);
    2189     malloc_string(executable);
    2190     malloc_string(command);
    2191     malloc_string(tmp);
    2192     filelist_subset_fname[0] = '\0';
    21931789    /* to do it with a file... */
    21941790    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    2195     sprintf(tmp,
     1791    asprintf(&tmp,
    21961792            "Restoring from fileset #%ld (%ld KB) on %s #%d",
    21971793            current_tarball_number, (long) size >> 10,
     
    21991795            g_current_media_number);
    22001796    log_msg(2, tmp);
     1797    paranoid_free(tmp);
    22011798    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
    22021799
     
    22061803   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
    22071804   ****************************************************************************/
    2208     filelist_fname[0] = filelist_subset_fname[0] = '\0';
    2209     sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
     1805    asprintf(&afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
    22101806            current_tarball_number);
    2211     sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
     1807    asprintf(&filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
    22121808            current_tarball_number);
    2213     sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
     1809    asprintf(&filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
    22141810            bkpinfo->tmpdir, current_tarball_number);
    2215 //  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
    22161811    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
    22171812    if (strstr(tarball_fname, ".star")) {
     
    22211816        log_msg(1, "Warning - error reading afioball from tape");
    22221817    }
    2223     if (bkpinfo->compression_level == 0) {
    2224         executable[0] = '\0';
    2225     } else {
     1818    if (bkpinfo->compression_level != 0) {
    22261819        if (bkpinfo->use_star) {
    2227             strcpy(executable, " -bz");
     1820            asprintf(&executable, " -bz");
    22281821        } else {
    2229             sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
     1822            asprintf(&executable, "-P %s -Z", bkpinfo->zip_exe);
    22301823        }
    22311824    }
     
    22381831        if (strstr(tarball_fname, ".star.")) {
    22391832            use_star = TRUE;
    2240             sprintf(command, "star -t file=%s %s", afio_fname, executable);
     1833            asprintf(&command, "star -t file=%s %s > %s 2>> %s", afio_fname, executable, filelist_fname, MONDO_LOGFILE);
    22411834        } else {
    22421835            use_star = FALSE;
    2243             sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
    2244                     executable, afio_fname);
    2245         }
    2246         sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
    2247                 MONDO_LOGFILE);
     1836            asprintf(&command, "afio -t -M 8m -b %ld %s %s > %s 2>> %s", TAPE_BLOCK_SIZE,
     1837                    executable, afio_fname, filelist_fname, MONDO_LOGFILE);
     1838        }
    22481839        log_msg(1, "command = %s", command);
    22491840        if (system(command)) {
    22501841            log_msg(4, "Warning - error occurred while retrieving TOC");
    22511842        }
     1843        paranoid_free(command);
    22521844        if ((matches =
    22531845             save_filelist_entries_in_common(filelist_fname, filelist,
     
    22591851                        current_tarball_number);
    22601852            }
    2261             sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
     1853            asprintf(&tmp, "Skipping fileset %ld", current_tarball_number);
    22621854            log_msg(2, tmp);
     1855            paranoid_free(tmp);
    22631856            restore_this_fileset = FALSE;
    22641857        } else {
     
    22691862        }
    22701863    }
     1864    unlink(filelist_fname);
     1865    paranoid_free(filelist_fname);
    22711866
    22721867// Concoct the call to star/afio to restore files
    2273     if (strstr(tarball_fname, ".star."))    // star
    2274     {
    2275         sprintf(command, "star -x file=%s %s", afio_fname, executable);
     1868    if (strstr(tarball_fname, ".star.")) {
     1869        // star
    22761870        if (filelist) {
    2277             sprintf(command + strlen(command), " list=%s",
    2278                     filelist_subset_fname);
    2279         }
    2280     } else                      // afio
    2281     {
    2282         sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
    2283                 executable);
     1871            asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable
     1872                    filelist_subset_fname,MONDO_LOGFILE);
     1873        } else {
     1874            asprintf(&command,"star -x file=%s %s 2>> %s", afio_fname, executable,MONDO_LOGFILE);
     1875        }
     1876    } else {
     1877        // afio
    22841878        if (filelist) {
    2285             sprintf(command + strlen(command), " -w %s",
    2286                     filelist_subset_fname);
    2287         }
    2288         sprintf(command + strlen(command), " %s", afio_fname);
    2289     }
    2290     sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
    2291 
    2292 // Call if IF there are files to restore (selectively/unconditionally)
     1879            asprintf(&command, "afio -i -M 8m -b %ld %s -w %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, filelist_subset_fname,afio_fname,MONDO_LOGFILE);
     1880        } else {
     1881            asprintf(&command, "afio -i -M 8m -b %ld %s %s 2>> %s", TAPE_BLOCK_SIZE, executable,afio_fname,MONDO_LOGFILE);
     1882        }
     1883    }
     1884    paranoid_free(executable);
     1885
     1886    // Call if IF there are files to restore (selectively/unconditionally)
    22931887    if (restore_this_fileset) {
    22941888        log_msg(1, "Calling command='%s'", command);
     
    23151909        log_msg(1, "NOT CALLING '%s'", command);
    23161910    }
     1911    paranoid_free(command);
    23171912
    23181913    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
     
    23221917
    23231918    unlink(filelist_subset_fname);
    2324     unlink(filelist_fname);
    23251919    unlink(afio_fname);
    23261920
    23271921    paranoid_free(filelist_subset_fname);
    2328     paranoid_free(filelist_fname);
    23291922    paranoid_free(afio_fname);
    2330     paranoid_free(command);
    2331     paranoid_free(tmp);
    23321923    return (retval);
    23331924}
     
    23361927 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
    23371928 **************************************************************************/
    2338 
    2339 
    23401929
    23411930
     
    23541943{
    23551944    int retval = 0;
    2356     int res;
    2357     long noof_biggiefiles, bigfileno = 0, total_slices;
    2358   /** malloc **/
    2359     char *tmp;
    2360     bool just_changed_cds = FALSE, finished;
    2361     char *xattr_fname;
    2362     char *acl_fname;
    2363     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
    2364     char *pathname_of_last_biggie_restored;
     1945    int res = 0;
     1946    long noof_biggiefiles = 0L, bigfileno = 0L, total_slices = 0L;
     1947    char *tmp = NULL;
     1948    bool just_changed_cds = FALSE, finished = FALSE;
     1949    char *xattr_fname = NULL;
     1950    char *acl_fname = NULL;
     1951    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
     1952    char *pathname_of_last_biggie_restored = NULL;
    23651953    FILE *fbw = NULL;
    23661954
    2367     malloc_string(xattr_fname);
    2368     malloc_string(acl_fname);
    2369     malloc_string(tmp);
    2370     malloc_string(biggies_whose_EXATs_we_should_set);
    2371     malloc_string(pathname_of_last_biggie_restored);
    23721955    assert(bkpinfo != NULL);
    23731956
    2374     sprintf(biggies_whose_EXATs_we_should_set,
     1957    asprintf(&biggies_whose_EXATs_we_should_set,
    23751958            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    23761959    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     
    23811964    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    23821965    total_slices = atol(tmp);
    2383     sprintf(tmp, _("Reassembling large files      "));
     1966    paranoid_free(tmp);
     1967
     1968    asprintf(&tmp, _("Reassembling large files      "));
    23841969    mvaddstr_and_log_it(g_currentY, 0, tmp);
     1970    paranoid_free(tmp);
     1971
    23851972    if (length_of_file(BIGGIELIST) < 6) {
    23861973        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
     
    23931980        return (0);
    23941981    }
    2395     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     1982    asprintf(&tmp, "OK, there are %ld biggiefiles in the archives",
    23961983            noof_biggiefiles);
    23971984    log_msg(2, tmp);
     1985    paranoid_free(tmp);
    23981986
    23991987    open_progress_form(_("Reassembling large files"),
     
    24031991    for (bigfileno = 0, finished = FALSE; !finished;) {
    24041992        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
    2405         if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     1993        tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, "");
     1994        if (!does_file_exist(tmp)) {
    24061995            log_msg(3,
    24071996                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
     
    24101999                    media_descriptor_string(bkpinfo->backup_media_type),
    24112000                    g_current_media_number);
    2412             log_msg(3, "Slicename would have been %s",
    2413                     slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
     2001            tmp1 = slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "");
     2002            log_msg(3, "Slicename would have been %s", tmp1);
     2003            paranoid_free(tmp1);
     2004
    24142005            // I'm not positive 'just_changed_cds' is even necessary...
    24152006            if (just_changed_cds) {
     
    24202011                insist_on_this_cd_number(bkpinfo,
    24212012                                         ++g_current_media_number);
    2422                 sprintf(tmp, _("Restoring from %s #%d"),
     2013                asprintf(&tmp, _("Restoring from %s #%d"),
    24232014                        media_descriptor_string(bkpinfo->
    24242015                                                backup_media_type),
    24252016                        g_current_media_number);
    24262017                log_to_screen(tmp);
     2018                paranoid_free(tmp);
     2019
    24272020                just_changed_cds = TRUE;
    24282021            } else {
     
    24342027        } else {
    24352028            just_changed_cds = FALSE;
    2436             sprintf(tmp, _("Restoring big file %ld"), bigfileno + 1);
     2029            asprintf(&tmp, _("Restoring big file %ld"), bigfileno + 1);
    24372030            update_progress_form(tmp);
    2438             res =
    2439                 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
    2440                                              pathname_of_last_biggie_restored);
     2031            paranoid_free(tmp);
     2032
     2033            pathname_of_last_biggie_restored =
     2034                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist);
    24412035            iamhere(pathname_of_last_biggie_restored);
    24422036            if (fbw && pathname_of_last_biggie_restored[0]) {
    24432037                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
    24442038            }
     2039            paranoid_free(pathname_of_last_biggie_restored);
    24452040            retval += res;
    24462041            bigfileno++;
    24472042
    24482043        }
     2044        paranoid_free(tmp);
    24492045    }
    24502046
    24512047    if (fbw) {
    24522048        fclose(fbw);
    2453         sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    2454         sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2049        asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
     2050        asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
    24552051        if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) {
    24562052            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
     
    24602056            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
    24612057        }
    2462     }
     2058        paranoid_free(acl_fname);
     2059        paranoid_free(xattr_fname);
     2060    }
     2061    paranoid_free(biggies_whose_EXATs_we_should_set);
     2062
    24632063    if (does_file_exist("/PAUSE")) {
    24642064        popup_and_OK
    2465             (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
     2065            (_
     2066             ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
    24662067    }
    24672068    close_progress_form();
     
    24712072        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    24722073    }
    2473     paranoid_free(xattr_fname);
    2474     paranoid_free(acl_fname);
    2475     paranoid_free(tmp);
    2476     paranoid_free(biggies_whose_EXATs_we_should_set);
    2477     paranoid_free(pathname_of_last_biggie_restored);
    24782074    return (retval);
    24792075}
    2480 
    24812076/**************************************************************************
    24822077 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
    24832078 **************************************************************************/
    2484 
    24852079
    24862080
     
    25062100  /**malloc ***/
    25072101    char *tmp;
     2102    char *tmp1;
    25082103    char *tarball_fname;
    25092104    char *progress_str;
    25102105    char *comment;
    2511 
    2512     malloc_string(tmp);
    2513     malloc_string(tarball_fname);
    2514     malloc_string(progress_str);
    2515     malloc_string(comment);
    25162106
    25172107    assert(bkpinfo != NULL);
     
    25272117    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    25282118    max_val = atol(tmp) + 1;
    2529     sprintf(progress_str, _("Restoring from %s #%d"),
     2119    paranoid_free(tmp);
     2120
     2121    asprintf(&progress_str, _("Restoring from %s #%d"),
    25302122            media_descriptor_string(bkpinfo->backup_media_type),
    25312123            g_current_media_number);
     
    25382130        insist_on_this_cd_number(bkpinfo, g_current_media_number);
    25392131        update_progress_form(progress_str);
    2540         sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
     2132
     2133        asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
    25412134                current_tarball_number);
    25422135        if (!does_file_exist(tarball_fname)) {
    2543             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
     2136            paranoid_free(tarball_fname);
     2137            asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
    25442138                    current_tarball_number);
    25452139        }
    25462140        if (!does_file_exist(tarball_fname)) {
    2547             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
     2141            paranoid_free(tarball_fname);
     2142            asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.",
    25482143                    current_tarball_number);
    25492144        }
    25502145        if (!does_file_exist(tarball_fname)) {
    2551             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
     2146            paranoid_free(tarball_fname);
     2147            asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
    25522148                    current_tarball_number);
    25532149        }
    25542150        if (!does_file_exist(tarball_fname)) {
    2555             sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
     2151            paranoid_free(tarball_fname);
     2152            asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.",
    25562153                    current_tarball_number);
    25572154        }
    25582155        if (!does_file_exist(tarball_fname)) {
     2156            paranoid_free(tarball_fname);
    25592157            if (current_tarball_number == 0) {
    25602158                log_to_screen
    2561                     (_("No tarballs. Strange. Maybe you only backed up freakin' big files?"));
     2159                    (_
     2160                     ("No tarballs. Strange. Maybe you only backed up freakin' big files?"));
    25622161                return (0);
    25632162            }
     
    25692168            }
    25702169            g_current_media_number++;
    2571             sprintf(progress_str, _("Restoring from %s #%d"),
     2170            paranoid_free(progress_str);
     2171            asprintf(&progress_str, _("Restoring from %s #%d"),
    25722172                    media_descriptor_string(bkpinfo->backup_media_type),
    25732173                    g_current_media_number);
    25742174            log_to_screen(progress_str);
    25752175        } else {
    2576             sprintf(progress_str, _("Restoring from fileset #%ld on %s #%d"),
     2176            paranoid_free(progress_str);
     2177            asprintf(&progress_str,
     2178                    _("Restoring from fileset #%ld on %s #%d"),
    25772179                    current_tarball_number,
    25782180                    media_descriptor_string(bkpinfo->backup_media_type),
     
    25862188                                              filelist);
    25872189            }
    2588             sprintf(tmp, _("%s #%d, fileset #%ld - restore "),
     2190            if (res) {
     2191                asprintf(&tmp1, _("reported errors"));
     2192            } else {
     2193                asprintf(&tmp1, _("succeeded"));
     2194            }
     2195            asprintf(&tmp, _("%s #%d, fileset #%ld - restore %s"),
    25892196                    media_descriptor_string(bkpinfo->backup_media_type),
    2590                     g_current_media_number, current_tarball_number);
    2591             if (res) {
    2592                 strcat(tmp, _("reported errors"));
    2593             } else if (attempts > 1) {
    2594                 strcat(tmp, _("succeeded"));
    2595             } else {
    2596                 strcat(tmp, _("succeeded"));
    2597             }
     2197                    g_current_media_number, current_tarball_number,tmp1);
     2198            paranoid_free(tmp1);
     2199           
    25982200            if (attempts > 1) {
    2599                 sprintf(tmp + strlen(tmp), _(" (%d attempts) - review logs"),
    2600                         attempts);
    2601             }
    2602             strcpy(comment, tmp);
     2201                asprintf(&tmp1, _(" (%d attempts) - review logs"), attempts);
     2202            }
     2203            asprintf(&comment, "%s%s", tmp, tmp1);
     2204            paranoid_free(tmp);
     2205            paranoid_free(tmp1);
    26032206            if (attempts > 1) {
    26042207                log_to_screen(comment);
    26052208            }
     2209            paranoid_free(comment);
    26062210
    26072211            retval += res;
     
    26092213            g_current_progress++;
    26102214        }
    2611     }
     2215        paranoid_free(tarball_fname);
     2216    }
     2217    paranoid_free(progress_str);
    26122218    close_progress_form();
     2219
    26132220    if (retval) {
    26142221        mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
     
    26162223        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    26172224    }
    2618     paranoid_free(tmp);
    2619     paranoid_free(tarball_fname);
    2620     paranoid_free(progress_str);
    2621     paranoid_free(comment);
    26222225
    26232226    return (retval);
     
    26272230 *END_RESTORE_ALL_TARBALLS_FROM_CD                                        *
    26282231 **************************************************************************/
    2629 
    26302232
    26312233
     
    26502252
    26512253  /** malloc add ****/
    2652     char *tmp;
    2653     char *biggie_fname;
    2654     char *biggie_cksum;
    2655     char *xattr_fname;
    2656     char *acl_fname;
    2657     char *p;
    2658     char *pathname_of_last_biggie_restored;
    2659     char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
    2660     long long biggie_size;
     2254    char *tmp = NULL;
     2255    char *biggie_fname = NULL;
     2256    char *xattr_fname = NULL;
     2257    char *acl_fname = NULL;
     2258    char *p = NULL;
     2259    char *pathname_of_last_biggie_restored = NULL;
     2260    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
     2261    long long biggie_size = NULL;
    26612262    FILE *fbw = NULL;
    26622263
    2663     malloc_string(tmp);
    2664     malloc_string(biggie_fname);
    2665     malloc_string(biggie_cksum);
    2666     malloc_string(xattr_fname);
    2667     malloc_string(acl_fname);
    2668     malloc_string(biggies_whose_EXATs_we_should_set);
    2669     malloc_string(pathname_of_last_biggie_restored);
    26702264    assert(bkpinfo != NULL);
    26712265
    26722266    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
    2673 
    26742267    total_slices = atol(tmp);
    2675     sprintf(tmp, "Reassembling large files      ");
    2676     sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    2677     sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2268    paranoid_free(tmp);
     2269
     2270    asprintf(&tmp, "Reassembling large files      ");
     2271    asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
     2272    asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
    26782273    mvaddstr_and_log_it(g_currentY, 0, tmp);
    2679     sprintf(biggies_whose_EXATs_we_should_set,
     2274    paranoid_free(tmp);
     2275
     2276    asprintf(&biggies_whose_EXATs_we_should_set,
    26802277            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
    26812278    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
     
    26942291
    26952292    noof_biggiefiles = atol(biggie_fname);
    2696     sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
     2293    asprintf(&tmp, "OK, there are %ld biggiefiles in the archives",
    26972294            noof_biggiefiles);
    26982295    log_msg(2, tmp);
     2296    paranoid_free(tmp);
     2297
    26992298    open_progress_form(_("Reassembling large files"),
    27002299                       _("I am now reassembling all the large files."),
     
    27132312            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
    27142313        }
     2314        /* BERLIOS: useless
    27152315        p = strrchr(biggie_fname, '/');
    27162316        if (!p) {
     
    27192319            p++;
    27202320        }
    2721         sprintf(tmp, _("Restoring big file %ld (%lld K)"),
     2321        */
     2322        asprintf(&tmp, _("Restoring big file %ld (%lld K)"),
    27222323                current_bigfile_number + 1, biggie_size / 1024);
    27232324        update_progress_form(tmp);
    2724         res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
     2325        paranoid_free(tmp);
     2326
     2327        pathname_of_last_biggie_restored = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
    27252328                                               current_bigfile_number,
    2726                                                biggie_cksum,
    2727                                                biggie_size,
    2728                                                filelist, ctrl_chr,
    2729                                                pathname_of_last_biggie_restored);
     2329                                               filelist, ctrl_chr);
    27302330        log_msg(1, "I believe I have restored %s",
    27312331                pathname_of_last_biggie_restored);
     
    27332333            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
    27342334        }
     2335        paranoid_free(pathname_of_last_biggie_restored);
     2336
    27352337        retval += res;
    27362338        current_bigfile_number++;
     
    27392341    if (current_bigfile_number != noof_biggiefiles
    27402342        && noof_biggiefiles != 0) {
    2741         sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
     2343        asprintf(&tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
    27422344                current_bigfile_number, noof_biggiefiles);
    27432345    } else {
    2744         sprintf(tmp,
     2346        asprintf(&tmp,
    27452347                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
    27462348                noof_biggiefiles, current_bigfile_number);
    27472349    }
    27482350    log_msg(1, tmp);
     2351    paranoid_free(tmp);
    27492352
    27502353    if (fbw) {
     
    27682371        }
    27692372    }
     2373    paranoid_free(xattr_fname);
     2374    paranoid_free(acl_fname);
     2375    paranoid_free(biggies_whose_EXATs_we_should_set);
     2376
    27702377    if (does_file_exist("/PAUSE")) {
    27712378        popup_and_OK
    2772             (_("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
     2379            (_
     2380             ("Press ENTER to go on. Delete /PAUSE to stop these pauses."));
    27732381    }
    27742382
     
    27792387        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    27802388    }
    2781     paranoid_free(biggies_whose_EXATs_we_should_set);
    2782     paranoid_free(pathname_of_last_biggie_restored);
    27832389    paranoid_free(biggie_fname);
    2784     paranoid_free(biggie_cksum);
    2785     paranoid_free(xattr_fname);
    2786     paranoid_free(acl_fname);
    2787     paranoid_free(tmp);
    27882390    return (retval);
    27892391}
     
    27922394 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
    27932395 **************************************************************************/
    2794 
    2795 
    2796 
    2797 
    27982396
    27992397
     
    28192417
    28202418  /** malloc **/
    2821     char *tmp;
    2822     char *progress_str;
    2823     char *tmp_fname;
    2824     char *xattr_fname;
    2825     char *acl_fname;
     2419    char *tmp = NULL;
     2420    char *progress_str = NULL;
     2421    char *tmp_fname = NULL;
     2422    char *xattr_fname = NULL;
     2423    char *acl_fname = NULL;
    28262424
    28272425    long long tmp_size;
    28282426
    2829     malloc_string(tmp);
    2830     malloc_string(progress_str);
    2831     malloc_string(tmp_fname);
    28322427    assert(bkpinfo != NULL);
    2833     malloc_string(xattr_fname);
    2834     malloc_string(acl_fname);
    28352428    mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives"));
    28362429    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    28372430    max_val = atol(tmp) + 1;
     2431    paranoid_free(tmp);
    28382432
    28392433    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
     
    28412435    run_program_and_log_output("pwd", 5);
    28422436
    2843     sprintf(progress_str, _("Restoring from media #%d"),
     2437    asprintf(&progress_str, _("Restoring from media #%d"),
    28442438            g_current_media_number);
    28452439    log_to_screen(progress_str);
     
    28632457    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
    28642458        update_progress_form(progress_str);
    2865         sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
     2459        asprintf(&xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
    28662460                current_afioball_number);
    2867         sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
     2461        asprintf(&acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
    28682462                current_afioball_number);
    28692463        unlink(xattr_fname);
     
    28792473            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    28802474        }
    2881         sprintf(tmp,
     2475        /* BERLIOS: useless ?
     2476        asprintf(&tmp,
    28822477                _("Restoring from fileset #%ld (name=%s, size=%ld K)"),
    28832478                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
     2479                */
    28842480        res =
    28852481            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
     
    28892485        retval += res;
    28902486        if (res) {
    2891             sprintf(tmp, _("Fileset %ld - errors occurred"),
     2487            asprintf(&tmp, _("Fileset %ld - errors occurred"),
    28922488                    current_afioball_number);
    28932489            log_to_screen(tmp);
     2490            paranoid_free(tmp);
    28942491        }
    28952492        res =
     
    29012498        current_afioball_number++;
    29022499        g_current_progress++;
    2903         sprintf(progress_str, _("Restoring from fileset #%ld on %s #%d"),
     2500
     2501        paranoid_free(progress_str);
     2502        asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"),
    29042503                current_afioball_number,
    29052504                media_descriptor_string(bkpinfo->backup_media_type),
     
    29092508        unlink(xattr_fname);
    29102509        unlink(acl_fname);
     2510        paranoid_free(xattr_fname);
     2511        paranoid_free(acl_fname);
    29112512    }                           // next
     2513    paranoid_free(progress_str);
     2514    paranoid_free(tmp_fname);
     2515
    29122516    log_msg(1, "All done with afioballs");
    29132517    close_progress_form();
     
    29172521        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    29182522    }
    2919     paranoid_free(tmp);
    2920     paranoid_free(progress_str);
    2921     paranoid_free(tmp_fname);
    2922     paranoid_free(xattr_fname);
    2923     paranoid_free(acl_fname);
    29242523    return (retval);
    29252524}
     
    29462545
    29472546  /** mallco ***/
    2948     char *cwd;
    2949     char *newpath;
    2950     char *tmp;
     2547    char *cwd = NULL;
     2548    char *newpath = NULL;
     2549    char *tmp = NULL;
    29512550    assert(bkpinfo != NULL);
    29522551
    29532552    malloc_string(cwd);
    29542553    malloc_string(newpath);
    2955     malloc_string(tmp);
    29562554    log_msg(2, "restore_everything() --- starting");
    29572555    g_current_media_number = 1;
     2556    /* BERLIOS: should test return value, or better change the function */
    29582557    getcwd(cwd, MAX_STR_LEN - 1);
    2959     sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
     2558    asprintf(&tmp, "mkdir -p %s", bkpinfo->restore_path);
    29602559    run_program_and_log_output(tmp, FALSE);
     2560    paranoid_free(tmp);
     2561
    29612562    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
    29622563    chdir(bkpinfo->restore_path);
     2564    /* BERLIOS: should test return value, or better change the function */
    29632565    getcwd(newpath, MAX_STR_LEN - 1);
    29642566    log_msg(1, "path is now %s", newpath);
     
    29662568    if (!find_home_of_exe("petris") && !g_text_mode) {
    29672569        newtDrawRootText(0, g_noof_rows - 2,
    2968                          _("Press ALT-<left cursor> twice to play Petris :-) "));
     2570                         _
     2571                         ("Press ALT-<left cursor> twice to play Petris :-) "));
    29692572        newtRefresh();
    29702573    }
    2971     mvaddstr_and_log_it(g_currentY, 0, _("Preparing to read your archives"));
     2574    mvaddstr_and_log_it(g_currentY, 0,
     2575                        _("Preparing to read your archives"));
    29722576    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    29732577        mount_cdrom(bkpinfo);
    29742578        mvaddstr_and_log_it(g_currentY++, 0,
    2975                             _("Restoring OS and data from streaming media"));
     2579                            _
     2580                            ("Restoring OS and data from streaming media"));
    29762581        if (bkpinfo->backup_media_type == cdstream) {
    29772582            openin_cdstream(bkpinfo);
     
    30082613    paranoid_free(cwd);
    30092614    paranoid_free(newpath);
    3010     paranoid_free(tmp);
    30112615    return (resA + resB);
    30122616}
     
    30172621
    30182622
    3019 
    3020 /**
    3021  * @brief Haha. You wish! (This function is not implemented :-)
    3022  */
    3023 int
    3024 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
    3025                                  char *monitas_device,
    3026                                  char *restore_this_directory,
    3027                                  char *restore_here)
    3028      /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
    3029 {
    3030     FILE *fout;
    3031     int retval = 0;
    3032     int i;
    3033     int j;
    3034     struct mountlist_itself the_mountlist;
    3035     static struct raidlist_itself the_raidlist;
    3036   /** malloc **/
    3037     char tmp[MAX_STR_LEN + 1];
    3038     char command[MAX_STR_LEN + 1];
    3039     char datablock[256 * 1024];
    3040     char datadisks_fname[MAX_STR_LEN + 1];
    3041     long k;
    3042     long length;
    3043     long long llt;
    3044     struct s_node *filelist = NULL;
    3045     assert(bkpinfo != NULL);
    3046     assert_string_is_neither_NULL_nor_zerolength(monitas_device);
    3047     assert(restore_this_directory != NULL);
    3048     assert(restore_here != NULL);
    3049 
    3050     sprintf(tmp, "restore_here = '%s'", restore_here);
    3051 
    3052     log_msg(2, tmp);
    3053 
    3054     log_msg(2, "restore_live_from_monitas_server() - starting");
    3055     unlink("/tmp/mountlist.txt");
    3056     unlink("/tmp/filelist.full");
    3057     unlink("/tmp/biggielist.txt");
    3058     if (restore_here[0] == '\0') {
    3059         strcpy(bkpinfo->restore_path, MNT_RESTORING);
    3060     } else {
    3061         strcpy(bkpinfo->restore_path, restore_here);
    3062     }
    3063     log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3064     sprintf(tmp, "FYI - data will be restored to %s",
    3065             bkpinfo->restore_path);
    3066     log_msg(3, tmp);
    3067     log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
    3068     sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
    3069             (int) (random() % 32768));
    3070     chdir(bkpinfo->tmpdir);
    3071 
    3072     sprintf(command, "cat %s", monitas_device);
    3073     g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
    3074     if (!(fout = fopen(datadisks_fname, "w"))) {
    3075         log_OS_error(datadisks_fname);
    3076         return (1);
    3077     }
    3078     for (i = 0; i < 32; i++) {
    3079         for (j = 0; j < 4; j++) {
    3080             for (length = k = 0; length < 256 * 1024; length += k) {
    3081                 k = fread(datablock + length, 1, 256 * 1024 - length,
    3082                           g_tape_stream);
    3083             }
    3084             fwrite(datablock, 1, length, fout);
    3085             g_tape_posK += length;
    3086         }
    3087     }
    3088     paranoid_fclose(fout);
    3089     sprintf(command,
    3090             "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
    3091             datadisks_fname);
    3092     run_program_and_log_output(command, 4);
    3093     read_header_block_from_stream(&llt, tmp, &i);
    3094     read_header_block_from_stream(&llt, tmp, &i);
    3095 
    3096     unlink(datadisks_fname);
    3097     read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    3098     retval = load_mountlist(&the_mountlist, g_mountlist_fname);
    3099 
    3100 
    3101     load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
    3102     iamhere("FIXME");
    3103     fatal_error("This will fail");
    3104     sprintf(command,
    3105             "grep -x \"%s.*\" %s > %s",
    3106             restore_this_directory, g_filelist_full, g_filelist_full);
    3107     if (system(command)) {
    3108         retval++;
    3109         log_to_screen
    3110             (_("Error(s) occurred while processing filelist and wildcard"));
    3111     }
    3112     iamhere("FIXME");
    3113     fatal_error("This will fail");
    3114     sprintf(command,
    3115             "grep -x \"%s.*\" %s > %s",
    3116             restore_this_directory, g_biggielist_txt, g_biggielist_txt);
    3117     if (system(command)) {
    3118         log_msg(1,
    3119                 "Error(s) occurred while processing biggielist and wildcard");
    3120     }
    3121     sprintf(command, "touch %s", g_biggielist_txt);
    3122     run_program_and_log_output(command, FALSE);
    3123 //  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
    3124     retval += restore_everything(bkpinfo, filelist);
    3125     free_filelist(filelist);
    3126     log_msg(2, "--------End of restore_live_from_monitas_server--------");
    3127     return (retval);
    3128 }
    3129 
    3130 /**************************************************************************
    3131  *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
    3132  **************************************************************************/
    3133 
    3134 
    3135 
    3136 
    31372623extern void wait_until_software_raids_are_prepped(char *, int);
    3138 
    31392624
    31402625char which_restore_mode(void);
     
    31462631void welcome_to_mondorestore()
    31472632{
    3148     log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION);
     2633    log_msg(0, "-------------- Mondo Restore v%s -------------",
     2634            PACKAGE_VERSION);
    31492635    log_msg(0,
    31502636            "DON'T PANIC! Mondorestore logs almost everything, so please ");
     
    31702656            "stopped for some reason, chances are it's detailed here.    ");
    31712657    log_msg(0,
    3172             "More than likely there's a message at the very end of this  ");
     2658            "More than likely there's a message near the end of this     ");
    31732659    log_msg(0,
    31742660            "log that will tell you what is wrong.  Please read it!      ");
     
    31782664
    31792665
    3180 
    31812666/**
    31822667 * Restore the user's data.
     
    31852670int main(int argc, char *argv[])
    31862671{
    3187     FILE *fin;
    3188     FILE *fout;
     2672    FILE *fin = NULL;
     2673    FILE *fout = NULL;
    31892674    int retval = 0;
    3190     int res;
    3191 //  int c;
    3192     char *tmp;
    3193 
    3194     struct mountlist_itself *mountlist;
    3195     struct raidlist_itself *raidlist;
    3196     struct s_bkpinfo *bkpinfo;
    3197     struct s_node *filelist;
    3198     char *a, *b;
     2675    int res = 0;
     2676    char *tmp = NULL;
     2677
     2678    struct mountlist_itself *mountlist = NULL;
     2679    struct raidlist_itself *raidlist = NULL;
     2680    struct s_bkpinfo *bkpinfo = NULL;
     2681    struct s_node *filelist = NULL;
     2682    char *a = NULL, *b = NULL;
    31992683
    32002684  /**************************************************************************
     
    32152699
    32162700    g_loglevel = DEFAULT_MR_LOGLEVEL;
    3217     malloc_string(tmp);
    32182701
    32192702/* Configure global variables */
    32202703#ifdef __FreeBSD__
    3221     if (strstr
    3222         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    3223          "textonly"))
     2704    tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
    32242705#else
    3225     if (strstr
    3226         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    3227          "textonly"))
     2706    tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
    32282707#endif
    3229     {
     2708    if (strstr(tmp,"textonly")) {
    32302709        g_text_mode = TRUE;
    32312710        log_msg(1, "TEXTONLY MODE");
     
    32332712        g_text_mode = FALSE;
    32342713    }                           // newt :-)
     2714    paranoid_free(tmp);
     2715
    32352716    if (!
    32362717        (bkpinfo = g_bkpinfo_DONTUSETHIS =
     
    32472728    malloc_libmondo_global_strings();
    32482729
    3249     asprintf(&g_mondo_home,
    3250              call_program_and_get_last_line_of_output
    3251              ("which mondorestore"));
     2730    g_mondo_home = call_program_and_get_last_line_of_output("which mondorestore"));
    32522731    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
    32532732    make_hole_for_dir(g_tmpfs_mountpt);
     
    32572736    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
    32582737
    3259     malloc_string(tmp);
    3260     malloc_string(a);
    3261     malloc_string(b);
    32622738    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
    32632739    reset_bkpinfo(bkpinfo);
     
    32812757
    32822758/* Backup original mountlist.txt */
    3283     sprintf(tmp, "%s.orig", g_mountlist_fname);
     2759    asprintf(&tmp, "%s.orig", g_mountlist_fname);
    32842760    if (!does_file_exist(g_mountlist_fname)) {
    32852761        log_msg(2,
     
    32872763                __LINE__, g_mountlist_fname);
    32882764    } else if (!does_file_exist(tmp)) {
    3289         sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
     2765        paranoid_free(tmp);
     2766        asprintf(&tmp, "cp -f %s %s.orig", g_mountlist_fname,
    32902767                g_mountlist_fname);
    32912768        run_program_and_log_output(tmp, FALSE);
    32922769    }
     2770    paranoid_free(tmp);
    32932771
    32942772/* Init directories */
    32952773    make_hole_for_dir(bkpinfo->tmpdir);
    3296     sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
     2774    asprintf(&tmp, "mkdir -p %s", bkpinfo->tmpdir);
    32972775    run_program_and_log_output(tmp, FALSE);
     2776    paranoid_free(tmp);
     2777
    32982778    make_hole_for_dir("/var/log");
    32992779    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
    33002780    run_program_and_log_output("umount " MNT_CDROM, FALSE);
    33012781    run_program_and_log_output
    3302         ("ln -sf "MONDO_LOGFILE" /tmp/mondo-restore.log",
    3303          FALSE);
     2782        ("ln -sf " MONDO_LOGFILE " /tmp/mondo-restore.log", FALSE);
    33042783
    33052784    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
     
    33612840        system("rm -Rf /tmp/*pih*");
    33622841
    3363         restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
     2842        (void)restore_a_biggiefile_from_CD(bkpinfo, 42, NULL);
    33642843    }
    33652844
     
    33782857//      finish(0);
    33792858//      toggle_path_selection (filelist, "/root/stuff", TRUE);
    3380         strcpy(a, argv[3]);
    3381         strcpy(b, argv[4]);
     2859        asprintf(&a, argv[3]);
     2860        asprintf(&b, argv[4]);
    33822861
    33832862        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
    33842863        free_filelist(filelist);
     2864        paranoid_free(a);
     2865        paranoid_free(b);
    33852866        printf("res = %d", res);
    33862867        finish(0);
     
    34442925        if (argc != 1) {
    34452926            popup_and_OK
    3446                 (_("Live mode doesn't support command-line parameters yet."));
     2927                (_
     2928                 ("Live mode doesn't support command-line parameters yet."));
    34472929            paranoid_MR_finish(1);
    34482930//    return(1);
     
    34542936        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
    34552937            g_restoring_live_from_cd = TRUE;
    3456         }
    3457         if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
    3458             retval =
    3459                 restore_live_from_monitas_server(bkpinfo,
    3460                                                  argv[2],
    3461                                                  argv[3], argv[4]);
    34622938        } else {
    34632939            log_msg(2, "Calling restore_to_live_filesystem()");
     
    34662942        log_msg(2, "Still here. Yay.");
    34672943        if (strlen(bkpinfo->tmpdir) > 0) {
    3468             sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
     2944            asprintf(&tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
    34692945            run_program_and_log_output(tmp, FALSE);
     2946            paranoid_free(tmp);
    34702947        }
    34712948        unmount_boot_if_necessary();    /* for Gentoo users */
     
    34962973                sprintf(bkpinfo->isodir, "/tmp/isodir");
    34972974                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
    3498                 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
     2975                asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir",
    34992976                        bkpinfo->nfs_mount);
    35002977                run_program_and_log_output(tmp, 1);
     2978                paranoid_free(tmp);
    35012979            }
    35022980        }
     
    35052983        if (retval) {
    35062984            log_to_screen
    3507                 (_("Warning - load_raidtab_into_raidlist returned an error"));
     2985                (_
     2986                 ("Warning - load_raidtab_into_raidlist returned an error"));
    35082987        }
    35092988
     
    35773056        if (does_file_exist("/tmp/changed.files")) {
    35783057            log_to_screen
    3579                 (_("See /tmp/changed.files for list of files that have changed."));
     3058                (_
     3059                 ("See /tmp/changed.files for list of files that have changed."));
    35803060        }
    35813061        mvaddstr_and_log_it(g_currentY++,
    35823062                            0,
    3583                             _("Run complete. Errors were reported. Please review the logfile."));
     3063                            _
     3064                            ("Run complete. Errors were reported. Please review the logfile."));
    35843065    } else {
    35853066        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    35863067            mvaddstr_and_log_it(g_currentY++,
    35873068                                0,
    3588                                 _("Run complete. Please remove floppy/CD/media and reboot."));
     3069                                _
     3070                                ("Run complete. Please remove floppy/CD/media and reboot."));
    35893071        } else {
    35903072            run_program_and_log_output("sync", FALSE);
     
    36073089            mvaddstr_and_log_it(g_currentY++,
    36083090                                0,
    3609                                 _("Run complete. Please remove media and reboot."));
     3091                                _
     3092                                ("Run complete. Please remove media and reboot."));
    36103093        }
    36113094    }
     
    36173100            if (mount_all_devices(mountlist, TRUE)) {
    36183101                log_to_screen
    3619                     (_("Unable to re-mount partitions for post-nuke stuff"));
     3102                    (_
     3103                     ("Unable to re-mount partitions for post-nuke stuff"));
    36203104            } else {
    36213105                log_msg(1, "Re-mounted partitions for post-nuke stuff");
    3622                 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
     3106                asprintf(&tmp, "post-nuke %s %d", bkpinfo->restore_path,
    36233107                        retval);
    36243108                if (!g_text_mode) {
     
    36293113                    log_OS_error(tmp);
    36303114                }
     3115                paranoid_free(tmp);
    36313116                if (!g_text_mode) {
    36323117                    newtResume();
     
    36473132    unlink("/tmp/mondo-run-prog.tmp");
    36483133    set_signals(FALSE);
    3649     sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
     3134    asprintf(&tmp, "rm -Rf %s", bkpinfo->tmpdir);
    36503135    run_program_and_log_output(tmp, FALSE);
     3136    paranoid_free(tmp);
     3137
    36513138    log_to_screen
    3652         (_("Restore log copied to /tmp/mondo-restore.log on your hard disk"));
    3653     sprintf(tmp,
    3654             _("Mondo-restore is exiting (retval=%d)                                      "),
     3139        (_
     3140         ("Restore log copied to /tmp/mondo-restore.log on your hard disk"));
     3141    asprintf(&tmp,
     3142            _
     3143            ("Mondo-restore is exiting (retval=%d)                                      "),
    36553144            retval);
    36563145    log_to_screen(tmp);
    3657     sprintf(tmp, "umount %s", bkpinfo->isodir);
     3146    paranoid_free(tmp);
     3147
     3148    asprintf(&tmp, "umount %s", bkpinfo->isodir);
    36583149    run_program_and_log_output(tmp, 5);
     3150    paranoid_free(tmp);
     3151
    36593152    paranoid_free(mountlist);
    36603153    paranoid_free(raidlist);
     
    36643157    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
    36653158    free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3666     paranoid_free(a);
    3667     paranoid_free(b);
    3668     paranoid_free(tmp);
    36693159
    36703160    unlink("/tmp/filelist.full");
     
    36793169
    36803170
    3681 
    3682 
    3683 
    36843171/**************************************************************************
    36853172 *END_MONDO-RESTORE.C                                                     *
Note: See TracChangeset for help on using the changeset viewer.