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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/mondo-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}
Note: See TracChangeset for help on using the changeset viewer.