source: MondoRescue/branches/2.2.6/mondo/src/mondorestore/mondo-rstr-tools.c@ 1934

Last change on this file since 1934 was 1934, checked in by Bruno Cornec, 16 years ago

Handle part of #250

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