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


Ignore:
Timestamp:
Aug 31, 2006, 5:09:20 PM (18 years ago)
Author:
Bruno Cornec
Message:
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

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

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondorestore/Makefile.am

    r426 r783  
    22## Process with Automake to generate Makefile.in
    33##
     4
     5AM_CPPFLAGS = -DMONDO_CONF_DIR=\"$(sysconfdir)\" -I${top_builddir}/mondo/include
    46
    57## Headers
     
    1214mondorestore_SOURCES  = mondo-prep.c mondo-restore.c mondo-rstr-newt.c \
    1315                        mondo-rstr-compare.c mondo-rstr-tools.c
    14 mondorestore_LDADD    = ${top_builddir}/mondo/common/libmondo.a @MONDORESTORE_STATIC@
     16mondorestore_LDADD    = ${top_builddir}/mondo/common/libmondo.a ${top_builddir}/mondo/lib/libmr.a @MONDORESTORE_STATIC@
     17
     18
  • trunk/mondo/mondo/mondorestore/mondo-prep.c

    r764 r783  
    99
    1010
    11 #include "../common/my-stuff.h"
     11#include "my-stuff.h"
    1212#include "../common/mondostructures.h"
    1313#include "mondoprep.h"
     
    5353    char *command;
    5454    int lino;
    55     int i;
    5655    FILE *fout;
    5756    char *buf;
    58     const int blocksize = 512;
    5957    struct list_of_disks *drivelist = NULL;
    6058// If LVMs are present and a zero-and-reboot wasn't recently undertaken
    6159// then zero & insist on reboot.
    62     buf = malloc(blocksize);
    6360    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
    6461    {
     
    8986            log_to_screen("Please hit 'Enter' to reboot.");
    9087            for (lino = 0; lino < drivelist->entries; lino++) {
    91                 for (i = 0; i < blocksize; i++) {
    92                     buf[i] = 0;
    93                 }
    94                 sprintf(buf, "%s\n", MONDO_WAS_HERE);
     88                asprintf(&buf, "%s\n", MONDO_WAS_HERE);
    9589                fout = fopen(drivelist->el[lino].device, "w+");
    9690                if (!fout) {
     
    9892                            drivelist->el[lino].device);
    9993                } else {
    100                     if (1 != fwrite(buf, blocksize, 1, fout)) {
     94                    if (1 != fwrite(buf, strlen(buf)+1, 1, fout)) {
    10195                        log_msg(1, "Failed to wipe %s",
    10296                                drivelist->el[lino].device);
     
    107101                    fclose(fout);
    108102                }
     103                paranoid_free(buf);
    109104            }
    110105            sync();
     
    257252    for (getline(&incoming, &n1, fin); !feof(fin); getline(&incoming, &n1, fin)) {
    258253        fgetpos(fin, &orig_pos);
    259         /* BERLIOS : Strange no ? */
     254        /* we want to execute lines begining with a # */
    260255        if (incoming[0] != '#') {
    261256            continue;
     
    268263        }
    269264        if ((p = strstr(incoming, "vgcreate"))) {
    270 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
     265            // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    271266            for (getline(&tmp, &n, fin); !feof(fin); getline(&tmp, &n, fin)) {
    272267                if (tmp[0] == '#') {
     
    287282                }
    288283            }
    289             malloc_string(tmp1);
    290             strcpy(tmp1, p + strlen("vgcreate") + 1);
     284            asprintf(&tmp1, p + strlen("vgcreate") + 1);
    291285            for (q = tmp1; *q > 32; q++);
    292286            *q = '\0';
     
    294288            asprintf(&tmp, "rm -Rf /dev/%s", tmp1);
    295289            paranoid_free(tmp1);
     290
    296291            run_program_and_log_output(tmp, 1);
    297292            paranoid_free(tmp);
     
    304299        }
    305300        for (p = incoming + 1; *p == ' '; p++);
    306         paranoid_free(command);
    307         asprintf(&command, p);
     301        paranoid_alloc(command,p);
    308302        for (p = command; *p != '\0'; p++);
    309303        for (; *(p - 1) < 32; p--);
    310304        *p = '\0';
     305
     306        /* BERLIOS: we should rather define LVMv1 or v2 and use it */
    311307        res = run_program_and_log_output(command, 5);
    312308        if (res > 0 && (p = strstr(command, "lvm "))) {
     
    338334            log_msg(5, "p='%s' --> extents=%ld", p, extents);
    339335            paranoid_free(tmp);
     336
    340337            p = strstr(command, "-L");
    341338            if (!p) {
     
    349346                        *q = ' ';
    350347                    }
     348                    /* BERLIOS: Dangerous: no size control !! */
    351349                    sprintf(p, "%ld", extents);
    352350                    i = strlen(p);
     
    359357                        *(q - 1) = ' ';
    360358                    }
     359                    /* BERLIOS: Dangerous: no size control !! */
    361360                    sprintf(p, "%ld%c", extents, 'm');
    362361                    i = strlen(p);
     
    673672    char *tmp = NULL;
    674673    char *tmp1 = NULL;
     674#ifdef __FreeBSD__
    675675    char *line = NULL;
    676676    char *status = NULL;
     
    679679    size_t n = 0;
    680680    size_t n1 = 0;
     681#endif
    681682
    682683    /** end ****************************************************************/
     
    15251526            // If so, then we just call label_drive_or_slice() and return.
    15261527            char c;
     1528            char *command;
     1529
    15271530            if (current_devno == 1) {
    15281531                // try DangerouslyDedicated mode
     
    15381541                                                 drivename,
    15391542                                                 0);
    1540                     char command[MAX_STR_LEN];
    1541                     sprintf(command, "disklabel -B %s",
     1543                    asprintf(&command, "disklabel -B %s",
    15421544                            basename(drivename));
    15431545                    if (system(command)) {
     
    15461548                             ("Warning! Unable to make the drive bootable."));
    15471549                    }
     1550                    paranoid_free(command);
    15481551                    paranoid_free(device_str);
    15491552
     
    20772080        asprintf(&partcode, "8e");
    20782081    } else if (format[0] == '\0') { /* LVM physical partition */
    2079         asprintf(&partcode, "");
     2082        asprintf(&partcode, "%s", "");
    20802083    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    20812084        asprintf(&partcode, format);
     
    23752378
    23762379    assert_string_is_neither_NULL_nor_zerolength(format);
    2377     assert(program != NULL);
    23782380
    23792381    if (strcmp(format, "swap") == 0) {
    23802382#ifdef __FreeBSD__
    2381         strcpy(program, "true");
     2383        asprintf(&program, "true");
    23822384#else
    2383         strcpy(program, "mkswap");
     2385        asprintf(&program, "mkswap");
    23842386#endif
    23852387    } else if (strcmp(format, "vfat") == 0) {
    2386         strcpy(program, "format-and-kludge-vfat");
     2388        asprintf(&program, "format-and-kludge-vfat");
    23872389#ifndef __FreeBSD__
    23882390    } else if (strcmp(format, "reiserfs") == 0) {
    2389         strcpy(program, "mkreiserfs -ff");
     2391        asprintf(&program, "mkreiserfs -ff");
    23902392    } else if (strcmp(format, "xfs") == 0) {
    2391         strcpy(program, "mkfs.xfs -f -q");
     2393        asprintf(&program, "mkfs.xfs -f -q");
    23922394    } else if (strcmp(format, "jfs") == 0) {
    2393         strcpy(program, "mkfs.jfs");
     2395        asprintf(&program, "mkfs.jfs");
    23942396    } else if (strcmp(format, "ext3") == 0) {
    2395         strcpy(program, "mkfs -t ext2 -F -j -q");
     2397        asprintf(&program, "mkfs -t ext2 -F -j -q");
    23962398    } else if (strcmp(format, "minix") == 0) {
    2397         strcpy(program, "mkfs.minix");
     2399        asprintf(&program, "mkfs.minix");
    23982400#endif
    23992401    } else if (strcmp(format, "ext2") == 0) {
    2400         strcpy(program, "mke2fs -F -q");
     2402        asprintf(&program, "mke2fs -F -q");
    24012403    } else {
    24022404#ifdef __FreeBSD__
    2403         sprintf(program, "newfs_%s", format);
     2405        asprintf(&program, "newfs_%s", format);
    24042406#else
    2405         sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
     2407        asprintf(&program, "mkfs -t %s -c", format);    // -c checks for bad blocks
    24062408#endif
    24072409        asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format,
     
    25042506    }
    25052507
    2506     /*
    2507        sprintf (tmp, "cp -f %s %s.pre-resize", g_mountlist_fname, g_mountlist_fname);
    2508        run_program_and_log_output (tmp, FALSE);
    2509      */
    2510 
    25112508    current_size_of_drive = get_phys_size_of_drive(drive_name);
    25122509
     
    26002597    assert(mountlist != NULL);
    26012598
    2602     if (g_mountlist_fname[0] == '\0') {
     2599    if (g_mountlist_fname == NULL) {
    26032600        log_it
    26042601            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
     
    26482645    if (c && strncmp(c, "/disc", 5) == 0) {
    26492646        /* yup its devfs, change the "disc" to "part" so the existing code works */
    2650         strcpy(c + 1, "part");
     2647        strncpy(c + 1, "part", (size_t)5);
    26512648    }
    26522649    drivemntlist->entries = 0;
  • trunk/mondo/mondo/mondorestore/mondo-restore-EXT.h

    r688 r783  
    1010extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
    1111extern bool g_I_have_just_nuked;
    12 extern char *g_tmpfs_mountpt;
    1312extern char *g_isodir_device;
    1413extern char *g_isodir_format;
     
    3231                         struct raidlist_itself *);
    3332extern void sort_mountlist_by_device(struct mountlist_itself *);
    34 extern void find_pathname_of_executable_preferably_in_RESTORING(char *,
    35                                                                 char *,
    36                                                                 char *);
    3733extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
    3834                            struct raidlist_itself *);
     
    5349extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long,
    5450                                        struct s_node *);
    55 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *,
    56                                             long, char *, long long,
    57                                             struct s_node *);
     51extern char *restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *,
     52                                            long, struct s_node *, int);
    5853extern int restore_a_tarball_from_CD(char *, int, struct s_node *);
    5954extern int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, int,
  • trunk/mondo/mondo/mondorestore/mondo-restore.c

    r689 r783  
    1313#include <unistd.h>
    1414
    15 #include "../common/my-stuff.h"
     15#include "my-stuff.h"
    1616#include "../common/mondostructures.h"
    1717#include "../common/libmondo.h"
     
    158158    assert(raidlist != NULL);
    159159    if (!bkpinfo->disaster_recovery) {
    160         strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     160        paranoid_alloc(g_mountlist_fname, "/tmp/mountlist.txt");
    161161        log_msg(2, "I guess you're testing edit_mountlist()");
    162162    }
     
    310310/**************************************************************************
    311311 *END_  EXTRACT_CONFIG_FILE_FROM_RAMDISK                                  *
    312  **************************************************************************/
    313 
    314 
    315 /**
    316  * Locate an executable in the directory structure rooted at @p restg.
    317  * @param out_path Where to put the executable.
    318  * @param fname The basename of the executable.
    319  * @param restg The directory structure to look in.
    320  * @note If it could not be found in @p restg then @p fname is put in @p out_path.
    321  * @ingroup restoreUtilityGroup
    322  */
    323 void
    324 find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
    325                                                     char *fname,
    326                                                     char *restg)
    327 {
    328     assert(out_path != NULL);
    329     assert_string_is_neither_NULL_nor_zerolength(fname);
    330 
    331     sprintf(out_path, "%s/sbin/%s", restg, fname);
    332     if (does_file_exist(out_path)) {
    333         sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
    334         if (does_file_exist(out_path)) {
    335             sprintf(out_path, "%s/bin/%s", restg, fname);
    336             if (does_file_exist(out_path)) {
    337                 sprintf(out_path, "%s/usr/bin/%s", restg, fname);
    338                 if (does_file_exist(out_path)) {
    339                     strcpy(out_path, fname);
    340                 }
    341             }
    342         }
    343     }
    344 }
    345 
    346 /**************************************************************************
    347  *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING                 *
    348312 **************************************************************************/
    349313
     
    534498             ask_me_yes_or_no
    535499             (_("Do you want me to restore _some_ of your data?")))) {
    536         old_restpath = bkpinfo->restore_path;
     500        asprintf(&old_restpath,bkpinfo->restore_path);
    537501        for (done = FALSE; !done;) {
    538502            unlink("/tmp/filelist.full");
     
    548512                    if (!strcmp(bkpinfo->restore_path, "/")) {
    549513                        if (!ask_me_yes_or_no(_("Are you sure?"))) {
    550                             paranoid_free(bkpinfo->restore_path);
    551                             bkpinfo->restore_path = old_restpath;
     514                            paranoid_alloc(bkpinfo->restore_path, old_restpath);
    552515                            goto gotos_suck;
    553516                        }
     
    558521                    free_filelist(filelist);
    559522                } else {
    560                     bkpinfo->restore_path = old_restpath;
     523                    paranoid_alloc(bkpinfo->restore_path,old_restpath);
    561524                    free_filelist(filelist);
    562525                }
     
    569532            }
    570533        }
     534        paranoid_free(old_restpath);
    571535    } else {
    572536        mvaddstr_and_log_it(g_currentY++,
     
    630594                            ("Warning - errors occurred during the restore phase."));
    631595    }
     596    return(retval);
    632597}
    633598
     
    750715    bool boot_loader_installed = FALSE;
    751716    char *tmp = NULL;
    752     char tmpA[MAX_STR_LEN];
    753     char tmpB[MAX_STR_LEN];
    754     char tmpC[MAX_STR_LEN];
     717    char *tmpA = NULL;
     718    char *tmpB = NULL;
     719    char *tmpC = NULL;
    755720
    756721    assert(bkpinfo != NULL);
     
    807772            tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline");
    808773#endif
    809             if (strstr(tmp,,"nopart")) {
     774            if (strstr(tmp,"nopart")) {
    810775                log_msg(2,
    811776                        "Not partitioning drives due to 'nopart' option.");
     
    949914    if (filelist) {
    950915        save_filelist(filelist, "/tmp/selected-files.txt");
    951         old_restpath = bkpinfo->restore_path;
     916        asprintf(&old_restpath,bkpinfo->restore_path);
    952917        if (popup_and_get_string(_("Restore path"),
    953918                                 _("Restore files to where? )"),
     
    957922        }
    958923        free_filelist(filelist);
    959         bkpinfo->restore_path = old_restpath;
     924        paranoid_alloc(bkpinfo->restore_path,old_restpath);
    960925    }
    961926    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    1012977    char *bigblk = NULL;
    1013978    char *pathname_of_last_file_restored = NULL;
    1014     int retval = 0;
    1015979    int finished = FALSE;
    1016980    long sliceno;
     
    11721136            asprintf(&tmp3,
    11731137                    "Asking for %s #%d so that I may read slice #%ld\n",
    1174                     media_descriptor_string(bkpinfo->backup_media_type),
     1138                    bkpinfo->backup_media_string,
    11751139                    g_current_media_number, sliceno);
    11761140            log_msg(2, tmp3);
     
    11781142
    11791143            asprintf(&tmp3, _("Restoring from %s #%d"),
    1180                     media_descriptor_string(bkpinfo->backup_media_type),
     1144                    bkpinfo->backup_media_string,
    11811145                    g_current_media_number);
    11821146            log_to_screen(tmp3);
     
    11981162                        asprintf(&bzip2_command, "bzip2 -dc %s 2>> %s",tmp2, MONDO_LOGFILE);
    11991163                } else if (does_file_exist(tmp)) {
    1200                         asprintf(&bzip2_command, "");
     1164                        asprintf(&bzip2_command, "%s", "");
    12011165                } else {
    12021166                    log_to_screen(_("OK, that's pretty fsck0red..."));
     
    12091173            }
    12101174            asprintf(&tmp3, "Working on %s #%d, file #%ld, slice #%ld ",
    1211                     media_descriptor_string(bkpinfo->backup_media_type),
     1175                    bkpinfo->backup_media_string,
    12121176                    g_current_media_number, bigfileno + 1, sliceno);
    12131177            log_msg(2, tmp3);
     
    13001264    char *command = NULL;
    13011265    char *outfile_fname = NULL;
    1302     char *ntfsprog_command = NULL;
    13031266    char *ntfsprog_fifo = NULL;
    13041267    char *file_to_openout = NULL;
     
    14181381    }
    14191382
    1420     if (!bkpinfo->zip_exe[0]) {
     1383    if (bkpinfo->zip_exe == NULL) {
    14211384        asprintf(&command, "cat > \"%s\"", file_to_openout);
    14221385    } else {
     
    16491612                asprintf(&tmp, " -bz");
    16501613            } else {
    1651                 asprintf(&tmp, "");
     1614                asprintf(&tmp, "%s", "");
    16521615            }
    16531616            asprintf(&command,
     
    17921755            "Restoring from fileset #%ld (%ld KB) on %s #%d",
    17931756            current_tarball_number, (long) size >> 10,
    1794             media_descriptor_string(bkpinfo->backup_media_type),
     1757            bkpinfo->backup_media_string,
    17951758            g_current_media_number);
    17961759    log_msg(2, tmp);
     
    18691832        // star
    18701833        if (filelist) {
    1871             asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable
     1834            asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable,
    18721835                    filelist_subset_fname,MONDO_LOGFILE);
    18731836        } else {
     
    19461909    long noof_biggiefiles = 0L, bigfileno = 0L, total_slices = 0L;
    19471910    char *tmp = NULL;
     1911    char *tmp1 = NULL;
    19481912    bool just_changed_cds = FALSE, finished = FALSE;
    19491913    char *xattr_fname = NULL;
     
    19971961            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
    19981962                    bigfileno + 1,
    1999                     media_descriptor_string(bkpinfo->backup_media_type),
     1963                    bkpinfo->backup_media_string,
    20001964                    g_current_media_number);
    20011965            tmp1 = slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "");
     
    20121976                                         ++g_current_media_number);
    20131977                asprintf(&tmp, _("Restoring from %s #%d"),
    2014                         media_descriptor_string(bkpinfo->
    2015                                                 backup_media_type),
     1978                        bkpinfo->backup_media_string,
    20161979                        g_current_media_number);
    20171980                log_to_screen(tmp);
     
    21242087
    21252088    asprintf(&progress_str, _("Restoring from %s #%d"),
    2126             media_descriptor_string(bkpinfo->backup_media_type),
     2089            bkpinfo->backup_media_string,
    21272090            g_current_media_number);
    21282091    log_to_screen(progress_str);
     
    21742137            paranoid_free(progress_str);
    21752138            asprintf(&progress_str, _("Restoring from %s #%d"),
    2176                     media_descriptor_string(bkpinfo->backup_media_type),
     2139                    bkpinfo->backup_media_string,
    21772140                    g_current_media_number);
    21782141            log_to_screen(progress_str);
     
    21822145                    _("Restoring from fileset #%ld on %s #%d"),
    21832146                    current_tarball_number,
    2184                     media_descriptor_string(bkpinfo->backup_media_type),
     2147                    bkpinfo->backup_media_string,
    21852148                    g_current_media_number);
    21862149//    log_msg(3, "progress_str = %s", progress_str);
     
    21982161            }
    21992162            asprintf(&tmp, _("%s #%d, fileset #%ld - restore %s"),
    2200                     media_descriptor_string(bkpinfo->backup_media_type),
     2163                    bkpinfo->backup_media_string,
    22012164                    g_current_media_number, current_tarball_number,tmp1);
    22022165            paranoid_free(tmp1);
     
    22602223    char *xattr_fname = NULL;
    22612224    char *acl_fname = NULL;
    2262     char *p = NULL;
    22632225    char *pathname_of_last_biggie_restored = NULL;
    22642226    char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes
    2265     long long biggie_size = NULL;
    2266     FILE *fbw = NULL;
     2227    long long biggie_size = (long long)0;
     2228    FILE *fbw;
    22672229
    22682230    assert(bkpinfo != NULL);
     
    25062468        asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"),
    25072469                current_afioball_number,
    2508                 media_descriptor_string(bkpinfo->backup_media_type),
     2470                bkpinfo->backup_media_string,
    25092471                g_current_media_number);
    25102472        res =
     
    27352697    malloc_libmondo_global_strings();
    27362698
    2737     g_mondo_home = call_program_and_get_last_line_of_output("which mondorestore"));
    2738     sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
     2699    g_mondo_home = call_program_and_get_last_line_of_output("which mondorestore");
     2700    paranoid_alloc(g_tmpfs_mountpt, "/tmp/tmpfs");
    27392701    make_hole_for_dir(g_tmpfs_mountpt);
    27402702    g_current_media_number = 1; // precaution
     
    27462708    reset_bkpinfo(bkpinfo);
    27472709    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     2710    bkpinfo->backup_media_string = NULL;
    27482711    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
    27492712    if (am_I_in_disaster_recovery_mode()) {
     
    27572720
    27582721    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
    2759     if (strlen(g_mountlist_fname) < 3) {
    2760         fatal_error
    2761             ("Serious error in malloc()'ing. Could be a bug in your glibc.");
    2762     }
    27632722    mkdir(MNT_CDROM, 0x770);
    27642723
     
    28122771        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
    28132772        if (!does_file_exist(g_mountlist_fname)) {
    2814             strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     2773            paranoid_alloc(g_mountlist_fname, "/tmp/mountlist.txt");
    28152774        }
    28162775        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
     
    28392798        bkpinfo->compression_level = 1;
    28402799        g_current_media_number = 2;
    2841         strcpy(bkpinfo->restore_path, "/tmp/TESTING");
     2800        paranoid_alloc(bkpinfo->restore_path, "/tmp/TESTING");
    28422801        bkpinfo->backup_media_type = dvd;
     2802        paranoid_free(bkpinfo->backup_media_string);
     2803        bkpinfo->backup_media_string = bkptype_to_string(bkpinfo->backup_media_type);
    28432804        open_progress_form(_("Reassembling /dev/hda1"),
    28442805                           _("Shark is a bit of a silly person."),
     
    29652926
    29662927        iamhere("About to call load_mountlist and load_raidtab");
    2967         strcpy(bkpinfo->restore_path, MNT_RESTORING);
     2928        paranoid_alloc(bkpinfo->restore_path, MNT_RESTORING);
    29682929        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
    29692930        retval = load_mountlist(mountlist, g_mountlist_fname);
     
    29782939                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
    29792940                log_msg(1, "Mounting nfs dir");
    2980                 sprintf(bkpinfo->isodir, "/tmp/isodir");
     2941                paranoid_alloc(bkpinfo->isodir, "/tmp/isodir");
    29812942                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
    29822943                asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir",
     
    30002961            log_msg(0, "Partitioning only.");
    30012962            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
    3002             strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     2963            paranoid_alloc(g_mountlist_fname, "/tmp/mountlist.txt");
    30032964            load_mountlist(mountlist, g_mountlist_fname);
    30042965            res = partition_everything(mountlist);
     
    30092970            log_msg(0, "Formatting only.");
    30102971            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
    3011             strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     2972            paranoid_alloc(g_mountlist_fname, "/tmp/mountlist.txt");
    30122973            load_mountlist(mountlist, g_mountlist_fname);
    30132974            res = format_everything(mountlist, FALSE, raidlist);
     
    30182979            log_msg(0, "Stopping LVM and RAID");
    30192980            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
    3020             strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
     2981            paranoid_alloc(g_mountlist_fname, "/tmp/mountlist.txt");
    30212982            load_mountlist(mountlist, g_mountlist_fname);
    30222983            res = do_my_funky_lvm_stuff(TRUE, FALSE);
  • trunk/mondo/mondo/mondorestore/mondo-restore.h

    r688 r783  
    1010int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *,
    1111                  struct raidlist_itself *);
    12 void find_pathname_of_executable_preferably_in_RESTORING(char *, char *,
    13                                                          char *);
    1412int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *,
    1513                     struct raidlist_itself *);
     
    2220int restore_mode(struct s_bkpinfo *, struct mountlist_itself *,
    2321                 struct raidlist_itself *);
    24 int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long,
    25                                      char *, long long, struct s_node *,
    26                                      int, char *);
     22char *restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long,
     23                                     struct s_node *, int);
    2724int restore_a_tarball_from_CD(char *, long, struct s_node *);
    2825int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, long,
  • trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c

    r689 r783  
    44
    55
    6 #include "../common/my-stuff.h"
     6#include "my-stuff.h"
    77#include "../common/mondostructures.h"
    88#include "../common/libmondo.h"
     
    4444    char *p = NULL;
    4545    int i = 0;
    46     int n = 0;
     46    size_t n = 0;
    4747    int retval = 0;
    4848
     
    258258        }
    259259        paranoid_free(tmp);
     260
    260261        if (use_star) {
    261262            if (strcmp(compressor_exe, "bzip2")) {
     
    264265            }
    265266        } else {
    266             asprintf(&tmp, compressor_exe);
    267             sprintf(compressor_exe, "-P %s -Z", tmp);
     267            tmp = compressor_exe;
     268            asprintf(&compressor_exe, "-P %s -Z", tmp);
    268269            paranoid_free(tmp);
    269270        }
     
    299300        log_OS_error(command);
    300301    }
     302    paranoid_free(command);
     303
    301304    if (length_of_file(logfile) > 5) {
    302         sprintf(command,
     305        asprintf(&command,
    303306                "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vx \"dev/.*\" >> /tmp/changed.txt",
    304307                logfile);
    305308        system(command);
     309        paranoid_free(command);
    306310        archiver_errors = count_lines_in_file(logfile);
    307311    } else {
    308312        archiver_errors = 0;
    309313    }
    310     paranoid_free(command);
    311314
    312315    if (archiver_errors) {
     
    353356
    354357    asprintf(&progress_str, _("Comparing with %s #%d "),
    355             media_descriptor_string(bkpinfo->backup_media_type),
     358            bkpinfo->backup_media_string,
    356359            g_current_media_number);
    357360
     
    402405            paranoid_free(progress_str);
    403406            asprintf(&progress_str, _("Comparing with %s #%d "),
    404                     media_descriptor_string(bkpinfo->backup_media_type),
     407                    bkpinfo->backup_media_string,
    405408                    g_current_media_number);
    406409            log_to_screen(progress_str);
  • trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c

    r764 r783  
    537537    char *personalities = NULL;
    538538    char *prompt = NULL;
    539     char *sz = NULL;
    540539    int out = 0, res = 0;
    541540
     
    544543    system
    545544        ("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    546     personalities = last_line_of_file("/tmp/raid-personalities.txt"));
     545    personalities = last_line_of_file("/tmp/raid-personalities.txt");
    547546    asprintf(&prompt, _("Please enter the RAID level you want. %s"),
    548547             personalities);
     
    616615    int i = 0;
    617616    int pos = 0;
    618 
    619     /** buffers ***********************************************************/
    620     char *tmp = NULL;
    621617
    622618    assert(mountlist != NULL);
     
    858854            popup_and_OK(tmp);
    859855        } else {
     856            paranoid_free(av->el[lino].label);
     857            paranoid_free(av->el[lino].value);
    860858            memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
    861859                   sizeof(struct raid_var_line));
     860            /* BERLIOS: New way of doing should be replaced by line below. Hope it's ok.
     861             * Will be when memory for struct is also dynamically allocated
     862            av->el[lino] = av->el[av->entries--];
     863                   */
    862864        }
    863865    }
     
    13231325                                                 device);
    13241326                if (j < 0) {
    1325                     sprintf(tmp,
     1327                    asprintf(&tmp,
    13261328                            _
    13271329                            ("/etc/raidtab does not have an entry for %s; please delete it and add it again"),
    13281330                            mountlist->el[currline].device);
    13291331                    popup_and_OK(tmp);
     1332                    paranoid_free(tmp);
    13301333                } else {
    13311334                    log_it(_("edit_raidlist_entry - calling"));
     
    14991502
    15001503    void *keylist[10];
    1501     void *curr_choice;
     1504    void *curr_choice = NULL;
    15021505
    15031506    int currline2 = 0;
     
    19711974            raidrec->additional_vars.el[lino].label, sz_out);
    19721975    if (popup_and_get_string(header, comment, sz_out)) {
    1973         strcpy(raidrec->additional_vars.el[lino].value, sz_out);
     1976        paranoid_free(raidrec->additional_vars.el[lino].value);
     1977        raidrec->additional_vars.el[lino].value = sz_out;
    19741978    }
    19751979    paranoid_free(header);
    19761980    paranoid_free(comment);
    1977     paranoid_free(sz_out);
    19781981}
    19791982#endif
     
    20152018    int currline = 0;
    20162019    int finished = FALSE;
     2020    int res = 0;
    20172021
    20182022    /** buffers **********************************************************/
     
    20252029    assert(raidlist != NULL);
    20262030
    2027     asprintf(&flaws_str_A, "xxxxxxxxx");
    2028     asprintf(&flaws_str_B, "xxxxxxxxx");
    2029     asprintf(&flaws_str_C, "xxxxxxxxx");
    20302031    if (mountlist->entries > ARBITRARY_MAXIMUM) {
    20312032        log_to_screen(_("Arbitrary limits suck, man!"));
     
    20452046            _("Format"), _("Size (MB)"));
    20462047    headerMsg = newtLabel(2, 1, tmp);
    2047     flawsLabelA = newtLabel(2, 13, flaws_str_A);
    2048     flawsLabelB = newtLabel(2, 14, flaws_str_B);
    2049     flawsLabelC = newtLabel(2, 15, flaws_str_C);
     2048    flawsLabelA = newtLabel(2, 13, "x");
     2049    flawsLabelB = newtLabel(2, 14, "x");
     2050    flawsLabelC = newtLabel(2, 15, "x");
    20502051    partitionsListbox =
    20512052        newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     
    20572058                          bEdit, bDelete, bReload, bCancel, bOK, NULL);
    20582059    while (!finished) {
    2059         evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B,
     2060        res = evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B,
    20602061                           flaws_str_C);
    20612062        newtLabelSetText(flawsLabelA, flaws_str_A);
    20622063        newtLabelSetText(flawsLabelB, flaws_str_B);
    20632064        newtLabelSetText(flawsLabelC, flaws_str_C);
     2065
     2066        paranoid_free(flaws_str_A);
     2067        paranoid_free(flaws_str_B);
     2068        paranoid_free(flaws_str_C);
     2069
    20642070        b_res = newtRunForm(myForm);
    20652071        /* BERLIOS: This needs to be re-written */
    20662072        if (b_res == bOK) {
    2067             if (!evaluate_mountlist
    2068                 (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) {
     2073            if (!res) {
    20692074                finished =
    20702075                    ask_me_yes_or_no
     
    21132118            }
    21142119        }
    2115         paranoid_free(flaws_str_A);
    2116         paranoid_free(flaws_str_B);
    2117         paranoid_free(flaws_str_C);
    21182120    }
    21192121    newtFormDestroy(myForm);
     
    24132415    raidrec = &raidlist->el[pos_in_raidlist];
    24142416    initialize_raidrec(raidrec);
    2415     strcpy(raidrec->OSSWAP(raid_device, volname),
     2417    asprintf(&raidrec->OSSWAP(raid_device, volname),
    24162418           OSSWAP(device, basename(device)));
    24172419#ifndef __FreeBSD__
     
    26472649                   (void *) &raidrec->additional_vars.el[i],
    26482650                   sizeof(struct raid_var_line));
     2651            /* BERLIOS : To be changed */
    26492652        }
    26502653        raidrec->additional_vars.entries--;
  • trunk/mondo/mondo/mondorestore/mondo-rstr-newt.h

    r688 r783  
    33**/
    44
    5 #include "../common/my-stuff.h"
     5#include "my-stuff.h"
    66#include "../common/mondostructures.h"
    77#include "../common/libmondo.h"
  • trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c

    r764 r783  
    55#include <unistd.h>
    66
    7 #include "../common/my-stuff.h"
     7#include "my-stuff.h"
    88#include "../common/mondostructures.h"
    99#include "../common/libmondo.h"
     
    3939
    4040extern t_bkptype g_backup_media_type;
     41extern char *g_backup_media_string;
    4142
    4243extern int g_partition_table_locked_up;
     
    290291    assert(bkpinfo != NULL);
    291292    g_ISO_restore_mode = TRUE;
     293
     294    paranoid_free(g_isodir_device);
    292295    read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    293296    if (bkpinfo->disaster_recovery) {
    294297/* Patch Conor Daly 26-june-2004
    295298 * Don't let this clobber an existing bkpinfo->isodir */
    296         if (!bkpinfo->isodir[0]) {
    297             strcpy(bkpinfo->isodir, "/tmp/isodir");
     299        if (!bkpinfo->isodir) {
     300            paranoid_alloc(bkpinfo->isodir, "/tmp/isodir");
    298301        }
    299302/* End patch */
     
    344347    i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
    345348    asprintf(&tmp, "%s #%d has been mounted via loopback mount",
    346             media_descriptor_string(bkpinfo->backup_media_type), i);
     349            bkpinfo->backup_media_string, i);
    347350    log_msg(1, tmp);
    348351    paranoid_free(tmp);
     
    497500{
    498501    char *mount_cmd = NULL;
    499     char *tmp = NULL;
    500502    int i, res;
    501503#ifdef __FreeBSD__
     
    519521        log_msg(2, "Mounting for NFS thingy");
    520522        log_msg(2, "isodir = %s", bkpinfo->isodir);
    521         if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
     523        if ((!bkpinfo->isodir || !strcmp(bkpinfo->isodir, "/"))
    522524            && am_I_in_disaster_recovery_mode()) {
    523             strcpy(bkpinfo->isodir, "/tmp/isodir");
     525            paranoid_alloc(bkpinfo->isodir, "/tmp/isodir");
    524526            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    525527        }
     
    663665        asprintf(&p2, ",user_xattr");
    664666    } else {
    665         asprintf(&p2, "");
     667        asprintf(&p2, "%s", "");
    666668    }
    667669    paranoid_free(tmp);
     
    671673        asprintf(&p3, ",acl");
    672674    } else {
    673         asprintf(&p3, "");
     675        asprintf(&p3, "%s", "");
    674676    }
    675677    paranoid_free(tmp);
     
    789791    char *value = NULL;
    790792    char *tmp = NULL;
     793    char *tmp1 = NULL;
    791794    char *command = NULL;
    792795    char *iso_mnt = NULL;
     
    836839
    837840            if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    838                 paranoid_free(bkpinfo->prefix);
    839                 bkpinfo->prefix = value;
     841                paranoid_alloc(bkpinfo->prefix,value);
    840842            } else {
    841843                paranoid_alloc(bkpinfo->prefix, STD_PREFIX);
     
    845847            paranoid_free(value);
    846848            if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    847                 paranoid_free(bkpinfo->prefix);
    848                 bkpinfo->prefix = value;
     849                paranoid_alloc(bkpinfo->prefix,value);
    849850            } else {
    850851                paranoid_alloc(bkpinfo->prefix, STD_PREFIX);
     
    869870        } else if (bkpinfo->backup_media_type == tape
    870871                   || bkpinfo->backup_media_type == udev) {
     872            paranoid_free(bkpinfo->media_device);
    871873            if (read_cfg_var(cfg_file, "media-dev", bkpinfo->media_device)) {
    872874                fatal_error("Cannot get tape device name from cfg file");
     
    964966                    "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
    965967        } else {
     968            paranoid_free(bkpinfo->nfs_mount);
     969            paranoid_free(bkpinfo->nfs_remote_dir);
    966970            read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
    967971                         bkpinfo->nfs_mount);
     
    976980         * isodir in disaster recovery mode
    977981         */
    978         old_isodir = bkpinfo->isodir;
     982        paranoid_alloc(old_isodir,bkpinfo->isodir);
    979983        read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    980984        read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
    981985        if (iso_mnt && iso_path) {
     986            paranoid_free(bkpinfo->isodir);
    982987            asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    983         } else {
    984             bkpinfo->isodir = old_isodir;
    985988        }
    986989        paranoid_free(iso_mnt);
     
    992995                    ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
    993996                     old_isodir, bkpinfo->isodir);
    994                 if (bkpinfo->isodir != old_isodir) {
    995                     paranoid_free(old_isodir);
    996                 }
    997             } else {
    998                 paranoid_free(old_isodir);
    999             }
    1000         }
    1001 
     997            }
     998        }
     999        paranoid_free(old_isodir);
     1000
     1001        paranoid_free(g_isodir_device);
    10021002        read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    10031003        log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
     
    10291029                    paranoid_free(iso_mnt);
    10301030                    paranoid_free(iso_path);
    1031                     asprintf(&iso_mnt, "");
    1032                     asprintf(&iso_path, "");
     1031                    asprintf(&iso_mnt, "%s", "");
     1032                    asprintf(&iso_path, "%s", "");
    10331033
    10341034                    if (mount_cdrom(bkpinfo)) {
     
    10691069    }
    10701070    g_backup_media_type = bkpinfo->backup_media_type;
     1071    bkpinfo->backup_media_string = bkptype_to_string(bkpinfo->backup_media_type);
     1072    g_backup_media_string = bkpinfo->backup_media_string;
    10711073    return (0);
    10721074}
     
    18231825    assert(bkpinfo != NULL);
    18241826
    1825     malloc_string(g_tmpfs_mountpt);
    1826 
    18271827    asprintf(&g_biggielist_txt, "%s/%s",bkpinfo->tmpdir , BIGGIELIST_TXT_STUB);
    18281828    asprintf(&g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);
     
    18301830    asprintf(&g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
    18311831            bkpinfo->tmpdir);
     1832    paranoid_free(g_mondo_cfg_file);
     1833    paranoid_free(g_mountlist_fname);
    18321834    if (bkpinfo->disaster_recovery) {
    18331835        asprintf(&g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
     
    21102112{
    21112113    int retval = 0;
    2112     char *device = NULL;
    21132114    char *command = NULL;
    21142115    char *cfg_file = NULL;
     
    23642365
    23652366    g_backup_media_type = bkpinfo->backup_media_type;
     2367    bkpinfo->backup_media_string = bkptype_to_string(bkpinfo->backup_media_type);
     2368    g_backup_media_string = bkpinfo->backup_media_string;
    23662369    return (retval);
    23672370}
Note: See TracChangeset for help on using the changeset viewer.