Ignore:
Timestamp:
Mar 21, 2007, 12:48:32 PM (13 years ago)
Author:
Bruno Cornec
Message:

Begining of work on conf file introduction in mondo

  • create a new struct mr_ar_conf to store conf info
  • adds a static mr_ar_store_conf function to store conf file info in that struc
  • mondo.conf is now the .dist version
  • md5 not done yet

Not tested may not work at all nor compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/mondoarchive/mondoarchive.c

    r1245 r1256  
    2222#include "mondo-cli-EXT.h"
    2323
     24#include "mondoarchive.h"
    2425#include "mr_mem.h"
    2526#include "mr_str.h"
    2627#include "mr_msg.h"
    2728#include "mr_file.h"
     29#include "mr_conf.h"
    2830
    2931// for CVS
     
    4143extern char *g_erase_tmpdir_and_scratchdir;
    4244extern char *g_cdrw_drive_is_here;
     45extern double g_kernel_version;
     46extern char *g_magicdev_command;
     47extern t_bkptype g_backup_media_type;
     48extern int g_loglevel;
     49
    4350static char *g_cdrom_drive_is_here = NULL;
    4451static char *g_dvd_drive_is_here = NULL;
    45 extern double g_kernel_version;
    46 
    47 /***************** global vars, used only by main.c ******************/
     52
     53struct mr_ar_conf mr_conf;
     54
     55/***************** global vars ******************/
    4856bool g_skip_floppies;
    4957long diffs;
     
    5159char *ps_proc_id = "$2";
    5260
    53 extern t_bkptype g_backup_media_type;
    54 extern int g_loglevel;
    55 
    56 /****************** subroutines used only by main.c ******************/
     61/****************** subroutines used only here ******************/
    5762
    5863
     
    6065 * Print a "don't panic" message to the log and a message about the logfile to the screen.
    6166 */
    62 void welcome_to_mondoarchive(void)
     67static void welcome_to_mondoarchive(void)
    6368{
    64     mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org",
    65             PACKAGE_VERSION);
     69    mr_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION);
    6670    mr_msg(0, "running on %s architecture", get_architecture());
    67     mr_msg(0,
    68             "-----------------------------------------------------------");
    69     mr_msg(0,
    70             "NB: Mondo logs almost everything, so don't panic if you see");
    71     mr_msg(0,
    72             "some error messages.  Please read them carefully before you");
    73     mr_msg(0,
    74             "decide to break out in a cold sweat.    Despite (or perhaps");
    75     mr_msg(0,
    76             "because of) the wealth of messages. some users are inclined");
    77     mr_msg(0,
    78             "to stop reading this log. If Mondo stopped for some reason,");
    79     mr_msg(0,
    80             "chances are it's detailed here.  More than likely there's a");
    81     mr_msg(0,
    82             "message at the very end of this log that will tell you what");
    83     mr_msg(0,
    84             "is wrong. Please read it!                          -Devteam");
    85     mr_msg(0,
    86             "-----------------------------------------------------------");
     71    mr_msg(0, "-----------------------------------------------------------");
     72    mr_msg(0, "NB: Mondo logs almost everything, so don't panic if you see");
     73    mr_msg(0, "some error messages.  Please read them carefully before you");
     74    mr_msg(0, "decide to break out in a cold sweat.    Despite (or perhaps");
     75    mr_msg(0, "because of) the wealth of messages. some users are inclined");
     76    mr_msg(0, "to stop reading this log. If Mondo stopped for some reason,");
     77    mr_msg(0, "chances are it's detailed here.  More than likely there's a");
     78    mr_msg(0, "message at the very end of this log that will tell you what");
     79    mr_msg(0, "is wrong. Please read it!                          -Devteam");
     80    mr_msg(0, "-----------------------------------------------------------");
    8781
    8882    mr_msg(0, "Zero...");
     
    9892}
    9993
    100 
    101 extern char *g_magicdev_command;
    102 
    10394/**
    10495 * Do whatever is necessary to insure a successful backup on the Linux distribution
    10596 * of the day.
    10697 */
    107 void distro_specific_kludges_at_start_of_mondoarchive(void)
     98static void distro_specific_kludges_at_start_of_mondoarchive(void)
    10899{
    109100    mr_msg(2, "Unmounting old ramdisks if necessary");
     
    120111 * Undo whatever was done by distro_specific_kludges_at_start_of_mondoarchive().
    121112 */
    122 void distro_specific_kludges_at_end_of_mondoarchive(void)
     113static void distro_specific_kludges_at_end_of_mondoarchive(void)
    123114{
    124115    mr_msg(2, "Restarting magicdev if necessary");
     
    133124    sync();
    134125    unmount_boot_if_necessary();    // for Gentoo users
     126}
     127
     128/* create the mr_ar_conf structure from mondo's conf file */
     129static void mr_ar_store_conf(struct mr_ar_conf *mr_conf) {
     130   
     131    mr_asprintf(mr_conf->iso_creation_cmd, mr_conf_sread("mondo_iso_creation_cmd"));
     132    mr_asprintf(mr_conf->iso_creation_options, mr_conf_sread("mondo_iso_creation_options"));
     133    mr_asprintf(mr_conf->iso_burning_cmd, mr_conf_sread("mondo_iso_burning_cmd"));
     134    mr_asprintf(mr_conf->iso_burning_options, mr_conf_sread("mondo_iso_burning_options"));
     135    iso_burning_speed = mr_conf_iread("mondo_iso_burning_speed");
     136    media_size = mr_conf_iread("mondo_media_size");
     137    mr_asprintf(mr_conf->media_device, mr_conf_sread("mondo_media_device"));
     138    manual_tray = mr_conf_bread("mondo_manual_tray");
     139    log_level = mr_conf_iread("mondo_log_level");
     140    mr_asprintf(mr_conf->prefix, mr_conf_sread("mondo_prefix"));
     141    external_tape_blocksize = mr_conf_iread("mondo_external_tape_blocksize");
     142    internal_tape_blocksize = mr_conf_iread("mondo_internal_tape_blocksize");
     143    slice_size = mr_conf_iread("mondo_slice_size");
     144    mr_asprintf(mr_conf->deplist_file, mr_conf_sread("mondo_deplist_file"));
     145    write_boot_floppy = mr_conf_bread("mondo_write_boot_floppy");
     146    create_mindi_cd = mr_conf_bread("mondo_create_mindi_cd");
     147    mr_asprintf(mr_conf->kernel, mr_conf_sread("mondo_kernel"));
     148    mr_asprintf(mr_conf->additional_modules, mr_conf_sread("mondo_additional_modules"));
     149    mr_asprintf(mr_conf->boot_loader, mr_conf_sread("mondo_boot_loader"));
     150    differential = mr_conf_bread("mondo_differential");
     151    mr_asprintf(mr_conf->compression_tool, mr_conf_sread("mondo_compression_tool"));
     152    compression_level = mr_conf_iread("mondo_compression_level");
     153    mr_asprintf(mr_conf->exclude_paths, mr_conf_sread("mondo_exclude_paths"));
     154    mr_asprintf(mr_conf->include_paths, mr_conf_sread("mondo_include_paths"));
     155    mr_asprintf(mr_conf->ui_mode, mr_conf_sread("mondo_ui_mode"));
     156    automatic_restore = mr_conf_bread("mondo_automatic_restore");
     157    mr_asprintf(mr_conf->scratch_dir, mr_conf_sread("mondo_scratch_dir"));
     158    mr_asprintf(mr_conf->tmp_dir, mr_conf_sread("mondo_tmp_dir"));
     159    mr_asprintf(mr_conf->images_dir, mr_conf_sread("mondo_images_dir"));
    135160}
    136161
     
    145170int main(int argc, char *argv[])
    146171{
    147     struct s_bkpinfo *bkpinfo;
     172    struct s_bkpinfo *bkpinfo = NULL;
    148173    struct stat stbuf;
    149174    char *tmp = NULL;
     
    157182    (void) textdomain("mondo");
    158183#endif
    159 /* Make sure I'm root; abort if not */
     184    printf(_("Initializing..."));
     185
     186    /* initialize log file with time stamp */
     187    /* We start with a loglevel of 4 - Adapted later on */
     188    /* It's mandatory to set this up first as all mr_ functions rely on it */
     189    unlink(MONDO_LOGFILE);
     190    mr_msg_init(MONDO_LOGFILE,4);
     191    mr_msg(0, _("Time started: %s"), mr_date());
     192
     193    /* Make sure I'm root; abort if not */
    160194    if (getuid() != 0) {
    161         fprintf(stderr, _("Please run as root.\n"));
    162         exit(127);
     195        mr_log_exit(127, _("Please run as root."));
    163196    }
    164197
     
    168201            || !strcmp(argv[argc - 1], "--version"))) {
    169202        printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
    170         exit(0);
    171     }
     203        mr_exit(0, NULL);
     204    }
     205
     206    /* Conf file management */
     207    /* Check md5 sum before */
     208    /* Get content */
     209    if (mr_conf_open(MONDO_CONF_DIR"/mondo.conf.dist") != 0) {
     210            mr_log_exit(-1, "Unable to open "MONDO_CONF_DIR"/mondo.conf.dist");
     211    }
     212    mr_ar_store_conf(&mr_conf);
     213    mr_conf_close();
     214
     215    /* Add MONDO_SHARE + other environment variables for mindi */
     216    setenv_mondo_var();
    172217
    173218    /* Initialize variables */
    174219    malloc_libmondo_global_strings();
    175 
    176     res = 0;
    177     retval = 0;
    178220    diffs = 0;
    179 
    180     /* initialize log file with time stamp */
    181     unlink(MONDO_LOGFILE);
    182     mr_msg_init(MONDO_LOGFILE,4);
    183     mr_msg(0, _("Initializing...\n"));
    184     mr_msg(0, _("Time started: %s"), mr_date());
    185 
    186221    bkpinfo = mr_malloc(sizeof(struct s_bkpinfo));
    187 
    188     /* Add the ARCH environment variable for ia64 purposes */
    189     setenv("ARCH", get_architecture(), 1);
    190 
    191     /* Add MONDO_SHARE + other environment variables for mindi */
    192     setenv_mondo_var();
    193 
    194222    if (stat(MONDO_CACHE, &stbuf) != 0) {
    195223        mr_mkdir(MONDO_CACHE,0x755);
Note: See TracChangeset for help on using the changeset viewer.