Changeset 688 in MondoRescue for trunk/mondo/mondo/mondorestore


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 !)

Location:
trunk/mondo/mondo/mondorestore
Files:
14 edited

Legend:

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

    r687 r688  
    11/***************************************************************************
    2 mondo-prep.c  -  description
    3 -----------------
    4 
    5 begin: Fri Apr 19 16:40:35 EDT 2002
    6 copyright : (C) 2002 Mondo  Hugo Rabson
    7 email     : Hugo Rabson <hugorabson@msn.com>
    8 edited by : by Stan Benoit 4/2002
    9 email     : troff@nakedsoul.org
    10 cvsid     : $Id$
    11 ***************************************************************************/
    12 
    13 /***************************************************************************
    14  *                                                                         *
    15  *   This program is free software; you can redistribute it and/or modify  *
    16  *   it under the terms of the GNU General Public License as published by  *
    17  *   the Free Software Foundation; either version 2 of the License, or     *
    18  *   (at your option) any later version.                                   *
    19  *                                                                         *
    20  ***************************************************************************/
    21 
    22 /* mondo-prep.c             Hugo Rabson
    23 
    24 
    25 
    26 07/20
    27 - when starting RAID, don't do it twice :)
    28 - moved Joshua's new get_phys_size_of_drive() code
    29   from resize_drive... into get_phys_size_of_drive()
    30 
    31 06/29
    32 - make sure software RAID devices are formatted IF user says they're to be
    33 - drivelist is struct now, not char[][]
    34 
    35 06/26
    36 - drop make_relevant_partition_bootable(); do it yourself in C (mostly)
    37 - offer to reboot if partition table is locked up by the kernel
    38 
    39 06/22
    40 - be sure not to resize non-NTFS images when restoring
    41 - set non-NTFS images' partition types properly
    42 
    43 06/19
    44 - shut down all LVMs and VGs before prepping
    45 
    46 05/07
    47 - usage of parted2fdisk instead of fdisk alone (ia32/ia64 compatibility)
    48   BCO
    49 
    50 03/31
    51 - rewrote partitioning and formatting code to call fdisk once per disk
    52 
    53 10/21/2003
    54 - suspend/resume Newt gui before/after calling do_my_funky_lvm_stuff()
    55 
    56 10/20
    57 - rewrote format_everything() - what a mess it was.
    58   It now does things in three phases:-
    59   - formats software RAID devices (/dev/md0, etc.)
    60   - formats and configures LVM devices
    61   - formats regular partitions (/dev/hda1, /dev/sdb2, etc.)
    62     and any LVMs recently prepped
    63 
    64 10/07
    65 - use strstr(format, "raid") instead of strcmp(format,"raid") to determin
    66   if partition is a RAID component
    67 
    68 09/23
    69 - better comments
    70 
    71 09/18
    72 - better logging of RAID activity
    73 
    74 05/05
    75 - added Joshua Oreman's FreeBSD patches
    76 
    77 04/30
    78 - added textonly mode
    79 
    80 04/24
    81 - added lots of assert()'s and log_OS_error()'s
    82 
    83 04/21
    84 - format_everything() --- don't let bar go too far
    85 - mkfs -c to check for bad blocks when formatting
    86 
    87 04/04
    88 - misc clean-up (Tom Mortell)
    89 
    90 01/15/2003
    91 - added code for LVM and SW Raid (Brian Borgeson)
    92 
    93 12/10/2002
    94 - line 1238: friendlier output
    95 
    96 11/20
    97 - when wiping a given device in preparation for partitioning + formatting
    98   it, don't wipe the MBR; just the partition table. That allows for
    99   stupid-ass Compaq users who like to play with their MBR's.
    100 - disable mountlist.txt-->mountlist.txt.pre-resize copying (superfluous)
    101 
    102 09/09
    103 - run_program_and_log_output() now takes boolean operator to specify
    104   whether it will log its activities in the event of _success_
    105 
    106 07/01 - 07/31
    107 - added hooks to libmondo
    108 - RAID enhancements (Philippe de Muyter)
    109 
    110 01/01 - 03/31
    111 - partition_device() will refuse to partition /dev/mdX now (cos it's a
    112   virtual drive); however, it will return 0 (i.e. not an error)
    113 - make_list_of_drives() will exclude /dev/md* from list
    114 - mkreiserfs -ff instead of -q (Andy Glass)
    115 - don't resize drive if drive not found (or if its size cannot be det'd)
    116 - when generating list of drives from mountlist, skip the 'p' at the end
    117   of drive name if /dev/ida/ or /dev/cciss/; just do it (Michael Eisenberg)
    118 - don't specify journal size when formatting ext3
    119   (used to have -Jsize=10 in the call to mkfs)
    120 - handles files >2GB in size
    121 - format interactively, if Interactive Mode
    122 - removed reference to g_tape_size
    123 - when executing /tmp/i-want-my-lvm, only record the error# if the command
    124   was _not_ an 'insmod' command
    125 - pass partition size to fdisk in Kilobytes now, not Megabytes
    126 - log fdisk's output to /tmp/mondo-restore.log if it fails
    127 - don't try to format partitions of type 'image'
    128 - don't type to set types of 'image' partitions
    129 - if format code is 1 or 2 chars then assume it is a hex string
    130 - took out all '/ /' comments
    131 - don't extrapolate/add partition from RAID dev to mountlist if it's already
    132   present in mountlist
    133 - less repetitive logging in the event of vacuum-packing of last part'n
    134 - no extrapolation at all: RAID partitions should be listed in mountlist
    135   already, thanks to either Mindi v0.5x or the mountlist editor itself
    136 - no longer say, 'and logging to...' when setting a partition's type
    137 - don't run mkfs on RAID partitions (/dev/hd*, /dev/sd*); just set type
    138 - the setting of a partition's type now takes place in a separate subroutine
    139   from the subroutine that actually creates the partition
    140 - no need to set type if 83: 83 is the default (under fdisk)
    141 - turned on '-Wall'; cleaned up some cruft
    142 - if vacuum-packing partition (i.e. size=0MB --> max) then say, "(maximum)"
    143   not, "(0 MB)"
    144 
    145 11/22/2001
    146 - preliminary code review
    147 - created on Nov 22nd, 2001
    148 */
     2 * $Id
     3**/
    1494
    1505/**
     
    15914#include "../common/libmondo.h"
    16015#include "mondo-rstr-tools-EXT.h"
     16
    16117#include <sys/ioctl.h>
    16218#include <linux/hdreg.h>
    16319#include <math.h>
     20#include <unistd.h>
    16421
    16522
     
    18542extern char *g_mountlist_fname;
    18643extern long g_current_progress, g_maximum_progress;
    187 
    18844extern bool g_text_mode;
    189 
    19045extern void pause_for_N_seconds(int, char *);
    19146
    192 
    19347FILE *g_fprep = NULL;
    194 
    195 
    196 
    19748int g_partition_table_locked_up = 0;
    198 
    199 
    200 
    201 
    202 
    203 
    204 
    205 
    20649
    20750
     
    20952{
    21053    char *command;
    211     char *tmp;
    21254    int lino;
    21355    int i;
     
    21860// If LVMs are present and a zero-and-reboot wasn't recently undertaken
    21961// then zero & insist on reboot.
    220     malloc_string(command);
    221     malloc_string(tmp);
    22262    buf = malloc(blocksize);
    22363    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
     
    22666        make_list_of_drives_in_mountlist(mountlist, drivelist);
    22767        for (lino = 0; lino < drivelist->entries; lino++) {
    228             sprintf(command,
    229                     "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
    230                     drivelist->el[lino].device, MONDO_WAS_HERE);
     68            asprintf(&command,
     69                     "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
     70                     drivelist->el[lino].device, MONDO_WAS_HERE);
    23171            if (!run_program_and_log_output(command, 1)) {
    23272                log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)",
    23373                        lino, drivelist->el[lino].device);
     74                paranoid_free(command);
    23475                break;
    23576            }
     77            paranoid_free(command);
    23678        }
    23779
     
    23981// zero & reboot
    24082            log_to_screen
    241                 (_("I am sorry for the inconvenience but I must ask you to reboot."));
    242             log_to_screen
    243                 (_("I need to reset the Master Boot Record; in order to be"));
    244             log_to_screen
    245                 (_("sure the kernel notices, I must reboot after doing it."));
     83                (_
     84                 ("I am sorry for the inconvenience but I must ask you to reboot."));
     85            log_to_screen(_
     86                          ("I need to reset the Master Boot Record; in order to be"));
     87            log_to_screen(_
     88                          ("sure the kernel notices, I must reboot after doing it."));
    24689            log_to_screen("Please hit 'Enter' to reboot.");
    24790            for (lino = 0; lino < drivelist->entries; lino++) {
     
    265108                }
    266109            }
    267             system("sync");
    268             system("sync");
    269             system("sync");
     110            sync();
     111            sync();
     112            sync();
    270113            popup_and_OK
    271                 (_("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."));
     114                (_
     115                 ("I must reboot now. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."));
    272116            system("reboot");
    273117        }
    274118    }
    275119// Still here? Cool!
    276     paranoid_free(command);
    277     paranoid_free(tmp);
    278120    log_msg(1, "Cool. I didn't have to wipe anything.");
    279121}
    280 
    281 
    282 
    283 
    284122
    285123
     
    311149    return (i);
    312150}
    313 
    314 
    315 
    316 
    317 
    318 
    319 
    320 
    321151
    322152
     
    330160 * @return The number of errors encountered (0 for success).
    331161 */
    332 
    333 
    334162int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
    335163                          bool vacuum_pack)
    336164{
    337     /**  buffers **********************************************/
    338     char *tmp;
    339     char *incoming;
    340     char *command;
    341     char *lvscan_sz;
    342     char *lvremove_sz;
    343     char *pvscan_sz;
    344     char *vgscan_sz;
    345     char *vgcreate_sz;
    346     char *vgchange_sz;
    347     char *vgremove_sz;
    348 //  char *do_this_last;
    349 
    350165    /** char **************************************************/
    351     char *p;
    352     char *q;
     166    char *tmp = NULL;
     167    char *tmp1 = NULL;
     168    char *incoming = NULL;
     169    char *command = NULL;
     170    char *lvscan_sz = NULL;
     171    char *lvremove_sz = NULL;
     172    char *pvscan_sz = NULL;
     173    char *vgscan_sz = NULL;
     174    char *vgchange_sz = NULL;
     175    char *vgremove_sz = NULL;
     176    char *p = NULL;
     177    char *q = NULL;
    353178
    354179    /** int ***************************************************/
    355180    int retval = 0;
    356181    int res = 0;
    357     int i;
     182    int i = 0;
    358183    int lvmversion = 1;
    359184    long extents;
    360185    fpos_t orig_pos;
     186    size_t n = 0;
     187    size_t n1 = 0;
    361188
    362189    /** pointers **********************************************/
     
    374201    }
    375202
    376     malloc_string(tmp);
    377     malloc_string(incoming);
    378     malloc_string(lvscan_sz);
    379     malloc_string(lvremove_sz);
    380     malloc_string(vgscan_sz);
    381     malloc_string(pvscan_sz);
    382     malloc_string(vgcreate_sz);
    383     malloc_string(vgchange_sz);
    384     malloc_string(vgremove_sz);
    385 //  malloc_string(do_this_last); // postpone lvcreate call if necessary
    386     command = malloc(512);
    387 
    388 //  do_this_last[0] = '\0';
    389203    iamhere("STARTING");
    390204    log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
    391205    if (find_home_of_exe("lvm"))    // found it :) cool
    392206    {
    393         strcpy(lvscan_sz, "lvm lvscan");
    394         strcpy(lvremove_sz, "lvm lvremove");
    395         strcpy(vgscan_sz, "lvm vgscan");
    396         strcpy(pvscan_sz, "lvm pvscan");
    397         strcpy(vgcreate_sz, "lvm vgcreate");
    398         strcpy(vgchange_sz, "lvm vgchange");
    399         strcpy(vgremove_sz, "lvm vgremove");
     207        asprintf(&lvscan_sz, "lvm lvscan");
     208        asprintf(&lvremove_sz, "lvm lvremove");
     209        asprintf(&vgscan_sz, "lvm vgscan");
     210        asprintf(&pvscan_sz, "lvm pvscan");
     211        asprintf(&vgchange_sz, "lvm vgchange");
     212        asprintf(&vgremove_sz, "lvm vgremove");
    400213    } else {
    401         strcpy(lvscan_sz, "lvscan");
    402         strcpy(lvremove_sz, "lvremove");
    403         strcpy(vgscan_sz, "vgscan");
    404         strcpy(pvscan_sz, "pvscan");
    405         strcpy(vgcreate_sz, "vgcreate");
    406         strcpy(vgchange_sz, "vgchange");
    407         strcpy(vgremove_sz, "vgremove");
    408     }
    409     sprintf(command,
     214        asprintf(&lvscan_sz, "lvscan");
     215        asprintf(&lvremove_sz, "lvremove");
     216        asprintf(&vgscan_sz, "vgscan");
     217        asprintf(&pvscan_sz, "pvscan");
     218        asprintf(&vgchange_sz, "vgchange");
     219        asprintf(&vgremove_sz, "vgremove");
     220    }
     221    asprintf(&command,
    410222            "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> "
    411223            MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz);
     224    paranoid_free(lvscan_sz);
     225    paranoid_free(lvremove_sz);
     226
    412227    run_program_and_log_output(command, 5);
     228    paranoid_free(command);
     229
    413230    sleep(1);
    414     sprintf(command,
     231    asprintf(&command,
    415232            "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> "
    416             MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz,
    417             vgremove_sz, vgremove_sz);
     233            MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz);
     234    paranoid_free(vgchange_sz);
     235    paranoid_free(vgremove_sz);
     236
    418237    run_program_and_log_output(command, 5);
     238    paranoid_free(command);
     239
    419240    if (just_erase_existing_volumes) {
    420241        paranoid_fclose(fin);
    421242        log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs.");
    422         retval = 0;
    423         goto end_of_i_want_my_lvm;
     243        sync();
     244        sync();
     245        sync();
     246        sleep(1);
     247        iamhere("ENDING");
     248        log_msg(1, "Not many errors. Returning 0.");
     249        return (0);
    424250    }
    425251
    426252    log_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff...");
    427253    rewind(fin);
    428     for (fgets(incoming, 512, fin); !feof(fin); fgets(incoming, 512, fin)) {
     254    for (getline(&incoming, &n1, fin); !feof(fin); getline(&incoming, &n1, fin)) {
    429255        fgetpos(fin, &orig_pos);
     256        /* BERLIOS : Strange no ? */
    430257        if (incoming[0] != '#') {
    431258            continue;
     
    433260        if (res && strstr(command, "create") && vacuum_pack) {
    434261            sleep(2);
    435             system("sync");
    436             system("sync");
    437             system("sync");
     262            sync();
     263            sync();
     264            sync();
    438265        }
    439266        if ((p = strstr(incoming, "vgcreate"))) {
    440267// include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    441             for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
     268            for (getline(&tmp, &n, fin); !feof(fin); getline(&tmp, &n, fin)) {
    442269                if (tmp[0] == '#') {
    443270                    fsetpos(fin, &orig_pos);
     
    445272                } else {
    446273                    fgetpos(fin, &orig_pos);
    447                     strcat(incoming, tmp);
     274                    asprintf(&tmp1, "%s%s", incoming, tmp);
     275                    paranoid_free(incoming);
     276                    incoming = tmp1;
    448277                }
    449278            }
     279            paranoid_free(tmp);
     280
    450281            for (q = incoming; *q != '\0'; q++) {
    451282                if (*q < 32) {
     
    453284                }
    454285            }
    455             strcpy(tmp, p + strlen("vgcreate") + 1);
    456             for (q = tmp; *q > 32; q++);
     286            malloc_string(tmp1);
     287            strcpy(tmp1, p + strlen("vgcreate") + 1);
     288            for (q = tmp1; *q > 32; q++);
    457289            *q = '\0';
    458             log_msg(1, "Deleting old entries at /dev/%s", tmp);
    459 //             sprintf(command, "%s -f %s", vgremove_sz, tmp);
    460 //             run_program_and_log_output(command, 1);
    461             sprintf(command, "rm -Rf /dev/%s", tmp);
    462             run_program_and_log_output(command, 1);
     290            log_msg(1, "Deleting old entries at /dev/%s", tmp1);
     291            asprintf(&tmp, "rm -Rf /dev/%s", tmp1);
     292            paranoid_free(tmp1);
     293            run_program_and_log_output(tmp, 1);
     294            paranoid_free(tmp);
     295
    463296            run_program_and_log_output(vgscan_sz, 1);
    464297            run_program_and_log_output(pvscan_sz, 1);
     
    468301        }
    469302        for (p = incoming + 1; *p == ' '; p++);
    470         strcpy(command, p);
     303        paranoid_free(command);
     304        asprintf(&command, p);
    471305        for (p = command; *p != '\0'; p++);
    472306        for (; *(p - 1) < 32; p--);
     
    485319            if (strstr(command, "lvm lvcreate"))
    486320                lvmversion = 2;
     321            /* BERLIOS : this tmp may be uninitialized ?
    487322            log_it("%s... so I'll get creative.", tmp);
     323            */
    488324            if (lvmversion == 2) {
    489                 strcpy(tmp, call_program_and_get_last_line_of_output
    490                        ("tail -n5 "MONDO_LOGFILE" | grep Insufficient | tail -n1"));
     325                tmp = call_program_and_get_last_line_of_output
     326                        ("tail -n5 " MONDO_LOGFILE
     327                        " | grep Insufficient | tail -n1");
    491328            } else {
    492                 strcpy(tmp, call_program_and_get_last_line_of_output
    493                        ("tail -n5 "MONDO_LOGFILE" | grep lvcreate | tail -n1"));
     329                tmp = call_program_and_get_last_line_of_output
     330                       ("tail -n5 " MONDO_LOGFILE
     331                        " | grep lvcreate | tail -n1");
    494332            }
    495333            for (p = tmp; *p != '\0' && !isdigit(*p); p++);
    496334            extents = atol(p);
    497335            log_msg(5, "p='%s' --> extents=%ld", p, extents);
     336            paranoid_free(tmp);
    498337            p = strstr(command, "-L");
    499338            if (!p) {
     
    543382            retval++;
    544383        }
    545         sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);
     384        asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command);
    546385        system(tmp);
     386        paranoid_free(tmp);
    547387        sleep(1);
    548388    }
    549389    paranoid_fclose(fin);
    550     log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    551   end_of_i_want_my_lvm:
    552     paranoid_free(tmp);
    553     paranoid_free(incoming);
    554     paranoid_free(command);
    555     paranoid_free(lvscan_sz);
    556     paranoid_free(lvremove_sz);
    557390    paranoid_free(vgscan_sz);
    558391    paranoid_free(pvscan_sz);
    559     paranoid_free(vgcreate_sz);
    560     paranoid_free(vgchange_sz);
    561     paranoid_free(vgremove_sz);
    562 //  paranoid_free(do_this_last);
    563     system("sync");
    564     system("sync");
    565     system("sync");
     392    paranoid_free(command);
     393    paranoid_free(incoming);
     394
     395    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
     396    sync();
     397    sync();
     398    sync();
    566399    sleep(1);
    567400    iamhere("ENDING");
     
    589422                                                     *old_mountlist)
    590423{
    591     /** pointers *********************************************************/
    592     FILE *fin;
    593 
    594     /** int **************************************************************/
    595     int lino;
    596     int j;
    597 
    598     /** buffers **********************************************************/
    599     char *incoming;
    600     char *tmp;
    601 
    602     /** pointers *********************************************************/
    603     char *p;
     424    FILE *fin = NULL;
     425    int lino = 0;
     426    int j = 0;
     427    char *incoming = NULL;
     428    char *tmp = NULL;
     429    char *p = NULL;
     430    size_t n = 0;
    604431
    605432    /** init *************************************************************/
     
    608435    /** end **************************************************************/
    609436
    610     malloc_string(incoming);
    611     malloc_string(tmp);
    612437    assert(new_mountlist != NULL);
    613438    assert(old_mountlist != NULL);
     
    615440#ifdef __FreeBSD__
    616441    log_to_screen
    617         (_("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."));
     442        (_
     443         ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."));
    618444    return (1);
    619445#endif
     
    624450            if (!does_file_exist("/etc/raidtab")) {
    625451                log_to_screen
    626                     (_("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"));
     452                    (_
     453                     ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"));
    627454                finish(1);
    628455            }
     
    631458                finish(1);
    632459            }
    633             for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
     460            for (getline(&incoming, &n, fin); !feof(fin)
    634461                 && !strstr(incoming, old_mountlist->el[lino].device);
    635                  fgets(incoming, MAX_STR_LEN - 1, fin));
     462                 getline(&incoming, &n, fin));
    636463            if (!feof(fin)) {
    637                 sprintf(tmp, "Investigating %s",
     464                asprintf(&tmp, "Investigating %s",
    638465                        old_mountlist->el[lino].device);
    639466                log_it(tmp);
    640                 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
     467                paranoid_free(tmp);
     468
     469                for (getline(&incoming, &n, fin); !feof(fin)
    641470                     && !strstr(incoming, "raiddev");
    642                      fgets(incoming, MAX_STR_LEN - 1, fin)) {
     471                     getline(&incoming, &n, fin)) {
    643472                    if (strstr(incoming, OSSWAP("device", "drive"))
    644473                        && !strchr(incoming, '#')) {
     
    647476                        *p = '\0';
    648477                        for (p--; p > incoming && *(p - 1) > 32; p--);
    649                         sprintf(tmp, "Extrapolating %s", p);
     478                        asprintf(&tmp, "Extrapolating %s", p);
    650479                        log_it(tmp);
     480                        paranoid_free(tmp);
     481
    651482                        for (j = 0;
    652483                             j < new_mountlist->entries
     
    666497                            new_mountlist->entries++;
    667498                        } else {
    668                             sprintf(tmp,
    669                                     "Not adding %s to mountlist: it's already there",
    670                                     p);
     499                            asprintf(&tmp,
     500                                    "Not adding %s to mountlist: it's already there", p);
    671501                            log_it(tmp);
     502                            paranoid_free(tmp);
    672503                        }
    673504                    }
    674505                }
    675506            }
     507            paranoid_free(incoming);
    676508            paranoid_fclose(fin);
    677509        } else {
     
    687519        }
    688520    }
    689     paranoid_free(incoming);
    690     paranoid_free(tmp);
    691521
    692522    return (0);
     
    702532 * @return 0 for success, nonzero for failure.
    703533 */
    704 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device)
     534int create_raid_device_via_mdadm(struct raidlist_itself *raidlist,
     535                                 char *device)
    705536{
    706537  /** int **************************************************************/
    707   int i  = 0;
    708   int j  = 0;
    709   int res = 0;
    710  
     538    int i = 0;
     539    int j = 0;
     540    int res = 0;
     541
    711542  /** buffers ***********************************************************/
    712   char *devices = NULL;
    713   char *strtmp  = NULL;
    714   char *level   = NULL;
    715   char *program = NULL;
    716  
    717   // leave straight away if raidlist is initial or has no entries
    718   if (!raidlist || raidlist->entries == 0) {
    719     log_msg(1, "No RAID arrays found.");
    720     return 1;
    721   } else {
    722     log_msg(1, "%d RAID arrays found.", raidlist->entries);
    723   }
    724   // find raidlist entry for requested device
    725   for (i = 0; i < raidlist->entries; i++) {
    726     if (!strcmp(raidlist->el[i].raid_device, device)) break;
    727   }
    728   // check whether RAID device was found in raidlist
    729   if (i == raidlist->entries) {
    730     log_msg(1, "RAID device %s not found in list.", device);
    731     return 1;
    732   }
    733   // create device list from normal disks followed by spare ones
    734   asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
    735   for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    736     asprintf(&strtmp, "%s", devices);
    737     paranoid_free(devices);
    738     asprintf(&devices, "%s %s", strtmp,
    739          raidlist->el[i].data_disks.el[j].device);
    740     paranoid_free(strtmp);
    741   }
    742   for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    743     asprintf(&strtmp, "%s", devices);
    744     paranoid_free(devices);
    745     asprintf(&devices, "%s %s", strtmp,
    746          raidlist->el[i].spare_disks.el[j].device);
    747     paranoid_free(strtmp);
    748   }
    749   // translate RAID level
    750   if (raidlist->el[i].raid_level == -2) {
    751     asprintf(&level, "multipath");
    752   } else if (raidlist->el[i].raid_level == -1) {
    753     asprintf(&level, "linear");
    754   } else {
    755     asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    756   }
    757   // create RAID device:
    758   // - RAID device, number of devices and devices mandatory
    759   // - parity algorithm, chunk size and spare devices optional
    760   // - faulty devices ignored
    761   // - persistent superblock always used as this is recommended
    762   asprintf(&program,
    763        "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
    764        raidlist->el[i].raid_device, level,
    765        raidlist->el[i].data_disks.entries);
    766   if (raidlist->el[i].parity != -1) {
    767     asprintf(&strtmp, "%s", program);
    768     paranoid_free(program);
    769     switch(raidlist->el[i].parity) {
    770     case 0:
    771       asprintf(&program, "%s --parity=%s", strtmp, "la");
    772       break;
    773     case 1:
    774       asprintf(&program, "%s --parity=%s", strtmp, "ra");
    775       break;
    776     case 2:
    777       asprintf(&program, "%s --parity=%s", strtmp, "ls");
    778       break;
    779     case 3:
    780       asprintf(&program, "%s --parity=%s", strtmp, "rs");
    781       break;
    782     default:
    783       fatal_error("Unknown RAID parity algorithm.");
    784       break;
    785     }
    786     paranoid_free(strtmp);
    787   }
    788   if (raidlist->el[i].chunk_size != -1) {
    789     asprintf(&strtmp, "%s", program);
    790     paranoid_free(program);
    791     asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
    792     paranoid_free(strtmp);
    793   }
    794   if (raidlist->el[i].spare_disks.entries > 0) {
    795     asprintf(&strtmp, "%s", program);
    796     paranoid_free(program);
    797     asprintf(&program, "%s --spare-devices=%d", strtmp,
    798          raidlist->el[i].spare_disks.entries);
    799     paranoid_free(strtmp);
    800   }
    801   asprintf(&strtmp, "%s", program);
    802   paranoid_free(program);
    803   asprintf(&program, "%s %s", strtmp, devices);
    804   paranoid_free(strtmp);
    805   res = run_program_and_log_output(program, 1);
    806   // free memory
    807   paranoid_free(devices);
    808   paranoid_free(level);
    809   paranoid_free(program);
    810   // return to calling instance
    811   return res;
     543    char *devices = NULL;
     544    char *strtmp = NULL;
     545    char *level = NULL;
     546    char *program = NULL;
     547
     548    // leave straight away if raidlist is initial or has no entries
     549    if (!raidlist || raidlist->entries == 0) {
     550        log_msg(1, "No RAID arrays found.");
     551        return 1;
     552    } else {
     553        log_msg(1, "%d RAID arrays found.", raidlist->entries);
     554    }
     555    // find raidlist entry for requested device
     556    for (i = 0; i < raidlist->entries; i++) {
     557        if (!strcmp(raidlist->el[i].raid_device, device))
     558            break;
     559    }
     560    // check whether RAID device was found in raidlist
     561    if (i == raidlist->entries) {
     562        log_msg(1, "RAID device %s not found in list.", device);
     563        return 1;
     564    }
     565    // create device list from normal disks followed by spare ones
     566    asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
     567    for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
     568        asprintf(&strtmp, "%s", devices);
     569        paranoid_free(devices);
     570        asprintf(&devices, "%s %s", strtmp,
     571                 raidlist->el[i].data_disks.el[j].device);
     572        paranoid_free(strtmp);
     573    }
     574    for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
     575        asprintf(&strtmp, "%s", devices);
     576        paranoid_free(devices);
     577        asprintf(&devices, "%s %s", strtmp,
     578                 raidlist->el[i].spare_disks.el[j].device);
     579        paranoid_free(strtmp);
     580    }
     581    // translate RAID level
     582    if (raidlist->el[i].raid_level == -2) {
     583        asprintf(&level, "multipath");
     584    } else if (raidlist->el[i].raid_level == -1) {
     585        asprintf(&level, "linear");
     586    } else {
     587        asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     588    }
     589    // create RAID device:
     590    // - RAID device, number of devices and devices mandatory
     591    // - parity algorithm, chunk size and spare devices optional
     592    // - faulty devices ignored
     593    // - persistent superblock always used as this is recommended
     594    asprintf(&program,
     595             "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
     596             raidlist->el[i].raid_device, level,
     597             raidlist->el[i].data_disks.entries);
     598    if (raidlist->el[i].parity != -1) {
     599        asprintf(&strtmp, "%s", program);
     600        paranoid_free(program);
     601        switch (raidlist->el[i].parity) {
     602        case 0:
     603            asprintf(&program, "%s --parity=%s", strtmp, "la");
     604            break;
     605        case 1:
     606            asprintf(&program, "%s --parity=%s", strtmp, "ra");
     607            break;
     608        case 2:
     609            asprintf(&program, "%s --parity=%s", strtmp, "ls");
     610            break;
     611        case 3:
     612            asprintf(&program, "%s --parity=%s", strtmp, "rs");
     613            break;
     614        default:
     615            fatal_error("Unknown RAID parity algorithm.");
     616            break;
     617        }
     618        paranoid_free(strtmp);
     619    }
     620    if (raidlist->el[i].chunk_size != -1) {
     621        asprintf(&strtmp, "%s", program);
     622        paranoid_free(program);
     623        asprintf(&program, "%s --chunk=%d", strtmp,
     624                 raidlist->el[i].chunk_size);
     625        paranoid_free(strtmp);
     626    }
     627    if (raidlist->el[i].spare_disks.entries > 0) {
     628        asprintf(&strtmp, "%s", program);
     629        paranoid_free(program);
     630        asprintf(&program, "%s --spare-devices=%d", strtmp,
     631                 raidlist->el[i].spare_disks.entries);
     632        paranoid_free(strtmp);
     633    }
     634    asprintf(&strtmp, "%s", program);
     635    paranoid_free(program);
     636    asprintf(&program, "%s %s", strtmp, devices);
     637    paranoid_free(strtmp);
     638    res = run_program_and_log_output(program, 1);
     639    // free memory
     640    paranoid_free(devices);
     641    paranoid_free(level);
     642    paranoid_free(program);
     643    // return to calling instance
     644    return res;
    812645}
    813646
     
    823656 * @return 0 for success, nonzero for failure.
    824657 */
    825 int format_device(char *device, char *format, struct raidlist_itself *raidlist)
     658int format_device(char *device, char *format,
     659                  struct raidlist_itself *raidlist)
    826660{
    827661    /** int **************************************************************/
    828     int res;
     662    int res = 0;
    829663    int retval = 0;
    830664#ifdef __FreeBSD__
     
    833667
    834668    /** buffers ***********************************************************/
    835     char *program;
    836     char *tmp;
     669    char *program = NULL;
     670    char *tmp = NULL;
     671    char *tmp1 = NULL;
     672    char *line = NULL;
     673    char *status = NULL;
     674    FILE *pin;
     675    FILE *fin;
     676    size_t n = 0;
     677    size_t n1 = 0;
    837678
    838679    /** end ****************************************************************/
    839680
    840     malloc_string(program);
    841     malloc_string(tmp);
    842681    assert_string_is_neither_NULL_nor_zerolength(device);
    843682    assert(format != NULL);
    844683
    845684    if (strstr(format, "raid")) {   // do not form RAID disks; do it to /dev/md* instead
    846         sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
     685        asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device);
    847686        log_it(tmp);
    848         paranoid_free(program);
    849687        paranoid_free(tmp);
    850688        return (0);
     
    853691    if (strcmp(format, "swap") == 0) {
    854692        log_it("Not formatting %s - it's swap", device);
    855         paranoid_free(program);
    856         paranoid_free(tmp);
    857693        return (0);
    858694    }
    859695#endif
    860696    if (strlen(format) <= 2) {
    861         sprintf(tmp,
     697        asprintf(&tmp,
    862698                "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
    863699                device, format);
    864700        log_it(tmp);
    865         paranoid_free(program);
    866701        paranoid_free(tmp);
    867702        return (0);
    868703    }
    869704    if (is_this_device_mounted(device)) {
    870         sprintf(tmp, _("%s is mounted - cannot format it       "), device);
     705        asprintf(&tmp, _("%s is mounted - cannot format it       "), device);
    871706        log_to_screen(tmp);
    872         paranoid_free(program);
    873707        paranoid_free(tmp);
    874708        return (1);
     
    880714            if (!does_file_exist("/tmp/raidconf.txt")) {
    881715                log_to_screen
    882                     (_("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."));
     716                    (_
     717                     ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."));
    883718            } else {
    884719                int res;
     
    888723                if (res) {
    889724                    log_to_screen
    890                         (_("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."));
     725                        (_
     726                         ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."));
    891727                    finish(1);
    892728                }
     
    896732
    897733        if (vinum_started_yet) {
    898             FILE *fin;
    899             char line[MAX_STR_LEN];
    900             sprintf(tmp,
    901                     _("Initializing Vinum device %s (this may take a *long* time)"),
     734            asprintf(&tmp,
     735                    _
     736                    ("Initializing Vinum device %s (this may take a *long* time)"),
    902737                    device);
    903738            log_to_screen(tmp);
     739            paranoid_free(tmp);
     740
    904741            /* format raid partition */
    905             //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
    906             sprintf(program,
     742            asprintf(&program,
    907743                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
    908744                    basename(device));
    909745            system(program);
     746
    910747            if (g_fprep) {
    911748                fprintf(g_fprep, "%s\n", program);
    912749            }
     750            paranoid_free(program);
     751
    913752            fin = fopen("/tmp/plexes", "r");
    914             while (fgets(line, MAX_STR_LEN - 1, fin)) {
     753            while (getline(&line, &n, fin)) {
    915754                if (strchr(line, '\n'))
    916755                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    917756
    918                 sprintf(tmp, "Initializing plex: %s", line);
     757                asprintf(&tmp, "Initializing plex: %s", line);
    919758                open_evalcall_form(tmp);
    920                 sprintf(tmp, "vinum init %s", line);
     759                paranoid_free(tmp);
     760
     761                asprintf(&tmp, "vinum init %s", line);
    921762                system(tmp);
     763                paranoid_free(tmp);
     764
    922765                while (1) {
    923                     sprintf(tmp,
     766                    asprintf(&tmp,
    924767                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    925768                            line);
    926                     FILE *pin = popen(tmp, "r");
    927                     char status[MAX_STR_LEN / 4];
    928                     fgets(status, MAX_STR_LEN / 4 - 1, pin);
     769                    pin = popen(tmp, "r");
     770                    paranoid_free(tmp);
     771
     772                    getline(&status, &n1, pin);
    929773                    pclose(pin);
    930774
     
    934778                    update_evalcall_form(atoi(status));
    935779                    usleep(250000);
     780                    paranoid_free(status);
    936781                }
    937782                close_evalcall_form();
    938783            }
     784            paranoid_free(line);
    939785            fclose(fin);
    940786            unlink("/tmp/plexes");
     
    942788        }
    943789#else
    944         sprintf(tmp, _("Initializing RAID device %s"), device);
     790        asprintf(&tmp, _("Initializing RAID device %s"), device);
    945791        log_to_screen(tmp);
     792        paranoid_free(tmp);
    946793
    947794// Shouldn't be necessary.
    948795        log_to_screen(_("Stopping %s"), device);
    949796        stop_raid_device(device);
    950         system("sync");
     797        sync();
    951798        sleep(1);
     799        /* BERLIOS: This code is wrong as program has not been initialized
    952800        if (g_fprep) {
    953801            fprintf(g_fprep, "%s\n", program);
    954802        }
     803        */
    955804
    956805        log_msg(1, "Making %s", device);
    957806        // use mkraid if it exists, otherwise use mdadm
    958         if (run_program_and_log_output("which mkraid", FALSE)) {
    959             res = create_raid_device_via_mdadm(raidlist, device);
    960             log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
     807        if (run_program_and_log_output("which mkraid", FALSE)) {
     808            res = create_raid_device_via_mdadm(raidlist, device);
     809            log_msg(1, "Creating RAID device %s via mdadm returned %d",
     810                    device, res);
    961811        } else {
    962             sprintf(program, "mkraid --really-force %s", device);
     812            asprintf(&program, "mkraid --really-force %s", device);
    963813            res = run_program_and_log_output(program, 1);
    964814            log_msg(1, "%s returned %d", program, res);
    965             system("sync");
     815            sync();
    966816            sleep(3);
    967817            start_raid_device(device);
     
    969819                fprintf(g_fprep, "%s\n", program);
    970820            }
    971         }
    972         system("sync");
     821            paranoid_free(program);
     822        }
     823        sync();
    973824        sleep(2);
    974 //      log_to_screen("Starting %s", device);
    975 //      sprintf(program, "raidstart %s", device);
    976 //      res = run_program_and_log_output(program, 1);
    977 //      log_msg(1, "%s returned %d", program, res);
    978 //      system("sync"); sleep(1);
    979 #endif
    980         system("sync");
     825#endif
     826        sync();
    981827        sleep(1);
    982828        newtResume();
     
    987833    if (!strcmp(format, "lvm")) {
    988834        log_msg(1, "Don't format %s - it's part of an lvm volume", device);
    989         paranoid_free(program);
    990         paranoid_free(tmp);
    991835        return (0);
    992836    }
     837    /* This function allocates program */
    993838    res = which_format_command_do_i_need(format, program);
    994     sprintf(tmp, "%s %s", program, device);
    995839    if (strstr(program, "kludge")) {
    996         strcat(tmp, " /");
    997     }
    998     sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
    999     sprintf(tmp, "Formatting %s as %s", device, format);
     840        asprintf(&tmp, "%s %s /", program, device);
     841    } else {
     842        asprintf(&tmp, "%s %s", program, device);
     843    }
     844    paranoid_free(program);
     845
     846    asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
     847    paranoid_free(tmp);
     848
     849    asprintf(&tmp, "Formatting %s as %s", device, format);
    1000850    update_progress_form(tmp);
     851
    1001852    res = run_program_and_log_output(program, FALSE);
    1002853    if (res && strstr(program, "kludge")) {
    1003         sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
    1004                 format, device);
    1005854#ifdef __FreeBSD__
    1006         sprintf(program, "newfs_msdos -F 32 %s", device);
     855        paranoid_free(program);
     856        asprintf(&program, "newfs_msdos -F 32 %s", device);
    1007857#else
    1008858#ifdef __IA64__
    1009859        /* For EFI partitions take fat16
    1010860         * as we want to make small ones */
    1011         sprintf(program, "mkfs -t %s -F 16 %s", format, device);
     861        paranoid_free(program);
     862        asprintf(&program, "mkfs -t %s -F 16 %s", format, device);
    1012863#else
    1013         sprintf(program, "mkfs -t %s -F 32 %s", format, device);
     864        paranoid_free(program);
     865        asprintf(&program, "mkfs -t %s -F 32 %s", format, device);
    1014866#endif
    1015867#endif
     
    1019871        }
    1020872    }
     873    paranoid_free(program);
     874
    1021875    retval += res;
    1022876    if (retval) {
    1023         strcat(tmp, _("...failed"));
     877        asprintf(&tmp1, "%s%s",tmp, _("...failed"));
    1024878    } else {
    1025         strcat(tmp, _("...OK"));
    1026     }
    1027 
    1028     log_to_screen(tmp);
    1029     paranoid_free(program);
     879        asprintf(&tmp1, "%s%s",tmp, _("...OK"));
     880    }
    1030881    paranoid_free(tmp);
    1031     system("sync");
     882
     883    log_to_screen(tmp1);
     884    paranoid_free(tmp1);
     885    sync();
    1032886    sleep(1);
    1033887    return (retval);
    1034888}
    1035 
    1036 
    1037 
    1038889
    1039890
     
    1044895 * @return The number of errors encountered (0 for success).
    1045896 */
    1046 int format_everything(struct mountlist_itself *mountlist, bool interactively,
    1047                           struct raidlist_itself *raidlist)
     897int format_everything(struct mountlist_itself *mountlist,
     898                      bool interactively, struct raidlist_itself *raidlist)
    1048899{
    1049900    /** int **************************************************************/
     
    1068919
    1069920    assert(mountlist != NULL);
    1070     malloc_string(tmp);
    1071     sprintf(tmp, "format_everything (mountlist, interactively = %s",
     921    asprintf(&tmp, "format_everything (mountlist, interactively = %s",
    1072922            (interactively) ? "true" : "false");
    1073923    log_it(tmp);
     924    paranoid_free(tmp);
     925
    1074926    mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions     "));
    1075927    open_progress_form(_("Formatting partitions"),
     
    1085937    log_msg(1, "Stopping all RAID devices");
    1086938    stop_all_raid_devices(mountlist);
    1087     system("sync");
    1088     system("sync");
    1089     system("sync");
     939    sync();
     940    sync();
     941    sync();
    1090942    sleep(2);
    1091943    log_msg(1, "Prepare soft-RAIDs");   // prep and format too
     
    1096948            if (interactively) {
    1097949                // ask user if we should format the current device
    1098                 sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     950                asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    1099951                        me->mountpoint);
    1100952                do_it = ask_me_yes_or_no(tmp);
     953                paranoid_free(tmp);
    1101954            } else {
    1102955                do_it = TRUE;
     
    1109962        }
    1110963    }
    1111     system("sync");
    1112     system("sync");
    1113     system("sync");
     964    sync();
     965    sync();
     966    sync();
    1114967    sleep(2);
    1115968// This last step is probably necessary
     
    1126979            newtSuspend();
    1127980        }
    1128 /*
    1129         for(i=0; i<3; i++)
    1130           {
    1131             res = do_my_funky_lvm_stuff(FALSE, FALSE);
    1132             if (!res) { break; }
    1133             sleep(3);
    1134             res = do_my_funky_lvm_stuff(TRUE, FALSE);
    1135             sleep(3);
    1136           }
    1137         if (res) {
    1138             log_msg(1, "Vacuum-packing...");
    1139 */
    1140981        res = do_my_funky_lvm_stuff(FALSE, TRUE);
    1141 /*
    1142         }
    1143 */
    1144982        if (!g_text_mode) {
    1145983            newtResume();
     
    1150988            log_to_screen("Failed to initialize LVM");
    1151989        }
    1152         // retval += res;
    1153990        if (res) {
    1154991            retval++;
     
    1162999        me = &mountlist->el[lino];  // the current mountlist entry
    11631000        if (!strcmp(me->mountpoint, "image")) {
    1164             sprintf(tmp, "Not formatting %s - it's an image", me->device);
     1001            asprintf(&tmp, "Not formatting %s - it's an image", me->device);
    11651002            log_it(tmp);
     1003            paranoid_free(tmp);
    11661004        } else if (!strcmp(me->format, "raid")) {
    1167             sprintf(tmp, "Not formatting %s - it's a raid-let",
     1005            asprintf(&tmp, "Not formatting %s - it's a raid-let",
    11681006                    me->device);
    11691007            log_it(tmp);
     1008            paranoid_free(tmp);
    11701009            continue;
    11711010        } else if (!strcmp(me->format, "lvm")) {
    1172             sprintf(tmp, "Not formatting %s - it's an LVM", me->device);
     1011            asprintf(&tmp, "Not formatting %s - it's an LVM", me->device);
    11731012            log_it(tmp);
     1013            paranoid_free(tmp);
    11741014            continue;
    11751015        } else if (!strncmp(me->device, "/dev/md", 7)) {
    1176             sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",
     1016            asprintf(&tmp, "Already formatted %s - it's a soft-RAID dev",
    11771017                    me->device);
    11781018            log_it(tmp);
     1019            paranoid_free(tmp);
    11791020            continue;
    11801021        } else if (!does_file_exist(me->device)
    11811022                   && strncmp(me->device, "/dev/hd", 7)
    11821023                   && strncmp(me->device, "/dev/sd", 7)) {
    1183             sprintf(tmp,
     1024            asprintf(&tmp,
    11841025                    "Not formatting %s yet - doesn't exist - probably an LVM",
    11851026                    me->device);
    11861027            log_it(tmp);
     1028            paranoid_free(tmp);
    11871029            continue;
    11881030        } else {
    11891031            if (interactively) {
    11901032                // ask user if we should format the current device
    1191                 sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     1033                asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    11921034                        me->mountpoint);
    11931035                do_it = ask_me_yes_or_no(tmp);
     1036                paranoid_free(tmp);
    11941037            } else {
    11951038                do_it = TRUE;
     
    12151058        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    12161059        log_to_screen
    1217             (_("Errors occurred during the formatting of your hard drives."));
     1060            (_
     1061             ("Errors occurred during the formatting of your hard drives."));
    12181062    } else {
    12191063        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    12201064    }
    12211065
    1222     sprintf(tmp, "format_everything () - %s",
     1066    asprintf(&tmp, "format_everything () - %s",
    12231067            (retval) ? "failed!" : "finished successfully");
    12241068    log_it(tmp);
     1069    paranoid_free(tmp);
    12251070
    12261071    if (g_partition_table_locked_up > 0) {
     
    12281073//123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    12291074            log_to_screen
    1230                 (_("Partition table locked up %d times. At least one 'mkfs' (format) command"),
     1075                (_
     1076                 ("Partition table locked up %d times. At least one 'mkfs' (format) command"),
    12311077                 g_partition_table_locked_up);
    1232             log_to_screen
    1233                 (_("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"));
    1234             log_to_screen
    1235                 (_("to refresh its copy of the partition table causes the kernel to lock the "));
    1236             log_to_screen
    1237                 (_("partition table. I believe this has just happened."));
     1078            log_to_screen(_
     1079                          ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"));
     1080            log_to_screen(_
     1081                          ("to refresh its copy of the partition table causes the kernel to lock the "));
     1082            log_to_screen(_
     1083                          ("partition table. I believe this has just happened."));
    12381084            if (ask_me_yes_or_no
    1239                 (_("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")))
     1085                (_
     1086                 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")))
    12401087            {
    1241                 system("sync");
    1242                 system("sync");
    1243                 system("sync");
     1088                sync();
     1089                sync();
     1090                sync();
    12441091                system("reboot");
    12451092            }
    12461093        } else {
    12471094            log_to_screen
    1248                 (_("Partition table locked up %d time%c. However, disk formatting succeeded."),
     1095                (_
     1096                 ("Partition table locked up %d time%c. However, disk formatting succeeded."),
    12491097                 g_partition_table_locked_up,
    12501098                 (g_partition_table_locked_up == 1) ? '.' : 's');
     
    12541102    system("clear");
    12551103    newtResume();
    1256     paranoid_free(tmp);
    12571104    return (retval);
    12581105}
     
    12811128    /** end **************************************************************/
    12821129
    1283     malloc_string(tmp);
    12841130    assert_string_is_neither_NULL_nor_zerolength(drivename);
    12851131
    12861132    if (devno_we_must_allow_for >= 5) {
    1287         sprintf(tmp, "Making dummy primary %s%d", drivename, 1);
     1133        asprintf(&tmp, "Making dummy primary %s%d", drivename, 1);
    12881134        log_it(tmp);
     1135        paranoid_free(tmp);
     1136
    12891137        g_maximum_progress++;
    12901138        res =
     
    12991147    }
    13001148    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1301         sprintf(tmp, "Creating dummy partition %s%d", drivename,
     1149        asprintf(&tmp, "Creating dummy partition %s%d", drivename,
    13021150                current_devno);
    13031151        log_it(tmp);
     1152        paranoid_free(tmp);
     1153
    13041154        g_maximum_progress++;
    13051155        res =
     
    13091159        previous_devno = current_devno;
    13101160    }
    1311     paranoid_free(tmp);
    13121161    return (previous_devno);
    13131162}
     
    13401189    }
    13411190}
     1191
    13421192
    13431193/* The following 2 functions are stolen from /usr/src/sbin/disklabel/disklabel.c */
     
    14421292    static struct disklabel loclab;
    14431293    struct partition *dp;
    1444     char lnamebuf[BBSIZE];
     1294    char *lnamebuf;
    14451295    int f;
    14461296    u_int secsize, u;
    14471297    off_t mediasize;
    14481298
    1449     (void) snprintf(lnamebuf, BBSIZE, "%s", dkname);
     1299    asprintf(&lnamebuf, "%s", dkname);
    14501300    if ((f = open(lnamebuf, O_RDONLY)) == -1) {
    14511301        warn("cannot open %s", lnamebuf);
     1302        paranoid_free(lnamebuf);
    14521303        return (NULL);
    14531304    }
     1305    paranoid_free(lnamebuf);
    14541306
    14551307    /* New world order */
     
    15221374                         char *drivename, struct disklabel *ret)
    15231375{
    1524     char subdev_str[MAX_STR_LEN];
    1525     char command[MAX_STR_LEN];
     1376    char *subdev_str;
     1377    char *command;
    15261378    struct disklabel *lp;
    15271379    int i, lo = 0;
     
    15331385    for (c = 'a'; c <= 'z'; ++c) {
    15341386        int idx;
    1535         sprintf(subdev_str, "%s%c", drivename, c);
     1387        asprintf(&subdev_str, "%s%c", drivename, c);
    15361388        if ((idx = find_device_in_mountlist(mountlist, subdev_str)) < 0) {
    15371389            lp->d_partitions[c - 'a'].p_size = 0;
     
    15581410                lp->d_partitions[c - 'a'].p_fstype = FS_OTHER;
    15591411        }
     1412        paranoid_free(subdev_str);
    15601413    }
    15611414
     
    15881441    display_disklabel(ftmp, lp);
    15891442    fclose(ftmp);
    1590     sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));
     1443    asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename));
    15911444    retval += run_program_and_log_output(command, TRUE);
    1592     sprintf(command, "disklabel -R %s /tmp/disklabel",
     1445    paranoid_free(command);
     1446
     1447    asprintf(&command, "disklabel -R %s /tmp/disklabel",
    15931448            canonical_name(drivename));
    15941449    retval += run_program_and_log_output(command, TRUE);
     1450    paranoid_free(command);
    15951451    if (ret)
    15961452        *ret = *lp;
     
    16091465{
    16101466    /** int *************************************************************/
    1611     int current_devno;
     1467    int current_devno = 0;
    16121468    int previous_devno = 0;
    1613     int lino;
     1469    int lino = 0;
    16141470    int retval = 0;
    1615     int i;
     1471    int i = 0;
    16161472    FILE *pout_to_fdisk = NULL;
    16171473
    16181474#ifdef __FreeBSD__
    16191475    bool fbsd_part = FALSE;
    1620     char subdev_str[MAX_STR_LEN];
     1476    char *subdev_str = NULL;
    16211477#endif
    16221478
     
    16251481
    16261482    /** buffers *********************************************************/
    1627     char *device_str;
    1628     char *format;
    1629     char *tmp;
     1483    char *device_str = NULL;
     1484    char *format = NULL;
     1485    char *tmp = NULL;
     1486    char *tmp1 = NULL;
    16301487
    16311488    /** end *************************************************************/
     
    16341491    assert_string_is_neither_NULL_nor_zerolength(drivename);
    16351492
    1636     malloc_string(device_str);
    1637     malloc_string(format);
    1638     malloc_string(tmp);
    1639 
    1640     sprintf(tmp, "Partitioning drive %s", drivename);
     1493    asprintf(&tmp, "Partitioning drive %s", drivename);
    16411494    log_it(tmp);
     1495    paranoid_free(tmp);
    16421496
    16431497#if __FreeBSD__
     
    16461500#else
    16471501    make_hole_for_file(FDISK_LOG);
    1648     sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1502    asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1503            FDISK_LOG);
    16491504    pout_to_fdisk = popen(tmp, "w");
     1505    paranoid_free(tmp);
     1506
    16501507    if (!pout_to_fdisk) {
    1651         log_to_screen(_("Cannot call parted2fdisk to configure %s"), drivename);
    1652         paranoid_free(device_str);
    1653         paranoid_free(format);
    1654         paranoid_free(tmp);
     1508        log_to_screen(_("Cannot call parted2fdisk to configure %s"),
     1509                      drivename);
    16551510        return (1);
    16561511    }
    16571512#endif
    16581513    for (current_devno = 1; current_devno < 99; current_devno++) {
    1659         build_partition_name(device_str, drivename, current_devno);
     1514        device_str = build_partition_name(drivename, current_devno);
    16601515        lino = find_device_in_mountlist(mountlist, device_str);
    16611516
     
    16701525                // try DangerouslyDedicated mode
    16711526                for (c = 'a'; c <= 'z'; c++) {
    1672                     sprintf(subdev_str, "%s%c", drivename, c);
    1673                     if (find_device_in_mountlist(mountlist, subdev_str) >
    1674                         0) {
     1527                    asprintf(&subdev_str, "%s%c", drivename, c);
     1528                    if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    16751529                        fbsd_part = TRUE;
    16761530                    }
     1531                    paranoid_free(subdev_str);
    16771532                }
    16781533                if (fbsd_part) {
     
    16851540                    if (system(command)) {
    16861541                        log_to_screen
    1687                             (_("Warning! Unable to make the drive bootable."));
     1542                            (_
     1543                             ("Warning! Unable to make the drive bootable."));
    16881544                    }
    16891545                    paranoid_free(device_str);
    1690                     paranoid_free(format);
    1691                     paranoid_free(tmp);
     1546
    16921547                    return r;
    16931548                }
    16941549            }
    16951550            for (c = 'a'; c <= 'z'; c++) {
    1696                 sprintf(subdev_str, "%s%c", device_str, c);
     1551                asprintf(&subdev_str, "%s%c", device_str, c);
    16971552                if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    16981553                    fbsd_part = TRUE;
    16991554                }
     1555                paranoid_free(subdev_str);
    17001556            }
    17011557            // Now we check the subpartitions of the current partition.
     
    17031559                int i, line;
    17041560
    1705                 strcpy(format, "ufs");
     1561                asprintf(&format, "ufs");
    17061562                partsize = 0;
    17071563                for (i = 'a'; i < 'z'; ++i) {
    1708                     sprintf(subdev_str, "%s%c", device_str, i);
     1564                    asprintf(&subdev_str, "%s%c", device_str, i);
    17091565                    line = find_device_in_mountlist(mountlist, subdev_str);
     1566                    paranoid_free(subdev_str);
     1567
    17101568                    if (line > 0) {
    17111569                        // We found one! Add its size to the total size.
     
    17301588#if __FreeBSD__
    17311589            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1732 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1733 //          if (run_program_and_log_output(tmp, TRUE)) {
    17341590            file = open(drivename, O_WRONLY);
    17351591            if (!file) {
    1736                 sprintf(tmp,
     1592                asprintf(&tmp,
    17371593                        _("Warning - unable to open %s for wiping it's partition table"),
    17381594                        drivename);
    17391595                log_to_screen(tmp);
     1596                paranoid_free(tmp);
    17401597            }
    17411598
    17421599            for (i = 0; i < 512; i++) {
    17431600                if (!write(file, "\0", 1)) {
    1744                     sprintf(tmp, _("Warning - unable to write to %s"),
     1601                    asprintf(&tmp, _("Warning - unable to write to %s"),
    17451602                            drivename);
    17461603                    log_to_screen(tmp);
     1604                    paranoid_free(tmp);
    17471605                }
    17481606            }
    1749             system("sync");
     1607            sync();
    17501608#else
    17511609            iamhere("New, kernel-friendly partition remover");
     
    17541612                fflush(pout_to_fdisk);
    17551613            }
    1756 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1757 //          run_program_and_log_output(tmp, 1);
    17581614#endif
    17591615            if (current_devno > 1) {
     
    17671623#endif
    17681624
    1769             strcpy(format, mountlist->el[lino].format);
     1625            asprintf(&format, mountlist->el[lino].format);
    17701626            partsize = mountlist->el[lino].size;
    17711627
     
    17761632        if (current_devno == 5 && previous_devno == 4) {
    17771633            log_to_screen
    1778                 (_("You must leave at least one partition spare as the Extended partition."));
     1634                (_
     1635                 ("You must leave at least one partition spare as the Extended partition."));
    17791636            paranoid_free(device_str);
    17801637            paranoid_free(format);
    1781             paranoid_free(tmp);
     1638
    17821639            return (1);
    17831640        }
     
    17891646#ifdef __FreeBSD__
    17901647        if ((current_devno <= 4) && fbsd_part) {
    1791             sprintf(tmp, "disklabel -B %s", basename(device_str));
     1648            asprintf(&tmp, "disklabel -B %s", basename(device_str));
    17921649            retval += label_drive_or_slice(mountlist, device_str, 0);
    17931650            if (system(tmp)) {
     
    17951652                    (_("Warning! Unable to make the slice bootable."));
    17961653            }
     1654            paranoid_free(tmp);
    17971655        }
    17981656#endif
     
    18001658        previous_devno = current_devno;
    18011659    }
     1660    paranoid_free(device_str);
     1661    paranoid_free(format);
    18021662
    18031663    if (pout_to_fdisk) {
    1804 // mark relevant partition as bootable
    1805         sprintf(tmp, "a\n%s\n",
    1806                 call_program_and_get_last_line_of_output
    1807                 ("make-me-bootable /tmp/mountlist.txt dummy"));
     1664        // mark relevant partition as bootable
     1665        tmp1 = call_program_and_get_last_line_of_output
     1666                ("make-me-bootable /tmp/mountlist.txt dummy");
     1667        asprintf(&tmp, "a\n%s\n", tmp1);
     1668        paranoid_free(tmp1);
     1669
    18081670        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1809 // close fdisk
     1671        paranoid_free(tmp);
     1672
     1673        // close fdisk
    18101674        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    1811         system("sync");
     1675        sync();
    18121676        paranoid_pclose(pout_to_fdisk);
    18131677        log_msg(0,
    18141678                "------------------- fdisk.log looks like this ------------------");
    1815         sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
     1679        asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    18161680        system(tmp);
     1681        paranoid_free(tmp);
     1682
    18171683        log_msg(0,
    18181684                "------------------- end of fdisk.log... word! ------------------");
    1819         sprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
     1685        asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
    18201686        if (!run_program_and_log_output(tmp, 5)) {
    18211687            g_partition_table_locked_up++;
    18221688            log_to_screen
    1823                 (_("A flaw in the Linux kernel has locked the partition table."));
    1824         }
    1825     }
    1826     paranoid_free(device_str);
    1827     paranoid_free(format);
    1828     paranoid_free(tmp);
     1689                (_
     1690                 ("A flaw in the Linux kernel has locked the partition table."));
     1691        }
     1692        paranoid_free(tmp);
     1693    }
    18291694    return (retval);
    18301695}
     1696
    18311697
    18321698/**
     
    18511717    char *partition_name;
    18521718    char *tmp;
    1853     char *logfile;
    18541719    char *output;
    18551720
     
    18611726    /** end ***************************************************************/
    18621727
    1863     malloc_string(program);
    1864     malloc_string(partition_name);
    1865     malloc_string(tmp);
    1866     malloc_string(logfile);
    1867     malloc_string(output);
    1868 
    18691728    assert_string_is_neither_NULL_nor_zerolength(drive);
    18701729    assert(format != NULL);
     
    18741733
    18751734    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    1876         sprintf(tmp, "Not partitioning %s - it is a virtual drive", drive);
     1735        asprintf(&tmp, "Not partitioning %s - it is a virtual drive", drive);
    18771736        log_it(tmp);
    1878         paranoid_free(program);
    1879         paranoid_free(partition_name);
    18801737        paranoid_free(tmp);
    1881         paranoid_free(logfile);
    1882         paranoid_free(output);
    18831738        return (0);
    18841739    }
    1885     build_partition_name(partition_name, drive, partno);
     1740    partition_name = build_partition_name(drive, partno);
    18861741    if (partsize <= 0) {
    1887         sprintf(tmp, "Partitioning device %s (max size)", partition_name);
     1742        asprintf(&tmp, "Partitioning device %s (max size)", partition_name);
    18881743    } else {
    1889         sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,
     1744        asprintf(&tmp, "Partitioning device %s (%lld MB)", partition_name,
    18901745                (long long) partsize / 1024);
    18911746    }
    18921747    update_progress_form(tmp);
    18931748    log_it(tmp);
     1749    paranoid_free(tmp);
    18941750
    18951751    if (is_this_device_mounted(partition_name)) {
    1896         sprintf(tmp, _("%s is mounted, and should not be partitioned"),
     1752        asprintf(&tmp, _("%s is mounted, and should not be partitioned"),
    18971753                partition_name);
     1754        paranoid_free(partition_name);
     1755
    18981756        log_to_screen(tmp);
    1899         paranoid_free(program);
    1900         paranoid_free(partition_name);
    19011757        paranoid_free(tmp);
    1902         paranoid_free(logfile);
    1903         paranoid_free(output);
    19041758        return (1);
    1905 /*
    1906     } else if (does_partition_exist(drive, partno)) {
    1907         sprintf(tmp, "%s already has a partition", partition_name);
    1908         log_to_screen(tmp);
    1909         return (1);
    1910 */
    1911     }
    1912 
    1913 
    1914     /*  sprintf(tmp,"Partitioning %s  ",partition_name); */
    1915     /*  mvaddstr_and_log_it(g_currentY+1,30,tmp); */
     1759    }
     1760
    19161761    p = (char *) strrchr(partition_name, '/');
    1917     sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
    1918     sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1762    asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
    19191763            MONDO_LOGFILE);
    19201764
    1921     /* BERLIOS: shoould not be called each time */
     1765    /* BERLIOS: should not be called each time */
    19221766    part_table_fmt = which_partition_format(drive);
    1923     output[0] = '\0';
    19241767    /* make it a primary/extended/logical */
    19251768    if (partno <= 4) {
    1926         sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1769        asprintf(&output,"n\np\n%d\n", partno);
    19271770    } else {
    19281771        /* MBR needs an extended partition if more than 4 partitions */
     
    19311774                if (prev_partno >= 4) {
    19321775                    log_to_screen
    1933                         (_("You need to leave at least one partition free, for 'extended/logical'"));
     1776                        (_
     1777                         ("You need to leave at least one partition free, for 'extended/logical'"));
     1778                    paranoid_free(partition_name);
    19341779                    paranoid_free(program);
    1935                     paranoid_free(partition_name);
    1936                     paranoid_free(tmp);
    1937                     paranoid_free(logfile);
     1780
    19381781                    paranoid_free(output);
    19391782                    return (1);
    19401783                } else {
    1941                     sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
    1942                             prev_partno + 1);
     1784                    asprintf(&output,"n\ne\n%d\n\n\n",prev_partno + 1);
    19431785                }
    19441786            }
    1945             strcat(output + strlen(output), "n\nl\n");
     1787            asprintf(&tmp,"%sn\nl\n",output);
     1788            paranoid_free(output);
     1789            output = tmp;
    19461790        } else {
    19471791            /* GPT allows more than 4 primary partitions */
    1948             sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1792            asprintf(&output,"n\np\n%d\n",partno);
    19491793        }
    19501794    }
    19511795    paranoid_free(part_table_fmt);
    1952     strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
     1796    /*start block (ENTER for next free blk */
     1797    asprintf(&tmp,"%s\n",output);
     1798    paranoid_free(output);
     1799    output = tmp;
     1800
    19531801    if (partsize > 0) {
    19541802        if (!strcmp(format, "7")) {
     
    19561804            partsize += 512;
    19571805        }
    1958         sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    1959     }
    1960     strcat(output + strlen(output), "\n");
     1806        asprintf(&tmp,"%s+%lldK", output,  (long long) (partsize));
     1807        paranoid_free(output);
     1808        output = tmp;
     1809    }
     1810    asprintf(&tmp,"%s\n",output);
     1811    paranoid_free(output);
     1812    output = tmp;
    19611813#if 0
    19621814/*
    19631815#endif
    1964     sprintf(tmp,"PARTSIZE = +%ld",(long)partsize);
     1816    asprintf(&tmp,"PARTSIZE = +%ld",(long)partsize);
    19651817    log_it(tmp);
     1818    paranoid_free(tmp);
     1819
    19661820    log_it("---fdisk command---");
    19671821    log_it(output);
     
    19771831        fput_string_one_char_at_a_time(pout_to_fdisk, output);
    19781832        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    1979         strcpy(tmp, last_line_of_file(FDISK_LOG));
     1833        tmp = last_line_of_file(FDISK_LOG);
    19801834        if (strstr(tmp, " (m ")) {
    19811835            log_msg(1, "Successfully created %s%d", drive, partno);
     
    19851839                    partno);
    19861840        }
     1841        paranoid_free(tmp);
     1842
    19871843        if (!retval) {
    19881844            log_msg(1, "Trying to set %s%d's partition type now", drive,
     
    20021858        }
    20031859    } else {
    2004         strcat(output, "w\n\n");
     1860        asprintf(&tmp,"%sw\n\n",output);
     1861        paranoid_free(output);
     1862        output = tmp;
     1863
    20051864        if (g_fprep) {
    20061865            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     
    20201879                                 format, -1);
    20211880            if (res) {
    2022                 sprintf(tmp, "Failed to vacuum-pack %s", partition_name);
     1881                asprintf(&tmp, "Failed to vacuum-pack %s", partition_name);
    20231882                log_it(tmp);
     1883                paranoid_free(tmp);
     1884
    20241885                retval++;
    20251886            } else {
     
    20321893                                   partsize);
    20331894            if (retval) {
    2034                 sprintf(tmp, "Partitioned %s but failed to set its type",
     1895                asprintf(&tmp, "Partitioned %s but failed to set its type",
    20351896                        partition_name);
    20361897                log_it(tmp);
     1898                paranoid_free(tmp);
    20371899            } else {
    20381900                if (partsize > 0) {
    2039                     sprintf(tmp, "Partition %s created+configured OK",
     1901                    asprintf(&tmp, "Partition %s created+configured OK",
    20401902                            partition_name);
    20411903                    log_to_screen(tmp);
     1904                    paranoid_free(tmp);
    20421905                } else {
    20431906                    log_it("Returning from a successful vacuum-pack");
     
    20451908            }
    20461909        } else {
    2047             sprintf(tmp, "Failed to partition %s", partition_name);
     1910            asprintf(&tmp, "Failed to partition %s", partition_name);
    20481911            if (partsize > 0) {
    20491912                log_to_screen(tmp);
     
    20511914                log_it(tmp);
    20521915            }
     1916            paranoid_free(tmp);
    20531917            retval++;
    20541918        }
     
    20561920    g_current_progress++;
    20571921    log_it("partition_device() --- leaving");
     1922    paranoid_free(partition_name);
    20581923    paranoid_free(program);
    2059     paranoid_free(partition_name);
    2060     paranoid_free(tmp);
    2061     paranoid_free(logfile);
    20621924    paranoid_free(output);
    20631925    return (retval);
    20641926}
    2065 
    20661927
    20671928
     
    21241985    open_progress_form(_("Partitioning devices"),
    21251986                       _("I am now going to partition all your drives."),
    2126                        _("This should not take more than five minutes."), "",
    2127                        mountlist->entries);
     1987                       _("This should not take more than five minutes."),
     1988                       "", mountlist->entries);
    21281989
    21291990    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    21381999        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    21392000        log_to_screen
    2140             (_("Errors occurred during the partitioning of your hard drives."));
     2001            (_
     2002             ("Errors occurred during the partitioning of your hard drives."));
    21412003    } else {
    21422004        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
     
    21682030{
    21692031    /** buffers *********************************************************/
    2170     char *partition;
    2171     char *command;
    2172     char *output;
    2173     char *tmp;
    2174     char *partcode;
    2175     char *logfile;
     2032    char *partition = NULL;
     2033    char *command = NULL;
     2034    char *output = NULL;
     2035    char *tmp = NULL;
     2036    char *tmp1 = NULL;
     2037    char *partcode = NULL;
    21762038
    21772039    /** pointers *********************************************************/
    2178     char *p;
    2179     FILE *fout;
     2040    char *p = NULL;
     2041    FILE *fout = NULL;
    21802042
    21812043    /** int **************************************************************/
     
    21872049    assert(format != NULL);
    21882050
    2189     malloc_string(partition);
    2190     malloc_string(command);
    2191     malloc_string(output);
    2192     malloc_string(tmp);
    2193     malloc_string(partcode);
    2194     malloc_string(logfile);
    2195 
    2196     build_partition_name(partition, drive, partno);
     2051    partition = build_partition_name(drive, partno);
    21972052    p = (char *) strrchr(partition, '/');
    2198     sprintf(logfile, "/tmp/fdisk-set-type.%s.log", ++p);
    21992053    if (strcmp(format, "swap") == 0) {
    2200         strcpy(partcode, "82");
     2054        asprintf(&partcode, "82");
    22012055    } else if (strcmp(format, "vfat") == 0) {
    22022056        if (partsize / 1024 > 8192) {
    2203             strcpy(partcode, "c");
     2057            asprintf(&partcode, "c");
    22042058        } else {
    2205             strcpy(partcode, "b");
     2059            asprintf(&partcode, "b");
    22062060        }
    22072061    } else if (strcmp(format, "ext2") == 0
     
    22092063               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
    22102064               || strcmp(format, "jfs") == 0) {
    2211         strcpy(partcode, "83");
     2065        asprintf(&partcode, "83");
    22122066    } else if (strcmp(format, "minix") == 0) {
    2213         strcpy(partcode, "81");
     2067        asprintf(&partcode, "81");
    22142068    } else if (strcmp(format, "raid") == 0) {
    2215         strcpy(partcode, "fd");
     2069        asprintf(&partcode, "fd");
    22162070    } else if ((strcmp(format, "ufs") == 0)
    22172071               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    2218         strcpy(partcode, "a5");
     2072        asprintf(&partcode, "a5");
    22192073    } else if (strcmp(format, "lvm") == 0) {
    2220         strcpy(partcode, "8e");
     2074        asprintf(&partcode, "8e");
    22212075    } else if (format[0] == '\0') { /* LVM physical partition */
    2222         partcode[0] = '\0';
     2076        asprintf(&partcode, "");
    22232077    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    2224         strcpy(partcode, format);
     2078        asprintf(&partcode, format);
    22252079    } else {
    22262080        /* probably an image */
    2227         sprintf(tmp,
     2081        asprintf(&tmp,
    22282082                "Unknown format ('%s') - using supplied string anyway",
    22292083                format);
    22302084        mvaddstr_and_log_it(g_currentY++, 0, tmp);
     2085        paranoid_free(tmp);
    22312086#ifdef __FreeBSD__
    2232         strcpy(partcode, format);   // was a5
     2087        asprintf(&partcode, format);    // was a5
    22332088#else
    2234         strcpy(partcode, format);   // was 83
    2235 #endif
    2236     }
    2237     sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,
     2089        asprintf(&partcode, format);    // was 83
     2090#endif
     2091    }
     2092    asprintf(&tmp, "Setting %s's type to %s (%s)", partition, format,
    22382093            partcode);
     2094    paranoid_free(partition);
     2095
    22392096    log_msg(1, tmp);
     2097    paranoid_free(tmp);
    22402098    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    22412099
     
    22432101            res = 0;
    22442102            fput_string_one_char_at_a_time(pout_to_fdisk, "t\n");
     2103            tmp1 = last_line_of_file(FDISK_LOG);
    22452104            if (partno > 1
    2246                 || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
     2105                || strstr(tmp1, " (1-4)")) {
    22472106                log_msg(5, "Specifying partno (%d) - yay", partno);
    2248                 sprintf(tmp, "%d\n", partno);
     2107                asprintf(&tmp, "%d\n", partno);
    22492108                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    2250                 log_msg(5, "A - last line = '%s'",
    2251                         last_line_of_file(FDISK_LOG));
    2252             }
    2253 
    2254             sprintf(tmp, "%s\n", partcode);
     2109                paranoid_free(tmp);
     2110                paranoid_free(tmp1);
     2111                tmp1 = last_line_of_file(FDISK_LOG);
     2112                log_msg(5, "A - last line = '%s'", tmp1);
     2113            }
     2114            paranoid_free(tmp1);
     2115
     2116            asprintf(&tmp, "%s\n", partcode);
    22552117            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    2256             log_msg(5, "B - last line = '%s'",
    2257                     last_line_of_file(FDISK_LOG));
     2118            paranoid_free(tmp);
     2119            tmp1 = last_line_of_file(FDISK_LOG);
     2120            log_msg(5, "B - last line = '%s'",tmp1);
     2121            paranoid_free(tmp1);
     2122
    22582123            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    2259             log_msg(5, "C - last line = '%s'",
    2260                     last_line_of_file(FDISK_LOG));
    2261 
    2262             strcpy(tmp, last_line_of_file(FDISK_LOG));
     2124            tmp1 = last_line_of_file(FDISK_LOG);
     2125            log_msg(5, "C - last line = '%s'",tmp1);
     2126            paranoid_free(tmp1);
     2127
     2128            tmp = last_line_of_file(FDISK_LOG);
    22632129            if (!strstr(tmp, " (m ")) {
    22642130                log_msg(1, "last line = '%s'; part type set failed", tmp);
     
    22662132                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    22672133            }
     2134            paranoid_free(tmp);
    22682135            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    22692136        } else {
    2270             sprintf(output, "t\n%d\n%s\n", partno, partcode);
    2271             strcat(output, "w\n");
    2272             sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
     2137            asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
     2138            asprintf(&command, "parted2fdisk %s >> %s 2>> %s", drive,
    22732139                    MONDO_LOGFILE, MONDO_LOGFILE);
    22742140            log_msg(5, "output = '%s'", output);
     
    22842150                paranoid_pclose(fout);
    22852151            }
    2286         }
     2152            paranoid_free(command);
     2153            paranoid_free(output);
     2154        }
     2155        /* BERLIOS: Useless as command not initialized in all cases
    22872156        if (res) {
    22882157            log_OS_error(command);
    22892158        }
    2290     }
    2291 
    2292     paranoid_free(partition);
    2293     paranoid_free(command);
    2294     paranoid_free(output);
    2295     paranoid_free(tmp);
     2159        */
     2160    }
    22962161    paranoid_free(partcode);
    2297     paranoid_free(logfile);
     2162
    22982163
    22992164    return (res);
     
    23132178
    23142179    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    2315     malloc_string(program);
    23162180
    23172181#ifdef __FreeBSD__
     
    23202184        return 1;
    23212185    }
    2322     sprintf(program, "vinum start -f %s", raid_device);
     2186    asprintf(&program, "vinum start -f %s", raid_device);
    23232187#else
    2324     sprintf(program, "raidstart %s", raid_device);
     2188    asprintf(&program, "raidstart %s", raid_device);
    23252189//      sprintf (program, "raidstart " RAID_DEVICE_STUB "*");
    23262190#endif
     
    23302194        fprintf(g_fprep, "%s\n", program);
    23312195    }
     2196    paranoid_free(program);
     2197
    23322198    if (res) {
    23332199        log_msg(1, "Warning - failed to start RAID device %s",
     
    23382204    return (retval);
    23392205}
    2340 
    23412206
    23422207
     
    23582223
    23592224    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    2360     malloc_string(program);
    23612225
    23622226#ifdef __FreeBSD__
     
    23652229        return 1;
    23662230    }
    2367     sprintf(program, "vinum stop -f %s", raid_device);
     2231    asprintf(&program, "vinum stop -f %s", raid_device);
    23682232#else
    2369     // use raidstop if it exists, otherwise use mdadm
    2370     if (run_program_and_log_output("which raidstop", FALSE)) {
    2371         sprintf(program, "mdadm -S %s", raid_device);
     2233    // use raidstop if it exists, otherwise use mdadm
     2234    if (run_program_and_log_output("which raidstop", FALSE)) {
     2235        asprintf(&program, "mdadm -S %s", raid_device);
    23722236    } else {
    2373         sprintf(program, "raidstop %s", raid_device);
     2237        asprintf(&program, "raidstop %s", raid_device);
    23742238    }
    23752239#endif
     
    23792243        fprintf(g_fprep, "%s\n", program);
    23802244    }
     2245    paranoid_free(program);
     2246
    23812247    if (res) {
    23822248        log_msg(1, "Warning - failed to stop RAID device %s", raid_device);
     
    24092275    return (retval);
    24102276}
     2277
    24112278
    24122279/**
     
    24212288    int retval = 0;
    24222289#ifndef __FreeBSD__
    2423     int res;
     2290    int res = 0;
    24242291#endif
    24252292
    24262293    /** char ************************************************************/
    2427     char *incoming;
     2294    char *incoming = NULL;
    24282295#ifndef __FreeBSD__
    2429     char *dev;
     2296    char *dev = NULL;
    24302297#endif
    24312298    /** pointers ********************************************************/
    24322299#ifndef __FreeBSD__
    2433     char *p;
    2434 #endif
    2435     FILE *fin;
    2436     int i;
     2300    char *p = NULL;
     2301#endif
     2302    FILE *fin = NULL;
     2303    int i = 0;
     2304    size_t n = 0;
    24372305
    24382306    /** end ****************************************************************/
    24392307
    2440     malloc_string(dev);
    2441     malloc_string(incoming);
    24422308    assert(mountlist != NULL);
    24432309
     
    24492315             "r");
    24502316        if (!fin) {
    2451             paranoid_free(dev);
    2452             paranoid_free(incoming);
    24532317            return (1);
    24542318        }
    2455         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2456              fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2319        for (getline(&incoming, &n, fin); !feof(fin);
     2320             getline(&incoming, &n, fin)) {
    24572321            retval += stop_raid_device(incoming);
    24582322        }
     
    24612325        if (!fin) {
    24622326            log_OS_error("/proc/mdstat");
    2463             paranoid_free(dev);
    2464             paranoid_free(incoming);
    24652327            return (1);
    24662328        }
    2467         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2468              fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2329        for (getline(&incoming, &n, fin); !feof(fin);
     2330             getline(&incoming, &n, fin)) {
    24692331            for (p = incoming;
    24702332                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
    24712333                                || !isdigit(*(p + 2))); p++);
    24722334            if (*p != '\0') {
    2473                 sprintf(dev, "/dev/%s", p);
     2335                asprintf(&dev, "/dev/%s", p);
     2336                /* BERLIOS : 32 Hard coded value */
    24742337                for (p = dev; *p > 32; p++);
    24752338                *p = '\0';
    24762339                res = stop_raid_device(dev);
    2477             }
    2478         }
    2479 #endif
     2340                paranoid_free(dev);
     2341            }
     2342        }
     2343#endif
     2344        paranoid_free(incoming);
    24802345    }
    24812346    paranoid_fclose(fin);
     
    24832348        log_msg(1, "Warning - unable to stop some RAID devices");
    24842349    }
    2485     paranoid_free(dev);
    2486     paranoid_free(incoming);
    2487     system("sync");
    2488     system("sync");
    2489     system("sync");
     2350    sync();
     2351    sync();
     2352    sync();
    24902353    sleep(1);
    24912354    return (retval);
    24922355}
    2493 
    24942356
    24952357
     
    25102372    /** end ***************************************************************/
    25112373
    2512     malloc_string(tmp);
    25132374    assert_string_is_neither_NULL_nor_zerolength(format);
    25142375    assert(program != NULL);
     
    25422403        sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    25432404#endif
    2544         sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2405        asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format,
    25452406                program);
    25462407        log_it(tmp);
     2408        paranoid_free(tmp);
    25472409        res = 0;
    25482410    }
    2549     paranoid_free(tmp);
    25502411    return (res);
    25512412}
     
    25732434    /** end *************************************************************/
    25742435
    2575     malloc_string(tmp);
    25762436    assert(mountlist != NULL);
    25772437    assert_string_is_neither_NULL_nor_zerolength(drive_name);
     
    25842444            original_size_of_drive += mountlist->el[partno].size;
    25852445        } else {
    2586             sprintf(tmp, "Skipping %s", mountlist->el[partno].device);
     2446            asprintf(&tmp, "Skipping %s", mountlist->el[partno].device);
    25872447//                      log_to_screen(tmp);
     2448            paranoid_free(tmp);
    25882449        }
    25892450    }
    25902451    original_size_of_drive = original_size_of_drive / 1024;
    2591     paranoid_free(tmp);
    25922452    return (original_size_of_drive);
    25932453}
     
    26322492    /** end **************************************************************/
    26332493
    2634     malloc_string(tmp);
    26352494    assert(mountlist != NULL);
    26362495    assert_string_is_neither_NULL_nor_zerolength(drive_name);
     
    26392498        if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))
    26402499            == 0) {
    2641             paranoid_free(tmp);
    26422500            return;
    26432501        }
     
    26532511    if (current_size_of_drive <= 0) {
    26542512        log_it("Not resizing to match %s - can't find drive", drive_name);
    2655         paranoid_free(tmp);
    26562513        return;
    26572514    }
    2658     sprintf(tmp, _("Expanding entries to suit drive %s (%ld MB)"), drive_name,
    2659             current_size_of_drive);
     2515    asprintf(&tmp, _("Expanding entries to suit drive %s (%ld MB)"),
     2516            drive_name, current_size_of_drive);
    26602517    log_to_screen(tmp);
     2518    paranoid_free(tmp);
    26612519
    26622520    drivemntlist = malloc(sizeof(struct mountlist_reference));
     
    26752533
    26762534    if (original_size_of_drive <= 0) {
    2677         sprintf(tmp, _("Cannot resize %s's entries. Drive not found."),
     2535        asprintf(&tmp, _("Cannot resize %s's entries. Drive not found."),
    26782536                drive_name);
    26792537        log_to_screen(tmp);
     
    26832541    factor =
    26842542        (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2685     sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2543    asprintf(&tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
    26862544            drive_name, original_size_of_drive, current_size_of_drive,
    26872545            factor);
    26882546    log_to_screen(tmp);
     2547    paranoid_free(tmp);
    26892548
    26902549    lastpart = drivemntlist->entries - 1;
     
    27052564            newsizL = (long) new_size;
    27062565        }
    2707         sprintf(tmp, _("Changing %s from %lld KB to %ld KB"),
     2566        asprintf(&tmp, _("Changing %s from %lld KB to %ld KB"),
    27082567                drivemntlist->el[partno]->device,
    27092568                drivemntlist->el[partno]->size, newsizL);
    27102569        log_to_screen(tmp);
     2570        paranoid_free(tmp);
    27112571        drivemntlist->el[partno]->size = newsizL;
    27122572    }
    27132573    final_size = get_phys_size_of_drive(drive_name);
    2714     sprintf(tmp, _("final_size = %ld MB"), final_size);
     2574    asprintf(&tmp, _("final_size = %ld MB"), final_size);
    27152575    log_to_screen(tmp);
    27162576    paranoid_free(tmp);
     
    27782638    log_msg(1, "Creating list of partitions for drive %s", drive_name);
    27792639
    2780     tmp_drive_name = strdup(drive_name);
     2640    asprintf(&tmp_drive_name,drive_name);
    27812641    if (!tmp_drive_name)
    27822642        fatal_error("Out of memory");
     
    27982658        }
    27992659    }
    2800     if (tmp_drive_name)
    2801         free(tmp_drive_name);
     2660    paranoid_free(tmp_drive_name);
    28022661}
    28032662
  • trunk/mondo/mondo/mondorestore/mondo-restore-EXT.h

    r426 r688  
    1 /* mondo-restore-EXT.h */
     1/*
     2 * $Id$
     3**/
    24
    35#ifdef __FreeBSD__
  • 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                                                     *
  • trunk/mondo/mondo/mondorestore/mondo-restore.h

    r59 r688  
    1 /* mondo-restore.h
     1/*
    22 * $Id$
    3  */
     3**/
    44
    55/**************************************************************************
     
    2222int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
    2323                 struct raidlist_itself *);
    24 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *,
    25                                  char *);
    2624int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long,
    2725                                     char *, long long, struct s_node *,
  • trunk/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h

    r59 r688  
    1 /* mondo-rstr-compare-EXT.h */
     1/*
     2 * $Id$
     3**/
    24
    35
  • trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c

    r524 r688  
    11/***************************************************************************
    2        mondo-compare.c  -  compares mondoarchive data
    3                              -------------------
    4     begin                : Fri Apr 25 2003
    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 
    26 10/21/2003
    27 - changed "/mnt/cdrom" to MNT_CDROM
    28 
    29 10/18
    30 - don't say unknown compressor if no compressor at all
    31 
    32 09/17
    33 - cleaned up logging & conversion-to-changed.txt
    34 - cleaned up compare_mode()
    35 
    36 09/16
    37 - fixed bad malloc(),free() pairs in compare_a_biggiefile()
    38 
    39 09/14
    40 - compare_mode() --- a couple of strings were the wrong way round,
    41   e.g. changed.txt and changed.files
    42 
    43 05/05
    44 - exclude /dev/ * from list of changed files
    45 
    46 04/30
    47 - added textonly mode
    48 
    49 04/27
    50 - improved compare_mode() to allow for ISO/cd/crazy people
    51 
    52 04/25
    53 - first incarnation
    54 */
     2 * $Id$ - compares mondoarchive data
     3**/
    554
    565
     
    587#include "../common/mondostructures.h"
    598#include "../common/libmondo.h"
    60 //#include "../../config.h"
    619#include "mr-externs.h"
    6210#include "mondo-rstr-compare.h"
     
    6715#endif
    6816
    69 //static char cvsid[] = "$Id$";
    70 
    7117void popup_changelist_from_file(char *);
    7218
     
    8935
    9036  /** needs malloc *******/
    91     char *checksum_ptr;
    92     char *original_cksum_ptr;
    93     char *bigfile_fname_ptr;
    94     char *tmp_ptr;
    95     char *command_ptr;
    96 
    97     char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
    98 
    99     char *p;
    100     int i;
     37    char *checksum = NULL;
     38    char *original_cksum = NULL;
     39    char *bigfile_fname = NULL;
     40    char *tmp = NULL;
     41    char *tmp1 = NULL;
     42    char *command = NULL;
     43
     44    char *p = NULL;
     45    int i = 0;
     46    int n = 0;
    10147    int retval = 0;
    10248
    10349    struct s_filename_and_lstat_info biggiestruct;
    10450
    105     malloc_string(checksum);
    106     malloc_string(original_cksum);
    107     malloc_string(bigfile_fname);
    108     malloc_string(tmp);
    109     malloc_string(command);
    110     malloc_string(checksum_ptr);
    111     malloc_string(original_cksum_ptr);
    112     malloc_string(bigfile_fname_ptr);
    113     malloc_string(command_ptr);
    114     malloc_string(tmp_ptr);
    115 
    116   /*********************************************************************
    117    * allocate memory clear test                sab 16 feb 2003         *
    118    *********************************************************************/
    11951    assert(bkpinfo != NULL);
    120     memset(checksum_ptr, '\0', sizeof(checksum));
    121     memset(original_cksum_ptr, '\0', sizeof(original_cksum));
    122     memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    123     memset(tmp_ptr, '\0', sizeof(tmp));
    124     memset(command_ptr, '\0', sizeof(command));
    125   /** end **/
    126 
    127     if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
     52
     53    tmp1 = slice_fname(bigfileno, 0, ARCHIVES_PATH, "");
     54    if (!does_file_exist(tmp1)) {
    12855        if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
    12956            insist_on_this_cd_number(bkpinfo, (++g_current_media_number));
    13057        } else {
    131             sprintf(tmp_ptr,
    132                     "No CD's left. No biggiefiles left. No prob, Bob.");
    133             log_msg(2, tmp_ptr);
     58            log_msg(2, "No CD's left. No biggiefiles left. No problem.");
    13459            return (0);
    13560        }
    13661    }
    137     if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
    138         sprintf(tmp_ptr,
    139                 _("Cannot open bigfile %ld (%s)'s info file"),
    140                 bigfileno + 1, bigfile_fname_ptr);
    141         log_to_screen(tmp_ptr);
     62    if (!(fin = fopen(tmp1, "r"))) {
     63        asprintf(&tmp, _("Cannot open bigfile %ld (%s)'s info file"),
     64                bigfileno + 1, tmp);
     65        log_to_screen(tmp);
     66        paranoid_free(tmp);
     67        paranoid_free(tmp1);
    14268        return (1);
    14369    }
     
    14571    paranoid_fclose(fin);
    14672
    147     strcpy(checksum_ptr, biggiestruct.checksum);
    148     strcpy(bigfile_fname_ptr, biggiestruct.filename);
    149 
    150     log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
    151     log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
    152 
    153     sprintf(tmp_ptr, _("Comparing %s"), bigfile_fname_ptr);
     73    asprintf(&checksum, biggiestruct.checksum);
     74    asprintf(&bigfile_fname, biggiestruct.filename);
     75
     76    log_msg(2, "biggiestruct.filename = %s", bigfile_fname);
     77    log_msg(2, "biggiestruct.checksum = %s", checksum);
    15478
    15579    if (!g_text_mode) {
    156         newtDrawRootText(0, 22, tmp_ptr);
     80        asprintf(&tmp, _("Comparing %s"), bigfile_fname);
     81        newtDrawRootText(0, 22, tmp);
    15782        newtRefresh();
    158     }
     83        paranoid_free(tmp);
     84    }
     85    /* BERLIOS: Useless ?
    15986    if (!checksum[0]) {
    16087        log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
    161     }
    162     if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
    163         strcpy(original_cksum_ptr, "IGNORE");
    164     } else {
    165         sprintf(command_ptr,
     88    } */
     89    if (!strncmp(bigfile_fname, "/dev/", 5)) {
     90        log_msg(2, _("Ignoring device %s"), bigfile_fname);
     91        return(0);
     92    } else {
     93        asprintf(&command,
    16694                "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt",
    167                 MNT_RESTORING, bigfile_fname_ptr);
    168     }
    169     log_msg(2, command_ptr);
    170     paranoid_system
    171         ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null");
    172     if (system(command_ptr)) {
     95                MNT_RESTORING, bigfile_fname);
     96    }
     97    log_msg(2, command);
     98    paranoid_system("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null");
     99    if (system(command)) {
    173100        log_OS_error("Warning - command failed");
    174         original_cksum[0] = '\0';
     101        paranoid_free(command);
     102        paranoid_free(bigfile_fname);
    175103        return (1);
    176104    } else {
     105        paranoid_free(command);
    177106        if (!(fin = fopen("/tmp/md5sum.txt", "r"))) {
    178             log_msg(2,
    179                     "Unable to open /tmp/md5sum.txt; can't get live checksum");
    180             original_cksum[0] = '\0';
     107            log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum");
     108            paranoid_free(bigfile_fname);
    181109            return (1);
    182110        } else {
    183             fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
     111            getline(&original_cksum, &n, fin);
    184112            paranoid_fclose(fin);
    185             for (i = strlen(original_cksum_ptr);
     113            for (i = strlen(original_cksum);
    186114                 i > 0 && original_cksum[i - 1] < 32; i--);
    187115            original_cksum[i] = '\0';
    188             p = (char *) strchr(original_cksum_ptr, ' ');
     116            p = (char *) strchr(original_cksum, ' ');
    189117            if (p) {
    190118                *p = '\0';
     
    192120        }
    193121    }
    194     sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
    195             bigfile_fname_ptr);
    196     if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
    197         strcat(tmp_ptr, " ... OK");
    198     } else {
    199         strcat(tmp_ptr, "... changed");
     122    if (!strcmp(checksum, original_cksum) != 0) {
     123        log_msg(1, "bigfile #%ld ('%s') ... OK", bigfileno + 1, bigfile_fname);
     124    } else {
     125        log_msg(1, "bigfile #%ld ('%s') ... changed", bigfileno + 1, bigfile_fname);
    200126        retval++;
    201127    }
    202     log_msg(1, tmp_ptr);
     128    paranoid_free(original_cksum);
     129    paranoid_free(checksum);
     130
    203131    if (retval) {
    204132        if (!(fout = fopen("/tmp/changed.txt", "a"))) {
    205133            fatal_error("Cannot openout changed.txt");
    206134        }
    207         fprintf(fout, "%s\n", bigfile_fname_ptr);
     135        fprintf(fout, "%s\n", bigfile_fname);
    208136        paranoid_fclose(fout);
    209137    }
    210 
    211     paranoid_free(original_cksum_ptr);
    212     paranoid_free(original_cksum);
    213     paranoid_free(bigfile_fname_ptr);
    214138    paranoid_free(bigfile_fname);
    215     paranoid_free(checksum_ptr);
    216     paranoid_free(checksum);
    217     paranoid_free(command_ptr);
    218     paranoid_free(command);
    219     paranoid_free(tmp_ptr);
    220     paranoid_free(tmp);
    221139
    222140    return (retval);
     
    238156    int res;
    239157    long noof_biggiefiles, bigfileno = 0;
    240     char tmp[MAX_STR_LEN];
     158    char *tmp;
    241159
    242160    assert(bkpinfo != NULL);
     
    254172    }
    255173    mvaddstr_and_log_it(g_currentY, 0,
    256                         _("Comparing large files                                                  "));
     174                        _
     175                        ("Comparing large files                                                  "));
    257176    open_progress_form(_("Comparing large files"),
    258177                       _("I am now comparing the large files"),
     
    260179                       noof_biggiefiles);
    261180    for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) {
    262         sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);
     181        asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1);
    263182        log_msg(1, tmp);
    264183        update_progress_form(tmp);
     184        paranoid_free(tmp);
    265185        res = compare_a_biggiefile(bkpinfo, bigfileno);
    266186        retval += res;
     
    268188    }
    269189    close_progress_form();
     190    /* BERLIOS: useless ?
    270191    return (0);
     192    */
    271193    if (retval) {
    272194        mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
     
    299221
    300222  /***  needs malloc *********/
    301     char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
    302         *compressor_exe;
    303 
    304     malloc_string(command);
    305     malloc_string(tmp);
    306     malloc_string(filelist_name);
    307     malloc_string(logfile);
    308     malloc_string(archiver_exe);
    309     malloc_string(compressor_exe);
     223    char *command = NULL;
     224    char *tmp = NULL;
     225    char *filelist_name = NULL;
     226    char *logfile = NULL;
     227    char *archiver_exe = NULL;
     228    char *compressor_exe = NULL;
    310229
    311230    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    312231    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    313     sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number);
    314     sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d",
     232    asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d",
    315233            current_tarball_number);
    316234
    317235    noof_lines = count_lines_in_file(filelist_name);
     236    paranoid_free(filelist_name);
    318237
    319238    if (strstr(tarball_fname, ".bz2")) {
    320         strcpy(compressor_exe, "bzip2");
     239        asprintf(&compressor_exe, "bzip2");
    321240    } else if (strstr(tarball_fname, ".lzo")) {
    322         strcpy(compressor_exe, "lzop");
    323     } else {
    324         compressor_exe[0] = '\0';
     241        asprintf(&compressor_exe, "lzop");
     242    } else {
     243        compressor_exe = NULL;
    325244    }
    326245
    327246    if (use_star) {
    328         strcpy(archiver_exe, "star");
    329     } else {
    330         strcpy(archiver_exe, "afio");
    331     }
    332 
    333     if (compressor_exe[0]) {
    334         strcpy(tmp, compressor_exe);
    335         if (!find_home_of_exe(tmp)) {
     247        asprintf(&archiver_exe, "star -bz");
     248    } else {
     249        asprintf(&archiver_exe, "afio");
     250    }
     251
     252    if (compressor_exe != NULL) {
     253        if (!find_home_of_exe(compressor_exe)) {
    336254            fatal_error("(compare_a_tarball) Compression program missing");
    337255        }
    338         if (use_star)           // star
    339         {
    340             if (!strcmp(compressor_exe, "bzip2")) {
    341                 strcat(archiver_exe, " -bz");
    342             } else {
     256        if (use_star) {
     257            if (strcmp(compressor_exe, "bzip2")) {
    343258                fatal_error
    344259                    ("(compare_a_tarball) Please use only bzip2 with star");
    345260            }
    346         } else                  // afio
    347         {
     261        } else {
     262            asprintf(&tmp, compressor_exe);
    348263            sprintf(compressor_exe, "-P %s -Z", tmp);
     264            paranoid_free(tmp);
    349265        }
    350266    }
     
    356272#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
    357273#endif
     274
     275    asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number);
    358276    if (use_star)               // doesn't use compressor_exe
    359277    {
    360         sprintf(command,
     278        asprintf(&command,
    361279                "%s -diff H=star file=%s >> %s 2>> %s",
    362280                archiver_exe, tarball_fname, logfile, logfile);
    363281    } else {
    364         sprintf(command,
     282        asprintf(&command,
    365283                "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s",
    366284                archiver_exe,
     
    369287    }
    370288#undef BUFSIZE
     289    paranoid_free(archiver_exe);
     290    paranoid_free(compressor_exe);
    371291
    372292    res = system(command);
     
    374294    if (res) {
    375295        log_OS_error(command);
    376         sprintf(tmp, "Warning - afio returned error = %d", res);
    377296    }
    378297    if (length_of_file(logfile) > 5) {
     
    385304        archiver_errors = 0;
    386305    }
    387     sprintf(tmp, "%ld difference%c in fileset #%d          ",
    388             archiver_errors, (archiver_errors != 1) ? 's' : ' ',
    389             current_tarball_number);
     306    paranoid_free(command);
     307
    390308    if (archiver_errors) {
    391         sprintf(tmp,
     309        asprintf(&tmp,
    392310                "Differences found while processing fileset #%d       ",
    393311                current_tarball_number);
    394312        log_msg(1, tmp);
     313        paranoid_free(tmp);
    395314    }
    396315    unlink(logfile);
    397     paranoid_free(command);
    398     paranoid_free(tmp);
    399     paranoid_free(filelist_name);
    400316    paranoid_free(logfile);
    401     malloc_string(archiver_exe);
    402     malloc_string(compressor_exe);
    403317    return (retval);
    404318}
     
    422336  /**  needs malloc **********/
    423337
    424     char *tarball_fname, *progress_str, *tmp;
     338    char *tarball_fname = NULL;
     339    char *progress_str = NULL;
     340    char *tmp = NULL;
    425341    long max_val;
    426 
    427     malloc_string(tarball_fname);
    428     malloc_string(progress_str);
    429     malloc_string(tmp);
    430342
    431343    assert(bkpinfo != NULL);
     
    434346
    435347    max_val = atol(tmp);
    436     sprintf(progress_str, _("Comparing with %s #%d "),
     348    paranoid_free(tmp);
     349
     350    asprintf(&progress_str, _("Comparing with %s #%d "),
    437351            media_descriptor_string(bkpinfo->backup_media_type),
    438352            g_current_media_number);
     
    448362        insist_on_this_cd_number(bkpinfo, g_current_media_number);
    449363        update_progress_form(progress_str);
    450         sprintf(tarball_fname,
     364        asprintf(&tarball_fname,
    451365                MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number);
    452366
    453367        if (!does_file_exist(tarball_fname)) {
    454             sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
     368            paranoid_free(tarball_fname);
     369            asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",
    455370                    current_tarball_number);
    456371        }
    457372        if (!does_file_exist(tarball_fname)) {
    458             sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",
     373            paranoid_free(tarball_fname);
     374            asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.",
    459375                    current_tarball_number);
    460376        }
    461377        if (!does_file_exist(tarball_fname)) {
    462             sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
     378            paranoid_free(tarball_fname);
     379            asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2",
    463380                    current_tarball_number);
    464381        }
    465382        if (!does_file_exist(tarball_fname)) {
    466             sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.",
     383            paranoid_free(tarball_fname);
     384            asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.",
    467385                    current_tarball_number);
    468386        }
     
    473391                == 0) {
    474392                log_msg(2, "OK, I think I'm done with tarballs...");
     393                paranoid_free(tarball_fname);
    475394                break;
    476395            }
    477396            log_msg(2, "OK, I think it's time for another CD...");
    478397            g_current_media_number++;
    479             sprintf(progress_str, _("Comparing with %s #%d "),
     398            paranoid_free(progress_str);
     399            asprintf(&progress_str, _("Comparing with %s #%d "),
    480400                    media_descriptor_string(bkpinfo->backup_media_type),
    481401                    g_current_media_number);
     
    483403        } else {
    484404            res = compare_a_tarball(tarball_fname, current_tarball_number);
     405            paranoid_free(tarball_fname);
    485406
    486407            g_current_progress++;
     
    488409        }
    489410    }
     411    paranoid_free(progress_str);
    490412    close_progress_form();
     413
    491414    if (retval) {
    492415        mvaddstr_and_log_it(g_currentY++, 74, _("Errors."));
     
    494417        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    495418    }
    496     paranoid_free(tarball_fname);
    497     paranoid_free(progress_str);
    498     paranoid_free(tmp);
    499419    return (retval);
    500420}
     
    519439{
    520440  /** needs malloc *********/
    521     char *tmp, *cwd, *new, *command;
     441    char *tmp = NULL;
     442    char *cwd = NULL;
     443    char *new = NULL;
     444    char *command = NULL;
    522445    int resA = 0;
    523446    int resB = 0;
    524447    long noof_changed_files;
    525448
    526     malloc_string(tmp);
    527449    malloc_string(cwd);
    528450    malloc_string(new);
    529     malloc_string(command);
    530451
    531452    assert(bkpinfo != NULL);
     
    534455    chdir(bkpinfo->restore_path);
    535456    getcwd(new, MAX_STR_LEN - 1);
    536     sprintf(tmp, "new path is %s", new);
    537457    insist_on_this_cd_number(bkpinfo, g_current_media_number);
    538458    unlink("/tmp/changed.txt");
     
    543463    noof_changed_files = count_lines_in_file("/tmp/changed.txt");
    544464    if (noof_changed_files) {
    545         sprintf(tmp, _("%ld files do not match the backup            "),
     465        asprintf(&tmp, _("%ld files do not match the backup            "),
    546466                noof_changed_files);
    547467        //      mvaddstr_and_log_it( g_currentY++, 0, tmp );
    548468        log_to_screen(tmp);
    549         sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
     469        paranoid_free(tmp);
     470
     471        asprintf(&command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE);
    550472        paranoid_system(command);
    551     } else {
    552         sprintf(tmp, _("All files match the backup                     "));
     473        paranoid_free(command);
     474    } else {
     475        asprintf(&tmp, _("All files match the backup                     "));
    553476        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    554477        log_to_screen(tmp);
    555     }
    556 
    557     paranoid_free(tmp);
     478        paranoid_free(tmp);
     479    }
     480
    558481    paranoid_free(cwd);
    559482    paranoid_free(new);
    560     paranoid_free(command);
    561483
    562484    return (resA + resB);
     
    566488 *END_COMPARE_TO_CD                                                       *
    567489 **************************************************************************/
    568 
    569 
    570490
    571491
     
    588508    char *tmp;
    589509
    590     malloc_string(tmp);
    591 
    592510  /**************************************************************************
    593511   * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to     *
     
    600518    while (get_cfg_file_from_archive(bkpinfo)) {
    601519        if (!ask_me_yes_or_no
    602             (_("Failed to find config file/archives. Choose another source?")))
     520            (_
     521             ("Failed to find config file/archives. Choose another source?")))
    603522        {
    604523            fatal_error("Unable to find config file/archives. Aborting.");
     
    628547        mvaddstr_and_log_it(g_currentY++,
    629548                            0,
    630                             _("Warning - differences found during the compare phase"));
     549                            _
     550                            ("Warning - differences found during the compare phase"));
    631551    }
    632552
     
    635555    if (count_lines_in_file("/tmp/changed.txt") > 0) {
    636556        mvaddstr_and_log_it(g_currentY++, 0,
    637                             _("Differences found while files were being compared."));
     557                            _
     558                            ("Differences found while files were being compared."));
    638559        streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt");
    639560        if (count_lines_in_file("/tmp/changed.files") <= 0) {
    640561            mvaddstr_and_log_it(g_currentY++, 0,
    641                                 _("...but they were logfiles and temporary files. Your archives are fine."));
    642             log_to_screen
    643                 (_("The differences were logfiles and temporary files. Your archives are fine."));
     562                                _
     563                                ("...but they were logfiles and temporary files. Your archives are fine."));
     564            log_to_screen(_
     565                          ("The differences were logfiles and temporary files. Your archives are fine."));
    644566        } else {
    645567            q = count_lines_in_file("/tmp/changed.files");
    646             sprintf(tmp, _("%ld significant difference%s found."), q,
     568            asprintf(&tmp, _("%ld significant difference%s found."), q,
    647569                    (q != 1) ? "s" : "");
    648570            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    649571            log_to_screen(tmp);
    650 
    651             strcpy(tmp,
     572            paranoid_free(tmp);
     573
     574            asprintf(&tmp,
    652575                   _("Type 'less /tmp/changed.files' for a list of non-matching files"));
    653576            mvaddstr_and_log_it(g_currentY++, 0, tmp);
    654577            log_to_screen(tmp);
     578            paranoid_free(tmp);
    655579
    656580            log_msg(2, "calling popup_changelist_from_file()");
     
    660584    } else {
    661585        log_to_screen
    662             (_("No significant differences were found. Your backup is perfect."));
     586            (_
     587             ("No significant differences were found. Your backup is perfect."));
    663588    }
    664589    kill_petris();
    665     paranoid_free(tmp);
    666590    return (retval);
    667591}
     
    670594 *END_COMPARE_MODE                                                        *
    671595 **************************************************************************/
     596
    672597
    673598/**
     
    683608    int res;
    684609
     610    char *dir = NULL;
     611    char *command = NULL;
     612
     613    assert(bkpinfo != NULL);
    685614  /** needs malloc **/
    686     char *dir, *command, *tmp;
    687 
    688     assert(bkpinfo != NULL);
    689615    malloc_string(dir);
    690     malloc_string(command);
    691616    getcwd(dir, MAX_STR_LEN);
    692617    chdir(bkpinfo->restore_path);
    693618
    694     sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     619    asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    695620            bkpinfo->restore_path);
    696621    run_program_and_log_output(command, FALSE);
     622    paranoid_free(command);
    697623    mvaddstr_and_log_it(g_currentY,
    698624                        0, _("Verifying archives against filesystem"));
     
    700626    if (bkpinfo->disaster_recovery
    701627        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    702         asprintf(&tmp,
    703                last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    704628        paranoid_free(bkpinfo->media_device);
    705         bkpinfo->media_device = tmp;
     629        // last_line_of_file allocates the string
     630        bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    706631    } else {
    707632        paranoid_free(bkpinfo->media_device);
     633        // find_cdrom_device allocates the string
    708634        bkpinfo->media_device = find_cdrom_device(FALSE);
    709635    }
     
    721647    mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    722648    paranoid_free(dir);
    723     paranoid_free(command);
    724649    return (res);
    725650}
     
    744669{
    745670    int res;
    746     char *dir, *command;
     671    char *dir = NULL;
     672    char *command = NULL;
    747673
    748674    assert(bkpinfo != NULL);
    749675    malloc_string(dir);
    750     malloc_string(command);
    751676
    752677    getcwd(dir, MAX_STR_LEN);
    753678    chdir(bkpinfo->restore_path);
    754     sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
     679    asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",
    755680            bkpinfo->restore_path);
    756681    run_program_and_log_output(command, FALSE);
     682    paranoid_free(command);
     683
    757684    mvaddstr_and_log_it(g_currentY,
    758685                        0, _("Verifying archives against filesystem"));
     
    765692    }
    766693    paranoid_free(dir);
    767     paranoid_free(command);
    768694    return (res);
    769695}
  • trunk/mondo/mondo/mondorestore/mondo-rstr-compare.h

    r59 r688  
    1 /* mondo-rstr-compare.h
     1/*
    22 * $Id$
    3  */
     3**/
    44
    55
  • trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c

    r539 r688  
    11/***************************************************************************
    22 * $Id$
    3 */
     3**/
    44
    55
     
    1111#ifdef __FreeBSD__
    1212#define OSSWAP(linux,fbsd) fbsd
    13 //#include <libgen.h>
    1413#else
    1514#define OSSWAP(linux,fbsd) linux
     
    1716
    1817#include "mondo-rstr-newt.h"
    19 
    20 //static char cvsid[] = "$Id$";
    21 
    22 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
    23 
    2418
    2519/**
     
    5751{
    5852    /** buffers ***********************************************************/
    59     char *tmp;
     53    char *tmp = NULL;
    6054
    6155    /** newt **************************************************************/
     
    8276
    8377    newtPushHelpLine
    84         (_("   Add one of the following unallocated RAID partitions to this RAID device."));
     78        (_
     79         ("   Add one of the following unallocated RAID partitions to this RAID device."));
    8580    asprintf(&tmp, "%-26s %s", _("Device"), _("Size"));
    8681    headerMsg = newtLabel(1, 1, tmp);
     
    157152    newtComponent formatComp;
    158153
    159     /** buffers **********************************************************/
    160     char *drive_to_add;
    161     char *mountpoint_str;
     154    char *drive_to_add = NULL;
     155    char *mountpoint_str = NULL;
    162156    char *size_str = NULL;
    163     char *device_str;
    164     char *format_str;
    165 
    166     /** pointers *********************************************************/
    167     char *mountpoint_here;
    168     char *size_here;
    169     char *device_here;
    170     char *format_here;
     157    char *device_str = NULL;
     158    char *format_str = NULL;
     159    char *mountpoint_here = NULL;
     160    char *size_here = NULL;
     161    char *device_here = NULL;
     162    char *format_here = NULL;
    171163
    172164    assert(mountlist != NULL);
     
    198190    bCancel = newtButton(17, 6, _("Cancel"));
    199191    newtPushHelpLine
    200         (_("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"));
     192        (_
     193         ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"));
    201194    myForm = newtForm(NULL, NULL, 0);
    202195    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     
    229222            if (size_of_specific_device_in_mountlist(mountlist, device_str)
    230223                >= 0) {
    231                 popup_and_OK(_("Can't add this - you've got one already!"));
     224                popup_and_OK(_
     225                             ("Can't add this - you've got one already!"));
    232226                b_res = NULL;
    233227            }
     
    286280
    287281    if (popup_and_get_string
    288         ("Add variable", _("Enter the name of the variable to add"), sz_out,
    289          MAX_STR_LEN)) {
    290         strip_spaces(sz_out);
     282        ("Add variable", _("Enter the name of the variable to add"),
     283         sz_out)) {
    291284        items = raidrec->additional_vars.entries;
    292285        for (i = 0;
     
    295288        if (i < items) {
    296289            popup_and_OK
    297                 (_("No need to add that variable. It is already listed here."));
     290                (_
     291                 ("No need to add that variable. It is already listed here."));
    298292        } else {
    299293            strcpy(raidrec->additional_vars.el[items].label, sz_out);
     
    302296        }
    303297    }
     298    paranoid_free(sz_out);
    304299}
    305300#endif
     
    322317
    323318    /** structures ********************************************************/
    324     struct vinum_volume *raidrec;
    325 
    326     /** int ***************************************************************/
     319    struct vinum_volume *raidrec = NULL;
     320
    327321    int i = 0, j = 0;
    328322    int noof_partitions = 0;
    329323
    330     /** long **************************************************************/
    331324    long total_size = 0;
    332325    long plex_size = 0;
     
    335328    long sp = 0;
    336329
    337     /** buffers ***********************************************************/
    338     char *tmp;
    339     char *devname;
    340 
    341 
    342 
     330    char *tmp = NULL;
     331    char *devname = NULL;
    343332
    344333    for (i = 0;
     
    347336    if (i == raidlist->entries) {
    348337        asprintf(&tmp,
    349                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    350                 raid_device);
     338                 "Cannot calc size of raid device %s - cannot find it in raidlist",
     339                 raid_device);
    351340        log_it(tmp);
    352341        paranoid_free(tmp);
     
    411400    }
    412401
    413     asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device,
    414             (long) smallest_plex);
     402    asprintf(&tmp, "I have calculated %s's real size to be %ld",
     403             raid_device, (long) smallest_plex);
    415404    log_it(tmp);
    416405    paranoid_free(tmp);
     
    420409
    421410    /** structures ********************************************************/
    422     struct raid_device_record *raidrec;
     411    struct raid_device_record *raidrec = NULL;
    423412
    424413    /** int ***************************************************************/
     
    432421
    433422    /** buffers ***********************************************************/
    434     char *tmp;
     423    char *tmp = NULL;
    435424
    436425    assert(mountlist != NULL);
     
    443432    if (i == raidlist->entries) {
    444433        asprintf(&tmp,
    445                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    446                 raid_device);
     434                 "Cannot calc size of raid device %s - cannot find it in raidlist",
     435                 raid_device);
    447436        log_it(tmp);
    448437        paranoid_free(tmp);
     
    469458        total_size = smallest_partition * (noof_partitions - 1);
    470459    }
    471     asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device,
    472             (long) total_size);
     460    asprintf(&tmp, "I have calculated %s's real size to be %ld",
     461             raid_device, (long) total_size);
    473462    log_it(tmp);
    474463    paranoid_free(tmp);
     
    478467
    479468
    480 
    481469/**
    482470 * Choose the RAID level for the RAID device record in @p raidrec.
     
    495483
    496484    /** buffers ***********************************************************/
    497     char *tmp;
    498     char *prompt;
    499     char *sz;
     485    char *tmp = NULL;
     486    char *prompt = NULL;
     487    char *sz = NULL;
    500488
    501489    asprintf(&prompt,
    502             _("Please enter the RAID level you want. (concat, striped, raid5)"));
     490             _
     491             ("Please enter the RAID level you want. (concat, striped, raid5)"));
    503492    if (raidrec->raidlevel == -1) {
    504493        asprintf(&tmp, "concat");
     
    509498    }
    510499    for (out = 999; out == 999;) {
    511         res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
     500        res = popup_and_get_string("Specify RAID level", prompt, tmp);
    512501        if (!res) {
    513502            return;
    514503        }
    515         strip_spaces(tmp);
     504        /* BERLIOS: Useless ???
    516505        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    517506            asprintf(&sz, tmp);
     
    520509            paranoid_free(sz);
    521510        }
     511        */
    522512        if (!strcmp(tmp, "concat")) {
    523513            out = -1;
     
    544534#else
    545535    /** buffers ***********************************************************/
    546     char *tmp;
    547     char personalities[MAX_STR_LEN];
    548     char *prompt;
    549     char *sz;
     536    char *tmp = NULL;
     537    char *personalities = NULL;
     538    char *prompt = NULL;
     539    char *sz = NULL;
    550540    int out = 0, res = 0;
    551541
     
    554544    system
    555545        ("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    556     strcpy(personalities,
    557            last_line_of_file("/tmp/raid-personalities.txt"));
     546    personalities = last_line_of_file("/tmp/raid-personalities.txt"));
    558547    asprintf(&prompt, _("Please enter the RAID level you want. %s"),
    559             personalities);
     548             personalities);
     549    paranoid_free(personalities);
     550
    560551    if (raidrec->raid_level == -1) {
    561552        asprintf(&tmp, "linear");
     
    566557         out != -1 && out != 0 && out != 1 && out != 4 && out != 5
    567558         && out != 10;) {
    568         res = popup_and_get_string(_("Specify RAID level"), prompt, tmp, 10);
     559        res =
     560            popup_and_get_string(_("Specify RAID level"), prompt, tmp);
    569561        if (!res) {
    570562            return;
    571563        }
    572         strip_spaces(tmp);
     564        /* BERLIOS: Useless ???
    573565        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    574566            asprintf(&sz, tmp);
    575             strncpy(tmp, sz + 1, strlen(sz) - 2);
     567            paranoid_free(tmp);
     568
     569            asprintf(&tmp, sz + 1);
    576570            tmp[strlen(sz) - 2] = '\0';
    577571            paranoid_free(sz);
    578572        }
     573        */
    579574        if (!strcmp(tmp, "linear")) {
    580575            out = -1;
     
    585580        }
    586581        log_it(tmp);
    587         paranoid_free(tmp);
    588582        if (is_this_raid_personality_registered(out)) {
    589583            log_it
     
    591585        } else {
    592586            if (ask_me_yes_or_no
    593                 (_("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")))
     587                (_
     588                 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")))
    594589            {
    595590                out = 999;
     
    597592        }
    598593    }
     594    paranoid_free(tmp);
    599595    paranoid_free(prompt);
    600596    raidrec->raid_level = out;
     
    622618
    623619    /** buffers ***********************************************************/
    624     char *tmp;
     620    char *tmp = NULL;
    625621
    626622    assert(mountlist != NULL);
     
    634630             pos++);
    635631        if (pos < mountlist->entries) {
    636             asprintf(&tmp,
    637                     "Deleting partition %s cos it was part of a now-defunct RAID",
    638                     mountlist->el[pos].device);
    639             log_it(tmp);
    640             paranoid_free(tmp);
     632            log_it("Deleting partition %s cos it was part of a now-defunct RAID",
     633                     mountlist->el[pos].device);
    641634            memcpy((void *) &mountlist->el[pos],
    642635                   (void *) &mountlist->el[mountlist->entries - 1],
     
    665658
    666659    /** buffers ***********************************************************/
    667     char *tmp;
     660    char *tmp = NULL;
    668661
    669662    assert(disklist != NULL);
     
    671664
    672665    asprintf(&tmp, _("Delete %s from RAID device %s - are you sure?"),
    673             disklist->el[currline].device, raid_device);
     666             disklist->el[currline].device, raid_device);
    674667    if (!ask_me_yes_or_no(tmp)) {
    675668        paranoid_free(tmp);
     
    705698
    706699    /** buffers ***********************************************************/
    707     char *tmp;
    708     char *device;
     700    char *tmp = NULL;
     701    char *device = NULL;
    709702
    710703    assert(mountlist != NULL);
     
    718711                                                  device);
    719712    if (pos >= 0) {
    720         asprintf(&tmp, _("Cannot delete %s: it is in use by RAID device %s"),
    721                 mountlist->el[currline].device,
    722                 raidlist->el[pos].OSSWAP(raid_device, volname));
     713        asprintf(&tmp,
     714                 _("Cannot delete %s: it is in use by RAID device %s"),
     715                 mountlist->el[currline].device,
     716                 raidlist->el[pos].OSSWAP(raid_device, volname));
    723717        popup_and_OK(tmp);
    724718        paranoid_free(tmp);
     
    726720    }
    727721    asprintf(&tmp, _("Delete %s - are you sure?"),
    728             mountlist->el[currline].device);
     722             mountlist->el[currline].device);
    729723    if (!ask_me_yes_or_no(tmp)) {
    730724        paranoid_free(tmp);
     
    740734             && strcmp(mountlist->el[currline].device, device);
    741735             currline++);
    742         if (currline == mountlist->entries) {
    743             log_it("Dev is gone. I can't delete it. Ho-hum");
    744             paranoid_free(device);
    745             return;
    746         }
     736            if (currline == mountlist->entries) {
     737                log_it("Dev is gone. I can't delete it. Ho-hum");
     738                paranoid_free(device);
     739                return;
     740            }
    747741        paranoid_free(device);
    748742    }
     
    775769
    776770    /** buffers ***********************************************************/
    777     char *tmp;
     771    char *tmp = NULL;
    778772
    779773    assert(mountlist != NULL);
     
    785779        return;
    786780    }
    787     asprintf(&tmp, _("Do you want me to delete %s's partitions, too?", device));
     781    asprintf(&tmp,
     782             _("Do you want me to delete %s's partitions, too?"), device);
    788783    delete_partitions_too = ask_me_yes_or_no(tmp);
    789784    if (delete_partitions_too) {
     
    846841
    847842    /** buffers ************************************************************/
    848     char *tmp;
     843    char *tmp = NULL;
    849844
    850845    /** structures *********************************************************/
    851     struct additional_raid_variables *av;
     846    struct additional_raid_variables *av = NULL;
    852847
    853848    assert(raidrec != NULL);
    854849
    855850    av = &raidrec->additional_vars;
    856     asprintf(&tmp, _("Delete %s - are you sure?", av->el[lino].label));
     851    asprintf(&tmp, _("Delete %s - are you sure?"), av->el[lino].label);
    857852    if (ask_me_yes_or_no(tmp)) {
    858853        if (!strcmp(av->el[lino].label, "persistent-superblock")
     
    860855            paranoid_free(tmp);
    861856            asprintf(&tmp, _("%s must not be deleted. It would be bad."),
    862                     av->el[lino].label);
     857                     av->el[lino].label);
    863858            popup_and_OK(tmp);
    864859        } else {
     
    891886
    892887    /** structures *******************************************************/
    893     struct s_node *node;
     888    struct s_node *node = NULL;
    894889
    895890    /** buffers **********************************************************/
    896     static char *current_filename;
    897     char *tmp;
     891    static char *current_filename = NULL;
     892    char *tmp = NULL;
    898893
    899894    /** bool *************************************************************/
     
    905900    assert(keylist != NULL);
    906901    assert(listbox != NULL);
    907 
    908902
    909903    if (depth == 0) {
     
    927921                    warned_already = TRUE;
    928922                    asprintf(&tmp,
    929                             _("Too many lines. Displaying first %d entries only. Close a directory to see more."),
    930                             ARBITRARY_MAXIMUM);
     923                             _
     924                             ("Too many lines. Displaying first %d entries only. Close a directory to see more."),
     925                             ARBITRARY_MAXIMUM);
    931926                    popup_and_OK(tmp);
    932927                    paranoid_free(tmp);
     
    964959        newtListboxClear(listbox);
    965960        for (i = 0; i < lines_in_flist_window; i++) {
    966             asprintf(&tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '),
    967                     (g_is_path_expanded[i] ? '+' : '-'),
    968                     strip_path(g_strings_of_flist_window[i]));
    969             // BERLIOS: this is dangerous now
     961            asprintf(&tmp, "%c%c %-80s",
     962                     (g_is_path_selected[i] ? '*' : ' '),
     963                     (g_is_path_expanded[i] ? '+' : '-'),
     964                     strip_path(g_strings_of_flist_window[i]));
     965            // BERLIOS: this is dangerous now  => Memory leak
    970966            if (strlen(tmp) > 71) {
    971967                tmp[70] = '\0';
     
    10111007        slashcount--;           /* Keep one slash 'cos Hugh does... */
    10121008
     1009    /* BERLIOS: tmpnopath and prev not defined !! How can this compile ?? */
    10131010    for (i = 0; i < slashcount; i++) {  /* Replace each dir with a space char */
    10141011        tmpnopath[i] = ' ';
     
    10621059    void *keylist[ARBITRARY_MAXIMUM];
    10631060
    1064     /** buffers ***********************************************************/
    1065     char tmp[MAX_STR_LEN];
    1066 
    10671061    /** bool **************************************************************/
    10681062    bool dummybool;
     
    10741068    log_to_screen(_("Editing filelist"));
    10751069    newtPushHelpLine
    1076         (_("   Please edit the filelist to your satisfaction, then click OK or Cancel."));
     1070        (_
     1071         ("   Please edit the filelist to your satisfaction, then click OK or Cancel."));
    10771072    j = 4;
    10781073    bLess = newtCompactButton(j, 17, _(" Less "));
     
    11111106                indexno = 0;
    11121107            }
    1113             sprintf(tmp, "You selected '%s'",
     1108            log_it("You selected '%s'",
    11141109                    g_strings_of_flist_window[indexno]);
    1115             log_it(tmp);
    11161110            if (b_res == bMore) {
    11171111                g_is_path_expanded[indexno] = TRUE;
     
    12041198    newtComponent b_raid = NULL;
    12051199
    1206   /** buffers ***********************************************************/
    1207     char device_str[MAX_STR_LEN];
    1208     char mountpoint_str[MAX_STR_LEN];
    1209     char size_str[MAX_STR_LEN];
    1210     char format_str[MAX_STR_LEN];
    1211     char tmp[MAX_STR_LEN];
    1212     char device_used_to_be[MAX_STR_LEN];
    1213     char mountpt_used_to_be[MAX_STR_LEN];
    1214 
    1215     /** pointers **********************************************************/
    1216     char *device_here;
    1217     char *mountpoint_here;
    1218     char *size_here;
    1219     char *format_here;
    1220 
    1221     /** int ***************************************************************/
     1200    char *device_str = NULL;
     1201    char *mountpoint_str = NULL;
     1202    char *size_str = NULL;
     1203    char *format_str = NULL;
     1204    char *tmp = NULL;
     1205    char *device_used_to_be = NULL;
     1206    char *mountpt_used_to_be = NULL;
     1207    char *device_here = NULL;
     1208    char *mountpoint_here = NULL;
     1209    char *size_here = NULL;
     1210    char *format_here = NULL;
     1211
    12221212    int j = 0;
    12231213
     
    12291219    memcpy((void *) &bkp_raidlist, (void *) raidlist,
    12301220           sizeof(struct raidlist_itself));
    1231     strcpy(device_str, mountlist->el[currline].device);
    1232     strcpy(device_used_to_be, mountlist->el[currline].device);
    1233     strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
    1234     strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
    1235     strcpy(format_str, mountlist->el[currline].format);
    1236     sprintf(size_str, "%lld", mountlist->el[currline].size / 1024);
     1221    asprintf(&device_str, mountlist->el[currline].device);
     1222    asprintf(&device_used_to_be, mountlist->el[currline].device);
     1223    asprintf(&mountpoint_str, mountlist->el[currline].mountpoint);
     1224    asprintf(&mountpt_used_to_be, mountlist->el[currline].mountpoint);
     1225    asprintf(&format_str, mountlist->el[currline].format);
     1226    asprintf(&size_str, "%lld", mountlist->el[currline].size / 1024);
     1227
    12371228    newtOpenWindow(20, 5, 48, 10, "Edit entry");
    12381229    label0 = newtLabel(2, 1, _("Device:"));
     
    12421233    deviceComp =
    12431234        newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     1235    paranoid_free(device_str);
     1236
    12441237    mountpointComp =
    12451238        newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     1239    paranoid_free(mountpoint_str);
     1240
    12461241    formatComp =
    12471242        newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     1243    paranoid_free(format_str);
     1244
    12481245    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12491246        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     
    12521249        sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
    12531250    }
     1251    paranoid_free(size_str);
     1252
    12541253    bOK = newtButton(2, 6, _("  OK  "));
    12551254    bCancel = newtButton(14, 6, _("Cancel"));
     
    12581257    }
    12591258    newtPushHelpLine
    1260         (_("       Edit this partition's mountpoint, size and format; then click 'OK'."));
     1259        (_
     1260         ("       Edit this partition's mountpoint, size and format; then click 'OK'."));
    12611261    myForm = newtForm(NULL, NULL, 0);
    12621262    newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp,
     
    12651265    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
    12661266        b_res = newtRunForm(myForm);
    1267         strcpy(device_str, device_here);
     1267
     1268        paranoid_free(device_str);
     1269        asprintf(&device_str, device_here);
    12681270        strip_spaces(device_str);
    1269         strcpy(mountpoint_str, mountpoint_here);
     1271
     1272        paranoid_free(mountpoint_str);
     1273        asprintf(&mountpoint_str, mountpoint_here);
    12701274        strip_spaces(mountpoint_str);
    1271         strcpy(format_str, format_here);
     1275
     1276        paranoid_free(format_str);
     1277        asprintf(&format_str, format_here);
     1278        paranoid_free(format_here);
    12721279        strip_spaces(format_str);
    12731280        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
     
    12791286        } else if (b_res == bOK && !strcmp(mountpoint_str, "image")
    12801287                   && strcmp(mountpt_used_to_be, "image")) {
    1281             popup_and_OK(_("You can't change a regular device to an image."));
     1288            popup_and_OK(_
     1289                         ("You can't change a regular device to an image."));
    12821290            b_res = NULL;
    12831291            continue;
    12841292        }
     1293        paranoid_free(mountpt_used_to_be);
     1294
    12851295        if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12861296            && strcmp(mountlist->el[currline].mountpoint, "image")) {
    1287             strcpy(size_str, size_here);
     1297            asprintf(&size_str, size_here);
    12881298            strip_spaces(size_str);
    12891299        } else {
    1290             sprintf(size_str, "%ld",
     1300            asprintf(&size_str, "%ld",
    12911301                    calculate_raid_device_size(mountlist, raidlist,
    12921302                                               mountlist->el[currline].
     
    12941304            newtLabelSetText(sizeComp, size_str);
    12951305        }
     1306        paranoid_free(size_here);
     1307
    12961308        /* do not let user click RAID button if user has changed device_str */
    12971309        if (b_res == b_raid) {
     
    13021314                 */
    13031315                popup_and_OK
    1304                     (_("You cannot edit the RAID settings until you have OK'd your change to the device node."));
     1316                    (_
     1317                     ("You cannot edit the RAID settings until you have OK'd your change to the device node."));
    13051318            } else {
    13061319                j = find_raid_device_in_raidlist(raidlist,
     
    13091322                if (j < 0) {
    13101323                    sprintf(tmp,
    1311                             _("/etc/raidtab does not have an entry for %s; please delete it and add it again"),
     1324                            _
     1325                            ("/etc/raidtab does not have an entry for %s; please delete it and add it again"),
    13121326                            mountlist->el[currline].device);
    13131327                    popup_and_OK(tmp);
     
    13201334        }
    13211335    }
     1336    paranoid_free(device_here);
     1337    paranoid_free(mountpoint_here);
     1338
    13221339    newtFormDestroy(myForm);
    13231340    newtPopHelpLine();
     
    13301347    strcpy(mountlist->el[currline].device, device_str);
    13311348    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     1349    paranoid_free(mountpoint_str);
     1350
    13321351    strcpy(mountlist->el[currline].format, format_str);
     1352    paranoid_free(format_str);
     1353
    13331354    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    13341355        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     
    13391360        mountlist->el[currline].size = atol(size_str) * 1024;
    13401361    }
     1362    paranoid_free(size_str);
     1363
    13411364    newtListboxSetEntry(listbox, (int) keylist[currline],
    13421365                        mountlist_entry_to_string(mountlist, currline));
     
    13631386    else if (strcmp(device_used_to_be, device_str)) {
    13641387        popup_and_OK
    1365             (_("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."));
     1388            (_
     1389             ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."));
    13661390    }
    13671391#endif
    13681392    redraw_mountlist(mountlist, keylist, listbox);
     1393    paranoid_free(device_str);
     1394    paranoid_free(device_used_to_be);
    13691395}
    13701396
     
    14251451}
    14261452
     1453
    14271454void
    14281455edit_raidlist_plex(struct mountlist_itself *mountlist,
     
    14551482
    14561483    /** buffers ***********************************************************/
    1457     char title_of_editraidForm_window[MAX_STR_LEN];
     1484    char *title_of_editraidForm_window;
    14581485
    14591486    /** newt **************************************************************/
     
    14721499
    14731500    int currline2 = 0;
     1501    char *pname = NULL;
     1502    char *raidlevel = NULL;
     1503    char *chunksize = NULL;
     1504    char *entry = NULL;
     1505    char *msg = NULL;
     1506    int i = 0;
     1507    char *headerstr = NULL;
    14741508
    14751509    log_it(_("Started edit_raidlist_entry"));
    14761510    memcpy((void *) &bkp_raidrec, (void *) raidrec,
    14771511           sizeof(struct vinum_volume));
    1478     sprintf(title_of_editraidForm_window, _("Plexes on %s"),
     1512    asprintf(&title_of_editraidForm_window, _("Plexes on %s"),
    14791513            raidrec->volname);
    14801514    newtPushHelpLine(_("   Please select a plex to edit"));
    14811515    newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window);
     1516    paranoid_free(title_of_editraidForm_window);
     1517
    14821518    for (;;) {
    1483         int i;
    1484         char headerstr[MAX_STR_LEN];
    1485         snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s  %11s  %8s",
    1486                  _("Plex"), _("Level",) _("Stripe Size"), _("Subdisks"));
     1519        asprintf(&headerstr, "%-14s %-8s  %11s  %8s", _("Plex"), _("Level",) _("Stripe Size"), _("Subdisks"));
    14871520
    14881521        bOK = newtCompactButton(2, 13, _("  OK  "));
     
    14951528            newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    14961529        plexesHeader = newtLabel(2, 2, headerstr);
     1530        paranoid_free(headerstr);
     1531
    14971532        editraidForm = newtForm(NULL, NULL, 0);
    14981533
     
    15011536            keylist[i] = (void *) i;
    15021537            if (i < raidrec->plexes) {
    1503                 char pname[64], entry[MAX_STR_LEN], raidlevel[64],
    1504                     chunksize[64];
    15051538                switch (raidrec->plex[i].raidlevel) {
    15061539                case -1:
    1507                     strcpy(raidlevel, "concat");
     1540                    asprintf(&raidlevel, "concat");
    15081541                    break;
    15091542                case 0:
    1510                     strcpy(raidlevel, "striped");
     1543                    asprintf(&raidlevel, "striped");
    15111544                    break;
    15121545                case 5:
    1513                     strcpy(raidlevel, "raid5");
     1546                    asprintf(&raidlevel, "raid5");
    15141547                    break;
    15151548                default:
    1516                     sprintf(raidlevel, "raid%i",
     1549                    asprintf(&raidlevel, "raid%i",
    15171550                            raidrec->plex[i].raidlevel);
    15181551                    break;
     
    15201553
    15211554                if (raidrec->plex[i].raidlevel == -1) {
    1522                     strcpy(chunksize, "N/A");
     1555                    asprintf(&chunksize, "N/A");
    15231556                } else {
    1524                     sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
     1557                    asprintf(&chunksize, "%dk", raidrec->plex[i].stripesize);
    15251558                }
    1526                 snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
    1527                 snprintf(entry, MAX_STR_LEN, "%-14s %-8s  %11s  %8d",
     1559                asprintf(&pname, "%s.p%i", raidrec->volname, i);
     1560                asprintf(&entry, "%-14s %-8s  %11s  %8d",
    15281561                         pname, raidlevel, chunksize,
    15291562                         raidrec->plex[i].subdisks);
     1563                paranoid_free(pname);
     1564                paranoid_free(chunksize);
     1565                paranoid_free(raidlevel);
    15301566                newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
     1567                paranoid_free(entry);
    15311568            }
    15321569        }
     
    15491586
    15501587        if (b_res == bDelete) {
    1551             char msg[MAX_STR_LEN];
    1552             sprintf(msg, _("Are you sure you want to delete %s.p%i?"),
     1588            asprintf(&msg, _("Are you sure you want to delete %s.p%i?"),
    15531589                    raidrec->volname, currline2);
    15541590            if (ask_me_yes_or_no(msg)) {
     
    15591595                raidrec->plexes--;
    15601596            }
     1597            paranoid_free(msg);
    15611598            continue;
    15621599        }
     
    15811618#else
    15821619    /** structures ********************************************************/
    1583     struct raid_device_record *bkp_raidrec;
     1620    struct raid_device_record *bkp_raidrec = NULL;
    15841621
    15851622
    15861623    /** buffers ***********************************************************/
    1587     char *title_of_editraidForm_window;
    1588     char *sz_raid_level;
    1589     char *sz_data_disks;
    1590     char *sz_spare_disks;
    1591     char *sz_parity_disks;
    1592     char *sz_failed_disks;
     1624    char *title_of_editraidForm_window = NULL;
     1625    char *sz_raid_level = NULL;
     1626    char *sz_data_disks = NULL;
     1627    char *sz_spare_disks = NULL;
     1628    char *sz_parity_disks = NULL;
     1629    char *sz_failed_disks = NULL;
    15931630
    15941631    /** newt **************************************************************/
     
    16081645    assert(raidrec != NULL);
    16091646
    1610     malloc_string(title_of_editraidForm_window);
    1611     malloc_string(sz_raid_level);
    1612     malloc_string(sz_data_disks);
    1613     malloc_string(sz_spare_disks);
    1614     malloc_string(sz_parity_disks);
    1615     malloc_string(sz_failed_disks);
    16161647    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
    16171648        fatal_error("Cannot malloc space for raidrec");
     
    16221653    memcpy((void *) bkp_raidrec, (void *) raidrec,
    16231654           sizeof(struct raid_device_record));
    1624     sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
     1655    asprintf(&title_of_editraidForm_window, _("Edit %s"), raidrec->raid_device);
    16251656    log_msg(2, "Opening newt window");
    16261657    newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
     1658    paranoid_free(title_of_editraidForm_window);
     1659
    16271660    for (;;) {
    16281661        log_msg(2, "Main loop");
    1629         sprintf(title_of_editraidForm_window, _("Edit %s"),
    1630                 raidrec->raid_device);
    1631         strcpy(sz_raid_level,
     1662        asprintf(&sz_raid_level,
    16321663               turn_raid_level_number_to_string(raidrec->raid_level));
    1633         strcpy(sz_data_disks,
     1664        asprintf(&sz_data_disks,
    16341665               number_of_disks_as_string(raidrec->data_disks.entries,
    16351666                                         _("data")));
    1636         strcpy(sz_spare_disks,
     1667        asprintf(&sz_spare_disks,
    16371668               number_of_disks_as_string(raidrec->spare_disks.entries,
    16381669                                         _("spare")));
    1639         strcpy(sz_parity_disks,
     1670        asprintf(&sz_parity_disks,
    16401671               number_of_disks_as_string(raidrec->parity_disks.entries,
    16411672                                         _("parity")));
    1642         strcpy(sz_failed_disks,
     1673        asprintf(&sz_failed_disks,
    16431674               number_of_disks_as_string(raidrec->failed_disks.entries,
    16441675                                         _("failed")));
     
    16481679        bSelectFailed = newtButton(20, 5, sz_failed_disks);
    16491680        bChangeRaid = newtButton(1, 9, sz_raid_level);
     1681        paranoid_free(sz_raid_level);
     1682        paranoid_free(sz_data_disks);
     1683        paranoid_free(sz_spare_disks);
     1684        paranoid_free(sz_parity_disks);
     1685        paranoid_free(sz_failed_disks);
     1686
    16501687        bOK = newtButton(16 + (raidrec->raid_level == -1), 9, _("  OK  "));
    16511688        bCancel = newtButton(28, 9, _("Cancel"));
     
    16541691                              _("Additional settings and information"));
    16551692        newtPushHelpLine
    1656             (_("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel."));
     1693            (_
     1694             ("  Edit the RAID device's settings to your heart's content, then hit OK/Cancel."));
    16571695        editraidForm = newtForm(NULL, NULL, 0);
    16581696        newtFormAddComponents(editraidForm, bSelectData, bSelectParity,
     
    16911729        calculate_raid_device_size(mountlist, raidlist,
    16921730                                   raidrec->raid_device);
    1693     paranoid_free(title_of_editraidForm_window);
    1694     paranoid_free(sz_raid_level);
    1695     paranoid_free(sz_data_disks);
    1696     paranoid_free(sz_spare_disks);
    1697     paranoid_free(sz_parity_disks);
    1698     paranoid_free(sz_failed_disks);
    16991731    paranoid_free(bkp_raidrec);
    17001732#endif
    17011733}
    1702 
    17031734#ifdef __FreeBSD__
     1735
    17041736
    17051737/**
     
    17241756
    17251757    /** buffers ***********************************************************/
    1726     char title_of_editraidForm_window[MAX_STR_LEN];
     1758    char *title_of_editraidForm_window = NULL;
     1759    char *tmp = NULL;
     1760    char *entry = NULL;
    17271761
    17281762    /** newt **************************************************************/
     
    17421776    void *curr_choice_a, *curr_choice_u;
    17431777    int currline_a, currline_u;
    1744 
    1745     struct mountlist_itself *unallocparts;
    1746 
     1778    int i;
     1779
     1780    struct mountlist_itself *unallocparts = NULL;
     1781
     1782    /* BERLIOS: Check return value */
    17471783    unallocparts = malloc(sizeof(struct mountlist_itself));
    17481784
     
    17501786    memcpy((void *) &bkp_raidrec, (void *) raidrec,
    17511787           sizeof(struct vinum_plex));
    1752     sprintf(title_of_editraidForm_window, "%s.p%i",
     1788    asprintf(&title_of_editraidForm_window, "%s.p%i",
    17531789            raidlist->el[currline].volname, currline2);
    17541790    newtPushHelpLine
    1755         (_("   Please select a subdisk to edit, or edit this plex's parameters"));
     1791        (_
     1792         ("   Please select a subdisk to edit, or edit this plex's parameters"));
    17561793    newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window);
     1794    paranoid_free(title_of_editraidForm_window);
     1795
    17571796    for (;;) {
    1758         int i;
    1759         char headerstr[MAX_STR_LEN];
    1760         char tmp[64];
    1761         snprintf(headerstr, MAX_STR_LEN, "%-24s %s", _("Subdisk"), _("Device"));
    1762 
    1763 
    17641797        switch (raidrec->raidlevel) {
    17651798        case -1:
    1766             strcpy(tmp, "concat");
     1799            asprintf(&tmp, "concat");
    17671800            break;
    17681801        case 0:
    1769             strcpy(tmp, "striped");
     1802            asprintf(&tmp, "striped");
    17701803            break;
    17711804        case 5:
    1772             strcpy(tmp, "raid5");
     1805            asprintf(&tmp, "raid5");
    17731806            break;
    17741807        default:
    1775             sprintf(tmp, _("unknown (%i)"), raidrec->raidlevel);
     1808            asprintf(&tmp, _("unknown (%i)"), raidrec->raidlevel);
    17761809            break;
    17771810        }
    17781811        bLevel = newtCompactButton(2, 2, _(" RAID level "));
    17791812        sLevel = newtLabel(19, 2, tmp);
     1813        paranoid_free(tmp);
    17801814
    17811815        if (raidrec->raidlevel >= 0) {
    1782             sprintf(tmp, "%ik", raidrec->stripesize);
     1816            asprintf(&tmp, "%ik", raidrec->stripesize);
    17831817            bStripeSize = newtCompactButton(2, 4, _(" Stripe size "));
    17841818        } else {
    1785             strcpy(tmp, "N/A");
     1819            asprintf(&tmp, "N/A");
    17861820            bStripeSize = newtLabel(2, 4, _("Stripe size:"));
    17871821        }
    17881822        sStripeSize = newtLabel(19, 4, tmp);
     1823        paranoid_free(tmp);
    17891824
    17901825        bOK = newtCompactButton(2, 16, _("  OK  "));
     
    17961831
    17971832        //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1798         //  plexesHeader  = newtLabel (2, 6, headerstr);
    17991833        unallocListbox =
    18001834            newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     
    18121846                                                 raidlist);
    18131847        for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
    1814             char entry[MAX_STR_LEN];
    18151848            keylist[i] = (void *) i;
    18161849            if (i < raidrec->subdisks) {
    1817                 snprintf(entry, MAX_STR_LEN, "%-17s",
     1850                asprintf(&entry, "%-17s",
    18181851                         find_dev_entry_for_raid_device_name(raidlist,
    18191852                                                             raidrec->
     
    18211854                                                             which_device));
    18221855                newtListboxAppendEntry(allocListbox, entry, keylist[i]);
     1856                paranoid_free(entry);
    18231857            }
    18241858            if (i < unallocparts->entries) {
    1825                 snprintf(entry, MAX_STR_LEN, "%-17s",
    1826                          unallocparts->el[i].device);
     1859                asprintf(&entry, "%-17s", unallocparts->el[i].device);
    18271860                newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
     1861                paranoid_free(entry);
    18281862            }
    18291863        }
     
    18751909            choose_raid_level(raidrec);
    18761910        } else if (b_res == bStripeSize) {
    1877             char tmp[64];
    1878             sprintf(tmp, "%i", raidrec->stripesize);
     1911            asprintf(&tmp, "%i", raidrec->stripesize);
    18791912            if (popup_and_get_string
    18801913                (_("Stripe size"),
    1881                  _("Please enter the stripe size in kilobytes."), tmp, 20)) {
     1914                 _("Please enter the stripe size in kilobytes."), tmp)) {
    18821915                raidrec->stripesize = atoi(tmp);
    18831916            }
     1917            paranoid_free(tmp);
    18841918        } else if ((b_res == bAlloc) || (b_res == unallocListbox)) {
    18851919            if (currline_u <= unallocparts->entries)
     
    19221956
    19231957    /** buffers ***********************************************************/
    1924     char header[MAX_STR_LEN];
    1925     char comment[MAX_STR_LEN];
    1926     char sz_out[MAX_STR_LEN];
     1958    char *header = NULL;
     1959    char *comment = NULL;
     1960    char *sz_out = NULL;
    19271961
    19281962    assert(raidrec != 0);
    19291963    assert(lino >= 0);
    19301964
    1931     strcpy(sz_out, raidrec->additional_vars.el[lino].value);
    1932     sprintf(header, _("Edit %s"), raidrec->additional_vars.el[lino].label);
    1933     sprintf(comment, _("Please set %s's value (currently '%s')"),
     1965    asprintf(&sz_out, raidrec->additional_vars.el[lino].value);
     1966    asprintf(&header, _("Edit %s"), raidrec->additional_vars.el[lino].label);
     1967    asprintf(&comment, _("Please set %s's value (currently '%s')"),
    19341968            raidrec->additional_vars.el[lino].label, sz_out);
    1935     if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) {
    1936         strip_spaces(sz_out);
     1969    if (popup_and_get_string(header, comment, sz_out)) {
    19371970        strcpy(raidrec->additional_vars.el[lino].value, sz_out);
    19381971    }
    1939 }
    1940 
    1941 
    1942 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain.       - Hugo, 09/01/2001 */
    1943 
     1972    paranoid_free(header);
     1973    paranoid_free(comment);
     1974    paranoid_free(sz_out);
     1975}
    19441976#endif
     1977
    19451978
    19461979/**
     
    19722005
    19732006    /** ???? *************************************************************/
    1974     void *curr_choice;
     2007    void *curr_choice = NULL;
    19752008    void *keylist[ARBITRARY_MAXIMUM];
    19762009
     
    19812014
    19822015    /** buffers **********************************************************/
    1983     char tmp[MAX_STR_LEN];
    1984     char flaws_str_A[MAX_STR_LEN];
    1985     char flaws_str_B[MAX_STR_LEN];
    1986     char flaws_str_C[MAX_STR_LEN];
     2016    char *tmp = NULL;
     2017    char *flaws_str_A = NULL;
     2018    char *flaws_str_B = NULL;
     2019    char *flaws_str_C = NULL;
    19872020
    19882021    assert(mountlist != NULL);
    19892022    assert(raidlist != NULL);
    19902023
    1991     strcpy(flaws_str_A, "xxxxxxxxx");
    1992     strcpy(flaws_str_B, "xxxxxxxxx");
    1993     strcpy(flaws_str_C, "xxxxxxxxx");
     2024    asprintf(&flaws_str_A, "xxxxxxxxx");
     2025    asprintf(&flaws_str_B, "xxxxxxxxx");
     2026    asprintf(&flaws_str_C, "xxxxxxxxx");
    19942027    if (mountlist->entries > ARBITRARY_MAXIMUM) {
    19952028        log_to_screen(_("Arbitrary limits suck, man!"));
     
    19972030    }
    19982031    newtPushHelpLine
    1999         (_("   Please edit the mountlist to your satisfaction, then click OK or Cancel."));
     2032        (_
     2033         ("   Please edit the mountlist to your satisfaction, then click OK or Cancel."));
    20002034    i = 4;
    20012035    bAdd = newtCompactButton(i, 17, _(" Add "));
     
    20052039    bCancel = newtCompactButton(i += 12, 17, _("Cancel"));
    20062040    bOK = newtCompactButton(i += 12, 17, _("  OK  "));
    2007     sprintf(tmp, "%-24s %-24s %-8s  %s", _("Device"), _("Mountpoint"), _("Format"),
    2008             _("Size (MB)"));
     2041    asprintf(&tmp, "%-24s %-24s %-8s  %s", _("Device"), _("Mountpoint"),
     2042            _("Format"), _("Size (MB)"));
    20092043    headerMsg = newtLabel(2, 1, tmp);
    20102044    flawsLabelA = newtLabel(2, 13, flaws_str_A);
     
    20262060        newtLabelSetText(flawsLabelC, flaws_str_C);
    20272061        b_res = newtRunForm(myForm);
     2062        /* BERLIOS: This needs to be re-written */
    20282063        if (b_res == bOK) {
    20292064            if (!evaluate_mountlist
     
    20352070                finished =
    20362071                    ask_me_yes_or_no
    2037                     (_("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"));
     2072                    (_
     2073                     ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"));
    20382074            }
    20392075        } else if (b_res == bCancel) {
     
    20412077        } else if (b_res == bReload) {
    20422078            if (ask_me_yes_or_no(_("Reload original mountlist?"))) {
    2043 /*
    2044 This would be really dumb. RAIDTAB_FNAME is #define'd.   --- Hugo, 2003/04/24
    2045           if (!RAIDTAB_FNAME[0])
    2046         {
    2047                   strcpy(RAIDTAB_FNAME, "/etc/raidtab");
    2048           log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);
    2049         }
    2050 */
    20512079                load_mountlist(mountlist, mountlist_fname);
    20522080                load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     
    20762104                    } else {
    20772105                        popup_and_OK
    2078                             (_("Please add an entry. Then press ENTER to edit it."));
     2106                            (_
     2107                             ("Please add an entry. Then press ENTER to edit it."));
    20792108                    }
    20802109                }
    20812110            }
    20822111        }
     2112        paranoid_free(flaws_str_A);
     2113        paranoid_free(flaws_str_B);
     2114        paranoid_free(flaws_str_C);
    20832115    }
    20842116    newtFormDestroy(myForm);
     
    20952127
    20962128
    2097 
    20982129/**
    20992130 * Edit the mountlist.
     
    21072138{
    21082139    int res = 0;
    2109 //  char tmp[MAX_STR_LEN];
    21102140
    21112141    iamhere("entering eml");
     
    21212151    return (res);
    21222152}
    2123 
    2124 
    21252153
    21262154
     
    21492177
    21502178    /** ?? ***************************************************************/
    2151     void *keylist[ARBITRARY_MAXIMUM], *curr_choice;
     2179    void *keylist[ARBITRARY_MAXIMUM], *curr_choice = NULL;
    21522180
    21532181    /** buffers **********************************************************/
    2154     char title_of_window[MAX_STR_LEN];
     2182    char *title_of_window = NULL;
    21552183
    21562184    /** int **************************************************************/
     
    21632191    memcpy((void *) &bkp_raidrec, (void *) raidrec,
    21642192           sizeof(struct raid_device_record));
    2165     sprintf(title_of_window, "Additional variables");
     2193    asprintf(&title_of_window, "Additional variables");
    21662194    newtPushHelpLine
    2167         (_("  Edit the additional fields to your heart's content, then click OK or Cancel."));
    2168     headerMsg = newtLabel(1, 1, _("Label                            Value"));
     2195        (_
     2196         ("  Edit the additional fields to your heart's content, then click OK or Cancel."));
     2197    headerMsg =
     2198        newtLabel(1, 1, _("Label                            Value"));
    21692199    varsListbox =
    21702200        newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     
    21762206    bCancel = newtCompactButton(i += 9, 9, _("Cancel"));
    21772207    newtOpenWindow(17, 7, 46, 10, title_of_window);
     2208    paranoid_free(title_of_window);
     2209
    21782210    myForm = newtForm(NULL, NULL, 0);
    21792211    newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit,
     
    22472279
    22482280
    2249 
    22502281/**
    22512282 * Locate @p device in @p raidlist.
     
    22592290                             char *device)
    22602291{
    2261 
    22622292    /** int ***************************************************************/
    22632293    int i = 0;
    22642294#ifdef __FreeBSD__
    2265     char vdev[64];
    2266 #else
    2267 // Linux
     2295    char *vdev = NULL;
    22682296#endif
    22692297
     
    22732301#ifdef __FreeBSD__
    22742302    for (i = 0; i < raidlist->entries; i++) {
    2275         sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    2276         if (!strcmp(device, vdev))
     2303        asprintf(&vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2304        if (!strcmp(device, vdev)) {
     2305            paranoid_free(vdev);
    22772306            break;
     2307        }
     2308        paranoid_free(vdev);
    22782309    }
    22792310#else
     
    23052336    /** initialize ********************************************************/
    23062337
    2307     assert(isodir_device != NULL);
    2308     assert(isodir_format != NULL);
    2309     assert(isodir_path != NULL);
    2310 
    2311     log_it("%d - AAA - isodir_path = %s", isodir_path);
    2312     isodir_format[0] = '\0';
    2313     if (isodir_device[0] == '\0') {
    2314         strcpy(isodir_device, "/dev/");
    2315     }
    2316     if (isodir_path[0] == '\0') {
    2317         strcpy(isodir_path, "/");
     2338    // %d no var ???
     2339    // log_it("%d - AAA - isodir_path = %s", isodir_path);
     2340    if (isodir_device == NULL) {
     2341        asprintf(&isodir_device, "/dev/");
     2342    }
     2343    if (isodir_path == NULL) {
     2344        asprintf(&isodir_path, "/");
    23182345    }
    23192346    if (does_file_exist("/tmp/NFS-SERVER-PATH")) {
    2320         strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT"));
    2321         strcpy(isodir_format, "nfs");
    2322         strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH"));
     2347        paranoid_free(isodir_device);
     2348        isodir_device = last_line_of_file("/tmp/NFS-SERVER-MOUNT");
     2349        asprintf(&isodir_format, "nfs");
     2350        paranoid_free(isodir_path);
     2351        isodir_path = last_line_of_file("/tmp/NFS-SERVER-PATH");
    23232352    }
    23242353    if (nuke_me_please) {
     
    23272356
    23282357    if (popup_and_get_string
    2329         (_("ISO Mode - device"), _("On what device do the ISO files live?"),
    2330          isodir_device, MAX_STR_LEN / 4)) {
     2358        (_("ISO Mode - device"),
     2359         _("On what device do the ISO files live?"), isodir_device)) {
    23312360        if (popup_and_get_string
    23322361            (_("ISO Mode - format"),
    2333              _("What is the disk format of the device? (Hit ENTER if you don't know.)"),
    2334              isodir_format, 16)) {
     2362             _
     2363             ("What is the disk format of the device? (Hit ENTER if you don't know.)"),
     2364             isodir_format)) {
    23352365            if (popup_and_get_string
    23362366                (_("ISO Mode - path"),
    2337                  _("At what path on this device can the ISO files be found?"),
    2338                  isodir_path, MAX_STR_LEN / 4)) {
    2339                 strip_spaces(isodir_device);
    2340                 strip_spaces(isodir_format);
    2341                 strip_spaces(isodir_path);
    2342                 log_it("%d - BBB - isodir_path = %s", isodir_path);
     2367                 _
     2368                 ("At what path on this device can the ISO files be found?"),
     2369                 isodir_path)) {
     2370                // Same pb:
     2371                // log_it("%d - BBB - isodir_path = %s", isodir_path);
    23432372                return (TRUE);
    23442373            }
     
    23622391                            int currline, char *device)
    23632392{
    2364 
    23652393    /** structure *********************************************************/
    23662394    struct OSSWAP (raid_device_record, vinum_volume) * raidrec;
     
    24152443    raidrec->additional_vars.entries = items;
    24162444}
    2417 
    24182445#endif
     2446
    24192447
    24202448/**
     
    24332461
    24342462    newtPushHelpLine
    2435         (_("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!"));
     2463        (_
     2464         ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!"));
    24362465    newtOpenWindow(24, 3, 32, 13, _("Nuking"));
    24372466    b1 = newtButton(7, 1, _("Slowly"));
     
    24472476
    24482477
    2449 
    24502478/**
    24512479 * Redraw the disklist.
     
    25122540
    25132541
    2514 
    2515 
    25162542/**
    25172543 * Redraw the list of unallocated RAID partitions.
     
    25312557
    25322558    /** buffers **********************************************************/
    2533     char tmp[MAX_STR_LEN];
     2559    char *tmp = NULL;
    25342560
    25352561    assert(unallocated_raid_partitions != NULL);
     
    25422568    }
    25432569    for (i = 0; i < unallocated_raid_partitions->entries; i++) {
    2544         sprintf(tmp, "%-22s %8lld",
     2570        asprintf(&tmp, "%-22s %8lld",
    25452571                unallocated_raid_partitions->el[i].device,
    25462572                unallocated_raid_partitions->el[i].size / 1024);
    25472573        newtListboxAppendEntry(listbox, tmp, keylist[i]);
    2548     }
    2549 }
     2574        paranoid_free(tmp);
     2575    }
     2576}
     2577
    25502578
    25512579#ifndef __FreeBSD__
     
    25652593
    25662594    /** buffers *********************************************************/
    2567     char tmp[MAX_STR_LEN];
     2595    char *tmp;
    25682596
    25692597    assert(additional_vars != NULL);
     
    25772605    }
    25782606    for (i = 0; i < additional_vars->entries; i++) {
    2579         sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label,
     2607        asprintf(&tmp, "%-32s %-8s", additional_vars->el[i].label,
    25802608                additional_vars->el[i].value);
    25812609        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2610        paranoid_free(tmp);
    25822611    }
    25832612}
     
    26222651#endif
    26232652
     2653
    26242654/**
    26252655 * Change all RAID devices to use @p new_dev instead of @p old_dev.
     
    26352665{
    26362666    /** buffers ********************************************************/
    2637     char tmp[MAX_STR_LEN];
     2667    char *tmp;
    26382668
    26392669    /** int ************************************************************/
     
    26472677    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
    26482678    if (pos < 0) {
    2649         sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
     2679        asprintf(&tmp, "No need to rejig %s in raidlist: it's not listed.",
    26502680                old_dev);
    26512681        log_it(tmp);
     2682        paranoid_free(tmp);
    26522683    } else {
    26532684        if ((j =
     
    26812712#endif
    26822713        else {
    2683             sprintf(tmp,
     2714            asprintf(&tmp,
    26842715                    "%s is supposed to be listed in this raid dev but it's not...",
    26852716                    old_dev);
    26862717            log_it(tmp);
     2718            paranoid_free(tmp);
    26872719        }
    26882720    }
     
    27172749    res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size");
    27182750}
     2751
    27192752
    27202753/**
     
    27342767                  struct list_of_disks *disklist)
    27352768{
    2736     void *curr_choice;
    2737 
    2738     /** ??? ***************************************************************/
     2769    void *curr_choice = NULL;
    27392770
    27402771    /** structures ********************************************************/
    2741     struct raidlist_itself *bkp_raidlist;
    2742     struct raid_device_record *bkp_raidrec;
    2743     struct list_of_disks *bkp_disklist;
    2744     struct mountlist_itself *unallocated_raid_partitions;
     2772    struct raidlist_itself *bkp_raidlist = NULL;
     2773    struct raid_device_record *bkp_raidrec = NULL;
     2774    struct list_of_disks *bkp_disklist = NULL;
     2775    struct mountlist_itself *unallocated_raid_partitions = NULL;
    27452776
    27462777    /** newt **************************************************************/
     
    27562787    /** buffers **********************************************************/
    27572788    void *keylist[ARBITRARY_MAXIMUM];
    2758     char *tmp;
    2759     char *help_text;
    2760     char *title_of_window;
    2761     char *sz_res;
    2762     char *header_text;
     2789    char *tmp = NULL;
     2790    char *help_text = NULL;
     2791    char *title_of_window = NULL;
     2792    char *sz_res = NULL;
     2793    char *header_text = NULL;
    27632794
    27642795  /** int **************************************************************/
     
    27732804
    27742805    iamhere("malloc'ing");
    2775     malloc_string(tmp);
    2776     malloc_string(help_text);
    2777     malloc_string(title_of_window);
    2778     malloc_string(sz_res);
    2779     malloc_string(header_text);
    27802806    if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) {
    27812807        fatal_error("Cannot malloc space for raidrec");
     
    28012827
    28022828    iamhere("Post-malloc");
    2803     strcpy(help_text,
    2804            _("   Edit this RAID device's list of partitions. Choose OK or Cancel when done."));
    2805     sprintf(header_text, "%-24s    %s", _("Device"), _("Index"));
    2806     sprintf(title_of_window, _("%s contains..."), raidrec->raid_device);
     2829    asprintf(&help_text,
     2830           _
     2831           ("   Edit this RAID device's list of partitions. Choose OK or Cancel when done."));
     2832    asprintf(&header_text, "%-24s    %s", _("Device"), _("Index"));
     2833    asprintf(&title_of_window, _("%s contains..."), raidrec->raid_device);
    28072834    newtPushHelpLine(help_text);
     2835    paranoid_free(help_text);
    28082836    for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) {
    28092837        headerMsg = newtLabel(1, 1, header_text);
     
    28442872                    if (unallocated_raid_partitions->entries <= 0) {
    28452873                        popup_and_OK
    2846                             (_("There are no unallocated partitions marked for RAID."));
     2874                            (_
     2875                             ("There are no unallocated partitions marked for RAID."));
    28472876                    } else {
    28482877                        log_it
    2849                             (_("Done. The user may add one or more of the above to RAID device"));
     2878                            (_
     2879                             ("Done. The user may add one or more of the above to RAID device"));
    28502880                        add_disklist_entry(disklist, raidrec->raid_device,
    28512881                                           unallocated_raid_partitions);
    2852                         log_it(_("I have finished adding a disklist entry."));
     2882                        log_it(_
     2883                               ("I have finished adding a disklist entry."));
    28532884                        redraw_disklist(disklist, keylist,
    28542885                                        partitionsListbox);
     
    28592890                    redraw_disklist(disklist, keylist, partitionsListbox);
    28602891                } else {
    2861                     sprintf(tmp, _("%s's index is %d. What should it be?"),
     2892                    asprintf(&tmp, _("%s's index is %d. What should it be?"),
    28622893                            raidrec->raid_device,
    28632894                            disklist->el[currline].index);
    2864                     sprintf(sz_res, "%d", disklist->el[currline].index);
    2865                     if (popup_and_get_string(_("Set index"), tmp, sz_res, 10)) {
     2895                    asprintf(&sz_res, "%d", disklist->el[currline].index);
     2896                    if (popup_and_get_string
     2897                        (_("Set index"), tmp, sz_res)) {
    28662898                        disklist->el[currline].index = atoi(sz_res);
    28672899                    }
     2900                    paranoid_free(tmp);
     2901                    paranoid_free(sz_res);
    28682902                    redraw_disklist(disklist, keylist, partitionsListbox);
    28692903                }
     
    28732907        newtPopWindow();
    28742908    }
     2909    paranoid_free(title_of_window);
     2910    paranoid_free(header_text);
     2911
    28752912    newtPopHelpLine();
    28762913    if (b_res == bCancel) {
     
    28822919               sizeof(struct list_of_disks));
    28832920    }
    2884     paranoid_free(tmp);
    2885     paranoid_free(help_text);
    2886     paranoid_free(title_of_window);
    2887     paranoid_free(sz_res);
    2888     paranoid_free(header_text);
    28892921    paranoid_free(bkp_raidrec);
    28902922    paranoid_free(bkp_disklist);
     
    28952927
    28962928
    2897 
    28982929/**
    28992930 * Ask the user which restore mode (nuke, interactive, or compare) we should use.
     
    29062937  /** char *************************************************************/
    29072938    char output = '\0';
    2908     char tmp[MAX_STR_LEN];
     2939    char *tmp = NULL;
     2940    size_t n = 0;
    29092941
    29102942  /** newt *************************************************************/
     
    29202952        for (output = 'z'; !strchr("AICE", output); output = tmp[0]) {
    29212953            printf
    2922                 (_("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "));
    2923             fgets(tmp, MAX_STR_LEN - 1, stdin);
    2924         }
     2954                (_
     2955                 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "));
     2956            getline(&tmp, &n, stdin);
     2957        }
     2958        paranoid_free(tmp);
    29252959        return (output);
    29262960    }
    29272961
    29282962    newtPushHelpLine
    2929         (_("   Do you want to 'nuke' your system, restore interactively, or just compare?"));
     2963        (_
     2964         ("   Do you want to 'nuke' your system, restore interactively, or just compare?"));
    29302965    newtOpenWindow(24, 3, 32, 17, _("How should I restore?"));
    29312966    b1 = newtButton(7, 1, _("Automatically"));
  • trunk/mondo/mondo/mondorestore/mondo-rstr-newt.h

    r507 r688  
    1 /***************************************************************************
    2                           mondo-rstr-newt.h  -  description
    3                              -------------------
    4     begin                : Sat Apr 20 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    10 /***************************************************************************
    11  *                                                                         *
    12  *   This program is free software; you can redistribute it and/or modify  *
    13  *   it under the terms of the GNU General Public License as published by  *
    14  *   the Free Software Foundation; either version 2 of the License, or     *
    15  *   (at your option) any later version.                                   *
    16  *                                                                         *
    17  ***************************************************************************/
    18 
     1/*
     2 * $Id$
     3**/
    194
    205#include "../common/my-stuff.h"
     
    7257extern bool g_ISO_restore_mode;
    7358
    74 
    75 /* my global variables */
    76 
    77 //extern newtComponent g_progressForm, g_blurb1, g_blurb2, g_blurb3, g_label,
    78 //  g_timeline, g_percentline, g_scale;
    79 //extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN], g_blurb_str_1[MAX_STR_LEN] =
    80 //  "", g_blurb_str_2[MAX_STR_LEN] = "", g_blurb_str_3[MAX_STR_LEN] = "";
    81 //newtComponent g_isoform_main =
    82 //  NULL, g_isoform_header, g_isoform_scale, g_isoform_timeline,
    83 //  g_isoform_pcline;
    84 //long g_isoform_starttime;
    85 //int g_isoform_old_progress = -1;
    86 //char g_isoform_header_str[MAX_STR_LEN];
    87 //int g_mysterious_dot_counter;
    88 
    89 
    90 
    91 
    92 
    9359/* my subroutines */
    9460
     
    137103                   struct raidlist_itself *);
    138104void edit_raidrec_additional_vars(struct raid_device_record *);
    139 int evaluate_drive_within_mountlist(struct mountlist_itself *, char *,
    140                                     char *);
    141105int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *);
    142106int find_device_in_mountlist(struct mountlist_itself *, char *);
     
    151115void log_to_screen(const char *fmt, ...);
    152116int look_for_duplicate_mountpoints(struct mountlist_itself *, char *);
    153 int look_for_weird_formats(struct mountlist_itself *, char *);
    154117void make_list_of_unallocated_raid_partitions(struct mountlist_itself *,
    155118                                              struct mountlist_itself *,
     
    162125void open_progress_form(char *, char *, char *, char *, long);
    163126void popup_and_OK(char *);
    164 bool popup_and_get_string(char *, char *, char *, int);
     127bool popup_and_get_string(char *, char *, char *);
    165128bool popup_with_buttons(char *, char *, char *);
    166129void redraw_disklist(struct list_of_disks *, void *keylist[],
     
    194157char *strip_path(char *);
    195158
    196 
    197 
    198 
    199159/* -------------------------------------------------------------------- */
    200160
    201 
    202 
    203 
    204 char tmpnopath[MAX_STR_LEN + 2];
    205 char tmpprevpath[MAX_STR_LEN + 2];
    206161
    207162#ifdef __FreeBSD__
  • trunk/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h

    r59 r688  
    1 /* mondo-rstr-tools-EXT.h
     1/*
    22 * $Id: mondo-rstr-tools-EXT.h
    3  */
     3**/
    44
    55extern void free_MR_global_filenames();
     
    88extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99extern void kill_petris(void);
    10 extern int modify_rclocal_one_time(char *path);
    1110extern int mount_cdrom(struct s_bkpinfo *bkpinfo);
    1211extern int mount_device(char *, char *, char *, bool);
     
    2726extern void set_signals(int on);
    2827extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo);
    29 //extern void setup_signals(int);
    3028extern void terminate_daemon(int);
    3129extern void termination_in_progress(int);
  • trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r687 r688  
    11/*
    22 * $Id$
    3 */
    4 
     3**/
     4
     5#include <unistd.h>
    56
    67#include "../common/my-stuff.h"
     
    89#include "../common/libmondo.h"
    910#include "mr-externs.h"
    10 //#include "mondo-restore.h"
    11 //#include "mondo-rstr-compare-EXT.h"
    1211#include "mondo-rstr-tools.h"
    1312#ifndef S_SPLINT_S
     
    5554    paranoid_free(g_filelist_full);
    5655    paranoid_free(g_filelist_imagedevs);
    57 //  paranoid_free (g_imagedevs_pot );
    5856    paranoid_free(g_imagedevs_restthese);
    5957    paranoid_free(g_mondo_cfg_file);
     
    6765
    6866
    69 
    7067/**
    7168 * Ask the user which imagedevs from the list contained in @p infname should
     
    7774void ask_about_these_imagedevs(char *infname, char *outfname)
    7875{
    79     FILE *fin;
    80     FILE *fout;
     76    FILE *fin = NULL;
     77    FILE *fout = NULL;
    8178  /************************************************************************
    8279   * allocate memory regions. test and set  -sab 16 feb 2003              *
    8380   ************************************************************************/
    84     char *incoming;
    85     char *question;
     81    char *incoming = NULL;
     82    char *question = NULL;
    8683
    8784    size_t n = 0;
     
    105102
    106103        asprintf(&question,
    107                 _("Should I restore the image of %s ?", incoming));
     104                 _("Should I restore the image of %s ?"), incoming);
    108105
    109106        if (ask_me_yes_or_no(question)) {
    110107            fprintf(fout, "%s\n", incoming);
    111108        }
     109        paranoid_free(question);
    112110    }
    113111
    114112  /*** free memory ***********/
    115113    paranoid_free(incoming);
    116     paranoid_free(question);
    117 
    118114
    119115    paranoid_fclose(fout);
     
    124120 *ASK_ABOUT_THESE_IMAGEDEVS                                               *
    125121 **************************************************************************/
    126 
    127 
    128 
    129 
    130 
    131 
    132122
    133123
     
    147137                                 char *output_mountlist_file)
    148138{
    149     char *mountpt;
    150     char *command;
    151     char *orig_fname;
     139    char *mountpt = NULL;
     140    char *command = NULL;
     141    char *orig_fname = NULL;
    152142    int retval = 0;
    153143
    154144    assert(bkpinfo != NULL);
    155     malloc_string(mountpt);
    156     malloc_string(command);
    157     malloc_string(orig_fname);
    158145    assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
    159146    assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
    160147    assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
    161     sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    162     sprintf(command, "mkdir -p %s", mountpt);
     148    asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     149    asprintf(&command, "mkdir -p %s", mountpt);
    163150    run_program_and_log_output(command, FALSE);
    164     sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
     151    paranoid_free(command);
     152
     153    asprintf(&command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
    165154            ramdisk_fname, bkpinfo->tmpdir);
    166 
    167155    run_program_and_log_output(command, FALSE);
    168     sprintf(command, "umount %s", mountpt);
    169 
     156    paranoid_free(command);
     157
     158    asprintf(&command, "umount %s", mountpt);
    170159    run_program_and_log_output(command, FALSE);
    171 
    172     sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
     160    paranoid_free(command);
     161
     162    asprintf(&command, "mount -o loop %s/mindi.rd -t ext2 %s",
    173163            bkpinfo->tmpdir, mountpt);
    174 
    175164    run_program_and_log_output(command, FALSE);
    176 
    177     sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    178 
     165    paranoid_free(command);
     166
     167    asprintf(&command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    179168    run_program_and_log_output(command, FALSE);
    180 
    181     sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
     169    paranoid_free(command);
     170
     171    asprintf(&command, "cp -f %s/%s %s",    // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
    182172            mountpt, g_mondo_cfg_file, output_cfg_file);
    183173    run_program_and_log_output(command, FALSE);
    184 
    185     sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
     174    paranoid_free(command);
     175
     176    asprintf(&orig_fname, "%s/%s", mountpt, g_mountlist_fname);
    186177    if (does_file_exist(orig_fname)) {
    187         sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
     178        asprintf(&command, "cp -f %s %s", orig_fname, output_mountlist_file);
    188179        run_program_and_log_output(command, FALSE);
    189     }
    190     sprintf(command, "umount %s", mountpt);
     180        paranoid_free(command);
     181    }
     182    asprintf(&command, "umount %s", mountpt);
     183    paranoid_free(mountpt);
     184
    191185    run_program_and_log_output(command, FALSE);
     186    paranoid_free(command);
     187
    192188    if (!does_file_exist(output_cfg_file)
    193189        || (!does_file_exist(output_mountlist_file)
     
    199195        retval = 0;
    200196    }
    201     paranoid_free(mountpt);
    202     paranoid_free(command);
    203197    paranoid_free(orig_fname);
    204198    return (retval);
    205 
    206 }
    207 
    208 
     199}
    209200
    210201
     
    217208    while (get_cfg_file_from_archive(bkpinfo)) {
    218209        if (!ask_me_yes_or_no
    219             (_("Failed to find config file/archives. Choose another source?")))
     210            (_
     211             ("Failed to find config file/archives. Choose another source?")))
    220212        {
    221213            fatal_error("Could not find config file/archives. Aborting.");
     
    237229
    238230  /** needs malloc **/
    239     char *command;
    240     char *file;
    241     char *tmp;
    242     int res;
    243 
    244     malloc_string(command);
    245     malloc_string(file);
    246     malloc_string(tmp);
     231    char *command = NULL;
     232    char *file = NULL;
     233    char *tmp = NULL;
     234    int res = 0;
     235
    247236    assert_string_is_neither_NULL_nor_zerolength(f);
    248237    assert_string_is_neither_NULL_nor_zerolength(list_fname);
     
    250239
    251240    if (strncmp(preamble, f, strlen(preamble)) == 0) {
    252         strcpy(file, f + strlen(preamble));
    253     } else {
    254         strcpy(file, f);
     241        asprintf(&file, f + strlen(preamble));
     242    } else {
     243        asprintf(&file, f);
    255244    }
    256245    if (file[0] == '/' && file[1] == '/') {
    257         strcpy(tmp, file);
    258         strcpy(file, tmp + 1);
    259     }
    260     sprintf(tmp,
     246        asprintf(&tmp, file);
     247        paranoid_free(file);
     248        asprintf(&file, tmp + 1);
     249        paranoid_free(tmp);
     250    }
     251    asprintf(&tmp,
    261252            "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
    262253            f, file);
    263254    log_msg(2, tmp);
    264     sprintf(command, "grep -x \"%s\" %s", file, list_fname);
     255    paranoid_free(tmp);
     256
     257    asprintf(&command, "grep -x \"%s\" %s", file, list_fname);
     258    paranoid_free(file);
     259
    265260    res = run_program_and_log_output(command, FALSE);
    266261    paranoid_free(command);
    267     paranoid_free(file);
    268     paranoid_free(tmp);
    269262    if (res) {
    270263        return (FALSE);
     
    273266    }
    274267}
    275 
    276268/**************************************************************************
    277269 *END_IS_FILE_IN_LIST                                                     *
    278270 **************************************************************************/
    279 
    280271
    281272
     
    291282int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please)
    292283{
    293     char *mount_isodir_command, *tmp, *command;
    294     int retval = 0, i;
     284    char *mount_isodir_command = NULL;
     285    char *tmp = NULL;
     286    char *command = NULL;
     287    int retval = 0, i = 0;
    295288    bool already_mounted = FALSE;
    296289
    297290    assert(bkpinfo != NULL);
    298     malloc_string(mount_isodir_command);
    299     malloc_string(tmp);
    300     malloc_string(command);
    301291    g_ISO_restore_mode = TRUE;
    302292    read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     
    308298        }
    309299/* End patch */
    310         sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     300        asprintf(&command, "mkdir -p %s", bkpinfo->isodir);
    311301        run_program_and_log_output(command, 5);
     302        paranoid_free(command);
    312303        log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
    313304    }
     
    324315        already_mounted = TRUE;
    325316    } else {
    326         sprintf(mount_isodir_command, "mount %s", g_isodir_device);
    327         if (strlen(g_isodir_format) > 1) {
    328             sprintf(mount_isodir_command + strlen(mount_isodir_command),
    329                     " -t %s", g_isodir_format);
    330         }
    331         strcat(mount_isodir_command, " -o ro ");
    332         strcat(mount_isodir_command, bkpinfo->isodir);
     317        if (g_isodir_format != NULL) {
     318            asprintf(&mount_isodir_command, "mount %s -t %s -o ro %s", g_isodir_device, g_isodir_format, bkpinfo->isodir);
     319        } else {
     320            asprintf(&mount_isodir_command, "mount %s -o ro %s", g_isodir_device, bkpinfo->isodir);
     321        }
    333322        run_program_and_log_output("df -P -m", FALSE);
    334         sprintf(tmp,
     323        asprintf(&tmp,
    335324                "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
    336325                mount_isodir_command);
    337326        log_msg(1, tmp);
     327        paranoid_free(tmp);
     328
    338329        if (run_program_and_log_output(mount_isodir_command, FALSE)) {
    339330            popup_and_OK
    340                 (_("Cannot mount the device where the ISO files are stored."));
     331                (_
     332                 ("Cannot mount the device where the ISO files are stored."));
     333            paranoid_free(mount_isodir_command);
    341334            return (1);
    342335        }
     336        paranoid_free(mount_isodir_command);
    343337        log_to_screen
    344             (_("I have mounted the device where the ISO files are stored."));
     338            (_
     339             ("I have mounted the device where the ISO files are stored."));
    345340    }
    346341    if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    348343    }
    349344    i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
    350     sprintf(tmp, "%s #%d has been mounted via loopback mount",
     345    asprintf(&tmp, "%s #%d has been mounted via loopback mount",
    351346            media_descriptor_string(bkpinfo->backup_media_type), i);
    352347    log_msg(1, tmp);
     348    paranoid_free(tmp);
     349
    353350    if (i < 0) {
    354351        popup_and_OK
     
    358355    log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
    359356            bkpinfo->isodir);
    360     paranoid_free(mount_isodir_command);
    361     paranoid_free(tmp);
    362     paranoid_free(command);
    363357    return (retval);
    364358}
    365359
    366360
    367 
    368 
    369361/**
    370362 * Kill all Petris processes.
     
    373365{
    374366    char *command;
    375     malloc_string(command);
    376     sprintf(command,
     367    asprintf(&command,
    377368            "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
    378369    paranoid_system(command);
     
    383374 *END_KILL_PETRIS                                                         *
    384375 **************************************************************************/
    385 
    386 
    387 /**
    388  * (Disabled) Modify rc.local to fix some things on first boot.
    389  * This function currently doesn't do anything except make sure /tmp has the
    390  * right permissions.
    391  * @param path The path to /etc on the user's filesystem.
    392  * @return 0 for success, nonzero for failure.
    393  */
    394 int modify_rclocal_one_time(char *path)
    395 {
    396   /** malloc **/
    397     char *rclocal_fname;
    398     char *newfile_fname;
    399     char *tmp;
    400 
    401     malloc_string(rclocal_fname);
    402     malloc_string(newfile_fname);
    403     malloc_string(tmp);
    404     assert_string_is_neither_NULL_nor_zerolength(path);
    405 
    406     sprintf(rclocal_fname, "%s/rc.local", path);
    407 
    408 //  sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);
    409 //  run_program_and_log_output( tmp, FALSE );
    410     return (0);                 /* remove this line to open the floodgates... */
    411 
    412     if (!does_file_exist(rclocal_fname)) {
    413         sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
    414     }
    415     if (!does_file_exist(rclocal_fname)) {
    416         paranoid_free(rclocal_fname);
    417         paranoid_free(newfile_fname);
    418         paranoid_free(tmp);
    419         return (1);
    420     }
    421     sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
    422     sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null",
    423             rclocal_fname);
    424     if (system(tmp)) {
    425         sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
    426                 newfile_fname, newfile_fname, rclocal_fname);
    427 
    428         paranoid_system(tmp);
    429     }
    430     sprintf(tmp, "echo -en \"#!/bin/sh\
    431 \\n\
    432 \\n\
    433 grep -v mondorescue %s > %s\\n\
    434 rm -f /var/lock/subsys/*xfs*\\n\
    435 rm -f /var/run/xfs.*\\n\
    436 killall xfs\\n\
    437 service xfs start\\n\
    438 yes | rm -f %s\\n\
    439 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);
    440     sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
    441     run_program_and_log_output(tmp, FALSE);
    442     paranoid_free(rclocal_fname);
    443     paranoid_free(newfile_fname);
    444     paranoid_free(tmp);
    445     return (0);
    446 }
    447 
    448 /**************************************************************************
    449  *END_ MODIFY_RCLOCAL_ONE_TIME                                            *
    450  **************************************************************************/
    451 
    452 
    453 
    454376
    455377
     
    463385                      *p_external_copy_of_mountlist, bool writeable)
    464386{
    465     int retval = 0, lino, res;
    466     char *tmp, *these_failed, *format;
    467     struct mountlist_itself *mountlist;
    468 
    469     malloc_string(tmp);
    470     malloc_string(format);
    471     malloc_string(these_failed);
     387    int retval = 0;
     388    int lino = 0;
     389    int res = 0;
     390    char *tmp = NULL;
     391    char *these_failed = NULL;
     392    char *format = NULL;
     393    struct mountlist_itself *mountlist = NULL;
     394
    472395    assert(p_external_copy_of_mountlist != NULL);
    473396    mountlist = malloc(sizeof(struct mountlist_itself));
     
    476399    sort_mountlist_by_mountpoint(mountlist, 0);
    477400
    478   /** menset **/
    479     these_failed[0] = '\0';
    480 
    481401    mvaddstr_and_log_it(g_currentY, 0, _("Mounting devices         "));
    482402    open_progress_form(_("Mounting devices"),
     
    490410                    "Again with the /proc - why is this in your mountlist?");
    491411        } else if (is_this_device_mounted(mountlist->el[lino].device)) {
    492             sprintf(tmp, _("%s is already mounted"),
     412            asprintf(&tmp, _("%s is already mounted"),
    493413                    mountlist->el[lino].device);
    494414            log_to_screen(tmp);
     415            paranoid_free(tmp);
    495416        } else if (strcmp(mountlist->el[lino].mountpoint, "none")
    496417                   && strcmp(mountlist->el[lino].mountpoint, "lvm")
    497418                   && strcmp(mountlist->el[lino].mountpoint, "raid")
    498419                   && strcmp(mountlist->el[lino].mountpoint, "image")) {
    499             sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
     420            asprintf(&tmp, "Mounting %s", mountlist->el[lino].device);
    500421            update_progress_form(tmp);
    501             strcpy(format, mountlist->el[lino].format);
     422            paranoid_free(tmp);
     423
     424            asprintf(&format, mountlist->el[lino].format);
    502425            if (!strcmp(format, "ext3")) {
    503                 strcpy(format, "ext2");
     426                paranoid_free(format);
     427                asprintf(&format, "ext2");
    504428            }
    505429            res = mount_device(mountlist->el[lino].device,
     
    508432            retval += res;
    509433            if (res) {
    510                 strcat(these_failed, mountlist->el[lino].device);
    511                 strcat(these_failed, " ");
    512             }
     434                if (these_failed != NULL) { /* not the first time */
     435                    asprintf(&tmp, "%s %s", these_failed, mountlist->el[lino].device);
     436                    paranoid_free(these_failed);
     437                    these_failed = tmp;
     438                } else { /* The first time */
     439                    asprintf(&these_failed, "%s ", mountlist->el[lino].device);
     440                }
     441            }
     442            paranoid_free(format);
    513443        }
    514444        g_current_progress++;
     
    519449        if (g_partition_table_locked_up > 0) {
    520450            log_to_screen
    521                 (_("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to"));
    522             log_to_screen
    523                 (_("lock up the partition table. You might have to reboot and use Interactive Mode to"));
    524             log_to_screen
    525                 (_("format and restore *without* partitioning first. Sorry for the inconvenience."));
    526         }
    527         sprintf(tmp, _("Could not mount devices %s- shall I abort?"),
     451                (_
     452                 ("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to"));
     453            log_to_screen(_
     454                          ("lock up the partition table. You might have to reboot and use Interactive Mode to"));
     455            log_to_screen(_
     456                          ("format and restore *without* partitioning first. Sorry for the inconvenience."));
     457        }
     458        asprintf(&tmp, _("Could not mount devices %s- shall I abort?"),
    528459                these_failed);
     460        paranoid_free(these_failed);
     461
    529462        if (!ask_me_yes_or_no(tmp)) {
    530463            retval = 0;
    531464            log_to_screen
    532                 (_("Continuing, although some devices failed to be mounted"));
     465                (_
     466                 ("Continuing, although some devices failed to be mounted"));
    533467            mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    534468        } else {
     
    537471                (_("Unable to mount some or all of your partitions."));
    538472        }
     473        paranoid_free(tmp);
    539474    } else {
    540475        log_to_screen(_("All partitions were mounted OK."));
     
    543478    run_program_and_log_output("df -P -m", 3);
    544479    paranoid_free(mountlist);
    545     paranoid_free(tmp);
    546     paranoid_free(format);
    547     paranoid_free(these_failed);
    548480    return (retval);
    549481}
    550 
    551482 /**************************************************************************
    552483  *END_MOUNT_ALL_DEVICES                                                   *
     
    565496int mount_cdrom(struct s_bkpinfo *bkpinfo)
    566497{
    567     char *mount_cmd, *tmp;
     498    char *mount_cmd = NULL;
     499    char *tmp = NULL;
    568500    int i, res;
    569501#ifdef __FreeBSD__
    570     char mdd[32];
    571     char *mddev = mdd;
     502    char *mddev = NULL;
    572503#endif
    573504
    574     malloc_string(mount_cmd);
    575505    assert(bkpinfo != NULL);
    576506
     
    578508        || bkpinfo->backup_media_type == udev) {
    579509        log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
    580         paranoid_free(mount_cmd);
    581510        return 0;
    582511    }
     
    584513    if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
    585514        log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
    586         paranoid_free(mount_cmd);
    587515        return (0);
    588516    }
     
    597525        }
    598526#ifdef __FreeBSD__
    599         sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
    600                 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number);
     527        asprintf(&mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
     528                bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     529                g_current_media_number);
    601530        mddev = make_vn(mount_cmd);
    602         sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     531        paranoid_free(mount_cmd);
     532
     533        asprintf(&mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     534        paranoid_free(mddev);
    603535#else
    604         sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
    605                 bkpinfo->isodir, bkpinfo->nfs_remote_dir,
    606                 bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     536        asprintf(&mount_cmd,
     537                "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
     538                bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix,
     539                g_current_media_number, MNT_CDROM);
    607540#endif
    608541
    609542    } else if (bkpinfo->backup_media_type == iso) {
    610543#ifdef __FreeBSD__
    611         sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
     544        asprintf(&mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
    612545                bkpinfo->prefix, g_current_media_number);
    613546        mddev = make_vn(mount_cmd);
    614         sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     547        paranoid_free(mount_cmd);
     548
     549        asprintf(&mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     550        paranoid_free(mddev);
    615551#else
    616         sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
    617                 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     552        asprintf(&mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
     553                bkpinfo->isodir, bkpinfo->prefix, g_current_media_number,
     554                MNT_CDROM);
    618555#endif
    619556    } else if (strstr(bkpinfo->media_device, "/dev/"))
    620557#ifdef __FreeBSD__
    621558    {
    622         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     559        asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    623560                MNT_CDROM);
    624561    }
    625562#else
    626563    {
    627         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     564        asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s",
    628565                bkpinfo->media_device, MNT_CDROM);
    629566    }
     
    634571            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    635572            paranoid_free(bkpinfo->media_device);
    636             asprintf(&tmp,
    637                    last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    638             bkpinfo->media_device = tmp;
     573            bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    639574        } else {
    640575            paranoid_free(bkpinfo->media_device);
     
    643578
    644579#ifdef __FreeBSD__
    645         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     580        asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    646581                MNT_CDROM);
    647582#else
    648         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     583        asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s",
    649584                bkpinfo->media_device, MNT_CDROM);
    650585#endif
     
    662597        }
    663598    }
     599    paranoid_free(mount_cmd);
     600
    664601    if (res) {
    665602        log_msg(2, "Failed, despite %d attempts", i);
     
    667604        log_msg(2, "Mounted CD-ROM drive OK");
    668605    }
    669     paranoid_free(mount_cmd);
    670606    return (res);
    671607}
    672 
    673 
    674 
    675 
    676 
    677608/**************************************************************************
    678609 *END_MOUNT_CDROM                                                         *
     
    692623    int res = 0;
    693624
    694   /** malloc **/
    695     char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     625    char *tmp = NULL;
     626    char *command = NULL;
     627    char *mountdir = NULL;
     628    char *mountpoint = NULL;
     629    char *additional_parameters = NULL;
     630    char *p1 = NULL;
     631    char *p2 = NULL;
     632    char *p3 = NULL;
    696633
    697634    assert_string_is_neither_NULL_nor_zerolength(device);
    698635    assert_string_is_neither_NULL_nor_zerolength(mpt);
    699636    assert(format != NULL);
    700     malloc_string(tmp);
    701     malloc_string(command);
    702     malloc_string(mountdir);
    703     malloc_string(mountpoint);
    704     malloc_string(additional_parameters);
    705637
    706638    if (!strcmp(mpt, "/1")) {
    707         strcpy(mountpoint, "/");
     639        asprintf(&mountpoint, "/");
    708640        log_msg(3, "Mommm! SME is being a dildo!");
    709641    } else {
    710         strcpy(mountpoint, mpt);
     642        asprintf(&mountpoint, mpt);
    711643    }
    712644
    713645    if (!strcmp(mountpoint, "lvm")) {
     646        paranoid_free(mountpoint);
    714647        return (0);
    715648    }
    716649    if (!strcmp(mountpoint, "image")) {
     650        paranoid_free(mountpoint);
    717651        return (0);
    718652    }
    719     sprintf(tmp, "Mounting device %s   ", device);
     653    asprintf(&tmp, "Mounting device %s   ", device);
    720654    log_msg(1, tmp);
     655
    721656    if (writeable) {
    722         strcpy(additional_parameters, "-o rw");
    723     } else {
    724         strcpy(additional_parameters, "-o ro");
     657        asprintf(&p1, "-o rw");
     658    } else {
     659        asprintf(&p1, "-o ro");
    725660    }
    726661    if (find_home_of_exe("setfattr")) {
    727         strcat(additional_parameters, ",user_xattr");
     662        asprintf(&p2, ",user_xattr");
     663    } else {
     664        asprintf(&p2, "");
    728665    }
    729666    if (find_home_of_exe("setfacl")) {
    730         strcat(additional_parameters, ",acl");
    731     }
     667        asprintf(&p3, ",acl");
     668    } else {
     669        asprintf(&p3, "");
     670    }
     671    asprintf(&additional_parameters, "%s%s%s", p1, p2, p3);
     672    paranoid_free(p1);
     673    paranoid_free(p2);
     674    paranoid_free(p3);
    732675
    733676    if (!strcmp(mountpoint, "swap")) {
    734         sprintf(command, "swapon %s", device);
     677        asprintf(&command, "swapon %s", device);
    735678    } else {
    736679        if (!strcmp(mountpoint, "/")) {
    737             strcpy(mountdir, MNT_RESTORING);
     680            asprintf(&mountdir, MNT_RESTORING);
    738681        } else {
    739             sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
    740         }
    741         sprintf(command, "mkdir -p %s", mountdir);
     682            asprintf(&mountdir, "%s%s", MNT_RESTORING, mountpoint);
     683        }
     684        asprintf(&command, "mkdir -p %s", mountdir);
    742685        run_program_and_log_output(command, FALSE);
    743         sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
     686        paranoid_free(command);
     687
     688        asprintf(&command, "mount -t %s %s %s %s 2>> %s", format, device,
    744689                additional_parameters, mountdir, MONDO_LOGFILE);
    745690        log_msg(2, "command='%s'", command);
    746691    }
     692    paranoid_free(additional_parameters);
     693
    747694    res = run_program_and_log_output(command, TRUE);
    748695    if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
    749696        log_msg(1, "Re-trying without the fancy extra parameters");
    750         sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
     697        paranoid_free(command);
     698
     699        asprintf(&command, "mount -t %s %s %s 2>> %s", format, device,
    751700                mountdir, MONDO_LOGFILE);
    752701        res = run_program_and_log_output(command, TRUE);
     
    760709        } else {
    761710            log_msg(2, "Retrying w/o the '-t' switch");
    762             sprintf(command, "mount %s %s 2>> %s", device, mountdir,
     711            paranoid_free(command);
     712
     713            asprintf(&command, "mount %s %s 2>> %s", device, mountdir,
    763714                    MONDO_LOGFILE);
    764715            log_msg(2, "2nd command = '%s'", command);
     
    772723        }
    773724    }
     725    paranoid_free(tmp);
     726    paranoid_free(command);
     727    paranoid_free(mountdir);
     728
    774729    if (res && !strcmp(mountpoint, "swap")) {
    775730        log_msg(2, "That's ok. It's just a swap partition.");
     
    777732        res = 0;
    778733    }
    779 
    780     paranoid_free(tmp);
    781     paranoid_free(command);
    782     paranoid_free(mountdir);
    783734    paranoid_free(mountpoint);
    784     paranoid_free(additional_parameters);
    785735
    786736    return (res);
    787737}
    788 
    789738/**************************************************************************
    790739 *END_MOUNT_DEVICE                                                        *
    791740 **************************************************************************/
    792 
    793741
    794742
     
    819767                               TRUE);
    820768}
    821 
    822769/**************************************************************************
    823770 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
    824771 **************************************************************************/
    825 
    826 
    827772
    828773
     
    836781int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
    837782{
    838   /** add mallocs **/
    839     char *value;
    840     char *tmp;
    841     char *command;
    842     char *iso_mnt;
    843     char *iso_path;
    844     char *old_isodir;
    845     char cfg_file[100];
     783    char *value = NULL;
     784    char *tmp = NULL;
     785    char *command = NULL;
     786    char *iso_mnt = NULL;
     787    char *iso_path = NULL;
     788    char *old_isodir = NULL;
     789    char *cfg_file = NULL;
    846790    t_bkptype media_specified_by_user;
    847791
    848     malloc_string(command);
    849     malloc_string(iso_mnt);
    850     malloc_string(iso_path);
    851     malloc_string(old_isodir);
    852     malloc_string(value);
    853     malloc_string(tmp);
    854 //  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
    855792    assert(bkpinfo != NULL);
    856793
    857794    if (!cfgf) {
    858         strcpy(cfg_file, g_mondo_cfg_file);
    859     } else {
    860         strcpy(cfg_file, cfgf);
     795        cfg_file = g_mondo_cfg_file;
     796    } else {
     797        cfg_file = cfgf;
    861798    }
    862799
     
    873810            bkpinfo->backup_media_type = dvd;
    874811        } else if (!strcmp(value, "iso")) {
    875 /*
    876       if (am_I_in_disaster_recovery_mode()
    877       && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
    878       && does_file_exist(MNT_CDROM"/archives/filelist.0"))
    879 */
    880 
    881 // Patch by Conor Daly - 2004/07/12
     812            // Patch by Conor Daly - 2004/07/12
    882813            bkpinfo->backup_media_type = iso;
    883814            if (am_I_in_disaster_recovery_mode()) {
     
    896827                }
    897828            }
     829            paranoid_free(value);
     830
    898831            if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    899                     strcpy(bkpinfo->prefix,value);
     832                paranoid_free(bkpinfo->prefix);
     833                bkpinfo->prefix = value;
    900834            } else {
    901                     strcpy(bkpinfo->prefix,STD_PREFIX);
     835                paranoid_alloc(bkpinfo->prefix, STD_PREFIX);
    902836            }
    903837        } else if (!strcmp(value, "nfs")) {
    904838            bkpinfo->backup_media_type = nfs;
     839            paranoid_free(value);
    905840            if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    906                     strcpy(bkpinfo->prefix,value);
     841                paranoid_free(bkpinfo->prefix);
     842                bkpinfo->prefix = value;
    907843            } else {
    908                     strcpy(bkpinfo->prefix,STD_PREFIX);
     844                paranoid_alloc(bkpinfo->prefix, STD_PREFIX);
    909845            }
    910846        } else if (!strcmp(value, "tape")) {
     
    918854        fatal_error("backup-media-type not specified!");
    919855    }
     856    paranoid_free(value);
     857
    920858    if (bkpinfo->disaster_recovery) {
    921859        if (bkpinfo->backup_media_type == cdstream) {
     
    930868            read_cfg_var(cfg_file, "media-size", value);
    931869            bkpinfo->media_size[1] = atol(value);
    932             sprintf(tmp, "Backup medium is TAPE --- dev=%s",
     870            paranoid_free(value);
     871
     872            asprintf(&tmp, "Backup medium is TAPE --- dev=%s",
    933873                    bkpinfo->media_device);
    934874            log_msg(2, tmp);
     875            paranoid_free(tmp);
    935876        } else {
    936877            paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
     
    949890        log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
    950891    }
     892    paranoid_free(value);
    951893
    952894    if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
     
    960902                DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
    961903    }
     904    paranoid_free(value);
    962905
    963906    read_cfg_var(cfg_file, "use-lzo", value);
    964907    if (strstr(value, "yes")) {
    965908        bkpinfo->use_lzo = TRUE;
    966         strcpy(bkpinfo->zip_exe, "lzop");
    967         strcpy(bkpinfo->zip_suffix, "lzo");
    968     } else {
     909        paranoid_alloc(bkpinfo->zip_exe, "lzop");
     910        paranoid_alloc(bkpinfo->zip_suffix, "lzo");
     911    } else {
     912        paranoid_free(value);
    969913        read_cfg_var(cfg_file, "use-comp", value);
    970914        if (strstr(value, "yes")) {
    971915            bkpinfo->use_lzo = FALSE;
    972             strcpy(bkpinfo->zip_exe, "bzip2");
    973             strcpy(bkpinfo->zip_suffix, "bz2");
     916            paranoid_alloc(bkpinfo->zip_exe, "bzip2");
     917            paranoid_alloc(bkpinfo->zip_suffix, "bz2");
    974918        } else {
    975             bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    976         }
    977     }
    978 
    979     value[0] = '\0';
     919            // Just to be sure
     920            bkpinfo->zip_exe = NULL;
     921            bkpinfo->zip_suffix = NULL;
     922        }
     923    }
     924    paranoid_free(value);
     925
    980926    read_cfg_var(cfg_file, "differential", value);
    981927    if (!strcmp(value, "yes") || !strcmp(value, "1")) {
     
    983929    }
    984930    log_msg(2, "differential var = '%s'", value);
     931    paranoid_free(value);
     932
    985933    if (bkpinfo->differential) {
    986934        log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
     
    990938
    991939    read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
    992     if (tmp[0]
    993         ||
    994         strstr(call_program_and_get_last_line_of_output
    995                ("cat /proc/cmdline"), "donteject")) {
     940#ifdef __FreeBSD__
     941    tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline");
     942#else
     943    tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline");
     944#endif
     945    if ((tmp != NULL) || strstr(tmp1,"donteject")) {
    996946        bkpinfo->please_dont_eject = TRUE;
    997947        log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
    998948    }
     949    paranoid_free(tmp);
     950    paranoid_free(tmp1);
    999951
    1000952    if (bkpinfo->backup_media_type == nfs) {
     
    1018970         * isodir in disaster recovery mode
    1019971         */
    1020         strcpy(old_isodir, bkpinfo->isodir);
     972        old_isodir = bkpinfo->isodir;
    1021973        read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    1022974        read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
    1023         sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1024         if (!bkpinfo->isodir[0]) {
    1025             strcpy(bkpinfo->isodir, old_isodir);
    1026         }
     975        if (iso_mnt && iso_path) {
     976            asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     977        } else {
     978            bkpinfo->isodir = old_isodir;
     979        }
     980        paranoid_free(iso_mnt);
     981        paranoid_free(iso_path);
     982
    1027983        if (!bkpinfo->disaster_recovery) {
    1028984            if (strcmp(old_isodir, bkpinfo->isodir)) {
     
    1030986                    ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
    1031987                     old_isodir, bkpinfo->isodir);
    1032                 strcpy(bkpinfo->isodir, old_isodir);
    1033             }
    1034         }
     988                if (bkpinfo->isodir != old_isodir) {
     989                    paranoid_free(old_isodir);
     990                }
     991            } else {
     992                paranoid_free(old_isodir);
     993            }
     994        }
     995
    1035996        read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    1036         log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
    1037                 g_isodir_device);
     997        log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
    1038998        if (bkpinfo->disaster_recovery) {
    1039999            if (is_this_device_mounted(g_isodir_device)) {
    10401000                log_msg(2, "NB: isodir is already mounted");
    10411001                /* Find out where it's mounted */
    1042                 sprintf(command,
     1002                asprintf(&command,
    10431003                        "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
    10441004                        g_isodir_device);
    10451005                log_it("command = %s", command);
    1046                 log_it("res of it = %s",
    1047                        call_program_and_get_last_line_of_output(command));
    1048                 sprintf(iso_mnt, "%s",
    1049                         call_program_and_get_last_line_of_output(command));
     1006                tmp = call_program_and_get_last_line_of_output(command);
     1007                log_it("res of it = %s", tmp);
     1008                iso_mnt = tmp;
     1009                paranoid_free(command);
    10501010            } else {
    1051                 sprintf(iso_mnt, "/tmp/isodir");
    1052                 sprintf(tmp, "mkdir -p %s", iso_mnt);
     1011                asprintf(&iso_mnt, "/tmp/isodir");
     1012                asprintf(&tmp, "mkdir -p %s", iso_mnt);
    10531013                run_program_and_log_output(tmp, 5);
    1054                 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
     1014                paranoid_free(tmp);
     1015
     1016                asprintf(&tmp, "mount %s %s", g_isodir_device, iso_mnt);
    10551017                if (run_program_and_log_output(tmp, 3)) {
    10561018                    log_msg(1,
     
    10581020                    bkpinfo->backup_media_type = cdr;
    10591021                    paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
    1060                     bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
     1022                    paranoid_free(bkpinfo->isodir);
     1023                    paranoid_free(iso_mnt);
     1024                    paranoid_free(iso_path);
     1025                    asprintf(&iso_mnt, "");
     1026                    asprintf(&iso_path, "");
     1027
    10611028                    if (mount_cdrom(bkpinfo)) {
    10621029                        fatal_error
     
    10671034                    }
    10681035                }
     1036                paranoid_free(tmp);
    10691037            }
    10701038            /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
    10711039            if (bkpinfo->backup_media_type == iso) {
    1072                 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1073             }
     1040                paranoid_free(bkpinfo->isodir);
     1041                asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1042            }
     1043            paranoid_free(iso_mnt);
     1044            paranoid_free(iso_path);
    10741045        }
    10751046    }
     
    10801051                log_msg(2,
    10811052                        "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
    1082                 interactively_obtain_media_parameters_from_user(bkpinfo,
    1083                                                                 FALSE);
     1053                interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    10841054                media_specified_by_user = bkpinfo->backup_media_type;
    10851055                get_cfg_file_from_archive(bkpinfo);
     
    10931063    }
    10941064    g_backup_media_type = bkpinfo->backup_media_type;
    1095     paranoid_free(value);
    1096     paranoid_free(tmp);
    1097     paranoid_free(command);
    1098     paranoid_free(iso_mnt);
    1099     paranoid_free(iso_path);
    1100     paranoid_free(old_isodir);
    11011065    return (0);
    1102 
    1103 }
    1104 
     1066}
    11051067/**************************************************************************
    11061068 *END_READ_CFG_FILE_INTO_BKPINFO                                          *
    11071069 **************************************************************************/
    1108 
    1109 
    11101070
    11111071
     
    11251085    struct s_node *filelist;
    11261086
    1127   /** add mallocs**/
    1128     char *command;
    1129     char *tmp;
     1087    char *command = NULL;
     1088    char *tmp = NULL;
    11301089    int res = 0;
     1090    size_t n = 0;
    11311091    pid_t pid;
    11321092
    11331093    assert(bkpinfo != NULL);
    1134     malloc_string(command);
    11351094    malloc_string(tmp);
    11361095
     
    11501109        unlink("/tmp/i-want-my-lvm");
    11511110        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    1152             sprintf(command,
     1111            asprintf(&command,
    11531112                    "tar -zxf %s %s %s %s %s %s",
    11541113                    bkpinfo->media_device,
     
    11591118            log_msg(1, "tarcommand = %s", command);
    11601119            run_program_and_log_output(command, 1);
     1120            paranoid_free(command);
    11611121        } else {
    11621122            log_msg(2,
     
    11661126            log_msg(2, "Back from iotcn");
    11671127            run_program_and_log_output("mount", 1);
    1168             sprintf(command,
     1128            asprintf(&command,
    11691129                    "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
    11701130                    MNT_CDROM,
     
    11761136            log_msg(1, "tarcommand = %s", command);
    11771137            run_program_and_log_output(command, 1);
    1178 //    popup_and_OK("Press ENTER to continue");
     1138            paranoid_free(command);
     1139
    11791140            if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
    11801141                fatal_error
     
    11861147            }
    11871148        }
    1188         sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
     1149        asprintf(&command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
    11891150                g_mondo_cfg_file);
    11901151        run_program_and_log_output(command, FALSE);
    1191 
    1192         sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
     1152        paranoid_free(command);
     1153
     1154        asprintf(&command, "cp -f %s/%s %s", bkpinfo->tmpdir,
    11931155                BIGGIELIST_TXT_STUB, g_biggielist_txt);
    11941156        log_msg(1, "command = %s", command);
    11951157        paranoid_system(command);
    1196         sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
     1158        paranoid_free(command);
     1159
     1160        asprintf(&command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
    11971161                FILELIST_FULL_STUB, g_filelist_full);
    11981162        log_msg(1, "command = %s", command);
    11991163        paranoid_system(command);
     1164        paranoid_free(command);
    12001165    }
    12011166
    12021167    if (am_I_in_disaster_recovery_mode()
    12031168        &&
    1204         ask_me_yes_or_no(_("Do you want to retrieve the mountlist as well?")))
     1169        ask_me_yes_or_no(_
     1170                         ("Do you want to retrieve the mountlist as well?")))
    12051171    {
    1206 //      sprintf(command, "cp -f tmp/mountlist.txt /tmp");
    1207         sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
     1172        asprintf(&command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
    12081173                bkpinfo->tmpdir);
    12091174        paranoid_system(command);
     1175        paranoid_free(command);
    12101176    }
    12111177
    12121178    chdir(tmp);
     1179    paranoid_free(tmp);
    12131180
    12141181    if (!does_file_exist(g_biggielist_txt)) {
     
    12301197        log_to_screen(("Pre-processing filelist"));
    12311198        if (!does_file_exist(g_biggielist_txt)) {
    1232             sprintf(command, "> %s", g_biggielist_txt);
     1199            asprintf(&command, "> %s", g_biggielist_txt);
    12331200            paranoid_system(command);
    1234         }
    1235         sprintf(command, "grep  -x \"/dev/.*\" %s > %s",
     1201            paranoid_free(command);
     1202        }
     1203        asprintf(&command, "grep  -x \"/dev/.*\" %s > %s",
    12361204                g_biggielist_txt, g_filelist_imagedevs);
    12371205        paranoid_system(command);
     1206        paranoid_free(command);
    12381207        exit(0);
    12391208        break;
     
    12541223    if (g_text_mode) {
    12551224        printf(_("Restore which directory? --> "));
    1256         fgets(tmp, sizeof(tmp), stdin);
     1225        getline(&tmp, &n, stdin);
    12571226        toggle_path_selection(filelist, tmp, TRUE);
    12581227        if (strlen(tmp) == 0) {
     
    12611230            res = 0;
    12621231        }
     1232        paranoid_free(tmp);
    12631233    } else {
    12641234        res = edit_filelist(filelist);
     
    12821252                                      TRUE);
    12831253    }
    1284 
    1285     paranoid_free(command);
    1286     paranoid_free(tmp);
    12871254    return (filelist);
    12881255}
    1289 
    12901256/**************************************************************************
    12911257 *END_ PROCESS_FILELIST_AND_BIGGIELIST                                    *
    12921258 **************************************************************************/
    1293 
    1294 
    12951259
    12961260
     
    13041268int backup_crucial_file(char *path_root, char *filename)
    13051269{
    1306     char *tmp;
    1307     char *command;
    1308     int res;
    1309 
    1310     malloc_string(tmp);
    1311     malloc_string(command);
     1270    char *command = NULL;
     1271    int res = 0;
     1272
    13121273    assert(path_root != NULL);
    13131274    assert_string_is_neither_NULL_nor_zerolength(filename);
    13141275
    1315     sprintf(tmp, "%s/%s", path_root, filename);
    1316     sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
    1317 
     1276    asprintf(&command, "cp -f %s/%s %s/%s.pristine", path_root, filename,path_root, filename);
    13181277    res = run_program_and_log_output(command, 5);
    1319     paranoid_free(tmp);
    13201278    paranoid_free(command);
    13211279    return (res);
     
    13341292    int retval = 0;
    13351293
    1336   /** malloc *******/
    1337     char *device;
    1338     char *tmp;
    1339     char *name;
    1340 
    1341     malloc_string(device);
    1342     malloc_string(tmp);
    1343     malloc_string(name);
     1294    char *device = NULL;
     1295    char *tmp = NULL;
     1296    char *name = NULL;
     1297
    13441298    backup_crucial_file(MNT_RESTORING, "/etc/fstab");
    13451299    backup_crucial_file(MNT_RESTORING, "/etc/grub.conf");
     
    13481302    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    13491303    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
    1350     sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);
     1304    asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);
    13511305    log_msg(2, tmp);
    1352     system("sync");
     1306    paranoid_free(tmp);
     1307
     1308    sync();
    13531309    if (!strcmp(name, "LILO")) {
    13541310        res = run_lilo(offer_to_hack_scripts);
     
    13711327#ifdef __FreeBSD__
    13721328    else if (!strcmp(name, "BOOT0")) {
    1373         sprintf(tmp, "boot0cfg -B %s", device);
     1329        asprintf(&tmp, "boot0cfg -B %s", device);
    13741330        res = run_program_and_log_output(tmp, FALSE);
    1375     } else {
    1376         sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device);
     1331        paranoid_free(tmp);
     1332    } else {
     1333        asprintf(&tmp, "ls /dev | grep -xq %ss[1-4].*", device);
    13771334        if (!system(tmp)) {
    1378             sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
     1335            paranoid_free(tmp);
     1336            asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    13791337            res = run_program_and_log_output(tmp, 3);
    13801338        } else {
     
    13821340                    "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
    13831341        }
     1342        paranoid_free(tmp);
    13841343    }
    13851344#else
    13861345    else {
    13871346        log_to_screen
    1388             (_("Unable to determine type of boot loader. Defaulting to LILO."));
     1347            (_
     1348             ("Unable to determine type of boot loader. Defaulting to LILO."));
    13891349        res = run_lilo(offer_to_hack_scripts);
    13901350    }
    13911351#endif
     1352    paranoid_free(device);
     1353    paranoid_free(name);
     1354
    13921355    retval += res;
    13931356    if (res) {
     
    13961359        log_to_screen(_("Your boot loader ran OK"));
    13971360    }
    1398     paranoid_free(device);
    1399     paranoid_free(tmp);
    1400     paranoid_free(name);
    14011361    return (retval);
    14021362}
    1403 
    14041363/**************************************************************************
    14051364 *END_ RUN_BOOT_LOADER                                                    *
     
    14071366
    14081367
    1409 
    14101368/**
    14111369 * Attempt to find the user's editor.
    14121370 * @return The editor found ("vi" if none could be found).
    1413  * @note The returned string points to static storage that will be overwritten with each call.
     1371 * @note The returned string points to malloced storage that needs to be freed by caller
    14141372 */
    14151373char *find_my_editor(void)
    14161374{
    1417     static char output[MAX_STR_LEN];
     1375    char *output = NULL;
     1376
     1377    /* BERLIOS: This should use $EDITOR + conf file rather first */
    14181378    if (find_home_of_exe("pico")) {
    1419         strcpy(output, "pico");
     1379        asprintf(&output, "pico");
    14201380    } else if (find_home_of_exe("nano")) {
    1421         strcpy(output, "nano");
     1381        asprintf(&output, "nano");
    14221382    } else if (find_home_of_exe("e3em")) {
    1423         strcpy(output, "e3em");
     1383        asprintf(&output, "e3em");
    14241384    } else if (find_home_of_exe("e3vi")) {
    1425         strcpy(output, "e3vi");
    1426     } else {
    1427         strcpy(output, "vi");
     1385        asprintf(&output, "e3vi");
     1386    } else {
     1387        asprintf(&output, "vi");
    14281388    }
    14291389    if (!find_home_of_exe(output)) {
     
    14421402int run_grub(bool offer_to_run_stabgrub, char *bd)
    14431403{
    1444   /** malloc **/
    1445     char *command;
    1446     char *boot_device;
    1447     char *rootdev;
    1448     char *rootdrive;
    1449     char *conffile;
    1450     char *tmp;
    1451     char *editor;
    1452 
    1453     int res;
    1454     int done;
    1455 
    1456     malloc_string(command);
    1457     malloc_string(boot_device);
    1458     malloc_string(tmp);
    1459     malloc_string(editor);
    1460     malloc_string(rootdev);
    1461     malloc_string(rootdrive);
    1462     malloc_string(conffile);
     1404    char *command = NULL;
     1405    char *tmp = NULL;
     1406    char *editor = NULL;
     1407
     1408    int res = 0;
     1409    int done = 0;
     1410
    14631411    assert_string_is_neither_NULL_nor_zerolength(bd);
    1464     strcpy(editor, "vi");       // find_my_editor() );
    1465     strcpy(boot_device, bd);
    1466 
    1467     if (!run_program_and_log_output("which grub-MR", FALSE)) {
    1468         log_msg(1, "Yay! grub-MR found...");
    1469         sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
    1470         log_msg(1, "command = %s", command);
    1471     } else {
    1472         sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
    1473                 boot_device);
    1474         log_msg(1, "WARNING - grub-MR not found; using grub-install");
    1475     }
     1412
    14761413    if (offer_to_run_stabgrub
    14771414        && ask_me_yes_or_no(_("Did you change the mountlist?")))
     
    14801417        mvaddstr_and_log_it(g_currentY,
    14811418                            0,
    1482                             _("Modifying fstab and grub.conf, and running GRUB...                             "));
     1419                            _
     1420                            ("Modifying fstab and grub.conf, and running GRUB...                             "));
    14831421        for (done = FALSE; !done;) {
    14841422            popup_and_get_string(_("Boot device"),
    1485                                  _("Please confirm/enter the boot device. If in doubt, try /dev/hda"),
    1486                                  boot_device, MAX_STR_LEN / 4);
    1487             sprintf(command, "stabgrub-me %s", boot_device);
     1423                                 _("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd);
     1424            asprintf(&command, "stabgrub-me %s", bd);
    14881425            res = run_program_and_log_output(command, 1);
     1426            paranoid_free(command);
     1427
    14891428            if (res) {
    14901429                popup_and_OK
    1491                     (_("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."));
     1430                    (_
     1431                     ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."));
    14921432                newtSuspend();
    14931433                system("chroot " MNT_RESTORING);
     
    15011441                newtSuspend();
    15021442            }
    1503             sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1443            editor = find_my_editor();
     1444            asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    15041445            paranoid_system(tmp);
    1505             sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
     1446            paranoid_free(tmp);
     1447
     1448            asprintf(&tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor);
     1449            paranoid_free(editor);
     1450
    15061451            paranoid_system(tmp);
     1452            paranoid_free(tmp);
     1453
    15071454            if (!g_text_mode) {
    15081455                newtResume();
    15091456            }
    15101457        }
    1511     } else
     1458    } else {
    15121459        /* nuke mode */
    1513     {
     1460        if (!run_program_and_log_output("which grub-MR", FALSE)) {
     1461            log_msg(1, "Yay! grub-MR found...");
     1462            asprintf(&command, "grub-MR %s /tmp/mountlist.txt", bd);
     1463            log_msg(1, "command = %s", command);
     1464        } else {
     1465            asprintf(&command, "chroot " MNT_RESTORING " grub-install %s", bd);
     1466            log_msg(1, "WARNING - grub-MR not found; using grub-install");
     1467        }
    15141468        mvaddstr_and_log_it(g_currentY,
    15151469                            0,
    1516                             _("Running GRUB...                                                 "));
     1470                            _
     1471                            ("Running GRUB...                                                 "));
    15171472        iamhere(command);
    15181473        res = run_program_and_log_output(command, 1);
     1474        paranoid_free(command);
     1475
    15191476        if (res) {
    15201477            popup_and_OK
    1521                 (_("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."));
     1478                (_
     1479                 ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."));
    15221480            newtSuspend();
    15231481            system("chroot " MNT_RESTORING);
     
    15291487        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    15301488        log_to_screen
    1531             (_("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."));
     1489            (_
     1490             ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."));
    15321491        log_msg(1, "Type:-");
    15331492        log_msg(1, "    mount-me");
     
    15421501        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    15431502    }
    1544     paranoid_free(rootdev);
    1545     paranoid_free(rootdrive);
    1546     paranoid_free(conffile);
    1547     paranoid_free(command);
    1548     paranoid_free(boot_device);
    1549     paranoid_free(tmp);
    1550     paranoid_free(editor);
    1551 
    15521503    return (res);
    15531504}
    1554 
    15551505/**************************************************************************
    15561506 *END_RUN_GRUB                                                            *
     
    15651515int run_elilo(bool offer_to_run_stabelilo)
    15661516{
    1567   /** malloc **/
    1568     char *command;
    1569     char *tmp;
    1570     char *editor;
    1571 
    1572     int res;
    1573     int done;
    1574 
    1575     malloc_string(command);
    1576     malloc_string(tmp);
    1577     malloc_string(editor);
    1578     strcpy(editor, find_my_editor());
     1517    char *command = NULL;
     1518    char *tmp = NULL;
     1519    char *editor = NULL;
     1520
     1521    int res = 0;
     1522    int done = 0;
     1523
    15791524    if (offer_to_run_stabelilo
    15801525        && ask_me_yes_or_no(_("Did you change the mountlist?")))
     
    15841529        mvaddstr_and_log_it(g_currentY,
    15851530                            0,
    1586                             _("Modifying fstab and elilo.conf...                             "));
    1587         sprintf(command, "stabelilo-me");
     1531                            _
     1532                            ("Modifying fstab and elilo.conf...                             "));
     1533        asprintf(&command, "stabelilo-me");
    15881534        res = run_program_and_log_output(command, 3);
     1535        paranoid_free(command);
     1536
    15891537        if (res) {
    15901538            popup_and_OK
    1591                 (_("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."));
     1539                (_
     1540                 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."));
    15921541            for (done = FALSE; !done;) {
    15931542                if (!g_text_mode) {
    15941543                    newtSuspend();
    15951544                }
    1596                 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1545                editor = find_my_editor();
     1546                asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    15971547                paranoid_system(tmp);
    1598                 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf",
    1599                         editor);
     1548                paranoid_free(tmp);
     1549
     1550                asprintf(&tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor);
     1551                paranoid_free(editor);
     1552
    16001553                paranoid_system(tmp);
     1554                paranoid_free(tmp);
     1555
    16011556                if (!g_text_mode) {
    16021557                    newtResume();
     
    16161571        res = TRUE;
    16171572    }
    1618     paranoid_free(command);
    1619     paranoid_free(tmp);
    1620     paranoid_free(editor);
    16211573    return (res);
    16221574}
    1623 
    16241575/**************************************************************************
    16251576 *END_RUN_ELILO                                                            *
     
    16351586{
    16361587  /** malloc **/
    1637     char *command;
    1638     char *tmp;
    1639     char *editor;
    1640 
    1641     int res;
    1642     int done;
     1588    char *command = NULL;
     1589    char *tmp = NULL;
     1590    char *editor = NULL;
     1591
     1592    int res = 0;
     1593    int done = 0;
    16431594    bool run_lilo_M = FALSE;
    1644     malloc_string(command);
    1645     malloc_string(tmp);
    1646     malloc_string(editor);
    16471595
    16481596    if (!run_program_and_log_output
     
    16511599    }
    16521600
    1653     strcpy(editor, find_my_editor());
    16541601    if (offer_to_run_stablilo
    1655         && ask_me_yes_or_no(_("Did you change the mountlist?")))
    1656 
     1602        && ask_me_yes_or_no(_("Did you change the mountlist?"))) {
    16571603        /* interactive mode */
    1658     {
    16591604        mvaddstr_and_log_it(g_currentY,
    16601605                            0,
    1661                             _("Modifying fstab and lilo.conf, and running LILO...                             "));
    1662         sprintf(command, "stablilo-me");
     1606                            _
     1607                            ("Modifying fstab and lilo.conf, and running LILO...                             "));
     1608        asprintf(&command, "stablilo-me");
    16631609        res = run_program_and_log_output(command, 3);
     1610        paranoid_free(command);
     1611
    16641612        if (res) {
    16651613            popup_and_OK
    1666                 (_("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."));
     1614                (_
     1615                 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."));
    16671616            for (done = FALSE; !done;) {
    16681617                if (!g_text_mode) {
    16691618                    newtSuspend();
    16701619                }
    1671                 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1620                editor = find_my_editor();
     1621                asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    16721622                paranoid_system(tmp);
    1673                 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1623                paranoid_free(tmp);
     1624
     1625                asprintf(&tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
     1626                paranoid_free(editor);
     1627
    16741628                paranoid_system(tmp);
     1629                paranoid_free(tmp);
     1630
    16751631                if (!g_text_mode) {
    16761632                    newtResume();
     
    16991655            log_to_screen(_("lilo.conf and fstab were modified OK"));
    17001656        }
    1701     } else
     1657    } else {
    17021658        /* nuke mode */
    1703     {
    17041659        mvaddstr_and_log_it(g_currentY,
    17051660                            0,
    1706                             _("Running LILO...                                                 "));
     1661                            _
     1662                            ("Running LILO...                                                 "));
    17071663        res =
    17081664            run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
     
    17161672            mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    17171673            log_to_screen
    1718                 (_("Failed to re-jig fstab and/or lilo. Edit/run manually, please."));
     1674                (_
     1675                 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please."));
    17191676        } else {
    17201677            mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
     
    17271684                                   " lilo -M /dev/sda", 3);
    17281685    }
    1729     paranoid_free(command);
    1730     paranoid_free(tmp);
    1731     paranoid_free(editor);
    17321686    return (res);
    17331687}
     
    17461700int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
    17471701{
    1748   /** malloc **/
    1749     char *command;
    1750     char *boot_device;
    1751     char *tmp;
    1752     char *editor;
    1753     int res;
    1754     int done;
    1755 
    1756     malloc_string(command);
    1757     malloc_string(boot_device);
    1758     malloc_string(tmp);
    1759     malloc_string(editor);
     1702    char *command = NULL;
     1703    char *tmp = NULL;
     1704    char *editor = NULL;
     1705    int res = 0;
     1706    int done = 0;
     1707
    17601708    assert_string_is_neither_NULL_nor_zerolength(bd);
    17611709
    1762     strcpy(editor, find_my_editor());
    1763     strcpy(boot_device, bd);
    1764     sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
    1765     log_msg(2, "run_raw_mbr() --- command='%s'", command);
    1766 
    17671710    if (offer_to_hack_scripts
    1768         && ask_me_yes_or_no(_("Did you change the mountlist?")))
     1711        && ask_me_yes_or_no(_("Did you change the mountlist?"))) {
    17691712        /* interactive mode */
    1770     {
    17711713        mvaddstr_and_log_it(g_currentY, 0,
    1772                             _("Modifying fstab and restoring MBR...                           "));
     1714                            _
     1715                            ("Modifying fstab and restoring MBR...                           "));
    17731716        for (done = FALSE; !done;) {
    17741717            if (!run_program_and_log_output("which vi", FALSE)) {
     
    17771720                    newtSuspend();
    17781721                }
    1779                 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1722                editor = find_my_editor();
     1723                asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1724                paranoid_free(editor);
     1725
    17801726                paranoid_system(tmp);
     1727                paranoid_free(tmp);
     1728
    17811729                if (!g_text_mode) {
    17821730                    newtResume();
     
    17851733            }
    17861734            popup_and_get_string(_("Boot device"),
    1787                                  _("Please confirm/enter the boot device. If in doubt, try /dev/hda"),
    1788                                  boot_device, MAX_STR_LEN / 4);
    1789             sprintf(command, "stabraw-me %s", boot_device);
     1735                                 _
     1736                                 ("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd);
     1737            asprintf(&command, "stabraw-me %s", bd);
    17901738            res = run_program_and_log_output(command, 3);
     1739            paranoid_free(command);
     1740
    17911741            if (res) {
    1792                 done = ask_me_yes_or_no(_("Modifications failed. Re-try?"));
     1742                done =
     1743                    ask_me_yes_or_no(_("Modifications failed. Re-try?"));
    17931744            } else {
    17941745                done = TRUE;
    17951746            }
    17961747        }
    1797     } else
     1748    } else {
    17981749        /* nuke mode */
    1799     {
    18001750        mvaddstr_and_log_it(g_currentY, 0,
    1801                             _("Restoring MBR...                                               "));
     1751                            _
     1752                            ("Restoring MBR...                                               "));
     1753        asprintf(&command, "raw-MR %s /tmp/mountlist.txt", bd);
     1754        log_msg(2, "run_raw_mbr() --- command='%s'", command);
    18021755        res = run_program_and_log_output(command, 3);
     1756        paranoid_free(command);
    18031757    }
    18041758    if (res) {
    18051759        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    18061760        log_to_screen
    1807             (_("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."));
     1761            (_
     1762             ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."));
    18081763    } else {
    18091764        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    18101765    }
    1811     paranoid_free(command);
    1812     paranoid_free(boot_device);
    1813     paranoid_free(tmp);
    1814     paranoid_free(editor);
    18151766    return (res);
    18161767}
    1817 
    18181768/**************************************************************************
    18191769 *END_RUN_RAW_MBR                                                         *
    18201770 **************************************************************************/
    1821 
    1822 
    1823 
    18241771
    18251772
     
    18581805void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo)
    18591806{
    1860     char *temppath;
    1861 
    18621807    assert(bkpinfo != NULL);
    18631808
    1864     malloc_string(g_biggielist_txt);
    1865     malloc_string(g_filelist_full);
    1866     malloc_string(g_filelist_imagedevs);
    1867     malloc_string(g_imagedevs_restthese);
    1868     malloc_string(g_mondo_cfg_file);
    1869     malloc_string(g_mountlist_fname);
    18701809    malloc_string(g_tmpfs_mountpt);
    1871     malloc_string(g_isodir_device);
    1872     malloc_string(g_isodir_format);
    1873 
    1874     temppath = bkpinfo->tmpdir;
    1875 
    1876     sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
    1877     sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
    1878     sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
    1879 //  sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
    1880     sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
    1881             temppath);
     1810
     1811    asprintf(&g_biggielist_txt, "%s/%s",bkpinfo->tmpdir , BIGGIELIST_TXT_STUB);
     1812    asprintf(&g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);
     1813    asprintf(&g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir);
     1814    asprintf(&g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
     1815            bkpinfo->tmpdir);
    18821816    if (bkpinfo->disaster_recovery) {
    1883         sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
    1884         sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
    1885     } else {
    1886         sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
    1887         sprintf(g_mountlist_fname, "%s/%s", temppath,
    1888                 MOUNTLIST_FNAME_STUB);
    1889     }
    1890 }
    1891 
     1817        asprintf(&g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
     1818        asprintf(&g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
     1819    } else {
     1820        asprintf(&g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
     1821        asprintf(&g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
     1822    }
     1823}
    18921824/**************************************************************************
    18931825 *END_SET_GLOBAL_FILENAME                                                 *
     
    19051837    FILE *fin;
    19061838    FILE *fout;
    1907   /** malloc **/
    1908     char *incoming;
     1839    char *incoming = NULL;
     1840    size_t n = 0;
    19091841
    19101842    assert_string_is_neither_NULL_nor_zerolength(output_file);
    19111843    assert_string_is_neither_NULL_nor_zerolength(input_file);
    1912     malloc_string(incoming);
    19131844
    19141845    if (!(fin = fopen(input_file, "r"))) {
     
    19191850        fatal_error("cannot open output_file");
    19201851    }
    1921     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    1922          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1852    for (getline(&incoming, &n, fin); !feof(fin);
     1853         getline(&incoming, &n, fin)) {
    19231854        if (strncmp(incoming, "etc/adjtime", 11)
    19241855            && strncmp(incoming, "etc/mtab", 8)
     
    19301861            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
    19311862    }
     1863    paranoid_free(incoming);
    19321864    paranoid_fclose(fout);
    19331865    paranoid_fclose(fin);
    1934     paranoid_free(incoming);
    1935 }
    1936 
     1866}
    19371867/**************************************************************************
    19381868 *END_STREAMLINE_CHANGES_FILE                                             *
     
    19471877{
    19481878    log_to_screen
    1949         (_("Mondorestore is terminating in response to a signal from the OS"));
     1879        (_
     1880         ("Mondorestore is terminating in response to a signal from the OS"));
    19501881    paranoid_MR_finish(254);
    19511882}
    1952 
    19531883/**************************************************************************
    19541884 *END_TERMINATE_DAEMON                                                    *
     
    19621892{
    19631893    int i;
    1964     /* MALLOC * */
    1965     char *tmp;
    1966 
    1967     malloc_string(tmp);
     1894    char *tmp = NULL;
     1895
    19681896    if (does_file_exist("/tmp/NOPAUSE")) {
    19691897        return;
    19701898    }
    19711899    open_progress_form(_("CAUTION"),
    1972                        _("Be advised: I am about to ERASE your hard disk(s)!"),
     1900                       _
     1901                       ("Be advised: I am about to ERASE your hard disk(s)!"),
    19731902                       _("You may press Ctrl+Alt+Del to abort safely."),
    19741903                       "", 20);
    19751904    for (i = 0; i < 20; i++) {
    19761905        g_current_progress = i;
    1977         sprintf(tmp, _("You have %d seconds left to abort."), 20 - i);
     1906        asprintf(&tmp, _("You have %d seconds left to abort."), 20 - i);
    19781907        update_progress_form(tmp);
     1908        paranoid_free(tmp);
    19791909        sleep(1);
    19801910    }
    19811911    close_progress_form();
    1982     paranoid_free(tmp);
    1983 }
    1984 
     1912}
    19851913/**************************************************************************
    19861914 *END_TWENTY_SECONDS_TIL_YIKES                                            *
     
    19881916
    19891917
    1990 
    1991 
    1992 
    19931918/**
    19941919 * Exit due to a signal (no cleanup).
     
    20011926    pthread_exit(0);
    20021927}
    2003 
    20041928/**************************************************************************
    20051929 *END_TERMINATION_IN_PROGRESS                                             *
     
    20071931
    20081932
    2009 
    20101933/**
    20111934 * Unmount all devices in @p p_external_copy_of_mountlist.
     
    20171940{
    20181941    struct mountlist_itself *mountlist;
    2019     int retval = 0, lino, res = 0, i;
    2020     char *command;
    2021     char *tmp;
    2022 
    2023     malloc_string(command);
    2024     malloc_string(tmp);
     1942    int retval = 0;
     1943    int lino = 0;
     1944    int res = 0;
     1945    int i = 0;
     1946    char *command = NULL;
     1947    char *tmp = NULL;
     1948    char *tmp1 = NULL;
     1949
    20251950    assert(p_external_copy_of_mountlist != NULL);
    20261951
     
    20341959    open_progress_form(_("Unmounting devices"),
    20351960                       _("Unmounting all devices that were mounted,"),
    2036                        _("in preparation for the post-restoration reboot."),
     1961                       _
     1962                       ("in preparation for the post-restoration reboot."),
    20371963                       "", mountlist->entries);
    20381964    chdir("/");
     
    20471973    }
    20481974
    2049     paranoid_system("sync");
     1975    sync();
    20501976
    20511977    if (run_program_and_log_output
     
    20671993            continue;
    20681994        }
    2069         sprintf(tmp, _("Unmounting device %s  "), mountlist->el[lino].device);
     1995        asprintf(&tmp, _("Unmounting device %s  "),
     1996                mountlist->el[lino].device);
    20701997
    20711998        update_progress_form(tmp);
     1999
    20722000        if (is_this_device_mounted(mountlist->el[lino].device)) {
    20732001            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
    2074                 sprintf(command, "swapoff %s", mountlist->el[lino].device);
     2002                asprintf(&command, "swapoff %s", mountlist->el[lino].device);
    20752003            } else {
    20762004                if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
    2077                     sprintf(command, "umount %s/", MNT_RESTORING);
     2005                    asprintf(&command, "umount %s/", MNT_RESTORING);
    20782006                    log_msg(3,
    20792007                            "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
    20802008                } else {
    2081                     sprintf(command, "umount " MNT_RESTORING "%s",
     2009                    asprintf(&command, "umount " MNT_RESTORING "%s",
    20822010                            mountlist->el[lino].mountpoint);
    20832011                }
     
    20852013            log_msg(10, "The 'umount' command is '%s'", command);
    20862014            res = run_program_and_log_output(command, 3);
     2015            paranoid_free(command);
    20872016        } else {
    2088             strcat(tmp, _("...not mounted anyway :-) OK"));
     2017            asprintf(&tmp1, "%s%s", tmp, _("...not mounted anyway :-) OK"));
     2018            paranoid_free(tmp);
     2019            tmp = tmp1;
    20892020            res = 0;
    20902021        }
    20912022        g_current_progress++;
    20922023        if (res) {
    2093             strcat(tmp, _("...Failed"));
     2024            asprintf(&tmp1, "%s%s", tmp, _("...Failed"));
     2025            paranoid_free(tmp);
     2026            tmp = tmp1;
    20942027            retval++;
    20952028            log_to_screen(tmp);
     
    20972030            log_msg(2, tmp);
    20982031        }
     2032        paranoid_free(tmp);
    20992033    }
    21002034    close_progress_form();
     
    21102044    }
    21112045    free(mountlist);
    2112     paranoid_free(command);
    2113     paranoid_free(tmp);
    21142046    return (retval);
    21152047}
    2116 
    21172048/**************************************************************************
    21182049 *END_UNMOUNT_ALL_DEVICES                                                 *
    21192050 **************************************************************************/
    2120 
    21212051
    21222052
     
    21292059int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
    21302060{
    2131     char *command;
     2061    char *command = NULL;
    21322062    int res = 0;
    2133     // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
     2063    // BERLIOS: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
    21342064    long tape_block_size = 32768;
    21352065
    2136     malloc_string(command);
    2137 
    21382066    // tar -zxvf-
    2139     sprintf(command,
     2067    asprintf(&command,
    21402068            "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
    21412069            dev,
     
    21462074    log_msg(2, "command = '%s'", command);
    21472075    res = run_program_and_log_output(command, -1);
     2076    paranoid_free(command);
     2077
    21482078    if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) {
    21492079        res = 0;
    21502080    }
    2151     paranoid_free(command);
    21522081    return (res);
    21532082}
    2154 
    21552083
    21562084
     
    21662094{
    21672095    int retval = 0;
    2168 
    2169    /** malloc *****/
    2170     char *device;
    2171     char *command;
    2172     char *cfg_file;
    2173     char *mounted_cfgf_path;
    2174     char *tmp;
    2175     char *sav;
    2176     char *mountpt;
    2177     char *ramdisk_fname;
    2178     char *mountlist_file;
    2179     int res;
     2096    char *device = NULL;
     2097    char *command = NULL;
     2098    char *cfg_file = NULL;
     2099    char *mounted_cfgf_path = NULL;
     2100    char *tmp = NULL;
     2101    char *tmp1 = NULL;
     2102    char *sav = NULL;
     2103    char *mountpt = NULL;
     2104    char *ramdisk_fname = NULL;
     2105    char *mountlist_file = NULL;
     2106    int res = 0;
    21802107
    21812108    bool try_plan_B;
    21822109
    21832110    assert(bkpinfo != NULL);
    2184     malloc_string(cfg_file);
    2185     malloc_string(mounted_cfgf_path);
    2186     malloc_string(mountpt);
    2187     malloc_string(ramdisk_fname);
    2188     malloc_string(mountlist_file);
    2189     malloc_string(device);
    2190     malloc_string(command);
    2191     malloc_string(tmp);
    21922111    log_msg(2, "gcffa --- starting");
    21932112    log_to_screen(_("I'm thinking..."));
    2194     sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    2195     device[0] = '\0';
     2113    asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    21962114    chdir(bkpinfo->tmpdir);
    2197     strcpy(cfg_file, MONDO_CFG_FILE_STUB);
    2198     unlink(cfg_file);           // cfg_file[] is missing the '/' at the start, FYI, by intent
     2115    // MONDO_CFG_FILE_STUB is missing the '/' at the start, FYI, by intent
     2116    unlink(MONDO_CFG_FILE_STUB);
     2117
    21992118    unlink(FILELIST_FULL_STUB);
    22002119    unlink(BIGGIELIST_TXT_STUB);
    22012120    unlink("tmp/i-want-my-lvm");
    2202     sprintf(command, "mkdir -p %s", mountpt);
     2121    asprintf(&command, "mkdir -p %s", mountpt);
    22032122    run_program_and_log_output(command, FALSE);
    2204 
    2205 //   unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely?
    2206 
    2207     sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
    2208     sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir,
     2123    paranoid_free(command);
     2124
     2125    asprintf(&cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
     2126    asprintf(&mountlist_file, "%s/%s", bkpinfo->tmpdir,
    22092127            MOUNTLIST_FNAME_STUB);
    2210     //   make_hole_for_file( cfg_file );
    2211     //   make_hole_for_file( mountlist_file);
    22122128    log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
    22132129
    22142130    /* Floppy? */
    2215     sprintf(tmp, "mkdir -p %s", mountpt);
     2131    asprintf(&tmp, "mkdir -p %s", mountpt);
    22162132    run_program_and_log_output(tmp, FALSE);
    2217     sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     2133    paranoid_free(tmp);
     2134
     2135    asprintf(&tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    22182136    run_program_and_log_output(tmp, FALSE);
    2219 
    2220     sprintf(command, "mount /dev/fd0u1722 %s", mountpt);
    2221     sprintf(tmp,
     2137    paranoid_free(tmp);
     2138
     2139    asprintf(&command, "mount /dev/fd0u1722 %s", mountpt);
     2140    asprintf(&tmp,
    22222141            "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &",
    22232142            command);
    22242143    log_msg(1, "tmp = '%s'", tmp);
    22252144    system(tmp);
     2145    paranoid_free(tmp);
     2146
    22262147    res = run_program_and_log_output(command, FALSE);
     2148    paranoid_free(command);
     2149
    22272150    if (res) {
    2228         sprintf(command, "mount /dev/fd0H1440 %s", mountpt);
     2151        asprintf(&command, "mount /dev/fd0H1440 %s", mountpt);
    22292152        res = run_program_and_log_output(command, FALSE);
     2153        paranoid_free(command);
    22302154    }
    22312155    if (res) {
     
    22372161// NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK.
    22382162        log_msg(2, "Processing floppy (plan A?)");
    2239         sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);
     2163        asprintf(&ramdisk_fname, "%s/mindi.rdz", mountpt);
    22402164        if (!does_file_exist(ramdisk_fname)) {
    2241             sprintf(ramdisk_fname, "%s/initrd.img", mountpt);
     2165            paranoid_free(ramdisk_fname);
     2166            asprintf(&ramdisk_fname, "%s/initrd.img", mountpt);
    22422167        }
    22432168        if (!does_file_exist(ramdisk_fname)) {
     
    22502175                    "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled.");
    22512176        }
    2252         sprintf(command, "umount %s", mountpt);
     2177        asprintf(&command, "umount %s", mountpt);
    22532178        run_program_and_log_output(command, 5);
     2179        paranoid_free(command);
     2180
    22542181        unlink(ramdisk_fname);
     2182        paranoid_free(ramdisk_fname);
    22552183    }
    22562184    if (!does_file_exist(cfg_file)) {
     
    22772205            run_program_and_log_output("mkdir -p tmp", FALSE);
    22782206
    2279             if (strlen(bkpinfo->media_device) == 0) {
    2280                 paranoid_alloc(bkpinfo->media_device, "/dev/st0");
    2281                 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
    2282             }
    2283             asprintf(&sav,bkpinfo->media_device);
     2207            if (bkpinfo->media_device == NULL) {
     2208                asprintf(&bkpinfo->media_device, "/dev/st0");
     2209                log_msg(2, "media_device is blank; assuming %s",
     2210                        bkpinfo->media_device);
     2211            }
     2212            asprintf(&sav, bkpinfo->media_device);
    22842213            if (extract_cfg_file_and_mountlist_from_tape_dev
    22852214                (bkpinfo->media_device)) {
     
    23032232
    23042233            if (!does_file_exist("tmp/mondo-restore.cfg")) {
    2305                 log_to_screen(_("Cannot find config info on tape/CD/floppy"));
     2234                log_to_screen(_
     2235                              ("Cannot find config info on tape/CD/floppy"));
    23062236                return (1);
    23072237            }
     
    23092239            log_msg(2,
    23102240                    "gcffa --- looking at mounted CD for mindi-boot.2880.img");
    2311             sprintf(command,
     2241            /* BERLIOS : Useless ?
     2242            asprintf(&command,
    23122243                    "mount " MNT_CDROM
    23132244                    "/images/mindi-boot.2880.img -o loop %s", mountpt);
    2314             sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
     2245                    */
     2246            asprintf(&mounted_cfgf_path, "%s/%s", mountpt, cfg_file);
    23152247            if (!does_file_exist(mounted_cfgf_path)) {
    23162248                log_msg(2,
    23172249                        "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz");
    2318                 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
     2250                asprintf(&command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm");    // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
    23192251                run_program_and_log_output(command, TRUE);
     2252                paranoid_free(command);
     2253
    23202254                if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
    23212255                    fatal_error
     
    23232257                }
    23242258            }
    2325         }
    2326     }
     2259            paranoid_free(mounted_cfgf_path);
     2260        }
     2261    }
     2262    paranoid_free(mountpt);
     2263
    23272264    if (does_file_exist(MONDO_CFG_FILE_STUB)) {
    23282265        log_msg(1, "gcffa --- great! We've got the config file");
    2329         sprintf(tmp, "%s/%s",
    2330                 call_program_and_get_last_line_of_output("pwd"),
    2331                 MONDO_CFG_FILE_STUB);
    2332         sprintf(command, "cp -f %s %s", tmp, cfg_file);
     2266        tmp1 = call_program_and_get_last_line_of_output("pwd");
     2267        asprintf(&tmp, "%s/%s", tmp1,MONDO_CFG_FILE_STUB);
     2268        asprintf(&command, "cp -f %s %s", tmp, cfg_file);
    23332269        iamhere(command);
     2270
    23342271        if (strcmp(tmp, cfg_file)
    23352272            && run_program_and_log_output(command, 1)) {
     
    23402277            log_msg(1, "... and I moved it successfully to %s", cfg_file);
    23412278        }
    2342         sprintf(command, "cp -f %s/%s %s",
    2343                 call_program_and_get_last_line_of_output("pwd"),
     2279        paranoid_free(command);
     2280
     2281        asprintf(&command, "cp -f %s/%s %s",tmp1,
    23442282                MOUNTLIST_FNAME_STUB, mountlist_file);
     2283        paranoid_free(tmp1);
     2284
    23452285        iamhere(command);
    23462286        if (strcmp(tmp, cfg_file)
     
    23492289        } else {
    23502290            log_msg(1, "Got mountlist too");
    2351             sprintf(command, "cp -f %s %s", mountlist_file,
     2291            paranoid_free(command);
     2292            asprintf(&command, "cp -f %s %s", mountlist_file,
    23522293                    g_mountlist_fname);
    23532294            if (run_program_and_log_output(command, 1)) {
     
    23552296            } else {
    23562297                log_msg(1, "Copied mountlist to /tmp as well OK");
    2357                 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2298                paranoid_free(command);
     2299                asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/");
    23582300                run_program_and_log_output(command, 1);
    2359 /*        sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
    2360           if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
    2361             {
    2362           log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
    2363         }
    2364               else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
    2365                 {
    2366           log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
    2367               do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
    2368           stop_raid_device("/dev/md0");
    2369           stop_raid_device("/dev/md1");
    2370           stop_raid_device("/dev/md2");
    2371           unlink("/tmp/i-want-my-lvm");
    2372         }
    2373           else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
    2374             {
    2375           log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
    2376         }
    2377 */
    2378             }
    2379         }
     2301            }
     2302        }
     2303        paranoid_free(command);
     2304        paranoid_free(tmp);
    23802305    }
    23812306    run_program_and_log_output("umount " MNT_CDROM, FALSE);
     
    23842309        log_msg(1, "%s not found", cfg_file);
    23852310        log_to_screen
    2386             (_("Oh dear. Unable to recover configuration file from boot disk"));
     2311            (_
     2312             ("Oh dear. Unable to recover configuration file from boot disk"));
    23872313        return (1);
    23882314    }
     
    23942320/* start SAH */
    23952321    else {
    2396         sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
     2322        asprintf(&command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
    23972323                bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
    23982324        run_program_and_log_output(command, FALSE);
    2399     }
    2400 /*--commented out by SAH
    2401   sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB );
    2402   run_program_and_log_output( command, FALSE );
    2403   sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB );
    2404   run_program_and_log_output( command, FALSE );
    2405 */
     2325        paranoid_free(command);
     2326    }
    24062327/* end SAH */
    24072328
    2408     sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2329    asprintf(&command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
     2330    paranoid_free(cfg_file);
     2331
    24092332    run_program_and_log_output(command, FALSE);
    2410     sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2333    paranoid_free(command);
     2334
     2335    asprintf(&command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
     2336    paranoid_free(mountlist_file);
     2337
    24112338    run_program_and_log_output(command, FALSE);
    2412     sprintf(command, "cp -f etc/raidtab /etc/");
     2339    paranoid_free(command);
     2340
     2341    asprintf(&command, "cp -f etc/raidtab /etc/");
    24132342    run_program_and_log_output(command, FALSE);
    2414     sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
     2343    paranoid_free(command);
     2344
     2345    asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/");
    24152346    run_program_and_log_output(command, FALSE);
     2347    paranoid_free(command);
     2348
    24162349    g_backup_media_type = bkpinfo->backup_media_type;
    2417     paranoid_free(device);
    2418     paranoid_free(command);
    2419     paranoid_free(tmp);
    2420     paranoid_free(cfg_file);
    2421     paranoid_free(mounted_cfgf_path);
    2422     paranoid_free(mountpt);
    2423     paranoid_free(ramdisk_fname);
    2424     paranoid_free(mountlist_file);
    24252350    return (retval);
    24262351}
    2427 
    24282352/**************************************************************************
    24292353 *END_GET_CFG_FILE_FROM_ARCHIVE                                           *
    24302354 **************************************************************************/
    2431 
    24322355/* @} - end restoreUtilityGroup */
    2433 
    2434 
    2435 /***************************************************************************
    2436  * F@                                                                      *
    2437  * () -- Hugo Rabson                                  *
    2438  *                                                                         *
    2439  * Purpose:                                                                *
    2440  *                                                                         *
    2441  * Called by:                                                              *
    2442  * Params:    -                      -                                     *
    2443  * Returns:   0=success; nonzero=failure                                   *
    2444  ***************************************************************************/
    2445 
    24462356
    24472357
     
    24492359                                           int wait_for_percentage)
    24502360{
    2451     struct raidlist_itself *raidlist;
    2452     int unfinished_mdstat_devices = 9999, i;
    2453     char *screen_message;
    2454 
    2455     malloc_string(screen_message);
     2361    struct raidlist_itself *raidlist = NULL;
     2362    int unfinished_mdstat_devices = 9999, i = 0;
     2363    char *screen_message = NULL;
     2364
    24562365    raidlist = malloc(sizeof(struct raidlist_itself));
    24572366
     
    24612370        if (parse_mdstat(raidlist, "/dev/")) {
    24622371            log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
    2463             log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
     2372            log_msg(1, "Sorry, cannot read %s", MDSTAT_FILE);
    24642373            return;
    24652374        }
    2466         for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) {
     2375        for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries;
     2376             i++) {
    24672377            if (raidlist->el[i].progress < wait_for_percentage) {
    24682378                unfinished_mdstat_devices++;
    2469                 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
    2470                 sprintf(screen_message, "Sync'ing %s",
     2379                log_msg(1, "Sync'ing %s (i=%d)",
     2380                        raidlist->el[i].raid_device, i);
     2381                asprintf(&screen_message, "Sync'ing %s",
    24712382                        raidlist->el[i].raid_device);
    24722383                open_evalcall_form(screen_message);
     2384                paranoid_free(screen_message);
     2385
    24732386                if (raidlist->el[i].progress == -1) // delayed while another partition inits
    24742387                {
     
    24762389                }
    24772390                while (raidlist->el[i].progress < wait_for_percentage) {
    2478                     log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
     2391                    log_msg(1, "Percentage sync'ed: %d",
     2392                            raidlist->el[i].progress);
    24792393                    update_evalcall_form(raidlist->el[i].progress);
    24802394                    sleep(2);
     
    24882402        }
    24892403    }
    2490     paranoid_free(screen_message);
    24912404    paranoid_free(raidlist);
    24922405}
  • trunk/mondo/mondo/mondorestore/mondo-rstr-tools.h

    r426 r688  
    1 /* mondo-rstr-tools.h
     1/*
    22 * $Id: mondo-rstr-tools.h
    3  */
     3**/
    44
    55void free_global_filenames();
     
    88int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please);
    99void kill_petris(void);
    10 int modify_rclocal_one_time(char *path);
    1110int mount_cdrom(struct s_bkpinfo *bkpinfo);
    1211int mount_device(char *, char *, char *, bool);
     
    2625void set_signals(int on);
    2726void setup_global_filenames(struct s_bkpinfo *bkpinfo);
    28 //void setup_signals(int);
    2927void twenty_seconds_til_yikes(void);
    3028int run_raw_mbr(bool offer_to_hack_scripts, char *bd);
  • trunk/mondo/mondo/mondorestore/mondoprep.h

    r687 r688  
    1 /***************************************************************************
    2                           mondoprep.h  -  description
    3                              -------------------
    4     begin                : Sat Apr 20 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    10 /***************************************************************************
    11  *                                                                         *
    12  *   This program is free software; you can redistribute it and/or modify  *
    13  *   it under the terms of the GNU General Public License as published by  *
    14  *   the Free Software Foundation; either version 2 of the License, or     *
    15  *   (at your option) any later version.                                   *
    16  *                                                                         *
    17  ***************************************************************************/
     1/*
     2 * $Id$
     3**/
    184
    195
     
    2814extern bool ask_me_yes_or_no(char *);
    2915extern long get_phys_size_of_drive(char *);
    30 //extern void log_to_screen (char *);
    3116extern void update_progress_form(char *);
    3217extern void open_progress_form(char *, char *, char *, char *, long);
    3318extern void close_progress_form(void);
    3419extern void popup_and_OK(char *);
    35 extern bool popup_and_get_string(char *, char *, char *, int);
     20extern bool popup_and_get_string(char *, char *, char *);
    3621extern long get_time(void);
    3722extern bool is_this_device_mounted(char *);
     
    4126extern off_t length_of_file(char *);
    4227extern long noof_lines_that_match_wildcard(char *, char *);
    43 //extern char *slice_fname (long, long, bool, char *);
    4428extern char *last_line_of_file(char *);
    4529extern void log_file_end_to_screen(char *, char *);
     
    5842int start_all_raid_devices(struct mountlist_itself *);
    5943int stop_all_raid_devices(struct mountlist_itself *);
    60 int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *);
     44int format_everything(struct mountlist_itself *, bool,
     45                      struct raidlist_itself *);
    6146int partition_device(FILE *, const char *, int, int, const char *,
    6247                     long long);
  • trunk/mondo/mondo/mondorestore/mr-externs.h

    r687 r688  
    2727extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *,
    2828                          struct raidlist_itself *);
    29 extern int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *);
     29extern int format_everything(struct mountlist_itself *, bool,
     30                             struct raidlist_itself *);
    3031extern int format_device(char *, char *, struct raidlist_itself *);
    3132extern void finish(int);
     
    5960extern int partition_everything(struct mountlist_itself *);
    6061extern void popup_and_OK(char *);
    61 extern bool popup_and_get_string(char *, char *, char *, int);
     62extern bool popup_and_get_string(char *, char *, char *);
    6263extern void setup_newt_stuff(void);
    6364extern void reset_bkpinfo(struct s_bkpinfo *);
Note: See TracChangeset for help on using the changeset viewer.