Changeset 171 in MondoRescue for trunk/mondo/mondo/mondoarchive
- Timestamp:
- Dec 8, 2005, 5:20:29 PM (18 years ago)
- Location:
- trunk/mondo/mondo/mondoarchive
- Files:
-
- 4 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); -
trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h
r59 r171 5 5 extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 6 6 extern int process_switches(struct s_bkpinfo *bkpinfo, 7 char flag_val[128][MAX_STR_LEN],7 char *flag_val[128], 8 8 bool flag_set[128]); 9 9 extern int retrieve_switches_from_command_line(int argc, char *argv[], 10 10 char 11 flag_val[128][MAX_STR_LEN],11 *flag_val[128], 12 12 bool flag_set[128]); 13 13 extern void help_screen(); -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r146 r171 1 1 /*************************************************************************** 2 mondo-cli.c 3 ------------------- 4 begin : Fri Apr 19 16:40:35 EDT 2002 5 copyright : (C) 2002 Mondo Hugo Rabson 6 email : Hugo Rabson <hugorabson@msn.com> 7 edited by : by Stan Benoit 4/2002 8 email : troff@nakedsoul.org 9 cvsid : $Id$ 10 ***************************************************************************/ 11 12 /*************************************************************************** 13 * * 14 * This program is free software; you can redistribute it and/or modify * 15 * it under the terms of the GNU General Public License as published by * 16 * the Free Software Foundation; either version 2 of the License, or * 17 * (at your option) any later version. * 18 * * 19 ***************************************************************************/ 20 21 /*************************************************************************** 22 UPDATE LOG 23 24 25 08/04 26 - if user specifies a dumb -T value, abort 27 28 07/22 29 - handle -Q sensibly (don't abort if only -Q supplied) 30 31 07/17 32 - better checking of NFS dir's validity 33 34 06/19 35 - added AUX_VER 36 37 04/17 38 - added '-b' support 39 04/03 40 - added star support 41 42 02/06 43 - fixed "Please give /dev entry" error msg 44 45 01/20/2004 46 - added 2.6.x-kernel "device = /dev/...." support to param reader 47 - better handling of SCSI and /dev entries 48 - touch /boot/boot.b if necessary 49 50 09/26/2003 51 - typo in command-line handling of 'r' 52 53 09/25 54 - added DVD write support 55 56 09/24 57 - if tape backup (-t) but user doesn't specify tape drive then 58 make an educated guess using find_tape_device_and_size() 59 60 09/18 61 - insist on partimagehack being present if -x found 62 63 09/16 64 - added support for multiple -I's and -E's in call to mondoarchive 65 - the '-D' flag doesn't take a value now 66 67 07/14 68 - fatal error if -E too short 69 70 05/14 71 - if 'n' and user doesn't have rights to write to output dir 72 then error out 73 74 05/05 75 - added Joshua Oreman's FreeBSD patches 76 77 05/04 78 - added Herman Kuster's multi-level bkp patch 79 80 05/02 81 - write errors to screen, not just to log 82 83 04/25 84 - added lots of assert()'s and log_OS_error()'s 85 86 04/21 87 - line 570 --- resolve boot device if softlink 88 89 04/08 90 - changed a bunch of fprintf(stderr,...)'s to log_it()'s 91 - fixed final / removal in retrieve_switches_from_command_line() 92 93 04/04 94 - added -e 95 96 03/15 97 - reject relative paths if -d flag (Alessandro Polverini) 98 99 01/02/2003 100 - added -J flag (to let user specify incoming filelist) 101 102 12/13/2002 103 - various strcpy() calls replaced with strncpy() calls 104 105 12/10 106 - added g_loglevel 107 108 11/25 109 - line 614 --- if commmand-line param ends in '/' then drop that '/' 110 111 11/19 112 - rewrote finish() to kill processes more softly 113 - if user calls with '-l RAW' then 114 115 09/01 - 09/30 116 - added -N to let user exclude all NFS-related mounts and devices 117 - run_program_and_log_output() now takes boolean operator to specify 118 whether it will log its activities in the event of _success_ 119 120 08/01 - 08/31 121 - if no device specified when backing up to tape streamer then assume /dev/st0 122 - abort if tape user specifies tape size (just for testing porpoises) 123 - tape users no longer need to specify tape size 124 - added some comments 125 - added bkpinfo->backup_media_type 126 - renamed from mondo-archive.c to mondo-cli.c 127 128 07/01 - 07/31 129 - better check for mkfs.vfat 130 - more sanity-checking for -d flag 131 - if isodir does not exist then abort 132 - removed "the rest are..." comment from log 133 - do not permit '-H' and '-t' in the same command line 134 - if not '-o' then insist on vfat-friendly kernel 135 136 06/01 - 06/30 137 - added signal-trapping 138 - added '-W' (won't make bootable CD or floppies) flag 139 - added missing 'j++' to -s switch's code 140 - expanded -s switch 141 - added -u switch 142 - if dvdrecord exists and cdrecord doesn't then use 143 dvdrecord instead of cdrecord 144 145 04/01 - 04/30 146 - if CD-ROM is supermounted then unmount, run, and remount 147 - replace MONDO_VERSION #define with VERSION from ../config.h 148 - if CD-ROM is mounted at start then abort 149 - improved homedir-locating code 150 - improved "backup will occupy N CD's" calculation a bit 151 - added -m (manual CD tray) flag 152 153 154 *******************************************************************/ 155 156 /** 157 * @file 2 * $Id$ 3 * 158 4 * Functions for handling command-line arguments passed to mondoarchive. 159 5 */ … … 180 26 extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks 181 27 extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ????? 182 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];183 28 extern char g_tmpfs_mountpt[MAX_STR_LEN]; 184 29 extern bool g_sigpipe; … … 245 90 /*@ buffers *************** */ 246 91 char *tmp; 247 char flag_val[128][MAX_STR_LEN];92 char *flag_val[128]; 248 93 bool flag_set[128]; 249 94 250 malloc_string(tmp);251 95 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 96 252 97 for (i = 0; i < 128; i++) { 253 flag_val[i] [0] = '\0';98 flag_val[i] = NULL; 254 99 flag_set[i] = FALSE; 255 100 } 256 // strcpy (bkpinfo->tmpdir, "/root/images/mondo");257 // strcpy (bkpinfo->scratchdir, "/home");258 101 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 259 102 bkpinfo->media_size[j] = 650; … … 275 118 for (i = 0; i < 128; i++) { 276 119 if (flag_set[i]) { 277 sprintf(tmp, "-%c %s", i, flag_val[i]);120 asprintf(&tmp, "-%c %s", i, flag_val[i]); 278 121 log_msg(3, tmp); 122 paranoid_free(tmp); 279 123 } 280 124 } 281 125 // } 282 sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);126 asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 283 127 paranoid_system(tmp); 284 sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 128 paranoid_free(tmp); 129 130 asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 285 131 paranoid_system(tmp); 132 paranoid_free(tmp); 133 286 134 sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", 287 135 random() % 32767); 288 136 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), 289 137 "/mondo.scratch.%ld", random() % 32767); 290 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 138 139 asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 291 140 paranoid_system(tmp); 292 sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir); 141 paranoid_free(tmp); 142 143 asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir); 293 144 paranoid_system(tmp); 145 paranoid_free(tmp); 146 294 147 if (bkpinfo->nfs_mount[0] != '\0') { 295 148 store_nfs_config(bkpinfo); 296 149 } 297 paranoid_free(tmp);298 150 return (retval); 299 151 } 300 301 302 152 303 153 … … 312 162 { 313 163 int j; 314 char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN]; 164 char *tmp; 165 char *p; 166 char *q; 167 char *comment; 315 168 316 169 assert(bkpinfo != NULL); … … 320 173 for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ','); 321 174 j++, p = strchr(p, ',') + 1) { 322 strncpy(tmp, p, MAX_STR_LEN); 323 *(strchr(tmp, ',')) = '\0'; 175 asprintf(&tmp, p); 176 q = strchr(tmp, ','); 177 if (q != NULL) { 178 *q = '\0'; 179 } 324 180 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp); 325 sprintf(comment, "media_size[%d] = %ld", j, 181 paranoid_free(tmp); 182 183 asprintf(&comment, "media_size[%d] = %ld", j, 326 184 bkpinfo->media_size[j]); 327 185 log_msg(3, comment); 186 paranoid_free(comment); 328 187 } 329 188 for (; j <= MAX_NOOF_MEDIA; j++) { 330 189 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p); 331 190 } 332 // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];333 191 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 334 192 if (bkpinfo->media_size[j] <= 0) { … … 339 197 return (0); 340 198 } 341 342 199 343 200 … … 354 211 int 355 212 process_switches(struct s_bkpinfo *bkpinfo, 356 char flag_val[128][MAX_STR_LEN], bool flag_set[128])213 char *flag_val[128], bool flag_set[128]) 357 214 { 358 215 … … 364 221 /*@ buffers ** */ 365 222 char *tmp; 223 char *tmp2; 366 224 char *psz; 367 225 … … 374 232 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 375 233 376 /* compulsory */234 /* compulsory */ 377 235 i = flag_set['c'] + flag_set['i'] + flag_set['n'] + 378 236 flag_set['t'] + flag_set['u'] + flag_set['r'] + … … 502 360 ("You must use -L with -C. Therefore I am setting it for you."); 503 361 flag_set['L'] = 1; 504 flag_val['L'] [0] = '\0';362 flag_val['L'] = NULL; 505 363 } 506 364 } else { 507 365 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 508 366 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 509 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );510 367 if (flag_set['c']) { 511 368 bkpinfo->cdrw_speed = atoi(flag_val['c']); … … 546 403 } 547 404 if (!flag_set['d']) { 548 if ( !find_dvd_device(flag_val['d'], FALSE)) {405 if ((flag_val['d'] = find_dvd_device()) != NULL) { 549 406 flag_set['d'] = TRUE; 550 407 log_to_screen("I guess DVD drive is at %s", flag_val['d']); … … 564 421 } 565 422 if (!flag_set['s']) { 566 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 567 strcat(flag_val['s'], "m"); 423 asprintf(&flag_val['s'], "%dm", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 568 424 log_to_screen 569 425 ("You did not specify a size (-s) for DVD. I'm guessing %s.", … … 571 427 flag_set['s'] = 1; 572 428 } 573 /*574 if (flag_set['Z']) {575 bkpinfo->blank_dvd_first = TRUE;576 }577 */578 429 } 579 430 … … 612 463 } 613 464 if (flag_set['n']) { 614 strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN); 465 asprintf(&tmp, flag_val['n']); 466 bkpinfo->nfs_mount = tmp; 615 467 if (!flag_set['d']) { 616 strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); 468 asprintf(&tmp, "/"); 469 bkpinfo->nfs_remote_dir = tmp; 617 470 } 618 471 asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 619 472 bkpinfo->nfs_mount); 620 strncpy(bkpinfo->isodir, 621 call_program_and_get_last_line_of_output(tmp), 622 MAX_STR_LEN / 4); 473 asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp)); 474 bkpinfo->isodir = tmp2; 623 475 paranoid_free(tmp); 624 476 … … 714 566 } 715 567 if (flag_set['x']) { 716 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4); 568 asprintf(&tmp, flag_val['x']); 569 bkpinfo->image_devs = tmp; 717 570 if (run_program_and_log_output("which partimagehack", 2)) { 718 571 fatal_error("Please install partimagehack RPM/tarball."); … … 723 576 } 724 577 if (flag_set['k']) { 725 strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 726 if (!strcmp(bkpinfo->kernel_path, "failsafe")) { 727 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 728 } 729 if (strcmp(bkpinfo->kernel_path, "FAILSAFE") 730 && !does_file_exist(bkpinfo->kernel_path)) { 731 retval++; 732 asprintf(&tmp, 578 if (strcasecmp(flag_val['k'], "FAILSAFE")) { 579 asprintf(&tmp, "FAILSAFE"); 580 bkpinfo->kernel_path = tmp; 581 582 if (!does_file_exist(bkpinfo->kernel_path)) { 583 retval++; 584 asprintf(&tmp, 733 585 "You specified kernel '%s', which does not exist\n", 734 586 bkpinfo->kernel_path); 735 log_to_screen(tmp); 736 paranoid_free(tmp); 587 log_to_screen(tmp); 588 paranoid_free(tmp); 589 } 590 } else { 591 asprintf(&tmp, flag_val['k']); 592 bkpinfo->kernel_path = tmp; 737 593 } 738 594 } 739 595 if (flag_set['p']) { 740 strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4); 596 asprintf(&tmp, bkpinfo->prefix); 597 bkpinfo->prefix = tmp; 741 598 } 742 599 … … 744 601 if (flag_set['d']) { /* backup directory (if ISO/NFS) */ 745 602 if (flag_set['i']) { 746 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); 603 asprintf(&tmp, flag_val['d']); 604 bkpinfo->isodir = tmp; 747 605 asprintf(&tmp, "ls -l %s", bkpinfo->isodir); 748 606 if (run_program_and_log_output(tmp, FALSE)) { … … 752 610 paranoid_free(tmp); 753 611 } else if (flag_set['n']) { 754 strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 612 asprintf(&tmp, flag_val['d']); 613 bkpinfo->nfs_remote_dir = tmp; 755 614 } else { /* backup device (if tape/CD-R/CD-RW) */ 756 615 757 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);616 paranoid_alloc(bkpinfo->media_device, flag_val['d']); 758 617 } 759 618 } … … 782 641 log_to_screen("User opted to cancel."); 783 642 } 784 } else if (find_cdrw_device(bkpinfo->media_device)) { 643 } else if ((tmp = find_cdrw_device()) == NULL) { 644 paranoid_free(bkpinfo->media_device); 645 bkpinfo->media_device = tmp; 785 646 retval++; 786 647 log_to_screen … … 788 649 } else { 789 650 flag_set['d'] = TRUE; 790 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);651 asprintf(&flag_val['d'], bkpinfo->media_device); 791 652 } 792 653 } … … 805 666 } 806 667 if (flag_set['S']) { 807 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],668 asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'], 808 669 random() % 32768); 670 bkpinfo->scratchdir = tmp; 809 671 } 810 672 if (flag_set['T']) { 811 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],673 asprintf(&tmp, "%s/tmp.mondo.%ld", flag_val['T'], 812 674 random() % 32768); 675 bkpinfo->tmpdir = tmp; 813 676 asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']); 814 677 if (run_program_and_log_output(tmp, 1)) { … … 831 694 } 832 695 if (flag_set['A']) { 833 strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 696 asprintf(&tmp, flag_val['A']); 697 bkpinfo->call_after_iso = tmp; 834 698 } 835 699 if (flag_set['B']) { 836 strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 700 asprintf(&tmp, flag_val['B']); 701 bkpinfo->call_before_iso = tmp; 837 702 } 838 703 if (flag_set['F']) { … … 864 729 if (flag_set['f']) { 865 730 tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']); 866 strncpy(bkpinfo->boot_device, tmp, 867 MAX_STR_LEN / 4); 731 bkpinfo->boot_device = tmp; 868 732 } 869 733 if (flag_set['Q']) { … … 880 744 881 745 if (flag_set['P']) { 882 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 746 asprintf(&tmp, flag_val['P']); 747 bkpinfo->postnuke_tarball = tmp; 883 748 } 884 749 if (flag_set['L']) { … … 894 759 && 895 760 !run_program_and_log_output 896 (" cat /etc/issue.net | grep -i suse| grep 64", TRUE)) {761 ("grep -i suse /etc/issue.net | grep 64", TRUE)) { 897 762 bkpinfo->make_cd_use_lilo = TRUE; 898 763 log_to_screen … … 963 828 int 964 829 retrieve_switches_from_command_line(int argc, char *argv[], 965 char flag_val[128][MAX_STR_LEN],830 char *flag_val[128], 966 831 bool flag_set[128]) 967 832 { 968 833 /*@ ints ** */ 969 834 int opt = 0; 970 char tmp[MAX_STR_LEN];835 char *tmp; 971 836 int i = 0; 972 837 int len; … … 979 844 980 845 for (i = 0; i < 128; i++) { 981 flag_val[i] [0] = '\0';846 flag_val[i] = NULL; 982 847 flag_set[i] = FALSE; 983 848 } … … 992 857 if (flag_set[optopt]) { 993 858 bad_switches = TRUE; 994 sprintf(tmp, "Switch -%c previously defined as %s\n", opt,859 asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, 995 860 flag_val[i]); 996 861 log_to_screen(tmp); 862 paranoid_free(tmp); 997 863 } else { 998 864 flag_set[opt] = TRUE; … … 1008 874 if (strchr(flag_val[opt], '/') 1009 875 && flag_val[opt][0] != '/') { 1010 sprintf(tmp,876 asprintf(&tmp, 1011 877 "-%c flag --- must be absolute path --- '%s' isn't absolute", 1012 878 opt, flag_val[opt]); 1013 879 log_to_screen(tmp); 880 paranoid_free(tmp); 1014 881 bad_switches = TRUE; 1015 882 } 1016 883 } 1017 strcpy(flag_val[opt], optarg);884 asprintf(&flag_val[opt], optarg); 1018 885 } 1019 886 } … … 1022 889 for (i = optind; i < argc; i++) { 1023 890 bad_switches = TRUE; 1024 sprintf(tmp, "Invalid arg -- %s\n", argv[i]);891 asprintf(&tmp, "Invalid arg -- %s\n", argv[i]); 1025 892 log_to_screen(tmp); 893 paranoid_free(tmp); 1026 894 } 1027 895 return (bad_switches); … … 1047 915 void terminate_daemon(int sig) 1048 916 { 1049 char tmp[64]; 1050 char tmp2[MAX_STR_LEN]; 1051 // char command[512]; 1052 // pid_t pid; 917 char *tmp; 918 char *tmp2; 1053 919 1054 920 switch (sig) { 1055 921 case SIGINT: 1056 sprintf(tmp, "SIGINT");1057 strcpy(tmp2, "You interrupted me :-)");922 asprintf(&tmp, "SIGINT signal received from OS"); 923 asprintf(&tmp2, "You interrupted me :-)"); 1058 924 break; 1059 925 case SIGKILL: 1060 sprintf(tmp, "SIGKILL");1061 strcpy(tmp2,926 asprintf(&tmp, "SIGKILL signal received from OS"); 927 asprintf(&tmp2, 1062 928 "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1063 929 break; 1064 930 case SIGTERM: 1065 sprintf(tmp, "SIGTERM");1066 strcpy(tmp2, "Got terminate signal");931 asprintf(&tmp, "SIGTERM signal received from OS"); 932 asprintf(&tmp2, "Got terminate signal"); 1067 933 break; 1068 934 case SIGHUP: 1069 sprintf(tmp, "SIGHUP");1070 strcpy(tmp2, "Hangup on line");935 asprintf(&tmp, "SIGHUP signal received from OS"); 936 asprintf(&tmp2, "Hangup on line"); 1071 937 break; 1072 938 case SIGSEGV: 1073 sprintf(tmp, "SIGSEGV");1074 strcpy(tmp2,939 asprintf(&tmp, "SIGSEGV signal received from OS"); 940 asprintf(&tmp2, 1075 941 "Internal programming error. Please send a backtrace as well as your log."); 1076 942 break; 1077 943 case SIGPIPE: 1078 sprintf(tmp, "SIGPIPE");1079 strcpy(tmp2, "Pipe was broken");944 asprintf(&tmp, "SIGPIPE signal received from OS"); 945 asprintf(&tmp2, "Pipe was broken"); 1080 946 break; 1081 947 case SIGABRT: 1082 sprintf(tmp, "SIGABRT");1083 sprintf(tmp2,948 asprintf(&tmp, "SIGABRT signal received from OS"); 949 asprintf(&tmp2, 1084 950 "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1085 951 break; 1086 952 default: 1087 sprintf(tmp, "(Unknown)");1088 }1089 1090 strcat(tmp, " signal received from OS"); 953 asprintf(&tmp, "(Unknown)"); 954 asprintf(&tmp2, "(Unknown)"); 955 } 956 1091 957 log_to_screen(tmp); 1092 958 log_to_screen(tmp2); 959 paranoid_free(tmp); 960 paranoid_free(tmp2); 1093 961 if (sig == SIGABRT) { 1094 962 sleep(10); … … 1099 967 finish(254); // just in case 1100 968 } 1101 1102 1103 969 1104 970 … … 1122 988 } 1123 989 } 1124 1125 1126 990 1127 991 -
trunk/mondo/mondo/mondoarchive/mondo-cli.h
r59 r171 7 7 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 8 8 int process_switches(struct s_bkpinfo *bkpinfo, 9 char flag_val[128][MAX_STR_LEN], bool flag_set[128]);9 char *flag_val[128], bool flag_set[128]); 10 10 int retrieve_switches_from_command_line(int argc, char *argv[], 11 char flag_val[128][MAX_STR_LEN],11 char *flag_val[128], 12 12 bool flag_set[128]); 13 13 void help_screen();
Note:
See TracChangeset
for help on using the changeset viewer.