Ignore:
Timestamp:
Sep 25, 2013, 8:55:43 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Modification to 3.1 branch to make it extremely similar to 3.0. What remains are function rewrite with allocation in the function and desallocation outside of the function. Will be next step
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/mondo/src/common/libmondo-tools.c

    r3161 r3190  
    5757 */
    5858char *g_mondo_home = NULL;
     59
     60/**
     61 * The serial string (used to differentiate between backups) of the current backup.
     62 */
     63char *g_serial_string = NULL;
    5964
    6065/**
     
    363368    assert(bkpinfo != NULL);
    364369
    365     if (!bkpinfo->tmpdir) {
    366         fatal_error("Tmpdir set to NULL !");
    367     }
    368 
    369370    bkpinfo->optimal_set_size =
    370371        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
    371372        1024;
    372 
    373     if (strlen(bkpinfo->tmpdir) < 2) {
    374         log_it("tmpdir is blank/missing");
    375         retval++;
    376     }
    377373
    378374    log_msg(1, "Post-param");
     
    393389        }
    394390        mr_free(tmp);
    395     }
    396     if (bkpinfo->scratchdir) {
    397         make_hole_for_dir(bkpinfo->scratchdir);
    398         chmod(bkpinfo->scratchdir, 0700);
    399     } else {
    400         fatal_error("Scratchdir set to NULL !");
    401391    }
    402392    if (bkpinfo->backup_media_type == iso)
     
    461451    }
    462452#endif
    463         else
    464         {
     453        else {
    465454            mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    466455        }
    467456        if (bkpinfo->manual_cd_tray) {
    468             paranoid_free(mondo_mkisofs_sz);
    469457            fatal_error("Manual CD tray + DVD not supported yet.");
    470458            // -m isn't supported by growisofs, BTW...
    471         } else {
    472             if (bkpinfo->media_device == NULL) {
    473                 return(1);
    474             }
     459        } else {}
    475460            mr_free(bkpinfo->call_make_iso);
    476461            mr_asprintf(bkpinfo->call_make_iso, "%s %s -Z %s . 2>> _ERR_", mondo_mkisofs_sz, "", bkpinfo->media_device);
    477             paranoid_free(mondo_mkisofs_sz);
    478         }
     462        }
     463        mr_free(mondo_mkisofs_sz);
    479464        if (getenv ("SUDO_COMMAND")) {
    480465            mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     
    506491        }
    507492        if (find_home_of_exe("cdrecord")) {
    508             strcpy(cdr_exe, "cdrecord");
     493            mr_asprintf(cdr_exe, "cdrecord");
    509494        } else if (find_home_of_exe("dvdrecord")) {
    510             strcpy(cdr_exe, "dvdrecord");
     495            mr_asprintf(cdr_exe, "dvdrecord");
    511496        } else {
    512497            mr_free(tmp);
     
    569554        }
    570555        mr_free(cdr_exe);
    571         paranoid_free(mondo_mkisofs_sz);
    572         paranoid_free(extra_cdrom_params);
     556        mr_free(mondo_mkisofs_sz);
     557        mr_free(extra_cdrom_params);
    573558    }                           // end of CD code
    574559
     
    587572        iso_dev = call_program_and_get_last_line_of_output(command,TRUE);
    588573        log_it("res of it = %s", iso_dev);
     574        mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
     575        write_one_liner_data_file(tmp, iso_dev);
     576        mr_free(tmp);
    589577        mr_free(command);
    590578
     
    595583        iso_mnt = call_program_and_get_last_line_of_output(command,TRUE);
    596584        log_it("res of it = %s", iso_mnt);
     585        mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
     586        write_one_liner_data_file(tmp, iso_mnt);
     587        mr_free(tmp);
    597588        mr_free(command);
    598589
     
    602593            mr_asprintf(iso_path, "%s", "");
    603594        } else {
    604             // If iso_mnt is only / then iso_path is the full dir 
     595            // If iso_mnt is only / then iso_path is the full dir
    605596            // (the formula bellow doesn't work in this case)
    606597            if (strcmp(iso_mnt, "/") == 0) {
     
    614605        mr_free(iso_tmp);
    615606
     607        mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     608        write_one_liner_data_file(tmp, iso_path);
     609        mr_free(tmp);
     610
    616611        log_it("isodir: %s", iso_path);
    617612        mr_free(iso_path);
     613
     614        mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     615        write_one_liner_data_file(tmp, bkpinfo->prefix);
     616        mr_free(tmp);
    618617
    619618        log_it("iso-prefix: %s",  bkpinfo->prefix);
     
    666665    }
    667666    if (bkpinfo->include_paths == NULL) {
    668         mr_asprintf(p, "/");
    669         bkpinfo->include_paths = p;
     667        mr_asprintf(bkpinfo->include_paths, "/");
    670668    }
    671669    g_backup_media_type = bkpinfo->backup_media_type;
     
    731729    if ((bkpinfo->tmpdir != NULL) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
    732730        /* purging a potential old tmpdir */
    733         log_it("Purging old tmpdir %s", bkpinfo->tmpdir);
    734731        if (chdir("/tmp")) {
    735732            // FIXME
     
    757754        finish(-1);
    758755    }
    759 
    760756    bkpinfo->tmpdir = p;
    761757    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
     758
     759    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     760    paranoid_system(tmp);
     761    mr_free(tmp);
     762}
     763
     764
     765void setup_scratchdir(char *path) {
     766
     767    char *tmp = NULL;
     768    char *p = NULL;
     769
     770    if (bkpinfo->scratchdir != NULL) {
     771        /* purging a potential old scratchdir */
     772        if (chdir("/tmp")) {
     773            // FIXME
     774        }
     775        if (strstr(bkpinfo->scratchdir,"mondo.scratch.") != NULL) {
     776            log_it("Purging old scratchdir %s", bkpinfo->scratchdir);
     777            mr_asprintf(tmp,"rm -Rf %s",bkpinfo->scratchdir);
     778        } else {
     779            log_it("Purging old scratchdir %s/mondo.scratch.*", bkpinfo->scratchdir);
     780            mr_asprintf(tmp,"rm -Rf %s/mondo.scratch.*",bkpinfo->scratchdir);
     781        }
     782        paranoid_system(tmp);
     783        mr_free(tmp);
     784    }
     785
     786    /* Always take in account arg first, then env, then default */
     787    if (path != NULL) {
     788        mr_asprintf(tmp, "%s/mondo.scratch.XXXXXX", path);
     789    } else if (getenv("MRSCRATCH")) {
     790        mr_asprintf(tmp, "%s/mondo.scratch.XXXXXX", getenv("MRSCRATCH"));
     791    } else {
     792        mr_asprintf(tmp, "/tmp/mondo.scratch.XXXXXX");
     793    }
     794    p = mkdtemp(tmp);
     795    if (p == NULL) {
     796        log_it("Failed to create global scratch directory %s for Mondo.",tmp);
     797        finish(-1);
     798    }
     799    strcpy(bkpinfo->scratchdir,p);
     800    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
     801    paranoid_free(tmp);
     802
     803    mr_asprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
     804    paranoid_system(tmp);
     805    mr_free(tmp);
    762806}
    763807
     
    805849    bkpinfo = (struct s_bkpinfo *)mr_malloc(sizeof(struct s_bkpinfo));
    806850
    807     /*  We need tmpdir as early as possible for further function calls */
    808     bkpinfo->tmpdir = NULL;         // Really setup after
    809     setup_tmpdir(NULL);
    810 
    811851    /* Initialized in same order as in the structure declaration to detect errors more easily */
    812852    bkpinfo->media_device = NULL;
    813     for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    814         bkpinfo->media_size[i] = -1;
    815     }
     853    bkpinfo->media_size = -1;
    816854    bkpinfo->boot_loader = '\0';
    817855    bkpinfo->boot_device = NULL;
     
    828866    bkpinfo->use_star = FALSE;
    829867    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     868   
     869/*  We need tmpdir as early as possible for further function calls */
     870    bkpinfo->tmpdir = NULL;         // Really setup after
     871    setup_tmpdir(NULL);
     872    setup_scratchdir(NULL);
     873
    830874    bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode();
    831875    if (bkpinfo->disaster_recovery) {
     
    835879    }
    836880    mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
    837     /*   bkpinfo->tmpdir is here in the struct */
    838     bkpinfo->scratchdir = NULL;     // Really setup after
    839881    bkpinfo->optimal_set_size = 0;
    840882    bkpinfo->backup_media_type = none;
    841883    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
     884    bkpinfo->exclude_paths = NULL;
    842885    bkpinfo->include_paths = NULL;
    843     bkpinfo->exclude_paths = NULL;
    844886    bkpinfo->exclude_devs = NULL;
    845887    bkpinfo->restore_path = NULL;
     
    850892    bkpinfo->kernel_path = NULL;
    851893    bkpinfo->netfs_mount = NULL;
     894    bkpinfo->netfs_proto = NULL;
     895    bkpinfo->netfs_user = NULL;
    852896    bkpinfo->netfs_remote_dir = NULL;
    853     bkpinfo->netfs_user = NULL;
    854     bkpinfo->netfs_proto = NULL;
    855897    bkpinfo->postnuke_tarball = NULL;
    856898    bkpinfo->subdir = NULL;
     
    864906    bkpinfo->use_obdr = FALSE;
    865907    bkpinfo->restore_mode = interactive;
    866 
    867     sensibly_set_scratchdir();
    868 }
    869 
    870 
     908}
    871909
    872910
     
    12181256    mr_asprintf(command, "mount | grep -Ew '/boot'");
    12191257    mr_free(tmp);
     1258
    12201259    tmp = call_program_and_get_last_line_of_output(command,TRUE);
    12211260    mr_free(command);
    12221261
    12231262    if (!strcmp(tmp,"")) {
    1224         if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")!= NULL)) {
     1263        if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) {
    12251264            if (!run_program_and_log_output("mount /boot", 5)) {
    12261265                strcpy(g_boot_mountpt, "/boot");
Note: See TracChangeset for help on using the changeset viewer.