source: branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c @ 2386

Last change on this file since 2386 was 2386, checked in by bruno, 10 years ago

Be compatible on backup type by making old nfs recognized as netfs and proto forced

  • Property svn:keywords set to Id
File size: 74.5 KB
Line 
1/***************************************************************************
2$Id: mondo-rstr-tools.c 2386 2009-09-10 14:06:52Z bruno $
3***************************************************************************/
4
5#include <pthread.h>
6#include <linux/fd.h>
7#include "my-stuff.h"
8#include "mr_mem.h"
9#include "../common/mondostructures.h"
10#include "../common/libmondo.h"
11#include "mr-externs.h"
12#include "mondo-rstr-tools.h"
13
14/**
15 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).
16 */
17#define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"
18
19/**
20 * The filelist stub (appended to the directory where all.tar.gz was unpacked).
21 */
22#define FILELIST_FULL_STUB "tmp/filelist.full.gz"
23
24/**
25 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).
26 */
27#define MOUNTLIST_FNAME_STUB "tmp/mountlist.txt"
28
29/**
30 * The mondo-restore.cfg stub (appended to the directory where all.tar.gz was unpacked).
31 */
32#define MONDO_CFG_FILE_STUB "tmp/mondo-restore.cfg"
33/**
34 * The i-want-my-lvm stub
35 */
36#define IWANTMYLVM_STUB "tmp/i-want-my-lvm"
37
38extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
39extern bool g_I_have_just_nuked;
40/*
41extern char *g_tmpfs_mountpt;
42*/
43extern char *g_isodir_device;
44extern char *g_isodir_format;
45extern long g_current_progress, g_maximum_progress;
46extern char *g_biggielist_txt;  // where 'biggielist.txt' is stored, on ramdisk / tempdir;
47                  // biggielist.txt is the list of big files stored on the
48                  // backup media set in question
49extern char *g_filelist_full;   // filelist.full.gz is the list of all regular files
50                  // (excluding big files) stored on the backup media set
51extern char *g_biggielist_pot;  // list of big files which _could_ be restored, if the
52                  // user chooses them
53extern char *g_filelist_imagedevs;  // list of devices (e.g. /dev/hda1, /dev/sda5) which
54                     // were archived as images, not just /dev entries
55                     // ... e.g. NTFS, BeOS partitions
56extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
57                      // restore only these
58extern char *g_mondo_cfg_file;  // where m*ndo-restore.cfg (the config file) is stored
59extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
60extern char *g_mondo_home;      // homedir of Mondo; usually /usr/local/share/mondo
61
62extern t_bkptype g_backup_media_type;
63
64extern int g_partition_table_locked_up;
65extern char *MONDO_LOGFILE;
66
67/* Reference to global bkpinfo */
68extern struct s_bkpinfo *bkpinfo;
69
70/* Should we use or not extended attributes and acl when restoring */
71char *g_getfattr = NULL;
72char *g_getfacl = NULL;
73
74extern void kill_anything_like_this(char *str);
75extern int skip_obdr(void);
76extern int set_tape_block_size_with_mt(long internal_tape_block_size);
77
78/**
79* @addtogroup restoreUtilityGroup
80* @{
81*/
82/**
83* Free the malloc()s for the filename variables.
84*/
85void free_MR_global_filenames(void)
86{
87paranoid_free(g_biggielist_txt);
88paranoid_free(g_filelist_full);
89paranoid_free(g_filelist_imagedevs);
90paranoid_free(g_imagedevs_restthese);
91paranoid_free(g_mondo_cfg_file);
92paranoid_free(g_mountlist_fname);
93paranoid_free(g_mondo_home);
94/*
95paranoid_free(g_tmpfs_mountpt);
96*/
97paranoid_free(g_isodir_device);
98paranoid_free(g_isodir_format);
99
100}
101
102
103
104/**
105* Ask the user which imagedevs from the list contained in @p infname should
106* actually be restored.
107* @param infname The file containing a list of all imagedevs.
108* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
109* @ingroup restoreUtilityGroup
110*/
111void ask_about_these_imagedevs(char *infname, char *outfname)
112{
113FILE *fin;
114FILE *fout;
115/************************************************************************
116* allocate memory regions. test and set  -sab 16 feb 2003              *
117************************************************************************/
118char *incoming_ptr;
119char *question_ptr;
120
121char incoming[MAX_STR_LEN] = "\0";
122char question[MAX_STR_LEN];
123
124assert_string_is_neither_NULL_nor_zerolength(infname);
125assert_string_is_neither_NULL_nor_zerolength(outfname);
126
127incoming_ptr = malloc(sizeof(incoming));
128if (incoming_ptr == NULL) {
129fprintf(stderr, "Out of Memory\n");
130exit(EXIT_FAILURE);
131}
132
133question_ptr = malloc(sizeof(question));
134if (question_ptr == NULL) {
135fprintf(stderr, "Out of Memory\n");
136exit(EXIT_FAILURE);
137}
138
139memset(incoming_ptr, '\0', sizeof(incoming));
140memset(question_ptr, '\0', sizeof(question));
141
142
143
144if (!(fin = fopen(infname, "r"))) {
145fatal_error("Cannot openin infname");
146}
147if (!(fout = fopen(outfname, "w"))) {
148fatal_error("Cannot openin outfname");
149}
150for (fgets(incoming_ptr, MAX_STR_LEN, fin);
151 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
152strip_spaces(incoming_ptr);
153
154if (incoming[0] == '\0') {
155    continue;
156}
157
158sprintf(question_ptr,
159        "Should I restore the image of %s ?", incoming_ptr);
160
161if (ask_me_yes_or_no(question_ptr)) {
162    fprintf(fout, "%s\n", incoming_ptr);
163}
164}
165
166/*** free memory ***********/
167paranoid_free(incoming_ptr);
168incoming_ptr = NULL;
169paranoid_free(question_ptr);
170question_ptr = NULL;
171
172
173paranoid_fclose(fout);
174paranoid_fclose(fin);
175}
176
177/**************************************************************************
178*ASK_ABOUT_THESE_IMAGEDEVS                                               *
179**************************************************************************/
180
181
182
183
184
185
186
187
188/**
189* Extract @c mondo-restore.cfg and @c mountlist.txt from @p ramdisk_fname.
190* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
191* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
192* @param output_cfg_file Where to put the configuration file extracted.
193* @param output_mountlist_file Where to put the mountlist file extracted.
194* @return 0 for success, nonzero for failure.
195* @ingroup restoreUtilityGroup
196*/
197
198/**
199* Keep trying to get mondo-restore.cfg from the archive, until the user gives up.
200*/
201void get_cfg_file_from_archive_or_bust()
202{
203while (get_cfg_file_from_archive()) {
204if (!ask_me_yes_or_no
205    ("Failed to find config file/archives. Choose another source?"))
206{
207    fatal_error("Could not find config file/archives. Aborting.");
208}
209interactively_obtain_media_parameters_from_user(FALSE);
210}
211}
212
213
214/**
215* Determine whether @p list_fname contains a line containing @p f.
216* @param f The line to search for.
217* @param list_fname The file to search in.
218* @param preamble Ignore this beginning part of @p f ("" to disable).
219* @return TRUE if it's in the list, FALSE if it's not.
220*/
221bool is_file_in_list(char *f, char *list_fname, char *preamble)
222{
223
224/** needs malloc **/
225char *command;
226char *file;
227char *tmp;
228int res;
229
230malloc_string(command);
231malloc_string(file);
232malloc_string(tmp);
233assert_string_is_neither_NULL_nor_zerolength(f);
234assert_string_is_neither_NULL_nor_zerolength(list_fname);
235assert(preamble != NULL);
236
237if (strncmp(preamble, f, strlen(preamble)) == 0) {
238strcpy(file, f + strlen(preamble));
239} else {
240strcpy(file, f);
241}
242if (file[0] == '/' && file[1] == '/') {
243strcpy(tmp, file);
244strcpy(file, tmp + 1);
245}
246sprintf(tmp,
247    "Checking to see if f=%s, file=%s, is in the list of biggiefiles",
248    f, file);
249log_msg(2, tmp);
250sprintf(command, "grep -E '^%s$' %s", file, list_fname);
251res = run_program_and_log_output(command, FALSE);
252paranoid_free(command);
253paranoid_free(file);
254paranoid_free(tmp);
255if (res) {
256return (FALSE);
257} else {
258return (TRUE);
259}
260}
261
262/**************************************************************************
263*END_IS_FILE_IN_LIST                                                     *
264**************************************************************************/
265
266
267
268/**
269* Set up an ISO backup.
270* @param bkpinfo The backup information structure. Fields used:
271* - @c bkpinfo->backup_media_type
272* - @c bkpinfo->disaster_recovery
273* - @c bkpinfo->isodir
274* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
275* @return 0 for success, nonzero for failure.
276*/
277int iso_fiddly_bits(bool nuke_me_please)
278{
279char *mount_isodir_command = NULL;
280char *tmp, *command;
281char *mds = NULL;
282int retval = 0, i;
283bool already_mounted = FALSE;
284
285assert(bkpinfo != NULL);
286malloc_string(tmp);
287malloc_string(command);
288g_ISO_restore_mode = TRUE;
289read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
290if (bkpinfo->disaster_recovery) {
291    /* Patch Conor Daly 26-june-2004
292    * Don't let this clobber an existing bkpinfo->isodir */
293    if (!bkpinfo->isodir[0]) {
294        strcpy(bkpinfo->isodir, "/tmp/isodir");
295    }
296    /* End patch */
297    sprintf(command, "mkdir -p %s", bkpinfo->isodir);
298    run_program_and_log_output(command, 5);
299    log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
300}
301
302if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {
303    return (1);
304}
305paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
306
307if (is_this_device_mounted(g_isodir_device)) {
308    log_to_screen("WARNING - isodir is already mounted");
309    already_mounted = TRUE;
310} else {
311    mr_asprintf(&mount_isodir_command, "mount %s", g_isodir_device);
312    if (strlen(g_isodir_format) > 1) {
313        mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
314    }
315    mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
316    run_program_and_log_output("df -m", FALSE);
317    sprintf(tmp,
318        "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
319        mount_isodir_command);
320    log_msg(1, tmp);
321    if (run_program_and_log_output(mount_isodir_command, FALSE)) {
322        popup_and_OK
323            ("Cannot mount the device where the ISO files are stored.");
324        return (1);
325    }
326    paranoid_free(mount_isodir_command);
327    log_to_screen
328    ("I have mounted the device where the ISO files are stored.");
329}
330if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
331    mount_media();
332}
333i = what_number_cd_is_this();   /* has the side-effect of calling mount_media() */
334mds = media_descriptor_string(bkpinfo->backup_media_type);
335sprintf(tmp, "%s #%d has been mounted via loopback mount", mds, i);
336mr_free(mds);
337
338log_msg(1, tmp);
339if (i < 0) {
340popup_and_OK
341    ("Cannot find ISO images in the directory you specified.");
342retval = 1;
343}
344log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
345    bkpinfo->isodir);
346paranoid_free(tmp);
347paranoid_free(command);
348return (retval);
349}
350
351
352
353
354/**
355* Kill all Petris processes.
356*/
357void kill_petris(void) {
358    kill_anything_like_this("petris");
359}
360
361/**************************************************************************
362*END_KILL_PETRIS                                                         *
363**************************************************************************/
364
365
366/**
367 * Mount @p device at @p mpt as @p format.
368 * @param device The device (/dev entry) to mount.
369 * @param mpt The directory to mount it on.
370 * @param format The filesystem type of @p device.
371 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
372 * @return 0 for success, nonzero for failure.
373 */
374int mount_device(char *device, char *mpt, char *format, bool writeable)
375{
376int res = 0;
377
378/** malloc **/
379char *tmp, *command, *mountdir, *mountpoint;
380char *additional_parameters = NULL;
381
382assert_string_is_neither_NULL_nor_zerolength(device);
383assert_string_is_neither_NULL_nor_zerolength(mpt);
384assert(format != NULL);
385malloc_string(tmp);
386malloc_string(command);
387malloc_string(mountdir);
388malloc_string(mountpoint);
389
390    if (!strcmp(mpt, "/1")) {
391        strcpy(mountpoint, "/");
392        log_msg(3, "Mommm! SME is being a dildo!");
393    } else {
394        strcpy(mountpoint, mpt);
395    }
396
397    if (!strcmp(mountpoint, "lvm")) {
398        return (0);
399    }
400    if (!strcmp(mountpoint, "image")) {
401        return (0);
402    }
403    sprintf(tmp, "Mounting device %s   ", device);
404    log_msg(1, tmp);
405    /* Deal with additional params only if not /proc or /sys */
406    mr_asprintf(&additional_parameters, "");
407    if (strcmp(format, "proc") && strcmp(format, "sys")) {
408        if (writeable) {
409            mr_strcat(additional_parameters, "-o rw");
410        } else {
411            mr_strcat(additional_parameters, "-o ro");
412        }
413        if (find_home_of_exe("setfattr")) {
414            mr_strcat(additional_parameters, ",user_xattr");
415        }
416        if (find_home_of_exe("setfacl")) {
417            mr_strcat(additional_parameters, ",acl");
418        }
419    }
420
421    if (!strcmp(mountpoint, "swap")) {
422        sprintf(command, "swapon %s", device);
423    } else {
424        if (!strcmp(mountpoint, "/")) {
425            strcpy(mountdir, MNT_RESTORING);
426        } else {
427            sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
428        }
429        sprintf(command, "mkdir -p %s", mountdir);
430        run_program_and_log_output(command, FALSE);
431        sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device,
432                additional_parameters, mountdir, MONDO_LOGFILE);
433        log_msg(2, "command='%s'", command);
434    }
435    paranoid_free(additional_parameters);
436
437    res = run_program_and_log_output(command, TRUE);
438    if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
439        log_msg(1, "Re-trying without the fancy extra parameters");
440        sprintf(command, "mount -t %s %s %s 2>> %s", format, device,
441            mountdir, MONDO_LOGFILE);
442        res = run_program_and_log_output(command, TRUE);
443    }
444    if (res) {
445        log_msg(1, "Unable to mount device %s (type %s) at %s", device,
446                format, mountdir);
447        log_msg(1, "command was '%s'", command);
448        if (!strcmp(mountpoint, "swap")) {
449            log_to_screen(tmp);
450        } else {
451            log_msg(2, "Retrying w/o the '-t' switch");
452            sprintf(command, "mount %s %s 2>> %s", device, mountdir,
453                MONDO_LOGFILE);
454            log_msg(2, "2nd command = '%s'", command);
455            res = run_program_and_log_output(command, TRUE);
456            if (res == 0) {
457                log_msg(1,
458                    "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
459            } else {
460                log_to_screen(tmp);
461            }
462        }
463    }
464
465    if (res && !strcmp(mountpoint, "swap")) {
466        log_msg(2, "That's ok. It's just a swap partition.");
467        log_msg(2, "Non-fatal error. Returning 0.");
468        res = 0;
469    }
470
471paranoid_free(tmp);
472paranoid_free(command);
473paranoid_free(mountdir);
474paranoid_free(mountpoint);
475
476    return (res);
477}
478/**************************************************************************
479 *END_MOUNT_DEVICE                                                        *
480**************************************************************************/
481
482
483/**
484 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
485 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
486 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
487 * @return The number of errors encountered (0 for success).
488 */
489int mount_all_devices(struct mountlist_itself
490                      *p_external_copy_of_mountlist, bool writeable)
491{
492int retval = 0, lino, res;
493char *tmp;
494char *these_failed = NULL;
495char *format;
496struct mountlist_itself *mountlist = NULL;
497
498malloc_string(tmp);
499malloc_string(format);
500
501assert(p_external_copy_of_mountlist != NULL);
502mountlist = malloc(sizeof(struct mountlist_itself));
503memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
504   sizeof(struct mountlist_itself));
505    sort_mountlist_by_mountpoint(mountlist, 0);
506
507
508    mvaddstr_and_log_it(g_currentY, 0, "Mounting devices         ");
509    open_progress_form("Mounting devices",
510               "I am now mounting all the drives.",
511               "This should not take long.",
512               "", mountlist->entries);
513
514    mr_asprintf(&these_failed, "");
515    for (lino = 0; lino < mountlist->entries; lino++) {
516        if (!strcmp(mountlist->el[lino].device, "/proc")) {
517            log_msg(1,
518                "Again with the /proc - why is this in your mountlist?");
519        } else if (is_this_device_mounted(mountlist->el[lino].device)) {
520            sprintf(tmp, "%s is already mounted",
521                mountlist->el[lino].device);
522            log_to_screen(tmp);
523        } else if (strcmp(mountlist->el[lino].mountpoint, "none")
524           && strcmp(mountlist->el[lino].mountpoint, "lvm")
525           && strcmp(mountlist->el[lino].mountpoint, "raid")
526           && strcmp(mountlist->el[lino].mountpoint, "image")) {
527            sprintf(tmp, "Mounting %s", mountlist->el[lino].device);
528            update_progress_form(tmp);
529            strcpy(format, mountlist->el[lino].format);
530            res = mount_device(mountlist->el[lino].device,
531                       mountlist->el[lino].mountpoint,
532                       format, writeable);
533            retval += res;
534            if (res) {
535                mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
536            }
537        }
538        g_current_progress++;
539    }
540    close_progress_form();
541    if (retval) {
542        if (g_partition_table_locked_up > 0) {
543            log_to_screen
544                ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
545            log_to_screen
546                ("lock up the partition table. You might have to reboot and use Interactive Mode to");
547            log_to_screen
548                ("format and restore *without* partitioning first. Sorry for the inconvenience.");
549        }
550        sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
551
552        if (!ask_me_yes_or_no(tmp)) {
553            retval = 0;
554            log_to_screen
555                ("Continuing, although some device(s) failed to be mounted");
556            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
557        } else {
558            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
559            log_to_screen
560        ("Unable to mount some or all of your partitions.");
561        }
562    } else {
563        log_to_screen("All partitions were mounted OK.");
564        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
565    }
566    paranoid_free(these_failed);
567
568    /* Also mounting under MNT_RESTORING  special FS */
569    (void)mount_device("/proc","/proc","proc",TRUE);
570    (void)mount_device("/sys","/sys","sysfs",TRUE);
571    run_program_and_log_output("df -m", 3);
572    paranoid_free(mountlist);
573    paranoid_free(tmp);
574    paranoid_free(format);
575    return (retval);
576}
577/**************************************************************************
578*END_MOUNT_ALL_DEVICES                                                   *
579**************************************************************************/
580
581
582/**
583* Mount the CD-ROM or USB device at /mnt/cdrom.
584* @param bkpinfo The backup information structure. Fields used:
585* - @c bkpinfo->backup_media_type
586* - @c bkpinfo->disaster_recovery
587* - @c bkpinfo->isodir
588* - @c bkpinfo->media_device
589* @return 0 for success, nonzero for failure.
590*/
591int mount_media()
592{
593char *mount_cmd;
594int i, res;
595#ifdef __FreeBSD__
596char mdd[32];
597char *mddev = mdd;
598#endif
599
600malloc_string(mount_cmd);
601assert(bkpinfo != NULL);
602
603    if (bkpinfo->backup_media_type == tape
604        || bkpinfo->backup_media_type == udev) {
605        log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
606        paranoid_free(mount_cmd);
607        return 0;
608    }
609
610    if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
611        log_msg(2, "mount_media() - media already mounted. Fair enough.");
612        paranoid_free(mount_cmd);
613        return (0);
614    }
615
616    if (bkpinfo->backup_media_type == netfs) {
617        log_msg(2, "Mounting for Network thingy");
618        log_msg(2, "isodir = %s", bkpinfo->isodir);
619        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
620            && am_I_in_disaster_recovery_mode()) {
621            strcpy(bkpinfo->isodir, "/tmp/isodir");
622            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
623        }
624#ifdef __FreeBSD__
625        sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
626            bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
627        mddev = make_vn(mount_cmd);
628        sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
629#else
630        sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
631            bkpinfo->isodir, bkpinfo->netfs_remote_dir,
632            bkpinfo->prefix, g_current_media_number, MNT_CDROM);
633#endif
634
635    } else if (bkpinfo->backup_media_type == iso) {
636#ifdef __FreeBSD__
637        sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,
638            bkpinfo->prefix, g_current_media_number);
639        mddev = make_vn(mount_cmd);
640        sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
641#else
642        sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
643            bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
644#endif
645    } else if (bkpinfo->backup_media_type == usb) {
646        sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
647    } else if (strstr(bkpinfo->media_device, "/dev/")) {
648#ifdef __FreeBSD__
649        sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
650        MNT_CDROM);
651#else
652        sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
653        bkpinfo->media_device, MNT_CDROM);
654#endif
655    } else {
656        if (bkpinfo->disaster_recovery
657            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
658            strcpy(bkpinfo->media_device,
659                last_line_of_file("/tmp/CDROM-LIVES-HERE"));
660        } else {
661            find_cdrom_device(bkpinfo->media_device, TRUE);
662        }
663
664#ifdef __FreeBSD__
665    sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
666        MNT_CDROM);
667#else
668    sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
669        bkpinfo->media_device, MNT_CDROM);
670#endif
671    }
672
673    log_msg(2, "(mount_media) --- command = %s", mount_cmd);
674    for (i = 0; i < 2; i++) {
675        res = run_program_and_log_output(mount_cmd, FALSE);
676        if (!res) {
677            break;
678        } else {
679            log_msg(2, "Failed to mount device.");
680            sleep(5);
681            run_program_and_log_output("sync", FALSE);
682        }
683    }
684
685    if (res) {
686        log_msg(2, "Failed, despite %d attempts", i);
687    } else {
688        log_msg(2, "Mounted media drive OK");
689    }
690    paranoid_free(mount_cmd);
691    return (res);
692}
693/**************************************************************************
694*END_MOUNT_CDROM                                                         *
695**************************************************************************/
696
697
698
699/**
700* Fix some miscellaneous things in the filesystem so the system will come
701* up correctly on the first boot.
702*/
703void protect_against_braindead_sysadmins()
704{
705run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct",
706                       FALSE);
707run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct",
708                       FALSE);
709if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) {
710run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp",
711                           FALSE);
712}
713run_program_and_log_output("mkdir -p " MNT_RESTORING
714                       "/var/run/console", FALSE);
715run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null",
716                       FALSE);
717run_program_and_log_output("cd " MNT_RESTORING
718                       "; 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",
719                       TRUE);
720run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid",
721                       TRUE);
722run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*",
723                       TRUE);
724}
725
726/**************************************************************************
727*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS                                 *
728**************************************************************************/
729
730
731
732
733/**
734* Fill out @p bkpinfo based on @p cfg_file.
735* @param cfg_file The mondo-restore.cfg file to read into @p bkpinfo.
736* @param bkpinfo The backup information structure to fill out with information
737* from @p cfg_file.
738* @return 0 for success, nonzero for failure.
739*/
740int read_cfg_file_into_bkpinfo(char *cfgf)
741{
742/** add mallocs **/
743char *value = NULL;
744char *tmp = NULL;
745char *envtmp1 = NULL;
746char *envtmp2 = NULL;
747char *command = NULL;
748char *iso_mnt = NULL;
749char *iso_path = NULL;
750char *old_isodir = NULL;
751char cfg_file[100];
752t_bkptype media_specified_by_user;
753
754malloc_string(command);
755malloc_string(iso_mnt);
756malloc_string(iso_path);
757malloc_string(old_isodir);
758malloc_string(value);
759malloc_string(tmp);
760//  assert_string_is_neither_NULL_nor_zerolength(cfg_file);
761assert(bkpinfo != NULL);
762
763if (!cfgf) {
764    strcpy(cfg_file, g_mondo_cfg_file);
765} else {
766    strcpy(cfg_file, cfgf);
767}
768
769media_specified_by_user = bkpinfo->backup_media_type;   // or 'none', if not specified
770
771if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
772if (!strcmp(value, "cdstream")) {
773    bkpinfo->backup_media_type = cdstream;
774} else if (!strcmp(value, "cdr")) {
775    bkpinfo->backup_media_type = cdr;
776} else if (!strcmp(value, "cdrw")) {
777    bkpinfo->backup_media_type = cdrw;
778} else if (!strcmp(value, "dvd")) {
779    bkpinfo->backup_media_type = dvd;
780} else if (!strcmp(value, "usb")) {
781    bkpinfo->backup_media_type = usb;
782    bkpinfo->please_dont_eject = TRUE;
783} else if (!strcmp(value, "iso")) {
784
785// Patch by Conor Daly - 2004/07/12
786    bkpinfo->backup_media_type = iso;
787    if (am_I_in_disaster_recovery_mode()) {
788        /* Check to see if CD is already mounted before mounting it... */
789        if (!is_this_device_mounted("/dev/cdrom")) {
790            log_msg(2,
791                    "NB: CDROM device not mounted, mounting...");
792            run_program_and_log_output("mount /dev/cdrom "
793                                       MNT_CDROM, 1);
794        }
795        if (does_file_exist(MNT_CDROM "/archives/filelist.0")) {
796            bkpinfo->backup_media_type = cdr;
797            run_program_and_log_output("umount " MNT_CDROM, 1);
798            log_it
799                ("Re-jigging configuration AGAIN. CD-R, not ISO.");
800        }
801    }
802    if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
803            strcpy(bkpinfo->prefix,value);
804    } else {
805            strcpy(bkpinfo->prefix,STD_PREFIX);
806    }
807} else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
808    /* Stay compatible with previous versions by allowing nfs as an entry here */
809    bkpinfo->backup_media_type = netfs;
810    bkpinfo->please_dont_eject = TRUE;
811    if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
812            strcpy(bkpinfo->prefix,value);
813    } else {
814            strcpy(bkpinfo->prefix,STD_PREFIX);
815    }
816    if (strstr(call_program_and_get_last_line_of_output
817       ("cat /proc/cmdline"), "pxe")) {
818        /* We need to override prefix value in PXE mode as it's
819        * already done in start-netfs */
820        envtmp1 = getenv("imgname");
821        if (envtmp1 == NULL) {
822            fatal_error("no imgname variable in environment");
823        }
824        strcpy(bkpinfo->prefix,envtmp1);
825    }
826    /* For compatibility, force protocol in old nfs case to be transparent */
827    if (!strcmp(value, "nfs")) {
828        mr_free(bkpinfo->netfs_proto);
829        mr_asprintf(bkpinfo->netfs_proto, "nfs");
830    }
831
832} else if (!strcmp(value, "tape")) {
833    bkpinfo->backup_media_type = tape;
834} else if (!strcmp(value, "udev")) {
835    bkpinfo->backup_media_type = udev;
836} else {
837    fatal_error("UNKNOWN bkp-media-type");
838}
839} else {
840fatal_error("backup-media-type not specified!");
841}
842if (bkpinfo->disaster_recovery) {
843    if (bkpinfo->backup_media_type == cdstream) {
844        sprintf(bkpinfo->media_device, "/dev/cdrom");
845//          bkpinfo->media_size[0] = -1;
846        bkpinfo->media_size[0] = 1999 * 1024;
847        bkpinfo->media_size[1] = 650;   /* good guess */
848    } else if (bkpinfo->backup_media_type == usb) {
849        envtmp1 = getenv("MRUSBDEV");
850        if (envtmp1 == NULL) {
851            if (read_cfg_var(cfg_file, "usb-dev", value)) {
852                fatal_error("Cannot get USB device name from cfg file");
853            }
854        } else {
855            strcpy(value,envtmp1);
856        }
857        sprintf(bkpinfo->media_device, "%s1", value);
858        sprintf(tmp, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
859        log_msg(2, tmp);
860    } else if (bkpinfo->backup_media_type == tape
861            || bkpinfo->backup_media_type == udev) {
862        if (read_cfg_var(cfg_file, "media-dev", value)) {
863            fatal_error("Cannot get tape device name from cfg file");
864        }
865        strcpy(bkpinfo->media_device, value);
866        read_cfg_var(cfg_file, "media-size", value);
867        bkpinfo->media_size[1] = atol(value);
868        sprintf(tmp, "Backup medium is TAPE --- dev=%s",
869                bkpinfo->media_device);
870        log_msg(2, tmp);
871    } else {
872        strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
873        bkpinfo->media_size[0] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
874        bkpinfo->media_size[1] = 1999 * 1024;   /* 650, probably, but we don't need this var anyway */
875        log_msg(2, "Backup medium is CD-R[W]");
876    }
877} else {
878    log_msg(2,
879        "Not in Disaster Recovery Mode. No need to derive device name from config file.");
880}
881
882read_cfg_var(cfg_file, "use-star", value);
883if (strstr(value, "yes")) {
884    bkpinfo->use_star = TRUE;
885    log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
886}
887
888read_cfg_var(cfg_file, "obdr", value);
889if (strstr(value, "TRUE")) {
890    bkpinfo->use_obdr = TRUE;
891    log_msg(1, "OBDR mode activated");
892}
893
894read_cfg_var(cfg_file, "acl", value);
895if (strstr(value, "TRUE")) {
896    mr_asprintf(&g_getfacl,"setfacl");
897    log_msg(1, "We will restore ACLs");
898    if (! find_home_of_exe("setfacl")) {
899        log_msg(1, "Unable to restore ACLs as no setfacl found");
900    }
901}
902read_cfg_var(cfg_file, "xattr", value);
903if (strstr(value, "TRUE")) {
904    mr_asprintf(&g_getfattr,"setfattr");
905    log_msg(1, "We will restore XATTRs");
906    if (! find_home_of_exe("setfattr")) {
907        log_msg(1, "Unable to restore XATTRs as no setfattr found");
908    }
909}
910
911if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
912bkpinfo->internal_tape_block_size = atol(value);
913log_msg(1, "Internal tape block size has been custom-set to %ld",
914        bkpinfo->internal_tape_block_size);
915} else {
916bkpinfo->internal_tape_block_size =
917    DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
918log_msg(1, "Internal tape block size = default (%ld)",
919        DEFAULT_INTERNAL_TAPE_BLOCK_SIZE);
920}
921
922read_cfg_var(cfg_file, "use-lzo", value);
923if (strstr(value, "yes")) {
924bkpinfo->use_lzo = TRUE;
925bkpinfo->use_gzip = FALSE;
926strcpy(bkpinfo->zip_exe, "lzop");
927strcpy(bkpinfo->zip_suffix, "lzo");
928} else {
929read_cfg_var(cfg_file, "use-gzip", value);
930if (strstr(value, "yes")) {
931    bkpinfo->use_lzo = FALSE;
932    bkpinfo->use_gzip = TRUE;
933    strcpy(bkpinfo->zip_exe, "gzip");
934    strcpy(bkpinfo->zip_suffix, "gz");
935} else {
936    read_cfg_var(cfg_file, "use-comp", value);
937    if (strstr(value, "yes")) {
938        bkpinfo->use_lzo = FALSE;
939        bkpinfo->use_gzip = FALSE;
940        strcpy(bkpinfo->zip_exe, "bzip2");
941        strcpy(bkpinfo->zip_suffix, "bz2");
942    } else {
943        bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
944    }
945}
946}
947
948value[0] = '\0';
949read_cfg_var(cfg_file, "differential", value);
950if (!strcmp(value, "yes") || !strcmp(value, "1")) {
951bkpinfo->differential = TRUE;
952}
953log_msg(2, "differential var = '%s'", value);
954if (bkpinfo->differential) {
955log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
956} else {
957log_msg(2, "This is a regular (full) backup");
958}
959
960read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);
961if (tmp[0]
962||
963strstr(call_program_and_get_last_line_of_output
964       ("cat /proc/cmdline"), "donteject")) {
965bkpinfo->please_dont_eject = TRUE;
966log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
967}
968
969if (bkpinfo->backup_media_type == netfs) {
970    if (!cfgf) {
971        log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
972        log_msg(2, "netfs_remote_dir remains %s",
973                bkpinfo->netfs_remote_dir);
974        log_msg(2,
975                "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
976    } else {
977        read_cfg_var(g_mondo_cfg_file, "netfs-server-mount",
978                    bkpinfo->netfs_mount);
979        read_cfg_var(g_mondo_cfg_file, "netfs-server-path",
980                    bkpinfo->netfs_remote_dir);
981        log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
982        log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
983        log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
984    }
985    if (strstr(call_program_and_get_last_line_of_output
986        ("cat /proc/cmdline"), "pxe")) {
987        /* We need to override values in PXE mode as it's
988        * already done in start-netfs */
989        envtmp1 = getenv("netfsmount");
990        if (envtmp1 == NULL) {
991            fatal_error("no netfsmount variable in environment");
992        }
993        envtmp2 = getenv("dirimg");
994        if (envtmp2 == NULL) {
995            fatal_error("no dirimg variable in environment");
996        }
997        strcpy(bkpinfo->netfs_mount,envtmp1);
998        strcpy(bkpinfo->netfs_remote_dir,envtmp2);
999    }
1000} else if (bkpinfo->backup_media_type == iso) {
1001    /* Patch by Conor Daly 23-june-2004
1002    * to correctly mount iso-dev and set a sensible
1003    * isodir in disaster recovery mode
1004    */
1005    strcpy(old_isodir, bkpinfo->isodir);
1006    read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt);
1007    read_cfg_var(g_mondo_cfg_file, "isodir", iso_path);
1008    sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1009    if (!bkpinfo->isodir[0]) {
1010        strcpy(bkpinfo->isodir, old_isodir);
1011    }
1012    if (!bkpinfo->disaster_recovery) {
1013        if (strcmp(old_isodir, bkpinfo->isodir)) {
1014            log_it
1015                ("user nominated isodir differs from archive, keeping user's choice: %s %s\n",
1016                old_isodir, bkpinfo->isodir);
1017            strcpy(bkpinfo->isodir, old_isodir);
1018        }
1019    }
1020    read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
1021    log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir,
1022            g_isodir_device);
1023    if (bkpinfo->disaster_recovery) {
1024        if (is_this_device_mounted(g_isodir_device)) {
1025            log_msg(2, "NB: isodir is already mounted");
1026            /* Find out where it's mounted */
1027            sprintf(command,
1028                    "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3",
1029                    g_isodir_device);
1030            log_it("command = %s", command);
1031            log_it("res of it = %s",
1032                call_program_and_get_last_line_of_output(command));
1033            sprintf(iso_mnt, "%s",
1034                    call_program_and_get_last_line_of_output(command));
1035        } else {
1036            sprintf(iso_mnt, "/tmp/isodir");
1037            sprintf(tmp, "mkdir -p %s", iso_mnt);
1038            run_program_and_log_output(tmp, 5);
1039            sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt);
1040            if (run_program_and_log_output(tmp, 3)) {
1041                log_msg(1,
1042                        "Unable to mount isodir. Perhaps this is really a CD backup?");
1043                bkpinfo->backup_media_type = cdr;
1044                strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
1045                bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
1046                if (mount_media()) {
1047                    fatal_error
1048                        ("Unable to mount isodir. Failed to mount CD-ROM as well.");
1049                } else {
1050                    log_msg(1,
1051                            "You backed up to disk, then burned some CDs.");
1052                }
1053            }
1054        }
1055        /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
1056        if (bkpinfo->backup_media_type == iso) {
1057            sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1058        }
1059    }
1060}
1061
1062if (media_specified_by_user != none) {
1063    if (g_restoring_live_from_cd) {
1064        if (bkpinfo->backup_media_type != media_specified_by_user) {
1065            log_msg(2,
1066                    "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
1067            interactively_obtain_media_parameters_from_user(FALSE);
1068            media_specified_by_user = bkpinfo->backup_media_type;
1069            get_cfg_file_from_archive();
1070    /*
1071        if (media_specified_by_user != cdr && media_specified_by_user == cdrw)
1072            { g_restoring_live_from_cd = FALSE; }
1073    */
1074        }
1075    }
1076    bkpinfo->backup_media_type = media_specified_by_user;
1077}
1078g_backup_media_type = bkpinfo->backup_media_type;
1079paranoid_free(value);
1080paranoid_free(tmp);
1081paranoid_free(command);
1082paranoid_free(iso_mnt);
1083paranoid_free(iso_path);
1084paranoid_free(old_isodir);
1085return (0);
1086
1087}
1088
1089/**************************************************************************
1090*END_READ_CFG_FILE_INTO_BKPINFO                                          *
1091**************************************************************************/
1092
1093
1094
1095
1096/**
1097 * Allow the user to edit the filelist and biggielist.
1098 * The filelist is unlinked after it is read.
1099 * @param bkpinfo The backup information structure. Fields used:
1100 * - @c bkpinfo->backup_media_type
1101 * - @c bkpinfo->isodir
1102 * - @c bkpinfo->media_device
1103 * - @c bkpinfo->tmpdir
1104 * @return The filelist structure containing the information read from disk.
1105 */
1106struct
1107s_node *process_filelist_and_biggielist()
1108{
1109struct s_node *filelist;
1110
1111/** add mallocs**/
1112char *command;
1113char *tmp;
1114int res = 0;
1115pid_t pid;
1116bool extract_mountlist_stub = FALSE;
1117
1118assert(bkpinfo != NULL);
1119malloc_string(command);
1120malloc_string(tmp);
1121
1122/* If those files already exist, do not overwrite them later on */
1123if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
1124    extract_mountlist_stub = FALSE;
1125} else {
1126    extract_mountlist_stub = TRUE;
1127}
1128
1129if (does_file_exist(g_filelist_full)
1130&& does_file_exist(g_biggielist_txt)) {
1131    log_msg(1, "%s exists", g_filelist_full);
1132    log_msg(1, "%s exists", g_biggielist_txt);
1133    log_msg(2,
1134        "Filelist and biggielist already recovered from media. Yay!");
1135} else {
1136    getcwd(tmp, MAX_STR_LEN);
1137    chdir(bkpinfo->tmpdir);
1138    log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1139    log_to_screen("Extracting filelist and biggielist from media...");
1140    unlink("/tmp/filelist.full");
1141    unlink(FILELIST_FULL_STUB);
1142    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1143        sprintf(command,
1144            "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s",
1145            bkpinfo->internal_tape_block_size,
1146            bkpinfo->media_device,
1147            MOUNTLIST_FNAME_STUB,
1148            BIGGIELIST_TXT_STUB,
1149            FILELIST_FULL_STUB,
1150            IWANTMYLVM_STUB,
1151            MONDO_CFG_FILE_STUB);
1152        log_msg(1, "tarcommand = %s", command);
1153        run_program_and_log_output(command, 1);
1154        if (!does_file_exist(FILELIST_FULL_STUB)) {
1155            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1156            log_msg(2, "pre-2.2.4 compatible mode on");
1157            sprintf(command,
1158                "tar -b %ld -zxf %s %s %s %s %s %s",
1159                bkpinfo->internal_tape_block_size,
1160                bkpinfo->media_device,
1161                MOUNTLIST_FNAME_STUB,
1162                BIGGIELIST_TXT_STUB,
1163                FILELIST_FULL_STUB,
1164                IWANTMYLVM_STUB,
1165                MONDO_CFG_FILE_STUB);
1166            log_msg(1, "tarcommand = %s", command);
1167            run_program_and_log_output(command, 1);
1168        }
1169    } else {
1170        log_msg(2,
1171            "Calling insist_on_this_cd_number; bkpinfo->isodir=%s",
1172            bkpinfo->isodir);
1173        insist_on_this_cd_number(1);
1174        log_msg(2, "Back from iotcn");
1175        run_program_and_log_output("mount", 1);
1176        sprintf(command,
1177            "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s",
1178            MNT_CDROM,
1179            MOUNTLIST_FNAME_STUB,
1180            BIGGIELIST_TXT_STUB,
1181            FILELIST_FULL_STUB,
1182            IWANTMYLVM_STUB,
1183            MONDO_CFG_FILE_STUB);
1184
1185        log_msg(1, "tarcommand = %s", command);
1186        run_program_and_log_output(command, 1);
1187        if (!does_file_exist(FILELIST_FULL_STUB)) {
1188            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1189            log_msg(2, "pre-2.2.4 compatible mode on");
1190            sprintf(command,
1191                "tar -zxf %s/images/all.tar.gz %s %s %s %s %s",
1192                MNT_CDROM,
1193                MOUNTLIST_FNAME_STUB,
1194                BIGGIELIST_TXT_STUB,
1195                FILELIST_FULL_STUB,
1196                IWANTMYLVM_STUB,
1197                MONDO_CFG_FILE_STUB);
1198
1199            log_msg(1, "tarcommand = %s", command);
1200            run_program_and_log_output(command, 1);
1201        }
1202        if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
1203            fatal_error
1204                ("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
1205        }
1206        if (!does_file_exist(FILELIST_FULL_STUB)) {
1207            fatal_error
1208                ("all.tar.gz did not include " FILELIST_FULL_STUB);
1209        }
1210    }
1211    sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,
1212        g_mondo_cfg_file);
1213    run_program_and_log_output(command, FALSE);
1214
1215    sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir,
1216        BIGGIELIST_TXT_STUB, g_biggielist_txt);
1217    log_msg(1, "command = %s", command);
1218    paranoid_system(command);
1219    sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir,
1220        FILELIST_FULL_STUB, g_filelist_full);
1221    log_msg(1, "command = %s", command);
1222    paranoid_system(command);
1223    }
1224
1225    if (am_I_in_disaster_recovery_mode()
1226    &&
1227    /* If it was there, do not overwrite it */
1228    (extract_mountlist_stub) 
1229    &&
1230    ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1231    {
1232        sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,
1233            bkpinfo->tmpdir);
1234    paranoid_system(command);
1235    }
1236
1237    chdir(tmp);
1238
1239    if (!does_file_exist(g_biggielist_txt)) {
1240        log_msg(1, "Warning - %s not found", g_biggielist_txt);
1241    }
1242    if (!does_file_exist(g_filelist_full)) {
1243        log_msg(1, "Warning - %s does not exist", g_filelist_full);
1244    }
1245//  popup_and_OK("Wonderful.");
1246
1247    log_msg(2, "Forking");
1248    pid = fork();
1249    switch (pid) {
1250    case -1:
1251        fatal_error("Forking error");
1252        break;
1253
1254    case 0:
1255        log_to_screen("Pre-processing filelist");
1256        if (!does_file_exist(g_biggielist_txt)) {
1257            sprintf(command, "echo -n > %s", g_biggielist_txt);
1258            paranoid_system(command);
1259        }
1260        sprintf(command, "grep -E '^/dev/.*' %s > %s",
1261                g_biggielist_txt, g_filelist_imagedevs);
1262        paranoid_system(command);
1263        exit(0);
1264        break;
1265
1266    default:
1267        open_evalcall_form("Pre-processing filelist");
1268        while (!waitpid(pid, (int *) 0, WNOHANG)) {
1269            usleep(100000);
1270            update_evalcall_form(0);
1271        }
1272    }
1273    close_evalcall_form();
1274
1275    log_msg(3, "loading filelist");
1276    filelist = load_filelist(g_filelist_full);
1277    log_msg(3, "deleting original filelist");
1278    unlink(g_filelist_full);
1279    if (g_text_mode) {
1280        printf("Restore which directory? --> ");
1281        fgets(tmp, sizeof(tmp), stdin);
1282        toggle_path_selection(filelist, tmp, TRUE);
1283        if (strlen(tmp) == 0) {
1284            res = 1;
1285        } else {
1286            res = 0;
1287        }
1288    } else {
1289        res = edit_filelist(filelist);
1290    }
1291    if (res) {
1292        log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1293        free_filelist(filelist);
1294        return (NULL);
1295    }
1296    ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1297    close_evalcall_form();
1298
1299    // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1300    // file. The filelist.full file already contains the filename of EVERY
1301    // file backed up - regular and biggie files.
1302
1303    // However, we do want to make sure the imagedevs selected by the user
1304    // are flagged for restoring.
1305    if (length_of_file(g_imagedevs_restthese) > 2) {
1306        add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1307                                      TRUE);
1308    }
1309
1310    paranoid_free(command);
1311    paranoid_free(tmp);
1312    return (filelist);
1313}
1314
1315/**************************************************************************
1316 *END_ PROCESS_FILELIST_AND_BIGGIELIST                                    *
1317 **************************************************************************/
1318
1319
1320
1321
1322/**
1323 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1324 * The backup filename is the filename of the original with ".pristine" added.
1325 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1326 * @param filename The filename (absolute path) within @p path_root.
1327 * @return 0 for success, nonzero for failure.
1328 */
1329int backup_crucial_file(char *path_root, char *filename)
1330{
1331    char *tmp;
1332    char *command;
1333    int res;
1334
1335    malloc_string(tmp);
1336    malloc_string(command);
1337    assert(path_root != NULL);
1338    assert_string_is_neither_NULL_nor_zerolength(filename);
1339
1340    sprintf(tmp, "%s/%s", path_root, filename);
1341    sprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1342
1343    res = run_program_and_log_output(command, 5);
1344    paranoid_free(tmp);
1345    paranoid_free(command);
1346    return (res);
1347}
1348
1349void offer_to_make_initrd() {
1350
1351if (bkpinfo->restore_mode != nuke) {
1352    if (ask_me_yes_or_no
1353        ("You will now be able to re-generate your initrd.\nThis is especially useful if you changed of hardware configuration, cloned, made P2V, used multipath...\nDo you need to do it ?")) {
1354        log_msg(1,"Launching shell for manual initrd recreation");
1355        popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your initrd with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nThen type exit to finish.");
1356        mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
1357        if (!g_text_mode) {
1358            newtSuspend();
1359        }
1360        (void)system("chroot " MNT_RESTORING);
1361        if (!g_text_mode) {
1362            newtResume();
1363        }
1364        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1365    } else {
1366        return;
1367    }
1368} else {
1369    log_to_screen("Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1370    log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1371}
1372}
1373
1374
1375/**
1376 * Install the user's boot loader in the MBR.
1377 * Currently LILO, ELILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1378 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1379 * @return 0 for success, nonzero for failure.
1380 */
1381int run_boot_loader(bool offer_to_hack_scripts)
1382{
1383    int res;
1384    int retval = 0;
1385
1386  /** malloc *******/
1387    char *device;
1388    char *tmp = NULL;
1389    char *name;
1390    char *cmd = NULL;
1391
1392    malloc_string(device);
1393    malloc_string(name);
1394
1395    /* In order to have a working bootloader, we need to have all devices
1396     * ready in the chroot. If they are not there (udev) then copy them from
1397     * the current /dev location
1398     */
1399    mr_asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
1400    run_program_and_log_output(cmd, 3);
1401    paranoid_free(cmd);
1402
1403    backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1404    backup_crucial_file(MNT_RESTORING, "/boot/grub/menu.lst");
1405    backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1406    backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf");
1407    backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map");
1408    backup_crucial_file(MNT_RESTORING, "/etc/mtab");
1409    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1410    read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1411    mr_asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);
1412    log_msg(2, tmp);
1413    paranoid_free(tmp);
1414    system("sync");
1415
1416    offer_to_make_initrd();
1417    if (!strcmp(name, "LILO")) {
1418        res = run_lilo(offer_to_hack_scripts);
1419    } else if (!strcmp(name, "ELILO")) {
1420        res = run_elilo(offer_to_hack_scripts);
1421    } else if (!strcmp(name, "GRUB")) {
1422        res = run_grub(offer_to_hack_scripts, device);
1423    } else if (!strcmp(name, "RAW")) {
1424        res = run_raw_mbr(offer_to_hack_scripts, device);
1425    }
1426#ifdef __FreeBSD__
1427    else if (!strcmp(name, "BOOT0")) {
1428        mr_asprintf(&tmp, "boot0cfg -B %s", device);
1429        res = run_program_and_log_output(tmp, FALSE);
1430        paranoid_free(tmp);
1431    } else {
1432        mr_asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
1433        if (!system(tmp)) {
1434            paranoid_free(tmp);
1435            mr_asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1436            res = run_program_and_log_output(tmp, 3);
1437        } else {
1438            log_msg(1,
1439                    "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1440        }
1441        paranoid_free(tmp);
1442    }
1443#else
1444    else {
1445        log_to_screen
1446            ("Unable to determine type of boot loader. Defaulting to LILO.");
1447        res = run_lilo(offer_to_hack_scripts);
1448    }
1449#endif
1450    retval += res;
1451    if (res) {
1452        log_to_screen("Your boot loader returned an error");
1453    } else {
1454        log_to_screen("Your boot loader ran OK");
1455    }
1456    paranoid_free(device);
1457    paranoid_free(name);
1458    return (retval);
1459}
1460
1461/**************************************************************************
1462 *END_ RUN_BOOT_LOADER                                                    *
1463 **************************************************************************/
1464
1465
1466
1467/**
1468 * Attempt to find the user's editor.
1469 * @return The editor found ("vi" if none could be found).
1470 * @note The returned string points to static storage that will be overwritten with each call.
1471 */
1472char *find_my_editor(void)
1473{
1474    static char output[MAX_STR_LEN];
1475    if (find_home_of_exe("pico")) {
1476        strcpy(output, "pico");
1477    } else if (find_home_of_exe("nano")) {
1478        strcpy(output, "nano");
1479    } else if (find_home_of_exe("e3em")) {
1480        strcpy(output, "e3em");
1481    } else if (find_home_of_exe("e3vi")) {
1482        strcpy(output, "e3vi");
1483    } else {
1484        strcpy(output, "vi");
1485    }
1486    if (!find_home_of_exe(output)) {
1487        log_msg(2, " (find_my_editor) --- warning - %s not found", output);
1488    }
1489    return (output);
1490}
1491
1492
1493/**
1494 * Install GRUB on @p bd.
1495 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1496 * @param bd The boot device where GRUB is installed.
1497 * @return 0 for success, nonzero for failure.
1498 */
1499int run_grub(bool offer_to_run_stabgrub, char *bd)
1500{
1501  /** malloc **/
1502    char *command;
1503    char *boot_device;
1504    char *rootdev;
1505    char *rootdrive;
1506    char *conffile;
1507    char *tmp;
1508    char *editor;
1509
1510    int res;
1511    int done;
1512
1513    malloc_string(command);
1514    malloc_string(boot_device);
1515    malloc_string(tmp);
1516    malloc_string(editor);
1517    malloc_string(rootdev);
1518    malloc_string(rootdrive);
1519    malloc_string(conffile);
1520    assert_string_is_neither_NULL_nor_zerolength(bd);
1521    strcpy(editor, find_my_editor());
1522    strcpy(boot_device, bd);
1523
1524    if (!run_program_and_log_output("which grub-MR", FALSE)) {
1525        log_msg(1, "Yay! grub-MR found...");
1526        sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);
1527        log_msg(1, "command = %s", command);
1528    } else {
1529        sprintf(command, "chroot " MNT_RESTORING " grub-install %s",
1530                boot_device);
1531        log_msg(1, "WARNING - grub-MR not found; using grub-install");
1532    }
1533    if (offer_to_run_stabgrub
1534        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1535        /* interactive mode */
1536    {
1537        mvaddstr_and_log_it(g_currentY,
1538                            0,
1539                            "Modifying fstab, mtab, device.map and menu.lst, and running GRUB...                             ");
1540        for (done = FALSE; !done;) {
1541            popup_and_get_string("Boot device",
1542                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1543                                 boot_device, MAX_STR_LEN / 4);
1544            sprintf(command, "stabgrub-me %s", boot_device);
1545            res = run_program_and_log_output(command, 1);
1546            if (res) {
1547                popup_and_OK
1548                    ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
1549                newtSuspend();
1550                system("chroot " MNT_RESTORING);
1551                newtResume();
1552                popup_and_OK("Thank you.");
1553            } else {
1554                done = TRUE;
1555            }
1556            popup_and_OK("You will now edit fstab, mtab, device.map and menu.lst");
1557            if (!g_text_mode) {
1558                newtSuspend();
1559            }
1560            sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1561            paranoid_system(tmp);
1562            sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
1563            paranoid_system(tmp);
1564            sprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
1565            paranoid_system(tmp);
1566            sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
1567            paranoid_system(tmp);
1568            if (!g_text_mode) {
1569                newtResume();
1570            }
1571        }
1572    } else
1573        /* nuke mode */
1574    {
1575        mvaddstr_and_log_it(g_currentY,
1576                            0,
1577                            "Running GRUB...                                                 ");
1578        log_it("%s",command);
1579        res = run_program_and_log_output(command, 1);
1580        if (res) {
1581            popup_and_OK
1582                ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
1583            newtSuspend();
1584            system("chroot " MNT_RESTORING);
1585            newtResume();
1586            popup_and_OK("Thank you.");
1587        }
1588    }
1589    if (res) {
1590        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1591        log_to_screen
1592            ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
1593        log_msg(1, "Type:-");
1594        log_msg(1, "    mount-me");
1595        log_msg(1, "    chroot " MNT_RESTORING);
1596        log_msg(1, "    mount /boot");
1597        log_msg(1, "    grub-install '(hd0)'");
1598        log_msg(1, "    exit");
1599        log_msg(1, "    unmount-me");
1600        log_msg(1,
1601                "If you're really stuck, please e-mail the mailing list.");
1602    } else {
1603        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1604    }
1605    paranoid_free(rootdev);
1606    paranoid_free(rootdrive);
1607    paranoid_free(conffile);
1608    paranoid_free(command);
1609    paranoid_free(boot_device);
1610    paranoid_free(tmp);
1611    paranoid_free(editor);
1612
1613    return (res);
1614}
1615
1616/**************************************************************************
1617 *END_RUN_GRUB                                                            *
1618 **************************************************************************/
1619
1620
1621/**
1622 * Install ELILO on the user's boot drive (determined by elilo.conf).
1623 * @param offer_to_run_stabelilo If TRUE, then offer to hack the user's fstab for them.
1624 * @return 0 for success, nonzero for failure.
1625 */
1626int run_elilo(bool offer_to_run_stabelilo)
1627{
1628  /** malloc **/
1629    char *command;
1630    char *tmp;
1631    char *editor;
1632
1633    int res;
1634    int done;
1635
1636    malloc_string(command);
1637    malloc_string(tmp);
1638    malloc_string(editor);
1639    strcpy(editor, find_my_editor());
1640    if (offer_to_run_stabelilo
1641        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1642
1643        /* interactive mode */
1644    {
1645        mvaddstr_and_log_it(g_currentY,
1646                            0,
1647                            "Modifying fstab and elilo.conf...                             ");
1648        sprintf(command, "stabelilo-me");
1649        res = run_program_and_log_output(command, 3);
1650        if (res) {
1651            popup_and_OK
1652                ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.");
1653            for (done = FALSE; !done;) {
1654                if (!g_text_mode) {
1655                    newtSuspend();
1656                }
1657                sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1658                paranoid_system(tmp);
1659                sprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor);
1660                paranoid_system(tmp);
1661                if (!g_text_mode) {
1662                    newtResume();
1663                }
1664//              newtCls();
1665                if (ask_me_yes_or_no("Edit them again?")) {
1666                    continue;
1667                }
1668                done = TRUE;
1669            }
1670        } else {
1671            log_to_screen("elilo.conf and fstab were modified OK");
1672        }
1673    } else
1674        /* nuke mode */
1675    {
1676        res = TRUE;
1677    }
1678    paranoid_free(command);
1679    paranoid_free(tmp);
1680    paranoid_free(editor);
1681    return (res);
1682}
1683
1684/**************************************************************************
1685 *END_RUN_ELILO                                                            *
1686 **************************************************************************/
1687
1688
1689/**
1690 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1691 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1692 * @return 0 for success, nonzero for failure.
1693 */
1694int run_lilo(bool offer_to_run_stablilo)
1695{
1696  /** malloc **/
1697    char *command;
1698    char *tmp;
1699    char *editor;
1700
1701    int res;
1702    int done;
1703    bool run_lilo_M = FALSE;
1704    malloc_string(command);
1705    malloc_string(tmp);
1706    malloc_string(editor);
1707
1708    if (!run_program_and_log_output
1709        ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1710        run_lilo_M = TRUE;
1711    }
1712
1713    strcpy(editor, find_my_editor());
1714    if (offer_to_run_stablilo
1715        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1716
1717        /* interactive mode */
1718    {
1719        mvaddstr_and_log_it(g_currentY,
1720                            0,
1721                            "Modifying fstab and lilo.conf, and running LILO...                             ");
1722        sprintf(command, "stablilo-me");
1723        res = run_program_and_log_output(command, 3);
1724        if (res) {
1725            popup_and_OK
1726                ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1727            for (done = FALSE; !done;) {
1728                if (!g_text_mode) {
1729                    newtSuspend();
1730                }
1731                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1732                paranoid_system(tmp);
1733                sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1734                paranoid_system(tmp);
1735                if (!g_text_mode) {
1736                    newtResume();
1737                }
1738//              newtCls();
1739                if (ask_me_yes_or_no("Edit them again?")) {
1740                    continue;
1741                }
1742                res =
1743                    run_program_and_log_output("chroot " MNT_RESTORING
1744                                               " lilo -L", 3);
1745                if (res) {
1746                    res =
1747                        run_program_and_log_output("chroot " MNT_RESTORING
1748                                                   " lilo", 3);
1749                }
1750                if (res) {
1751                    done =
1752                        ask_me_yes_or_no
1753                        ("LILO failed. Re-edit system files?");
1754                } else {
1755                    done = TRUE;
1756                }
1757            }
1758        } else {
1759            log_to_screen("lilo.conf and fstab were modified OK");
1760        }
1761    } else
1762        /* nuke mode */
1763    {
1764        mvaddstr_and_log_it(g_currentY,
1765                            0,
1766                            "Running LILO...                                                 ");
1767        res =
1768            run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1769                                       3);
1770        if (res) {
1771            res =
1772                run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1773                                           3);
1774        }
1775        if (res) {
1776            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1777            log_to_screen
1778                ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1779        } else {
1780            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1781        }
1782    }
1783    if (run_lilo_M) {
1784        run_program_and_log_output("chroot " MNT_RESTORING
1785                                   " lilo -M /dev/hda", 3);
1786        run_program_and_log_output("chroot " MNT_RESTORING
1787                                   " lilo -M /dev/sda", 3);
1788    }
1789    paranoid_free(command);
1790    paranoid_free(tmp);
1791    paranoid_free(editor);
1792    return (res);
1793}
1794
1795/**************************************************************************
1796 *END_RUN_LILO                                                            *
1797 **************************************************************************/
1798
1799
1800/**
1801 * Install a raw MBR onto @p bd.
1802 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1803 * @param bd The device to copy the stored MBR to.
1804 * @return 0 for success, nonzero for failure.
1805 */
1806int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1807{
1808  /** malloc **/
1809    char *command;
1810    char *boot_device;
1811    char *tmp;
1812    char *editor;
1813    int res;
1814    int done;
1815
1816    malloc_string(command);
1817    malloc_string(boot_device);
1818    malloc_string(tmp);
1819    malloc_string(editor);
1820    assert_string_is_neither_NULL_nor_zerolength(bd);
1821
1822    strcpy(editor, find_my_editor());
1823    strcpy(boot_device, bd);
1824    sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);
1825    log_msg(2, "run_raw_mbr() --- command='%s'", command);
1826
1827    if (offer_to_hack_scripts
1828        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1829        /* interactive mode */
1830    {
1831        mvaddstr_and_log_it(g_currentY, 0,
1832                            "Modifying fstab and restoring MBR...                           ");
1833        for (done = FALSE; !done;) {
1834            if (!run_program_and_log_output("which vi", FALSE)) {
1835                popup_and_OK("You will now edit fstab");
1836                if (!g_text_mode) {
1837                    newtSuspend();
1838                }
1839                sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1840                paranoid_system(tmp);
1841                if (!g_text_mode) {
1842                    newtResume();
1843                }
1844//              newtCls();
1845            }
1846            popup_and_get_string("Boot device",
1847                                 "Please confirm/enter the boot device. If in doubt, try /dev/hda",
1848                                 boot_device, MAX_STR_LEN / 4);
1849            sprintf(command, "stabraw-me %s", boot_device);
1850            res = run_program_and_log_output(command, 3);
1851            if (res) {
1852                done = ask_me_yes_or_no("Modifications failed. Re-try?");
1853            } else {
1854                done = TRUE;
1855            }
1856        }
1857    } else
1858        /* nuke mode */
1859    {
1860        mvaddstr_and_log_it(g_currentY, 0,
1861                            "Restoring MBR...                                               ");
1862        res = run_program_and_log_output(command, 3);
1863    }
1864    if (res) {
1865        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1866        log_to_screen
1867            ("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
1868    } else {
1869        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1870    }
1871    paranoid_free(command);
1872    paranoid_free(boot_device);
1873    paranoid_free(tmp);
1874    paranoid_free(editor);
1875    return (res);
1876}
1877
1878/**************************************************************************
1879 *END_RUN_RAW_MBR                                                         *
1880 **************************************************************************/
1881
1882
1883
1884/**
1885 * malloc() and set sensible defaults for the mondorestore filename variables.
1886 * @param bkpinfo The backup information structure. Fields used:
1887 * - @c bkpinfo->tmpdir
1888 * - @c bkpinfo->disaster_recovery
1889 */
1890void setup_MR_global_filenames()
1891{
1892    char *temppath;
1893
1894    assert(bkpinfo != NULL);
1895
1896    malloc_string(g_biggielist_txt);
1897    malloc_string(g_filelist_full);
1898    malloc_string(g_filelist_imagedevs);
1899    malloc_string(g_imagedevs_restthese);
1900    malloc_string(g_mondo_cfg_file);
1901    malloc_string(g_mountlist_fname);
1902    malloc_string(g_mondo_home);
1903    /*
1904    malloc_string(g_tmpfs_mountpt);
1905    */
1906    malloc_string(g_isodir_device);
1907    malloc_string(g_isodir_format);
1908
1909    temppath = bkpinfo->tmpdir;
1910
1911    sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB);
1912    sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB);
1913    sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath);
1914//  sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath);
1915    sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
1916            temppath);
1917    if (bkpinfo->disaster_recovery) {
1918        sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
1919        sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
1920    } else {
1921        sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);
1922        sprintf(g_mountlist_fname, "%s/%s", temppath,
1923                MOUNTLIST_FNAME_STUB);
1924    }
1925}
1926
1927/**************************************************************************
1928 *END_SET_GLOBAL_FILENAME                                                 *
1929 **************************************************************************/
1930
1931
1932/**
1933 * Copy @p input_file (containing the result of a compare) to @p output_file,
1934 * deleting spurious "changes" along the way.
1935 * @param output_file The output file to write with spurious changes removed.
1936 * @param input_file The input file, a list of changed files created by a compare.
1937 */
1938void streamline_changes_file(char *output_file, char *input_file)
1939{
1940    FILE *fin;
1941    FILE *fout;
1942  /** malloc **/
1943    char *incoming;
1944
1945    assert_string_is_neither_NULL_nor_zerolength(output_file);
1946    assert_string_is_neither_NULL_nor_zerolength(input_file);
1947    malloc_string(incoming);
1948
1949    if (!(fin = fopen(input_file, "r"))) {
1950        log_OS_error(input_file);
1951        return;
1952    }
1953    if (!(fout = fopen(output_file, "w"))) {
1954        fatal_error("cannot open output_file");
1955    }
1956    for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
1957         fgets(incoming, MAX_STR_LEN - 1, fin)) {
1958        if (strncmp(incoming, "etc/adjtime", 11)
1959            && strncmp(incoming, "etc/mtab", 8)
1960            && strncmp(incoming, "tmp/", 4)
1961            && strncmp(incoming, "boot/map", 8)
1962            && !strstr(incoming, "incheckentry")
1963            && strncmp(incoming, "etc/mail/statistics", 19)
1964            && strncmp(incoming, "var/", 4))
1965            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
1966    }
1967    paranoid_fclose(fout);
1968    paranoid_fclose(fin);
1969    paranoid_free(incoming);
1970}
1971
1972/**************************************************************************
1973 *END_STREAMLINE_CHANGES_FILE                                             *
1974 **************************************************************************/
1975
1976
1977/**
1978 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
1979 */
1980void twenty_seconds_til_yikes()
1981{
1982    int i;
1983    /* MALLOC * */
1984    char *tmp;
1985
1986    malloc_string(tmp);
1987    if (does_file_exist("/tmp/NOPAUSE")) {
1988        return;
1989    }
1990    open_progress_form("CAUTION",
1991                       "Be advised: I am about to ERASE your hard disk(s)!",
1992                       "You may press Ctrl+Alt+Del to abort safely.",
1993                       "", 20);
1994    for (i = 0; i < 20; i++) {
1995        g_current_progress = i;
1996        sprintf(tmp, "You have %d seconds left to abort.", 20 - i);
1997        update_progress_form(tmp);
1998        sleep(1);
1999    }
2000    close_progress_form();
2001    paranoid_free(tmp);
2002}
2003
2004/**************************************************************************
2005 *END_TWENTY_SECONDS_TIL_YIKES                                            *
2006 **************************************************************************/
2007
2008
2009/**
2010 * Unmount all devices in @p p_external_copy_of_mountlist.
2011 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
2012 * @return 0 for success, nonzero for failure.
2013 */
2014int unmount_all_devices(struct mountlist_itself
2015                        *p_external_copy_of_mountlist)
2016{
2017    struct mountlist_itself *mountlist;
2018    int retval = 0, lino, res = 0, i;
2019    char *command;
2020    char *tmp = NULL;
2021
2022    malloc_string(command);
2023    assert(p_external_copy_of_mountlist != NULL);
2024
2025    mountlist = malloc(sizeof(struct mountlist_itself));
2026    memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
2027           sizeof(struct mountlist_itself));
2028    sort_mountlist_by_mountpoint(mountlist, 0);
2029
2030    run_program_and_log_output("df -m", 3);
2031    mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices      ");
2032    open_progress_form("Unmounting devices",
2033                       "Unmounting all devices that were mounted,",
2034                       "in preparation for the post-restoration reboot.",
2035                       "", mountlist->entries);
2036    chdir("/");
2037    for (i = 0;
2038         i < 10
2039         &&
2040         run_program_and_log_output
2041         ("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0;
2042         i++) {
2043        sleep(1);
2044        log_msg(2, "Waiting for buffer() to finish");
2045    }
2046
2047    paranoid_system("sync");
2048
2049    mr_asprintf(&tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
2050    if (run_program_and_log_output(tmp, FALSE)) {
2051        log_msg(1,
2052                "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
2053    }
2054    paranoid_free(tmp);
2055    if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
2056        run_program_and_log_output("mkdir -p " MNT_RESTORING
2057                                   "/mnt/.boot.d", 5);
2058    }
2059
2060    /* Unmounting the local /proc and /sys first */
2061    run_program_and_log_output("umount " MNT_RESTORING "/proc",3);
2062    run_program_and_log_output("umount " MNT_RESTORING "/sys",3);
2063
2064    for (lino = mountlist->entries - 1; lino >= 0; lino--) {
2065        if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
2066            continue;
2067        }
2068        mr_asprintf(&tmp, "Unmounting device %s  ", mountlist->el[lino].device);
2069
2070        update_progress_form(tmp);
2071
2072        if (is_this_device_mounted(mountlist->el[lino].device)) {
2073            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
2074                sprintf(command, "swapoff %s", mountlist->el[lino].device);
2075            } else {
2076                if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
2077                    sprintf(command, "umount %s/", MNT_RESTORING);
2078                    log_msg(3,
2079                            "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2080                } else {
2081                    sprintf(command, "umount " MNT_RESTORING "%s",
2082                            mountlist->el[lino].mountpoint);
2083
2084                    /* To support latest Ubuntu where /var is a separate FS
2085                     * Cf: http://linux.derkeiler.com/Mailing-Lists/Ubuntu/2007-04/msg01319.html
2086                     * we need to create some dirs under the real / before unmounting it */
2087                    if (!strcmp(mountlist->el[lino].mountpoint, "/")) {
2088                        run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/lock", FALSE);
2089                        run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run", FALSE);
2090                    }
2091                }
2092            }
2093            log_msg(10, "The 'umount' command is '%s'", command);
2094            res = run_program_and_log_output(command, 3);
2095        } else {
2096            mr_strcat(tmp, "...not mounted anyway :-) OK");
2097            res = 0;
2098        }
2099        g_current_progress++;
2100        if (res) {
2101            mr_strcat(tmp, "...Failed");
2102            retval++;
2103            log_to_screen(tmp);
2104        } else {
2105            log_msg(2, tmp);
2106        }
2107        paranoid_free(tmp);
2108    }
2109    close_progress_form();
2110    if (retval) {
2111        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2112    } else {
2113        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2114    }
2115    if (retval) {
2116        log_to_screen("Unable to unmount some of your partitions.");
2117    } else {
2118        log_to_screen("All partitions were unmounted OK.");
2119    }
2120    free(mountlist);
2121    paranoid_free(command);
2122    return (retval);
2123}
2124
2125/**************************************************************************
2126 *END_UNMOUNT_ALL_DEVICES                                                 *
2127 **************************************************************************/
2128
2129
2130
2131/**
2132 * Extract mondo-restore.cfg and the mountlist from the tape inserted
2133 * to the ./tmp/ directory.
2134 * @param dev The tape device to read from.
2135 * @return 0 for success, nonzero for failure.
2136 */
2137int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
2138{
2139    char *command;
2140    int res = 0;
2141
2142    malloc_string(command);
2143
2144    if (bkpinfo->use_obdr) {
2145        skip_obdr();
2146    } else {
2147        // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
2148        set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
2149    }
2150
2151    sprintf(command,
2152            "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s",
2153            dev,
2154            bkpinfo->internal_tape_block_size,
2155            1024L * 1024 * 32 / bkpinfo->internal_tape_block_size,
2156            MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
2157            BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
2158    log_msg(2, "command = '%s'", command);
2159    res = run_program_and_log_output(command, -1);
2160    if (res != 0) {
2161        if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2162            res = 0;
2163        } else {
2164            /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2165            log_msg(2, "pre-2.2.4 compatible mode on");
2166            sprintf(command,
2167                    "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s",
2168                    dev,
2169                    bkpinfo->internal_tape_block_size,
2170                    1024L * 1024 * 32 / bkpinfo->internal_tape_block_size,
2171                    MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB,
2172                    BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
2173            log_msg(2, "command = '%s'", command);
2174            res = run_program_and_log_output(command, -1);
2175            if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
2176                res = 0;
2177            }
2178        }
2179    }
2180    paranoid_free(command);
2181    return (res);
2182}
2183
2184
2185
2186/**
2187 * Get the configuration file from the floppy, tape, or CD.
2188 * @param bkpinfo The backup information structure. Fields used:
2189 * - @c bkpinfo->backup_media_type
2190 * - @c bkpinfo->media_device
2191 * - @c bkpinfo->tmpdir
2192 * @return 0 for success, nonzero for failure.
2193 */
2194int get_cfg_file_from_archive()
2195{
2196    int retval = 0;
2197
2198   /** malloc *****/
2199    char *device;
2200    char *command;
2201    char *cfg_file;
2202    char *mounted_cfgf_path;
2203    char *tmp;
2204    char *mountpt;
2205    char *ramdisk_fname;
2206    char *mountlist_file;
2207    bool extract_mountlist_stub = FALSE;
2208    bool extract_i_want_my_lvm = FALSE;
2209
2210    bool try_plan_B;
2211
2212    assert(bkpinfo != NULL);
2213    malloc_string(cfg_file);
2214    malloc_string(mounted_cfgf_path);
2215    malloc_string(mountpt);
2216    malloc_string(ramdisk_fname);
2217    malloc_string(mountlist_file);
2218    malloc_string(device);
2219    malloc_string(command);
2220    malloc_string(tmp);
2221    log_msg(2, "gcffa --- starting");
2222    log_to_screen("I'm thinking...");
2223    sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
2224    device[0] = '\0';
2225    chdir(bkpinfo->tmpdir);
2226    strcpy(cfg_file, MONDO_CFG_FILE_STUB);
2227    unlink(cfg_file);           // cfg_file[] is missing the '/' at the start, FYI, by intent
2228    unlink(FILELIST_FULL_STUB);
2229    unlink(BIGGIELIST_TXT_STUB);
2230    sprintf(command, "mkdir -p %s", mountpt);
2231    run_program_and_log_output(command, FALSE);
2232
2233    sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2234    sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2235    //   make_hole_for_file( cfg_file );
2236    //   make_hole_for_file( mountlist_file);
2237    log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
2238
2239    if (!does_file_exist(cfg_file)) {
2240        log_msg(2, "gcffa --- we don't have cfg file yet.");
2241        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2242            try_plan_B = TRUE;
2243        } else {
2244            log_msg(2, "gcffa --- calling mount_media now :)");
2245            if (!mount_media()) {
2246                log_msg(2,
2247                        "gcffa --- managed to mount CD; so, no need for Plan B");
2248                try_plan_B = FALSE;
2249            } else {
2250                try_plan_B = TRUE;
2251            }
2252            if (what_number_cd_is_this() > 1) {
2253                insist_on_this_cd_number((g_current_media_number = 1));
2254            }
2255        }
2256        if (try_plan_B) {
2257            log_msg(2, "gcffa --- OK, switching to Plan B");
2258            chdir(bkpinfo->tmpdir);
2259            run_program_and_log_output("mkdir -p tmp", FALSE);
2260
2261            if (strlen(bkpinfo->media_device) == 0) {
2262                strcpy(bkpinfo->media_device, "/dev/st0");
2263                log_msg(2, "media_device is blank; assuming %s");
2264            }
2265            strcpy(tmp, bkpinfo->media_device);
2266            if (extract_cfg_file_and_mountlist_from_tape_dev
2267                (bkpinfo->media_device)) {
2268                strcpy(bkpinfo->media_device, "/dev/st0");
2269                if (extract_cfg_file_and_mountlist_from_tape_dev
2270                    (bkpinfo->media_device)) {
2271                    strcpy(bkpinfo->media_device, "/dev/osst0");
2272                    if (extract_cfg_file_and_mountlist_from_tape_dev
2273                        (bkpinfo->media_device)) {
2274                        strcpy(bkpinfo->media_device, "/dev/ht0");
2275                        if (extract_cfg_file_and_mountlist_from_tape_dev
2276                            (bkpinfo->media_device)) {
2277                            log_msg(3,
2278                                    "I tried lots of devices but none worked.");
2279                            strcpy(bkpinfo->media_device, tmp);
2280                        }
2281                    }
2282                }
2283            }
2284
2285            if (!does_file_exist("tmp/mondo-restore.cfg")) {
2286                log_to_screen("Cannot find config info on media");
2287                return (1);
2288            }
2289        } else {
2290                if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
2291                    extract_mountlist_stub = FALSE;
2292                } else {
2293                    extract_mountlist_stub = TRUE;
2294                }
2295                if (does_file_exist("/"IWANTMYLVM_STUB)) {
2296                    extract_i_want_my_lvm = FALSE;
2297                } else {
2298                    extract_i_want_my_lvm = TRUE;
2299                }
2300
2301                log_msg(2,
2302                        "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
2303                sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);    // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
2304                run_program_and_log_output(command, TRUE);
2305                if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2306                    /* Doing that allow us to remain compatible with pre-2.2.5 versions */
2307                    log_msg(2, "pre-2.2.4 compatible mode on");
2308                    sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);  // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
2309                    run_program_and_log_output(command, TRUE);
2310                    if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
2311                        fatal_error
2312                            ("Please reinsert the disk/CD and try again.");
2313                    }
2314                }
2315        }
2316    }
2317    if (does_file_exist(MONDO_CFG_FILE_STUB)) {
2318        log_msg(1, "gcffa --- great! We've got the config file");
2319        sprintf(tmp, "%s/%s",
2320                call_program_and_get_last_line_of_output("pwd"),
2321                MONDO_CFG_FILE_STUB);
2322        sprintf(command, "cp -f %s %s", tmp, cfg_file);
2323        log_it("%s",command);
2324        if (strcmp(tmp, cfg_file)
2325            && run_program_and_log_output(command, 1)) {
2326            log_msg(1,
2327                    "... but an error occurred when I tried to move it to %s",
2328                    cfg_file);
2329        } else {
2330            log_msg(1, "... and I moved it successfully to %s", cfg_file);
2331        }
2332        sprintf(command, "cp -f %s/%s %s",
2333            call_program_and_get_last_line_of_output("pwd"),
2334            MOUNTLIST_FNAME_STUB, mountlist_file);
2335        log_it("%s",command);
2336        if (extract_mountlist_stub) {
2337            if (strcmp(tmp, cfg_file)
2338                && run_program_and_log_output(command, 1)) {
2339                log_msg(1, "Failed to get mountlist");
2340            } else {
2341                log_msg(1, "Got mountlist too");
2342                sprintf(command, "cp -f %s %s", mountlist_file,
2343                        g_mountlist_fname);
2344                if (run_program_and_log_output(command, 1)) {
2345                    log_msg(1, "Failed to copy mountlist to /tmp");
2346                } else {
2347                    log_msg(1, "Copied mountlist to /tmp as well OK");
2348                    sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
2349                    run_program_and_log_output(command, 1);
2350                }
2351            }
2352        }
2353    }
2354    run_program_and_log_output("umount " MNT_CDROM, FALSE);
2355    if (!does_file_exist(cfg_file)) {
2356        log_it("%s",cfg_file);
2357        log_msg(1, "%s not found", cfg_file);
2358        log_to_screen
2359            ("Oh dear. Unable to recover configuration file from boot disk");
2360        return (1);
2361    }
2362
2363    log_to_screen("Recovered mondo-restore.cfg");
2364    if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
2365        log_to_screen("...but not mountlist.txt - a pity, really...");
2366    }
2367    else {
2368            /* Is this code really useful ??? */
2369        if (extract_mountlist_stub) {
2370            sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,
2371                    bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2372            run_program_and_log_output(command, FALSE);
2373        }
2374    }
2375
2376    sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
2377    run_program_and_log_output(command, FALSE);
2378    if (extract_mountlist_stub) {
2379        sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
2380        run_program_and_log_output(command, FALSE);
2381    }
2382    sprintf(command, "cp -f etc/raidtab /etc/");
2383    run_program_and_log_output(command, FALSE);
2384    if (extract_i_want_my_lvm) {
2385        sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
2386        run_program_and_log_output(command, FALSE);
2387    }
2388    g_backup_media_type = bkpinfo->backup_media_type;
2389    paranoid_free(device);
2390    paranoid_free(command);
2391    paranoid_free(tmp);
2392    paranoid_free(cfg_file);
2393    paranoid_free(mounted_cfgf_path);
2394    paranoid_free(mountpt);
2395    paranoid_free(ramdisk_fname);
2396    paranoid_free(mountlist_file);
2397    return (retval);
2398}
2399
2400/**************************************************************************
2401 *END_GET_CFG_FILE_FROM_ARCHIVE                                           *
2402 **************************************************************************/
2403
2404/* @} - end restoreUtilityGroup */
2405
2406
2407/***************************************************************************
2408 * F@                                                                      *
2409 * () -- Hugo Rabson                                  *
2410 *                                                                         *
2411 * Purpose:                                                                *
2412 *                                                                         *
2413 * Called by:                                                              *
2414 * Params:    -                      -                                     *
2415 * Returns:   0=success; nonzero=failure                                   *
2416 ***************************************************************************/
2417
2418
2419
2420void wait_until_software_raids_are_prepped(char *mdstat_file,
2421                                           int wait_for_percentage)
2422{
2423    struct raidlist_itself *raidlist;
2424    int unfinished_mdstat_devices = 9999, i;
2425    char *screen_message;
2426
2427    malloc_string(screen_message);
2428    raidlist = malloc(sizeof(struct raidlist_itself));
2429
2430    assert(wait_for_percentage <= 100);
2431    log_it("wait_until_software_raids_are_prepped");
2432    while (unfinished_mdstat_devices > 0) {
2433            // FIXME: Prefix '/dev/' should really be dynamic!
2434        if (parse_mdstat(raidlist, "/dev/")) {
2435            log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
2436            log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
2437            return;
2438        }
2439        for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) {
2440            if (raidlist->el[i].progress < wait_for_percentage) {
2441                unfinished_mdstat_devices++;
2442                if (raidlist->el[i].progress == -1) // delayed while another partition inits
2443                {
2444                    continue;
2445                }
2446                log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
2447                sprintf(screen_message, "Sync'ing %s",
2448                        raidlist->el[i].raid_device);
2449                open_evalcall_form(screen_message);
2450                while (raidlist->el[i].progress < wait_for_percentage) {
2451                    log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
2452                    update_evalcall_form(raidlist->el[i].progress);
2453                    sleep(2);
2454                    // FIXME: Prefix '/dev/' should really be dynamic!
2455                    if (parse_mdstat(raidlist, "/dev/")) {
2456                        break;
2457                    }
2458                }
2459                close_evalcall_form();
2460            }
2461        }
2462    }
2463    paranoid_free(screen_message);
2464    paranoid_free(raidlist);
2465}
2466
2467
Note: See TracBrowser for help on using the repository browser.