Changeset 3193 in MondoRescue for branches/3.2/mondo/src/mondorestore
- Timestamp:
- Sep 29, 2013, 9:31:34 AM (12 years ago)
- Location:
- branches/3.2/mondo/src/mondorestore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c
r3185 r3193 43 43 44 44 /** needs malloc *******/ 45 char *checksum_ptr; 46 char *original_cksum_ptr; 47 char *bigfile_fname_ptr; 48 char *tmp_ptr = NULL; 49 char *command_ptr; 50 51 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 45 char *checksum = NULL; 46 char *original_cksum = NULL; 47 char *bigfile_fname = NULL; 48 char *tmp = NULL; 49 char *command = NULL; 52 50 53 51 char *p; … … 56 54 57 55 struct s_filename_and_lstat_info biggiestruct; 58 59 malloc_string(checksum);60 malloc_string(original_cksum);61 malloc_string(bigfile_fname);62 malloc_string(tmp);63 malloc_string(command);64 malloc_string(checksum_ptr);65 malloc_string(original_cksum_ptr);66 malloc_string(bigfile_fname_ptr);67 malloc_string(command_ptr);68 56 69 57 /********************************************************************* … … 71 59 *********************************************************************/ 72 60 assert(bkpinfo != NULL); 73 memset(checksum_ptr, '\0', sizeof(checksum));74 memset(original_cksum_ptr, '\0', sizeof(original_cksum));75 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));76 memset(command_ptr, '\0', sizeof(command));77 61 /** end **/ 78 62 … … 81 65 insist_on_this_cd_number((++g_current_media_number)); 82 66 } else { 83 mr_asprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob."); 84 log_msg(2, tmp_ptr); 85 paranoid_free(tmp_ptr); 67 log_msg(2, "No CD's left. No biggiefiles left. No prob, Bob."); 86 68 return (0); 87 69 } 88 70 } 89 71 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 90 mr_asprintf(tmp_ptr, "Cannot open bigfile %ld (%s)'s info file", bigfileno + 1, bigfile_fname_ptr); 91 log_to_screen(tmp_ptr); 92 paranoid_free(tmp_ptr); 72 log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1); 93 73 return (1); 94 74 } … … 98 78 paranoid_fclose(fin); 99 79 100 strcpy(checksum_ptr, biggiestruct.checksum); 101 strcpy(bigfile_fname_ptr, biggiestruct.filename); 102 80 81 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename); 103 82 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 83 mr_asprintf(checksum, "%s", biggiestruct.checksum); 104 84 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 105 85 106 86 if (!g_text_mode) { 107 mr_asprintf(tmp _ptr, "Comparing %s", bigfile_fname_ptr);108 newtDrawRootText(0, 22, tmp _ptr);109 paranoid_free(tmp_ptr);87 mr_asprintf(tmp, "Comparing %s", bigfile_fname); 88 newtDrawRootText(0, 22, tmp); 89 mr_free(tmp); 110 90 newtRefresh(); 111 91 } 112 if (!checksum[0]) { 113 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 114 } 115 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 116 strcpy(original_cksum_ptr, "IGNORE"); 117 } else { 118 sprintf(command_ptr, 119 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", 120 MNT_RESTORING, bigfile_fname_ptr); 121 } 122 log_msg(2, command_ptr); 123 mr_asprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 124 paranoid_system(tmp_ptr); 125 paranoid_free(tmp_ptr); 126 127 if (system(command_ptr)) { 92 if (checksum == NULL]) { 93 log_msg(2, "Warning - %s has no checksum", bigfile_fname); 94 } 95 if (!strncmp(bigfile_fname, "/dev/", 5)) { 96 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname); 97 mr_free(checksum); 98 mr_free(bigfile_fname); 99 return (1); 100 } 101 102 mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname); 103 log_msg(2, command); 104 i = system(command); 105 mr_free(command); 106 107 mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 108 paranoid_system(tmp); 109 mr_free(tmp); 110 111 if (i) { 128 112 log_OS_error("Warning - command failed"); 129 original_cksum[0] = '\0'; 113 mr_free(checksum); 114 mr_free(bigfile_fname); 130 115 return (1); 131 116 } else { 132 117 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 133 log_msg(2, 134 "Unable to open /tmp/md5sum.txt; can't get live checksum");135 original_cksum[0] = '\0';118 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum"); 119 mr_free(checksum); 120 mr_free(bigfile_fname); 136 121 return (1); 137 122 } else { 138 if (fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin)) { 139 // FIXME 140 } 123 mr_getline(original_cksum, fin); 141 124 paranoid_fclose(fin); 142 for (i = strlen(original_cksum _ptr);125 for (i = strlen(original_cksum); 143 126 i > 0 && original_cksum[i - 1] < 32; i--); 144 127 original_cksum[i] = '\0'; 145 p = (char *) strchr(original_cksum_ptr, ' ');128 p = strchr(original_cksum, ' '); 146 129 if (p) { 147 130 *p = '\0'; … … 149 132 } 150 133 } 151 mr_asprintf(tmp _ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);152 if ( !strcmp(checksum_ptr, original_cksum_ptr) != 0) {153 mr_strcat(tmp _ptr, " ... OK");154 } else { 155 mr_strcat(tmp _ptr, "... changed");134 mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname); 135 if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) { 136 mr_strcat(tmp, " ... OK"); 137 } else { 138 mr_strcat(tmp, "... changed"); 156 139 retval++; 157 140 } 158 log_msg(1, tmp_ptr); 159 paranoid_free(tmp_ptr); 141 mr_free(checksum); 142 mr_free(original_cksum); 143 144 log_msg(1, tmp); 145 mr_free(tmp); 160 146 161 147 if (retval) { … … 163 149 fatal_error("Cannot openout changed.txt"); 164 150 } 165 fprintf(fout, "%s\n", bigfile_fname _ptr);151 fprintf(fout, "%s\n", bigfile_fname); 166 152 paranoid_fclose(fout); 167 153 } 168 169 paranoid_free(original_cksum_ptr); 170 paranoid_free(original_cksum); 171 paranoid_free(bigfile_fname_ptr); 172 paranoid_free(bigfile_fname); 173 paranoid_free(checksum_ptr); 174 paranoid_free(checksum); 175 paranoid_free(command_ptr); 176 paranoid_free(command); 177 paranoid_free(tmp); 154 mr_free(bigfile_fname); 178 155 179 156 return (retval); … … 194 171 int res; 195 172 long noof_biggiefiles, bigfileno = 0; 196 char tmp[MAX_STR_LEN];173 char *tmp = NULL; 197 174 198 175 log_msg(1, "Comparing biggiefiles"); … … 215 192 noof_biggiefiles); 216 193 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 217 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);194 mr_asprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 218 195 log_msg(1, tmp); 219 196 update_progress_form(tmp); 197 mr_free(tmp); 198 220 199 res = compare_a_biggiefile(bigfileno); 221 200 retval += res; … … 253 232 254 233 /*** needs malloc *********/ 255 char *command , *tmp, *filelist_name, *logfile,256 *compressor_exe;234 char *command = NULL; 235 char *tmp = NULL; 257 236 char *archiver_exe = NULL; 258 259 malloc_string(command); 260 malloc_string(tmp); 261 malloc_string(filelist_name); 262 malloc_string(logfile); 263 malloc_string(compressor_exe); 237 char *tmp1 = NULL; 238 char *logfile = NULL; 239 char *compressor_exe = NULL; 264 240 265 241 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 266 242 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 267 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 268 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 269 current_tarball_number); 243 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number); 270 244 271 245 if (strstr(tarball_fname, ".bz2")) { 272 strcpy(compressor_exe, "bzip2"); 246 mr_asprintf(compressor_exe, "bzip2"); 247 } else if (strstr(tarball_fname, ".lzma")) { 248 mr_asprintf(compressor_exe, "lzma"); 273 249 } else if (strstr(tarball_fname, ".gz")) { 274 strcpy(compressor_exe, "gzip");250 mr_asprintf(compressor_exe, "gzip"); 275 251 } else if (strstr(tarball_fname, ".lzo")) { 276 strcpy(compressor_exe, "lzop"); 277 } else { 278 compressor_exe[0] = '\0'; 252 mr_asprintf(compressor_exe, "lzop"); 279 253 } 280 254 … … 285 259 } 286 260 287 if (compressor_exe [0]) {288 strcpy(tmp, compressor_exe);261 if (compressor_exe) { 262 mr_asprintf(tmp, "%s", compressor_exe); 289 263 if (!find_home_of_exe(tmp)) { 264 mr_free(tmp); 265 mr_free(compressor_exe); 266 mr_free(archiver_exe); 290 267 fatal_error("(compare_a_tarball) Compression program missing"); 291 268 } 292 if (use_star) // star 293 { 269 mr_free(tmp); 270 271 if (use_star) { 294 272 if (!strcmp(compressor_exe, "bzip2")) { 295 273 mr_strcat(archiver_exe, " -bz"); 296 274 } else { 297 fatal_error 298 ("(compare_a_tarball) Please use only bzip2 with star"); 275 mr_free(compressor_exe); 276 mr_free(archiver_exe); 277 fatal_error("(compare_a_tarball) Please use only bzip2 with star"); 299 278 } 300 } else // afio 301 { 302 sprintf(compressor_exe, "-P %s -Z", tmp); 303 } 304 } 305 // star -diff H=star -bz file=.... 279 } else { 280 // afio 281 mr_asprintf(tmp, "%s", compressor_exe); 282 mr_free(compressor_exe); 283 mr_asprintf(compressor_exe, "-P %s -Z", tmp); 284 mr_free(tmp); 285 } 286 } 306 287 307 288 #ifdef __FreeBSD__ … … 310 291 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 311 292 #endif 312 if (use_star) // doesn't use compressor_exe 313 { 314 sprintf(command, 315 "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", 316 archiver_exe, tarball_fname, logfile, logfile); 317 } else { 318 sprintf(command, 319 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 320 archiver_exe, 321 TAPE_BLOCK_SIZE, 322 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 323 } 324 paranoid_free(archiver_exe); 293 mr_asprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 294 295 if (use_star) { 296 // doesn't use compressor_exe 297 mr_asprintf(command, "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile); 298 } else { 299 mr_asprintf(command, "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", archiver_exe, TAPE_BLOCK_SIZE, BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 300 } 301 mr_free(compressor_exe); 302 mr_free(archiver_exe); 325 303 326 304 #undef BUFSIZE … … 330 308 if (res) { 331 309 log_OS_error(command); 332 sprintf(tmp, "Warning - afio returned error = %d", res); 333 log_msg(2, tmp); 334 } 310 log_msg(2, "Warning - afio returned error = %d", res); 311 } 312 mr_free(command); 313 335 314 if (length_of_file(logfile) > 5) { 336 sprintf(command, 337 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", 338 logfile); 315 mr_asprintf(command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile); 339 316 paranoid_system(command); 317 mr_free(command); 318 340 319 archiver_errors = count_lines_in_file(logfile); 341 320 } else { 342 321 archiver_errors = 0; 343 322 } 344 sprintf(tmp, "%ld difference%c in fileset #%d ",345 archiver_errors, (archiver_errors != 1) ? 's' : ' ',346 current_tarball_number);347 323 if (archiver_errors) { 348 sprintf(tmp, 349 "Differences found while processing fileset #%d ", 350 current_tarball_number); 351 log_msg(1, tmp); 324 log_msg(1, "%ld difference%c in fileset #%d ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 352 325 } 353 326 unlink(logfile); 354 paranoid_free(command); 355 paranoid_free(tmp); 356 paranoid_free(filelist_name); 357 paranoid_free(logfile); 358 paranoid_free(compressor_exe); 327 mr_free(logfile); 328 359 329 return (retval); 360 330 } … … 377 347 /** needs malloc **********/ 378 348 379 char *tarball_fname, *progress_str, *tmp; 349 char *tarball_fname = NULL; 350 char *progress_str = NULL; 351 char *tmp = NULL; 380 352 char *mds = NULL; 381 353 long max_val; 382 354 383 malloc_string(tarball_fname);384 malloc_string(progress_str);385 355 malloc_string(tmp); 386 387 356 assert(bkpinfo != NULL); 388 357 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 389 358 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 390 391 359 max_val = atol(tmp); 360 paranoid_free(tmp); 361 392 362 mds = media_descriptor_string(bkpinfo->backup_media_type); 393 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);363 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 394 364 395 365 open_progress_form("Comparing files", … … 403 373 insist_on_this_cd_number(g_current_media_number); 404 374 update_progress_form(progress_str); 405 sprintf(tarball_fname, 406 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 375 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 407 376 408 377 if (!does_file_exist(tarball_fname)) { 409 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",410 378 mr_free(tarball_fname); 379 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number); 411 380 } 412 381 if (!does_file_exist(tarball_fname)) { 413 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",414 382 mr_free(tarball_fname); 383 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzma", current_tarball_number); 415 384 } 416 385 if (!does_file_exist(tarball_fname)) { 417 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",418 386 mr_free(tarball_fname); 387 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number); 419 388 } 420 389 if (!does_file_exist(tarball_fname)) { 421 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",422 390 mr_free(tarball_fname); 391 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number); 423 392 } 424 393 if (!does_file_exist(tarball_fname)) { 425 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 426 current_tarball_number); 394 mr_free(tarball_fname); 395 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number); 396 } 397 if (!does_file_exist(tarball_fname)) { 398 mr_free(tarball_fname); 399 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number); 427 400 } 428 401 if (!does_file_exist(tarball_fname)) { … … 432 405 == 0) { 433 406 log_msg(2, "OK, I think I'm done with tarballs..."); 407 mr_free(tarball_fname); 434 408 break; 435 409 } 436 410 log_msg(2, "OK, I think it's time for another CD..."); 437 411 g_current_media_number++; 438 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 412 413 mr_free(progress_str); 414 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 439 415 log_to_screen(progress_str); 440 416 } else { … … 444 420 current_tarball_number++; 445 421 } 446 } 422 mr_free(tarball_fname); 423 } 424 mr_free(progress_str); 447 425 mr_free(mds); 448 426 … … 453 431 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 454 432 } 455 paranoid_free(tarball_fname);456 paranoid_free(progress_str);457 paranoid_free(tmp);458 433 return (retval); 459 434 } … … 478 453 { 479 454 /** needs malloc *********/ 480 char *tmp, *cwd, *new, *command; 455 char *tmp = NULL; 456 char *cwd, *new; 457 char *command = NULL; 481 458 int resA = 0; 482 459 int resB = 0; … … 486 463 malloc_string(cwd); 487 464 malloc_string(new); 488 malloc_string(command);489 465 490 466 assert(bkpinfo != NULL); … … 509 485 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt"); 510 486 if (noof_changed_files) { 511 sprintf(tmp, "%ld files do not match the backup ", 512 noof_changed_files); 513 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 514 log_to_screen(tmp); 515 sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 487 log_to_screen("%ld files do not match the backup ", noof_changed_files); 488 489 mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 516 490 paranoid_system(command); 517 } else { 518 sprintf(tmp, "All files match the backup "); 491 mr_free(command); 492 } else { 493 mr_asprintf(tmp, "All files match the backup "); 519 494 mvaddstr_and_log_it(g_currentY++, 0, tmp); 520 495 log_to_screen(tmp); 521 }522 523 paranoid_free(tmp); 496 mr_free(tmp); 497 } 498 524 499 paranoid_free(cwd); 525 500 paranoid_free(new); 526 paranoid_free(command);527 501 528 502 return (resA + resB); … … 552 526 int res = 0; 553 527 long q; 554 char *tmp ;528 char *tmp = NULL; 555 529 char *new; 556 530 char *cwd; 557 531 558 malloc_string(tmp);559 532 malloc_string(new); 560 533 malloc_string(cwd); … … 630 603 } else { 631 604 q = count_lines_in_file(MONDO_CACHE"/changed.files"); 632 sprintf(tmp, "%ld significant difference%s found.", q, 633 (q != 1) ? "s" : ""); 605 mr_asprintf(tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : ""); 634 606 mvaddstr_and_log_it(g_currentY++, 0, tmp); 635 607 log_to_screen(tmp); 636 637 strcpy(tmp, 638 608 mr_free(tmp); 609 610 mr_asprintf(tmp, "Type 'less /tmp/changed.files' for a list of non-matching files"); 639 611 mvaddstr_and_log_it(g_currentY++, 0, tmp); 640 612 log_to_screen(tmp); 613 mr_free(tmp); 641 614 642 615 log_msg(2, "calling popup_changelist_from_file()"); … … 663 636 664 637 kill_petris(); 665 paranoid_free(tmp);666 638 paranoid_free(new); 667 639 paranoid_free(cwd); … … 686 658 687 659 /** needs malloc **/ 688 char *dir, *command; 660 char *dir; 661 char *command = NULL; 689 662 690 663 assert(bkpinfo != NULL); 691 664 malloc_string(dir); 692 malloc_string(command);693 665 if (getcwd(dir, MAX_STR_LEN)) { 694 666 // FIXME … … 698 670 } 699 671 700 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 701 bkpinfo->restore_path); 672 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 702 673 run_program_and_log_output(command, FALSE); 703 m vaddstr_and_log_it(g_currentY,704 674 mr_free(command); 675 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 705 676 706 677 if (bkpinfo->disaster_recovery … … 726 697 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 727 698 paranoid_free(dir); 728 paranoid_free(command);729 699 return (res); 730 700 } … … 749 719 { 750 720 int res; 751 char *dir, *command; 721 char *dir; 722 char *command = NULL; 752 723 753 724 assert(bkpinfo != NULL); 754 725 malloc_string(dir); 755 malloc_string(command);756 726 757 727 if (getcwd(dir, MAX_STR_LEN)) { … … 761 731 // FIXME 762 732 } 763 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 764 bkpinfo->restore_path); 733 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 765 734 run_program_and_log_output(command, FALSE); 766 mvaddstr_and_log_it(g_currentY, 767 0, "Verifying archives against filesystem"); 735 mr_free(command); 736 737 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 768 738 res = verify_tape_backups(); 769 739 if (chdir(dir)) { … … 776 746 } 777 747 paranoid_free(dir); 778 paranoid_free(command);779 748 return (res); 780 749 } -
branches/3.2/mondo/src/mondorestore/mondo-rstr-newt.c
r3185 r3193 12 12 #include "mondo-rstr-newt.h" 13 13 #include "mr_mem.h" 14 #include "mr_str.h" 14 15 15 16 //static char cvsid[] = "$Id$"; … … 52 53 { 53 54 /** buffers ***********************************************************/ 54 char tmp[MAX_STR_LEN];55 char *tmp = NULL; 55 56 56 57 /** newt **************************************************************/ … … 78 79 newtPushHelpLine 79 80 (" Add one of the following unallocated RAID partitions to this RAID device."); 80 sprintf(tmp, "%-26s %s", "Device", "Size");81 mr_asprintf(tmp, "%-26s %s", "Device", "Size"); 81 82 headerMsg = newtLabel(1, 1, tmp); 82 83 partitionsListbox = … … 104 105 105 106 items = disklist->entries; 106 strcpy(disklist->el[items].device, 107 unallocated_raid_partitions->el[currline].device); 107 strcpy(disklist->el[items].device, unallocated_raid_partitions->el[currline].device); 108 108 disklist->el[items].index = index; 109 109 disklist->entries = ++items; … … 112 112 } 113 113 newtFormDestroy(myForm); 114 mr_free(tmp); 114 115 newtPopWindow(); 115 116 newtPopHelpLine(); … … 152 153 153 154 /** buffers **********************************************************/ 154 char drive_to_add[MAX_STR_LEN];155 char mountpoint_str[MAX_STR_LEN];156 char size_str[MAX_STR_LEN];157 char device_str[MAX_STR_LEN];158 char format_str[MAX_STR_LEN];155 char *drive_to_add = NULL; 156 char *mountpoint_str = NULL; 157 char *size_str = NULL; 158 char *device_str = NULL; 159 char *format_str = NULL; 159 160 160 161 /** pointers *********************************************************/ … … 169 170 assert(keylist != NULL); 170 171 171 strcpy(device_str, "/dev/"); 172 strcpy(mountpoint_str, "/"); 172 mr_asprintf(device_str, "/dev/"); 173 mr_asprintf(mountpoint_str, "/"); 174 mr_asprintf(size_str, ""); 173 175 #ifdef __FreeBSD__ 174 strcpy(format_str, "ufs");176 mr_asprintf(format_str, "ufs"); 175 177 #else 176 strcpy(format_str, "ext3");178 mr_asprintf(format_str, "ext3"); 177 179 #endif 178 size_str[0] = '\0';179 /* sprintf(size_str,""); */180 180 newtOpenWindow(20, 5, 48, 10, "Add entry"); 181 181 label0 = newtLabel(2, 1, "Device: "); … … 183 183 label2 = newtLabel(2, 3, "Size (MB): "); 184 184 label3 = newtLabel(2, 4, "Format: "); 185 deviceComp = 186 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 187 mountpointComp = 188 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 189 formatComp = 190 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 185 deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 186 mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 187 formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 191 188 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 192 189 bOK = newtButton(5, 6, " OK "); … … 200 197 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 201 198 b_res = newtRunForm(myForm); 202 strcpy(device_str, device_here); 203 strcpy(mountpoint_str, mountpoint_here); 204 strcpy(format_str, format_here); 205 strcpy(size_str, size_here); 206 // log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 207 strip_spaces(device_str); 208 strip_spaces(mountpoint_str); 209 strip_spaces(format_str); 210 strip_spaces(size_str); 211 // log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 199 mr_free(device_str); 200 mr_asprintf(device_str, "%s", device_here); 201 202 mr_free(mountpoint_str); 203 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 204 mr_strip_spaces(mountpoint_str); 205 206 mr_free(format_str); 207 mr_asprintf(format_str, "%s", format_here); 208 mr_strip_spaces(format_str); 209 210 mr_free(size_str); 211 mr_asprintf(size_str, "%s", size_here); 212 mr_strip_spaces(size_str); 213 214 mr_strip_spaces(device_str); 212 215 if (b_res == bOK) { 213 216 if (device_str[strlen(device_str) - 1] == '/') { … … 215 218 b_res = NULL; 216 219 } 217 if (size_of_specific_device_in_mountlist(mountlist, device_str) 218 >= 0) { 220 if (size_of_specific_device_in_mountlist(mountlist, device_str) >= 0) { 219 221 popup_and_OK("Can't add this - you've got one already!"); 220 222 b_res = NULL; … … 228 230 return; 229 231 } 230 strcpy(drive_to_add, device_str);232 mr_asprintf(drive_to_add, "%s", device_str); 231 233 for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--); 232 drive_to_add[i] = '\0'; 234 mr_free(drive_to_add); 235 233 236 currline = mountlist->entries; 234 237 strcpy(mountlist->el[currline].device, device_str); 235 238 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 239 mr_free(mountpoint_str); 240 236 241 strcpy(mountlist->el[currline].format, format_str); 242 mr_free(format_str); 243 237 244 mountlist->el[currline].size = atol(size_str) * 1024L; 245 mr_free(size_str); 246 238 247 mountlist->entries++; 239 248 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 240 initiate_new_raidlist_entry(raidlist, mountlist, currline, 241 device_str); 242 } 249 initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str); 250 } 251 mr_free(device_str); 252 243 253 redraw_mountlist(mountlist, keylist, listbox); 244 254 } … … 315 325 316 326 /** buffers ***********************************************************/ 317 char tmp[MAX_STR_LEN]; 318 319 320 327 char tmp = NULL; 328 char *devname = NULL; 321 329 322 330 for (i = 0; … … 324 332 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++); 325 333 if (i == raidlist->entries) { 326 sprintf(tmp, 327 "Cannot calc size of raid device %s - cannot find it in raidlist", 328 raid_device); 329 log_it(tmp); 334 log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device); 330 335 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 331 336 // then it has no size, right? … … 339 344 int k = 0, l = 0; 340 345 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 341 char devname[64]; 342 strcpy(devname, raidrec->plex[j].sd[k].which_device); 346 mr_asprintf(devname, "%s", raidrec->plex[j].sd[k].which_device); 343 347 for (l = 0; l < raidlist->disks.entries; ++l) { 344 348 if (!strcmp(devname, raidlist->disks.el[l].name)) { … … 368 372 } 369 373 } 374 mr_free(devname); 370 375 } 371 376 … … 388 393 } 389 394 390 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 391 (long) smallest_plex); 392 log_it(tmp); 395 log_it("I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex); 393 396 return (smallest_plex); 394 397 #else … … 407 410 long sp = 0; 408 411 409 /** buffers ***********************************************************/410 char tmp[MAX_STR_LEN];411 412 412 assert(mountlist != NULL); 413 413 assert(raidlist != NULL); … … 418 418 && strcmp(raidlist->el[i].raid_device, raid_device); i++); 419 419 if (i == raidlist->entries) { 420 sprintf(tmp, 421 "Cannot calc size of raid device %s - cannot find it in raidlist", 422 raid_device); 423 log_it(tmp); 420 log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device); 424 421 return (999999999); 425 422 } … … 444 441 total_size = smallest_partition * (noof_partitions - 1); 445 442 } 446 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 447 (long) total_size); 448 log_it(tmp); 443 log_it("I have calculated %s's real size to be %ld", raid_device, (long) total_size); 449 444 return (total_size); 450 445 #endif … … 470 465 /** buffers ***********************************************************/ 471 466 char tmp[MAX_STR_LEN]; 472 char prompt[MAX_STR_LEN];467 char *prompt = NULL; 473 468 char sz[MAX_STR_LEN]; 474 469 475 sprintf(prompt, 476 "Please enter the RAID level you want. (concat, striped, raid5)"); 470 mr_asprintf(prompt, "Please enter the RAID level you want. (concat, striped, raid5)"); 477 471 if (raidrec->raidlevel == -1) { 478 472 strcpy(tmp, "concat"); … … 485 479 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 486 480 if (!res) { 481 mr_free(prompt); 487 482 return; 488 483 } … … 502 497 log_it(tmp); 503 498 if (is_this_raid_personality_registered(out)) { 504 log_it 505 ("Groovy. You've picked a RAID personality which is registered."); 499 log_it("Groovy. You've picked a RAID personality which is registered."); 506 500 } else { 507 if (ask_me_yes_or_no 508 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 501 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 509 502 { 510 503 out = 999; … … 512 505 } 513 506 } 507 mr_free(prompt); 508 514 509 raidrec->raidlevel = out; 515 510 #else 516 511 /** buffers ***********************************************************/ 517 512 char tmp[MAX_STR_LEN]; 518 char personalities[MAX_STR_LEN];519 char prompt[MAX_STR_LEN];513 char *personalities = NULL; 514 char *prompt = NULL; 520 515 char sz[MAX_STR_LEN]; 521 int out = 0, res = 0; 516 int out = 0; 517 int res = 0; 522 518 523 519 524 520 assert(raidrec != NULL); 525 521 paranoid_system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null"); 526 strcpy(personalities,527 last_line_of_file("/tmp/raid-personalities.txt"));528 sprintf(prompt, "Please enter the RAID level you want. %s",529 personalities); 522 mr_asprintf(personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt")); 523 mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities); 524 mr_free(personalities); 525 530 526 if (raidrec->raid_level == -1) { 531 527 strcpy(tmp, "linear"); … … 555 551 log_it(tmp); 556 552 if (is_this_raid_personality_registered(out)) { 557 log_it 558 ("Groovy. You've picked a RAID personality which is registered."); 553 log_it("Groovy. You've picked a RAID personality which is registered."); 559 554 } else { 560 if (ask_me_yes_or_no 561 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 562 { 555 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) { 563 556 out = 999; 564 557 } 565 558 } 566 559 } 560 mr_free(prompt); 561 567 562 raidrec->raid_level = out; 568 563 #endif … … 589 584 int pos = 0; 590 585 591 /** buffers ***********************************************************/592 char tmp[MAX_STR_LEN];593 594 586 assert(mountlist != NULL); 595 587 assert(raidlist != NULL); … … 602 594 pos++); 603 595 if (pos < mountlist->entries) { 604 sprintf(tmp, 605 "Deleting partition %s cos it was part of a now-defunct RAID", 606 mountlist->el[pos].device); 607 log_it(tmp); 596 log_it("Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device); 597 608 598 memcpy((void *) &mountlist->el[pos], 609 599 (void *) &mountlist->el[mountlist->entries - 1], … … 631 621 /** int ***************************************************************/ 632 622 int pos = 0; 623 int res = 0; 633 624 634 625 /** buffers ***********************************************************/ 635 char tmp[MAX_STR_LEN];626 char *tmp = NULL; 636 627 637 628 assert(disklist != NULL); 638 629 assert_string_is_neither_NULL_nor_zerolength(raid_device); 639 630 640 sprintf(tmp, "Delete %s from RAID device %s - are you sure?", 641 disklist->el[currline].device, raid_device); 642 if (!ask_me_yes_or_no(tmp)) { 631 mr_asprintf(tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device); 632 res = ask_me_yes_or_no(tmp); 633 mr_free(tmp); 634 635 if (!res) { 643 636 return; 644 637 } 645 638 for (pos = currline; pos < disklist->entries - 1; pos++) { 646 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */647 639 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device); 648 640 } … … 670 662 /** int ***************************************************************/ 671 663 int pos = 0; 664 int res = 0; 672 665 673 666 /** buffers ***********************************************************/ 674 char tmp[MAX_STR_LEN];675 char device[MAX_STR_LEN];667 char *tmp = NULL; 668 char *device = NULL; 676 669 677 670 … … 681 674 assert(keylist != NULL); 682 675 683 pos = 684 which_raid_device_is_using_this_partition(raidlist, 685 mountlist->el[currline]. 686 device); 676 pos = which_raid_device_is_using_this_partition(raidlist, mountlist->el[currline].device); 687 677 if (pos >= 0) { 688 sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", 689 mountlist->el[currline].device, 690 raidlist->el[pos].OSSWAP(raid_device, volname)); 678 mr_asprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname)); 691 679 popup_and_OK(tmp); 680 mr_free(tmp); 692 681 return; 693 682 } 694 sprintf(tmp, "Delete %s - are you sure?", 695 mountlist->el[currline].device); 696 if (!ask_me_yes_or_no(tmp)) { 683 mr_asprintf(tmp, "Delete %s - are you sure?", mountlist->el[currline].device); 684 res = ask_me_yes_or_no(tmp); 685 mr_free(tmp); 686 687 if (!res) { 697 688 return; 698 689 } 699 690 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 700 strcpy(device, mountlist->el[currline].device);691 mr_asprintf(device, "%s", mountlist->el[currline].device); 701 692 delete_raidlist_entry(mountlist, raidlist, device); 702 693 for (currline = 0; … … 704 695 && strcmp(mountlist->el[currline].device, device); 705 696 currline++); 697 mr_free(device); 698 706 699 if (currline == mountlist->entries) { 707 700 log_it("Dev is gone. I can't delete it. Ho-hum"); … … 737 730 738 731 /** buffers ***********************************************************/ 739 char tmp[MAX_STR_LEN];732 char *tmp = NULL; 740 733 741 734 assert(mountlist != NULL); … … 747 740 return; 748 741 } 749 sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);742 mr_asprintf(tmp, "Do you want me to delete %s's partitions, too?", device); 750 743 delete_partitions_too = ask_me_yes_or_no(tmp); 751 744 if (delete_partitions_too) { … … 760 753 if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device, 761 754 raidlist->disks.el[z].name)) { 762 strcpy(d.el[d.entries].name, 763 raidlist->disks.el[z].name); 764 strcpy(d.el[d.entries++].device, 765 raidlist->disks.el[z].device); 755 strcpy(d.el[d.entries].name, raidlist->disks.el[z].name); 756 strcpy(d.el[d.entries++].device, raidlist->disks.el[z].device); 766 757 } 767 758 } … … 791 782 items--; 792 783 } 784 mr_free(tmp); 793 785 raidlist->entries = items; 794 786 } … … 806 798 807 799 /** buffers ************************************************************/ 808 char tmp[MAX_STR_LEN]; 800 char *tmp = NULL; 801 int res = 0; 809 802 810 803 /** structures *********************************************************/ … … 814 807 815 808 av = &raidrec->additional_vars; 816 sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 817 if (ask_me_yes_or_no(tmp)) { 809 mr_asprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 810 res = ask_me_yes_or_no(tmp); 811 mr_free(tmp); 812 813 if (res) { 818 814 if (!strcmp(av->el[lino].label, "persistent-superblock") 819 815 || !strcmp(av->el[lino].label, "chunk-size")) { 820 sprintf(tmp, "%s must not be deleted. It would be bad.", 821 av->el[lino].label); 816 mr_asprintf(tmp, "%s must not be deleted. It would be bad.", av->el[lino].label); 822 817 popup_and_OK(tmp); 818 mr_free(tmp); 823 819 } else { 824 820 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--], … … 856 852 static char current_filename[MAX_STR_LEN]; 857 853 char tmp[MAX_STR_LEN + 2]; 854 char *tmp1 = NULL; 858 855 859 856 /** bool *************************************************************/ … … 886 883 if (!warned_already) { 887 884 warned_already = TRUE; 888 sprintf(tmp, 889 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 890 ARBITRARY_MAXIMUM); 891 popup_and_OK(tmp); 885 mr_asprintf(tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM); 886 popup_and_OK(tmp1); 887 mr_free(tmp1); 892 888 } 893 889 } else { 894 strcpy(g_strings_of_flist_window[lines_in_flist_window], 895 current_filename); 890 strcpy(g_strings_of_flist_window[lines_in_flist_window], current_filename); 896 891 g_is_path_selected[lines_in_flist_window] = node->selected; 897 892 lines_in_flist_window++; … … 908 903 (g_strings_of_flist_window[i], 909 904 g_strings_of_flist_window[i - 1]) < 0) { 910 strcpy(tmp, g_strings_of_flist_window[i]); 911 strcpy(g_strings_of_flist_window[i], 912 g_strings_of_flist_window[i - 1]); 913 strcpy(g_strings_of_flist_window[i - 1], tmp); 905 mr_asprintf(tmp1, "%s", g_strings_of_flist_window[i]); 906 strcpy(g_strings_of_flist_window[i], g_strings_of_flist_window[i - 1]); 907 strcpy(g_strings_of_flist_window[i - 1], tmp1); 908 mr_free(tmp1); 909 914 910 dummybool = g_is_path_selected[i]; 915 911 g_is_path_selected[i] = g_is_path_selected[i - 1]; … … 1014 1010 void *curr_choice; 1015 1011 void *keylist[ARBITRARY_MAXIMUM]; 1016 1017 /** buffers ***********************************************************/1018 char tmp[MAX_STR_LEN];1019 1012 1020 1013 /** bool **************************************************************/ … … 1064 1057 indexno = 0; 1065 1058 } 1066 sprintf(tmp, "You selected '%s'", 1067 g_strings_of_flist_window[indexno]); 1068 log_it(tmp); 1059 log_it("You selected '%s'", g_strings_of_flist_window[indexno]); 1060 1069 1061 if (b_res == bMore) { 1070 1062 g_is_path_expanded[indexno] = TRUE; … … 1158 1150 1159 1151 /** buffers ***********************************************************/ 1160 char device_str[MAX_STR_LEN];1161 char mountpoint_str[MAX_STR_LEN];1162 char size_str[MAX_STR_LEN];1163 char format_str[MAX_STR_LEN];1164 char tmp[MAX_STR_LEN];1165 char device_used_to_be[MAX_STR_LEN];1166 char mountpt_used_to_be[MAX_STR_LEN];1152 char *device_str = NULL; 1153 char *mountpoint_str = NULL; 1154 char *size_str = NULL; 1155 char *format_str = NULL; 1156 char *tmp = NULL; 1157 char *device_used_to_be = NULL; 1158 char *mountpt_used_to_be = NULL; 1167 1159 1168 1160 /** pointers **********************************************************/ … … 1182 1174 memcpy((void *) &bkp_raidlist, (void *) raidlist, 1183 1175 sizeof(struct raidlist_itself)); 1184 strcpy(device_str, mountlist->el[currline].device);1185 strcpy(device_used_to_be, mountlist->el[currline].device);1186 strcpy(mountpoint_str, mountlist->el[currline].mountpoint);1187 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);1188 strcpy(format_str, mountlist->el[currline].format);1189 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);1176 mr_asprintf(device_str, "%s", mountlist->el[currline].device); 1177 mr_asprintf(device_used_to_be, "%s", mountlist->el[currline].device); 1178 mr_asprintf(mountpoint_str, "%s", mountlist->el[currline].mountpoint); 1179 mr_asprintf(mountpt_used_to_be, "%s", mountlist->el[currline].mountpoint); 1180 mr_asprintf(format_str, "%s", mountlist->el[currline].format); 1181 mr_asprintf(size_str, "%lld", mountlist->el[currline].size / 1024L); 1190 1182 newtOpenWindow(20, 5, 48, 10, "Edit entry"); 1191 1183 label0 = newtLabel(2, 1, "Device:"); … … 1193 1185 label2 = newtLabel(2, 3, "Size (MB): "); 1194 1186 label3 = newtLabel(2, 4, "Format: "); 1195 deviceComp = 1196 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1197 mountpointComp = 1198 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1199 formatComp = 1200 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1187 deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1188 mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1189 formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1201 1190 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1202 1191 || !strcmp(mountlist->el[currline].mountpoint, "image")) { … … 1218 1207 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 1219 1208 b_res = newtRunForm(myForm); 1220 strcpy(device_str, device_here); 1221 strip_spaces(device_str); 1222 strcpy(mountpoint_str, mountpoint_here); 1223 strip_spaces(mountpoint_str); 1224 strcpy(format_str, format_here); 1225 strip_spaces(format_str); 1209 mr_free(device_str); 1210 mr_asprintf(device_str, "%s", device_here); 1211 mr_strip_spaces(device_str); 1212 1213 mr_free(mountpoint_str); 1214 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 1215 mr_strip_spaces(mountpoint_str); 1216 1217 mr_free(format_str); 1218 mr_asprintf(format_str, "%s", format_here); 1219 mr_strip_spaces(format_str); 1220 1226 1221 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) 1227 1222 && strstr(device_used_to_be, RAID_DEVICE_STUB) … … 1238 1233 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1239 1234 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1240 strcpy(size_str, size_here); 1241 strip_spaces(size_str); 1235 mr_free(size_str); 1236 mr_asprintf(size_str, "%s", size_here); 1237 mr_strip_spaces(size_str); 1242 1238 } else { 1243 sprintf(size_str, "%ld", 1244 calculate_raid_device_size(mountlist, raidlist, 1245 mountlist->el[currline]. 1246 device) / 1024); 1239 mr_asprintf(size_str, "%ld", calculate_raid_device_size(mountlist, raidlist, mountlist->el[currline].device) / 1024); 1247 1240 newtLabelSetText(sizeComp, size_str); 1248 1241 } … … 1261 1254 device); 1262 1255 if (j < 0) { 1263 sprintf(tmp, 1264 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1265 mountlist->el[currline].device); 1256 mr_asprintf(tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device); 1266 1257 popup_and_OK(tmp); 1258 mr_free(tmp); 1267 1259 } else { 1268 1260 log_it("edit_raidlist_entry - calling"); … … 1276 1268 newtPopHelpLine(); 1277 1269 newtPopWindow(); 1270 mr_free(mountpt_used_to_be); 1271 1278 1272 if (b_res == bCancel) { 1279 1273 memcpy((void *) raidlist, (void *) &bkp_raidlist, 1280 1274 sizeof(struct raidlist_itself)); 1275 mr_free(device_str); 1276 mr_free(device_used_to_be); 1277 mr_free(format_str); 1278 mr_free(size_str); 1281 1279 return; 1282 1280 } 1283 1281 strcpy(mountlist->el[currline].device, device_str); 1284 1282 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 1283 mr_free(mountpoint_str); 1284 1285 1285 strcpy(mountlist->el[currline].format, format_str); 1286 mr_free(format_str); 1287 1286 1288 if (strcmp(mountlist->el[currline].mountpoint, "image")) { 1287 1289 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { … … 1293 1295 } 1294 1296 } 1297 mr_free(size_str); 1295 1298 newtListboxSetEntry(listbox, (long) keylist[currline], 1296 1299 mountlist_entry_to_string(mountlist, currline)); … … 1298 1301 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1299 1302 && !strstr(device_used_to_be, RAID_DEVICE_STUB)) { 1300 initiate_new_raidlist_entry(raidlist, mountlist, currline, 1301 device_str); 1303 initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str); 1302 1304 } 1303 1305 /* if moving from RAID to non-RAID then do funky stuff */ … … 1316 1318 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1317 1319 else if (strcmp(device_used_to_be, device_str)) { 1318 popup_and_OK 1319 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1320 popup_and_OK("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1320 1321 } 1321 1322 #endif 1323 mr_free(device_str); 1324 mr_free(device_used_to_be); 1325 1322 1326 redraw_mountlist(mountlist, keylist, listbox); 1323 1327 } … … 1342 1346 for (i = 0; i < raidlist->disks.entries; ++i) { 1343 1347 if (!strcmp(raidlist->disks.el[i].device, temp)) { 1344 strcpy(raidrec->sd[raidrec->subdisks].which_device, 1345 raidlist->disks.el[i].name); 1348 strcpy(raidrec->sd[raidrec->subdisks].which_device, raidlist->disks.el[i].name); 1346 1349 found = TRUE; 1347 1350 } 1348 1351 } 1349 1352 if (!found) { 1350 sprintf(raidlist->disks.el[raidlist->disks.entries].name, 1351 "drive%i", raidlist->disks.entries); 1352 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", 1353 raidlist->disks.entries); 1353 sprintf(raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries); 1354 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries); 1354 1355 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp); 1355 1356 } … … 1424 1425 void *keylist[10]; 1425 1426 void *curr_choice; 1427 char *raidlevel = NULL; 1428 char *chunksize = NULL; 1429 char *msg = NULL; 1426 1430 1427 1431 int currline2 = 0; 1432 int res = 0; 1428 1433 1429 1434 log_it("Started edit_raidlist_entry"); … … 1455 1460 keylist[i] = (void *) i; 1456 1461 if (i < raidrec->plexes) { 1457 char pname[64], entry[MAX_STR_LEN], raidlevel[64], 1458 chunksize[64]; 1462 char pname[64], entry[MAX_STR_LEN]; 1459 1463 switch (raidrec->plex[i].raidlevel) { 1460 1464 case -1: 1461 strcpy(raidlevel, "concat");1465 mr_asprintf(raidlevel, "concat"); 1462 1466 break; 1463 1467 case 0: 1464 strcpy(raidlevel, "striped");1468 mr_asprintf(raidlevel, "striped"); 1465 1469 break; 1466 1470 case 5: 1467 strcpy(raidlevel, "raid5");1471 mr_asprintf(raidlevel, "raid5"); 1468 1472 break; 1469 1473 default: 1470 sprintf(raidlevel, "raid%i", 1471 raidrec->plex[i].raidlevel); 1474 mr_asprintf(raidlevel, "raid%i", raidrec->plex[i].raidlevel); 1472 1475 break; 1473 1476 } 1474 1477 1475 1478 if (raidrec->plex[i].raidlevel == -1) { 1476 strcpy(chunksize, "N/A");1479 mr_asprintf(chunksize, "N/A"); 1477 1480 } else { 1478 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);1481 mr_asprintf(chunksize, "%dk", raidrec->plex[i].stripesize); 1479 1482 } 1480 1483 snprintf(pname, 64, "%s.p%i", raidrec->volname, i); … … 1482 1485 pname, raidlevel, chunksize, 1483 1486 raidrec->plex[i].subdisks); 1487 mr_free(raidlevel); 1488 mr_free(chunksize); 1489 1484 1490 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1485 1491 } … … 1503 1509 1504 1510 if (b_res == bDelete) { 1505 char msg[MAX_STR_LEN]; 1506 sprintf(msg, "Are you sure you want to delete %s.p%i?", 1507 raidrec->volname, currline2); 1508 if (ask_me_yes_or_no(msg)) { 1511 mr_asprintf(msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2); 1512 res = ask_me_yes_or_no(msg); 1513 mr_free(msg); 1514 1515 if (res) { 1509 1516 log_it("Deleting RAID plex"); 1510 1517 memcpy((void *) &raidrec->plex[currline2], … … 1540 1547 /** buffers ***********************************************************/ 1541 1548 char *title_of_editraidForm_window; 1542 char *sz_raid_level ;1543 char *sz_data_disks ;1544 char *sz_spare_disks ;1545 char *sz_parity_disks ;1546 char *sz_failed_disks ;1549 char *sz_raid_level = NULL; 1550 char *sz_data_disks = NULL; 1551 char *sz_spare_disks = NULL; 1552 char *sz_parity_disks = NULL; 1553 char *sz_failed_disks = NULL; 1547 1554 1548 1555 /** newt **************************************************************/ … … 1562 1569 assert(raidrec != NULL); 1563 1570 1564 malloc_string(title_of_editraidForm_window); 1565 malloc_string(sz_raid_level); 1566 malloc_string(sz_data_disks); 1567 malloc_string(sz_spare_disks); 1568 malloc_string(sz_parity_disks); 1569 malloc_string(sz_failed_disks); 1570 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 1571 fatal_error("Cannot malloc space for raidrec"); 1572 } 1573 1571 bkp_raidrec = mr_malloc(sizeof(struct raid_device_record)); 1574 1572 log_it("Started edit_raidlist_entry"); 1575 1573 1576 memcpy((void *) bkp_raidrec, (void *) raidrec, 1577 sizeof(struct raid_device_record)); 1578 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1574 memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record)); 1575 mr_asprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1579 1576 log_msg(2, "Opening newt window"); 1580 1577 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window); 1581 1578 for (;;) { 1582 1579 log_msg(2, "Main loop"); 1583 sprintf(title_of_editraidForm_window, "Edit %s", 1584 raidrec->raid_device); 1585 strcpy(sz_raid_level, 1586 turn_raid_level_number_to_string(raidrec->raid_level)); 1587 strcpy(sz_data_disks, 1588 number_of_disks_as_string(raidrec->data_disks.entries, 1589 "data")); 1590 strcpy(sz_spare_disks, 1591 number_of_disks_as_string(raidrec->spare_disks.entries, 1592 "spare")); 1593 strcpy(sz_parity_disks, 1594 number_of_disks_as_string(raidrec->parity_disks.entries, 1595 "parity")); 1596 strcpy(sz_failed_disks, 1597 number_of_disks_as_string(raidrec->failed_disks.entries, 1598 "failed")); 1580 mr_free(title_of_editraidForm_window); 1581 mr_asprintf(title_of_editraidForm_window, "Edit %s", raidrec->raid_device); 1582 mr_asprintf(sz_raid_level, "%s", turn_raid_level_number_to_string(raidrec->raid_level)); 1583 mr_asprintf(sz_data_disks, "%s", number_of_disks_as_string(raidrec->data_disks.entries, "data")); 1584 mr_asprintf(sz_spare_disks, "%s", number_of_disks_as_string(raidrec->spare_disks.entries, "spare")); 1585 mr_asprintf(sz_parity_disks, "%s", number_of_disks_as_string(raidrec->parity_disks.entries, "parity")); 1586 mr_asprintf(sz_failed_disks, "%s", number_of_disks_as_string(raidrec->failed_disks.entries, "failed")); 1599 1587 bSelectData = newtButton(1, 1, sz_data_disks); 1600 1588 bSelectSpare = newtButton(20, 1, sz_spare_disks); … … 1617 1605 choose_raid_level(raidrec); 1618 1606 } else if (b_res == bSelectData) { 1619 select_raid_disks(mountlist, raidlist, raidrec, "data", 1620 &raidrec->data_disks); 1607 select_raid_disks(mountlist, raidlist, raidrec, "data", &raidrec->data_disks); 1621 1608 } else if (b_res == bSelectSpare) { 1622 select_raid_disks(mountlist, raidlist, raidrec, "spare", 1623 &raidrec->spare_disks); 1609 select_raid_disks(mountlist, raidlist, raidrec, "spare", &raidrec->spare_disks); 1624 1610 } else if (b_res == bSelectParity) { 1625 select_raid_disks(mountlist, raidlist, raidrec, "parity", 1626 &raidrec->parity_disks); 1611 select_raid_disks(mountlist, raidlist, raidrec, "parity", &raidrec->parity_disks); 1627 1612 } else if (b_res == bSelectFailed) { 1628 select_raid_disks(mountlist, raidlist, raidrec, "failed", 1629 &raidrec->failed_disks); 1613 select_raid_disks(mountlist, raidlist, raidrec, "failed", &raidrec->failed_disks); 1630 1614 } else if (b_res == bAdditional) { 1631 1615 edit_raidrec_additional_vars(raidrec); … … 1635 1619 break; 1636 1620 } 1621 mr_free(sz_data_disks); 1622 mr_free(sz_spare_disks); 1623 mr_free(sz_parity_disks); 1624 mr_free(sz_failed_disks); 1637 1625 } 1638 1626 if (b_res == bCancel) { 1639 memcpy((void *) raidrec, (void *) bkp_raidrec, 1640 sizeof(struct raid_device_record)); 1627 memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record)); 1641 1628 } 1642 1629 newtPopHelpLine(); 1643 1630 newtPopWindow(); 1644 mountlist->el[currline].size = 1645 calculate_raid_device_size(mountlist, raidlist, 1646 raidrec->raid_device); 1647 paranoid_free(title_of_editraidForm_window); 1648 paranoid_free(sz_raid_level); 1649 paranoid_free(sz_data_disks); 1650 paranoid_free(sz_spare_disks); 1651 paranoid_free(sz_parity_disks); 1652 paranoid_free(sz_failed_disks); 1631 mountlist->el[currline].size = calculate_raid_device_size(mountlist, raidlist, raidrec->raid_device); 1632 mr_free(title_of_editraidForm_window); 1633 mr_free(sz_raid_level); 1653 1634 paranoid_free(bkp_raidrec); 1654 1635 #endif … … 1678 1659 1679 1660 /** buffers ***********************************************************/ 1680 char title_of_editraidForm_window[MAX_STR_LEN];1661 char *title_of_editraidForm_window = NULL; 1681 1662 1682 1663 /** newt **************************************************************/ … … 1697 1678 int currline_a, currline_u; 1698 1679 1680 char *p = NULL; 1681 char *tmp = NULL; 1682 char *entry = NULL; 1683 1699 1684 struct mountlist_itself *unallocparts; 1700 1685 … … 1704 1689 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1705 1690 sizeof(struct vinum_plex)); 1706 sprintf(title_of_editraidForm_window, "%s.p%i", 1707 raidlist->el[currline].volname, currline2); 1691 mr_asprintf(title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2); 1708 1692 newtPushHelpLine 1709 1693 (" Please select a subdisk to edit, or edit this plex's parameters"); 1710 1694 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1695 mr_free(title_of_editraidForm_window); 1696 1711 1697 for (;;) { 1712 1698 int i; 1713 char headerstr[MAX_STR_LEN];1714 char tmp[64];1715 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");1716 1717 1699 1718 1700 switch (raidrec->raidlevel) { 1719 1701 case -1: 1720 strcpy(tmp, "concat");1702 mr_asprintf(tmp, "concat"); 1721 1703 break; 1722 1704 case 0: 1723 strcpy(tmp, "striped");1705 mr_asprintf(tmp, "striped"); 1724 1706 break; 1725 1707 case 5: 1726 strcpy(tmp, "raid5");1708 mr_asprintf(tmp, "raid5"); 1727 1709 break; 1728 1710 default: 1729 sprintf(tmp, "unknown (%i)", raidrec->raidlevel);1711 mr_asprintf(tmp, "unknown (%i)", raidrec->raidlevel); 1730 1712 break; 1731 1713 } 1732 1714 bLevel = newtCompactButton(2, 2, " RAID level "); 1733 1715 sLevel = newtLabel(19, 2, tmp); 1716 mr_free(tmp); 1734 1717 1735 1718 if (raidrec->raidlevel >= 0) { 1736 sprintf(tmp, "%ik", raidrec->stripesize);1719 mr_asprintf(tmp, "%ik", raidrec->stripesize); 1737 1720 bStripeSize = newtCompactButton(2, 4, " Stripe size "); 1738 1721 } else { 1739 strcpy(tmp, "N/A");1722 mr_asprintf(tmp, "N/A"); 1740 1723 bStripeSize = newtLabel(2, 4, "Stripe size:"); 1741 1724 } 1742 1725 sStripeSize = newtLabel(19, 4, tmp); 1726 mr_free(tmp); 1743 1727 1744 1728 bOK = newtCompactButton(2, 16, " OK "); … … 1749 1733 1750 1734 1751 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);1752 // plexesHeader = newtLabel (2, 6, headerstr);1753 1735 unallocListbox = 1754 1736 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); … … 1766 1748 raidlist); 1767 1749 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1768 char entry[MAX_STR_LEN];1769 1750 keylist[i] = (void *) i; 1770 1751 if (i < raidrec->subdisks) { 1771 snprintf(entry, MAX_STR_LEN, "%-17s", 1772 find_dev_entry_for_raid_device_name(raidlist, 1773 raidrec-> 1774 sd[i]. 1775 which_device)); 1752 mr_asprintf(entry, "%-17s", find_dev_entry_for_raid_device_name(raidlist, raidrec->sd[i].which_device)); 1776 1753 newtListboxAppendEntry(allocListbox, entry, keylist[i]); 1754 mr_free(entry); 1777 1755 } 1778 1756 if (i < unallocparts->entries) { 1779 snprintf(entry, MAX_STR_LEN, "%-17s", 1780 unallocparts->el[i].device); 1757 mr_asprintf(entry, "%-17s", unallocparts->el[i].device); 1781 1758 newtListboxAppendEntry(unallocListbox, entry, keylist[i]); 1759 mr_free(entry); 1782 1760 } 1783 1761 } … … 1830 1808 choose_raid_level(raidrec); 1831 1809 } else if (b_res == bStripeSize) { 1832 char tmp [64];1833 sprintf(tmp , "%i", raidrec->stripesize);1810 char tmp1[64]; 1811 sprintf(tmp1, "%i", raidrec->stripesize); 1834 1812 if (popup_and_get_string 1835 1813 ("Stripe size", 1836 "Please enter the stripe size in kilobytes.", tmp , 20)) {1837 raidrec->stripesize = atoi(tmp );1814 "Please enter the stripe size in kilobytes.", tmp1, 20)) { 1815 raidrec->stripesize = atoi(tmp1); 1838 1816 } 1839 1817 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { … … 1849 1827 } 1850 1828 } 1851 #if 01852 } else {1853 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],1854 currline3);1855 }1856 #endif1857 1829 newtFormDestroy(editraidForm); 1858 1830 newtRefresh(); … … 1860 1832 1861 1833 if (b_res == bCancel) { 1862 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1863 sizeof(struct vinum_plex)); 1834 memcpy((void *) raidrec, (void *) &bkp_raidrec, sizeof(struct vinum_plex)); 1864 1835 } 1865 1836 newtPopWindow(); … … 1877 1848 1878 1849 /** buffers ***********************************************************/ 1879 char header[MAX_STR_LEN];1880 char comment[MAX_STR_LEN];1850 char *header = NULL; 1851 char *comment = NULL; 1881 1852 char sz_out[MAX_STR_LEN]; 1882 1853 … … 1885 1856 1886 1857 strcpy(sz_out, raidrec->additional_vars.el[lino].value); 1887 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1888 sprintf(comment, "Please set %s's value (currently '%s')", 1889 raidrec->additional_vars.el[lino].label, sz_out); 1858 mr_asprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1859 mr_asprintf(comment, "Please set %s's value (currently '%s')", raidrec->additional_vars.el[lino].label, sz_out); 1890 1860 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1891 1861 strip_spaces(sz_out); 1892 1862 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1893 1863 } 1894 } 1895 1896 1897 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain. - Hugo, 09/01/2001 */ 1864 mr_free(header); 1865 mr_free(comment); 1866 } 1898 1867 1899 1868 #endif … … 1936 1905 1937 1906 /** buffers **********************************************************/ 1938 char tmp[MAX_STR_LEN];1907 char *tmp = NULL; 1939 1908 char *flaws_str = NULL; 1940 1909 char *flaws_str_A = NULL; … … 1957 1926 bCancel = newtCompactButton(i += 12, 17, "Cancel"); 1958 1927 bOK = newtCompactButton(i += 12, 17, " OK "); 1959 sprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", "Size (MB)");1928 mr_asprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", "Size (MB)"); 1960 1929 headerMsg = newtLabel(2, 1, tmp); 1930 mr_free(tmp); 1931 1961 1932 flawsLabelA = newtLabel(2, 13, " "); 1962 1933 flawsLabelB = newtLabel(2, 14, " "); … … 2015 1986 } else if (b_res == bReload) { 2016 1987 if (ask_me_yes_or_no("Reload original mountlist?")) { 2017 /*2018 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/242019 if (!RAIDTAB_FNAME[0])2020 {2021 strcpy(RAIDTAB_FNAME, "/etc/raidtab");2022 log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);2023 }2024 */2025 1988 load_mountlist(mountlist, mountlist_fname); 2026 1989 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); … … 2237 2200 int i = 0; 2238 2201 #ifdef __FreeBSD__ 2239 char vdev[64]; 2202 char *vdev = NULL; 2203 int res = 0; 2240 2204 #else 2241 2205 // Linux … … 2247 2211 #ifdef __FreeBSD__ 2248 2212 for (i = 0; i < raidlist->entries; i++) { 2249 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2250 if (!strcmp(device, vdev)) 2213 mr_asprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2214 res = strcmp(device, vdev); 2215 mr_free(vdev); 2216 2217 if (!res) 2251 2218 break; 2252 2219 } … … 2298 2265 raidrec = &raidlist->el[pos_in_raidlist]; 2299 2266 initialize_raidrec(raidrec); 2300 strcpy(raidrec->OSSWAP(raid_device, volname), 2301 OSSWAP(device, basename(device))); 2267 strcpy(raidrec->OSSWAP(raid_device, volname), OSSWAP(device, basename(device))); 2302 2268 #ifndef __FreeBSD__ 2303 2269 choose_raid_level(raidrec); … … 2549 2515 char *new_dev) 2550 2516 { 2551 /** buffers ********************************************************/2552 char tmp[MAX_STR_LEN];2553 2554 2517 /** int ************************************************************/ 2555 2518 int pos = 0; … … 2562 2525 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2563 2526 if (pos < 0) { 2564 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.", 2565 old_dev); 2566 log_it(tmp); 2527 log_it("No need to rejig %s in raidlist: it's not listed.", old_dev); 2567 2528 } else { 2568 2529 if ((j = … … 2570 2531 OSSWAP(el[pos].data_disks, disks), 2571 2532 old_dev)) >= 0) { 2572 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j]. 2573 device, new_dev); 2533 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].device, new_dev); 2574 2534 } else 2575 2535 if ((j = … … 2578 2538 spares), 2579 2539 old_dev)) >= 0) { 2580 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j]. 2581 device, new_dev); 2540 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].device, new_dev); 2582 2541 } 2583 2542 #ifndef __FreeBSD__ … … 2596 2555 #endif 2597 2556 else { 2598 sprintf(tmp, 2599 "%s is supposed to be listed in this raid dev but it's not...", 2600 old_dev); 2601 log_it(tmp); 2557 log_it("%s is supposed to be listed in this raid dev but it's not...", old_dev); 2602 2558 } 2603 2559 } … … 2671 2627 /** buffers **********************************************************/ 2672 2628 void *keylist[ARBITRARY_MAXIMUM]; 2673 char *tmp; 2674 char *help_text; 2675 char *title_of_window; 2676 char *sz_res; 2677 char *header_text; 2629 char *tmp = NULL; 2630 char *help_text = NULL; 2631 char *title_of_window = NULL; 2632 char sz_res[MAX_STR_LEN]; 2633 char *header_text = NULL; 2634 char *p = NULL; 2678 2635 2679 2636 /** int **************************************************************/ … … 2688 2645 2689 2646 log_it("malloc'ing"); 2690 malloc_string(tmp); 2691 malloc_string(help_text); 2692 malloc_string(title_of_window); 2693 malloc_string(sz_res); 2694 malloc_string(header_text); 2695 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2696 fatal_error("Cannot malloc space for raidrec"); 2697 } 2698 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) { 2699 fatal_error("Cannot malloc space for disklist"); 2700 } 2701 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) { 2702 fatal_error("Cannot malloc space for raidlist"); 2703 } 2704 if (! 2705 (unallocated_raid_partitions = 2706 malloc(sizeof(struct mountlist_itself)))) { 2707 fatal_error("Cannot malloc space for unallocated_raid_partitions"); 2708 } 2709 2710 memcpy((void *) bkp_raidlist, (void *) raidlist, 2711 sizeof(struct raidlist_itself)); 2712 memcpy((void *) bkp_raidrec, (void *) raidrec, 2713 sizeof(struct raid_device_record)); 2714 memcpy((void *) bkp_disklist, (void *) disklist, 2715 sizeof(struct list_of_disks)); 2647 bkp_raidrec = mr_malloc(sizeof(struct raid_device_record)); 2648 bkp_disklist = mr_malloc(sizeof(struct list_of_disks)); 2649 bkp_raidlist = mr_malloc(sizeof(struct raidlist_itself)); 2650 unallocated_raid_partitions = mr_malloc(sizeof(struct mountlist_itself)); 2651 2652 memcpy((void *) bkp_raidlist, (void *) raidlist, sizeof(struct raidlist_itself)); 2653 memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record)); 2654 memcpy((void *) bkp_disklist, (void *) disklist, sizeof(struct list_of_disks)); 2716 2655 2717 2656 log_it("Post-malloc"); 2718 strcpy(help_text, 2719 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2720 sprintf(header_text, "%-24s %s", "Device", "Index"); 2721 sprintf(title_of_window, "%s contains...", raidrec->raid_device); 2657 mr_asprintf(help_text, " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2658 mr_asprintf(header_text, "%-24s %s", "Device", "Index"); 2659 mr_asprintf(title_of_window, "%s contains...", raidrec->raid_device); 2722 2660 newtPushHelpLine(help_text); 2723 2661 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { … … 2774 2712 redraw_disklist(disklist, keylist, partitionsListbox); 2775 2713 } else { 2776 sprintf(tmp, "%s's index is %d. What should it be?", 2777 raidrec->raid_device, 2778 disklist->el[currline].index); 2714 mr_asprintf(tmp, "%s's index is %d. What should it be?", raidrec->raid_device, disklist->el[currline].index); 2779 2715 sprintf(sz_res, "%d", disklist->el[currline].index); 2780 2716 if (popup_and_get_string("Set index", tmp, sz_res, 10)) { 2781 2717 disklist->el[currline].index = atoi(sz_res); 2782 2718 } 2719 mr_free(tmp); 2720 2783 2721 redraw_disklist(disklist, keylist, partitionsListbox); 2784 2722 } … … 2789 2727 } 2790 2728 newtPopHelpLine(); 2729 mr_free(help_text); 2730 mr_free(header_text); 2731 mr_free(title_of_window); 2732 2791 2733 if (b_res == bCancel) { 2792 memcpy((void *) raidlist, (void *) bkp_raidlist, 2793 sizeof(struct raidlist_itself)); 2794 memcpy((void *) raidrec, (void *) bkp_raidrec, 2795 sizeof(struct raid_device_record)); 2796 memcpy((void *) disklist, (void *) bkp_disklist, 2797 sizeof(struct list_of_disks)); 2798 } 2799 paranoid_free(tmp); 2800 paranoid_free(help_text); 2801 paranoid_free(title_of_window); 2734 memcpy((void *) raidlist, (void *) bkp_raidlist, sizeof(struct raidlist_itself)); 2735 memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record)); 2736 memcpy((void *) disklist, (void *) bkp_disklist, sizeof(struct list_of_disks)); 2737 } 2802 2738 paranoid_free(sz_res); 2803 paranoid_free(header_text); 2804 paranoid_free(bkp_raidrec); 2805 paranoid_free(bkp_disklist); 2806 paranoid_free(bkp_raidlist); 2807 paranoid_free(unallocated_raid_partitions); 2739 mr_free(bkp_raidrec); 2740 mr_free(bkp_disklist); 2741 mr_free(bkp_raidlist); 2742 mr_free(unallocated_raid_partitions); 2808 2743 } 2809 2744 #endif … … 2821 2756 /** char *************************************************************/ 2822 2757 char output = '\0'; 2823 char tmp[MAX_STR_LEN];2758 char *tmp = NULL; 2824 2759 2825 2760 /** newt *************************************************************/ … … 2833 2768 2834 2769 if (g_text_mode) { 2835 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) { 2836 printf 2837 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2838 if (fgets(tmp, MAX_STR_LEN - 1, stdin)) { 2839 // FIXME 2840 } 2770 while (!strchr("AICE", output)) { 2771 printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2772 mr_getline(tmp, stdin); 2773 output = tmp[0]; 2774 mr_free(tmp); 2841 2775 } 2842 2776 return (output); 2843 2777 } 2844 2778 2845 newtPushHelpLine 2846 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2779 newtPushHelpLine(" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2847 2780 newtOpenWindow(24, 3, 32, 17, "How should I restore?"); 2848 2781 b1 = newtButton(7, 1, "Automatically"); -
branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c
r3185 r3193 7 7 #include "my-stuff.h" 8 8 #include "mr_mem.h" 9 #include "mr_str.h" 9 10 #include "../common/mondostructures.h" 10 11 #include "../common/libmondo.h" … … 120 121 * @ingroup restoreUtilityGroup 121 122 */ 122 void ask_about_these_imagedevs(char *infname, char *outfname) 123 { 123 void ask_about_these_imagedevs(char *infname, char *outfname) { 124 124 125 FILE *fin; 125 126 FILE *fout; 126 /************************************************************************ 127 * allocate memory regions. test and set -sab 16 feb 2003 * 128 ************************************************************************/ 129 char *incoming_ptr; 130 char *question_ptr; 131 char *q; 132 133 char incoming[MAX_STR_LEN] = "\0"; 134 char question[MAX_STR_LEN]; 127 char *incoming = NULL; 128 char *question = NULL; 135 129 136 130 assert_string_is_neither_NULL_nor_zerolength(infname); 137 131 assert_string_is_neither_NULL_nor_zerolength(outfname); 138 132 139 incoming_ptr = malloc(sizeof(incoming));140 if (incoming_ptr == NULL) {141 fprintf(stderr, "Out of Memory\n");142 exit(EXIT_FAILURE);143 }144 145 question_ptr = malloc(sizeof(question));146 if (question_ptr == NULL) {147 fprintf(stderr, "Out of Memory\n");148 exit(EXIT_FAILURE);149 }150 151 memset(incoming_ptr, '\0', sizeof(incoming));152 memset(question_ptr, '\0', sizeof(question));153 154 155 156 133 if (!(fin = fopen(infname, "r"))) { 157 134 fatal_error("Cannot openin infname"); … … 160 137 fatal_error("Cannot openin outfname"); 161 138 } 162 for ( q = fgets(incoming_ptr, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); q = fgets(incoming_ptr, MAX_STR_LEN, fin)) {163 strip_spaces(incoming_ptr);139 for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) { 140 mr_strip_spaces(incoming); 164 141 165 142 if (incoming[0] == '\0') { 143 mr_free(incoming); 166 144 continue; 167 145 } 168 146 169 sprintf(question_ptr, "Should I restore the image of %s ?", incoming_ptr); 170 171 if (ask_me_yes_or_no(question_ptr)) { 172 fprintf(fout, "%s\n", incoming_ptr); 173 } 174 } 175 176 /*** free memory ***********/ 177 paranoid_free(incoming_ptr); 178 incoming_ptr = NULL; 179 paranoid_free(question_ptr); 180 question_ptr = NULL; 181 182 147 mr_asprintf(question, "Should I restore the image of %s ?", incoming); 148 149 if (ask_me_yes_or_no(question)) { 150 fprintf(fout, "%s\n", incoming); 151 } 152 mr_free(incoming); 153 } 154 mr_free(incoming); 155 mr_free(question); 183 156 paranoid_fclose(fout); 184 157 paranoid_fclose(fin); … … 232 205 { 233 206 234 /** needs malloc **/ 235 char *command; 236 char *file; 237 char *tmp; 207 char *command = NULL; 208 char *file = NULL; 209 char *tmp = NULL; 238 210 int res; 239 211 240 malloc_string(command);241 malloc_string(file);242 malloc_string(tmp);243 212 assert_string_is_neither_NULL_nor_zerolength(f); 244 213 assert_string_is_neither_NULL_nor_zerolength(list_fname); … … 246 215 247 216 if (strncmp(preamble, f, strlen(preamble)) == 0) { 248 strcpy(file, f + strlen(preamble));217 mr_asprintf(file, "%s", f + strlen(preamble)); 249 218 } else { 250 strcpy(file, f);219 mr_asprintf(file, "%s", f); 251 220 } 252 221 if (file[0] == '/' && file[1] == '/') { 253 strcpy(tmp, file); 254 strcpy(file, tmp + 1); 255 } 256 sprintf(tmp, 257 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 258 f, file); 259 log_msg(2, tmp); 260 sprintf(command, "grep -E '^%s$' %s", file, list_fname); 222 tmp = file; 223 224 mr_asprintf(file, "%s", tmp + 1); 225 mr_free(tmp); 226 } 227 log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file); 228 mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname); 229 mr_free(file); 230 261 231 res = run_program_and_log_output(command, FALSE); 262 paranoid_free(command); 263 paranoid_free(file); 264 paranoid_free(tmp); 232 mr_free(command); 265 233 if (res) { 266 return (FALSE);234 return (FALSE); 267 235 } else { 268 return (TRUE);236 return (TRUE); 269 237 } 270 238 } … … 351 319 * @return 0 for success, nonzero for failure. 352 320 */ 353 int iso_fiddly_bits(bool nuke_me_please) 354 { 321 int iso_fiddly_bits(bool nuke_me_please) { 322 355 323 char *mount_isodir_command = NULL; 356 char * tmp, *command;324 char *command = NULL; 357 325 char *mds = NULL; 358 326 int retval = 0, i; 359 327 360 assert(bkpinfo != NULL);361 malloc_string(tmp);362 malloc_string(command);363 328 g_ISO_restore_mode = TRUE; 364 329 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); … … 370 335 } 371 336 /* End patch */ 372 sprintf(command, "mkdir -p %s", bkpinfo->isodir);337 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir); 373 338 run_program_and_log_output(command, 5); 339 mr_free(command); 374 340 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 375 341 } … … 387 353 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format); 388 354 } 355 389 356 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir); 390 run_program_and_log_output("df -m", FALSE); 391 sprintf(tmp, 392 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 393 mount_isodir_command); 394 log_msg(1, tmp); 357 run_program_and_log_output("df -m -P", FALSE); 358 log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command); 395 359 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 396 360 popup_and_OK … … 407 371 i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */ 408 372 mds = media_descriptor_string(bkpinfo->backup_media_type); 409 sprintf(tmp, "%s #%d has been mounted via loopback mount", mds, i);410 373 mr_free(mds); 411 374 412 log_msg(1, tmp);375 log_msg(1, "%s #%d has been mounted via loopback mount", mds, i); 413 376 if (i < 0) { 414 popup_and_OK 415 ("Cannot find ISO images in the directory you specified."); 416 retval = 1; 417 } 418 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 419 bkpinfo->isodir); 420 paranoid_free(tmp); 421 paranoid_free(command); 377 popup_and_OK("Cannot find ISO images in the directory you specified."); 378 retval = 1; 379 } 380 log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir); 422 381 return (retval); 423 382 } … … 451 410 452 411 /** malloc **/ 453 char *tmp, *command, *mountdir, *mountpoint; 412 char *tmp = NULL; 413 char *command = NULL; 414 char *mountdir = NULL; 415 char *mountpoint = NULL; 454 416 char *additional_parameters = NULL; 455 417 … … 457 419 assert_string_is_neither_NULL_nor_zerolength(mpt); 458 420 assert(format != NULL); 459 malloc_string(tmp);460 malloc_string(command);461 malloc_string(mountdir);462 malloc_string(mountpoint);463 421 464 422 if (!strcmp(mpt, "/1")) { 465 strcpy(mountpoint, "/");423 mr_asprintf(mountpoint, "/"); 466 424 log_msg(3, "Mommm! SME is being a dildo!"); 467 425 } else { 468 strcpy(mountpoint, mpt);426 mr_asprintf(mountpoint, "%s", mpt); 469 427 } 470 428 … … 475 433 return (0); 476 434 } 477 sprintf(tmp, "Mounting device %s ", device);435 mr_asprintf(tmp, "Mounting device %s ", device); 478 436 log_msg(1, tmp); 479 437 /* Deal with additional params only if not /proc or /sys */ … … 494 452 495 453 if (!strcmp(mountpoint, "swap")) { 496 sprintf(command, "swapon %s", device); 454 mr_asprintf(command, "swapon %s", device); 455 mr_asprintf(mountdir, "swap"); 497 456 } else { 498 457 if (!strcmp(mountpoint, "/")) { 499 strcpy(mountdir, MNT_RESTORING);458 mr_asprintf(mountdir, "%s", MNT_RESTORING); 500 459 } else { 501 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);502 } 503 sprintf(command, "mkdir -p %s", mountdir);460 mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 461 } 462 mr_asprintf(command, "mkdir -p %s", mountdir); 504 463 run_program_and_log_output(command, FALSE); 505 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 506 additional_parameters, mountdir, MONDO_LOGFILE); 464 mr_free(command); 465 466 mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE); 507 467 log_msg(2, "command='%s'", command); 508 468 } 509 paranoid_free(additional_parameters);469 mr_free(additional_parameters); 510 470 511 471 res = run_program_and_log_output(command, TRUE); 512 472 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 513 473 log_msg(1, "Re-trying without the fancy extra parameters"); 514 sprintf(command, "mount -t %s %s %s 2>> %s", format, device,515 474 mr_free(command); 475 mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE); 516 476 res = run_program_and_log_output(command, TRUE); 517 477 } 518 478 if (res) { 519 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 520 format, mountdir); 479 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir); 521 480 log_msg(1, "command was '%s'", command); 522 481 if (!strcmp(mountpoint, "swap")) { … … 524 483 } else { 525 484 log_msg(2, "Retrying w/o the '-t' switch"); 526 sprintf(command, "mount %s %s 2>> %s", device, mountdir,527 485 mr_free(command); 486 mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE); 528 487 log_msg(2, "2nd command = '%s'", command); 529 488 res = run_program_and_log_output(command, TRUE); … … 543 502 } 544 503 545 paranoid_free(tmp);546 paranoid_free(command);547 paranoid_free(mountdir);548 paranoid_free(mountpoint);549 550 504 mr_free(tmp); 505 mr_free(command); 506 mr_free(mountdir); 507 mr_free(mountpoint); 508 509 return (res); 551 510 } 552 511 /************************************************************************** … … 561 520 * @return The number of errors encountered (0 for success). 562 521 */ 563 int mount_all_devices(struct mountlist_itself 564 *p_external_copy_of_mountlist, bool writeable) 522 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable) 565 523 { 566 524 int retval = 0, lino, res; 567 char *tmp ;525 char *tmp = NULL; 568 526 char *these_failed = NULL; 569 char *format;570 527 struct mountlist_itself *mountlist = NULL; 571 572 malloc_string(tmp);573 malloc_string(format);574 528 575 529 assert(p_external_copy_of_mountlist != NULL); … … 581 535 582 536 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 583 open_progress_form("Mounting devices", 584 "I am now mounting all the drives.", 585 "This should not take long.", 586 "", mountlist->entries); 537 open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries); 587 538 588 539 mr_asprintf(these_failed, ""); 589 540 for (lino = 0; lino < mountlist->entries; lino++) { 590 541 if (!strcmp(mountlist->el[lino].device, "/proc")) { 591 log_msg(1, 592 "Again with the /proc - why is this in your mountlist?"); 542 log_msg(1, "Again with the /proc - why is this in your mountlist?"); 593 543 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 594 sprintf(tmp, "%s is already mounted", 595 mountlist->el[lino].device); 596 log_to_screen(tmp); 544 log_to_screen("%s is already mounted", mountlist->el[lino].device); 597 545 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 598 546 && strcmp(mountlist->el[lino].mountpoint, "lvm") 599 547 && strcmp(mountlist->el[lino].mountpoint, "raid") 600 548 && strcmp(mountlist->el[lino].mountpoint, "image")) { 601 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);549 mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device); 602 550 update_progress_form(tmp); 603 strcpy(format, mountlist->el[lino].format); 604 res = mount_device(mountlist->el[lino].device, 605 mountlist->el[lino].mountpoint, 606 format, writeable); 551 mr_free(tmp); 552 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable); 607 553 retval += res; 608 554 if (res) { … … 615 561 if (retval) { 616 562 if (g_partition_table_locked_up > 0) { 617 log_to_screen 618 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 619 log_to_screen 620 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 621 log_to_screen 622 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 623 } 624 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 563 log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 564 log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to"); 565 log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience."); 566 } 567 mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 625 568 626 569 if (!ask_me_yes_or_no(tmp)) { 627 570 retval = 0; 628 log_to_screen 629 ("Continuing, although some device(s) failed to be mounted"); 571 log_to_screen("Continuing, although some device(s) failed to be mounted"); 630 572 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 631 573 } else { 632 574 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 633 log_to_screen 634 ("Unable to mount some or all of your partitions.");635 }575 log_to_screen("Unable to mount some or all of your partitions."); 576 } 577 mr_free(tmp); 636 578 } else { 637 579 log_to_screen("All partitions were mounted OK."); … … 643 585 (void)mount_device("/proc","/proc","proc",TRUE); 644 586 (void)mount_device("/sys","/sys","sysfs",TRUE); 645 run_program_and_log_output("df -m ", 3);587 run_program_and_log_output("df -m -P", 3); 646 588 paranoid_free(mountlist); 647 paranoid_free(tmp);648 paranoid_free(format);649 589 return (retval); 650 590 } … … 652 592 *END_MOUNT_ALL_DEVICES * 653 593 **************************************************************************/ 654 655 656 594 657 595 … … 700 638 { 701 639 /** add mallocs **/ 702 char *value = NULL;640 char value[MAX_STR_LEN]; 703 641 char *tmp = NULL; 642 char *tmp1 = NULL; 704 643 char *envtmp1 = NULL; 705 644 char *envtmp2 = NULL; 706 645 char *command = NULL; 707 char *iso_mnt = NULL;708 char *iso_path = NULL;646 char iso_mnt[MAX_STR_LEN]; 647 char iso_path[MAX_STR_LEN]; 709 648 char *old_isodir = NULL; 710 char cfg_file[100];649 char *cfg_file = NULL; 711 650 t_bkptype media_specified_by_user; 712 651 713 malloc_string(command);714 malloc_string(iso_mnt);715 malloc_string(iso_path);716 malloc_string(old_isodir);717 malloc_string(value);718 malloc_string(tmp);719 652 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 720 653 assert(bkpinfo != NULL); 654 assert(cfgf != NULL); 721 655 log_it("Entering read_cfg_file_into_bkpinfo"); 722 656 … … 730 664 731 665 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 732 if (!strcmp(value, "cdstream")) { 733 bkpinfo->backup_media_type = cdstream; 734 } else if (!strcmp(value, "cdr")) { 735 bkpinfo->backup_media_type = cdr; 736 } else if (!strcmp(value, "cdrw")) { 737 bkpinfo->backup_media_type = cdrw; 738 } else if (!strcmp(value, "dvd")) { 739 bkpinfo->backup_media_type = dvd; 740 } else if (!strcmp(value, "usb")) { 741 bkpinfo->backup_media_type = usb; 742 bkpinfo->please_dont_eject = TRUE; 743 } else if (!strcmp(value, "iso")) { 744 bkpinfo->backup_media_type = iso; 745 if (am_I_in_disaster_recovery_mode()) { 746 /* Check to see if CD is already mounted before mounting it... */ 747 if (!is_this_device_mounted("/dev/cdrom")) { 748 log_msg(2, "NB: CDROM device not mounted, mounting..."); 749 run_program_and_log_output("mount /dev/cdrom " MNT_CDROM, 1); 750 } 751 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) { 752 bkpinfo->backup_media_type = cdr; 753 run_program_and_log_output("umount -d " MNT_CDROM, 1); 754 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 755 } 756 } 757 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 758 strcpy(bkpinfo->prefix,value); 666 if (!strcmp(value, "cdstream")) { 667 bkpinfo->backup_media_type = cdstream; 668 } else if (!strcmp(value, "cdr")) { 669 bkpinfo->backup_media_type = cdr; 670 } else if (!strcmp(value, "cdrw")) { 671 bkpinfo->backup_media_type = cdrw; 672 } else if (!strcmp(value, "dvd")) { 673 bkpinfo->backup_media_type = dvd; 674 } else if (!strcmp(value, "usb")) { 675 bkpinfo->backup_media_type = usb; 676 bkpinfo->please_dont_eject = TRUE; 677 } else if (!strcmp(value, "iso")) { 678 bkpinfo->backup_media_type = iso; 679 if (am_I_in_disaster_recovery_mode()) { 680 /* Check to see if CD is already mounted before mounting it... */ 681 if (!is_this_device_mounted("/dev/cdrom")) { 682 log_msg(2, "NB: CDROM device not mounted, mounting..."); 683 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1); 684 } 685 if (does_file_exist(MNT_CDROM"/archives/filelist.0")) { 686 bkpinfo->backup_media_type = cdr; 687 run_program_and_log_output("umount -d "MNT_CDROM, 1); 688 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 689 } 690 } 691 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 692 strcpy(bkpinfo->prefix,value); 693 } else { 694 strcpy(bkpinfo->prefix,STD_PREFIX); 695 } 696 log_it("Setting Prefix to %s", bkpinfo->prefix); 697 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) { 698 /* Stay compatible with previous versions by allowing nfs as an entry here */ 699 bkpinfo->backup_media_type = netfs; 700 bkpinfo->please_dont_eject = TRUE; 701 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) { 702 mr_asprintf(bkpinfo->netfs_proto,"%s", value); 703 } else { 704 /* For compatibility, force protocol in old nfs case to be transparent */ 705 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 706 } 707 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) { 708 mr_asprintf(bkpinfo->netfs_user,"%s", value); 709 } 710 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 711 strcpy(bkpinfo->prefix,value); 712 } else { 713 strcpy(bkpinfo->prefix,STD_PREFIX); 714 } 715 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) { 716 /* We need to override prefix value in PXE mode as it's 717 * already done in start-netfs */ 718 envtmp1 = getenv("imgname"); 719 if (envtmp1 == NULL) { 720 fatal_error("no imgname variable in environment"); 721 } 722 strcpy(bkpinfo->prefix,envtmp1); 723 } 724 } else if (!strcmp(value, "tape")) { 725 bkpinfo->backup_media_type = tape; 726 } else if (!strcmp(value, "udev")) { 727 bkpinfo->backup_media_type = udev; 759 728 } else { 760 strcpy(bkpinfo->prefix,STD_PREFIX); 761 } 762 log_it("Setting Prefix to %s", bkpinfo->prefix); 763 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) { 764 /* Stay compatible with previous versions by allowing nfs as an entry here */ 765 bkpinfo->backup_media_type = netfs; 766 bkpinfo->please_dont_eject = TRUE; 767 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) { 768 mr_asprintf(bkpinfo->netfs_proto,"%s", value); 769 } else { 770 /* For compatibility, force protocol in old nfs case to be transparent */ 771 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 772 } 773 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) { 774 mr_asprintf(bkpinfo->netfs_user,"%s", value); 775 } 776 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 777 strcpy(bkpinfo->prefix,value); 778 } else { 779 strcpy(bkpinfo->prefix,STD_PREFIX); 780 } 781 if (strstr(call_program_and_get_last_line_of_output 782 ("cat /proc/cmdline"), "pxe")) { 783 /* We need to override prefix value in PXE mode as it's 784 * already done in start-netfs */ 785 envtmp1 = getenv("imgname"); 786 if (envtmp1 == NULL) { 787 fatal_error("no imgname variable in environment"); 788 } 789 strcpy(bkpinfo->prefix,envtmp1); 790 } 791 792 } else if (!strcmp(value, "tape")) { 793 bkpinfo->backup_media_type = tape; 794 } else if (!strcmp(value, "udev")) { 795 bkpinfo->backup_media_type = udev; 729 fatal_error("UNKNOWN bkp-media-type"); 730 } 796 731 } else { 797 fatal_error("UNKNOWN bkp-media-type"); 798 } 799 } else { 800 fatal_error("backup-media-type not specified!"); 801 } 732 fatal_error("backup-media-type not specified!"); 733 } 734 802 735 if (bkpinfo->disaster_recovery) { 803 736 if (bkpinfo->backup_media_type == cdstream) { … … 814 747 } 815 748 sprintf(bkpinfo->media_device, "%s1", value); 816 sprintf(tmp, "Backup medium is USB --- dev=%s", bkpinfo->media_device); 817 log_msg(2, tmp); 818 } else if (bkpinfo->backup_media_type == tape 819 || bkpinfo->backup_media_type == udev) { 749 log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device); 750 } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 820 751 if (read_cfg_var(cfg_file, "media-dev", value)) { 821 752 fatal_error("Cannot get tape device name from cfg file"); … … 824 755 read_cfg_var(cfg_file, "media-size", value); 825 756 bkpinfo->media_size = atol(value); 826 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 827 bkpinfo->media_device); 828 log_msg(2, tmp); 757 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device); 829 758 } else { 830 759 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ … … 833 762 } 834 763 } else { 835 log_msg(2, 836 "Not in Disaster Recovery Mode. No need to derive device name from config file."); 764 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file."); 837 765 } 838 766 … … 867 795 868 796 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { 869 bkpinfo->internal_tape_block_size = atol(value); 870 log_msg(1, "Internal tape block size has been custom-set to %ld", 871 bkpinfo->internal_tape_block_size); 797 bkpinfo->internal_tape_block_size = atol(value); 872 798 } else { 873 bkpinfo->internal_tape_block_size = 874 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 875 log_msg(1, "Internal tape block size = default (%ld)", 876 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 799 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 800 } 801 log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size); 802 803 read_cfg_var(cfg_file, "use-lzma", value); 804 if (strstr(value, "yes")) { 805 bkpinfo->use_lzma = TRUE; 806 bkpinfo->use_lzo = FALSE; 807 bkpinfo->use_gzip = FALSE; 808 strcpy(bkpinfo->zip_exe, "lzma"); 809 strcpy(bkpinfo->zip_suffix, "lzma"); 877 810 } 878 811 879 812 read_cfg_var(cfg_file, "use-lzo", value); 880 813 if (strstr(value, "yes")) { 881 bkpinfo->use_lzo = TRUE; 882 bkpinfo->use_gzip = FALSE; 883 strcpy(bkpinfo->zip_exe, "lzop"); 884 strcpy(bkpinfo->zip_suffix, "lzo"); 885 } else { 814 bkpinfo->use_lzma = FALSE; 815 bkpinfo->use_lzo = TRUE; 816 bkpinfo->use_gzip = FALSE; 817 strcpy(bkpinfo->zip_exe, "lzop"); 818 strcpy(bkpinfo->zip_suffix, "lzo"); 819 } 820 886 821 read_cfg_var(cfg_file, "use-gzip", value); 887 822 if (strstr(value, "yes")) { 823 bkpinfo->use_lzma = FALSE; 888 824 bkpinfo->use_lzo = FALSE; 889 825 bkpinfo->use_gzip = TRUE; 890 826 strcpy(bkpinfo->zip_exe, "gzip"); 891 827 strcpy(bkpinfo->zip_suffix, "gz"); 892 } else { 893 read_cfg_var(cfg_file, "use-comp", value); 894 if (strstr(value, "yes")) { 895 bkpinfo->use_lzo = FALSE; 896 bkpinfo->use_gzip = FALSE; 897 strcpy(bkpinfo->zip_exe, "bzip2"); 898 strcpy(bkpinfo->zip_suffix, "bz2"); 899 } else { 900 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 901 } 902 } 828 } 829 830 read_cfg_var(cfg_file, "use-comp", value); 831 if (strstr(value, "yes")) { 832 bkpinfo->use_lzma = FALSE; 833 bkpinfo->use_lzo = FALSE; 834 bkpinfo->use_gzip = FALSE; 835 strcpy(bkpinfo->zip_exe, "bzip2"); 836 strcpy(bkpinfo->zip_suffix, "bz2"); 903 837 } 904 838 … … 906 840 read_cfg_var(cfg_file, "differential", value); 907 841 if (!strcmp(value, "yes") || !strcmp(value, "1")) { 908 bkpinfo->differential = TRUE;842 bkpinfo->differential = TRUE; 909 843 } 910 844 log_msg(2, "differential var = '%s'", value); 911 845 if (bkpinfo->differential) { 912 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");846 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); 913 847 } else { 914 log_msg(2, "This is a regular (full) backup");915 } 916 917 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);918 if ( tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) {848 log_msg(2, "This is a regular (full) backup"); 849 } 850 851 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", value); 852 if (value[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) { 919 853 bkpinfo->please_dont_eject = TRUE; 920 854 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); … … 923 857 if (bkpinfo->backup_media_type == netfs) { 924 858 if (!cfgf) { 925 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount); 926 log_msg(2, "netfs_remote_dir remains %s", 927 bkpinfo->netfs_remote_dir); 928 log_msg(2, 929 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 859 if (bkpinfo->netfs_mount) { 860 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount); 861 } 862 if (bkpinfo->netfs_remote_dir) { 863 log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir); 864 } 865 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 930 866 } else { 931 read_cfg_var(g_mondo_cfg_file, "netfs-server-mount", 932 bkpinfo->netfs_mount); 933 read_cfg_var(g_mondo_cfg_file, "netfs-server-path", 934 bkpinfo->netfs_remote_dir); 935 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount); 936 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto); 937 if (bkpinfo->netfs_user) { 867 read_cfg_var(g_mondo_cfg_file, "netfs-server-mount", value); 868 mr_free(bkpinfo->netfs_mount); 869 mr_asprintf(bkpinfo->netfs_mount, "%s", value); 870 871 read_cfg_var(g_mondo_cfg_file, "netfs-server-path", value); 872 mr_free(bkpinfo->netfs_remote_dir); 873 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value); 874 875 if (bkpinfo->netfs_mount != NULL) { 876 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount); 877 } 878 if (bkpinfo->netfs_remote_dir != NULL) { 879 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir); 880 } 881 if (bkpinfo->netfs_proto != NULL) { 882 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto); 883 } 884 if (bkpinfo->netfs_user != NULL) { 938 885 log_msg(2, "netfs_user is %s", bkpinfo->netfs_user); 939 886 } 940 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir); 941 } 942 if (strstr(call_program_and_get_last_line_of_output 943 ("cat /proc/cmdline"), "pxe")) { 887 } 888 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) { 944 889 /* We need to override values in PXE mode as it's 945 890 * already done in start-netfs */ … … 952 897 fatal_error("no dirimg variable in environment"); 953 898 } 954 strcpy(bkpinfo->netfs_mount,envtmp1); 955 strcpy(bkpinfo->netfs_remote_dir,envtmp2); 899 mr_free(bkpinfo->netfs_mount); 900 mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1); 901 902 mr_free(bkpinfo->netfs_remote_dir); 903 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2); 956 904 } 957 905 } else if (bkpinfo->backup_media_type == iso) { … … 960 908 * isodir in disaster recovery mode 961 909 */ 962 strcpy(old_isodir, bkpinfo->isodir);910 mr_asprintf(old_isodir, "%s", bkpinfo->isodir); 963 911 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 964 912 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); … … 969 917 if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) { 970 918 if (strcmp(old_isodir, bkpinfo->isodir)) { 971 log_it 972 ("user nominated isodir %s differs from archive %s, keeping user's choice\n", 973 old_isodir, bkpinfo->isodir); 919 log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir ); 974 920 strcpy(bkpinfo->isodir, old_isodir); 975 921 } … … 982 928 983 929 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 930 984 931 if (bkpinfo->disaster_recovery) { 985 932 if (is_this_device_mounted(g_isodir_device)) { 986 933 log_msg(2, "NB: isodir is already mounted"); 987 934 /* Find out where it's mounted */ 988 sprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);935 mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device); 989 936 log_it("command = %s", command); 990 log_it("res of it = %s", 991 call_program_and_get_last_line_of_output(command)); 992 sprintf(iso_mnt, "%s", 993 call_program_and_get_last_line_of_output(command)); 937 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 938 mr_strcpy(iso_mnt, call_program_and_get_last_line_of_output(command)); 939 mr_free(command); 994 940 } else { 995 sprintf(iso_mnt, "/tmp/isodir"); 996 sprintf(tmp, "mkdir -p %s", iso_mnt); 997 run_program_and_log_output(tmp, 5); 998 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 999 if (run_program_and_log_output(tmp, 3)) { 1000 log_msg(1, 1001 "Unable to mount isodir. Perhaps this is really a CD backup?"); 941 mr_asprintf(iso_mnt, "/tmp/isodir"); 942 mr_asprintf(tmp1, "mkdir -p %s", iso_mnt); 943 run_program_and_log_output(tmp1, 5); 944 mr_free(tmp1); 945 946 mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt); 947 if (run_program_and_log_output(tmp1, 3)) { 948 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?"); 1002 949 bkpinfo->backup_media_type = cdr; 1003 950 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */ 1004 951 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1005 952 if (mount_media()) { 1006 fatal_error1007 953 mr_free(tmp1); 954 fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well."); 1008 955 } else { 1009 log_msg(1, 1010 "You backed up to disk, then burned some CDs.");1011 1012 }956 log_msg(1, "You backed up to disk, then burned some CDs."); 957 } 958 } 959 mr_free(tmp1); 1013 960 } 1014 961 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */ 1015 /* except when already done i siso_fiddly_bits */962 /* except when already done in iso_fiddly_bits */ 1016 963 if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) { 1017 964 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); … … 1027 974 media_specified_by_user = bkpinfo->backup_media_type; 1028 975 get_cfg_file_from_archive(); 1029 /*1030 if (media_specified_by_user != cdr && media_specified_by_user == cdrw)1031 { g_restoring_live_from_cd = FALSE; }1032 */1033 976 } 1034 977 } … … 1037 980 g_backup_media_type = bkpinfo->backup_media_type; 1038 981 paranoid_free(value); 1039 paranoid_free(tmp);1040 paranoid_free(command);1041 982 paranoid_free(iso_mnt); 1042 983 paranoid_free(iso_path); 1043 paranoid_free(old_isodir);1044 984 return (0); 1045 985 … … 1068 1008 struct s_node *filelist; 1069 1009 1070 /** add mallocs**/ 1071 char *command; 1010 char *command = NULL; 1072 1011 char *tmp; 1073 1012 char *q; … … 1077 1016 1078 1017 assert(bkpinfo != NULL); 1079 malloc_string(command);1080 1018 malloc_string(tmp); 1081 1019 … … 1105 1043 unlink(FILELIST_FULL_STUB); 1106 1044 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1107 sprintf(command, 1108 "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", 1109 bkpinfo->internal_tape_block_size, 1110 bkpinfo->media_device, 1111 MOUNTLIST_FNAME_STUB, 1112 BIGGIELIST_TXT_STUB, 1113 FILELIST_FULL_STUB, 1114 IWANTMYLVM_STUB, 1115 MONDO_CFG_FILE_STUB); 1045 mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1116 1046 log_msg(1, "tarcommand = %s", command); 1117 1047 run_program_and_log_output(command, 1); 1048 mr_free(command); 1049 1118 1050 if (!does_file_exist(FILELIST_FULL_STUB)) { 1119 1051 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 1120 1052 log_msg(2, "pre-2.2.4 compatible mode on"); 1121 sprintf(command, 1122 "tar -b %ld -zxf %s %s %s %s %s %s", 1123 bkpinfo->internal_tape_block_size, 1124 bkpinfo->media_device, 1125 MOUNTLIST_FNAME_STUB, 1126 BIGGIELIST_TXT_STUB, 1127 FILELIST_FULL_STUB, 1128 IWANTMYLVM_STUB, 1129 MONDO_CFG_FILE_STUB); 1053 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1130 1054 log_msg(1, "tarcommand = %s", command); 1131 1055 run_program_and_log_output(command, 1); 1056 mr_free(command); 1132 1057 } 1133 1058 } else { 1134 log_msg(2, 1135 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1136 bkpinfo->isodir); 1059 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir); 1137 1060 insist_on_this_cd_number(1); 1138 1061 log_msg(2, "Back from iotcn"); 1139 1062 run_program_and_log_output("mount", 1); 1140 sprintf(command, 1141 "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", 1142 MNT_CDROM, 1143 MOUNTLIST_FNAME_STUB, 1144 BIGGIELIST_TXT_STUB, 1145 FILELIST_FULL_STUB, 1146 IWANTMYLVM_STUB, 1147 MONDO_CFG_FILE_STUB); 1063 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1148 1064 1149 1065 log_msg(1, "tarcommand = %s", command); 1150 1066 run_program_and_log_output(command, 1); 1067 mr_free(command); 1068 1151 1069 if (!does_file_exist(FILELIST_FULL_STUB)) { 1152 1070 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 1153 1071 log_msg(2, "pre-2.2.4 compatible mode on"); 1154 sprintf(command, 1155 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1156 MNT_CDROM, 1157 MOUNTLIST_FNAME_STUB, 1158 BIGGIELIST_TXT_STUB, 1159 FILELIST_FULL_STUB, 1160 IWANTMYLVM_STUB, 1161 MONDO_CFG_FILE_STUB); 1072 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1162 1073 1163 1074 log_msg(1, "tarcommand = %s", command); 1164 1075 run_program_and_log_output(command, 1); 1076 mr_free(command); 1165 1077 } 1166 1078 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1167 fatal_error 1168 ("all.tar.gz did not include " BIGGIELIST_TXT_STUB); 1079 fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB); 1169 1080 } 1170 1081 if (!does_file_exist(FILELIST_FULL_STUB)) { 1171 fatal_error 1172 ("all.tar.gz did not include " FILELIST_FULL_STUB); 1173 } 1174 } 1175 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1176 g_mondo_cfg_file); 1082 fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB); 1083 } 1084 } 1085 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file); 1177 1086 run_program_and_log_output(command, FALSE); 1178 1179 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1180 BIGGIELIST_TXT_STUB, g_biggielist_txt);1087 mr_free(command); 1088 1089 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt); 1181 1090 log_msg(1, "command = %s", command); 1182 1091 paranoid_system(command); 1183 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1184 FILELIST_FULL_STUB, g_filelist_full); 1092 mr_free(command); 1093 1094 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full); 1185 1095 log_msg(1, "command = %s", command); 1186 1096 paranoid_system(command); 1097 mr_free(command); 1187 1098 } 1188 1099 … … 1194 1105 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1195 1106 { 1196 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,1197 bkpinfo->tmpdir);1198 paranoid_system(command);1107 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir); 1108 paranoid_system(command); 1109 mr_free(command); 1199 1110 } 1200 1111 … … 1209 1120 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1210 1121 } 1211 // popup_and_OK("Wonderful.");1212 1122 1213 1123 log_msg(2, "Forking"); … … 1221 1131 log_to_screen("Pre-processing filelist"); 1222 1132 if (!does_file_exist(g_biggielist_txt)) { 1223 sprintf(command, "echo -n > %s", g_biggielist_txt);1133 mr_asprintf(command, "echo -n > %s", g_biggielist_txt); 1224 1134 paranoid_system(command); 1225 }1226 sprintf(command, "grep -E '^/dev/.*' %s > %s",1227 1135 mr_free(command); 1136 } 1137 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs); 1228 1138 paranoid_system(command); 1139 mr_free(command); 1229 1140 exit(0); 1230 1141 break; … … 1247 1158 while (q == NULL) { 1248 1159 printf("Restore which directory? --> "); 1249 q = fgets(tmp, sizeof(tmp), stdin);1250 } 1251 toggle_path_selection(filelist, tmp, TRUE);1252 if (strlen( tmp) == 0) {1160 mr_getline(q, stdin); 1161 } 1162 toggle_path_selection(filelist, q, TRUE); 1163 if (strlen(q) == 0) { 1253 1164 res = 1; 1254 1165 } else { 1255 1166 res = 0; 1256 1167 } 1168 mr_free(q); 1257 1169 } else { 1258 1170 res = edit_filelist(filelist); … … 1277 1189 } 1278 1190 1279 paranoid_free(command);1280 1191 paranoid_free(tmp); 1281 1192 return (filelist); … … 1298 1209 int backup_crucial_file(char *path_root, char *filename) 1299 1210 { 1300 char *tmp ;1301 char *command ;1211 char *tmp = NULL; 1212 char *command = NULL; 1302 1213 int res; 1303 1214 1304 malloc_string(tmp);1305 malloc_string(command);1306 1215 assert(path_root != NULL); 1307 1216 assert_string_is_neither_NULL_nor_zerolength(filename); 1308 1217 1309 sprintf(tmp, "%s/%s", path_root, filename); 1310 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1218 mr_asprintf(tmp, "%s/%s", path_root, filename); 1219 mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1220 mr_free(tmp); 1311 1221 1312 1222 res = run_program_and_log_output(command, 5); 1313 paranoid_free(tmp); 1314 paranoid_free(command); 1223 mr_free(command); 1315 1224 return (res); 1316 1225 } … … 1358 1267 1359 1268 /** malloc *******/ 1360 char *device; 1361 char *tmp = NULL; 1362 char *name; 1269 char *device = NULL; 1270 char *name = NULL; 1363 1271 char *cmd = NULL; 1364 1272 … … 1385 1293 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1386 1294 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1387 mr_asprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1388 log_msg(2, tmp); 1389 paranoid_free(tmp); 1390 paranoid_system("sync"); 1295 log_msg(2, "run_boot_loader: device='%s', name='%s'", device, name); 1296 sync(); 1391 1297 1392 1298 offer_to_make_initrd(); … … 1408 1314 mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device); 1409 1315 if (!system(tmp)) { 1410 paranoid_free(tmp);1316 mr_free(tmp); 1411 1317 mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1412 1318 res = run_program_and_log_output(tmp, 3); 1413 1319 } else { 1414 log_msg(1, 1415 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1416 } 1417 paranoid_free(tmp); 1320 log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1321 } 1322 mr_free(tmp); 1418 1323 } 1419 1324 #else … … 1446 1351 * @note The returned string points to static storage that will be overwritten with each call. 1447 1352 */ 1448 char *find_my_editor(void) 1449 { 1353 char *find_my_editor(void) { 1354 1450 1355 static char output[MAX_STR_LEN]; 1451 1356 if (find_home_of_exe("pico")) { … … 1476 1381 { 1477 1382 /** malloc **/ 1478 char *command; 1479 char *boot_device; 1480 char *rootdev; 1481 char *rootdrive; 1482 char *conffile; 1483 char *tmp; 1484 char *editor; 1485 1383 char *command = NULL; 1384 char *boot_device = NULL; 1385 char *tmp = NULL; 1386 char *editor = NULL; 1387 1388 bool done; 1486 1389 int res = 0; /* FALSE */ 1487 int done;1488 1390 bool mntlistchg = FALSE; 1489 1391 FILE *fin = NULL; 1490 1392 1491 malloc_string(command);1492 1393 malloc_string(boot_device); 1493 malloc_string(tmp); 1494 malloc_string(editor); 1495 malloc_string(rootdev); 1496 malloc_string(rootdrive); 1497 malloc_string(conffile); 1394 1498 1395 assert_string_is_neither_NULL_nor_zerolength(bd); 1499 strcpy(editor, find_my_editor());1500 1396 strcpy(boot_device, bd); 1501 1397 1502 if (!run_program_and_log_output("which grub-MR", FALSE)) {1503 log_msg(1, "Yay! grub-MR found...");1504 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);1505 log_msg(1, "command = %s", command);1506 } else {1507 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",1508 boot_device);1509 log_msg(1, "WARNING - grub-MR not found; using grub-install");1510 }1511 1398 if (offer_to_run_stabgrub 1512 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) 1399 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) { 1513 1400 /* interactive mode */ 1514 {1515 1401 mvaddstr_and_log_it(g_currentY, 1516 1402 0, … … 1521 1407 } 1522 1408 for (done = FALSE; !done;) { 1523 popup_and_get_string("Boot device", 1524 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1525 boot_device, MAX_STR_LEN / 4); 1409 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4); 1526 1410 /* Only try to adapt grub here first if the mountlist wasn't changed before */ 1527 1411 if (! mntlistchg) { 1528 sprintf(command, "stabgrub-me %s", boot_device);1412 mr_asprintf(command, "stabgrub-me %s", boot_device); 1529 1413 res = run_program_and_log_output(command, 1); 1530 } 1531 if ((res) || (mntlistchg)){ 1414 mr_free(command); 1415 } 1416 1417 if ((res) || (mntlistchg)) { 1532 1418 if (res) { 1533 1419 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); … … 1538 1424 newtSuspend(); 1539 1425 } 1540 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1426 mr_asprintf(editor, "%s", find_my_editor()); 1427 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1541 1428 paranoid_system(tmp); 1542 sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1429 mr_free(tmp); 1430 1431 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1543 1432 paranoid_system(tmp); 1433 mr_free(tmp); 1434 1544 1435 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1545 sprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);1436 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1546 1437 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1547 sprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);1438 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1548 1439 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) { 1549 sprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);1440 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor); 1550 1441 } 1551 1442 paranoid_system(tmp); 1443 mr_free(tmp); 1444 1552 1445 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) { 1553 sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);1446 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor); 1554 1447 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) { 1555 sprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);1556 1448 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor); 1449 } 1557 1450 paranoid_system(tmp); 1451 mr_free(tmp); 1452 mr_free(editor); 1453 1558 1454 if (!g_text_mode) { 1559 1455 newtResume(); 1560 1456 } 1561 sprintf(command, "stabgrub-me %s", boot_device);1457 mr_asprintf(command, "stabgrub-me %s", boot_device); 1562 1458 res = run_program_and_log_output(command, 1); 1459 mr_free(command); 1460 1563 1461 if (res) { 1564 popup_and_OK 1565 ("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1462 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1566 1463 newtSuspend(); 1567 1464 paranoid_system("chroot " MNT_RESTORING); … … 1576 1473 } 1577 1474 } 1578 } else 1475 } else { 1579 1476 /* nuke mode */ 1580 { 1581 mvaddstr_and_log_it(g_currentY, 1582 0, 1583 "Running GRUB... "); 1477 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1478 log_msg(1, "Yay! grub-MR found..."); 1479 mr_asprintf(command, "grub-MR %s "MINDI_CACHE"/mountlist.txt", boot_device); 1480 log_msg(1, "command = %s", command); 1481 } else { 1482 mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device); 1483 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1484 } 1485 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... "); 1584 1486 log_it("%s",command); 1585 1487 res = run_program_and_log_output(command, 1); 1488 mr_free(command); 1489 1586 1490 if (res) { 1587 1491 popup_and_OK … … 1609 1513 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1610 1514 } 1611 paranoid_free(rootdev);1612 paranoid_free(rootdrive);1613 paranoid_free(conffile);1614 paranoid_free(command);1615 1515 paranoid_free(boot_device); 1616 paranoid_free(tmp);1617 paranoid_free(editor);1618 1516 1619 1517 return (res); … … 1633 1531 { 1634 1532 /** malloc **/ 1635 char *command ;1636 char *tmp ;1637 char *editor ;1533 char *command = NULL; 1534 char *tmp = NULL; 1535 char *editor = NULL; 1638 1536 1639 1537 int res; 1640 1538 int done; 1641 1539 1642 malloc_string(command);1643 malloc_string(tmp);1644 malloc_string(editor);1645 strcpy(editor, find_my_editor());1646 1540 if (offer_to_run_stabelilo 1647 1541 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) … … 1652 1546 0, 1653 1547 "Modifying fstab and elilo.conf... "); 1654 sprintf(command, "stabelilo-me");1548 mr_asprintf(command, "stabelilo-me"); 1655 1549 res = run_program_and_log_output(command, 3); 1550 mr_free(command); 1551 1656 1552 if (res) { 1657 1553 popup_and_OK … … 1661 1557 newtSuspend(); 1662 1558 } 1663 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1559 mr_asprintf(editor, "%s", find_my_editor()); 1560 1561 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1664 1562 paranoid_system(tmp); 1665 sprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor); 1563 mr_free(tmp); 1564 1565 mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor); 1666 1566 paranoid_system(tmp); 1567 mr_free(tmp); 1568 mr_free(editor); 1569 1667 1570 if (!g_text_mode) { 1668 1571 newtResume(); … … 1682 1585 res = TRUE; 1683 1586 } 1684 paranoid_free(command);1685 paranoid_free(tmp);1686 paranoid_free(editor);1687 1587 return (res); 1688 1588 } … … 1701 1601 { 1702 1602 /** malloc **/ 1703 char *command ;1704 char *tmp ;1705 char *editor ;1603 char *command = NULL; 1604 char *tmp = NULL; 1605 char *editor = NULL; 1706 1606 1707 1607 int res; 1708 1608 int done; 1709 1609 bool run_lilo_M = FALSE; 1710 malloc_string(command);1711 malloc_string(tmp);1712 malloc_string(editor);1713 1610 1714 1611 if (!run_program_and_log_output … … 1717 1614 } 1718 1615 1719 strcpy(editor, find_my_editor());1720 1616 if (offer_to_run_stablilo 1721 1617 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) … … 1726 1622 0, 1727 1623 "Modifying fstab and lilo.conf, and running LILO... "); 1728 sprintf(command, "stablilo-me");1624 mr_asprintf(command, "stablilo-me"); 1729 1625 res = run_program_and_log_output(command, 3); 1626 mr_free(command); 1627 1730 1628 if (res) { 1731 1629 popup_and_OK … … 1735 1633 newtSuspend(); 1736 1634 } 1737 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1635 mr_asprintf(editor, "%s", find_my_editor()); 1636 1637 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1738 1638 paranoid_system(tmp); 1739 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1639 mr_free(tmp); 1640 1641 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1740 1642 paranoid_system(tmp); 1643 mr_free(tmp); 1644 mr_free(editor); 1645 1741 1646 if (!g_text_mode) { 1742 1647 newtResume(); … … 1793 1698 " lilo -M /dev/sda", 3); 1794 1699 } 1795 paranoid_free(command);1796 paranoid_free(tmp);1797 paranoid_free(editor);1798 1700 return (res); 1799 1701 } … … 1813 1715 { 1814 1716 /** malloc **/ 1815 char *command ;1816 char *boot_device ;1817 char *tmp ;1717 char *command = NULL; 1718 char *boot_device = NULL; 1719 char *tmp = NULL; 1818 1720 char *editor; 1819 1721 int res; 1820 1722 int done; 1821 1723 1822 malloc_string(command);1823 1724 malloc_string(boot_device); 1824 malloc_string(tmp);1825 malloc_string(editor);1826 1725 assert_string_is_neither_NULL_nor_zerolength(bd); 1827 1726 1828 strcpy(editor, find_my_editor());1829 1727 strcpy(boot_device, bd); 1830 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);1831 log_msg(2, "run_raw_mbr() --- command='%s'", command);1832 1728 1833 1729 if (offer_to_hack_scripts 1834 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) 1730 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) { 1835 1731 /* interactive mode */ 1836 {1837 1732 mvaddstr_and_log_it(g_currentY, 0, 1838 1733 "Modifying fstab and restoring MBR... "); … … 1843 1738 newtSuspend(); 1844 1739 } 1845 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1740 mr_asprintf(editor, "%s", find_my_editor()); 1741 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1742 mr_free(editor); 1743 1846 1744 paranoid_system(tmp); 1745 mr_free(tmp); 1847 1746 if (!g_text_mode) { 1848 1747 newtResume(); 1849 1748 } 1850 // newtCls(); 1851 } 1852 popup_and_get_string("Boot device", 1853 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1854 boot_device, MAX_STR_LEN / 4); 1855 sprintf(command, "stabraw-me %s", boot_device); 1749 } 1750 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4); 1751 mr_asprintf(command, "stabraw-me %s", boot_device); 1856 1752 res = run_program_and_log_output(command, 3); 1753 mr_free(command); 1754 1857 1755 if (res) { 1858 1756 done = ask_me_yes_or_no("Modifications failed. Re-try?"); … … 1861 1759 } 1862 1760 } 1863 } else 1761 } else { 1864 1762 /* nuke mode */ 1865 { 1763 mr_asprintf(command, "raw-MR %s "MINDI_CACHE"/mountlist.txt", boot_device); 1764 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1765 1866 1766 mvaddstr_and_log_it(g_currentY, 0, 1867 1767 "Restoring MBR... "); 1868 1768 res = run_program_and_log_output(command, 3); 1769 mr_free(command); 1869 1770 } 1870 1771 if (res) { … … 1875 1776 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1876 1777 } 1877 paranoid_free(command);1878 1778 paranoid_free(boot_device); 1879 paranoid_free(tmp);1880 paranoid_free(editor);1881 1779 return (res); 1882 1780 } … … 1907 1805 malloc_string(g_mountlist_fname); 1908 1806 malloc_string(g_mondo_home); 1909 /*1910 malloc_string(g_tmpfs_mountpt);1911 */1912 1807 malloc_string(g_isodir_device); 1913 1808 malloc_string(g_isodir_format); … … 1946 1841 FILE *fin; 1947 1842 FILE *fout; 1948 /** malloc **/ 1949 char *incoming; 1950 char *q; 1843 char *incoming = NULL; 1951 1844 1952 1845 assert_string_is_neither_NULL_nor_zerolength(output_file); 1953 1846 assert_string_is_neither_NULL_nor_zerolength(input_file); 1954 malloc_string(incoming);1955 1847 1956 1848 if (!(fin = fopen(input_file, "r"))) { … … 1961 1853 fatal_error("cannot open output_file"); 1962 1854 } 1963 for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL); 1964 q = fgets(incoming, MAX_STR_LEN - 1, fin)) { 1855 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 1965 1856 if (strncmp(incoming, "etc/adjtime", 11) 1966 1857 && strncmp(incoming, "etc/mtab", 8) … … 1971 1862 && strncmp(incoming, "var/", 4)) 1972 1863 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 1973 } 1864 mr_free(incoming); 1865 } 1866 mr_free(incoming); 1974 1867 paranoid_fclose(fout); 1975 1868 paranoid_fclose(fin); 1976 paranoid_free(incoming);1977 1869 } 1978 1870 … … 1989 1881 int i; 1990 1882 /* MALLOC * */ 1991 char *tmp; 1992 1993 malloc_string(tmp); 1883 char *tmp = NULL; 1884 1994 1885 if (does_file_exist("/tmp/NOPAUSE")) { 1995 1886 return; … … 2001 1892 for (i = 0; i < 20; i++) { 2002 1893 g_current_progress = i; 2003 sprintf(tmp, "You have %d seconds left to abort.", 20 - i);1894 mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i); 2004 1895 update_progress_form(tmp); 1896 mr_free(tmp); 2005 1897 sleep(1); 2006 1898 } 2007 1899 close_progress_form(); 2008 paranoid_free(tmp);2009 1900 } 2010 1901 … … 2024 1915 struct mountlist_itself *mountlist; 2025 1916 int retval = 0, lino, res = 0, i; 2026 char *command ;1917 char *command = NULL; 2027 1918 char *tmp = NULL; 2028 1919 2029 malloc_string(command);2030 1920 assert(p_external_copy_of_mountlist != NULL); 2031 1921 … … 2035 1925 sort_mountlist_by_mountpoint(mountlist, 0); 2036 1926 2037 run_program_and_log_output("df -m ", 3);1927 run_program_and_log_output("df -m -P", 3); 2038 1928 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices "); 2039 1929 open_progress_form("Unmounting devices", … … 2054 1944 } 2055 1945 2056 paranoid_system("sync");1946 sync(); 2057 1947 2058 1948 mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE); … … 2068 1958 2069 1959 /* Unmounting the local /proc and /sys first */ 2070 run_program_and_log_output("umount " MNT_RESTORING "/proc",3);2071 run_program_and_log_output("umount " MNT_RESTORING "/sys",3);1960 run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3); 1961 run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3); 2072 1962 2073 1963 for (lino = mountlist->entries - 1; lino >= 0; lino--) { … … 2076 1966 } 2077 1967 mr_asprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device); 2078 2079 1968 update_progress_form(tmp); 2080 1969 2081 1970 if (is_this_device_mounted(mountlist->el[lino].device)) { 2082 1971 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { 2083 sprintf(command, "swapoff %s", mountlist->el[lino].device);1972 mr_asprintf(command, "swapoff %s", mountlist->el[lino].device); 2084 1973 } else { 2085 1974 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) { 2086 sprintf(command, "umount%s/", MNT_RESTORING);1975 mr_asprintf(command, "umount -d %s/", MNT_RESTORING); 2087 1976 log_msg(3, 2088 1977 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2089 1978 } else { 2090 sprintf(command, "umount " MNT_RESTORING "%s", 2091 mountlist->el[lino].mountpoint); 1979 mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint); 2092 1980 2093 1981 /* To support latest Ubuntu where /var is a separate FS … … 2102 1990 log_msg(10, "The 'umount' command is '%s'", command); 2103 1991 res = run_program_and_log_output(command, 3); 1992 mr_free(command); 2104 1993 } else { 2105 1994 mr_strcat(tmp, "...not mounted anyway :-) OK"); … … 2128 2017 } 2129 2018 free(mountlist); 2130 paranoid_free(command);2131 2019 return (retval); 2132 2020 } … … 2135 2023 *END_UNMOUNT_ALL_DEVICES * 2136 2024 **************************************************************************/ 2137 2138 2139 2025 2140 2026 /** … … 2146 2032 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 2147 2033 { 2148 char *command ;2034 char *command = NULL; 2149 2035 int res = 0; 2150 2151 malloc_string(command);2152 2036 2153 2037 if (bkpinfo->use_obdr) { … … 2158 2042 } 2159 2043 2160 sprintf(command, 2161 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", 2162 dev, 2163 bkpinfo->internal_tape_block_size, 2164 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, 2165 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2166 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); 2044 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); 2167 2045 log_msg(2, "command = '%s'", command); 2168 2046 res = run_program_and_log_output(command, -1); 2047 mr_free(command); 2048 2169 2049 if (res != 0) { 2170 2050 if (does_file_exist(MONDO_CFG_FILE_STUB)) { … … 2173 2053 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 2174 2054 log_msg(2, "pre-2.2.4 compatible mode on"); 2175 sprintf(command, 2176 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2177 dev, 2178 bkpinfo->internal_tape_block_size, 2179 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, 2180 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2181 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); 2055 mr_sprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); 2182 2056 log_msg(2, "command = '%s'", command); 2183 2057 res = run_program_and_log_output(command, -1); 2058 mr_free(command); 2184 2059 if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) { 2185 2060 res = 0; … … 2190 2065 return (res); 2191 2066 } 2192 2193 2067 2194 2068 … … 2206 2080 2207 2081 /** malloc *****/ 2208 char *device; 2209 char *command; 2210 char *cfg_file; 2211 char *mounted_cfgf_path; 2212 char *tmp; 2213 char *mountpt; 2214 char *ramdisk_fname; 2215 char *mountlist_file; 2082 char *command = NULL; 2083 char *cfg_file = NULL; 2084 char *tmp = NULL; 2085 char *mountpt = NULL; 2086 char *mountlist_file = NULL; 2216 2087 bool extract_mountlist_stub = FALSE; 2217 2088 bool extract_i_want_my_lvm = FALSE; … … 2220 2091 2221 2092 assert(bkpinfo != NULL); 2222 malloc_string(cfg_file);2223 malloc_string(mounted_cfgf_path);2224 malloc_string(mountpt);2225 malloc_string(ramdisk_fname);2226 malloc_string(mountlist_file);2227 malloc_string(device);2228 malloc_string(command);2229 malloc_string(tmp);2230 2093 log_msg(2, "gcffa --- starting"); 2231 2094 log_to_screen("I'm thinking..."); 2232 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2233 device[0] = '\0'; 2095 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2234 2096 if (chdir(bkpinfo->tmpdir)) { 2235 2097 // FIXME 2236 2098 } 2237 strcpy(cfg_file, MONDO_CFG_FILE_STUB);2099 mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB); 2238 2100 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent 2101 mr_free(cfg_file); 2102 2239 2103 unlink(FILELIST_FULL_STUB); 2240 2104 unlink(BIGGIELIST_TXT_STUB); 2241 sprintf(command, "mkdir -p %s", mountpt);2105 mr _asprintf(command, "mkdir -p %s", mountpt); 2242 2106 run_program_and_log_output(command, FALSE); 2243 2244 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2245 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2246 // make_hole_for_file( cfg_file ); 2247 // make_hole_for_file( mountlist_file); 2107 mr_free(command); 2108 2109 mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2110 mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2248 2111 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file); 2112 mr_free(mountpt); 2249 2113 2250 2114 if (!does_file_exist(cfg_file)) { … … 2276 2140 log_msg(2, "media_device is blank; assuming %s"); 2277 2141 } 2278 strcpy(tmp, bkpinfo->media_device);2142 mr_asprintf(tmp, "%s", bkpinfo->media_device); 2279 2143 if (extract_cfg_file_and_mountlist_from_tape_dev 2280 2144 (bkpinfo->media_device)) { … … 2295 2159 } 2296 2160 } 2161 mr_free(tmp); 2297 2162 2298 2163 if (!does_file_exist("tmp/mondo-restore.cfg")) { … … 2314 2179 log_msg(2, 2315 2180 "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz"); 2316 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2181 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2317 2182 run_program_and_log_output(command, TRUE); 2183 mr_free(command); 2184 2318 2185 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2319 2186 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 2320 2187 log_msg(2, "pre-2.2.4 compatible mode on"); 2321 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2188 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2322 2189 run_program_and_log_output(command, TRUE); 2190 mr_free(command); 2323 2191 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2324 2192 fatal_error … … 2330 2198 if (does_file_exist(MONDO_CFG_FILE_STUB)) { 2331 2199 log_msg(1, "gcffa --- great! We've got the config file"); 2332 sprintf(tmp, "%s/%s", 2333 call_program_and_get_last_line_of_output("pwd"), 2334 MONDO_CFG_FILE_STUB); 2335 sprintf(command, "cp -f %s %s", tmp, cfg_file); 2200 mr_asprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB); 2201 mr_asprintf(command, "cp -f %s %s", tmp, cfg_file); 2336 2202 log_it("%s",command); 2337 2203 if (strcmp(tmp, cfg_file) … … 2343 2209 log_msg(1, "... and I moved it successfully to %s", cfg_file); 2344 2210 } 2345 sprintf(command, "cp -f %s/%s %s",2346 call_program_and_get_last_line_of_output("pwd"), 2347 2211 mr_free(command); 2212 2213 mr_asprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file); 2348 2214 log_it("%s",command); 2349 2215 if (extract_mountlist_stub) { … … 2353 2219 } else { 2354 2220 log_msg(1, "Got mountlist too"); 2355 sprintf(command, "cp -f %s %s", mountlist_file,2356 2221 mr_free(command); 2222 mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname); 2357 2223 if (run_program_and_log_output(command, 1)) { 2358 2224 log_msg(1, "Failed to copy mountlist to /tmp"); 2359 2225 } else { 2360 2226 log_msg(1, "Copied mountlist to /tmp as well OK"); 2361 sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB); 2227 mr_free(command); 2228 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB); 2362 2229 run_program_and_log_output(command, 1); 2363 2230 } 2364 2231 } 2365 2232 } 2366 } 2233 mr_free(command); 2234 mr_free(tmp); 2235 } 2236 2367 2237 run_program_and_log_output("umount -d " MNT_CDROM, FALSE); 2368 2238 if (!does_file_exist(cfg_file)) { … … 2381 2251 /* Is this code really useful ??? */ 2382 2252 if (extract_mountlist_stub) { 2383 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, 2384 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2253 mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2385 2254 run_program_and_log_output(command, FALSE); 2386 } 2387 } 2388 2389 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2255 mr_free(command); 2256 } 2257 } 2258 2259 mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2260 mr_free(cfg_file); 2261 2390 2262 run_program_and_log_output(command, FALSE); 2263 mr_free(command); 2264 2391 2265 if (extract_mountlist_stub) { 2392 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);2266 mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2393 2267 run_program_and_log_output(command, FALSE); 2394 } 2395 sprintf(command, "cp -f etc/raidtab /etc/"); 2268 mr_free(command); 2269 } 2270 mr_free(mountlist_file); 2271 2272 mr_asprintf(command, "cp -f etc/raidtab /etc/"); 2396 2273 run_program_and_log_output(command, FALSE); 2274 mr_free(command); 2275 2397 2276 if (extract_i_want_my_lvm) { 2398 sprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);2277 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB); 2399 2278 run_program_and_log_output(command, FALSE); 2279 mr_free(command); 2400 2280 } 2401 2281 g_backup_media_type = bkpinfo->backup_media_type; 2402 paranoid_free(device);2403 paranoid_free(command);2404 paranoid_free(tmp);2405 paranoid_free(cfg_file);2406 paranoid_free(mounted_cfgf_path);2407 paranoid_free(mountpt);2408 paranoid_free(ramdisk_fname);2409 paranoid_free(mountlist_file);2410 2282 return (retval); 2411 2283 } … … 2416 2288 2417 2289 /* @} - end restoreUtilityGroup */ 2418 2419 2420 /***************************************************************************2421 * F@ *2422 * () -- Hugo Rabson *2423 * *2424 * Purpose: *2425 * *2426 * Called by: *2427 * Params: - - *2428 * Returns: 0=success; nonzero=failure *2429 ***************************************************************************/2430 2431 2432 2290 2433 2291 void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage) … … 2436 2294 int unfinished_mdstat_devices = 9999; 2437 2295 int i = 0; 2438 char *screen_message; 2439 2440 malloc_string(screen_message); 2296 char *screen_message = NULL; 2297 2441 2298 raidlist = malloc(sizeof(struct raidlist_itself)); 2442 2299 … … 2458 2315 } 2459 2316 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i); 2460 sprintf(screen_message, "Sync'ing %s", 2461 raidlist->el[i].raid_device); 2317 mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device); 2462 2318 open_evalcall_form(screen_message); 2319 mr_free(screen_message); 2320 2463 2321 while (raidlist->el[i].progress < wait_for_percentage) { 2464 2322 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress); … … 2474 2332 } 2475 2333 } 2476 paranoid_free(screen_message);2477 2334 paranoid_free(raidlist); 2478 2335 } 2479 2480 -
branches/3.2/mondo/src/mondorestore/mondorestore.c
r3185 r3193 253 253 struct raidlist_itself *raidlist) 254 254 { 255 char c, *tmp; 255 char c; 256 char *tmp = NULL; 256 257 int retval = 0; 257 258 … … 260 261 assert(mountlist != NULL); 261 262 assert(raidlist != NULL); 262 malloc_string(tmp);263 263 log_it("pre wrm"); 264 264 c = which_restore_mode(); … … 274 274 } 275 275 if (g_ISO_restore_mode) { 276 sprintf(tmp, "umount -d %s", bkpinfo->isodir);276 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir); 277 277 run_program_and_log_output(tmp, FALSE); 278 mr_free(tmp); 278 279 } 279 280 paranoid_MR_finish(0); … … 284 285 if (bkpinfo->backup_media_type == iso) { 285 286 if (iso_fiddly_bits((c == 'N') ? TRUE : FALSE)) { 286 log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); 287 log_msg(2, 288 "catchall_mode --- iso_fiddly_bits returned w/ error"); 287 289 return (1); 288 290 } else { … … 301 303 retval += compare_mode(mountlist, raidlist); 302 304 } 303 paranoid_free(tmp);304 305 return (retval); 305 306 } … … 418 419 * @return 0 for success, or the number of errors encountered. 419 420 */ 420 int 421 interactive_mode(struct mountlist_itself *mountlist, 422 struct raidlist_itself *raidlist) 421 int interactive_mode(struct mountlist_itself *mountlist, struct raidlist_itself *raidlist) 423 422 { 424 423 int retval = 0; … … 432 431 /** needs malloc **********/ 433 432 char *tmp; 434 char *fstab_fname; 435 char *old_restpath; 433 char *p = NULL; 434 char *tmp1 = NULL; 435 char *fstab_fname = NULL; 436 char *old_restpath = NULL; 436 437 437 438 struct s_node *filelist; … … 442 443 443 444 malloc_string(tmp); 444 malloc_string(fstab_fname);445 malloc_string(old_restpath);446 445 assert(bkpinfo != NULL); 447 446 assert(mountlist != NULL); … … 451 450 452 451 if (g_text_mode) { 453 if (!ask_me_yes_or_no 454 ("Interactive Mode + textonly = experimental! Proceed anyway?")) 455 { 452 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) { 456 453 fatal_error("Wise move."); 457 454 } … … 463 460 log_it("Done loading config file; resizing ML"); 464 461 465 #ifdef __FreeBSD__ 466 if (strstr 467 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 468 "noresize")) 469 #else 470 if (strstr 471 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 472 "noresize")) 473 #endif 474 { 462 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE); 463 if (strstr(tmp1, "noresize")) { 475 464 log_msg(1, "Not resizing mountlist."); 476 465 } else { 477 466 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 478 467 } 468 mr_free(tmp1); 469 479 470 for (done = FALSE; !done;) { 480 471 log_it("About to edit mountlist"); 481 472 if (g_text_mode) { 482 473 save_mountlist_to_disk(mountlist, g_mountlist_fname); 483 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 484 res = system(tmp); 474 mr_asprintf(tmp1, "%s %s", find_my_editor(), g_mountlist_fname); 475 res = system(tmp1); 476 mr_free(tmp1); 485 477 load_mountlist(mountlist, g_mountlist_fname); 486 478 } else { … … 571 563 } 572 564 /* restore */ 573 if ((restore_all = 574 ask_me_yes_or_no("Do you want me to restore all of your data?"))) 575 { 565 if ((restore_all = ask_me_yes_or_no("Do you want me to restore all of your data?"))) { 576 566 log_msg(1, "Restoring all data"); 577 567 retval += restore_everything(NULL); 578 } else 579 if ((restore_all = 580 ask_me_yes_or_no 581 ("Do you want me to restore _some_ of your data?"))) { 582 strcpy(old_restpath, bkpinfo->restore_path); 568 } else if ((restore_all = ask_me_yes_or_no("Do you want me to restore _some_ of your data?"))) { 569 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path); 583 570 for (done = FALSE; !done;) { 584 571 unlink("/tmp/filelist.full"); … … 590 577 gotos_suck: 591 578 strcpy(tmp, old_restpath); 592 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);579 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING); 593 580 if (popup_and_get_string 594 581 ("Restore path", "Restore files to where?", tmp, … … 608 595 free_filelist(filelist); 609 596 } 610 if (!ask_me_yes_or_no 611 ("Restore another subset of your backup?")) { 597 if (!ask_me_yes_or_no("Restore another subset of your backup?")) { 612 598 done = TRUE; 613 599 } … … 616 602 } 617 603 } 618 strcpy(old_restpath, bkpinfo->restore_path); 619 } else { 620 mvaddstr_and_log_it(g_currentY++, 621 0, 622 "User opted not to restore any data. "); 604 mr_free(old_restpath); 605 } else { 606 mvaddstr_and_log_it(g_currentY++, 0, "User opted not to restore any data. "); 623 607 } 624 608 if (retval) { 625 mvaddstr_and_log_it(g_currentY++, 626 0, 627 "Errors occurred during the restore phase. "); 609 mvaddstr_and_log_it(g_currentY++, 0, "Errors occurred during the restore phase. "); 628 610 } 629 611 … … 647 629 "Using tune2fs/tune4fs to identify your ext2,3,4 partitions"); 648 630 if (does_file_exist("/tmp/fstab.new")) { 649 strcpy(fstab_fname, "/tmp/fstab.new");631 mr_asprintf(fstab_fname, "/tmp/fstab.new"); 650 632 } else { 651 strcpy(fstab_fname, "/tmp/fstab");652 } 653 sprintf(tmp,654 "label-partitions-as-necessary %s < %s >> %s 2>> %s",655 g_mountlist_fname, fstab_fname, MONDO_LOGFILE, 656 MONDO_LOGFILE);657 res = system(tmp);633 mr_asprintf(fstab_fname, "/tmp/fstab"); 634 } 635 mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE); 636 mr_free(fstab_fname); 637 638 res = system(tmp1); 639 mr_free(tmp1); 658 640 if (res) { 659 641 log_to_screen … … 674 656 end_of_func: 675 657 paranoid_free(tmp); 676 paranoid_free(fstab_fname);677 paranoid_free(old_restpath);678 658 log_it("Leaving interactive_mode()"); 679 659 return (retval); … … 759 739 int retval = 0; 760 740 int res = 0; 761 /** malloc **/ 762 char tmp[MAX_STR_LEN];741 char *tmp = NULL; 742 char *tmp1 = NULL; 763 743 char *flaws_str = NULL; 764 744 … … 772 752 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 773 753 #ifdef __FreeBSD__ 774 if (strstr 775 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 776 "noresize")) 754 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 777 755 #else 778 if (strstr 779 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 780 "noresize")) 756 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 781 757 #endif 782 758 { … … 812 788 twenty_seconds_til_yikes(); 813 789 g_fprep = fopen("/tmp/prep.sh", "w"); 814 #ifdef __FreeBSD__ 815 if (strstr 816 (call_program_and_get_last_line_of_output 817 ("cat /tmp/cmdline"), "nopart")) 818 #else 819 if (strstr 820 (call_program_and_get_last_line_of_output 821 ("cat /proc/cmdline"), "nopart")) 822 #endif 823 { 824 log_msg(2, 825 "Not partitioning drives due to 'nopart' option."); 790 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE)); 791 if (strstr(tmp1, "nopart")) { 792 log_msg(2, "Not partitioning drives due to 'nopart' option."); 826 793 res = 0; 827 794 } else { 828 795 res = partition_everything(mountlist); 829 796 if (res) { 830 log_to_screen 831 ("Warning. Errors occurred during partitioning."); 797 log_to_screen("Warning. Errors occurred during partitioning."); 832 798 res = 0; 833 799 } 834 800 } 801 mr_free(tmp1); 802 835 803 retval += res; 836 804 if (!res) { 837 805 log_to_screen("Preparing to format your disk(s)"); 838 806 sleep(1); 839 paranoid_system("sync");807 sync(); 840 808 log_to_screen("Please wait. This may take a few minutes."); 841 809 res += format_everything(mountlist, FALSE, raidlist); … … 880 848 "Using tune2fs/tune4fs to identify your ext2,3,4 partitions"); 881 849 882 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", g_mountlist_fname, MONDO_LOGFILE, MONDO_LOGFILE);850 mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE); 883 851 res = run_program_and_log_output(tmp, TRUE); 852 mr_free(tmp1); 884 853 if (res) { 885 854 log_to_screen("label-partitions-as-necessary returned an error"); … … 891 860 892 861 after_the_nuke: 862 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE)); 893 863 if (retval) { 894 864 log_to_screen("Errors occurred during the nuke phase."); 895 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) { 896 log_to_screen 897 ("PC was restored successfully. Thank you for using Mondo Rescue."); 898 log_to_screen 899 ("Please visit our website at http://www.mondorescue.org for more information."); 900 } else { 901 strcpy(tmp,"Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information."); 902 popup_and_OK(tmp); 903 log_to_screen 904 ("Mondo has restored your system. Please wait for the command prompt."); 905 log_to_screen 906 ("Then remove the backup media and reboot."); 907 log_to_screen 908 ("Please visit our website at http://www.mondorescue.org for more information."); 909 } 865 } else if (strstr(tmp1, "RESTORE")) { 866 log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue."); 867 log_to_screen("Please visit our website at http://www.mondorescue.org for more information."); 868 } else { 869 mr_asprintf(tmp,"%s","Mondo has restored your system.\n\nPlease wait for the command prompt. Then remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information."); 870 popup_and_OK(tmp); 871 mr_free(tmp); 872 log_to_screen("Mondo has restored your system. Please wait for the command prompt."); 873 log_to_screen("Then remove the backup media and reboot."); 874 log_to_screen("Please visit our website at http://www.mondorescue.org for more information."); 875 } 876 mr_free(tmp1); 877 910 878 g_I_have_just_nuked = TRUE; 911 879 return (retval); … … 928 896 int retval = 0; 929 897 930 /** malloc **/ 931 char *old_restpath; 898 char *old_restpath = NULL; 932 899 933 900 struct mountlist_itself *mountlist = NULL; 934 // static935 901 struct raidlist_itself *raidlist = NULL; 936 902 struct s_node *filelist = NULL; … … 938 904 log_msg(1, "restore_to_live_filesystem() - starting"); 939 905 assert(bkpinfo != NULL); 940 malloc_string(old_restpath);941 906 mountlist = malloc(sizeof(struct mountlist_itself)); 942 907 raidlist = malloc(sizeof(struct raidlist_itself)); … … 974 939 if (!g_restoring_live_from_netfs && (filelist = process_filelist_and_biggielist())) { 975 940 save_filelist(filelist, "/tmp/selected-files.txt"); 976 strcpy(old_restpath, bkpinfo->restore_path);941 mr_asprintf(old_restpath, "%s", bkpinfo->restore_path); 977 942 if (popup_and_get_string("Restore path", 978 943 "Restore files to where? )", … … 986 951 } 987 952 strcpy(bkpinfo->restore_path, old_restpath); 953 mr_free(old_restpath); 988 954 } else { 989 955 if (filelist != NULL) { … … 1004 970 eject_device(bkpinfo->media_device); 1005 971 } 1006 paranoid_free(old_restpath);1007 972 free(mountlist); 1008 973 free(raidlist); … … 1043 1008 1044 1009 /** malloc ***/ 1045 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1046 *ntfsprog_command, *suffix, *sz_devfile; 1010 char *checksum = NULL; 1011 char *outfile_fname = NULL; 1012 char *tmp = NULL; 1013 char *bzip2_command = NULL; 1014 char *suffix = NULL; 1015 char *sz_devfile = NULL; 1047 1016 char *bigblk; 1048 1017 char *mds = NULL; … … 1051 1020 long sliceno; 1052 1021 long siz; 1053 char ntfsprog_fifo[MAX_STR_LEN];1022 char *ntfsprog_fifo = NULL; 1054 1023 char *file_to_openout = NULL; 1055 1024 struct s_filename_and_lstat_info biggiestruct; … … 1059 1028 int res = 0; 1060 1029 int old_loglevel; 1061 char sz_msg[MAX_STR_LEN];1062 1030 struct s_node *node; 1063 1031 … … 1065 1033 ubuf = &the_utime_buf; 1066 1034 assert(bkpinfo != NULL); 1067 1068 malloc_string(checksum);1069 malloc_string(outfile_fname);1070 malloc_string(tmp);1071 malloc_string(bzip2_command);1072 malloc_string(ntfsprog_command);1073 malloc_string(suffix);1074 malloc_string(sz_devfile);1075 1035 1076 1036 pathname_of_last_file_restored[0] = '\0'; … … 1092 1052 paranoid_fclose(fin); 1093 1053 1094 strcpy(checksum, biggiestruct.checksum); 1095 1054 mr_asprintf(checksum, "%s", biggiestruct.checksum); 1096 1055 if (!checksum[0]) { 1097 sprintf(tmp, "Warning - bigfile %ld does not have a checksum", 1098 bigfileno + 1); 1099 log_msg(3, tmp); 1100 } 1056 log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1); 1057 } 1058 mr_free(checksum); 1101 1059 1102 1060 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :) 1103 1061 { 1104 strcpy(outfile_fname, biggiestruct.filename); 1105 } else { 1106 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1107 biggiestruct.filename); 1062 mr_asprintf(outfile_fname, "%s", biggiestruct.filename); 1063 } else { 1064 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename); 1108 1065 } 1109 1066 … … 1112 1069 node = find_string_at_node(filelist, biggiestruct.filename); 1113 1070 if (!node) { 1114 log_msg(0, "Skipping %s (name isn't in filelist)", 1115 biggiestruct.filename); 1071 log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename); 1116 1072 pathname_of_last_file_restored[0] = '\0'; 1117 1073 return (0); 1118 1074 } else if (!(node->selected)) { 1119 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1120 biggiestruct.filename); 1075 log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename); 1121 1076 pathname_of_last_file_restored[0] = '\0'; 1122 1077 return (0); 1123 1078 } 1124 1079 } 1080 1125 1081 /* otherwise, continue */ 1126 1127 1082 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1128 1083 if (biggiestruct.use_ntfsprog) { 1129 1084 if (strncmp(biggiestruct.filename, "/dev/", 5)) { 1130 log_msg(1, 1131 "I was in error when I set biggiestruct.use_ntfsprog to TRUE."); 1085 log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE."); 1132 1086 log_msg(1, "%s isn't even in /dev", biggiestruct.filename); 1133 1087 biggiestruct.use_ntfsprog = FALSE; … … 1136 1090 1137 1091 if (biggiestruct.use_ntfsprog) // if it's an NTFS device 1138 // if (!strncmp ( biggiestruct.filename, "/dev/", 5))1139 1092 { 1140 1093 g_loglevel = 4; 1141 1094 use_ntfsprog_hack = TRUE; 1142 log_msg(2, 1143 "Calling ntfsclone in background because %s is an NTFS /dev entry", 1144 outfile_fname); 1145 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1146 (int) (random() % 32768)); 1095 log_msg(2, "Calling ntfsclone in background because %s is an NTFS /dev entry", outfile_fname); 1096 mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768)); 1147 1097 mkfifo(sz_devfile, 0x770); 1148 strcpy(ntfsprog_fifo, sz_devfile); 1098 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile); 1099 mr_free(sz_devfile); 1149 1100 file_to_openout = ntfsprog_fifo; 1150 1101 switch (pid = fork()) { … … 1152 1103 fatal_error("Fork failure"); 1153 1104 case 0: 1154 log_msg(3, 1155 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", 1156 biggiestruct.filename, ntfsprog_fifo); 1157 res = 1158 feed_outfrom_ntfsprog(biggiestruct.filename, 1159 ntfsprog_fifo); 1160 // log_msg(3, "CHILD - fip - exiting"); 1105 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo); 1106 res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo); 1107 mr_free(ntfsprog_fifo); 1161 1108 exit(res); 1162 1109 break; 1163 1110 default: 1164 log_msg(3, 1165 "feed_into_ntfsprog() called in background --- pid=%ld", 1166 (long int) (pid)); 1167 } 1111 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid)); 1112 } 1113 mr_free(ntfsprog_fifo); 1168 1114 } else { 1169 1115 use_ntfsprog_hack = FALSE; 1170 ntfsprog_fifo[0] = '\0';1171 1116 file_to_openout = outfile_fname; 1172 1117 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1176 1121 } 1177 1122 1178 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1, 1179 outfile_fname); 1180 log_msg(2, tmp); 1123 log_msg(2, "Reassembling big file %ld (%s)", bigfileno + 1, outfile_fname); 1181 1124 1182 1125 /* … … 1186 1129 */ 1187 1130 1188 strncpy(pathname_of_last_file_restored, biggiestruct.filename, 1189 MAX_STR_LEN - 1); 1131 strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1); 1190 1132 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1191 1133 … … 1198 1140 1199 1141 for (sliceno = 1, finished = FALSE; !finished;) { 1200 if (!does_file_exist 1201 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) 1202 && 1203 !does_file_exist(slice_fname 1204 (bigfileno, sliceno, ARCHIVES_PATH, "lzo")) 1205 && 1206 !does_file_exist(slice_fname 1207 (bigfileno, sliceno, ARCHIVES_PATH, "gz")) 1208 && 1209 !does_file_exist(slice_fname 1210 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1211 log_msg(3, 1212 "Cannot find a data slice or terminator slice on CD %d", 1213 g_current_media_number); 1142 if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) && 1143 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) && 1144 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) && 1145 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma")) && 1146 !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1147 log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number); 1214 1148 g_current_media_number++; 1215 1149 mds = media_descriptor_string(bkpinfo->backup_media_type); 1216 sprintf(tmp, 1217 "Asking for %s #%d so that I may read slice #%ld\n", mds, 1218 g_current_media_number, sliceno); 1219 log_msg(2, tmp); 1220 sprintf(tmp, "Restoring from %s #%d", mds, g_current_media_number); 1150 log_msg(2, "Asking for %s #%d so that I may read slice #%ld\n", mds, g_current_media_number, sliceno); 1221 1151 mr_free(mds); 1222 1152 1223 log_to_screen(tmp); 1153 log_to_screen("Restoring from %s #%d", mds, g_current_media_number); 1154 1224 1155 insist_on_this_cd_number(g_current_media_number); 1225 1156 log_to_screen("Continuing to restore."); 1226 1157 } else { 1227 strcpy(tmp, 1228 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")); 1158 mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")); 1229 1159 if (does_file_exist(tmp) && length_of_file(tmp) == 0) { 1230 log_msg(2, 1231 "End of bigfile # %ld (slice %ld is the terminator)", 1232 bigfileno + 1, sliceno); 1160 log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno); 1233 1161 finished = TRUE; 1162 mr_free(tmp); 1234 1163 continue; 1235 1164 } else { 1236 if (does_file_exist 1237 (slice_fname 1238 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1239 strcpy(bzip2_command, "lzop"); 1240 strcpy(suffix, "lzo"); 1165 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1166 mr_asprintf(bzip2_command, "lzop"); 1167 mr_asprintf(suffix, "lzo"); 1241 1168 } else 1242 if (does_file_exist 1243 (slice_fname 1244 (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) { 1245 strcpy(bzip2_command, "gzip"); 1246 strcpy(suffix, "gz"); 1169 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) { 1170 mr_asprintf(bzip2_command, "gzip"); 1171 mr_asprintf(suffix, "gz"); 1247 1172 } else 1248 if (does_file_exist 1249 (slice_fname 1250 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1251 strcpy(bzip2_command, "bzip2"); 1252 strcpy(suffix, "bz2"); 1173 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzma"))) { 1174 mr_asprintf(bzip2_command, "lzma"); 1175 mr_asprintf(suffix, "lzma"); 1253 1176 } else 1254 if (does_file_exist 1255 (slice_fname 1256 (bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1257 strcpy(bzip2_command, ""); 1258 strcpy(suffix, ""); 1177 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1178 mr_asprintf(bzip2_command, "bzip2"); 1179 mr_asprintf(suffix, "bz2"); 1180 } else 1181 if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1182 mr_asprintf(bzip2_command, ""); 1183 mr_asprintf(suffix, ""); 1259 1184 } else { 1260 1185 log_to_screen("OK, that's pretty fsck0red..."); 1186 mr_free(tmp); 1261 1187 return (1); 1262 1188 } 1263 1189 } 1264 if (bzip2_command[0] != '\0') { 1265 sprintf(bzip2_command + strlen(bzip2_command), 1266 " -dc %s 2>> %s", 1267 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1268 suffix), MONDO_LOGFILE); 1190 mr_free(tmp); 1191 if (bzip2_command != NULL) { 1192 mr_strcat(bzip2_command, " -dc %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE); 1269 1193 } else { 1270 sprintf(bzip2_command, "cat %s 2>> %s",1271 slice_fname(bigfileno, sliceno, ARCHIVES_PATH,1272 suffix), MONDO_LOGFILE);1273 } 1194 mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE); 1195 } 1196 mr_free(suffix); 1197 1274 1198 mds = media_descriptor_string(bkpinfo->backup_media_type); 1275 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", mds, 1276 g_current_media_number, bigfileno + 1, sliceno); 1199 mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", mds, g_current_media_number, bigfileno + 1, sliceno); 1277 1200 mr_free(mds); 1278 1201 log_msg(2, tmp); … … 1284 1207 update_progress_form(tmp); 1285 1208 } 1209 mr_free(tmp); 1210 1286 1211 if (!(fbzip2 = popen(bzip2_command, "r"))) { 1287 1212 fatal_error("Can't run popen command"); 1288 1213 } 1214 mr_free(bzip2_command); 1215 1289 1216 while (!feof(fbzip2)) { 1290 1217 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2); 1291 1218 if (siz > 0) { 1292 sprintf(sz_msg, "Read %ld from fbzip2", siz);1293 1219 siz = fwrite(bigblk, 1, siz, fout); 1294 sprintf(sz_msg + strlen(sz_msg),1295 "; written %ld to fout", siz);1296 // log_msg(2. sz_msg);1297 1220 } 1298 1221 } … … 1304 1227 } 1305 1228 } 1306 /*1307 memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...1308 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);1309 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);1310 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);1311 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);1312 */1313 1229 paranoid_fclose(fout); 1314 1230 g_loglevel = old_loglevel; … … 1316 1232 if (use_ntfsprog_hack) { 1317 1233 log_msg(3, "Waiting for ntfsclone to finish"); 1318 sprintf(tmp, 1319 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1234 mr_asprintf(tmp, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1320 1235 while (system(tmp) == 0) { 1321 1236 sleep(1); 1322 1237 } 1238 mr_free(tmp); 1323 1239 log_it("OK, ntfsclone has really finished"); 1324 1240 } 1325 1241 1326 1242 if (strcmp(outfile_fname, "/dev/null")) { 1327 if (chown(outfile_fname, biggiestruct.properties.st_uid, 1328 biggiestruct.properties.st_gid)) { 1243 if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) { 1329 1244 // FIXME 1330 1245 } … … 1334 1249 utime(outfile_fname, ubuf); 1335 1250 } 1251 mr_free(outfile_fname); 1336 1252 paranoid_free(bigblk); 1337 paranoid_free(checksum);1338 paranoid_free(outfile_fname);1339 paranoid_free(tmp);1340 paranoid_free(bzip2_command);1341 paranoid_free(ntfsprog_command);1342 paranoid_free(suffix);1343 paranoid_free(sz_devfile);1344 1253 1345 1254 return (retval); … … 1376 1285 1377 1286 /** mallocs ********/ 1378 char *tmp ;1379 char * command;1380 char * outfile_fname;1381 char * ntfsprog_command;1382 char *sz_devfile ;1383 char *ntfsprog_fifo ;1287 char *tmp = NULL; 1288 char *tmp1 = NULL; 1289 char *command = NULL; 1290 char *outfile_fname = NULL; 1291 char *sz_devfile = NULL; 1292 char *ntfsprog_fifo = NULL; 1384 1293 char *file_to_openout = NULL; 1385 1294 … … 1400 1309 1401 1310 malloc_string(tmp); 1402 malloc_string(ntfsprog_fifo);1403 malloc_string(outfile_fname);1404 malloc_string(command);1405 malloc_string(sz_devfile);1406 malloc_string(ntfsprog_command);1407 1311 old_loglevel = g_loglevel; 1408 1312 assert(bkpinfo != NULL); … … 1455 1359 if (use_ntfsprog) { 1456 1360 g_loglevel = 4; 1457 strcpy(outfile_fname, orig_bf_fname);1361 mr_asprintf(outfile_fname, "%s", orig_bf_fname); 1458 1362 use_ntfsprog_hack = TRUE; 1459 log_msg(2, 1460 "Calling ntfsclone in background because %s is a /dev entry", 1461 outfile_fname); 1462 sprintf(sz_devfile, "%s/%d.%d.000", 1463 bkpinfo->tmpdir, 1464 (int) (random() % 32768), 1465 (int) (random() % 32768)); 1363 log_msg(2, "Calling ntfsclone in background because %s is a /dev entry", outfile_fname); 1364 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768)); 1466 1365 mkfifo(sz_devfile, 0x770); 1467 strcpy(ntfsprog_fifo, sz_devfile); 1366 mr_asprintf(ntfsprog_fifo, "%s", sz_devfile); 1367 mr_free(sz_devfile); 1368 1468 1369 file_to_openout = ntfsprog_fifo; 1469 1370 switch (pid = fork()) { … … 1471 1372 fatal_error("Fork failure"); 1472 1373 case 0: 1473 log_msg(3, 1474 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", 1475 outfile_fname, ntfsprog_fifo); 1476 res = 1477 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo); 1478 // log_msg(3, "CHILD - fip - exiting"); 1374 log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo); 1375 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo); 1376 mr_free(ntfsprog_fifo); 1479 1377 exit(res); 1480 1378 break; 1481 1379 default: 1482 log_msg(3, 1483 "feed_into_ntfsprog() called in background --- pid=%ld", 1484 (long int) (pid)); 1485 } 1486 } else { 1487 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1488 { 1489 strcpy(outfile_fname, orig_bf_fname); 1490 } else // biggiefile 1491 { 1492 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1493 orig_bf_fname); 1380 log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid)); 1381 } 1382 mr_free(ntfsprog_fifo); 1383 } else { 1384 if (!strncmp(orig_bf_fname, "/dev/", 5)) { 1385 // non-NTFS partition 1386 mr_asprintf(outfile_fname, "%s", orig_bf_fname); 1387 } else { 1388 // biggiefile 1389 mr_asprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname); 1494 1390 } 1495 1391 use_ntfsprog_hack = FALSE; 1496 ntfsprog_fifo[0] = '\0';1497 1392 file_to_openout = outfile_fname; 1498 1393 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1500 1395 make_hole_for_file(outfile_fname); 1501 1396 } 1502 sprintf(tmp, "Reassembling big file %ld (%s)", 1503 biggiefile_number + 1, orig_bf_fname); 1504 log_msg(2, tmp); 1397 log_msg(2, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname); 1505 1398 } 1506 1399 1507 1400 if (dummy_restore) { 1508 sprintf(outfile_fname, "/dev/null"); 1401 mr_free(outfile_fname); 1402 mr_asprintf(outfile_fname, "/dev/null"); 1509 1403 } 1510 1404 1511 1405 if (!bkpinfo->zip_exe[0]) { 1512 sprintf(command, "cat > \"%s\"", file_to_openout); 1513 } else { 1514 sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, 1515 file_to_openout, MONDO_LOGFILE); 1406 mr_asprintf(command, "cat > \"%s\"", file_to_openout); 1407 } else { 1408 mr_asprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE); 1516 1409 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) { 1517 1410 /* Ignore SIGPIPE for gzip as it causes errors on big files 1518 * Cf: http://trac.mondorescue.org/ticket/244 1519 */ 1411 * Cf: http://trac.mondorescue.org/ticket/244 */ 1520 1412 signal(SIGPIPE,SIG_IGN); 1521 1413 } 1522 1414 } 1523 sprintf(tmp, "Pipe command = '%s'", command); 1524 log_msg(3, tmp); 1415 log_msg(3, "Pipe command = '%s'", command); 1525 1416 1526 1417 /* restore biggiefile, one slice at a time */ … … 1528 1419 fatal_error("Cannot pipe out"); 1529 1420 } 1421 mr_free(command); 1422 1530 1423 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1531 1424 ctrl_chr != BLK_STOP_A_BIGGIE; … … 1534 1427 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1535 1428 } 1536 sprintf(tmp, "Working on file #%ld, slice #%ld ", 1537 biggiefile_number + 1, current_slice_number); 1538 log_msg(2, tmp); 1429 log_msg(2, "Working on file #%ld, slice #%ld ", biggiefile_number + 1, current_slice_number); 1539 1430 if (!g_text_mode) { 1540 1431 newtDrawRootText(0, g_noof_rows - 2, tmp); … … 1575 1466 if (bkpinfo->zip_exe[0]) { 1576 1467 if (strcmp(bkpinfo->zip_exe, "gzip") == 0) { 1577 /* Re-enable SIGPIPE for gzip 1578 */ 1468 /* Re-enable SIGPIPE for gzip */ 1579 1469 signal(SIGPIPE, terminate_daemon); 1580 1470 } … … 1586 1476 if (use_ntfsprog_hack) { 1587 1477 log_msg(3, "Waiting for ntfsclone to finish"); 1588 sprintf(tmp, 1589 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1590 while (system(tmp) == 0) { 1478 mr_asprintf(tmp1, " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1479 while (system(tmp1) == 0) { 1591 1480 sleep(1); 1592 1481 } 1482 mr_free(tmp1); 1593 1483 log_msg(3, "OK, ntfsclone has really finished"); 1594 1484 } … … 1598 1488 if (strcmp(outfile_fname, "/dev/null")) { 1599 1489 chmod(outfile_fname, biggiestruct.properties.st_mode); 1600 if (chown(outfile_fname, biggiestruct.properties.st_uid, 1601 biggiestruct.properties.st_gid)) { 1490 if (chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid)) { 1602 1491 // FIXME 1603 1492 } … … 1606 1495 utime(outfile_fname, ubuf); 1607 1496 } 1497 mr_free(outfile_fname); 1608 1498 1609 1499 paranoid_free(tmp); 1610 paranoid_free(outfile_fname);1611 paranoid_free(command);1612 paranoid_free(ntfsprog_command);1613 paranoid_free(sz_devfile);1614 paranoid_free(ntfsprog_fifo);1615 1500 g_loglevel = old_loglevel; 1616 1501 return (retval); … … 1645 1530 /** malloc **/ 1646 1531 char *command = NULL; 1647 char *tmp; 1648 char *filelist_name; 1649 char *filelist_subset_fname; 1650 char *executable; 1651 char *temp_log; 1652 char screen_message[100]; 1532 char *tmp = NULL; 1533 char *filelist_name = NULL; 1534 char *filelist_subset_fname = NULL; 1535 char *executable = NULL; 1536 char *temp_log = NULL; 1653 1537 long matches = 0; 1654 1538 bool use_star; 1655 char *xattr_fname; 1656 char *acl_fname; 1657 // char files_to_restore_this_time_fname[MAX_STR_LEN]; 1539 char *xattr_fname = NULL; 1540 char *acl_fname = NULL; 1658 1541 1659 1542 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1660 malloc_string(tmp);1661 malloc_string(filelist_name);1662 malloc_string(filelist_subset_fname);1663 malloc_string(executable);1664 malloc_string(temp_log);1665 malloc_string(xattr_fname);1666 malloc_string(acl_fname);1667 1543 1668 1544 log_msg(5, "Entering"); 1669 filelist_subset_fname[0] = '\0';1670 1545 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1671 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());1672 1546 mr_asprintf(command, "mkdir -p %s/tmp", MNT_RESTORING); 1673 1547 run_program_and_log_output(command, 9); 1674 1548 paranoid_free(command); 1675 1549 1676 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1677 (int) (random() % 32768)); 1678 1679 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", 1680 current_tarball_number); 1550 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", current_tarball_number); 1681 1551 if (length_of_file(filelist_name) <= 2) { 1682 log_msg(2, "There are _zero_ files in filelist '%s'", 1683 filelist_name); 1684 log_msg(2, 1685 "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)"); 1686 log_msg(2, 1687 "but it's non-critical. It's cosmetic. Don't worry about it."); 1552 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name); 1553 log_msg(2, "This is a bit silly (ask dev-team to fix mondo_makefilelist, please)"); 1554 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it."); 1688 1555 retval = 0; 1689 goto leave_sub; 1690 } 1691 if (count_lines_in_file(filelist_name) <= 0 1692 || length_of_file(tarball_fname) <= 0) { 1556 mr_free(filelist_name); 1557 log_msg(5, "Leaving"); 1558 return(0); 1559 } 1560 if (count_lines_in_file(filelist_name) <= 0 || length_of_file(tarball_fname) <= 0) { 1693 1561 log_msg(3, "length_of_file(%s) = %llu", tarball_fname, length_of_file(tarball_fname)); 1694 1562 log_msg(3, "count_lines_in_file(%s) = %llu", tarball_fname, count_lines_in_file(tarball_fname)); 1695 sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)", 1696 current_tarball_number); 1697 log_to_screen(tmp); 1698 retval = 1; 1699 goto leave_sub; 1563 log_to_screen("Unable to restore fileset #%ld (CD I/O error)", current_tarball_number); 1564 mr_free(filelist_name); 1565 log_msg(5, "Leaving"); 1566 return(1); 1700 1567 } 1701 1568 1702 1569 if (filelist) { 1703 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", 1704 current_tarball_number); 1570 mr_asprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number); 1705 1571 if ((matches = 1706 1572 save_filelist_entries_in_common(filelist_name, filelist, 1707 1573 filelist_subset_fname, 1708 use_star)) 1709 <= 0) { 1710 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 1711 log_msg(1, tmp); 1574 use_star)) <= 0) { 1575 log_msg(1, "Skipping fileset %ld", current_tarball_number); 1712 1576 } else { 1713 log_msg(3, "Saved fileset %ld's subset to %s", 1714 current_tarball_number, filelist_subset_fname); 1715 } 1716 sprintf(screen_message, "Tarball #%ld --- %ld matches", 1717 current_tarball_number, matches); 1718 log_to_screen(screen_message); 1719 } else { 1720 filelist_subset_fname[0] = '\0'; 1721 } 1577 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname); 1578 } 1579 log_to_screen("Tarball #%ld --- %ld matches", current_tarball_number, matches); 1580 } 1581 mr_free(filelist_name); 1722 1582 1723 1583 if (filelist == NULL || matches > 0) { 1724 1584 if (g_getfattr) { 1725 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, 1726 MNT_CDROM "/archives", current_tarball_number); 1585 mr_asprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number); 1727 1586 } 1728 1587 if (g_getfacl) { 1729 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", 1730 current_tarball_number); 1588 mr_asprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", current_tarball_number); 1731 1589 } 1732 1590 if (strstr(tarball_fname, ".bz2")) { 1733 strcpy(executable, "bzip2"); 1591 mr_asprintf(executable, "bzip2"); 1592 } else if (strstr(tarball_fname, ".lzma")) { 1593 mr_asprintf(executable, "lzma"); 1734 1594 } else if (strstr(tarball_fname, ".gz")) { 1735 strcpy(executable, "gzip");1595 mr_asprintf(executable, "gzip"); 1736 1596 } else if (strstr(tarball_fname, ".lzo")) { 1737 strcpy(executable, "lzop");1738 } else {1739 executable[0] = '\0';1740 }1741 if (executable[0]) {1742 sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);1743 if (run_program_and_log_output(tmp, FALSE)) { 1744 log_to_screen1745 1597 mr_asprintf(executable, "lzop"); 1598 } 1599 if (executable) { 1600 mr_asprintf(tmp, "which %s > /dev/null 2> /dev/null", executable); 1601 res = run_program_and_log_output(tmp, FALSE); 1602 mr_free(tmp); 1603 1604 if (res) { 1605 log_to_screen("(compare_a_tarball) Compression program %s not found - oh no!", executable); 1746 1606 paranoid_MR_finish(1); 1747 1607 } 1748 strcpy(tmp, executable); 1749 sprintf(executable, "-P %s -Z", tmp); 1608 tmp = executable; 1609 mr_asprintf(executable, "-P %s -Z", tmp); 1610 mr_free(tmp); 1750 1611 } 1751 1612 #ifdef __FreeBSD__ … … 1755 1616 #endif 1756 1617 1757 // if (strstr(tarball_fname, ".star."))1758 1618 if (use_star) { 1759 1619 mr_asprintf(command, "star -x -force-remove -sparse -U " STAR_ACL_SZ " file=%s", tarball_fname); … … 1762 1622 } 1763 1623 } else { 1764 if ( filelist_subset_fname[0] != '\0') {1765 mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname);1624 if (! executable) { 1625 log_msg(2, "Mo executable, this shouldn't happen !"); 1766 1626 } else { 1767 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname); 1768 } 1769 } 1627 if (filelist_subset_fname != NULL) { 1628 mr_asprintf(command, "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, filelist_subset_fname, tarball_fname); 1629 } else { 1630 mr_asprintf(command, "afio -i -b %ld -c %ld -M 8m %s %s", TAPE_BLOCK_SIZE, BUFSIZE, executable, tarball_fname); 1631 } 1632 } 1633 } 1634 mr_free(executable); 1770 1635 1771 1636 #undef BUFSIZE 1637 mr_asprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), (int) (random() % 32768)); 1638 1772 1639 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log); 1773 1640 log_msg(1, "command = '%s'", command); … … 1828 1695 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 1829 1696 } 1697 unlink(temp_log); 1698 mr_free(temp_log); 1830 1699 } 1831 1700 if (does_file_exist("/PAUSE")) { … … 1834 1703 } 1835 1704 unlink(filelist_subset_fname); 1836 unlink(xattr_fname); 1837 unlink(acl_fname); 1838 unlink(temp_log); 1839 1840 leave_sub: 1841 paranoid_free(tmp); 1842 paranoid_free(filelist_name); 1843 paranoid_free(filelist_subset_fname); 1844 paranoid_free(executable); 1845 paranoid_free(temp_log); 1846 paranoid_free(xattr_fname); 1847 paranoid_free(acl_fname); 1705 mr_free(filelist_subset_fname); 1706 if (g_getfattr) { 1707 unlink(xattr_fname); 1708 mr_free(xattr_fname); 1709 } 1710 if (g_getfacl) { 1711 unlink(acl_fname); 1712 mr_free(acl_fname); 1713 } 1714 1848 1715 log_msg(5, "Leaving"); 1849 1716 return (retval); … … 1881 1748 1882 1749 /** malloc add ***/ 1883 char *tmp;1884 1750 char *mds = NULL; 1885 char *command ;1886 char *afio_fname ;1887 char *filelist_fname ;1888 char *filelist_subset_fname ;1889 char *executable ;1751 char *command = NULL; 1752 char *afio_fname = NULL; 1753 char *filelist_fname = NULL; 1754 char *filelist_subset_fname = NULL; 1755 char *executable = NULL; 1890 1756 long matches = 0; 1891 1757 bool restore_this_fileset = FALSE; … … 1894 1760 assert(bkpinfo != NULL); 1895 1761 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1896 malloc_string(filelist_subset_fname); 1897 malloc_string(filelist_fname); 1898 malloc_string(afio_fname); 1899 malloc_string(executable); 1900 malloc_string(command); 1901 malloc_string(tmp); 1902 filelist_subset_fname[0] = '\0'; 1762 1903 1763 /* to do it with a file... */ 1904 1764 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1905 1765 mds = media_descriptor_string(bkpinfo->backup_media_type); 1906 sprintf(tmp, 1907 "Restoring from fileset #%ld (%ld KB) on %s #%d", 1766 log_msg(2, "Restoring from fileset #%ld (%ld KB) on %s #%d", 1908 1767 current_tarball_number, (long) size >> 10, mds, g_current_media_number); 1909 1768 mr_free(mds); 1910 1769 1911 log_msg(2, tmp);1912 1770 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE); 1913 1771 … … 1917 1775 * in afio or someting; oh darn.. OK, use tmpfs :-) * 1918 1776 ****************************************************************************/ 1919 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 1920 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 1921 current_tarball_number); 1922 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, 1923 current_tarball_number); 1924 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", 1925 bkpinfo->tmpdir, current_tarball_number); 1926 // sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number); 1777 mr_asprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number); 1778 mr_asprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number); 1779 mr_asprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number); 1780 1927 1781 res = read_file_from_stream_to_file(afio_fname, size); 1928 1782 if (strstr(tarball_fname, ".star")) { … … 1933 1787 } 1934 1788 if (bkpinfo->compression_level == 0) { 1935 executable[0] = '\0';1789 mr_asprintf(executable, "%s", ""); 1936 1790 } else { 1937 1791 if (bkpinfo->use_star) { 1938 strcpy(executable, " -bz");1792 mr_asprintf(executable, "%s", " -bz"); 1939 1793 } else { 1940 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);1794 mr_asprintf(executable, "-P %s -Z", bkpinfo->zip_exe); 1941 1795 } 1942 1796 } … … 1949 1803 if (strstr(tarball_fname, ".star.")) { 1950 1804 use_star = TRUE; 1951 sprintf(command, "star -sparse -t file=%s %s", afio_fname, executable);1805 mr_asprintf(command, "star -sparse -t file=%s %s", afio_fname, executable); 1952 1806 } else { 1953 1807 use_star = FALSE; 1954 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 1955 executable, afio_fname); 1956 } 1957 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname, 1958 MONDO_LOGFILE); 1808 mr_asprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, executable, afio_fname); 1809 } 1810 mr_strcat(command, " > %s 2>> %s", filelist_fname, MONDO_LOGFILE); 1959 1811 log_msg(1, "command = %s", command); 1960 1812 if (system(command)) { 1961 1813 log_msg(4, "Warning - error occurred while retrieving TOC"); 1962 1814 } 1815 mr_free(command); 1816 1963 1817 if ((matches = 1964 1818 save_filelist_entries_in_common(filelist_fname, filelist, … … 1970 1824 current_tarball_number); 1971 1825 } 1972 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 1973 log_msg(2, tmp); 1826 log_msg(2, "Skipping fileset %ld", current_tarball_number); 1974 1827 restore_this_fileset = FALSE; 1975 1828 } else { … … 1982 1835 1983 1836 // Concoct the call to star/afio to restore files 1984 if (strstr(tarball_fname, ".star.")) // star1985 {1986 sprintf(command, "star -sparse -x file=%s %s", afio_fname, executable);1837 if (strstr(tarball_fname, ".star.")) { 1838 // star 1839 mr_asprintf(command, "star -sparse -x file=%s %s", afio_fname, executable); 1987 1840 if (filelist) { 1988 sprintf(command + strlen(command), " list=%s", 1989 filelist_subset_fname); 1990 } 1991 } else // afio 1992 { 1993 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, 1994 executable); 1841 mr_strcat(command, " list=%s", filelist_subset_fname); 1842 } 1843 } else { 1844 // afio 1845 mr_asprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable); 1995 1846 if (filelist) { 1996 sprintf(command + strlen(command), " -w %s",1997 filelist_subset_fname);1998 }1999 sprintf(command + strlen(command), " %s", afio_fname);2000 }2001 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);1847 mr_strcat(command, " -w %s", filelist_subset_fname); 1848 } 1849 mr_strcat(command, " %s", afio_fname); 1850 } 1851 mr_strcat(command, " 2>> %s", MONDO_LOGFILE); 1852 mr_free(executable); 2002 1853 2003 1854 // Call if IF there are files to restore (selectively/unconditionally) … … 2031 1882 log_msg(1, "NOT CALLING '%s'", command); 2032 1883 } 1884 mr_free(command); 2033 1885 2034 1886 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) { … … 2038 1890 2039 1891 unlink(filelist_subset_fname); 1892 mr_free(filelist_subset_fname); 2040 1893 unlink(filelist_fname); 1894 mr_free(filelist_fname); 2041 1895 unlink(afio_fname); 2042 2043 paranoid_free(filelist_subset_fname); 2044 paranoid_free(filelist_fname); 2045 paranoid_free(afio_fname); 2046 paranoid_free(command); 2047 paranoid_free(tmp); 1896 mr_free(afio_fname); 1897 2048 1898 return (retval); 2049 1899 } … … 2065 1915 * @return 0 for success, nonzero for failure. 2066 1916 */ 2067 int 2068 restore_all_biggiefiles_from_CD(struct s_node *filelist) 2069 { 1917 int restore_all_biggiefiles_from_CD(struct s_node *filelist) { 1918 2070 1919 int retval = 0; 2071 1920 int res = 0; 2072 1921 long noof_biggiefiles, bigfileno = 0, total_slices; 2073 1922 /** malloc **/ 2074 char *tmp; 1923 char *tmp = NULL; 1924 char *tmp1 = NULL; 2075 1925 char *mds = NULL; 2076 1926 bool just_changed_cds = FALSE; 2077 char *xattr_fname ;2078 char *acl_fname ;2079 char *biggies_whose_EXATs_we_should_set ; // EXtended ATtributes1927 char *xattr_fname = NULL; 1928 char *acl_fname = NULL; 1929 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes 2080 1930 char *pathname_of_last_biggie_restored; 2081 1931 FILE *fbw = NULL; 2082 1932 2083 malloc_string(xattr_fname); 2084 malloc_string(acl_fname); 1933 malloc_string(pathname_of_last_biggie_restored); 2085 1934 malloc_string(tmp); 2086 malloc_string(biggies_whose_EXATs_we_should_set);2087 malloc_string(pathname_of_last_biggie_restored);2088 1935 assert(bkpinfo != NULL); 2089 1936 2090 sprintf(biggies_whose_EXATs_we_should_set, 2091 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 1937 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2092 1938 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2093 log_msg(1, "Warning - cannot openout %s", 2094 biggies_whose_EXATs_we_should_set); 1939 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); 2095 1940 } 2096 1941 2097 1942 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2098 1943 total_slices = atol(tmp); 2099 sprintf(tmp, "Reassembling large files "); 2100 mvaddstr_and_log_it(g_currentY, 0, tmp); 1944 mr_free(tmp); 1945 1946 mr_asprintf(tmp1, "Reassembling large files "); 1947 mvaddstr_and_log_it(g_currentY, 0, tmp1); 1948 mr_free(tmp1); 1949 2101 1950 if (length_of_file(BIGGIELIST) < 6) { 2102 1951 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); … … 2105 1954 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2106 1955 if (noof_biggiefiles <= 0) { 2107 log_msg(2, 2108 "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 1956 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2109 1957 return (0); 2110 1958 } 2111 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2112 noof_biggiefiles); 2113 log_msg(2, tmp); 1959 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles); 2114 1960 2115 1961 open_progress_form("Reassembling large files", … … 2120 1966 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1); 2121 1967 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 2122 log_msg(3, 2123 "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 1968 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2124 1969 mds = media_descriptor_string(bkpinfo->backup_media_type); 2125 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", 2126 bigfileno + 1, mds, 2127 g_current_media_number); 1970 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno + 1, mds, g_current_media_number); 2128 1971 log_msg(3, "Slicename would have been %s", 2129 1972 slice_fname(bigfileno, 0, ARCHIVES_PATH, "")); … … 2131 1974 if (just_changed_cds) { 2132 1975 just_changed_cds = FALSE; 2133 log_msg(3, 2134 "I'll continue to scan this CD for bigfiles to be restored."); 1976 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored."); 2135 1977 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 2136 1978 insist_on_this_cd_number(++g_current_media_number); 2137 sprintf(tmp, "Restoring from %s #%d", mds, 2138 g_current_media_number); 2139 log_to_screen(tmp); 1979 log_to_screen("Restoring from %s #%d", mds, g_current_media_number); 2140 1980 just_changed_cds = TRUE; 2141 1981 } else { 2142 1982 /* That big file doesn't exist, but the followings may */ 2143 1983 /* So we need to continue looping */ 2144 log_msg(2, "There was no bigfile #%ld. That's OK.", 2145 bigfileno + 1); 1984 log_msg(2, "There was no bigfile #%ld. That's OK.", bigfileno + 1); 2146 1985 log_msg(2, "I'm going to stop restoring bigfiles now."); 2147 1986 retval++; … … 2151 1990 } else { 2152 1991 just_changed_cds = FALSE; 2153 sprintf(tmp, "Restoring big file %ld", bigfileno + 1);2154 update_progress_form(tmp );2155 res =2156 1992 mr_asprintf(tmp1, "Restoring big file %ld", bigfileno + 1); 1993 update_progress_form(tmp1); 1994 mr_free(tmp1); 1995 res = restore_a_biggiefile_from_CD(bigfileno, filelist, pathname_of_last_biggie_restored); 2157 1996 log_it("%s",pathname_of_last_biggie_restored); 2158 1997 if (fbw && pathname_of_last_biggie_restored[0]) { … … 2168 2007 fclose(fbw); 2169 2008 if (g_getfattr) { 2170 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);2009 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2171 2010 if (length_of_file(xattr_fname) > 0) { 2172 2011 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2173 2012 } 2013 mr_free(xattr_fname); 2174 2014 } 2175 2015 if (g_getfacl) { 2176 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);2016 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2177 2017 if (length_of_file(acl_fname) > 0) { 2178 2018 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2179 2019 } 2180 } 2181 } 2020 mr_free(acl_fname); 2021 } 2022 } 2023 mr_free(biggies_whose_EXATs_we_should_set); 2024 2182 2025 if (does_file_exist("/PAUSE")) { 2183 popup_and_OK 2184 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2026 popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2185 2027 } 2186 2028 close_progress_form(); … … 2190 2032 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2191 2033 } 2192 paranoid_free(xattr_fname);2193 paranoid_free(acl_fname);2194 paranoid_free(tmp);2195 paranoid_free(biggies_whose_EXATs_we_should_set);2196 2034 paranoid_free(pathname_of_last_biggie_restored); 2197 2035 return (retval); … … 2220 2058 int res; 2221 2059 int attempts; 2222 long current_tarball_number = 0 ;2060 long current_tarball_number = 0L; 2223 2061 long max_val; 2224 2062 /**malloc ***/ 2063 char *mds = NULL; 2225 2064 char *tmp = NULL; 2226 char *mds = NULL;2227 2065 char *tmp1 = NULL; 2228 char *tarball_fname; 2229 char *progress_str; 2230 char *comment; 2066 char *tarball_fname = NULL; 2067 char *progress_str = NULL; 2068 2069 assert(bkpinfo != NULL); 2231 2070 2232 2071 malloc_string(tmp); 2233 malloc_string(tarball_fname);2234 malloc_string(progress_str);2235 malloc_string(comment);2236 2237 assert(bkpinfo != NULL);2238 2239 2072 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2240 log_msg(2, 2241 "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER"); 2073 log_msg(2, "Insisting on 1st media, so that I can have a look at LAST-FILELIST-NUMBER"); 2242 2074 if (g_current_media_number != 1) { 2243 2075 log_msg(3, "OK, that's jacked up."); … … 2250 2082 2251 2083 mds = media_descriptor_string(bkpinfo->backup_media_type); 2252 sprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number);2084 mr_asprintf(progress_str, "Restoring from %s #%d", mds, g_current_media_number); 2253 2085 2254 2086 log_to_screen(progress_str); … … 2260 2092 insist_on_this_cd_number(g_current_media_number); 2261 2093 update_progress_form(progress_str); 2262 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2263 current_tarball_number); 2094 mr_free(progress_str); 2095 2096 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", current_tarball_number); 2264 2097 if (!does_file_exist(tarball_fname)) { 2265 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz",2266 2098 mr_free(tarball_fname); 2099 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.gz", current_tarball_number); 2267 2100 } 2268 2101 if (!does_file_exist(tarball_fname)) { 2269 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",2270 2102 mr_free(tarball_fname); 2103 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzma", current_tarball_number); 2271 2104 } 2272 2105 if (!does_file_exist(tarball_fname)) { 2273 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",2274 2106 mr_free(tarball_fname); 2107 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", current_tarball_number); 2275 2108 } 2276 2109 if (!does_file_exist(tarball_fname)) { 2277 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",2278 2110 mr_free(tarball_fname); 2111 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", current_tarball_number); 2279 2112 } 2280 2113 if (!does_file_exist(tarball_fname)) { 2281 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", 2282 current_tarball_number); 2114 mr_free(tarball_fname); 2115 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", current_tarball_number); 2116 } 2117 if (!does_file_exist(tarball_fname)) { 2118 mr_free(tarball_fname); 2119 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", current_tarball_number); 2283 2120 } 2284 2121 if (!does_file_exist(tarball_fname)) { … … 2286 2123 log_to_screen 2287 2124 ("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2125 mr_free(tarball_fname); 2288 2126 return (0); 2289 2127 } … … 2295 2133 } 2296 2134 g_current_media_number++; 2297 sprintf(progress_str, "Restoring from %s #%d", 2298 media_descriptor_string(bkpinfo->backup_media_type), 2299 g_current_media_number); 2135 mr_asprintf(progress_str, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2300 2136 log_to_screen(progress_str); 2301 2137 } else { 2302 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2303 current_tarball_number, mds, g_current_media_number); 2304 // log_msg(3, "progress_str = %s", progress_str); 2305 for (res = 999, attempts = 0; attempts < 3 && res != 0; 2306 attempts++) { 2307 res = 2308 restore_a_tarball_from_CD(tarball_fname, 2309 current_tarball_number, 2310 filelist); 2311 } 2312 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", 2313 mds, g_current_media_number, current_tarball_number); 2138 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_tarball_number, mds, g_current_media_number); 2139 for (res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) { 2140 res = restore_a_tarball_from_CD(tarball_fname, current_tarball_number, filelist); 2141 } 2142 mr_asprintf(tmp1, "%s #%d, fileset #%ld - restore ", mds, g_current_media_number, current_tarball_number); 2314 2143 if (res) { 2315 2144 mr_strcat(tmp1, "reported errors"); … … 2322 2151 mr_strcat(tmp1, " (%d attempts) - review logs", attempts); 2323 2152 } 2324 strcpy(comment, tmp1);2325 paranoid_free(tmp1);2326 2153 if (attempts > 1) { 2327 log_to_screen(comment); 2328 } 2154 log_to_screen(tmp1); 2155 } 2156 mr_free(tmp1); 2329 2157 2330 2158 retval += res; … … 2332 2160 g_current_progress++; 2333 2161 } 2162 mr_free(tarball_fname); 2163 2334 2164 /* Now we need to umount the current media to have the next mounted by insist_on_this_cd_number */ 2335 2165 /* run_program_and_log_output("umount " MNT_CDROM, FALSE); */ 2336 2166 } 2337 2167 mr_free(mds); 2168 mr_free(progress_str); 2338 2169 2339 2170 close_progress_form(); … … 2343 2174 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2344 2175 } 2345 paranoid_free(tarball_fname);2346 paranoid_free(progress_str);2347 paranoid_free(comment);2348 2176 2349 2177 return (retval); … … 2375 2203 2376 2204 /** malloc add ****/ 2377 char *tmp ;2205 char *tmp = NULL; 2378 2206 char *biggie_fname; 2379 2207 char *biggie_cksum; 2380 char *xattr_fname ;2381 char *acl_fname ;2208 char *xattr_fname = NULL; 2209 char *acl_fname = NULL; 2382 2210 char *p; 2383 2211 char *pathname_of_last_biggie_restored; 2384 char *biggies_whose_EXATs_we_should_set ; // EXtended ATtributes2212 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes 2385 2213 long long biggie_size; 2386 2214 FILE *fbw = NULL; … … 2389 2217 malloc_string(biggie_fname); 2390 2218 malloc_string(biggie_cksum); 2391 malloc_string(xattr_fname);2392 malloc_string(acl_fname);2393 malloc_string(biggies_whose_EXATs_we_should_set);2394 2219 malloc_string(pathname_of_last_biggie_restored); 2395 2220 assert(bkpinfo != NULL); … … 2398 2223 2399 2224 total_slices = atol(tmp); 2400 sprintf(tmp, "Reassembling large files "); 2225 2401 2226 if (g_getfattr) { 2402 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);2227 mr_asprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2403 2228 } 2404 2229 if (g_getfacl) { 2405 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2406 } 2407 mvaddstr_and_log_it(g_currentY, 0, tmp); 2408 sprintf(biggies_whose_EXATs_we_should_set, 2409 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2230 mr_asprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2231 } 2232 mr_asprintf(tmp1, "Reassembling large files "); 2233 mvaddstr_and_log_it(g_currentY, 0, tmp1); 2234 mr_free(tmp1); 2235 2236 mr_asprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2410 2237 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2411 log_msg(1, "Warning - cannot openout %s", 2412 biggies_whose_EXATs_we_should_set); 2413 } 2414 // get xattr and acl files if they're there 2415 res = 2416 read_header_block_from_stream(&biggie_size, biggie_fname, 2417 &ctrl_chr); 2238 log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); 2239 } 2240 2241 // get xattr and acl files if they're there 2242 res = read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr); 2418 2243 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2419 res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, 2420 &ctrl_chr, xattr_fname, acl_fname); 2244 res = read_EXAT_files_from_tape(&biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname); 2421 2245 } 2422 2246 2423 2247 noof_biggiefiles = atol(biggie_fname); 2424 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2425 noof_biggiefiles); 2426 log_msg(2, tmp); 2248 log_msg(2, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles); 2427 2249 open_progress_form("Reassembling large files", 2428 2250 "I am now reassembling all the large files.", … … 2447 2269 p++; 2448 2270 } 2449 sprintf(tmp, "Restoring big file %ld (%lld K)",2450 current_bigfile_number + 1, biggie_size / 1024);2451 update_progress_form(tmp);2271 mr_asprintf(tmp1, "Restoring big file %ld (%lld K)", current_bigfile_number + 1, biggie_size / 1024); 2272 update_progress_form(tmp1); 2273 mr_free(tmp1); 2452 2274 res = restore_a_biggiefile_from_stream(biggie_fname, 2453 2275 current_bigfile_number, … … 2467 2289 if (current_bigfile_number != noof_biggiefiles 2468 2290 && noof_biggiefiles != 0) { 2469 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", 2470 current_bigfile_number, noof_biggiefiles); 2471 } else { 2472 sprintf(tmp, 2473 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2474 noof_biggiefiles, current_bigfile_number); 2475 } 2476 log_msg(1, tmp); 2291 log_msg(1, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", current_bigfile_number, noof_biggiefiles); 2292 } else { 2293 log_msg(1, "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", noof_biggiefiles, current_bigfile_number); 2294 } 2477 2295 2478 2296 if (fbw) { … … 2482 2300 if (g_getfattr) { 2483 2301 if (length_of_file(xattr_fname) > 0) { 2484 log_msg(1, "set_fattr_List(%s,%s)", 2485 biggies_whose_EXATs_we_should_set, xattr_fname); 2486 set_fattr_list(biggies_whose_EXATs_we_should_set, 2487 xattr_fname); 2302 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname); 2303 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2488 2304 } 2489 2305 } 2490 2306 if (g_getfacl) { 2491 2307 if (length_of_file(acl_fname) > 0) { 2492 log_msg(1, "set_acl_list(%s,%s)", 2493 biggies_whose_EXATs_we_should_set, acl_fname); 2308 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname); 2494 2309 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2495 2310 } … … 2499 2314 } 2500 2315 } 2316 mr_free(xattr_fname); 2317 mr_free(acl_fname); 2318 mr_free(biggies_whose_EXATs_we_should_set); 2319 2501 2320 if (does_file_exist("/PAUSE")) { 2502 2321 popup_and_OK … … 2510 2329 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2511 2330 } 2512 paranoid_free(biggies_whose_EXATs_we_should_set);2513 2331 paranoid_free(pathname_of_last_biggie_restored); 2514 2332 paranoid_free(biggie_fname); 2515 2333 paranoid_free(biggie_cksum); 2516 paranoid_free(xattr_fname);2517 paranoid_free(acl_fname);2518 2334 paranoid_free(tmp); 2519 2335 return (retval); … … 2539 2355 * @return 0 for success, or the number of filesets that failed. 2540 2356 */ 2541 int 2542 restore_all_tarballs_from_stream(struct s_node *filelist) 2357 int restore_all_tarballs_from_stream(struct s_node *filelist) 2543 2358 { 2544 2359 int retval = 0; … … 2549 2364 2550 2365 /** malloc **/ 2551 char *tmp ;2366 char *tmp = NULL; 2552 2367 char *mds = NULL; 2553 char *progress_str ;2368 char *progress_str = NULL; 2554 2369 char *tmp_fname; 2555 char *xattr_fname ;2556 char *acl_fname ;2370 char *xattr_fname = NULL; 2371 char *acl_fname = NULL; 2557 2372 2558 2373 long long tmp_size; 2559 2374 2560 2375 malloc_string(tmp); 2561 malloc_string(progress_str);2562 2376 malloc_string(tmp_fname); 2563 2377 assert(bkpinfo != NULL); 2564 malloc_string(xattr_fname);2565 malloc_string(acl_fname);2566 2378 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2567 2379 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); … … 2574 2386 run_program_and_log_output("pwd", 5); 2575 2387 2576 sprintf(progress_str, "Restoring from media #%d", 2577 g_current_media_number); 2388 mr_asprintf(progress_str, "Restoring from media #%d", g_current_media_number); 2578 2389 log_to_screen(progress_str); 2579 2390 open_progress_form("Restoring from archives", … … 2597 2408 update_progress_form(progress_str); 2598 2409 if (g_getfattr) { 2599 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, 2600 current_afioball_number); 2410 mr_asprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2601 2411 unlink(xattr_fname); 2602 2412 } 2603 2413 if (g_getfacl) { 2604 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, 2605 current_afioball_number); 2414 mr_asprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2606 2415 unlink(acl_fname); 2607 2416 } 2608 2417 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2609 2418 log_it("Reading EXAT files from tape"); 2610 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, 2611 &ctrl_chr, xattr_fname, 2612 acl_fname); 2419 res = read_EXAT_files_from_tape(&tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname); 2613 2420 } 2614 2421 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 2615 2422 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 2616 2423 } 2617 sprintf(tmp, 2618 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2619 current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2620 res = 2621 restore_a_tarball_from_stream(tmp_fname, 2622 current_afioball_number, 2623 filelist, tmp_size, xattr_fname, 2624 acl_fname); 2424 log_msg(4, "Restoring from fileset #%ld (name=%s, size=%ld K)", current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2425 res = restore_a_tarball_from_stream(tmp_fname, current_afioball_number, filelist, tmp_size, xattr_fname, acl_fname); 2625 2426 retval += res; 2626 2427 if (res) { 2627 sprintf(tmp, "Fileset %ld - errors occurred", 2628 current_afioball_number); 2629 log_to_screen(tmp); 2428 log_to_screen("Fileset %ld - errors occurred", current_afioball_number); 2630 2429 } 2631 2430 res = … … 2638 2437 g_current_progress++; 2639 2438 mds = media_descriptor_string(bkpinfo->backup_media_type), 2640 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2641 current_afioball_number, mds,2642 2439 2440 mr_free(progress_str); 2441 mr_asprintf(progress_str, "Restoring from fileset #%ld on %s #%d", current_afioball_number, mds, g_current_media_number); 2643 2442 mr_free(mds); 2644 res = 2645 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2443 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2646 2444 if (g_getfattr) { 2647 2445 unlink(xattr_fname); … … 2651 2449 } 2652 2450 } // next 2451 mr_free(progress_str); 2452 if (g_getfattr) { 2453 mr_free(xattr_fname); 2454 } 2455 if (g_getfacl) { 2456 mr_free(acl_fname); 2457 } 2458 2653 2459 log_msg(1, "All done with afioballs"); 2654 2460 close_progress_form(); … … 2659 2465 } 2660 2466 paranoid_free(tmp); 2661 paranoid_free(progress_str);2662 2467 paranoid_free(tmp_fname); 2663 paranoid_free(xattr_fname);2664 paranoid_free(acl_fname);2665 2468 return (retval); 2666 2469 } … … 2689 2492 char *cwd; 2690 2493 char *newpath; 2691 char *tmp ;2494 char *tmp = NULL; 2692 2495 assert(bkpinfo != NULL); 2693 2496 2694 2497 malloc_string(cwd); 2695 2498 malloc_string(newpath); 2696 malloc_string(tmp);2697 2499 log_msg(2, "restore_everything() --- starting"); 2698 2500 g_current_media_number = 1; … … 2700 2502 // FIXME 2701 2503 } 2702 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);2504 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2703 2505 run_program_and_log_output(tmp, FALSE); 2506 mr_free(tmp); 2507 2704 2508 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2705 2509 if (chdir(bkpinfo->restore_path)) { … … 2755 2559 paranoid_free(cwd); 2756 2560 paranoid_free(newpath); 2757 paranoid_free(tmp);2758 2561 return (resA + resB); 2759 2562 } … … 2776 2579 { 2777 2580 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION); 2778 log_msg(0, 2779 "DON'T PANIC! Mondorestore logs almost everything, so please "); 2780 log_msg(0, 2781 "don't break out in a cold sweat just because you see a few "); 2782 log_msg(0, 2783 "error messages in the log. Read them; analyze them; see if "); 2784 log_msg(0, 2785 "they are significant; above all, verify your backups! Please"); 2786 log_msg(0, 2787 "attach a compressed copy of this log to any e-mail you send "); 2788 log_msg(0, 2789 "to the Mondo mailing list when you are seeking technical "); 2790 log_msg(0, 2791 "support. Without it, we can't help you. - DevTeam"); 2792 log_msg(0, 2793 "------------------------------------------------------------"); 2794 log_msg(0, 2795 "BTW, despite (or perhaps because of) the wealth of messages,"); 2796 log_msg(0, 2797 "some users are inclined to stop reading this log. If Mondo "); 2798 log_msg(0, 2799 "stopped for some reason, chances are it's detailed here. "); 2800 log_msg(0, 2801 "More than likely there's a message at the very end of this "); 2802 log_msg(0, 2803 "log that will tell you what is wrong. Please read it! "); 2804 log_msg(0, 2805 "------------------------------------------------------------"); 2581 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please "); 2582 log_msg(0, "don't break out in a cold sweat just because you see a few "); 2583 log_msg(0, "error messages in the log. Read them; analyze them; see if "); 2584 log_msg(0, "they are significant; above all, verify your backups! Please"); 2585 log_msg(0, "attach a compressed copy of this log to any e-mail you send "); 2586 log_msg(0, "to the Mondo mailing list when you are seeking technical "); 2587 log_msg(0, "support. Without it, we can't help you. - DevTeam"); 2588 log_msg(0, "------------------------------------------------------------"); 2589 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages,"); 2590 log_msg(0, "some users are inclined to stop reading this log. If Mondo "); 2591 log_msg(0, "stopped for some reason, chances are it's detailed here. "); 2592 log_msg(0, "More than likely there's a message at the very end of this "); 2593 log_msg(0, "log that will tell you what is wrong. Please read it! "); 2594 log_msg(0, "------------------------------------------------------------"); 2806 2595 } 2807 2596 … … 2818 2607 int retval = 0; 2819 2608 int res; 2820 // int c; 2821 char *tmp; 2609 char *tmp = NULL; 2822 2610 2823 2611 struct mountlist_itself *mountlist; 2824 2612 struct raidlist_itself *raidlist; 2825 2613 struct s_node *filelist; 2826 char *a, *b; 2614 char *tmp1 = NULL; 2615 char *tmp2 = NULL; 2827 2616 bool run_postnuke = FALSE; 2828 2617 … … 2838 2627 2839 2628 g_loglevel = DEFAULT_MR_LOGLEVEL; 2840 malloc_string(tmp);2841 2629 2842 2630 /* Configure global variables */ … … 2863 2651 } 2864 2652 2653 /* Init GUI */ 2654 setup_newt_stuff(); /* call newtInit and setup screen log */ 2655 2865 2656 malloc_libmondo_global_strings(); 2866 2657 2867 2658 strcpy(g_mondo_home, 2868 2659 call_program_and_get_last_line_of_output("which mondorestore")); 2869 /*2870 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");2871 make_hole_for_dir(g_tmpfs_mountpt);2872 */2873 2660 g_current_media_number = 1; // precaution 2874 2661 2875 2662 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE); 2876 2663 2877 malloc_string(a);2878 malloc_string(b);2879 2664 setup_MR_global_filenames(); // malloc() and set globals, using bkpinfo->tmpdir etc. 2880 2665 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type … … 2897 2682 2898 2683 /* Backup original mountlist.txt */ 2899 sprintf(tmp, "%s.orig", g_mountlist_fname);2684 mr_asprintf(tmp, "%s.orig", g_mountlist_fname); 2900 2685 if (!does_file_exist(g_mountlist_fname)) { 2901 log_msg(2, 2902 "%ld: Warning - g_mountlist_fname (%s) does not exist yet", 2903 __LINE__, g_mountlist_fname); 2686 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname); 2904 2687 } else if (!does_file_exist(tmp)) { 2905 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,2906 2688 mr_free(tmp); 2689 mr_asprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, g_mountlist_fname); 2907 2690 run_program_and_log_output(tmp, FALSE); 2908 2691 } 2692 mr_free(tmp); 2909 2693 2910 2694 /* Init directories */ … … 2912 2696 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */ 2913 2697 run_program_and_log_output("umount -d " MNT_CDROM, FALSE); 2914 /*2915 run_program_and_log_output("ln -sf /var/log/mondo-archive.log /tmp/mondorestore.log",2916 FALSE);2917 */2918 2698 2919 2699 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 2920 2700 2921 /* Init GUI */2922 setup_newt_stuff(); /* call newtInit and setup screen log */2923 2701 welcome_to_mondorestore(); 2924 2702 if (bkpinfo->disaster_recovery) { … … 2954 2732 } 2955 2733 2956 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {2957 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {2958 paranoid_system("mount " MNT_CDROM);2959 }2960 bkpinfo->compression_level = 1;2961 g_current_media_number = 2;2962 strcpy(bkpinfo->restore_path, "/tmp/TESTING");2963 bkpinfo->backup_media_type = dvd;2964 open_progress_form("Reassembling /dev/hda1",2965 "Shark is a bit of a silly person.",2966 "Please wait. This may take some time.",2967 "", 1999);2968 paranoid_system("rm -Rf /tmp/*pih*");2969 2970 restore_a_biggiefile_from_CD(42, NULL, tmp);2971 }2972 2973 2734 if (argc == 5 && strcmp(argv[1], "--common") == 0) { 2974 2735 g_loglevel = 6; … … 2981 2742 // BERLIOS: /usr/lib ??? 2982 2743 toggle_path_selection(filelist, "/usr/share", TRUE); 2983 // show_filelist(filelist);2984 2744 save_filelist(filelist, "/tmp/out.txt"); 2985 // finish(0); 2986 // toggle_path_selection (filelist, "/root/stuff", TRUE); 2987 strcpy(a, argv[3]); 2988 strcpy(b, argv[4]); 2989 2990 res = save_filelist_entries_in_common(a, filelist, b, FALSE); 2745 mr_asprintf(tmp1, "%s", argv[3]); 2746 mr_asprintf(tmp2, "%s", argv[4]); 2747 2748 res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE); 2749 mr_free(tmp1); 2750 mr_free(tmp2); 2751 2991 2752 free_filelist(filelist); 2992 2753 printf("res = %d", res); … … 3096 2857 log_msg(2, "Still here. Yay."); 3097 2858 if ((strlen(bkpinfo->tmpdir) > 0) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) { 3098 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);2859 mr_asprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir); 3099 2860 run_program_and_log_output(tmp, FALSE); 2861 mr_free(tmp); 3100 2862 } 3101 2863 unmount_boot_if_necessary(); /* for Gentoo users */ … … 3115 2877 // BCO:To be reviewed 3116 2878 if ((bkpinfo->restore_mode == compare) || (bkpinfo->restore_mode == nuke)) { 3117 if (bkpinfo->backup_media_type == netfs 3118 && !is_this_device_mounted(bkpinfo->netfs_mount)) { 2879 if ((bkpinfo->backup_media_type == netfs) && bkpinfo->netfs_mount && !is_this_device_mounted(bkpinfo->netfs_mount)) { 3119 2880 log_msg(1, "Mounting remote %s dir", bkpinfo->netfs_proto); 3120 2881 sprintf(bkpinfo->isodir, "/tmp/isodir"); … … 3122 2883 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 3123 2884 if (bkpinfo->netfs_user) { 3124 sprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", 3125 bkpinfo->netfs_user,bkpinfo->netfs_mount); 2885 mr_asprintf(tmp, "sshfs -o ro %s@%s /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount); 3126 2886 } else { 3127 sprintf(tmp, "sshfs -o ro %s /tmp/isodir", 3128 bkpinfo->netfs_mount); 2887 mr_asprintf(tmp, "sshfs -o ro %s /tmp/isodir", bkpinfo->netfs_mount); 3129 2888 } 3130 2889 } else { 3131 2890 if (strstr(bkpinfo->netfs_proto, "smbfs")) { 3132 2891 if (bkpinfo->netfs_user) { 3133 sprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", 3134 bkpinfo->netfs_mount,bkpinfo->netfs_user); 2892 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o user=%s,nolock,ro ", bkpinfo->netfs_mount,bkpinfo->netfs_user); 3135 2893 } else { 3136 sprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", 3137 bkpinfo->netfs_mount); 2894 mr_asprintf(tmp, "mount -t cifs %s /tmp/isodir -o nolock,ro ", bkpinfo->netfs_mount); 3138 2895 } 3139 2896 } else { 3140 2897 if (bkpinfo->netfs_user) { 3141 sprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", 3142 bkpinfo->netfs_user,bkpinfo->netfs_mount); 2898 mr_asprintf(tmp, "mount %s@%s -o nolock,ro /tmp/isodir", bkpinfo->netfs_user,bkpinfo->netfs_mount); 3143 2899 } else { 3144 sprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", 3145 bkpinfo->netfs_mount); 2900 mr_asprintf(tmp, "mount %s -o nolock,ro /tmp/isodir", bkpinfo->netfs_mount); 3146 2901 } 3147 2902 } 3148 2903 } 3149 2904 run_program_and_log_output(tmp, 1); 2905 mr_free(tmp); 3150 2906 } 3151 2907 } 3152 2908 3153 2909 if (retval) { 3154 log_to_screen 3155 ("Warning - load_raidtab_into_raidlist returned an error"); 2910 log_to_screen("Warning - load_raidtab_into_raidlist returned an error"); 3156 2911 } 3157 2912 … … 3205 2960 "Run complete. Please remove media and reboot."); 3206 2961 } else { 3207 run_program_and_log_output("sync", FALSE);2962 sync(); 3208 2963 if (is_this_device_mounted(MNT_CDROM)) { 3209 2964 run_program_and_log_output("umount -d " MNT_CDROM, FALSE); … … 3242 2997 } else { 3243 2998 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3244 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, 3245 retval); 2999 mr_asprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval); 3246 3000 log_msg(2, "Calling '%s'", tmp); 3247 3001 if ((res = run_program_and_log_output(tmp, 0))) { 3248 3002 log_OS_error(tmp); 3249 3003 } 3004 mr_free(tmp); 3250 3005 log_msg(1, "post-nuke returned w/ res=%d", res); 3251 3006 } … … 3263 3018 set_signals(FALSE); 3264 3019 log_to_screen("Restore log (%s) copied to /var/log on your hard disk", MONDO_LOGFILE); 3265 sprintf(tmp, 3266 "Mondo-restore is exiting (retval=%d) ", 3267 retval); 3268 log_to_screen(tmp); 3269 sprintf(tmp, "umount -d %s", bkpinfo->isodir); 3020 log_to_screen("Mondo-restore is exiting (retval=%d) ", retval); 3021 3022 mr_asprintf(tmp, "umount -d %s", bkpinfo->isodir); 3270 3023 run_program_and_log_output(tmp, 5); 3024 mr_free(tmp); 3025 3271 3026 paranoid_free(mountlist); 3272 3027 paranoid_free(raidlist); … … 3275 3030 } // for b0rken distros 3276 3031 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) { 3277 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);3032 mr_asprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir); 3278 3033 paranoid_system(tmp); 3034 mr_free(tmp); 3279 3035 } 3280 3036 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo 3281 3037 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3282 paranoid_free(a);3283 paranoid_free(b);3284 paranoid_free(tmp);3285 3038 3286 3039 unlink("/tmp/filelist.full"); -
branches/3.2/mondo/src/mondorestore/mr-externs.h
r3158 r3193 9 9 #define BIGGIELIST MNT_CDROM"/archives/biggielist.txt" 10 10 #define ARCHIVES_PATH MNT_CDROM"/archives" 11 #define BIGGIELIST ARCHIVES_PATH"/biggielist.txt" 11 12 12 13 #ifdef __FreeBSD__ … … 79 80 extern int verify_tape_backups(); 80 81 extern char which_restore_mode(void); 81 extern int which_format_command_do_i_need(char *, char *);82 82 extern int write_cfg_var(char *, char *, char *); 83 83 extern void wrong_marker(int, int);
Note:
See TracChangeset
for help on using the changeset viewer.