Ignore:
Timestamp:
Aug 31, 2006, 5:09:20 PM (14 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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.