Ignore:
Timestamp:
Aug 18, 2009, 3:20:37 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3338@localhost: bruno | 2009-08-11 23:03:30 +0200
bkpinfo->zip_suffix, bkpinfo->image_devs and bkpinfo->restore_path are now allocated dynmically

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/mondorestore/mondorestore.c

    r2326 r2327  
    360360    char *tmp1 = NULL;
    361361
    362     /* Clean up blkid cache file if they exist */
    363     mr_asprintf(tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
    364     (void)unlink(tmp1);
    365     paranoid_free(tmp1);
    366     mr_asprintf(tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
    367     (void)unlink(tmp1);
    368     paranoid_free(tmp1);
     362    if (bkpinfo->restore_path) {
     363        /* Clean up blkid cache file if they exist */
     364        mr_asprintf(tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
     365        (void)unlink(tmp1);
     366        paranoid_free(tmp1);
     367        mr_asprintf(tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
     368        (void)unlink(tmp1);
     369        paranoid_free(tmp1);
     370    }
    369371}
    370372
     
    375377    char *editor = NULL;
    376378
    377     /* Clean up multiconf cache file if they exist */
    378     mr_asprintf(tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
    379     (void)unlink(tmp1);
    380     paranoid_free(tmp1);
     379    if (bkpinfo->restore_path) {
     380        /* Clean up multiconf cache file if they exist */
     381        mr_asprintf(tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
     382        (void)unlink(tmp1);
     383        paranoid_free(tmp1);
     384    }
    381385
    382386    /* Edit multipath.conf if needed to adapt wwid */
     
    425429 * @return 0 for success, or the number of errors encountered.
    426430 */
    427 int
    428 interactive_mode(struct mountlist_itself *mountlist,
    429                  struct raidlist_itself *raidlist)
     431int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist)
    430432{
    431433    int retval = 0;
     
    442444    char *tmp1 = NULL;
    443445    char *fstab_fname;
    444     char *old_restpath;
     446    char *old_restpath = NULL;
    445447
    446448    struct s_node *filelist;
     
    452454    malloc_string(tmp);
    453455    malloc_string(fstab_fname);
    454     malloc_string(old_restpath);
    455456    assert(bkpinfo != NULL);
    456457    assert(mountlist != NULL);
     
    460461
    461462    if (g_text_mode) {
    462         if (!ask_me_yes_or_no
    463             ("Interactive Mode + textonly = experimental! Proceed anyway?"))
    464         {
     463        if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) {
    465464            fatal_error("Wise move.");
    466465        }
     
    473472
    474473#ifdef __FreeBSD__
    475     if (strstr
    476         (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
    477          "noresize"))
     474    if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize"))
    478475#else
    479     if (strstr
    480         (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
    481          "noresize"))
     476    if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize"))
    482477#endif
    483478    {
     
    581576    }
    582577    /* restore */
    583     if ((restore_all =
    584          ask_me_yes_or_no("Do you want me to restore all of your data?")))
    585     {
     578    if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) {
    586579        log_msg(1, "Restoring all data");
    587580        retval += restore_everything(NULL);
    588     } else
    589         if ((restore_all =
    590              ask_me_yes_or_no
    591              ("Do you want me to restore _some_ of your data?"))) {
    592         strcpy(old_restpath, bkpinfo->restore_path);
     581    } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) {
     582        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    593583        for (done = FALSE; !done;) {
    594584            unlink("/tmp/filelist.full");
     
    610600                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
    611601                    }
    612                     strcpy(bkpinfo->restore_path, tmp);
     602                    mr_free(bkpinfo->restore_path);
     603                    mr_asprintf(bkpinfo->restore_path, "%s", tmp);
    613604                    log_msg(1, "Restoring subset");
    614605                    retval += restore_everything(filelist);
    615                     free_filelist(filelist);
    616606                } else {
    617                     strcpy(bkpinfo->restore_path, old_restpath);
    618                     free_filelist(filelist);
     607                    mr_free(bkpinfo->restore_path);
     608                    mr_asprintf(bkpinfo->restore_path, "%s", old_restpath);
    619609                }
     610                free_filelist(filelist);
    620611                mr_free(p);
    621612
    622                 if (!ask_me_yes_or_no
    623                     ("Restore another subset of your backup?")) {
     613                if (!ask_me_yes_or_no("Restore another subset of your backup?")) {
    624614                    done = TRUE;
    625615                }
     
    628618            }
    629619        }
    630         strcpy(old_restpath, bkpinfo->restore_path);
    631     } else {
    632         mvaddstr_and_log_it(g_currentY++,
    633                             0,
    634                             "User opted not to restore any data.                                  ");
     620        mr_free(old_restpath);
     621    } else {
     622        mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data.                                  ");
    635623    }
    636624    if (retval) {
    637         mvaddstr_and_log_it(g_currentY++,
    638                             0,
    639                             "Errors occurred during the restore phase.            ");
     625        mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase.            ");
    640626    }
    641627
     
    685671    paranoid_free(tmp);
    686672    paranoid_free(fstab_fname);
    687     paranoid_free(old_restpath);
    688673    log_it("Leaving interactive_mode()");
    689674    return (retval);
     
    942927    int retval = 0;
    943928
    944   /** malloc **/
    945     char *old_restpath;
     929    char *old_restpath = NULL;
    946930    char *p = NULL;
    947931
    948932    struct mountlist_itself *mountlist = NULL;
    949 //  static
    950933    struct raidlist_itself *raidlist = NULL;
    951934    struct s_node *filelist = NULL;
     
    953936    log_msg(1, "restore_to_live_filesystem() - starting");
    954937    assert(bkpinfo != NULL);
    955     malloc_string(old_restpath);
    956938    mountlist = malloc(sizeof(struct mountlist_itself));
    957939    raidlist = malloc(sizeof(struct raidlist_itself));
     
    960942    }
    961943
    962     strcpy(bkpinfo->restore_path, "/");
     944    mr_free(bkpinfo->restore_path);
     945    mr_asprintf(bkpinfo->restore_path, "/");
    963946    if (!g_restoring_live_from_cd && !g_restoring_live_from_nfs) {
    964947        popup_and_OK
     
    990973    if (!g_restoring_live_from_nfs && (filelist = process_filelist_and_biggielist())) {
    991974        save_filelist(filelist, "/tmp/selected-files.txt");
    992         strcpy(old_restpath, bkpinfo->restore_path);
     975        mr_asprintf(old_restpath, "%s", bkpinfo->restore_path);
    993976        p = popup_and_get_string("Restore path", "Restore files to where? )", bkpinfo->restore_path);
    994977        if (p != NULL) {
    995             strcpy(bkpinfo->restore_path, p);
    996             mr_free(p);
     978            mr_free(bkpinfo->restore_path);
     979            bkpinfo->restore_path = p;
    997980
    998981            log_it("Restoring everything");
    999982            retval += restore_everything(filelist);
    1000             free_filelist(filelist);
    1001             strcpy(bkpinfo->restore_path, old_restpath);
    1002         } else {
    1003             free_filelist(filelist);
    1004         }
    1005         strcpy(bkpinfo->restore_path, old_restpath);
     983        }
     984        free_filelist(filelist);
     985        mr_free(bkpinfo->restore_path);
     986        bkpinfo->restore_path = old_restpath;
    1006987    } else {
    1007988        if (filelist != NULL) {
     
    10221003        eject_device(bkpinfo->media_device);
    10231004    }
    1024     paranoid_free(old_restpath);
    10251005    free(mountlist);
    10261006    free(raidlist);
     
    24272407 * @return 0 for success, or the number of filesets that failed.
    24282408 */
    2429 int
    2430 restore_all_tarballs_from_stream(struct s_node *filelist)
     2409int restore_all_tarballs_from_stream(struct s_node *filelist)
    24312410{
    24322411    int retval = 0;
     
    29042883            g_restoring_live_from_nfs = TRUE;
    29052884        }
     2885        /* Adding an initialisation in order to avoid to hndle NULL pointer later */
     2886        mr_free(bkpinfo->restore_path);
     2887        mr_asprintf(bkpinfo->restore_path, "%s", "/tmp");
     2888
    29062889        log_msg(2, "Calling restore_to_live_filesystem()");
    29072890        retval = restore_to_live_filesystem();
     
    29212904
    29222905        log_it("About to call load_mountlist and load_raidtab");
    2923         strcpy(bkpinfo->restore_path, MNT_RESTORING);
     2906        mr_free(bkpinfo->restore_path);
     2907        mr_asprintf(bkpinfo->restore_path, "%s", MNT_RESTORING);
    29242908        read_cfg_file_into_bkpinfo(g_mondo_cfg_file);
    29252909        retval = load_mountlist(mountlist, g_mountlist_fname);
Note: See TracChangeset for help on using the changeset viewer.