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


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/mondoarchive
Files:
3 edited

Legend:

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

    r537 r783  
    22## Process with Automake to generate Makefile.in
    33##
    4 AM_CPPFLAGS = -DMONDO_CONF_DIR=\"$(sysconfdir)\"
     4AM_CPPFLAGS = -DMONDO_CONF_DIR=\"$(sysconfdir)\" -I${top_builddir}/mondo/include
    55
    66## Headers
     
    1010sbin_PROGRAMS        = mondoarchive
    1111mondoarchive_SOURCES = main.c mondo-cli.c
    12 mondoarchive_LDADD   = ${top_builddir}/mondo/common/libmondo.a
     12mondoarchive_LDADD   = ${top_builddir}/mondo/common/libmondo.a ${top_builddir}/mondo/lib/libmr.a
  • trunk/mondo/mondo/mondoarchive/main.c

    r688 r783  
    1717#include <stdio.h>
    1818#include <stdlib.h>
    19 #include "../common/my-stuff.h"
     19#include "my-stuff.h"
    2020#include "../common/mondostructures.h"
    2121#include "../common/libmondo.h"
     
    3333extern bool g_remount_cdrom_at_end, g_remount_floppy_at_end;
    3434extern char *g_mondo_home;
    35 extern char *g_tmpfs_mountpt;
    3635extern char *g_erase_tmpdir_and_scratchdir;
    3736extern double g_kernel_version;
     
    4140long diffs;
    4241
    43 extern t_bkptype g_backup_media_type;
    4442extern int g_loglevel;
    4543
    4644/****************** subroutines used only by main.c ******************/
    4745
     46extern void mr_archive_init_conf(struct s_mr_conf *mr_conf);
    4847
    4948/**
     
    131130{
    132131    struct s_bkpinfo *bkpinfo;
    133     struct s_mrconf *mrconf;
    134132    char *tmp;
    135133    int res = 0;
     
    147145    }
    148146
    149 /* If -V, -v or --version then echo version no. and quit */
     147    /* If -V, -v or --version then echo version no. and quit */
    150148    if (argc == 2
    151149        && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
     
    155153    }
    156154
    157 /* Initialize variables */
    158 
     155    /* Initialize variables */
    159156    malloc_libmondo_global_strings();
    160 
    161     /* Initialize Configuration Structure */
    162     mrarchive_init_conf(mrconf);
    163157
    164158    res = 0;
     
    170164    }
    171165
    172 
    173 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
     166    /* Initialize Configuration Structure */
     167    mr_archive_init_conf(bkpinfo->mr_conf);
     168
     169
     170    /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    174171    asprintf(&tmp, "/sbin:/usr/sbin:%s:/usr/local/sbin", getenv("PATH"));
    175172    setenv("PATH", tmp, 1);
    176173    paranoid_free(tmp);
    177174
    178 /* Add the ARCH environment variable for ia64 purposes */
     175    /* Add the ARCH environment variable for ia64 purposes */
    179176    setenv("ARCH", get_architecture(), 1);
    180177
     
    331328    /* If we're meant to backup then backup */
    332329    if (bkpinfo->backup_data) {
    333         res = backup_data(bkpinfo, mrconf);
     330        res = backup_data(bkpinfo);
    334331        retval += res;
    335332        if (res) {
  • trunk/mondo/mondo/mondoarchive/mondo-cli.c

    r689 r783  
    77/** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
    88
    9 #include "../common/my-stuff.h"
     9#include "my-stuff.h"
    1010#include "../common/mondostructures.h"
    1111#include "mondo-cli-EXT.h"
     
    1818extern bool g_text_mode;
    1919extern bool g_skip_floppies;    ///< Whether to skip the creation of boot disks
    20 extern char g_startdir[MAX_STR_LEN];    ///< ????? @bug ?????
    21 extern char g_tmpfs_mountpt[MAX_STR_LEN];
    22 extern bool g_sigpipe;
    23 
    24 /*@ file pointer **************************************************/
    25 extern FILE *g_tape_stream;
    26 
    27 /*@ long long *****************************************************/
    28 extern long long g_tape_posK;
    29 
    30 /*@ long **********************************************************/
    31 extern long g_noof_sets;
    32 
    33 /*@ bool******** **************************************************/
    34 bool g_debugging = FALSE;       ///< ????? @bug ????? @ingroup globalGroup
    35 bool g_running_live = FALSE;    ///< ????? @bug ????? @ingroup globalGroup
    3620extern bool g_cd_recovery;
     21extern double g_kernel_version;
     22extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
    3723
    3824/**
     
    4430 */
    4531bool g_ISO_restore_mode = FALSE;
    46 
    47 
    48 extern double g_kernel_version;
    49 
    50 extern int g_current_media_number;
    51 
    52 
    53 
    54 extern pid_t g_main_pid;
    55 
    56 
    57 
    58 
    59 extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
    60 
    6132
    6233
     
    140111    paranoid_free(tmp);
    141112
    142     if (bkpinfo->nfs_mount[0] != '\0') {
     113    if (bkpinfo->nfs_mount != NULL) {
    143114        store_nfs_config(bkpinfo);
    144115    }
     
    303274        if (!strcmp(bkpinfo->include_paths, "/")) {
    304275            log_msg(2, "'/' is pleonastic.");
    305             bkpinfo->include_paths[0] = '\0';
    306         }
    307         if (bkpinfo->include_paths[0]) {
    308             strcat(bkpinfo->include_paths, " ");
     276            bkpinfo->include_paths = NULL;
    309277        }
    310278        asprintf(&tmp1, flag_val['I']);
     
    332300        paranoid_free(tmp1);
    333301
    334         strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
    335                 flag_val['I'],
    336                 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
     302        if (bkpinfo->include_paths == NULL) {
     303            asprintf(&tmp1, "%s", flag_val['I']);
     304        } else {
     305            asprintf(&tmp1, "%s %s", bkpinfo->include_paths, flag_val['I']);
     306        }
     307        paranoid_alloc(bkpinfo->include_paths,tmp1);
     308        paranoid_free(tmp1);
     309
    337310        log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
    338311        if (bkpinfo->include_paths[0] == '-') {
     
    348321    }
    349322
    350 
    351323    if (flag_set['J']) {
    352324        if (flag_set['I']) {
     
    356328        }
    357329        bkpinfo->make_filelist = FALSE;
    358         strcpy(bkpinfo->include_paths, flag_val['J']);
    359     }
     330        paranoid_alloc(bkpinfo->include_paths, flag_val['J']);
     331    }
     332
    360333    if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) {
    361334        if (!flag_set['r'] && g_kernel_version <= 2.5
     
    374347        }
    375348
    376         if (system("which cdrecord > /dev/null 2> /dev/null")
    377             && system("which dvdrecord > /dev/null 2> /dev/null")) {
    378             fatal_error
    379                 ("Please install dvdrecord/cdrecord and try again.");
    380         }
    381349        if (flag_set['C']) {
    382350            bkpinfo->cdrw_speed = atoi(flag_val['C']);
     
    408376        }
    409377    }
     378
    410379    if (flag_set['t'] && !flag_set['d']) {
    411380        log_it("Hmm! No tape drive specified. Let's see what we can do.");
     
    437406            }
    438407        }
    439         tmp = find_home_of_exe("growisofs");
    440         if (!tmp) {
    441             fatal_error
    442                 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    443         }
    444         paranoid_free(tmp);
    445 
    446         tmp = find_home_of_exe("dvd+rw-format");
    447         if (!tmp) {
    448             fatal_error
    449                 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
    450         }
    451         paranoid_free(tmp);
    452408
    453409        if (strchr(flag_val['d'], ',')) {
     
    498454    }
    499455    if (flag_set['n']) {
    500         asprintf(&tmp, flag_val['n']);
    501         bkpinfo->nfs_mount = tmp;
     456        paranoid_alloc(bkpinfo->nfs_mount,flag_val['n']);
    502457        if (!flag_set['d']) {
    503             asprintf(&tmp, "/");
    504             bkpinfo->nfs_remote_dir = tmp;
     458            paranoid_alloc(bkpinfo->nfs_remote_dir,"/");
    505459        }
    506460        asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
    507461                bkpinfo->nfs_mount);
     462        paranoid_free(bkpinfo->isodir);
    508463        bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp);
    509464        paranoid_free(tmp);
     
    516471        log_msg(3, "isodir= %s", bkpinfo->isodir);
    517472    }
     473
    518474    if (flag_set['c']) {
    519475        bkpinfo->backup_media_type = cdr;
     
    541497    }
    542498
    543 /* optional, popular */
     499    /* optional, popular */
    544500    if (flag_set['g']) {
    545501        g_text_mode = FALSE;
    546502    }
     503
    547504    if (flag_set['E']) {
    548         if (bkpinfo->exclude_paths[0]) {
    549             strcat(bkpinfo->exclude_paths, " ");
    550         }
    551505        asprintf(&tmp1, flag_val['E']);
    552506        p = tmp1;
     
    571525        paranoid_free(tmp1);
    572526
    573         strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
    574                 flag_val['E'],
    575                 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
    576     }
     527        if (bkpinfo->exclude_paths == NULL) {
     528            asprintf(&tmp1, "%s", flag_val['E']);
     529        } else {
     530            asprintf(&tmp1, "%s %s", bkpinfo->exclude_paths, flag_val['E']);
     531        }
     532        paranoid_alloc(bkpinfo->exclude_paths,tmp1);
     533        paranoid_free(tmp1);
     534    }
     535
    577536    if (flag_set['e']) {
    578537        bkpinfo->please_dont_eject = TRUE;
    579538    }
     539
    580540    if (flag_set['N'])          // exclude NFS mounts & devices
    581541    {
    582542        psz = list_of_NFS_mounts_only();
    583         if (bkpinfo->exclude_paths[0]) {
    584             strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN);
    585         }
    586         strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN);
     543        if (bkpinfo->exclude_paths != NULL) {
     544            asprintf(&tmp1, "%s %s", bkpinfo->exclude_paths, psz);
     545        } else {
     546            asprintf(&tmp1, "%s", psz);
     547        }
    587548        paranoid_free(psz);
     549        paranoid_alloc(bkpinfo->exclude_paths, tmp1);
     550        paranoid_free(tmp1);
    588551
    589552        log_msg(3, "-N means we're now excluding %s",
    590553                bkpinfo->exclude_paths);
    591554    }
    592     if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) {
    593         fatal_error
    594             ("Your '-E' parameter is too long. Please use '-J'. (See manual.)");
    595     }
     555
    596556    if (flag_set['b']) {
    597557        asprintf(&psz, flag_val['b']);
     
    613573        bkpinfo->internal_tape_block_size = itbs;
    614574    }
     575
    615576    if (flag_set['D']) {
    616577        bkpinfo->differential = 1;
     
    621582        }
    622583    }
     584
    623585    if (flag_set['x']) {
    624         asprintf(&tmp, flag_val['x']);
    625         bkpinfo->image_devs = tmp;
     586        paranoid_alloc(bkpinfo->image_devs,flag_val['x']);
    626587        if (run_program_and_log_output("which ntfsclone", 2)) {
    627588            fatal_error("Please install ntfsprogs package/tarball.");
    628589        }
    629590    }
     591
    630592    if (flag_set['m']) {
    631593        bkpinfo->manual_cd_tray = TRUE;
    632594    }
     595
    633596    if (flag_set['k']) {
    634597        if (strcasecmp(flag_val['k'], "FAILSAFE")) {
    635             asprintf(&tmp, "FAILSAFE");
    636             bkpinfo->kernel_path = tmp;
     598            paranoid_alloc(bkpinfo->kernel_path,"FAILSAFE");
    637599
    638600            if (!does_file_exist(bkpinfo->kernel_path)) {
     
    645607            }
    646608        } else {
    647             asprintf(&tmp, flag_val['k']);
    648             bkpinfo->kernel_path = tmp;
    649         }
    650     }
     609            paranoid_alloc(bkpinfo->kernel_path,flag_val['k']);
     610        }
     611    }
     612
    651613    if (flag_set['p']) {
    652         asprintf(&tmp, bkpinfo->prefix);
    653         bkpinfo->prefix = tmp;
    654     }
    655 
     614        paranoid_alloc(bkpinfo->prefix,flag_val['p']);
     615    }
    656616
    657617    if (flag_set['d']) {        /* backup directory (if ISO/NFS) */
    658618        if (flag_set['i']) {
    659             asprintf(&tmp, flag_val['d']);
    660             bkpinfo->isodir = tmp;
     619            paranoid_alloc(bkpinfo->isodir,flag_val['d']);
    661620            asprintf(&tmp, "ls -l %s", bkpinfo->isodir);
    662621            if (run_program_and_log_output(tmp, FALSE)) {
     
    666625            paranoid_free(tmp);
    667626        } else if (flag_set['n']) {
    668             asprintf(&tmp, flag_val['d']);
    669             bkpinfo->nfs_remote_dir = tmp;
     627            paranoid_alloc(bkpinfo->nfs_remote_dir,flag_val['d']);
    670628        } else {                /* backup device (if tape/CD-R/CD-RW) */
    671629
     
    698656            }
    699657        } else if ((tmp = find_cdrw_device()) ==  NULL) {
    700             paranoid_free(bkpinfo->media_device);
    701             bkpinfo->media_device = tmp;
     658            paranoid_alloc(bkpinfo->media_device, tmp);
     659            paranoid_free(tmp);
    702660            retval++;
    703661            log_to_screen
     
    723681    j = (int) random() % 32768;
    724682    if (flag_set['S']) {
    725         asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'], j);
     683        asprintf(&tmp, "%s/mondo.scratch.%d", flag_val['S'], j);
    726684        paranoid_free(bkpinfo->scratchdir);
    727685        bkpinfo->scratchdir = tmp;
    728686    }
    729687    if (flag_set['T']) {
    730         asprintf(&tmp, "%s/mondo.tmp.%ld", flag_val['T'], j);
     688        asprintf(&tmp, "%s/mondo.tmp.%d", flag_val['T'], j);
    731689        paranoid_free(bkpinfo->tmpdir);
    732690        bkpinfo->tmpdir = tmp;
     
    750708        paranoid_free(tmp);
    751709    }
     710
    752711    if (flag_set['A']) {
    753         asprintf(&tmp, flag_val['A']);
    754         bkpinfo->call_after_iso = tmp;
     712        paranoid_alloc(bkpinfo->call_after_iso,flag_val['A']);
    755713    }
    756714    if (flag_set['B']) {
    757         asprintf(&tmp, flag_val['B']);
    758         bkpinfo->call_before_iso = tmp;
     715        paranoid_alloc(bkpinfo->call_before_iso,flag_val['B']);
    759716    }
    760717    if (flag_set['F']) {
     
    784741#undef BOOT_LOADER_CHARS
    785742    }
     743
     744    tmp = NULL;
    786745    if (flag_set['f']) {
    787746        tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
    788         bkpinfo->boot_device = tmp;
     747        paranoid_alloc(bkpinfo->boot_device,tmp);
    789748    }
    790749    if (flag_set['Q']) {
     
    796755        log_msg(3, "boot loader is %c, residing at %s", i, tmp);
    797756        printf(_("boot loader is %c, residing at %s\n"), i, tmp);
     757        paranoid_free(tmp);
    798758        finish(0);
    799759    }
     
    801761
    802762    if (flag_set['P']) {
    803         asprintf(&tmp, flag_val['P']);
    804         bkpinfo->postnuke_tarball = tmp;
    805     }
     763        paranoid_alloc(bkpinfo->postnuke_tarball,flag_val['P']);
     764    }
     765
    806766    if (flag_set['L']) {
    807767        bkpinfo->use_lzo = TRUE;
     
    821781            (_("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."));
    822782    }
     783
    823784    if (flag_set['o']) {
    824785        bkpinfo->make_cd_use_lilo = TRUE;
Note: See TracChangeset for help on using the changeset viewer.