Changeset 783 in MondoRescue for trunk/mondo/mondo/common/libmondo-tools.c


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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-tools.c

    r689 r783  
    7474
    7575extern t_bkptype g_backup_media_type;
     76extern char *g_backup_media_string;
    7677
    7778extern bool am_I_in_disaster_recovery_mode(void);
     
    281282{
    282283    assert(raidrec != NULL);
    283     raidrec->raid_device[0] = '\0';
     284    raidrec->raid_device = NULL;
    284285    raidrec->raid_level = -9;
    285286    raidrec->persistent_superblock = 1;
     
    356357    char *tmp = NULL;
    357358    char *tmp1 = NULL;
    358     char call_before_iso_user[MAX_STR_LEN] = "\0";
     359    char *call_before_iso_user = NULL;
    359360    int rdsiz_MB;
    360361    char *iso_path = NULL;
     
    415416    if (avm / 1024 > rdsiz_MB * 3) {
    416417        if (run_program_and_log_output(command, 5)) {
    417             g_tmpfs_mountpt[0] = '\0';
     418            paranoid_free(g_tmpfs_mountpt);
    418419            log_it("Failed to mount tmpfs");
    419420        } else {
     
    421422        }
    422423    } else {
    423         g_tmpfs_mountpt[0] = '\0';
     424        paranoid_free(g_tmpfs_mountpt);
    424425        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
    425426    }
     
    427428
    428429    if (bkpinfo->use_lzo) {
    429         strcpy(bkpinfo->zip_exe, "lzop");
    430         strcpy(bkpinfo->zip_suffix, "lzo");
     430        paranoid_alloc(bkpinfo->zip_exe, "lzop");
     431        paranoid_alloc(bkpinfo->zip_suffix, "lzo");
    431432    } else if (bkpinfo->compression_level != 0) {
    432         strcpy(bkpinfo->zip_exe, "bzip2");
    433         strcpy(bkpinfo->zip_suffix, "bz2");
     433        paranoid_alloc(bkpinfo->zip_exe, "bzip2");
     434        paranoid_alloc(bkpinfo->zip_suffix, "bz2");
    434435    } else {
    435         bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     436        bkpinfo->zip_exe = NULL;
     437        bkpinfo->zip_suffix = NULL;
    436438    }
    437439
     
    470472            // -m isn't supported by growisofs, BTW...
    471473        } else {
    472             sprintf(bkpinfo->call_make_iso,
     474            asprintf(&bkpinfo->call_make_iso,
    473475                    "%s %s -Z %s . 2>> _ERR_",
    474476                    mondo_mkisofs_sz, "", bkpinfo->media_device);
     
    518520
    519521        if (bkpinfo->nonbootable_backup) {
    520             asprintf(&mondo_mkisofs_sz, "%s -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_", mrconf->mondo_iso_creation_cmd);
     522            asprintf(&mondo_mkisofs_sz, "%s -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_", bkpinfo->mr_conf->mondo_iso_creation_cmd);
    521523        } else if
    522524#ifdef __FreeBSD__
     
    539541        }
    540542        if (bkpinfo->manual_cd_tray) {
    541             if (bkpinfo->call_before_iso[0] == '\0') {
    542             sprintf(bkpinfo->call_before_iso,
     543            if (bkpinfo->call_before_iso == NULL) {
     544                asprintf(&bkpinfo->call_before_iso,
    543545                        "%s -o %s/temporary.iso . 2>> _ERR_",
    544546                        mondo_mkisofs_sz, bkpinfo->tmpdir);
    545                 } else {
    546                 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
    547                 sprintf (bkpinfo->call_before_iso,
     547            } else {
     548                asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
     549                asprintf(&bkpinfo->call_before_iso,
    548550                                    "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )",
    549551                        mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     552                paranoid_free(call_before_iso_user);
    550553            }
    551554            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
    552             sprintf(bkpinfo->call_make_iso,
     555            asprintf(&bkpinfo->call_make_iso,
    553556                    "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
    554557                    cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
     
    556559                    bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    557560        } else {
    558             sprintf(bkpinfo->call_make_iso,
     561            asprintf(&bkpinfo->call_make_iso,
    559562                    "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    560563                    mondo_mkisofs_sz, cdr_exe,
     
    641644                                                          h_addr)),
    642645                         strchr(bkpinfo->nfs_mount, ':'));
    643                 strcpy(bkpinfo->nfs_mount, ip_address);
     646                paranoid_alloc(bkpinfo->nfs_mount, ip_address);
    644647                paranoid_free(ip_address);
    645648            }
     
    663666        retval++;
    664667    }
    665     if (bkpinfo->include_paths[0] == '\0') {
     668    if (bkpinfo->include_paths == NULL) {
    666669        //      fatal_error ("Why no backup path?");
    667         strcpy(bkpinfo->include_paths, "/");
     670        asprintf(&bkpinfo->include_paths, "/");
    668671    }
    669672    chmod(bkpinfo->scratchdir, 0700);
    670673    chmod(bkpinfo->tmpdir, 0700);
    671674    g_backup_media_type = bkpinfo->backup_media_type;
     675    paranoid_alloc(g_backup_media_string,bkpinfo->backup_media_string);
    672676    return (retval);
    673677}
     
    712716    g_current_media_number = 1;
    713717    bkpinfo->postnuke_tarball = NULL;
    714     bkpinfo->nfs_mount = NULL;
     718    paranoid_free(bkpinfo->nfs_mount);
    715719    return (res);
    716720}
     
    748752    paranoid_free(bkpinfo->restore_path);
    749753    bkpinfo->use_lzo = FALSE;
    750     paranoid_free(bkpinfo->do_not_compress_these);
    751754    bkpinfo->verify_data = FALSE;
    752755    bkpinfo->backup_data = FALSE;
     
    767770    bkpinfo->optimal_set_size = 0;
    768771    bkpinfo->backup_media_type = none;
     772    paranoid_free(bkpinfo->backup_media_string);
    769773    paranoid_alloc(bkpinfo->include_paths, "/");
    770774    paranoid_free(bkpinfo->exclude_paths);
     
    10431047        value = NULL;
    10441048        return (1);
    1045     } else if (strstr(value, "/dev/") && strstr(value, "t0")
     1049    /* } BERLIOS: Useless:
     1050         else if (strstr(value, "/dev/") && strstr(value, "t0")
    10461051               && !strcmp(label, "media-dev")) {
    10471052        log_msg(2, "FYI, I shan't read new value for %s - already got %s",
    10481053                label, value);
    10491054        return (0);
    1050     } else {
     1055    */ } else {
    10511056        asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",
    10521057                label, config_file);
     
    11021107
    11031108    log_msg(1, "Started sub");
    1104     log_msg(4, "About to set g_boot_mountpt to \"\"");
    1105     asprintf(&g_boot_mountpt, "");
    1106     log_msg(4, "Done. Great. Seeting command to something");
     1109    log_msg(4, "Setting command to something");
    11071110    asprintf(&command,
    11081111             "grep -v \":\" /etc/fstab | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     
    11361139                asprintf(&tmp1, "mount %s", g_boot_mountpt);
    11371140                if (run_program_and_log_output(tmp1, 5)) {
     1141                    /* BERLIOS: Useless ???
    11381142                    paranoid_free(g_boot_mountpt);
    11391143                    asprintf(&g_boot_mountpt, " ");
     1144                    */
    11401145                    log_msg(1, "Plan B");
    11411146                    if (!run_program_and_log_output("mount /boot", 5)) {
     
    11661171
    11671172    log_msg(3, "starting");
    1168     if (g_boot_mountpt[0]) {
     1173    if (g_boot_mountpt != NULL) {
    11691174        asprintf(&tmp, "umount %s", g_boot_mountpt);
    11701175        if (run_program_and_log_output(tmp, 5)) {
Note: See TracChangeset for help on using the changeset viewer.