Changeset 2211 in MondoRescue for branches/2.2.9/mondo/src/mondorestore


Ignore:
Timestamp:
Jun 3, 2009, 7:10:19 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3089@localhost: bruno | 2009-05-18 06:41:05 +0200

  • move call to asprintf to call to mr_asprintf (suppress a compiler warning)
  • remove all the most obvious bad call to strcat and replace by mr_strcat as appropriate
Location:
branches/2.2.9/mondo/src/mondorestore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/mondorestore/mondo-prep.c

    r2205 r2211  
    11/***************************************************************************
    22$Id$
    3 ***************************************************************************/
    4 
    5 /***************************************************************************
    6  *                                                                         *
    7  *   This program is free software; you can redistribute it and/or modify  *
    8  *   it under the terms of the GNU General Public License as published by  *
    9  *   the Free Software Foundation; either version 2 of the License, or     *
    10  *   (at your option) any later version.                                   *
    11  *                                                                         *
    12  ***************************************************************************/
    13 
    14 /**
    15  * @file
    16  * Functions for prepping hard drives: partitioning, formatting, etc.
    17  */
     3* Functions for prepping hard drives: partitioning, formatting, etc.
     4*/
    185
    196
    207#include "my-stuff.h"
     8#include "mr_mem.h"
    219#include "../common/mondostructures.h"
    2210#include "mondoprep.h"
     
    349337            log_it("%s... so I'll get creative.", tmp);
    350338            if (lvmversion == 2) {
    351                 asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);
     339                mr_asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);
    352340                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    353341                free(tmp1);
    354342            } else {
    355                 asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);
     343                mr_asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);
    356344                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    357345                free(tmp1);
     
    596584  }
    597585  // create device list from normal disks followed by spare ones
    598   asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);
     586  mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);
    599587  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    600     asprintf(&strtmp, "%s", devices);
     588    mr_asprintf(&strtmp, "%s", devices);
    601589    paranoid_free(devices);
    602     asprintf(&devices, "%s %s", strtmp,
     590    mr_asprintf(&devices, "%s %s", strtmp,
    603591         raidlist->el[i].data_disks.el[j].device);
    604592    paranoid_free(strtmp);
    605593  }
    606594  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    607     asprintf(&strtmp, "%s", devices);
     595    mr_asprintf(&strtmp, "%s", devices);
    608596    paranoid_free(devices);
    609     asprintf(&devices, "%s %s", strtmp,
     597    mr_asprintf(&devices, "%s %s", strtmp,
    610598         raidlist->el[i].spare_disks.el[j].device);
    611599    paranoid_free(strtmp);
     
    613601  // translate RAID level
    614602  if (raidlist->el[i].raid_level == -2) {
    615     asprintf(&level, "multipath");
     603    mr_asprintf(&level, "multipath");
    616604  } else if (raidlist->el[i].raid_level == -1) {
    617     asprintf(&level, "linear");
     605    mr_asprintf(&level, "linear");
    618606  } else {
    619     asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     607    mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    620608  }
    621609  // create RAID device:
     
    624612  // - faulty devices ignored
    625613  // - persistent superblock always used as this is recommended
    626   asprintf(&program,
     614  mr_asprintf(&program,
    627615       "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
    628616       raidlist->el[i].raid_device, level,
    629617       raidlist->el[i].data_disks.entries);
    630618  if (raidlist->el[i].parity != -1) {
    631     asprintf(&strtmp, "%s", program);
     619    mr_asprintf(&strtmp, "%s", program);
    632620    paranoid_free(program);
    633621    switch(raidlist->el[i].parity) {
    634622    case 0:
    635       asprintf(&program, "%s --parity=%s", strtmp, "la");
     623      mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
    636624      break;
    637625    case 1:
    638       asprintf(&program, "%s --parity=%s", strtmp, "ra");
     626      mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
    639627      break;
    640628    case 2:
    641       asprintf(&program, "%s --parity=%s", strtmp, "ls");
     629      mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
    642630      break;
    643631    case 3:
    644       asprintf(&program, "%s --parity=%s", strtmp, "rs");
     632      mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
    645633      break;
    646634    default:
     
    651639  }
    652640  if (raidlist->el[i].chunk_size != -1) {
    653     asprintf(&strtmp, "%s", program);
     641    mr_asprintf(&strtmp, "%s", program);
    654642    paranoid_free(program);
    655     asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
     643    mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
    656644    paranoid_free(strtmp);
    657645  }
    658646  if (raidlist->el[i].spare_disks.entries > 0) {
    659     asprintf(&strtmp, "%s", program);
     647    mr_asprintf(&strtmp, "%s", program);
    660648    paranoid_free(program);
    661     asprintf(&program, "%s --spare-devices=%d", strtmp,
     649    mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    662650         raidlist->el[i].spare_disks.entries);
    663651    paranoid_free(strtmp);
    664652  }
    665   asprintf(&strtmp, "%s", program);
     653  mr_asprintf(&strtmp, "%s", program);
    666654  paranoid_free(program);
    667   asprintf(&program, "%s %s", strtmp, devices);
     655  mr_asprintf(&program, "%s %s", strtmp, devices);
    668656  paranoid_free(strtmp);
    669657  res = run_program_and_log_output(program, 1);
     
    690678{
    691679    /** int **************************************************************/
    692     int res;
    693     int retval = 0;
    694680#ifdef __FreeBSD__
    695681    static bool vinum_started_yet = FALSE;
     
    698684    /** buffers ***********************************************************/
    699685    char *program;
    700     char *tmp;
     686    char *tmp = NULL;
     687    int res = 0;
     688    int retval = 0;
    701689
    702690    /** end ****************************************************************/
    703691
    704692    malloc_string(program);
    705     malloc_string(tmp);
    706693    assert_string_is_neither_NULL_nor_zerolength(device);
    707694    assert(format != NULL);
    708695
    709696    if (strstr(format, "raid")) {   // do not form RAID disks; do it to /dev/md* instead
    710         sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
     697        mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device);
    711698        log_it(tmp);
     699        paranoid_free(tmp);
    712700        paranoid_free(program);
    713         paranoid_free(tmp);
    714701        return (0);
    715702    }
     
    723710#endif
    724711    if (strlen(format) <= 2) {
    725         sprintf(tmp,
     712        mr_asprintf(&tmp,
    726713                "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
    727714                device, format);
    728715        log_it(tmp);
     716        paranoid_free(tmp);
    729717        paranoid_free(program);
     718        return (0);
     719    }
     720    if (is_this_device_mounted(device)) {
     721        mr_asprintf(&tmp, "%s is mounted - cannot format it       ", device);
     722        log_to_screen(tmp);
    730723        paranoid_free(tmp);
    731         return (0);
    732     }
    733     if (is_this_device_mounted(device)) {
    734         sprintf(tmp, "%s is mounted - cannot format it       ", device);
    735         log_to_screen(tmp);
    736724        paranoid_free(program);
    737         paranoid_free(tmp);
    738725        return (1);
    739726    }
     
    762749            FILE *fin;
    763750            char line[MAX_STR_LEN];
    764             sprintf(tmp,
    765                     "Initializing Vinum device %s (this may take a *long* time)",
    766                     device);
     751
     752            mr_asprintf(&tmp, "Initializing Vinum device %s (this may take a *long* time)", device);
    767753            log_to_screen(tmp);
     754            paranoid_free(tmp);
     755
    768756            /* format raid partition */
    769757            //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
     
    780768                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    781769
    782                 sprintf(tmp, "Initializing plex: %s", line);
     770                mr_asprintf(&tmp, "Initializing plex: %s", line);
    783771                open_evalcall_form(tmp);
    784                 sprintf(tmp, "vinum init %s", line);
     772                paranoid_free(tmp);
     773
     774                mr_asprintf(&tmp, "vinum init %s", line);
    785775                system(tmp);
     776                paranoid_free(tmp);
     777
    786778                while (1) {
    787                     sprintf(tmp,
     779                    mr_asprintf(&tmp,
    788780                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    789781                            line);
    790782                    FILE *pin = popen(tmp, "r");
     783                    paranoid_free(tmp);
     784
    791785                    char status[MAX_STR_LEN / 4];
    792786                    fgets(status, MAX_STR_LEN / 4 - 1, pin);
     
    806800        }
    807801#else
    808         sprintf(tmp, "Initializing RAID device %s", device);
     802        mr_asprintf(&tmp, "Initializing RAID device %s", device);
    809803        log_to_screen(tmp);
     804        paranoid_free(tmp);
    810805
    811806// Shouldn't be necessary.
     
    856851    }
    857852    res = which_format_command_do_i_need(format, program);
    858     sprintf(tmp, "%s %s", program, device);
     853    mr_asprintf(&tmp, "%s %s", program, device);
    859854    if (strstr(program, "kludge")) {
    860         strcat(tmp, " /");
     855        mr_strcat(tmp, " /");
    861856    }
    862857    sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
    863     sprintf(tmp, "Formatting %s as %s", device, format);
     858    paranoid_free(tmp);
     859
     860    mr_asprintf(&tmp, "Formatting %s as %s", device, format);
    864861    update_progress_form(tmp);
     862    paranoid_free(tmp);
     863
    865864    res = run_program_and_log_output(program, FALSE);
     865    mr_asprintf(&tmp, "");
    866866    if (res && strstr(program, "kludge")) {
    867         sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
     867        mr_strcat(tmp, "Kludge failed; using regular mkfs.%s to format %s",
    868868                format, device);
    869869#ifdef __FreeBSD__
     
    885885    retval += res;
    886886    if (retval) {
    887         strcat(tmp, "...failed");
     887        mr_strcat(tmp, "...failed");
    888888    } else {
    889         strcat(tmp, "...OK");
     889        mr_strcat(tmp, "...OK");
    890890    }
    891891
    892892    log_to_screen(tmp);
     893    paranoid_free(tmp);
     894
    893895    paranoid_free(program);
    894     paranoid_free(tmp);
    895896    system("sync");
    896897    sleep(1);
     
    17171718    char *tmp;
    17181719    char *logfile;
    1719     char *output;
     1720    char *output = NULL;
    17201721
    17211722    /** pointers **********************************************************/
     
    17301731    malloc_string(tmp);
    17311732    malloc_string(logfile);
    1732     malloc_string(output);
    17331733
    17341734    assert_string_is_neither_NULL_nor_zerolength(drive);
     
    17451745        paranoid_free(tmp);
    17461746        paranoid_free(logfile);
    1747         paranoid_free(output);
    17481747        return (0);
    17491748    }
     
    17661765        paranoid_free(tmp);
    17671766        paranoid_free(logfile);
    1768         paranoid_free(output);
    17691767        return (1);
    17701768/*
     
    17861784    /* BERLIOS: should not be called each time */
    17871785    part_table_fmt = which_partition_format(drive);
    1788     output[0] = '\0';
     1786    mr_asprintf(&output, "");
    17891787    /* make it a primary/extended/logical */
    17901788    if (partno <= 4) {
    1791         sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1789        mr_strcat(output, "n\np\n%d\n", partno);
    17921790    } else {
    17931791        /* MBR needs an extended partition if more than 4 partitions */
     
    18041802                    return (1);
    18051803                } else {
    1806                     sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
    1807                             prev_partno + 1);
     1804                    mr_strcat(output, "n\ne\n%d\n\n\n", prev_partno + 1);
    18081805                }
    18091806            }
    1810             strcat(output + strlen(output), "n\nl\n");
     1807            mr_strcat(output, "n\nl\n");
    18111808        } else {
    18121809            /* GPT allows more than 4 primary partitions */
    1813             sprintf(output + strlen(output), "n\np\n%d\n", partno);
    1814         }
    1815     }
    1816     strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
     1810            mr_strcat(output, "n\np\n%d\n", partno);
     1811        }
     1812    }
     1813    mr_strcat(output, "\n");    /*start block (ENTER for next free blk */
    18171814    if (partsize > 0) {
    18181815        if (!strcmp(format, "7")) {
     
    18201817            partsize += 512;
    18211818        }
    1822         sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    1823     }
    1824     strcat(output + strlen(output), "\n");
     1819        mr_strcat(output, "+%lldK", (long long) (partsize));
     1820    }
     1821    mr_strcat(output, "\n");
    18251822#if 0
    18261823/*
     
    18641861        }
    18651862    } else {
    1866         strcat(output, "w\n\n");
     1863        mr_strcat(output, "w\n\n");
    18671864        if (g_fprep) {
    18681865            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     
    19161913        }
    19171914    }
     1915    paranoid_free(output);
     1916
    19181917    g_current_progress++;
    19191918    log_it("partition_device() --- leaving");
     
    19221921    paranoid_free(tmp);
    19231922    paranoid_free(logfile);
    1924     paranoid_free(output);
    19251923    return (retval);
    19261924}
     
    20322030    char *partition;
    20332031    char *command;
    2034     char *output;
     2032    char *output = NULL;
    20352033    char *tmp;
    20362034    char *partcode;
     
    20512049    malloc_string(partition);
    20522050    malloc_string(command);
    2053     malloc_string(output);
    20542051    malloc_string(tmp);
    20552052    malloc_string(partcode);
     
    21382135            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    21392136        } else {
    2140             sprintf(output, "t\n%d\n%s\n", partno, partcode);
    2141             strcat(output, "w\n");
     2137            mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
    21422138            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
    21432139                    MONDO_LOGFILE, MONDO_LOGFILE);
     
    21542150                paranoid_pclose(fout);
    21552151            }
     2152            paranoid_free(output);
    21562153        }
    21572154        if (res) {
     
    21622159    paranoid_free(partition);
    21632160    paranoid_free(command);
    2164     paranoid_free(output);
    21652161    paranoid_free(tmp);
    21662162    paranoid_free(partcode);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-compare.c

    r1930 r2211  
    11/***************************************************************************
    2        mondo-compare.c  -  compares mondoarchive data
    3                              -------------------
    4     begin                : Fri Apr 25 2003
    5     copyright            : (C) 2000 by Hugo Rabson
    6     email                : Hugo Rabson <hugorabson@msn.com>
    72    cvsid                : $Id$
    83***************************************************************************/
    94
    10 /***************************************************************************
    11  *                                                                         *
    12  *   This program is free software; you can redistribute it and/or modify  *
    13  *   it under the terms of the GNU General Public License as published by  *
    14  *   the Free Software Foundation; either version 2 of the License, or     *
    15  *   (at your option) any later version.                                   *
    16  *                                                                         *
    17  ***************************************************************************/
    18 
    19 /***************************************************************************
    20  *                         Change Log                                      *
    21  ***************************************************************************
    22 .
    23 
    24 
    25 
    26 10/21/2003
    27 - changed "/mnt/cdrom" to MNT_CDROM
    28 
    29 10/18
    30 - don't say unknown compressor if no compressor at all
    31 
    32 09/17
    33 - cleaned up logging & conversion-to-changed.txt
    34 - cleaned up compare_mode()
    35 
    36 09/16
    37 - fixed bad malloc(),free() pairs in compare_a_biggiefile()
    38 
    39 09/14
    40 - compare_mode() --- a couple of strings were the wrong way round,
    41   e.g. changed.txt and changed.files
    42 
    43 05/05
    44 - exclude /dev/ * from list of changed files
    45 
    46 04/30
    47 - added textonly mode
    48 
    49 04/27
    50 - improved compare_mode() to allow for ISO/cd/crazy people
    51 
    52 04/25
    53 - first incarnation
    54 */
    55 
    56 
    575#include <pthread.h>
    586#include "my-stuff.h"
     7#include "mr_mem.h"
    598#include "../common/mondostructures.h"
    609#include "../common/libmondo.h"
     
    9746    char *original_cksum_ptr;
    9847    char *bigfile_fname_ptr;
    99     char *tmp_ptr;
     48    char *tmp_ptr = NULL;
    10049    char *command_ptr;
    10150
     
    11766    malloc_string(bigfile_fname_ptr);
    11867    malloc_string(command_ptr);
    119     malloc_string(tmp_ptr);
    12068
    12169  /*********************************************************************
     
    12674    memset(original_cksum_ptr, '\0', sizeof(original_cksum));
    12775    memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    128     memset(tmp_ptr, '\0', sizeof(tmp));
    12976    memset(command_ptr, '\0', sizeof(command));
    13077  /** end **/
     
    13481            insist_on_this_cd_number((++g_current_media_number));
    13582        } else {
    136             sprintf(tmp_ptr,
     83            mr_asprintf(&tmp_ptr,
    13784                    "No CD's left. No biggiefiles left. No prob, Bob.");
    13885            log_msg(2, tmp_ptr);
     86            paranoid_free(tmp_ptr);
    13987            return (0);
    14088        }
    14189    }
    14290    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
    143         sprintf(tmp_ptr,
     91        mr_asprintf(&tmp_ptr,
    14492                "Cannot open bigfile %ld (%s)'s info file",
    14593                bigfileno + 1, bigfile_fname_ptr);
    14694        log_to_screen(tmp_ptr);
     95        paranoid_free(tmp_ptr);
    14796        return (1);
    14897    }
     
    156105    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
    157106
    158     sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    159 
    160107    if (!g_text_mode) {
     108        mr_asprintf(&tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    161109        newtDrawRootText(0, 22, tmp_ptr);
     110        paranoid_free(tmp_ptr);
    162111        newtRefresh();
    163112    }
     
    173122    }
    174123    log_msg(2, command_ptr);
    175     sprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
     124    mr_asprintf(&tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
    176125    paranoid_system(tmp_ptr);
     126    paranoid_free(tmp_ptr);
     127
    177128    if (system(command_ptr)) {
    178129        log_OS_error("Warning - command failed");
     
    197148        }
    198149    }
    199     sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
     150    mr_asprintf(&tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
    200151            bigfile_fname_ptr);
    201152    if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
    202         strcat(tmp_ptr, " ... OK");
    203     } else {
    204         strcat(tmp_ptr, "... changed");
     153        mr_strcat(tmp_ptr, " ... OK");
     154    } else {
     155        mr_strcat(tmp_ptr, "... changed");
    205156        retval++;
    206157    }
    207158    log_msg(1, tmp_ptr);
     159    paranoid_free(tmp_ptr);
     160
    208161    if (retval) {
    209162        if (!(fout = fopen(MONDO_CACHE"/changed.txt", "a"))) {
     
    222175    paranoid_free(command_ptr);
    223176    paranoid_free(command);
    224     paranoid_free(tmp_ptr);
    225177    paranoid_free(tmp);
    226178
     
    302254
    303255  /***  needs malloc *********/
    304     char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
     256    char *command, *tmp, *filelist_name, *logfile,
    305257        *compressor_exe;
     258    char *archiver_exe = NULL;
    306259
    307260    malloc_string(command);
     
    309262    malloc_string(filelist_name);
    310263    malloc_string(logfile);
    311     malloc_string(archiver_exe);
    312264    malloc_string(compressor_exe);
    313265
     
    331283
    332284    if (use_star) {
    333         strcpy(archiver_exe, "star");
    334     } else {
    335         strcpy(archiver_exe, "afio");
     285        mr_asprintf(&archiver_exe, "star");
     286    } else {
     287        mr_asprintf(&archiver_exe, "afio");
    336288    }
    337289
     
    344296        {
    345297            if (!strcmp(compressor_exe, "bzip2")) {
    346                 strcat(archiver_exe, " -bz");
     298                mr_strcat(archiver_exe, " -bz");
    347299            } else {
    348300                fatal_error
     
    373325                BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
    374326    }
     327    paranoid_free(archiver_exe);
     328
    375329#undef BUFSIZE
    376330
     
    405359    paranoid_free(filelist_name);
    406360    paranoid_free(logfile);
    407     paranoid_free(archiver_exe);
    408361    paranoid_free(compressor_exe);
    409362    return (retval);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-newt.c

    r2209 r2211  
    11/***************************************************************************
    22 * $Id$
    3  */
    4 
    5 
    6 /**
    7  * @file
    83 * Functions for handling GUI interfaces in the restore.
    94 */
     
    116#ifdef __FreeBSD__
    127#define OSSWAP(linux,fbsd) fbsd
    13 //#include <libgen.h>
    148#else
    159#define OSSWAP(linux,fbsd) linux
     
    1711
    1812#include "mondo-rstr-newt.h"
     13#include "mr_mem.h"
    1914
    2015//static char cvsid[] = "$Id$";
     
    19501945    assert(raidlist != NULL);
    19511946
    1952     asprintf(&flaws_str_A, "%s", "xxxxxxxxx");
    1953     asprintf(&flaws_str_B, "%s", "xxxxxxxxx");
    1954     asprintf(&flaws_str_C, "%s", "xxxxxxxxx");
     1947    mr_asprintf(&flaws_str_A, "%s", "         ");
     1948    mr_asprintf(&flaws_str_B, "%s", "         ");
     1949    mr_asprintf(&flaws_str_C, "%s", "         ");
    19551950    if (mountlist->entries > ARBITRARY_MAXIMUM) {
    19561951        log_to_screen("Arbitrary limits suck, man!");
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c

    r2206 r2211  
    11/***************************************************************************
    22$Id$
    3 
    4 ***************************************************************************
    5 *                                                                         *
    6 *   This program is free software; you can redistribute it and/or modify  *
    7 *   it under the terms of the GNU General Public License as published by  *
    8 *   the Free Software Foundation; either version 2 of the License, or     *
    9 *   (at your option) any later version.                                   *
    10 *                                                                         *
    113***************************************************************************/
    124
     
    146#include <linux/fd.h>
    157#include "my-stuff.h"
     8#include "mr_mem.h"
    169#include "../common/mondostructures.h"
    1710#include "../common/libmondo.h"
     
    284277int iso_fiddly_bits(bool nuke_me_please)
    285278{
    286 char *mount_isodir_command, *tmp, *command;
     279char *mount_isodir_command = NULL;
     280char *tmp, *command;
    287281int retval = 0, i;
    288282bool already_mounted = FALSE;
    289283
    290284assert(bkpinfo != NULL);
    291 malloc_string(mount_isodir_command);
    292285malloc_string(tmp);
    293286malloc_string(command);
     
    295288read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    296289if (bkpinfo->disaster_recovery) {
    297 /* Patch Conor Daly 26-june-2004
    298 * Don't let this clobber an existing bkpinfo->isodir */
    299 if (!bkpinfo->isodir[0]) {
    300     strcpy(bkpinfo->isodir, "/tmp/isodir");
    301 }
    302 /* End patch */
    303 sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    304 run_program_and_log_output(command, 5);
    305 log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
    306 }
    307 
    308 if (!get_isodir_info
    309 (g_isodir_device, g_isodir_format, bkpinfo->isodir,
    310  nuke_me_please)) {
    311 return (1);
     290    /* Patch Conor Daly 26-june-2004
     291    * Don't let this clobber an existing bkpinfo->isodir */
     292    if (!bkpinfo->isodir[0]) {
     293        strcpy(bkpinfo->isodir, "/tmp/isodir");
     294    }
     295    /* End patch */
     296    sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     297    run_program_and_log_output(command, 5);
     298    log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
     299}
     300
     301if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {
     302    return (1);
    312303}
    313304paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
    314305
    315306if (is_this_device_mounted(g_isodir_device)) {
    316 log_to_screen("WARNING - isodir is already mounted");
    317 already_mounted = TRUE;
     307    log_to_screen("WARNING - isodir is already mounted");
     308    already_mounted = TRUE;
    318309} else {
    319 sprintf(mount_isodir_command, "mount %s", g_isodir_device);
    320 if (strlen(g_isodir_format) > 1) {
    321     sprintf(mount_isodir_command + strlen(mount_isodir_command),
    322             " -t %s", g_isodir_format);
    323 }
    324 strcat(mount_isodir_command, " -o ro ");
    325 strcat(mount_isodir_command, bkpinfo->isodir);
    326 run_program_and_log_output("df -m", FALSE);
    327 sprintf(tmp,
     310    mr_asprintf(&mount_isodir_command, "mount %s", g_isodir_device);
     311    if (strlen(g_isodir_format) > 1) {
     312        mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
     313    }
     314    mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
     315    run_program_and_log_output("df -m", FALSE);
     316    sprintf(tmp,
    328317        "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
    329318        mount_isodir_command);
    330 log_msg(1, tmp);
    331 if (run_program_and_log_output(mount_isodir_command, FALSE)) {
    332     popup_and_OK
    333         ("Cannot mount the device where the ISO files are stored.");
    334     return (1);
    335 }
    336 log_to_screen
     319    log_msg(1, tmp);
     320    if (run_program_and_log_output(mount_isodir_command, FALSE)) {
     321        popup_and_OK
     322            ("Cannot mount the device where the ISO files are stored.");
     323        return (1);
     324    }
     325    paranoid_free(mount_isodir_command);
     326    log_to_screen
    337327    ("I have mounted the device where the ISO files are stored.");
    338328}
     
    351341log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
    352342    bkpinfo->isodir);
    353 paranoid_free(mount_isodir_command);
    354343paranoid_free(tmp);
    355344paranoid_free(command);
     
    385374
    386375/** malloc **/
    387 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     376char *tmp, *command, *mountdir, *mountpoint;
     377char *additional_parameters = NULL;
    388378
    389379assert_string_is_neither_NULL_nor_zerolength(device);
     
    394384malloc_string(mountdir);
    395385malloc_string(mountpoint);
    396 malloc_string(additional_parameters);
    397386
    398387    if (!strcmp(mpt, "/1")) {
     
    412401    log_msg(1, tmp);
    413402    /* Deal with additional params only if not /proc or /sys */
     403    mr_asprintf(&additional_parameters, "");
    414404    if (strcmp(format, "proc") && strcmp(format, "sys")) {
    415405        if (writeable) {
    416             strcpy(additional_parameters, "-o rw");
     406            mr_strcat(additional_parameters, "-o rw");
    417407        } else {
    418             strcpy(additional_parameters, "-o ro");
     408            mr_strcat(additional_parameters, "-o ro");
    419409        }
    420410        if (find_home_of_exe("setfattr")) {
    421             strcat(additional_parameters, ",user_xattr");
     411            mr_strcat(additional_parameters, ",user_xattr");
    422412        }
    423413        if (find_home_of_exe("setfacl")) {
    424             strcat(additional_parameters, ",acl");
     414            mr_strcat(additional_parameters, ",acl");
    425415        }
    426416    }
     
    440430        log_msg(2, "command='%s'", command);
    441431    }
     432    paranoid_free(additional_parameters);
    442433
    443434    res = run_program_and_log_output(command, TRUE);
     
    479470paranoid_free(mountdir);
    480471paranoid_free(mountpoint);
    481 paranoid_free(additional_parameters);
    482472
    483473    return (res);
     
    498488{
    499489int retval = 0, lino, res;
    500 char *tmp, *these_failed, *format;
    501     struct mountlist_itself *mountlist = NULL;
     490char *tmp;
     491char *these_failed = NULL;
     492char *format;
     493struct mountlist_itself *mountlist = NULL;
    502494
    503495malloc_string(tmp);
    504496malloc_string(format);
    505 malloc_string(these_failed);
    506 /** menset **/
    507 these_failed[0] = '\0';
    508497
    509498assert(p_external_copy_of_mountlist != NULL);
     
    520509               "", mountlist->entries);
    521510
     511    mr_asprintf(&these_failed, "");
    522512    for (lino = 0; lino < mountlist->entries; lino++) {
    523513        if (!strcmp(mountlist->el[lino].device, "/proc")) {
     
    540530            retval += res;
    541531            if (res) {
    542                 strcat(these_failed, mountlist->el[lino].device);
    543                 strcat(these_failed, " ");
     532                mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
    544533            }
    545534        }
     
    556545                ("format and restore *without* partitioning first. Sorry for the inconvenience.");
    557546        }
    558         sprintf(tmp, "Could not mount device(s) %s- shall I abort?",
    559                 these_failed);
     547        sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
    560548
    561549        if (!ask_me_yes_or_no(tmp)) {
     
    573561        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    574562    }
     563    paranoid_free(these_failed);
     564
    575565    /* Also mounting under MNT_RESTORING  special FS */
    576566    (void)mount_device("/proc","/proc","proc",TRUE);
     
    580570    paranoid_free(tmp);
    581571    paranoid_free(format);
    582     paranoid_free(these_failed);
    583572    return (retval);
    584573}
     
    896885read_cfg_var(cfg_file, "acl", value);
    897886if (strstr(value, "TRUE")) {
    898     asprintf(&g_getfacl,"setfacl");
     887    mr_asprintf(&g_getfacl,"setfacl");
    899888    log_msg(1, "We will restore ACLs");
    900889    if (! find_home_of_exe("setfacl")) {
     
    904893read_cfg_var(cfg_file, "xattr", value);
    905894if (strstr(value, "TRUE")) {
    906     asprintf(&g_getfattr,"setfattr");
     895    mr_asprintf(&g_getfattr,"setfattr");
    907896    log_msg(1, "We will restore XATTRs");
    908897    if (! find_home_of_exe("setfattr")) {
     
    13981387     * the current /dev location
    13991388     */
    1400     asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
     1389    mr_asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
    14011390    run_program_and_log_output(cmd, 3);
    14021391    paranoid_free(cmd);
     
    14101399    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    14111400    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
    1412     asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);
     1401    mr_asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);
    14131402    log_msg(2, tmp);
    14141403    paranoid_free(tmp);
     
    14271416#ifdef __FreeBSD__
    14281417    else if (!strcmp(name, "BOOT0")) {
    1429         asprintf(&tmp, "boot0cfg -B %s", device);
     1418        mr_asprintf(&tmp, "boot0cfg -B %s", device);
    14301419        res = run_program_and_log_output(tmp, FALSE);
    14311420        paranoid_free(tmp);
    14321421    } else {
    1433         asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
     1422        mr_asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
    14341423        if (!system(tmp)) {
    14351424            paranoid_free(tmp);
    1436             asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
     1425            mr_asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    14371426            res = run_program_and_log_output(tmp, 3);
    14381427        } else {
     
    20192008    int retval = 0, lino, res = 0, i;
    20202009    char *command;
    2021     char *tmp;
     2010    char *tmp = NULL;
    20222011
    20232012    malloc_string(command);
    2024     malloc_string(tmp);
    20252013    assert(p_external_copy_of_mountlist != NULL);
    20262014
     
    20492037    paranoid_system("sync");
    20502038
    2051     sprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
     2039    mr_asprintf(&tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
    20522040    if (run_program_and_log_output(tmp, FALSE)) {
    20532041        log_msg(1,
    20542042                "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
    20552043    }
     2044    paranoid_free(tmp);
    20562045    if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
    20572046        run_program_and_log_output("mkdir -p " MNT_RESTORING
     
    20672056            continue;
    20682057        }
    2069         sprintf(tmp, "Unmounting device %s  ", mountlist->el[lino].device);
     2058        mr_asprintf(&tmp, "Unmounting device %s  ", mountlist->el[lino].device);
    20702059
    20712060        update_progress_form(tmp);
     2061
    20722062        if (is_this_device_mounted(mountlist->el[lino].device)) {
    20732063            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
     
    20942084            res = run_program_and_log_output(command, 3);
    20952085        } else {
    2096             strcat(tmp, "...not mounted anyway :-) OK");
     2086            mr_strcat(tmp, "...not mounted anyway :-) OK");
    20972087            res = 0;
    20982088        }
    20992089        g_current_progress++;
    21002090        if (res) {
    2101             strcat(tmp, "...Failed");
     2091            mr_strcat(tmp, "...Failed");
    21022092            retval++;
    21032093            log_to_screen(tmp);
     
    21052095            log_msg(2, tmp);
    21062096        }
     2097        paranoid_free(tmp);
    21072098    }
    21082099    close_progress_form();
     
    21192110    free(mountlist);
    21202111    paranoid_free(command);
    2121     paranoid_free(tmp);
    21222112    return (retval);
    21232113}
  • branches/2.2.9/mondo/src/mondorestore/mondorestore.c

    r2209 r2211  
    22$Id$
    33restores mondoarchive data
     4The main file for mondorestore.
    45***************************************************************************/
    5 
    6 /**
    7  * @file
    8  * The main file for mondorestore.
    9  */
    106
    117/**************************************************************************
     
    1410#include <pthread.h>
    1511#include "my-stuff.h"
     12#include "mr_mem.h"
    1613#include "../common/mondostructures.h"
    1714#include "../common/libmondo.h"
     
    364361
    365362    /* Clean up blkid cache file if they exist */
    366     asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
     363    mr_asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
    367364    (void)unlink(tmp1);
    368365    paranoid_free(tmp1);
    369     asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
     366    mr_asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
    370367    (void)unlink(tmp1);
    371368    paranoid_free(tmp1);
     
    379376
    380377    /* Clean up multiconf cache file if they exist */
    381     asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
     378    mr_asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
    382379    (void)unlink(tmp1);
    383380    paranoid_free(tmp1);
    384381
    385382    /* Edit multipath.conf if needed to adapt wwid */
    386     asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
     383    mr_asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
    387384    if (does_file_exist(tmp1)) {
    388385        log_msg(2, "We may need to clean /etc/multipath.conf");
     
    394391
    395392    if (bkpinfo->restore_mode != nuke) {
    396         asprintf(&editor, "%s", find_my_editor());
    397         asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
     393        mr_asprintf(&editor, "%s", find_my_editor());
     394        mr_asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
    398395        popup_and_OK("You will now edit multipath.conf");
    399396        if (!g_text_mode) {
     
    788785    assert(raidlist != NULL);
    789786
    790     asprintf(&tmpA, "%s", "xxxxxxxxx");
    791     asprintf(&tmpB, "%s", "xxxxxxxxx");
    792     asprintf(&tmpC, "%s", "xxxxxxxxx");
     787    mr_asprintf(&tmpA, "%s", "         ");
     788    mr_asprintf(&tmpB, "%s", "         ");
     789    mr_asprintf(&tmpC, "%s", "         ");
    793790
    794791    log_msg(2, "nuke_mode --- starting");
     
    16711668
    16721669  /** malloc **/
    1673     char *command;
     1670    char *command = NULL;
    16741671    char *tmp;
    16751672    char *filelist_name;
     
    16851682
    16861683    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1687     malloc_string(command);
    16881684    malloc_string(tmp);
    16891685    malloc_string(filelist_name);
     
    16981694    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    16991695//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    1700     sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
     1696    mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
    17011697    run_program_and_log_output(command, 9);
     1698    paranoid_free(command);
     1699
    17021700    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    17031701            (int) (random() % 32768));
     
    17831781//      if (strstr(tarball_fname, ".star."))
    17841782        if (use_star) {
    1785             sprintf(command,
     1783            mr_asprintf(&command,
    17861784                    "star -x -force-remove -U " STAR_ACL_SZ
    17871785                    " errctl= file=%s", tarball_fname);
    17881786            if (strstr(tarball_fname, ".bz2")) {
    1789                 strcat(command, " -bz");
     1787                mr_strcat(command, " -bz");
    17901788            }
    17911789        } else {
    17921790            if (filelist_subset_fname[0] != '\0') {
    1793                 sprintf(command,
     1791                mr_asprintf(&command,
    17941792                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
    17951793                        TAPE_BLOCK_SIZE,
     
    17981796                        tarball_fname);
    17991797            } else {
    1800                 sprintf(command,
     1798                mr_asprintf(&command,
    18011799                        "afio -i -b %ld -c %ld -M 8m %s %s",
    18021800                        TAPE_BLOCK_SIZE,
     
    18041802            }
    18051803        }
     1804
    18061805#undef BUFSIZE
    1807         sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
    1808                 temp_log);
     1806        mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
    18091807        log_msg(1, "command = '%s'", command);
    18101808        unlink(temp_log);
     
    18181816            }
    18191817        }
     1818        paranoid_free(command);
     1819
    18201820        if (res && length_of_file(temp_log) < 5) {
    18211821            res = 0;
     
    18491849        }
    18501850        if (retval) {
    1851             sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     1851            mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    18521852            system(command);
     1853            paranoid_free(command);
     1854
    18531855            log_msg(2, "Errors occurred while processing fileset #%d",
    18541856                    current_tarball_number);
     
    18671869
    18681870  leave_sub:
    1869     paranoid_free(command);
    18701871    paranoid_free(tmp);
    18711872    paranoid_free(filelist_name);
     
    22492250    long max_val;
    22502251  /**malloc ***/
    2251     char *tmp;
     2252    char *tmp = NULL;
     2253    char *tmp1 = NULL;
    22522254    char *tarball_fname;
    22532255    char *progress_str;
     
    22712273    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    22722274    max_val = atol(tmp) + 1;
     2275    paranoid_free(tmp);
     2276
    22732277    sprintf(progress_str, "Restoring from %s #%d",
    22742278            media_descriptor_string(bkpinfo->backup_media_type),
     
    23342338                                              filelist);
    23352339            }
    2336             sprintf(tmp, "%s #%d, fileset #%ld - restore ",
     2340            mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ",
    23372341                    media_descriptor_string(bkpinfo->backup_media_type),
    23382342                    g_current_media_number, current_tarball_number);
    23392343            if (res) {
    2340                 strcat(tmp, "reported errors");
     2344                mr_strcat(tmp1, "reported errors");
    23412345            } else if (attempts > 1) {
    2342                 strcat(tmp, "succeeded");
     2346                mr_strcat(tmp1, "succeeded");
    23432347            } else {
    2344                 strcat(tmp, "succeeded");
     2348                mr_strcat(tmp1, "succeeded");
    23452349            }
    23462350            if (attempts > 1) {
    2347                 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
    2348                         attempts);
    2349             }
    2350             strcpy(comment, tmp);
     2351                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
     2352            }
     2353            strcpy(comment, tmp1);
     2354            paranoid_free(tmp1);
    23512355            if (attempts > 1) {
    23522356                log_to_screen(comment);
     
    23642368        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    23652369    }
    2366     paranoid_free(tmp);
    23672370    paranoid_free(tarball_fname);
    23682371    paranoid_free(progress_str);
Note: See TracChangeset for help on using the changeset viewer.