Changeset 171 in MondoRescue for trunk/mondo/mondo/mondoarchive/main.c
- Timestamp:
- Dec 8, 2005, 5:20:29 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondoarchive/main.c
r170 r171 1 /*************************************************************************** 2 main.c - description 3 ------------------- 4 begin : Fri Apr 19 16:40:35 EDT 2002 5 copyright : (C) 2002 by Stan Benoit 6 email : troff@nakedsoul.org 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 1 /* 2 * $Id$ 11 3 * * 12 4 * This program is free software; you can redistribute it and/or modify * … … 15 7 * (at your option) any later version. * 16 8 * * 17 ***************************************************************************/ 18 19 /** change log ****** MONDO-DEVEL 20 21 22 12/10 23 - disable stopping/starting of autofs 24 25 10/01 26 - update g_erase_tmpdir_and_scratchdir to delete user-specified tmpdir, scratchdir 27 28 06/19 29 - added AUX_VER 30 31 06/14/2004 32 - use mondorescue.iso, not mindi.iso 33 34 02/10/2004 35 - tell users where BusyBox's sources are 36 37 11/14/2003 38 - cleaned up logging at end# 39 40 10/23 41 - don't try to test-read tape ... That's already 42 handled by post_param_configuration() 43 44 10/19 45 - if your PATH var is too long, abort 46 47 09/23 48 - added some comments 49 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings() 50 and free_libmondo_global_strings() - which are in libmondo-tools.c 51 - better magicdev support 52 53 54 09/16 55 - delete /var/log/partimagehack-debug.log at start of main() 56 57 09/15 58 - added askbootloader 59 60 09/09 61 - if your tape is weird, I'll pause between backup and verify 62 - fixed silly bug in main() - re: say_at_end 63 64 01/01 - 08/31 65 - call 'dmesg -n1' at start, to shut the kernel logger up 66 - moved g_erase_tmpdir_and_scratchdir to common/newt-specific.c 67 - added 'don't panic' msg to start of logfile 68 - added 'nice(20)' to main() 69 - added lots of assert()'s and log_OS_error()'s 70 - clean-up (Hugo) 71 - make post_param_configuration() setup g_erase_tmpdir_and_scratchdir 72 - if --version then print & exit quickly 73 - re-run g_erase_tmpdir_and_scratchdir via system() at very end 74 75 Year: 2002 76 - if user goes root with 'su' instead of 'su -' then 77 workaround it by setting PATH correctly 78 - wipe mondoarchive.log at very beginning 79 - cleaned up code 80 - if changed.files.N exists then copy to changes.files for display 81 - run_program_and_log_output() now takes boolean operator to specify 82 whether it will log its activities in the event of _success_ 83 - added popup list of changed files 84 - removed 'beta-quality' warnings 85 - if kernel not found and mondo in graphics mode then popup and ask 86 for kernel path+filename 87 - fixed tmp[] 'too small' bug 88 - unmount and eject CD at end of verify cycle 89 - moved interactively_obtain...() to libmondo-stream.c 90 - wrote stuff to autodetect tape+cdrw+etc. 91 - renamed from main.c to mondo-archive.c 92 - fore+after warnings that this code is beta-quality 93 - abort if running from ramdisk 94 - remount floppy at end & unmount at start if Mandrake 95 - took out #debug stuff 96 - add 2> /dev/null to 'find' command 97 - add support for bkpinfo->nonbootable_backup 98 - add main function begin comment and debug conditional 99 compilation - Stan Benoit 100 - add debug statements to build a run tree. Stan Benoit 101 **** end change log **********/ 102 103 104 /** 105 * @file 9 *************************************************************************** 106 10 * The main file for mondoarchive. 107 11 */ … … 111 15 #include <pthread.h> 112 16 #endif 113 //#include <config.h>114 //#include "../../config.h"115 17 #include <stdio.h> 116 18 #include <stdlib.h> … … 141 43 extern char *g_tmpfs_mountpt; 142 44 extern char *g_erase_tmpdir_and_scratchdir; 143 extern char *g_cdrw_drive_is_here;144 static char *g_cdrom_drive_is_here = NULL;145 static char *g_dvd_drive_is_here = NULL;146 45 extern double g_kernel_version; 147 46 … … 211 110 ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2); 212 111 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted 213 // stop_autofs_if_necessary(); // for Xandros users214 112 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions 215 113 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way 216 114 } 217 218 115 219 116 … … 223 120 void distro_specific_kludges_at_end_of_mondoarchive() 224 121 { 225 // char tmp[500];226 122 log_msg(2, "Restarting magicdev if necessary"); 227 123 sync(); 228 124 restart_magicdev_if_necessary(); // for RH+Gnome users 229 125 230 log_msg(2, "Restarting autofs if necessary");231 sync();232 // restart_autofs_if_necessary(); // for Xandros users233 234 126 log_msg(2, "Restarting supermounts if necessary"); 235 127 sync(); … … 239 131 sync(); 240 132 unmount_boot_if_necessary(); // for Gentoo users 241 242 // log_msg( 2, "Cleaning up KDE desktop");243 // clean_up_KDE_desktop_if_necessary();244 133 } 245 246 247 /*-----------------------------------------------------------*/248 249 134 250 135 … … 257 142 struct s_bkpinfo *bkpinfo; 258 143 char *tmp; 259 int res, retval; 260 char *say_at_end; 144 int res = 0; 145 int retval = 0; 146 char *say_at_end = NULL; 261 147 262 148 /* Make sure I'm root; abort if not */ … … 277 163 278 164 malloc_libmondo_global_strings(); 279 malloc_string(tmp); 280 malloc_string(say_at_end); 281 282 res = 0; 283 retval = 0; 165 284 166 diffs = 0; 285 say_at_end[0] = '\0';286 167 unlink("/var/log/partimagehack-debug.log"); 287 168 printf("Initializing...\n"); … … 292 173 293 174 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */ 294 strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1); 295 tmp[MAX_STR_LEN - 1] = '\0'; 296 if (strlen(tmp) >= MAX_STR_LEN - 33) { 297 fatal_error 298 ("Your PATH environmental variable is too long. Please shorten it."); 299 } 300 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin"); 175 asprintf(&tmp, "/sbin:/usr/sbin:%s:/usr/local/sbin", getenv("PATH")); 301 176 setenv("PATH", tmp, 1); 177 paranoid_free(tmp); 302 178 303 179 /* Add the ARCH environment variable for ia64 purposes */ 304 strncpy(tmp, get_architecture(), MAX_STR_LEN - 1); 305 tmp[MAX_STR_LEN - 1] = '\0'; 306 setenv("ARCH", tmp, 1); 180 setenv("ARCH", get_architecture(), 1); 307 181 308 182 unlink(MONDO_LOGFILE); … … 339 213 if (argc == 4 && !strcmp(argv[1], "setfattr")) { 340 214 g_loglevel = 10; 341 // chdir("/tmp");342 215 g_text_mode = TRUE; 343 216 setup_newt_stuff(); … … 351 224 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 352 225 printf("in=%s; out=%s\n", argv[2], tmp); 226 paranoid_free(tmp); 353 227 finish(1); 354 228 } … … 368 242 if (argc == 4 && !strcmp(argv[1], "setfacl")) { 369 243 g_loglevel = 10; 370 // chdir("/tmp");371 244 g_text_mode = TRUE; 372 245 setup_newt_stuff(); … … 378 251 g_text_mode = TRUE; 379 252 setup_newt_stuff(); 380 if ( find_cdrw_device(tmp)) {253 if ((tmp = find_cdrw_device()) == NULL) { 381 254 printf("Failed to find CDR-RW drive\n"); 382 255 } else { 383 256 printf("CD-RW is at %s\n", tmp); 384 257 } 385 tmp[0] = '\0'; 386 if (find_cdrom_device(tmp, atoi(argv[2]))) { 258 paranoid_free(tmp); 259 260 if ((tmp = find_cdrom_device(FALSE)) == NULL) { 387 261 printf("Failed to find CD-ROM drive\n"); 388 262 } else { 389 263 printf("CD-ROM is at %s\n", tmp); 390 264 } 265 paranoid_free(tmp); 391 266 finish(0); 392 267 } … … 396 271 g_text_mode = TRUE; 397 272 setup_newt_stuff(); 398 if ( find_dvd_device(tmp, atoi(argv[2]))) {273 if ((tmp = find_dvd_device()) == NULL) { 399 274 printf("Failed to find DVD drive\n"); 400 275 } else { 401 276 printf("DVD is at %s\n", tmp); 402 277 } 278 paranoid_free(tmp); 403 279 finish(0); 404 280 } … … 451 327 log_to_screen 452 328 ("BusyBox's sources are available from http://www.busybox.net"); 453 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,454 bkpinfo->scratchdir);455 329 456 330 /* If we're meant to backup then backup */ 457 331 if (bkpinfo->backup_data) { 458 /*459 log_to_screen("INFERNAL PORPOISES");460 res = archive_this_fileset_with_star(bkpinfo, "/tmp/filelist.0", "/tmp/0.star.bz2", 0);461 log_to_screen("atfws returned %d", res);462 finish(0);463 */464 332 res = backup_data(bkpinfo); 465 333 retval += res; 466 334 if (res) { 467 strcat(say_at_end,335 asprintf(&say_at_end, 468 336 "Data archived. Please check the logs, just as a precaution. "); 469 337 } else { 470 strcat(say_at_end, "Data archived OK. ");338 asprintf(&say_at_end, "Data archived OK. "); 471 339 } 472 340 } … … 476 344 res = verify_data(bkpinfo); 477 345 if (res < 0) { 478 sprintf(tmp, "%d difference%c found.", -res,346 asprintf(&say_at_end, "%d difference%c found.", -res, 479 347 (-res != 1) ? 's' : ' '); 480 strcat(say_at_end, tmp);481 log_to_screen(tmp);482 348 res = 0; 483 349 } … … 485 351 } 486 352 487 /* Offer to write floppy disk images to physical disks */353 /* Offer to write floppy disk images to physical disks */ 488 354 if (bkpinfo->backup_data && !g_skip_floppies) { 489 355 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 490 356 retval += res; 491 // res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo); 492 // retval += res; 493 } 494 495 /* Report result of entire operation (success? errors?) */ 496 if (!retval) { 357 } 358 359 /* Report result of entire operation (success? errors?) */ 360 if (retval == 0) { 497 361 mvaddstr_and_log_it(g_currentY++, 0, 498 362 "Backup and/or verify ran to completion. Everything appears to be fine."); … … 523 387 } 524 388 log_to_screen(say_at_end); 525 sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 389 paranoid_free(say_at_end); 390 391 asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 526 392 run_program_and_log_output(tmp, TRUE); 393 paranoid_free(tmp); 394 395 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 396 bkpinfo->scratchdir); 527 397 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE); 528 398 … … 531 401 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 532 402 system("rm -Rf /tmp.mondo.* /mondo.scratch.*"); 533 if ( !retval) {403 if (retval == 0) { 534 404 printf("Mondoarchive ran OK.\n"); 535 405 } else { … … 542 412 system(g_erase_tmpdir_and_scratchdir); 543 413 free_libmondo_global_strings(); 544 paranoid_free(say_at_end);545 paranoid_free(tmp);546 414 paranoid_free(bkpinfo); 547 415 548 416 unlink("/tmp/filelist.full"); 549 417 unlink("/tmp/filelist.full.gz"); 550 551 if (!g_cdrom_drive_is_here) {552 log_msg(10, "FYI, g_cdrom_drive_is_here was never used");553 }554 if (!g_dvd_drive_is_here) {555 log_msg(10, "FYI, g_dvd_drive_is_here was never used");556 }557 418 558 419 run_program_and_log_output("date", 1);
Note:
See TracChangeset
for help on using the changeset viewer.