source: branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c @ 3600

Last change on this file since 3600 was 3600, checked in by bruno, 3 years ago

Use option -T for df for more details in logs where appropriate

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