Ignore:
Timestamp:
Mar 12, 2007, 2:26:06 AM (12 years ago)
Author:
bruno
Message:
  • Fix a bug for tape mangement where block size was missing during extract (Michel Loiseleur)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.2/mondo/src/mondorestore/mondo-rstr-tools.c

    r998 r1242  
    1212
    1313/***************************************************************************
    14  *                                                                         *
    15  *   This program is free software; you can redistribute it and/or modify  *
    16  *   it under the terms of the GNU General Public License as published by  *
    17  *   the Free Software Foundation; either version 2 of the License, or     *
    18  *   (at your option) any later version.                                   *
    19  *                                                                         *
    20  ***************************************************************************/
     14*                                                                         *
     15*   This program is free software; you can redistribute it and/or modify  *
     16*   it under the terms of the GNU General Public License as published by  *
     17*   the Free Software Foundation; either version 2 of the License, or     *
     18*   (at your option) any later version.                                   *
     19*                                                                         *
     20***************************************************************************/
    2121/* mondo-rstr-tools.c               Hugo Rabson
    2222
     
    242407/27
    2525- if the user is foolish enough to use /dev/md0 as boot device,
    26   call lilo -M /dev/hda to make sure lilo does its job properly
     26call lilo -M /dev/hda to make sure lilo does its job properly
    2727- better NFS+nuke support
    2828
     
    494906/14
    5050- shell out to /mnt/RESTORING chroot in order to let user install GRUB
    51   manually if automatic GRUB installation fails
     51manually if automatic GRUB installation fails
    5252
    535306/15
    5454- Added check for different 'isodir' chosen by user than stored in the archive
    55   Conor Daly <conor.daly@met.ie>
     55Conor Daly <conor.daly@met.ie>
    5656
    575704/17
     
    666604/02
    6767- when extracting cfg file and mountlist from all.tar.gz (tape copy),
    68   use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE
     68use block size of INTERNAL_TAPE_BLK_SIZE, not TAPE_BLOCK_SIZE
    6969
    707002/21
     
    797901/16/2004
    8080- instead of copying filelist, use 'ln -sf' to link to original;
    81   saves space
     81saves space
    8282
    838311/20/2003
     
    868611/16
    8787- fixed NFS path bug affecting the extractions of filelist/biggielist
    88   during selective restore
     88during selective restore
    8989
    909011/02
     
    10610610/15
    107107- run_grub() now uses its initiative instead
    108   of calling grub-install
     108of calling grub-install
    109109
    11011010/10
    111111- don't leave copies of filelist.full lying around, clogging up
    112   the ramdisk, there's a good fellow :-)
     112the ramdisk, there's a good fellow :-)
    113113
    11411410/02
     
    141141extern long g_current_progress, g_maximum_progress;
    142142extern char *g_biggielist_txt;  // where 'biggielist.txt' is stored, on ramdisk / tempdir;
    143                           // biggielist.txt is the list of big files stored on the
    144                           // backup media set in question
     143                  // biggielist.txt is the list of big files stored on the
     144                  // backup media set in question
    145145extern char *g_filelist_full;   // filelist.full.gz is the list of all regular files
    146                           // (excluding big files) stored on the backup media set
     146                  // (excluding big files) stored on the backup media set
    147147extern char *g_biggielist_pot;  // list of big files which _could_ be restored, if the
    148                           // user chooses them
     148                  // user chooses them
    149149extern char *g_filelist_imagedevs;  // list of devices (e.g. /dev/hda1, /dev/sda5) which
    150                             // were archived as images, not just /dev entries
    151                             // ... e.g. NTFS, BeOS partitions
     150                    // were archived as images, not just /dev entries
     151                    // ... e.g. NTFS, BeOS partitions
    152152extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
    153                               // restore only these
     153                      // restore only these
    154154extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
    155155extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
     
    166166
    167167/**
    168  * @addtogroup restoreUtilityGroup
    169  * @{
    170  */
    171 /**
    172  * Free the malloc()s for the filename variables.
    173  */
     168* @addtogroup restoreUtilityGroup
     169* @{
     170*/
     171/**
     172* Free the malloc()s for the filename variables.
     173*/
    174174void free_MR_global_filenames()
    175175{
    176     paranoid_free(g_biggielist_txt);
    177     paranoid_free(g_filelist_full);
    178     paranoid_free(g_filelist_imagedevs);
     176paranoid_free(g_biggielist_txt);
     177paranoid_free(g_filelist_full);
     178paranoid_free(g_filelist_imagedevs);
    179179//  paranoid_free (g_imagedevs_pot );
    180     paranoid_free(g_imagedevs_restthese);
    181     paranoid_free(g_mondo_cfg_file);
    182     paranoid_free(g_mountlist_fname);
    183     paranoid_free(g_mondo_home);
    184     paranoid_free(g_tmpfs_mountpt);
    185     paranoid_free(g_isodir_device);
    186     paranoid_free(g_isodir_format);
    187 
    188 }
    189 
    190 
    191 
    192 /**
    193  * Ask the user which imagedevs from the list contained in @p infname should
    194  * actually be restored.
    195  * @param infname The file containing a list of all imagedevs.
    196  * @param outfname The location of the output file containing the imagedevs the user wanted to restore.
    197  * @ingroup restoreUtilityGroup
    198  */
     180paranoid_free(g_imagedevs_restthese);
     181paranoid_free(g_mondo_cfg_file);
     182paranoid_free(g_mountlist_fname);
     183paranoid_free(g_mondo_home);
     184paranoid_free(g_tmpfs_mountpt);
     185paranoid_free(g_isodir_device);
     186paranoid_free(g_isodir_format);
     187
     188}
     189
     190
     191
     192/**
     193* Ask the user which imagedevs from the list contained in @p infname should
     194* actually be restored.
     195* @param infname The file containing a list of all imagedevs.
     196* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
     197* @ingroup restoreUtilityGroup
     198*/
    199199void ask_about_these_imagedevs(char *infname, char *outfname)
    200200{
    201     FILE *fin;
    202     FILE *fout;
    203   /************************************************************************
    204    * allocate memory regions. test and set  -sab 16 feb 2003              *
    205    ************************************************************************/
    206     char *incoming_ptr;
    207     char *question_ptr;
    208 
    209     char incoming[MAX_STR_LEN] = "\0";
    210     char question[MAX_STR_LEN];
    211 
    212     assert_string_is_neither_NULL_nor_zerolength(infname);
    213     assert_string_is_neither_NULL_nor_zerolength(outfname);
    214 
    215     incoming_ptr = malloc(sizeof(incoming));
    216     if (incoming_ptr == NULL) {
    217         fprintf(stderr, "Out of Memory\n");
    218         exit(EXIT_FAILURE);
    219     }
    220 
    221     question_ptr = malloc(sizeof(question));
    222     if (question_ptr == NULL) {
    223         fprintf(stderr, "Out of Memory\n");
    224         exit(EXIT_FAILURE);
    225     }
    226 
    227     memset(incoming_ptr, '\0', sizeof(incoming));
    228     memset(question_ptr, '\0', sizeof(question));
    229 
    230 
    231 
    232     if (!(fin = fopen(infname, "r"))) {
    233         fatal_error("Cannot openin infname");
    234     }
    235     if (!(fout = fopen(outfname, "w"))) {
    236         fatal_error("Cannot openin outfname");
    237     }
    238     for (fgets(incoming_ptr, MAX_STR_LEN, fin);
    239         !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    240         strip_spaces(incoming_ptr);
    241 
    242         if (incoming[0] == '\0') {
    243             continue;
    244         }
    245 
    246         sprintf(question_ptr,
    247                 "Should I restore the image of %s ?", incoming_ptr);
    248 
    249         if (ask_me_yes_or_no(question_ptr)) {
    250             fprintf(fout, "%s\n", incoming_ptr);
    251         }
    252     }
    253 
    254   /*** free memory ***********/
    255     paranoid_free(incoming_ptr);
    256     incoming_ptr = NULL;
    257     paranoid_free(question_ptr);
    258     question_ptr = NULL;
    259 
    260 
    261     paranoid_fclose(fout);
    262     paranoid_fclose(fin);
     201FILE *fin;
     202FILE *fout;
     203/************************************************************************
     204* allocate memory regions. test and set  -sab 16 feb 2003              *
     205************************************************************************/
     206char *incoming_ptr;
     207char *question_ptr;
     208
     209char incoming[MAX_STR_LEN] = "\0";
     210char question[MAX_STR_LEN];
     211
     212assert_string_is_neither_NULL_nor_zerolength(infname);
     213assert_string_is_neither_NULL_nor_zerolength(outfname);
     214
     215incoming_ptr = malloc(sizeof(incoming));
     216if (incoming_ptr == NULL) {
     217fprintf(stderr, "Out of Memory\n");
     218exit(EXIT_FAILURE);
     219}
     220
     221question_ptr = malloc(sizeof(question));
     222if (question_ptr == NULL) {
     223fprintf(stderr, "Out of Memory\n");
     224exit(EXIT_FAILURE);
     225}
     226
     227memset(incoming_ptr, '\0', sizeof(incoming));
     228memset(question_ptr, '\0', sizeof(question));
     229
     230
     231
     232if (!(fin = fopen(infname, "r"))) {
     233fatal_error("Cannot openin infname");
     234}
     235if (!(fout = fopen(outfname, "w"))) {
     236fatal_error("Cannot openin outfname");
     237}
     238for (fgets(incoming_ptr, MAX_STR_LEN, fin);
     239 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
     240strip_spaces(incoming_ptr);
     241
     242if (incoming[0] == '\0') {
     243    continue;
     244}
     245
     246sprintf(question_ptr,
     247        "Should I restore the image of %s ?", incoming_ptr);
     248
     249if (ask_me_yes_or_no(question_ptr)) {
     250    fprintf(fout, "%s\n", incoming_ptr);
     251}
     252}
     253
     254/*** free memory ***********/
     255paranoid_free(incoming_ptr);
     256incoming_ptr = NULL;
     257paranoid_free(question_ptr);
     258question_ptr = NULL;
     259
     260
     261paranoid_fclose(fout);
     262paranoid_fclose(fin);
    263263}
    264264
    265265/**************************************************************************
    266  *ASK_ABOUT_THESE_IMAGEDEVS                                               *
    267  **************************************************************************/
    268 
    269 
    270 
    271 
    272 
    273 
    274 
    275 
    276 /**
    277  * Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
    278  * @param bkpinfo The backup information structure. @c tmpdir is the only field used.
    279  * @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
    280  * @param output_cfg_file Where to put the configuration file extracted.
    281  * @param output_mountlist_file Where to put the mountlist file extracted.
    282  * @return 0 for success, nonzero for failure.
    283  * @ingroup restoreUtilityGroup
    284  */
     266*ASK_ABOUT_THESE_IMAGEDEVS                                               *
     267**************************************************************************/
     268
     269
     270
     271
     272
     273
     274
     275
     276/**
     277* Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
     278* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
     279* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
     280* @param output_cfg_file Where to put the configuration file extracted.
     281* @param output_mountlist_file Where to put the mountlist file extracted.
     282* @return 0 for success, nonzero for failure.
     283* @ingroup restoreUtilityGroup
     284*/
    285285int
    286286extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
    287                                 char *ramdisk_fname,
    288                                 char *output_cfg_file,
    289                                 char *output_mountlist_file)
    290 {
    291     char *mountpt;
    292     char *command;
    293     char *orig_fname;
    294     int retval = 0;
    295 
    296     assert(bkpinfo != NULL);
    297     malloc_string(mountpt);
    298     malloc_string(command);
    299     malloc_string(orig_fname);
    300     assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
    301     assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
    302     assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
    303     sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
    304     sprintf(command, "mkdir -p %s", mountpt);
    305     run_program_and_log_output(command, FALSE);
    306     sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
    307             ramdisk_fname, bkpinfo->tmpdir);
    308 
    309     run_program_and_log_output(command, FALSE);
    310     sprintf(command, "umount %s", mountpt);
    311 
    312     run_program_and_log_output(command, FALSE);
    313 
    314     sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
    315             bkpinfo->tmpdir, mountpt);
    316 
    317     run_program_and_log_output(command, FALSE);
    318 
    319     sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
    320 
    321     run_program_and_log_output(command, FALSE);
    322 
    323     sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
    324             mountpt, g_mondo_cfg_file, output_cfg_file);
    325     run_program_and_log_output(command, FALSE);
    326 
    327     sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
    328     if (does_file_exist(orig_fname)) {
    329         sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
    330         run_program_and_log_output(command, FALSE);
    331     }
    332     sprintf(command, "umount %s", mountpt);
    333     run_program_and_log_output(command, FALSE);
    334     if (!does_file_exist(output_cfg_file)
    335         || (!does_file_exist(output_mountlist_file)
    336             && does_file_exist(orig_fname))) {
    337         log_msg(2, "Failed to extract %s and/or %s from ramdisk",
    338                 output_cfg_file, output_mountlist_file);
    339         retval = 1;
    340     } else {
    341         retval = 0;
    342     }
    343     paranoid_free(mountpt);
    344     paranoid_free(command);
    345     paranoid_free(orig_fname);
    346     return (retval);
    347 
    348 }
    349 
    350 
    351 
    352 
    353 /**
    354  * Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
    355  * @param bkpinfo The backup information structure.
    356  */
     287                        char *ramdisk_fname,
     288                        char *output_cfg_file,
     289                        char *output_mountlist_file)
     290{
     291char *mountpt;
     292char *command;
     293char *orig_fname;
     294int retval = 0;
     295
     296assert(bkpinfo != NULL);
     297malloc_string(mountpt);
     298malloc_string(command);
     299malloc_string(orig_fname);
     300assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname);
     301assert_string_is_neither_NULL_nor_zerolength(output_cfg_file);
     302assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file);
     303sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
     304sprintf(command, "mkdir -p %s", mountpt);
     305run_program_and_log_output(command, FALSE);
     306sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null",
     307    ramdisk_fname, bkpinfo->tmpdir);
     308
     309run_program_and_log_output(command, FALSE);
     310sprintf(command, "umount %s", mountpt);
     311
     312run_program_and_log_output(command, FALSE);
     313
     314sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s",
     315    bkpinfo->tmpdir, mountpt);
     316
     317run_program_and_log_output(command, FALSE);
     318
     319sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir);
     320
     321run_program_and_log_output(command, FALSE);
     322
     323sprintf(command, "cp -f %s/%s %s",  // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg
     324    mountpt, g_mondo_cfg_file, output_cfg_file);
     325run_program_and_log_output(command, FALSE);
     326
     327sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname);
     328if (does_file_exist(orig_fname)) {
     329sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);
     330run_program_and_log_output(command, FALSE);
     331}
     332sprintf(command, "umount %s", mountpt);
     333run_program_and_log_output(command, FALSE);
     334if (!does_file_exist(output_cfg_file)
     335|| (!does_file_exist(output_mountlist_file)
     336    && does_file_exist(orig_fname))) {
     337log_msg(2, "Failed to extract %s and/or %s from ramdisk",
     338        output_cfg_file, output_mountlist_file);
     339retval = 1;
     340} else {
     341retval = 0;
     342}
     343paranoid_free(mountpt);
     344paranoid_free(command);
     345paranoid_free(orig_fname);
     346return (retval);
     347
     348}
     349
     350
     351
     352
     353/**
     354* Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
     355* @param bkpinfo The backup information structure.
     356*/
    357357void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo)
    358358{
    359     while (get_cfg_file_from_archive(bkpinfo)) {
    360         if (!ask_me_yes_or_no
    361             ("Failed to find config file/archives. Choose another source?"))
    362         {
    363             fatal_error("Could not find config file/archives. Aborting.");
    364         }
    365         interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
    366     }
    367 }
    368 
    369 
    370 /**
    371  * Determine whether @p list_fname contains a line containing @p f.
    372  * @param f The line to search for.
    373  * @param list_fname The file to search in.
    374  * @param preamble Ignore this beginning part of @p f ("" to disable).
    375  * @return TRUE if it's in the list, FALSE if it's not.
    376  */
     359while (get_cfg_file_from_archive(bkpinfo)) {
     360if (!ask_me_yes_or_no
     361    ("Failed to find config file/archives. Choose another source?"))
     362{
     363    fatal_error("Could not find config file/archives. Aborting.");
     364}
     365interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
     366}
     367}
     368
     369
     370/**
     371* Determine whether @p list_fname contains a line containing @p f.
     372* @param f The line to search for.
     373* @param list_fname The file to search in.
     374* @param preamble Ignore this beginning part of @p f ("" to disable).
     375* @return TRUE if it's in the list, FALSE if it's not.
     376*/
    377377bool is_file_in_list(char *f, char *list_fname, char *preamble)
    378378{
    379379
    380   /** needs malloc **/
    381     char *command;
    382     char *file;
    383     char *tmp;
    384     int res;
    385 
    386     malloc_string(command);
    387     malloc_string(file);
    388     malloc_string(tmp);
    389     assert_string_is_neither_NULL_nor_zerolength(f);
    390     assert_string_is_neither_NULL_nor_zerolength(list_fname);
    391     assert(preamble != NULL);
    392 
    393     if (strncmp(preamble, f, strlen(preamble)) == 0) {
    394         strcpy(file, f + strlen(preamble));
    395     } else {
    396         strcpy(file, f);
    397     }
    398     if (file[0] == '/' && file[1] == '/') {
    399         strcpy(tmp, file);
    400         strcpy(file, tmp + 1);
    401     }
    402     sprintf(tmp,
    403             "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
    404             f, file);
    405     log_msg(2, tmp);
    406     sprintf(command, "grep -E '^%s$' %s", file, list_fname);
    407     res = run_program_and_log_output(command, FALSE);
    408     paranoid_free(command);
    409     paranoid_free(file);
    410     paranoid_free(tmp);
    411     if (res) {
    412         return (FALSE);
    413     } else {
    414         return (TRUE);
    415     }
     380/** needs malloc **/
     381char *command;
     382char *file;
     383char *tmp;
     384int res;
     385
     386malloc_string(command);
     387malloc_string(file);
     388malloc_string(tmp);
     389assert_string_is_neither_NULL_nor_zerolength(f);
     390assert_string_is_neither_NULL_nor_zerolength(list_fname);
     391assert(preamble != NULL);
     392
     393if (strncmp(preamble, f, strlen(preamble)) == 0) {
     394strcpy(file, f + strlen(preamble));
     395} else {
     396strcpy(file, f);
     397}
     398if (file[0] == '/' && file[1] == '/') {
     399strcpy(tmp, file);
     400strcpy(file, tmp + 1);
     401}
     402sprintf(tmp,
     403    "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
     404    f, file);
     405log_msg(2, tmp);
     406sprintf(command, "grep -E '^%s$' %s", file, list_fname);
     407res = run_program_and_log_output(command, FALSE);
     408paranoid_free(command);
     409paranoid_free(file);
     410paranoid_free(tmp);
     411if (res) {
     412return (FALSE);
     413} else {
     414return (TRUE);
     415}
    416416}
    417417
    418418/**************************************************************************
    419  *END_IS_FILE_IN_LIST                                                     *
    420  **************************************************************************/
    421 
    422 
    423 
    424 /**
    425  * Set up an ISO backup.
    426  * @param bkpinfo The backup information structure. Fields used:
    427  * - @c bkpinfo->backup_media_type
    428  * - @c bkpinfo->disaster_recovery
    429  * - @c bkpinfo->isodir
    430  * @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
    431  * @return 0 for success, nonzero for failure.
    432  */
     419*END_IS_FILE_IN_LIST                                                     *
     420**************************************************************************/
     421
     422
     423
     424/**
     425* Set up an ISO backup.
     426* @param bkpinfo The backup information structure. Fields used:
     427* - @c bkpinfo->backup_media_type
     428* - @c bkpinfo->disaster_recovery
     429* - @c bkpinfo->isodir
     430* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
     431* @return 0 for success, nonzero for failure.
     432*/
    433433int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please)
    434434{
    435     char *mount_isodir_command, *tmp, *command;
    436     int retval = 0, i;
    437     bool already_mounted = FALSE;
    438 
    439     assert(bkpinfo != NULL);
    440     malloc_string(mount_isodir_command);
    441     malloc_string(tmp);
    442     malloc_string(command);
    443     g_ISO_restore_mode = TRUE;
    444     read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    445     if (bkpinfo->disaster_recovery) {
     435char *mount_isodir_command, *tmp, *command;
     436int retval = 0, i;
     437bool already_mounted = FALSE;
     438
     439assert(bkpinfo != NULL);
     440malloc_string(mount_isodir_command);
     441malloc_string(tmp);
     442malloc_string(command);
     443g_ISO_restore_mode = TRUE;
     444read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     445if (bkpinfo->disaster_recovery) {
    446446/* Patch Conor Daly 26-june-2004
    447  * Don't let this clobber an existing bkpinfo->isodir */
    448         if (!bkpinfo->isodir[0]) {
    449             strcpy(bkpinfo->isodir, "/tmp/isodir");
    450         }
     447* Don't let this clobber an existing bkpinfo->isodir */
     448if (!bkpinfo->isodir[0]) {
     449    strcpy(bkpinfo->isodir, "/tmp/isodir");
     450}
    451451/* End patch */
    452         sprintf(command, "mkdir -p %s", bkpinfo->isodir);
    453         run_program_and_log_output(command, 5);
    454         log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
    455     }
    456 
    457     if (!get_isodir_info
    458         (g_isodir_device, g_isodir_format, bkpinfo->isodir,
    459         nuke_me_please)) {
    460         return (1);
    461     }
    462     paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
    463 
    464     if (is_this_device_mounted(g_isodir_device)) {
    465         log_to_screen("WARNING - isodir is already mounted");
    466         already_mounted = TRUE;
    467     } else {
    468         sprintf(mount_isodir_command, "mount %s", g_isodir_device);
    469         if (strlen(g_isodir_format) > 1) {
    470             sprintf(mount_isodir_command + strlen(mount_isodir_command),
    471                     " -t %s", g_isodir_format);
    472         }
    473         strcat(mount_isodir_command, " -o ro ");
    474         strcat(mount_isodir_command, bkpinfo->isodir);
    475         run_program_and_log_output("df -m", FALSE);
    476         sprintf(tmp,
    477                 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
    478                 mount_isodir_command);
    479         log_msg(1, tmp);
    480         if (run_program_and_log_output(mount_isodir_command, FALSE)) {
    481             popup_and_OK
    482                 ("Cannot mount the device where the ISO files are stored.");
    483             return (1);
    484         }
    485         log_to_screen
    486             ("I have mounted the device where the ISO files are stored.");
    487     }
    488     if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    489         mount_cdrom(bkpinfo);
    490     }
    491     i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
    492     sprintf(tmp, "%s #%d has been mounted via loopback mount",
    493             media_descriptor_string(bkpinfo->backup_media_type), i);
    494     log_msg(1, tmp);
    495     if (i < 0) {
    496         popup_and_OK
    497             ("Cannot find ISO images in the directory you specified.");
    498         retval = 1;
    499     }
    500     log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
    501             bkpinfo->isodir);
    502     paranoid_free(mount_isodir_command);
    503     paranoid_free(tmp);
    504     paranoid_free(command);
    505     return (retval);
    506 }
    507 
    508 
    509 
    510 
    511 /**
    512  * Kill all Petris processes.
    513  */
     452sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     453run_program_and_log_output(command, 5);
     454log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
     455}
     456
     457if (!get_isodir_info
     458(g_isodir_device, g_isodir_format, bkpinfo->isodir,
     459 nuke_me_please)) {
     460return (1);
     461}
     462paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
     463
     464if (is_this_device_mounted(g_isodir_device)) {
     465log_to_screen("WARNING - isodir is already mounted");
     466already_mounted = TRUE;
     467} else {
     468sprintf(mount_isodir_command, "mount %s", g_isodir_device);
     469if (strlen(g_isodir_format) > 1) {
     470    sprintf(mount_isodir_command + strlen(mount_isodir_command),
     471            " -t %s", g_isodir_format);
     472}
     473strcat(mount_isodir_command, " -o ro ");
     474strcat(mount_isodir_command, bkpinfo->isodir);
     475run_program_and_log_output("df -m", FALSE);
     476sprintf(tmp,
     477        "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
     478        mount_isodir_command);
     479log_msg(1, tmp);
     480if (run_program_and_log_output(mount_isodir_command, FALSE)) {
     481    popup_and_OK
     482        ("Cannot mount the device where the ISO files are stored.");
     483    return (1);
     484}
     485log_to_screen
     486    ("I have mounted the device where the ISO files are stored.");
     487}
     488if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     489mount_cdrom(bkpinfo);
     490}
     491i = what_number_cd_is_this(bkpinfo);    /* has the side-effect of calling mount_cdrom() */
     492sprintf(tmp, "%s #%d has been mounted via loopback mount",
     493    media_descriptor_string(bkpinfo->backup_media_type), i);
     494log_msg(1, tmp);
     495if (i < 0) {
     496popup_and_OK
     497    ("Cannot find ISO images in the directory you specified.");
     498retval = 1;
     499}
     500log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
     501    bkpinfo->isodir);
     502paranoid_free(mount_isodir_command);
     503paranoid_free(tmp);
     504paranoid_free(command);
     505return (retval);
     506}
     507
     508
     509
     510
     511/**
     512* Kill all Petris processes.
     513*/
    514514void kill_petris(void)
    515515{
    516     char *command;
    517     malloc_string(command);
    518     sprintf(command,
    519             "kill `ps 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
    520     paranoid_system(command);
    521     paranoid_free(command);
     516char *command;
     517malloc_string(command);
     518sprintf(command,
     519    "kill `ps 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null");
     520paranoid_system(command);
     521paranoid_free(command);
    522522}
    523523
    524524/**************************************************************************
    525  *END_KILL_PETRIS                                                         *
    526  **************************************************************************/
    527 
    528 
    529 /**
    530  * (Disabled) Modify rc.local to fix some things on first boot.
    531  * This function currently doesn't do anything except make sure /tmp has the
    532  * right permissions.
    533  * @param path The path to /etc on the user's filesystem.
    534  * @return 0 for success, nonzero for failure.
    535  */
     525*END_KILL_PETRIS                                                         *
     526**************************************************************************/
     527
     528
     529/**
     530* (Disabled) Modify rc.local to fix some things on first boot.
     531* This function currently doesn't do anything except make sure /tmp has the
     532* right permissions.
     533* @param path The path to /etc on the user's filesystem.
     534* @return 0 for success, nonzero for failure.
     535*/
    536536int modify_rclocal_one_time(char *path)
    537537{
    538   /** malloc **/
    539     char *rclocal_fname;
    540     char *newfile_fname;
    541     char *tmp;
    542 
    543     malloc_string(rclocal_fname);
    544     malloc_string(newfile_fname);
    545     malloc_string(tmp);
    546     assert_string_is_neither_NULL_nor_zerolength(path);
    547 
    548     sprintf(rclocal_fname, "%s/rc.local", path);
     538/** malloc **/
     539char *rclocal_fname;
     540char *newfile_fname;
     541char *tmp;
     542
     543malloc_string(rclocal_fname);
     544malloc_string(newfile_fname);
     545malloc_string(tmp);
     546assert_string_is_neither_NULL_nor_zerolength(path);
     547
     548sprintf(rclocal_fname, "%s/rc.local", path);
    549549
    550550//  sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);
    551551//  run_program_and_log_output( tmp, FALSE );
    552     return (0);                 /* remove this line to open the floodgates... */
    553 
    554     if (!does_file_exist(rclocal_fname)) {
    555         sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
    556     }
    557     if (!does_file_exist(rclocal_fname)) {
    558         paranoid_free(rclocal_fname);
    559         paranoid_free(newfile_fname);
    560         paranoid_free(tmp);
    561         return (1);
    562     }
    563     sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
    564     sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null",
    565             rclocal_fname);
    566     if (system(tmp)) {
    567         sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
    568                 newfile_fname, newfile_fname, rclocal_fname);
    569 
    570         paranoid_system(tmp);
    571     }
    572     sprintf(tmp, "echo -en \"#!/bin/sh\
     552return (0);                 /* remove this line to open the floodgates... */
     553
     554if (!does_file_exist(rclocal_fname)) {
     555sprintf(rclocal_fname, "%s/rc.d/rc.local", path);
     556}
     557if (!does_file_exist(rclocal_fname)) {
     558paranoid_free(rclocal_fname);
     559paranoid_free(newfile_fname);
     560paranoid_free(tmp);
     561return (1);
     562}
     563sprintf(newfile_fname, "%s/rc.local.mondorescue", path);
     564sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null",
     565    rclocal_fname);
     566if (system(tmp)) {
     567sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",
     568        newfile_fname, newfile_fname, rclocal_fname);
     569
     570paranoid_system(tmp);
     571}
     572sprintf(tmp, "echo -en \"#!/bin/sh\
    573573\\n\
    574574\\n\
     
    580580yes | rm -f %s\\n\
    581581\" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);
    582     sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
    583     run_program_and_log_output(tmp, FALSE);
    584     paranoid_free(rclocal_fname);
    585     paranoid_free(newfile_fname);
    586     paranoid_free(tmp);
    587     return (0);
     582sprintf(tmp, "chmod +x \"%s\"", newfile_fname);
     583run_program_and_log_output(tmp, FALSE);
     584paranoid_free(rclocal_fname);
     585paranoid_free(newfile_fname);
     586paranoid_free(tmp);
     587return (0);
    588588}
    589589
    590590/**************************************************************************
    591  *END_ MODIFY_RCLOCAL_ONE_TIME                                            *
    592  **************************************************************************/
    593 
    594 
    595 
    596 
    597 
    598 /**
    599  * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
    600  * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
    601  * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
    602  * @return The number of errors encountered (0 for success).
     591*END_ MODIFY_RCLOCAL_ONE_TIME                                            *
     592**************************************************************************/
     593
     594
     595
     596
     597
     598/**
     599* Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
     600* @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
     601* @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
     602* @return The number of errors encountered (0 for success).
     603*/
     604int mount_all_devices(struct mountlist_itself
     605              *p_external_copy_of_mountlist, bool writeable)
     606{
     607int retval = 0, lino, res;
     608char *tmp, *these_failed, *format;
     609struct mountlist_itself *mountlist;
     610
     611malloc_string(tmp);
     612malloc_string(format);
     613malloc_string(these_failed);
     614assert(p_external_copy_of_mountlist != NULL);
     615mountlist = malloc(sizeof(struct mountlist_itself));
     616memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
     617   sizeof(struct mountlist_itself));
     618sort_mountlist_by_mountpoint(mountlist, 0);
     619
     620/** menset **/
     621these_failed[0] = '\0';
     622
     623mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
     624open_progress_form("Mounting devices",
     625               "I am now mounting all the drives.",
     626               "This should not take long.",
     627               "", mountlist->entries);
     628
     629for (lino = 0; lino < mountlist->entries; lino++) {
     630if (!strcmp(mountlist->el[lino].device, "/proc")) {
     631    log_msg(1,
     632            "Again with the /proc - why is this in your mountlist?");
     633} else if (is_this_device_mounted(mountlist->el[lino].device)) {
     634    sprintf(tmp, "%s is already mounted",
     635            mountlist->el[lino].device);
     636    log_to_screen(tmp);
     637} else if (strcmp(mountlist->el[lino].mountpoint, "none")
     638           && strcmp(mountlist->el[lino].mountpoint, "lvm")
     639           && strcmp(mountlist->el[lino].mountpoint, "raid")
     640           && strcmp(mountlist->el[lino].mountpoint, "image")) {
     641    sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
     642    update_progress_form(tmp);
     643    strcpy(format, mountlist->el[lino].format);
     644    if (!strcmp(format, "ext3")) {
     645        strcpy(format, "ext2");
     646    }
     647    res = mount_device(mountlist->el[lino].device,
     648                       mountlist->el[lino].mountpoint,
     649                       format, writeable);
     650    retval += res;
     651    if (res) {
     652        strcat(these_failed, mountlist->el[lino].device);
     653        strcat(these_failed, " ");
     654    }
     655}
     656g_current_progress++;
     657}
     658close_progress_form();
     659run_program_and_log_output("df -m", TRUE);
     660if (retval) {
     661if (g_partition_table_locked_up > 0) {
     662    log_to_screen
     663        ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
     664    log_to_screen
     665        ("lock up the partition table. You might have to reboot and use Interactive Mode to");
     666    log_to_screen
     667        ("format and restore *without* partitioning first. Sorry for the inconvenience.");
     668}
     669sprintf(tmp, "Could not mount devices %s- shall I abort?",
     670        these_failed);
     671if (!ask_me_yes_or_no(tmp)) {
     672    retval = 0;
     673    log_to_screen
     674        ("Continuing, although some devices failed to be mounted");
     675    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     676} else {
     677    mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     678    log_to_screen
     679        ("Unable to mount some or all of your partitions.");
     680}
     681} else {
     682log_to_screen("All partitions were mounted OK.");
     683mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     684}
     685run_program_and_log_output("df -m", 3);
     686paranoid_free(mountlist);
     687paranoid_free(tmp);
     688paranoid_free(format);
     689paranoid_free(these_failed);
     690return (retval);
     691}
     692
     693/**************************************************************************
     694*END_MOUNT_ALL_DEVICES                                                   *
     695**************************************************************************/
     696
     697
     698/**
     699* Mount the CD-ROM device at /mnt/cdrom.
     700* @param bkpinfo The backup information structure. Fields used:
     701* - @c bkpinfo->backup_media_type
     702* - @c bkpinfo->disaster_recovery
     703* - @c bkpinfo->isodir
     704* - @c bkpinfo->media_device
     705* @return 0 for success, nonzero for failure.
     706*/
     707int mount_cdrom(struct s_bkpinfo *bkpinfo)
     708{
     709char *mount_cmd;
     710int i, res;
     711#ifdef __FreeBSD__
     712char mdd[32];
     713char *mddev = mdd;
     714#endif
     715
     716malloc_string(mount_cmd);
     717assert(bkpinfo != NULL);
     718
     719if (bkpinfo->backup_media_type == tape
     720|| bkpinfo->backup_media_type == udev) {
     721log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
     722paranoid_free(mount_cmd);
     723return 0;
     724}
     725
     726if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
     727log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
     728paranoid_free(mount_cmd);
     729return (0);
     730}
     731
     732if (bkpinfo->backup_media_type == nfs) {
     733log_msg(2, "Mounting for NFS thingy");
     734log_msg(2, "isodir = %s", bkpinfo->isodir);
     735if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
     736    && am_I_in_disaster_recovery_mode()) {
     737    strcpy(bkpinfo->isodir, "/tmp/isodir");
     738    log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
     739}
     740#ifdef __FreeBSD__
     741sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
     742        bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number);
     743mddev = make_vn(mount_cmd);
     744sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     745#else
     746sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
     747        bkpinfo->isodir, bkpinfo->nfs_remote_dir,
     748        bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     749#endif
     750
     751} else
     752if (bkpinfo->backup_media_type == iso) {
     753#ifdef __FreeBSD__
     754sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
     755        bkpinfo->prefix, g_current_media_number);
     756mddev = make_vn(mount_cmd);
     757sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     758#else
     759sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
     760        bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     761#endif
     762} else if (strstr(bkpinfo->media_device, "/dev/"))
     763#ifdef __FreeBSD__
     764{
     765sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     766        MNT_CDROM);
     767}
     768#else
     769{
     770sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     771        bkpinfo->media_device, MNT_CDROM);
     772}
     773#endif
     774
     775else {
     776if (bkpinfo->disaster_recovery
     777    && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
     778    strcpy(bkpinfo->media_device,
     779           last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     780} else {
     781    find_cdrom_device(bkpinfo->media_device, TRUE);
     782}
     783
     784#ifdef __FreeBSD__
     785sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
     786        MNT_CDROM);
     787#else
     788sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
     789        bkpinfo->media_device, MNT_CDROM);
     790#endif
     791
     792}
     793log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
     794for (i = 0; i < 2; i++) {
     795res = run_program_and_log_output(mount_cmd, FALSE);
     796if (!res) {
     797    break;
     798} else {
     799    log_msg(2, "Failed to mount CD-ROM drive.");
     800    sleep(5);
     801    run_program_and_log_output("sync", FALSE);
     802}
     803}
     804if (res) {
     805log_msg(2, "Failed, despite %d attempts", i);
     806} else {
     807log_msg(2, "Mounted CD-ROM drive OK");
     808}
     809paranoid_free(mount_cmd);
     810return (res);
     811}
     812
     813
     814
     815
     816
     817/**************************************************************************
     818*END_MOUNT_CDROM                                                         *
     819**************************************************************************/
     820
     821
     822/**
     823* Mount @p device at @p mpt as @p format.
     824* @param device The device (/dev entry) to mount.
     825* @param mpt The directory to mount it on.
     826* @param format The filesystem type of @p device.
     827* @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
     828* @return 0 for success, nonzero for failure.
     829*/
     830int mount_device(char *device, char *mpt, char *format, bool writeable)
     831{
     832int res = 0;
     833
     834/** malloc **/
     835char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     836
     837assert_string_is_neither_NULL_nor_zerolength(device);
     838assert_string_is_neither_NULL_nor_zerolength(mpt);
     839assert(format != NULL);
     840malloc_string(tmp);
     841malloc_string(command);
     842malloc_string(mountdir);
     843malloc_string(mountpoint);
     844malloc_string(additional_parameters);
     845
     846if (!strcmp(mpt, "/1")) {
     847strcpy(mountpoint, "/");
     848log_msg(3, "Mommm! SME is being a dildo!");
     849} else {
     850strcpy(mountpoint, mpt);
     851}
     852
     853if (!strcmp(mountpoint, "lvm")) {
     854return (0);
     855}
     856if (!strcmp(mountpoint, "image")) {
     857return (0);
     858}
     859sprintf(tmp, "Mounting device %s   ", device);
     860log_msg(1, tmp);
     861if (writeable) {
     862strcpy(additional_parameters, "-o rw");
     863} else {
     864strcpy(additional_parameters, "-o ro");
     865}
     866if (find_home_of_exe("setfattr")) {
     867strcat(additional_parameters, ",user_xattr");
     868}
     869if (find_home_of_exe("setfacl")) {
     870strcat(additional_parameters, ",acl");
     871}
     872
     873if (!strcmp(mountpoint, "swap")) {
     874sprintf(command, "swapon %s", device);
     875} else {
     876if (!strcmp(mountpoint, "/")) {
     877    strcpy(mountdir, MNT_RESTORING);
     878} else {
     879    sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
     880}
     881sprintf(command, "mkdir -p %s", mountdir);
     882run_program_and_log_output(command, FALSE);
     883sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
     884        additional_parameters, mountdir, MONDO_LOGFILE);
     885log_msg(2, "command='%s'", command);
     886}
     887res = run_program_and_log_output(command, TRUE);
     888if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
     889log_msg(1, "Re-trying without the fancy extra parameters");
     890sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
     891        mountdir, MONDO_LOGFILE);
     892res = run_program_and_log_output(command, TRUE);
     893}
     894if (res) {
     895log_msg(1, "Unable to mount device %s (type %s) at %s", device,
     896        format, mountdir);
     897log_msg(1, "command was '%s'", command);
     898if (!strcmp(mountpoint, "swap")) {
     899    log_to_screen(tmp);
     900} else {
     901    log_msg(2, "Retrying w/o the '-t' switch");
     902    sprintf(command, "mount %s %s 2>> %s", device, mountdir,
     903            MONDO_LOGFILE);
     904    log_msg(2, "2nd command = '%s'", command);
     905    res = run_program_and_log_output(command, TRUE);
     906    if (res == 0) {
     907        log_msg(1,
     908                "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
     909    } else {
     910        log_to_screen(tmp);
     911    }
     912}
     913}
     914if (res && !strcmp(mountpoint, "swap")) {
     915log_msg(2, "That's ok. It's just a swap partition.");
     916log_msg(2, "Non-fatal error. Returning 0.");
     917res = 0;
     918}
     919
     920paranoid_free(tmp);
     921paranoid_free(command);
     922paranoid_free(mountdir);
     923paranoid_free(mountpoint);
     924paranoid_free(additional_parameters);
     925
     926return (res);
     927}
     928
     929/**************************************************************************
     930*END_MOUNT_DEVICE                                                        *
     931**************************************************************************/
     932
     933
     934
     935/**
     936* Fix some miscellaneous things in the filesystem so the system will come
     937* up correctly on the first boot.
     938*/
     939void protect_against_braindead_sysadmins()
     940{
     941run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
     942                       FALSE);
     943run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
     944                       FALSE);
     945if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
     946run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
     947                           FALSE);
     948}
     949run_program_and_log_output("mkdir -p " MNT_RESTORING
     950                       "/var/run/console", FALSE);
     951run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
     952                       FALSE);
     953run_program_and_log_output("cd " MNT_RESTORING
     954                       "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done",
     955                       TRUE);
     956run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
     957                       TRUE);
     958run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
     959                       TRUE);
     960}
     961
     962/**************************************************************************
     963*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
     964**************************************************************************/
     965
     966
     967
     968
     969/**
     970* Fill out @p bkpinfo based on @p cfg_file.
     971* @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
     972* @param bkpinfo The backup information structure to fill out with information
     973* from @p cfg_file.
     974* @return 0 for success, nonzero for failure.
     975*/
     976int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
     977{
     978/** add mallocs **/
     979char *value = NULL;
     980char *tmp = NULL;
     981char *envtmp1 = NULL;
     982char *envtmp2 = NULL;
     983char *command = NULL;
     984char *iso_mnt = NULL;
     985char *iso_path = NULL;
     986char *old_isodir = NULL;
     987char cfg_file[100];
     988t_bkptype media_specified_by_user;
     989
     990malloc_string(command);
     991malloc_string(iso_mnt);
     992malloc_string(iso_path);
     993malloc_string(old_isodir);
     994malloc_string(value);
     995malloc_string(tmp);
     996//  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
     997assert(bkpinfo != NULL);
     998
     999if (!cfgf) {
     1000strcpy(cfg_file, g_mondo_cfg_file);
     1001} else {
     1002strcpy(cfg_file, cfgf);
     1003}
     1004
     1005media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
     1006
     1007if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
     1008if (!strcmp(value, "cdstream")) {
     1009    bkpinfo->backup_media_type = cdstream;
     1010} else if (!strcmp(value, "cdr")) {
     1011    bkpinfo->backup_media_type = cdr;
     1012} else if (!strcmp(value, "cdrw")) {
     1013    bkpinfo->backup_media_type = cdrw;
     1014} else if (!strcmp(value, "dvd")) {
     1015    bkpinfo->backup_media_type = dvd;
     1016} else if (!strcmp(value, "iso")) {
     1017/*
     1018if (am_I_in_disaster_recovery_mode()
     1019&& !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
     1020&& does_file_exist(MNT_CDROM"/archives/filelist.0"))
     1021*/
     1022
     1023// Patch by Conor Daly - 2004/07/12
     1024    bkpinfo->backup_media_type = iso;
     1025    if (am_I_in_disaster_recovery_mode()) {
     1026        /* Check to see if CD is already mounted before mounting it... */
     1027        if (!is_this_device_mounted("/dev/cdrom")) {
     1028            log_msg(2,
     1029                    "NB: CDROM device not mounted, mounting...");
     1030            run_program_and_log_output("mount /dev/cdrom "
     1031                                       MNT_CDROM, 1);
     1032        }
     1033        if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
     1034            bkpinfo->backup_media_type = cdr;
     1035            run_program_and_log_output("umount " MNT_CDROM, 1);
     1036            log_it
     1037                ("Re-jigging configuration AGAIN. CD-R, not ISO.");
     1038        }
     1039    }
     1040    if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
     1041            strcpy(bkpinfo->prefix,value);
     1042    } else {
     1043            strcpy(bkpinfo->prefix,STD_PREFIX);
     1044    }
     1045} else if (!strcmp(value, "nfs")) {
     1046    bkpinfo->backup_media_type = nfs;
     1047    if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
     1048            strcpy(bkpinfo->prefix,value);
     1049    } else {
     1050            strcpy(bkpinfo->prefix,STD_PREFIX);
     1051    }
     1052    if (strstr(call_program_and_get_last_line_of_output
     1053       ("cat /proc/cmdline"), "pxe")) {
     1054        /* We need to override prefix value in PXE mode as it's
     1055        * already done in start-nfs */
     1056        envtmp1 = getenv("imgname");
     1057        if (envtmp1 == NULL) {
     1058            fatal_error("no imgname variable in environment");
     1059        }
     1060        strcpy(bkpinfo->prefix,envtmp1);
     1061    }
     1062
     1063} else if (!strcmp(value, "tape")) {
     1064    bkpinfo->backup_media_type = tape;
     1065} else if (!strcmp(value, "udev")) {
     1066    bkpinfo->backup_media_type = udev;
     1067} else {
     1068    fatal_error("UNKNOWN bkp-media-type");
     1069}
     1070} else {
     1071fatal_error("backup-media-type not specified!");
     1072}
     1073if (bkpinfo->disaster_recovery) {
     1074if (bkpinfo->backup_media_type == cdstream) {
     1075    sprintf(bkpinfo->media_device, "/dev/cdrom");
     1076//          bkpinfo->media_size[0] = -1;
     1077    bkpinfo->media_size[0] = 1999 * 1024;
     1078    bkpinfo->media_size[1] = 650;   /* good guess */
     1079} else if (bkpinfo->backup_media_type == tape
     1080           || bkpinfo->backup_media_type == udev) {
     1081    if (read_cfg_var(cfg_file, "media-dev", value)) {
     1082        fatal_error("Cannot get tape device name from cfg file");
     1083    }
     1084    strcpy(bkpinfo->media_device, value);
     1085    read_cfg_var(cfg_file, "media-size", value);
     1086    bkpinfo->media_size[1] = atol(value);
     1087    sprintf(tmp, "Backup medium is TAPE --- dev=%s",
     1088            bkpinfo->media_device);
     1089    log_msg(2, tmp);
     1090} else {
     1091    strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     1092    bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1093    bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
     1094    log_msg(2, "Backup medium is CD-R[W]");
     1095}
     1096} else {
     1097log_msg(2,
     1098        "Not in Disaster Recovery Mode. No need to derive device name from config file.");
     1099}
     1100
     1101read_cfg_var(cfg_file, "use-star", value);
     1102if (strstr(value, "yes")) {
     1103bkpinfo->use_star = TRUE;
     1104log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
     1105}
     1106
     1107read_cfg_var(cfg_file, "acl", value);
     1108if (strstr(value, "TRUE")) {
     1109asprintf(&g_getfacl,"setfacl");
     1110log_msg(1, "We will restore ACLs");
     1111if (! find_home_of_exe("setfacl")) {
     1112    log_msg(1, "Unable to restore ACLs as no setfacl found");
     1113}
     1114}
     1115read_cfg_var(cfg_file, "xattr", value);
     1116if (strstr(value, "TRUE")) {
     1117asprintf(&g_getfattr,"setfattr");
     1118log_msg(1, "We will restore XATTRs");
     1119if (! find_home_of_exe("setfattr")) {
     1120    log_msg(1, "Unable to restore XATTRs as no setfattr found");
     1121}
     1122}
     1123
     1124if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
     1125bkpinfo->internal_tape_block_size = atol(value);
     1126log_msg(1, "Internal tape block size has been custom-set to %ld",
     1127        bkpinfo->internal_tape_block_size);
     1128} else {
     1129bkpinfo->internal_tape_block_size =
     1130    DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     1131log_msg(1, "Internal tape block size = default (%ld)",
     1132        DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
     1133}
     1134
     1135read_cfg_var(cfg_file, "use-lzo", value);
     1136if (strstr(value, "yes")) {
     1137bkpinfo->use_lzo = TRUE;
     1138bkpinfo->use_gzip = FALSE;
     1139strcpy(bkpinfo->zip_exe, "lzop");
     1140strcpy(bkpinfo->zip_suffix, "lzo");
     1141} else {
     1142read_cfg_var(cfg_file, "use-gzip", value);
     1143if (strstr(value, "yes")) {
     1144    bkpinfo->use_lzo = FALSE;
     1145    bkpinfo->use_gzip = TRUE;
     1146    strcpy(bkpinfo->zip_exe, "gzip");
     1147    strcpy(bkpinfo->zip_suffix, "gz");
     1148} else {
     1149    read_cfg_var(cfg_file, "use-comp", value);
     1150    if (strstr(value, "yes")) {
     1151        bkpinfo->use_lzo = FALSE;
     1152        bkpinfo->use_gzip = FALSE;
     1153        strcpy(bkpinfo->zip_exe, "bzip2");
     1154        strcpy(bkpinfo->zip_suffix, "bz2");
     1155    } else {
     1156        bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     1157    }
     1158}
     1159}
     1160
     1161value[0] = '\0';
     1162read_cfg_var(cfg_file, "differential", value);
     1163if (!strcmp(value, "yes") || !strcmp(value, "1")) {
     1164bkpinfo->differential = TRUE;
     1165}
     1166log_msg(2, "differential var = '%s'", value);
     1167if (bkpinfo->differential) {
     1168log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
     1169} else {
     1170log_msg(2, "This is a regular (full) backup");
     1171}
     1172
     1173read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
     1174if (tmp[0]
     1175||
     1176strstr(call_program_and_get_last_line_of_output
     1177       ("cat /proc/cmdline"), "donteject")) {
     1178bkpinfo->please_dont_eject = TRUE;
     1179log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
     1180}
     1181
     1182if (bkpinfo->backup_media_type == nfs) {
     1183if (!cfgf) {
     1184    log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
     1185    log_msg(2, "nfs_remote_dir remains %s",
     1186            bkpinfo->nfs_remote_dir);
     1187    log_msg(2,
     1188            "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
     1189} else {
     1190    read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
     1191                 bkpinfo->nfs_mount);
     1192    read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
     1193                 bkpinfo->nfs_remote_dir);
     1194    log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
     1195    log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
     1196}
     1197if (strstr(call_program_and_get_last_line_of_output
     1198   ("cat /proc/cmdline"), "pxe")) {
     1199    /* We need to override values in PXE mode as it's
     1200    * already done in start-nfs */
     1201    envtmp1 = getenv("nfsmount");
     1202    if (envtmp1 == NULL) {
     1203        fatal_error("no nfsmount variable in environment");
     1204    }
     1205    envtmp2 = getenv("dirimg");
     1206    if (envtmp2 == NULL) {
     1207        fatal_error("no dirimg variable in environment");
     1208    }
     1209    strcpy(bkpinfo->nfs_mount,envtmp1);
     1210    strcpy(bkpinfo->nfs_remote_dir,envtmp2);
     1211}
     1212} else if (bkpinfo->backup_media_type == iso) {
     1213/* Patch by Conor Daly 23-june-2004
     1214 * to correctly mount iso-dev and set a sensible
     1215 * isodir in disaster recovery mode
    6031216 */
    604 int mount_all_devices(struct mountlist_itself
    605                       *p_external_copy_of_mountlist, bool writeable)
    606 {
    607     int retval = 0, lino, res;
    608     char *tmp, *these_failed, *format;
    609     struct mountlist_itself *mountlist;
    610 
    611     malloc_string(tmp);
    612     malloc_string(format);
    613     malloc_string(these_failed);
    614     assert(p_external_copy_of_mountlist != NULL);
    615     mountlist = malloc(sizeof(struct mountlist_itself));
    616     memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
    617            sizeof(struct mountlist_itself));
    618     sort_mountlist_by_mountpoint(mountlist, 0);
    619 
    620   /** menset **/
    621     these_failed[0] = '\0';
    622 
    623     mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
    624     open_progress_form("Mounting devices",
    625                        "I am now mounting all the drives.",
    626                        "This should not take long.",
    627                        "", mountlist->entries);
    628 
    629     for (lino = 0; lino < mountlist->entries; lino++) {
    630         if (!strcmp(mountlist->el[lino].device, "/proc")) {
     1217strcpy(old_isodir, bkpinfo->isodir);
     1218read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
     1219read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
     1220sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1221if (!bkpinfo->isodir[0]) {
     1222    strcpy(bkpinfo->isodir, old_isodir);
     1223}
     1224if (!bkpinfo->disaster_recovery) {
     1225    if (strcmp(old_isodir, bkpinfo->isodir)) {
     1226        log_it
     1227            ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
     1228             old_isodir, bkpinfo->isodir);
     1229        strcpy(bkpinfo->isodir, old_isodir);
     1230    }
     1231}
     1232read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
     1233log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
     1234        g_isodir_device);
     1235if (bkpinfo->disaster_recovery) {
     1236    if (is_this_device_mounted(g_isodir_device)) {
     1237        log_msg(2, "NB: isodir is already mounted");
     1238        /* Find out where it's mounted */
     1239        sprintf(command,
     1240                "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3",
     1241                g_isodir_device);
     1242        log_it("command = %s", command);
     1243        log_it("res of it = %s",
     1244               call_program_and_get_last_line_of_output(command));
     1245        sprintf(iso_mnt, "%s",
     1246                call_program_and_get_last_line_of_output(command));
     1247    } else {
     1248        sprintf(iso_mnt, "/tmp/isodir");
     1249        sprintf(tmp, "mkdir -p %s", iso_mnt);
     1250        run_program_and_log_output(tmp, 5);
     1251        sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
     1252        if (run_program_and_log_output(tmp, 3)) {
    6311253            log_msg(1,
    632                     "Again with the /proc - why is this in your mountlist?");
    633         } else if (is_this_device_mounted(mountlist->el[lino].device)) {
    634             sprintf(tmp, "%s is already mounted",
    635                     mountlist->el[lino].device);
    636             log_to_screen(tmp);
    637         } else if (strcmp(mountlist->el[lino].mountpoint, "none")
    638                    && strcmp(mountlist->el[lino].mountpoint, "lvm")
    639                    && strcmp(mountlist->el[lino].mountpoint, "raid")
    640                    && strcmp(mountlist->el[lino].mountpoint, "image")) {
    641             sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
    642             update_progress_form(tmp);
    643             strcpy(format, mountlist->el[lino].format);
    644             if (!strcmp(format, "ext3")) {
    645                 strcpy(format, "ext2");
     1254                    "Unable to mount isodir. Perhaps this is really a CD backup?");
     1255            bkpinfo->backup_media_type = cdr;
     1256            strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
     1257            bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
     1258            if (mount_cdrom(bkpinfo)) {
     1259                fatal_error
     1260                    ("Unable to mount isodir. Failed to mount CD-ROM as well.");
     1261            } else {
     1262                log_msg(1,
     1263                        "You backed up to disk, then burned some CDs.");
    6461264            }
    647             res = mount_device(mountlist->el[lino].device,
    648                                mountlist->el[lino].mountpoint,
    649                                format, writeable);
    650             retval += res;
    651             if (res) {
    652                 strcat(these_failed, mountlist->el[lino].device);
    653                 strcat(these_failed, " ");
    654             }
    655         }
    656         g_current_progress++;
    657     }
    658     close_progress_form();
    659     run_program_and_log_output("df -m", TRUE);
    660     if (retval) {
    661         if (g_partition_table_locked_up > 0) {
    662             log_to_screen
    663                 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
    664             log_to_screen
    665                 ("lock up the partition table. You might have to reboot and use Interactive Mode to");
    666             log_to_screen
    667                 ("format and restore *without* partitioning first. Sorry for the inconvenience.");
    668         }
    669         sprintf(tmp, "Could not mount devices %s- shall I abort?",
    670                 these_failed);
    671         if (!ask_me_yes_or_no(tmp)) {
    672             retval = 0;
    673             log_to_screen
    674                 ("Continuing, although some devices failed to be mounted");
    675             mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    676         } else {
    677             mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
    678             log_to_screen
    679                 ("Unable to mount some or all of your partitions.");
    680         }
    681     } else {
    682         log_to_screen("All partitions were mounted OK.");
    683         mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    684     }
    685     run_program_and_log_output("df -m", 3);
    686     paranoid_free(mountlist);
    687     paranoid_free(tmp);
    688     paranoid_free(format);
    689     paranoid_free(these_failed);
    690     return (retval);
    691 }
    692 
    693  /**************************************************************************
    694   *END_MOUNT_ALL_DEVICES                                                   *
    695   **************************************************************************/
    696 
    697 
    698 /**
    699  * Mount the CD-ROM device at /mnt/cdrom.
    700  * @param bkpinfo The backup information structure. Fields used:
    701  * - @c bkpinfo->backup_media_type
    702  * - @c bkpinfo->disaster_recovery
    703  * - @c bkpinfo->isodir
    704  * - @c bkpinfo->media_device
    705  * @return 0 for success, nonzero for failure.
    706  */
    707 int mount_cdrom(struct s_bkpinfo *bkpinfo)
    708 {
    709     char *mount_cmd;
    710     int i, res;
    711 #ifdef __FreeBSD__
    712     char mdd[32];
    713     char *mddev = mdd;
    714 #endif
    715 
    716     malloc_string(mount_cmd);
    717     assert(bkpinfo != NULL);
    718 
    719     if (bkpinfo->backup_media_type == tape
    720         || bkpinfo->backup_media_type == udev) {
    721         log_msg(8, "Tape/udev. Therefore, no need to mount CDROM.");
    722         paranoid_free(mount_cmd);
    723         return 0;
    724     }
    725 
    726     if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
    727         log_msg(2, "mount_cdrom() - CD already mounted. Fair enough.");
    728         paranoid_free(mount_cmd);
    729         return (0);
    730     }
    731 
    732     if (bkpinfo->backup_media_type == nfs) {
    733         log_msg(2, "Mounting for NFS thingy");
    734         log_msg(2, "isodir = %s", bkpinfo->isodir);
    735         if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    736             && am_I_in_disaster_recovery_mode()) {
    737             strcpy(bkpinfo->isodir, "/tmp/isodir");
    738             log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    739         }
    740 #ifdef __FreeBSD__
    741         sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
    742                 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number);
    743         mddev = make_vn(mount_cmd);
    744         sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    745 #else
    746         sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
    747                 bkpinfo->isodir, bkpinfo->nfs_remote_dir,
    748                 bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    749 #endif
    750 
    751     } else
    752      if (bkpinfo->backup_media_type == iso) {
    753 #ifdef __FreeBSD__
    754         sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
    755                 bkpinfo->prefix, g_current_media_number);
    756         mddev = make_vn(mount_cmd);
    757         sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    758 #else
    759         sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
    760                 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    761 #endif
    762     } else if (strstr(bkpinfo->media_device, "/dev/"))
    763 #ifdef __FreeBSD__
    764     {
    765         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    766                 MNT_CDROM);
    767     }
    768 #else
    769     {
    770         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    771                 bkpinfo->media_device, MNT_CDROM);
    772     }
    773 #endif
    774 
    775     else {
    776         if (bkpinfo->disaster_recovery
    777             && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    778             strcpy(bkpinfo->media_device,
    779                    last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    780         } else {
    781             find_cdrom_device(bkpinfo->media_device, TRUE);
    782         }
    783 
    784 #ifdef __FreeBSD__
    785         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    786                 MNT_CDROM);
    787 #else
    788         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    789                 bkpinfo->media_device, MNT_CDROM);
    790 #endif
    791 
    792     }
    793     log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd);
    794     for (i = 0; i < 2; i++) {
    795         res = run_program_and_log_output(mount_cmd, FALSE);
    796         if (!res) {
    797             break;
    798         } else {
    799             log_msg(2, "Failed to mount CD-ROM drive.");
    800             sleep(5);
    801             run_program_and_log_output("sync", FALSE);
    802         }
    803     }
    804     if (res) {
    805         log_msg(2, "Failed, despite %d attempts", i);
    806     } else {
    807         log_msg(2, "Mounted CD-ROM drive OK");
    808     }
    809     paranoid_free(mount_cmd);
    810     return (res);
    811 }
    812 
    813 
    814 
    815 
     1265        }
     1266    }
     1267    /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
     1268    if (bkpinfo->backup_media_type == iso) {
     1269        sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
     1270    }
     1271}
     1272}
     1273
     1274if (media_specified_by_user != none) {
     1275if (g_restoring_live_from_cd) {
     1276    if (bkpinfo->backup_media_type != media_specified_by_user) {
     1277        log_msg(2,
     1278                "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
     1279        interactively_obtain_media_parameters_from_user(bkpinfo,
     1280                                                        FALSE);
     1281        media_specified_by_user = bkpinfo->backup_media_type;
     1282        get_cfg_file_from_archive(bkpinfo);
     1283/*
     1284      if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
     1285        { g_restoring_live_from_cd = FALSE; }
     1286*/
     1287    }
     1288}
     1289bkpinfo->backup_media_type = media_specified_by_user;
     1290}
     1291g_backup_media_type = bkpinfo->backup_media_type;
     1292paranoid_free(value);
     1293paranoid_free(tmp);
     1294paranoid_free(command);
     1295paranoid_free(iso_mnt);
     1296paranoid_free(iso_path);
     1297paranoid_free(old_isodir);
     1298return (0);
     1299
     1300}
    8161301
    8171302/**************************************************************************
    818  *END_MOUNT_CDROM                                                         *
    819  **************************************************************************/
    820 
    821 
    822 /**
    823  * Mount @p device at @p mpt as @p format.
    824  * @param device The device (/dev entry) to mount.
    825  * @param mpt The directory to mount it on.
    826  * @param format The filesystem type of @p device.
    827  * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
    828  * @return 0 for success, nonzero for failure.
    829  */
    830 int mount_device(char *device, char *mpt, char *format, bool writeable)
    831 {
    832     int res = 0;
    833 
    834   /** malloc **/
    835     char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
    836 
    837     assert_string_is_neither_NULL_nor_zerolength(device);
    838     assert_string_is_neither_NULL_nor_zerolength(mpt);
    839     assert(format != NULL);
    840     malloc_string(tmp);
    841     malloc_string(command);
    842     malloc_string(mountdir);
    843     malloc_string(mountpoint);
    844     malloc_string(additional_parameters);
    845 
    846     if (!strcmp(mpt, "/1")) {
    847         strcpy(mountpoint, "/");
    848         log_msg(3, "Mommm! SME is being a dildo!");
    849     } else {
    850         strcpy(mountpoint, mpt);
    851     }
    852 
    853     if (!strcmp(mountpoint, "lvm")) {
    854         return (0);
    855     }
    856     if (!strcmp(mountpoint, "image")) {
    857         return (0);
    858     }
    859     sprintf(tmp, "Mounting device %s   ", device);
    860     log_msg(1, tmp);
    861     if (writeable) {
    862         strcpy(additional_parameters, "-o rw");
    863     } else {
    864         strcpy(additional_parameters, "-o ro");
    865     }
    866     if (find_home_of_exe("setfattr")) {
    867         strcat(additional_parameters, ",user_xattr");
    868     }
    869     if (find_home_of_exe("setfacl")) {
    870         strcat(additional_parameters, ",acl");
    871     }
    872 
    873     if (!strcmp(mountpoint, "swap")) {
    874         sprintf(command, "swapon %s", device);
    875     } else {
    876         if (!strcmp(mountpoint, "/")) {
    877             strcpy(mountdir, MNT_RESTORING);
    878         } else {
    879             sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
    880         }
    881         sprintf(command, "mkdir -p %s", mountdir);
    882         run_program_and_log_output(command, FALSE);
    883         sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
    884                 additional_parameters, mountdir, MONDO_LOGFILE);
    885         log_msg(2, "command='%s'", command);
    886     }
    887     res = run_program_and_log_output(command, TRUE);
    888     if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
    889         log_msg(1, "Re-trying without the fancy extra parameters");
    890         sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
    891                 mountdir, MONDO_LOGFILE);
    892         res = run_program_and_log_output(command, TRUE);
    893     }
    894     if (res) {
    895         log_msg(1, "Unable to mount device %s (type %s) at %s", device,
    896                 format, mountdir);
    897         log_msg(1, "command was '%s'", command);
    898         if (!strcmp(mountpoint, "swap")) {
    899             log_to_screen(tmp);
    900         } else {
    901             log_msg(2, "Retrying w/o the '-t' switch");
    902             sprintf(command, "mount %s %s 2>> %s", device, mountdir,
    903                     MONDO_LOGFILE);
    904             log_msg(2, "2nd command = '%s'", command);
    905             res = run_program_and_log_output(command, TRUE);
    906             if (res == 0) {
    907                 log_msg(1,
    908                         "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
    909             } else {
    910                 log_to_screen(tmp);
    911             }
    912         }
    913     }
    914     if (res && !strcmp(mountpoint, "swap")) {
    915         log_msg(2, "That's ok. It's just a swap partition.");
    916         log_msg(2, "Non-fatal error. Returning 0.");
    917         res = 0;
    918     }
    919 
    920     paranoid_free(tmp);
    921     paranoid_free(command);
    922     paranoid_free(mountdir);
    923     paranoid_free(mountpoint);
    924     paranoid_free(additional_parameters);
    925 
    926     return (res);
    927 }
    928 
    929 /**************************************************************************
    930  *END_MOUNT_DEVICE                                                        *
    931  **************************************************************************/
    932 
    933 
    934 
    935 /**
    936  * Fix some miscellaneous things in the filesystem so the system will come
    937  * up correctly on the first boot.
    938  */
    939 void protect_against_braindead_sysadmins()
    940 {
    941     run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
    942                                FALSE);
    943     run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
    944                                FALSE);
    945     if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
    946         run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
    947                                    FALSE);
    948     }
    949     run_program_and_log_output("mkdir -p " MNT_RESTORING
    950                                "/var/run/console", FALSE);
    951     run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
    952                                FALSE);
    953     run_program_and_log_output("cd " MNT_RESTORING
    954                                "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done",
    955                                TRUE);
    956     run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
    957                                TRUE);
    958     run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
    959                                TRUE);
    960 }
    961 
    962 /**************************************************************************
    963  *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
    964  **************************************************************************/
    965 
    966 
    967 
    968 
    969 /**
    970  * Fill out @p bkpinfo based on @p cfg_file.
    971  * @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
    972  * @param bkpinfo The backup information structure to fill out with information
    973  * from @p cfg_file.
    974  * @return 0 for success, nonzero for failure.
    975  */
    976 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo)
    977 {
    978   /** add mallocs **/
    979     char *value = NULL;
    980     char *tmp = NULL;
    981     char *envtmp1 = NULL;
    982     char *envtmp2 = NULL;
    983     char *command = NULL;
    984     char *iso_mnt = NULL;
    985     char *iso_path = NULL;
    986     char *old_isodir = NULL;
    987     char cfg_file[100];
    988     t_bkptype media_specified_by_user;
    989 
    990     malloc_string(command);
    991     malloc_string(iso_mnt);
    992     malloc_string(iso_path);
    993     malloc_string(old_isodir);
    994     malloc_string(value);
    995     malloc_string(tmp);
    996 //  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
    997     assert(bkpinfo != NULL);
    998 
    999     if (!cfgf) {
    1000         strcpy(cfg_file, g_mondo_cfg_file);
    1001     } else {
    1002         strcpy(cfg_file, cfgf);
    1003     }
    1004 
    1005     media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
    1006 
    1007     if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
    1008         if (!strcmp(value, "cdstream")) {
    1009             bkpinfo->backup_media_type = cdstream;
    1010         } else if (!strcmp(value, "cdr")) {
    1011             bkpinfo->backup_media_type = cdr;
    1012         } else if (!strcmp(value, "cdrw")) {
    1013             bkpinfo->backup_media_type = cdrw;
    1014         } else if (!strcmp(value, "dvd")) {
    1015             bkpinfo->backup_media_type = dvd;
    1016         } else if (!strcmp(value, "iso")) {
    1017 /*
    1018       if (am_I_in_disaster_recovery_mode()
    1019       && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1)
    1020       && does_file_exist(MNT_CDROM"/archives/filelist.0"))
     1303*END_READ_CFG_FILE_INTO_BKPINFO                                          *
     1304**************************************************************************/
     1305
     1306
     1307
     1308
     1309/**
     1310* Allow the user to edit the filelist and biggielist.
     1311* The filelist is unlinked after it is read.
     1312* @param bkpinfo The backup information structure. Fields used:
     1313* - @c bkpinfo->backup_media_type
     1314* - @c bkpinfo->isodir
     1315* - @c bkpinfo->media_device
     1316* - @c bkpinfo->tmpdir
     1317* @return The filelist structure containing the information read from disk.
    10211318*/
    1022 
    1023 // Patch by Conor Daly - 2004/07/12
    1024             bkpinfo->backup_media_type = iso;
    1025             if (am_I_in_disaster_recovery_mode()) {
    1026                 /* Check to see if CD is already mounted before mounting it... */
    1027                 if (!is_this_device_mounted("/dev/cdrom")) {
    1028                     log_msg(2,
    1029                             "NB: CDROM device not mounted, mounting...");
    1030                     run_program_and_log_output("mount /dev/cdrom "
    1031                                                MNT_CDROM, 1);
    1032                 }
    1033                 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
    1034                     bkpinfo->backup_media_type = cdr;
    1035                     run_program_and_log_output("umount " MNT_CDROM, 1);
    1036                     log_it
    1037                         ("Re-jigging configuration AGAIN. CD-R, not ISO.");
    1038                 }
    1039             }
    1040             if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    1041                     strcpy(bkpinfo->prefix,value);
    1042             } else {
    1043                     strcpy(bkpinfo->prefix,STD_PREFIX);
    1044             }
    1045         } else if (!strcmp(value, "nfs")) {
    1046             bkpinfo->backup_media_type = nfs;
    1047             if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
    1048                     strcpy(bkpinfo->prefix,value);
    1049             } else {
    1050                     strcpy(bkpinfo->prefix,STD_PREFIX);
    1051             }
    1052             if (strstr(call_program_and_get_last_line_of_output
    1053                ("cat /proc/cmdline"), "pxe")) {
    1054                 /* We need to override prefix value in PXE mode as it's
    1055                 * already done in start-nfs */
    1056                 envtmp1 = getenv("imgname");
    1057                 if (envtmp1 == NULL) {
    1058                     fatal_error("no imgname variable in environment");
    1059                 }
    1060                 strcpy(bkpinfo->prefix,envtmp1);
    1061             }
    1062 
    1063         } else if (!strcmp(value, "tape")) {
    1064             bkpinfo->backup_media_type = tape;
    1065         } else if (!strcmp(value, "udev")) {
    1066             bkpinfo->backup_media_type = udev;
    1067         } else {
    1068             fatal_error("UNKNOWN bkp-media-type");
    1069         }
    1070     } else {
    1071         fatal_error("backup-media-type not specified!");
    1072     }
    1073     if (bkpinfo->disaster_recovery) {
    1074         if (bkpinfo->backup_media_type == cdstream) {
    1075             sprintf(bkpinfo->media_device, "/dev/cdrom");
    1076 //          bkpinfo->media_size[0] = -1;
    1077             bkpinfo->media_size[0] = 1999 * 1024;
    1078             bkpinfo->media_size[1] = 650;   /* good guess */
    1079         } else if (bkpinfo->backup_media_type == tape
    1080                    || bkpinfo->backup_media_type == udev) {
    1081             if (read_cfg_var(cfg_file, "media-dev", value)) {
    1082                 fatal_error("Cannot get tape device name from cfg file");
    1083             }
    1084             strcpy(bkpinfo->media_device, value);
    1085             read_cfg_var(cfg_file, "media-size", value);
    1086             bkpinfo->media_size[1] = atol(value);
    1087             sprintf(tmp, "Backup medium is TAPE --- dev=%s",
    1088                     bkpinfo->media_device);
    1089             log_msg(2, tmp);
    1090         } else {
    1091             strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
    1092             bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
    1093             bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
    1094             log_msg(2, "Backup medium is CD-R[W]");
    1095         }
    1096     } else {
    1097         log_msg(2,
    1098                 "Not in Disaster Recovery Mode. No need to derive device name from config file.");
    1099     }
    1100 
    1101     read_cfg_var(cfg_file, "use-star", value);
    1102     if (strstr(value, "yes")) {
    1103         bkpinfo->use_star = TRUE;
    1104         log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
    1105     }
    1106 
    1107     read_cfg_var(cfg_file, "acl", value);
    1108     if (strstr(value, "TRUE")) {
    1109         asprintf(&g_getfacl,"setfacl");
    1110         log_msg(1, "We will restore ACLs");
    1111         if (! find_home_of_exe("setfacl")) {
    1112             log_msg(1, "Unable to restore ACLs as no setfacl found");
    1113         }
    1114     }
    1115     read_cfg_var(cfg_file, "xattr", value);
    1116     if (strstr(value, "TRUE")) {
    1117         asprintf(&g_getfattr,"setfattr");
    1118         log_msg(1, "We will restore XATTRs");
    1119         if (! find_home_of_exe("setfattr")) {
    1120             log_msg(1, "Unable to restore XATTRs as no setfattr found");
    1121         }
    1122     }
    1123 
    1124     if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
    1125         bkpinfo->internal_tape_block_size = atol(value);
    1126         log_msg(1, "Internal tape block size has been custom-set to %ld",
    1127                 bkpinfo->internal_tape_block_size);
    1128     } else {
    1129         bkpinfo->internal_tape_block_size =
    1130             DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    1131         log_msg(1, "Internal tape block size = default (%ld)",
    1132                 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
    1133     }
    1134 
    1135     read_cfg_var(cfg_file, "use-lzo", value);
    1136     if (strstr(value, "yes")) {
    1137         bkpinfo->use_lzo = TRUE;
    1138         bkpinfo->use_gzip = FALSE;
    1139         strcpy(bkpinfo->zip_exe, "lzop");
    1140         strcpy(bkpinfo->zip_suffix, "lzo");
    1141     } else {
    1142         read_cfg_var(cfg_file, "use-gzip", value);
    1143         if (strstr(value, "yes")) {
    1144             bkpinfo->use_lzo = FALSE;
    1145             bkpinfo->use_gzip = TRUE;
    1146             strcpy(bkpinfo->zip_exe, "gzip");
    1147             strcpy(bkpinfo->zip_suffix, "gz");
    1148         } else {
    1149             read_cfg_var(cfg_file, "use-comp", value);
    1150             if (strstr(value, "yes")) {
    1151                 bkpinfo->use_lzo = FALSE;
    1152                 bkpinfo->use_gzip = FALSE;
    1153                 strcpy(bkpinfo->zip_exe, "bzip2");
    1154                 strcpy(bkpinfo->zip_suffix, "bz2");
    1155             } else {
    1156                 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    1157             }
    1158         }
    1159     }
    1160 
    1161     value[0] = '\0';
    1162     read_cfg_var(cfg_file, "differential", value);
    1163     if (!strcmp(value, "yes") || !strcmp(value, "1")) {
    1164         bkpinfo->differential = TRUE;
    1165     }
    1166     log_msg(2, "differential var = '%s'", value);
    1167     if (bkpinfo->differential) {
    1168         log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
    1169     } else {
    1170         log_msg(2, "This is a regular (full) backup");
    1171     }
    1172 
    1173     read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
    1174     if (tmp[0]
    1175         ||
    1176         strstr(call_program_and_get_last_line_of_output
    1177                ("cat /proc/cmdline"), "donteject")) {
    1178         bkpinfo->please_dont_eject = TRUE;
    1179         log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
    1180     }
    1181 
    1182     if (bkpinfo->backup_media_type == nfs) {
    1183         if (!cfgf) {
    1184             log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount);
    1185             log_msg(2, "nfs_remote_dir remains %s",
    1186                     bkpinfo->nfs_remote_dir);
    1187             log_msg(2,
    1188                     "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
    1189         } else {
    1190             read_cfg_var(g_mondo_cfg_file, "nfs-server-mount",
    1191                          bkpinfo->nfs_mount);
    1192             read_cfg_var(g_mondo_cfg_file, "nfs-server-path",
    1193                          bkpinfo->nfs_remote_dir);
    1194             log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount);
    1195             log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir);
    1196         }
    1197         if (strstr(call_program_and_get_last_line_of_output
    1198            ("cat /proc/cmdline"), "pxe")) {
    1199             /* We need to override values in PXE mode as it's
    1200             * already done in start-nfs */
    1201             envtmp1 = getenv("nfsmount");
    1202             if (envtmp1 == NULL) {
    1203                 fatal_error("no nfsmount variable in environment");
    1204             }
    1205             envtmp2 = getenv("dirimg");
    1206             if (envtmp2 == NULL) {
    1207                 fatal_error("no dirimg variable in environment");
    1208             }
    1209             strcpy(bkpinfo->nfs_mount,envtmp1);
    1210             strcpy(bkpinfo->nfs_remote_dir,envtmp2);
    1211         }
    1212     } else if (bkpinfo->backup_media_type == iso) {
    1213         /* Patch by Conor Daly 23-june-2004
    1214          * to correctly mount iso-dev and set a sensible
    1215          * isodir in disaster recovery mode
    1216          */
    1217         strcpy(old_isodir, bkpinfo->isodir);
    1218         read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
    1219         read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
    1220         sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1221         if (!bkpinfo->isodir[0]) {
    1222             strcpy(bkpinfo->isodir, old_isodir);
    1223         }
    1224         if (!bkpinfo->disaster_recovery) {
    1225             if (strcmp(old_isodir, bkpinfo->isodir)) {
    1226                 log_it
    1227                     ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
    1228                      old_isodir, bkpinfo->isodir);
    1229                 strcpy(bkpinfo->isodir, old_isodir);
    1230             }
    1231         }
    1232         read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    1233         log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
    1234                 g_isodir_device);
    1235         if (bkpinfo->disaster_recovery) {
    1236             if (is_this_device_mounted(g_isodir_device)) {
    1237                 log_msg(2, "NB: isodir is already mounted");
    1238                 /* Find out where it's mounted */
    1239                 sprintf(command,
    1240                         "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3",
    1241                         g_isodir_device);
    1242                 log_it("command = %s", command);
    1243                 log_it("res of it = %s",
    1244                        call_program_and_get_last_line_of_output(command));
    1245                 sprintf(iso_mnt, "%s",
    1246                         call_program_and_get_last_line_of_output(command));
    1247             } else {
    1248                 sprintf(iso_mnt, "/tmp/isodir");
    1249                 sprintf(tmp, "mkdir -p %s", iso_mnt);
    1250                 run_program_and_log_output(tmp, 5);
    1251                 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
    1252                 if (run_program_and_log_output(tmp, 3)) {
    1253                     log_msg(1,
    1254                             "Unable to mount isodir. Perhaps this is really a CD backup?");
    1255                     bkpinfo->backup_media_type = cdr;
    1256                     strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
    1257                     bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    1258                     if (mount_cdrom(bkpinfo)) {
    1259                         fatal_error
    1260                             ("Unable to mount isodir. Failed to mount CD-ROM as well.");
    1261                     } else {
    1262                         log_msg(1,
    1263                                 "You backed up to disk, then burned some CDs.");
    1264                     }
    1265                 }
    1266             }
    1267             /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
    1268             if (bkpinfo->backup_media_type == iso) {
    1269                 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
    1270             }
    1271         }
    1272     }
    1273 
    1274     if (media_specified_by_user != none) {
    1275         if (g_restoring_live_from_cd) {
    1276             if (bkpinfo->backup_media_type != media_specified_by_user) {
    1277                 log_msg(2,
    1278                         "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
    1279                 interactively_obtain_media_parameters_from_user(bkpinfo,
    1280                                                                 FALSE);
    1281                 media_specified_by_user = bkpinfo->backup_media_type;
    1282                 get_cfg_file_from_archive(bkpinfo);
    1283 /*
    1284               if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
    1285                 { g_restoring_live_from_cd = FALSE; }
    1286 */
    1287             }
    1288         }
    1289         bkpinfo->backup_media_type = media_specified_by_user;
    1290     }
    1291     g_backup_media_type = bkpinfo->backup_media_type;
    1292     paranoid_free(value);
    1293     paranoid_free(tmp);
    1294     paranoid_free(command);
    1295     paranoid_free(iso_mnt);
    1296     paranoid_free(iso_path);
    1297     paranoid_free(old_isodir);
    1298     return (0);
    1299 
    1300 }
    1301 
    1302 /**************************************************************************
    1303  *END_READ_CFG_FILE_INTO_BKPINFO                                          *
    1304  **************************************************************************/
    1305 
    1306 
    1307 
    1308 
    1309 /**
    1310  * Allow the user to edit the filelist and biggielist.
    1311  * The filelist is unlinked after it is read.
    1312  * @param bkpinfo The backup information structure. Fields used:
    1313  * - @c bkpinfo->backup_media_type
    1314  * - @c bkpinfo->isodir
    1315  * - @c bkpinfo->media_device
    1316  * - @c bkpinfo->tmpdir
    1317  * @return The filelist structure containing the information read from disk.
    1318  */
    13191319struct
    13201320s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo)
    13211321{
    1322     struct s_node *filelist;
    1323 
    1324   /** add mallocs**/
    1325     char *command;
    1326     char *tmp;
    1327     int res = 0;
    1328     pid_t pid;
    1329 
    1330     assert(bkpinfo != NULL);
    1331     malloc_string(command);
    1332     malloc_string(tmp);
    1333 
    1334     if (does_file_exist(g_filelist_full)
    1335         && does_file_exist(g_biggielist_txt)) {
    1336         log_msg(1, "%s exists", g_filelist_full);
    1337         log_msg(1, "%s exists", g_biggielist_txt);
    1338         log_msg(2,
    1339                 "Filelist and biggielist already recovered from media. Yay!");
    1340     } else {
    1341         getcwd(tmp, MAX_STR_LEN);
    1342         chdir(bkpinfo->tmpdir);
    1343         log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
    1344         log_to_screen("Extracting filelist and biggielist from media...");
    1345         unlink("/tmp/filelist.full");
    1346         unlink("/" FILELIST_FULL_STUB);
    1347         unlink("/tmp/i-want-my-lvm");
    1348         if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    1349             sprintf(command,
    1350                     "tar -zxf %s %s %s %s %s %s",
    1351                     bkpinfo->media_device,
    1352                     MOUNTLIST_FNAME_STUB,
    1353                     BIGGIELIST_TXT_STUB,
    1354                     FILELIST_FULL_STUB,
    1355                     "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
    1356             log_msg(1, "tarcommand = %s", command);
    1357             run_program_and_log_output(command, 1);
    1358         } else {
    1359             log_msg(2,
    1360                     "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
    1361                     bkpinfo->isodir);
    1362             insist_on_this_cd_number(bkpinfo, 1);
    1363             log_msg(2, "Back from iotcn");
    1364             run_program_and_log_output("mount", 1);
    1365             sprintf(command,
    1366                     "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
    1367                     MNT_CDROM,
    1368                     MOUNTLIST_FNAME_STUB,
    1369                     BIGGIELIST_TXT_STUB,
    1370                     FILELIST_FULL_STUB,
    1371                     "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
    1372 
    1373             log_msg(1, "tarcommand = %s", command);
    1374             run_program_and_log_output(command, 1);
     1322struct s_node *filelist;
     1323
     1324/** add mallocs**/
     1325char *command;
     1326char *tmp;
     1327int res = 0;
     1328pid_t pid;
     1329
     1330assert(bkpinfo != NULL);
     1331malloc_string(command);
     1332malloc_string(tmp);
     1333
     1334if (does_file_exist(g_filelist_full)
     1335&& does_file_exist(g_biggielist_txt)) {
     1336log_msg(1, "%s exists", g_filelist_full);
     1337log_msg(1, "%s exists", g_biggielist_txt);
     1338log_msg(2,
     1339        "Filelist and biggielist already recovered from media. Yay!");
     1340} else {
     1341getcwd(tmp, MAX_STR_LEN);
     1342chdir(bkpinfo->tmpdir);
     1343log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
     1344log_to_screen("Extracting filelist and biggielist from media...");
     1345unlink("/tmp/filelist.full");
     1346unlink("/" FILELIST_FULL_STUB);
     1347unlink("/tmp/i-want-my-lvm");
     1348if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     1349    sprintf(command,
     1350            "tar -b %ld -zxf %s %s %s %s %s %s",
     1351            bkpinfo->internal_tape_block_size,
     1352            bkpinfo->media_device,
     1353            MOUNTLIST_FNAME_STUB,
     1354            BIGGIELIST_TXT_STUB,
     1355            FILELIST_FULL_STUB,
     1356            "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1357    log_msg(1, "tarcommand = %s", command);
     1358    run_program_and_log_output(command, 1);
     1359} else {
     1360    log_msg(2,
     1361            "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
     1362            bkpinfo->isodir);
     1363    insist_on_this_cd_number(bkpinfo, 1);
     1364    log_msg(2, "Back from iotcn");
     1365    run_program_and_log_output("mount", 1);
     1366    sprintf(command,
     1367            "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
     1368            MNT_CDROM,
     1369            MOUNTLIST_FNAME_STUB,
     1370            BIGGIELIST_TXT_STUB,
     1371            FILELIST_FULL_STUB,
     1372            "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB);
     1373
     1374    log_msg(1, "tarcommand = %s", command);
     1375    run_program_and_log_output(command, 1);
    13751376//    popup_and_OK("Press ENTER to continue");
    1376             if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
    1377                 fatal_error
    1378                     ("all.tar.gz did not include tmp/biggielist.txt");
    1379             }
    1380             if (!does_file_exist(FILELIST_FULL_STUB)) {
    1381                 fatal_error
    1382                     ("all.tar.gz did not include tmp/filelist.full.gz");
    1383             }
    1384         }
    1385         sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
    1386                 g_mondo_cfg_file);
    1387         run_program_and_log_output(command, FALSE);
    1388 
    1389         sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
    1390                 BIGGIELIST_TXT_STUB, g_biggielist_txt);
    1391         log_msg(1, "command = %s", command);
    1392         paranoid_system(command);
    1393         sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
    1394                 FILELIST_FULL_STUB, g_filelist_full);
    1395         log_msg(1, "command = %s", command);
    1396         paranoid_system(command);
    1397     }
    1398 
    1399     if (am_I_in_disaster_recovery_mode()
    1400         &&
    1401         ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
    1402     {
     1377    if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
     1378        fatal_error
     1379            ("all.tar.gz did not include tmp/biggielist.txt");
     1380    }
     1381    if (!does_file_exist(FILELIST_FULL_STUB)) {
     1382        fatal_error
     1383            ("all.tar.gz did not include tmp/filelist.full.gz");
     1384    }
     1385}
     1386sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
     1387        g_mondo_cfg_file);
     1388run_program_and_log_output(command, FALSE);
     1389
     1390sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
     1391        BIGGIELIST_TXT_STUB, g_biggielist_txt);
     1392log_msg(1, "command = %s", command);
     1393paranoid_system(command);
     1394sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
     1395        FILELIST_FULL_STUB, g_filelist_full);
     1396log_msg(1, "command = %s", command);
     1397paranoid_system(command);
     1398}
     1399
     1400if (am_I_in_disaster_recovery_mode()
     1401&&
     1402ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
     1403{
    14031404//      sprintf(command, "cp -f tmp/mountlist.txt /tmp");
    1404         sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
    1405                 bkpinfo->tmpdir);
    1406         paranoid_system(command);
    1407     }
    1408 
    1409     chdir(tmp);
    1410 
    1411     if (!does_file_exist(g_biggielist_txt)) {
    1412         log_msg(1, "Warning - %s not found", g_biggielist_txt);
    1413     }
    1414     if (!does_file_exist(g_filelist_full)) {
    1415         log_msg(1, "Warning - %s does not exist", g_filelist_full);
    1416     }
     1405sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
     1406        bkpinfo->tmpdir);
     1407paranoid_system(command);
     1408}
     1409
     1410chdir(tmp);
     1411
     1412if (!does_file_exist(g_biggielist_txt)) {
     1413log_msg(1, "Warning - %s not found", g_biggielist_txt);
     1414}
     1415if (!does_file_exist(g_filelist_full)) {
     1416log_msg(1, "Warning - %s does not exist", g_filelist_full);
     1417}
    14171418//  popup_and_OK("Wonderful.");
    14181419
    1419     log_msg(2, "Forking");
    1420     pid = fork();
    1421     switch (pid) {
    1422     case -1:
    1423         fatal_error("Forking error");
    1424         break;
    1425 
    1426     case 0:
    1427         log_to_screen("Pre-processing filelist");
    1428         if (!does_file_exist(g_biggielist_txt)) {
    1429             sprintf(command, "> %s", g_biggielist_txt);
     1420log_msg(2, "Forking");
     1421pid = fork();
     1422switch (pid) {
     1423case -1:
     1424fatal_error("Forking error");
     1425break;
     1426
     1427case 0:
     1428log_to_screen("Pre-processing filelist");
     1429if (!does_file_exist(g_biggielist_txt)) {
     1430            sprintf(command, "echo -n > %s", g_biggielist_txt);
    14301431            paranoid_system(command);
    14311432        }
Note: See TracChangeset for help on using the changeset viewer.