- Timestamp:
- Sep 25, 2013, 8:55:39 AM (12 years ago)
- Location:
- branches/3.0/mondo/src/common
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-archive.c
r3185 r3188 64 64 extern bool g_cd_recovery; 65 65 extern char *g_mondo_home; 66 /* 67 extern char *g_tmpfs_mountpt; 68 */ 69 extern char *g_serial_string; 66 67 /** 68 * The serial string (used to differentiate between backups) of the current backup. 69 */ 70 char *g_serial_string = NULL; 71 70 72 extern char *g_getfacl; 71 73 extern char *g_getfattr; … … 200 202 201 203 if (!does_file_exist(filelist)) { 202 mr_asprintf(tmp, "(archive_this_fileset) - filelist %s does not exist", filelist); 203 log_to_screen(tmp); 204 paranoid_free(tmp); 204 log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist); 205 205 return (1); 206 206 } … … 208 208 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 209 209 if (system(tmp)) { 210 paranoid_free(tmp);210 mr_free(tmp); 211 211 fatal_error("Unable to write tarball to scratchdir"); 212 212 } 213 213 paranoid_free(tmp); 214 214 215 mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s", 216 filelist, fname); 215 mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s", filelist, fname); 217 216 if (bkpinfo->use_lzo) { 217 mr_free(command); 218 218 fatal_error("Can't use lzop"); 219 219 } … … 235 235 res = 0; 236 236 } 237 paranoid_free(tmp);237 mr_free(tmp); 238 238 239 239 if (res) { … … 251 251 } 252 252 } 253 paranoid_free(command);253 mr_free(command); 254 254 255 255 retval += res; … … 307 307 308 308 if (!does_file_exist(filelist)) { 309 mr_asprintf(tmp, "(archive_this_fileset) - filelist %s does not exist", 310 filelist); 311 log_to_screen(tmp); 312 paranoid_free(tmp); 309 log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist); 313 310 return (1); 314 311 } 315 312 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 316 313 if (system(tmp)) { 317 paranoid_free(tmp);314 mr_free(tmp); 318 315 fatal_error("Unable to write tarball to scratchdir"); 319 316 } 320 paranoid_free(tmp);317 mr_free(tmp); 321 318 322 319 … … 324 321 mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 325 322 // -b %ld, TAPE_BLOCK_SIZE 326 mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, 327 bkpinfo->compression_level); 323 mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level); 328 324 if (does_file_exist(tmp)) { 329 325 mr_strcat(zipparams, " -E %s",tmp); … … 331 327 log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); 332 328 } 333 paranoid_free(tmp);329 mr_free(tmp); 334 330 } else { 335 331 mr_asprintf(zipparams, ""); 336 332 } 337 338 // make_hole_for_file(fname);339 333 340 334 if (!does_file_exist(bkpinfo->tmpdir)) { … … 346 340 fatal_error("scratchdir not found"); 347 341 } 348 mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, 349 fname, bkpinfo->zip_suffix); 342 mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname, bkpinfo->zip_suffix); 350 343 paranoid_system(command); 351 paranoid_free(command); 352 353 mr_asprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", 354 TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE); 355 paranoid_free(zipparams); 344 mr_free(command); 345 346 mr_asprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s", TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE); 347 mr_free(zipparams); 356 348 357 349 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 358 350 if (system(tmp)) { 359 paranoid_free(tmp);351 mr_free(tmp); 360 352 fatal_error("Unable to write tarball to scratchdir"); 361 353 } 362 paranoid_free(tmp);354 mr_free(tmp); 363 355 364 356 for (res = 99, tries = 0; tries < 3 && res != 0; tries++) { … … 406 398 { 407 399 int retval = 0, res = 0; 408 char *tmp ;400 char *tmp = NULL; 409 401 410 402 assert(bkpinfo != NULL); 411 403 set_g_cdrom_and_g_dvd_to_bkpinfo_value(); 412 malloc_string(tmp);413 404 if (bkpinfo->backup_media_type == dvd) { 414 405 #ifdef DVDRWFORMAT … … 431 422 } 432 423 433 /* 434 sprintf(tmp, "wc -l %s/archives/filelist.full > %s/archives/filelist.count",bkpinfo->scratchdir, bkpinfo->scratchdir); 435 if (run_program_and_log_output(tmp, 2)) 436 { fatal_error("Failed to count filelist.full"); } 437 */ 438 sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir); 424 mr_asprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir); 439 425 if (run_program_and_log_output(tmp, 2)) { 426 mr_free(tmp); 440 427 fatal_error("Failed to gzip filelist.full"); 441 428 } 442 sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, 443 bkpinfo->tmpdir); 429 mr_free(tmp); 430 431 mr_asprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir); 444 432 if (run_program_and_log_output(tmp, 2)) { 433 mr_free(tmp); 445 434 fatal_error("Failed to copy to tmpdir"); 446 435 } 436 mr_free(tmp); 447 437 448 438 copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists … … 464 454 } 465 455 retval += do_that_initial_phase(); // prepare 466 sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);456 mr_asprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir); 467 457 run_program_and_log_output(tmp, 1); 458 mr_free(tmp); 459 468 460 retval += make_those_afios_phase(); // backup regular files 469 461 retval += make_those_slices_phase(); // backup BIG files … … 473 465 sleep(2); 474 466 } 475 paranoid_free(tmp);476 467 return (retval); 477 468 } … … 514 505 char *use_lzo_sz = NULL; 515 506 char *use_gzip_sz = NULL; 507 char *use_lzma_sz = NULL; 516 508 char *use_comp_sz = NULL; 517 509 char *use_star_sz = NULL; … … 542 534 assert(bkpinfo != NULL); 543 535 544 mvaddstr_and_log_it(g_currentY, 0, 545 "Calling MINDI to create boot+data disks"); 536 mvaddstr_and_log_it(g_currentY, 0, "Calling MINDI to create boot+data disks"); 546 537 open_evalcall_form("Calling MINDI to create boot+data disks"); 547 538 mr_asprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir); … … 550 541 mr_asprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir); 551 542 if (!does_file_exist(tmp)) { 552 fatal_error553 543 mr_free(tmp); 544 fatal_error ("Cannot find filelist.full, so I cannot count its lines"); 554 545 } 555 546 } … … 571 562 } 572 563 } 573 paranoid_free(ntapedev);564 mr_free(ntapedev); 574 565 mr_asprintf(tape_device, "%s", bkpinfo->media_device); 575 566 } else { … … 586 577 } else { 587 578 mr_asprintf(use_gzip_sz, "no"); 579 } 580 if (bkpinfo->use_lzma) { 581 mr_asprintf(use_lzma_sz, "yes"); 582 } else { 583 mr_asprintf(use_lzma_sz, "no"); 588 584 } 589 585 if (bkpinfo->use_star) { … … 660 656 ch = 'U'; 661 657 if (bkpinfo->boot_loader != '\0') { 662 mr_asprintf(tmp, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader); 663 log_msg(2, tmp); 664 mr_free(tmp); 658 log_msg(2, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader); 665 659 } else { 666 660 bkpinfo->boot_loader = ch; 667 661 } 668 662 if (bkpinfo->boot_device[0] != '\0') { 669 mr_asprintf(tmp, "User specified boot device. It is '%s'.", bkpinfo->boot_device); 670 log_msg(2, tmp); 671 mr_free(tmp); 663 log_msg(2, "User specified boot device. It is '%s'.", bkpinfo->boot_device); 672 664 } else { 673 665 strcpy(bkpinfo->boot_device, bootdev); … … 692 684 mr_asprintf(bootldr_str, "LILO"); 693 685 if (!does_file_exist("/etc/lilo.conf")) { 694 fatal_error 695 ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?"); 686 fatal_error("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?"); 696 687 } 697 688 } else if (bkpinfo->boot_loader == 'G') { 698 689 mr_asprintf(bootldr_str, "GRUB"); 699 if (!does_file_exist("/boot/grub/menu.lst") 700 && does_file_exist("/boot/grub/grub.conf")) { 701 run_program_and_log_output 702 ("ln -sf /boot/grub/grub.conf /boot/grub/menu.lst", 5); 690 if (!does_file_exist("/boot/grub/menu.lst") && does_file_exist("/boot/grub/grub.conf")) { 691 run_program_and_log_output("ln -sf /boot/grub/grub.conf /boot/grub/menu.lst", 5); 703 692 } 704 693 if ((!does_file_exist("/boot/grub/menu.lst")) && (!does_file_exist("/boot/grub/grub.cfg")) && (!does_file_exist("/boot/grub2/grub.cfg"))) { 705 fatal_error 706 ("The de facto standard location for your boot loader's config file is /boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg but I cannot find it there. What is wrong with your Linux distribution?"); 694 fatal_error("The de facto standard location for your boot loader's config file is /boot/grub/menu.lst, /boot/grub/grub.cfg, or /boot/grub2/grub.cfg but I cannot find it there. What is wrong with your Linux distribution?"); 707 695 } 708 696 mr_asprintf(bootldr_ver, "%s", call_program_and_get_last_line_of_output("grub --version")); … … 710 698 mr_asprintf(bootldr_str, "ELILO"); 711 699 /* BCO: fix it for Debian, Mandrake, ... */ 712 if (!does_file_exist("/etc/elilo.conf") 713 && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) { 714 run_program_and_log_output 715 ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", 716 5); 717 } 718 if (!does_file_exist("/etc/elilo.conf") 719 && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) { 720 run_program_and_log_output 721 ("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf", 722 5); 723 } 724 if (!does_file_exist("/etc/elilo.conf") 725 && does_file_exist("/boot/efi/efi/debian/elilo.conf")) { 726 run_program_and_log_output 727 ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf", 728 5); 729 } 730 if (!does_file_exist("/etc/elilo.conf") 731 && does_file_exist("/boot/efi/debian/elilo.conf")) { 732 run_program_and_log_output 733 ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf", 734 5); 700 if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) { 701 run_program_and_log_output("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf", 5); 702 } 703 if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) { 704 run_program_and_log_output("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf", 5); 705 } 706 if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/efi/debian/elilo.conf")) { 707 run_program_and_log_output ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf", 5); 708 } 709 if (!does_file_exist("/etc/elilo.conf") && does_file_exist("/boot/efi/debian/elilo.conf")) { 710 run_program_and_log_output ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf", 5); 735 711 } 736 712 if (!does_file_exist("/etc/elilo.conf")) { 737 fatal_error 738 ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'"); 713 fatal_error("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'"); 739 714 } 740 715 } else if (bkpinfo->boot_loader == 'R') { … … 753 728 mr_asprintf(bootldr_str, "unknown"); 754 729 } 755 mr_asprintf(tmp, "Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device); 756 log_to_screen(tmp); 757 mr_free(tmp); 730 log_to_screen("Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device); 731 758 732 if (bootldr_ver != NULL) { 759 mr_asprintf(tmp, "Boot loader version string: %s", bootldr_ver); 760 log_to_screen(tmp); 761 mr_free(tmp); 733 log_to_screen("Boot loader version string: %s", bootldr_ver); 762 734 } 763 735 … … 799 771 fatal_error("Unknown backup_media_type"); 800 772 } 801 if (bkpinfo->backup_media_type == usb) { 773 774 if ((bkpinfo->backup_media_type == usb) && (bkpinfo->media_device)) { 802 775 mr_asprintf(tmp2, "--usb %s", bkpinfo->media_device); 803 776 } else { … … 808 781 if (write_one_liner_data_file(tmp, value)) { 809 782 res++; 810 log_msg(1, "%ld: Unable to write one-liner backup-media-type", 811 __LINE__); 783 log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__); 812 784 } 813 785 mr_free(value); … … 817 789 if (write_one_liner_data_file(tmp, bootldr_str)) { 818 790 res++; 819 log_msg(1, "%ld: Unable to write one-liner bootloader.name", 820 __LINE__); 791 log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__); 821 792 } 822 793 mr_free(bootldr_str); … … 865 836 } 866 837 867 estimated_total_noof_slices = 868 size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1; 869 /* add netfs stuff here? */838 estimated_total_noof_slices = size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1; 839 840 /* TODO: add netfs stuff here? */ 870 841 mr_asprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir); 871 842 if (system(command)) { … … 873 844 log_OS_error("Unable to make images directory"); 874 845 } 875 paranoid_free(command);846 mr_free(command); 876 847 log_msg(1, "lines_in_filelist = %ld", lines_in_filelist); 877 848 update_evalcall_form(3); … … 890 861 use_lzo_sz, // parameter #8 891 862 cd_recovery_sz, // parameter #9 892 bkpinfo->image_devs, // parameter #10863 (bkpinfo->image_devs == NULL) ? "\"\"" : bkpinfo->image_devs, // parameter #10 893 864 broken_bios_sz, // parameter #11 894 865 last_filelist_number, // parameter #12 (STRING) … … 900 871 bkpinfo->internal_tape_block_size, // parameter #18 (LONG) 901 872 bkpinfo->differential, // parameter #19 (INT) 902 use_gzip_sz); // parameter #20 (STRING) 873 use_gzip_sz, // parameter #19 (STRING) 874 use_lzma_sz, // parameter #20 (STRING) 875 value, // parameter #21 (STRING) 876 MONDO_LOGFILE); 903 877 904 878 mr_free(last_filelist_number); … … 906 880 mr_free(use_lzo_sz); 907 881 mr_free(use_gzip_sz); 882 mr_free(use_lzma_sz); 908 883 mr_free(use_star_sz); 909 884 mr_free(use_comp_sz); … … 913 888 mr_free(tape_size_sz); 914 889 890 /* This parameter is always the last one and optional */ 915 891 if (bkpinfo->nonbootable_backup) { 916 892 mr_strcat(command, " NONBOOTABLE"); … … 929 905 if (!res) { 930 906 log_to_screen("Boot+data disks were created OK"); 931 mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso", 932 bkpinfo->scratchdir, MINDI_CACHE); 907 mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso", bkpinfo->scratchdir, MINDI_CACHE); 933 908 log_msg(2, command); 934 909 run_program_and_log_output(command, FALSE); 935 paranoid_free(command);910 mr_free(command); 936 911 937 912 if (bkpinfo->nonbootable_backup) { 938 mr_asprintf(command, "cp -f %s/all.tar.gz %s/images", 939 bkpinfo->tmpdir, bkpinfo->scratchdir); 913 mr_asprintf(command, "cp -f %s/all.tar.gz %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir); 940 914 if (system(command)) { 941 paranoid_free(command);915 mr_free(command); 942 916 fatal_error("Unable to create temporary all tarball"); 943 917 } 944 paranoid_free(command);918 mr_free(command); 945 919 } 946 920 /* For USB we already have everything on the key */ … … 948 922 mr_asprintf(command, "rm -rf %s/images", bkpinfo->scratchdir); 949 923 run_program_and_log_output(command, FALSE); 950 paranoid_free(command);924 mr_free(command); 951 925 } else { 952 mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, 953 bkpinfo->tmpdir); 926 mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir); 954 927 if (system(tmp)) { 955 928 fatal_error("Cannot find all.tar.gz in tmpdir"); … … 966 939 mr_asprintf(command, "grep 'Fatal error' /var/log/mindi.log"); 967 940 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 968 paranoid_free(command);941 mr_free(command); 969 942 970 943 if (strlen(tmp) > 1) { … … 1017 990 void *create_afio_files_in_background(void *inbuf) 1018 991 { 1019 long int archiving_set_no ;1020 char *archiving_filelist_fname ;1021 char *archiving_afioball_fname ;992 long int archiving_set_no = 0L; 993 char *archiving_filelist_fname = NULL; 994 char *archiving_afioball_fname = NULL; 1022 995 char *curr_xattr_list_fname = NULL; 1023 char *curr_acl_list_fname ;1024 1025 char *tmp ;996 char *curr_acl_list_fname = NULL; 997 998 char *tmp = NULL; 1026 999 int res = 0, retval = 0; 1027 1000 int *p_archival_threads_running; … … 1031 1004 int this_thread_no = g_current_thread_no++; 1032 1005 1033 malloc_string(curr_xattr_list_fname);1034 malloc_string(curr_acl_list_fname);1035 malloc_string(archiving_filelist_fname);1036 malloc_string(archiving_afioball_fname);1037 malloc_string(tmp);1038 1006 p_last_set_archived = (int *) inbuf; 1039 1007 p_archival_threads_running = (int *) (inbuf + 4); … … 1041 1009 p_list_of_fileset_flags = (char *) (inbuf + 12); 1042 1010 1043 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, 1044 bkpinfo->tmpdir, 0L); 1045 for (archiving_set_no = 0L; does_file_exist(archiving_filelist_fname); 1046 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, 1047 bkpinfo->tmpdir, archiving_set_no)) { 1011 mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L); 1012 1013 while (does_file_exist(archiving_filelist_fname)) { 1048 1014 if (g_exiting) { 1015 mr_free(archiving_filelist_fname); 1049 1016 fatal_error("Execution run aborted (pthread)"); 1050 1017 } 1051 1018 if (archiving_set_no >= MAX_NOOF_SETS_HERE) { 1052 fatal_error1053 1019 mr_free(archiving_filelist_fname); 1020 fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please."); 1054 1021 } 1055 1022 if (!semaphore_p()) { 1056 1023 log_msg(3, "P sem failed (pid=%d)", (int) getpid()); 1024 mr_free(archiving_filelist_fname); 1057 1025 fatal_error("Cannot get semaphore P"); 1058 1026 } … … 1062 1030 *p_next_set_to_archive = *p_next_set_to_archive + 1; 1063 1031 if (!semaphore_v()) { 1032 mr_free(archiving_filelist_fname); 1064 1033 fatal_error("Cannot get semaphore V"); 1065 1034 } 1066 1035 1067 1036 /* backup this set of files */ 1068 sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ, 1069 bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix); 1070 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, 1071 bkpinfo->tmpdir, archiving_set_no); 1037 mr_asprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix); 1038 mr_free(archiving_filelist_fname); 1039 mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1072 1040 if (!does_file_exist(archiving_filelist_fname)) { 1073 log_msg(3, 1074 "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", 1075 FORTY_SPACES, getpid(), this_thread_no, 1076 archiving_set_no); 1041 log_msg(3, "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1042 mr_free(archiving_afioball_fname); 1077 1043 break; 1078 1044 } 1079 1045 1080 sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, 1081 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix); 1046 mr_asprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix); 1082 1047 if (does_file_exist(tmp)) { 1083 log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, 1084 getpid(), this_thread_no); 1048 log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no); 1085 1049 while (does_file_exist(tmp)) { 1086 1050 sleep(1); … … 1088 1052 log_msg(4, "[%d] - continuing", getpid()); 1089 1053 } 1090 1091 log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), 1092 this_thread_no, archiving_set_no); 1054 mr_free(tmp); 1055 1056 log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1057 1093 1058 if (g_getfattr) { 1094 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 1095 bkpinfo->tmpdir, archiving_set_no); 1059 mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1096 1060 get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname); 1061 mr_free(curr_xattr_list_fname); 1097 1062 } 1098 1063 if (g_getfacl) { 1099 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 1100 bkpinfo->tmpdir, archiving_set_no); 1064 mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1101 1065 get_acl_list(archiving_filelist_fname, curr_acl_list_fname); 1102 } 1103 1104 log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), 1105 this_thread_no, archiving_set_no); 1106 res = 1107 archive_this_fileset(archiving_filelist_fname, 1108 archiving_afioball_fname, 1109 archiving_set_no); 1066 mr_free(curr_acl_list_fname); 1067 } 1068 1069 log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1070 res = archive_this_fileset(archiving_filelist_fname, archiving_afioball_fname, archiving_set_no); 1071 mr_free(archiving_afioball_fname); 1072 1110 1073 retval += res; 1111 1074 1112 1075 if (res) { 1113 sprintf(tmp, 1114 "Errors occurred while archiving set %ld. Please review logs.", 1115 archiving_set_no); 1116 log_to_screen(tmp); 1117 } 1076 log_to_screen("Errors occurred while archiving set %ld. Please review logs.", archiving_set_no); 1077 } 1078 1118 1079 if (!semaphore_p()) { 1080 mr_free(archiving_filelist_fname); 1119 1081 fatal_error("Cannot get semaphore P"); 1120 1082 } … … 1127 1089 1128 1090 if (!semaphore_v()) { 1091 mr_free(archiving_filelist_fname); 1129 1092 fatal_error("Cannot get semaphore V"); 1130 1093 } 1131 log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), 1132 this_thread_no, archiving_set_no); 1094 log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1133 1095 archiving_set_no++; 1134 } 1096 1097 mr_free(archiving_filelist_fname); 1098 mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1099 } 1100 mr_free(archiving_filelist_fname); 1101 1135 1102 if (!semaphore_p()) { 1136 1103 fatal_error("Cannot get semaphore P"); … … 1140 1107 fatal_error("Cannot get semaphore V"); 1141 1108 } 1142 log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), 1143 this_thread_no); 1144 paranoid_free(archiving_filelist_fname); 1145 paranoid_free(archiving_afioball_fname); 1146 paranoid_free(curr_xattr_list_fname); 1147 paranoid_free(curr_acl_list_fname); 1148 paranoid_free(tmp); 1109 log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no); 1149 1110 pthread_exit(NULL); 1150 1111 } … … 1228 1189 1229 1190 /*@ buffers *********************************** */ 1230 char *command, *tmpfile, *data_disks_file; 1191 char *command = NULL; 1192 char *tmpfile = NULL; 1193 char *data_disks_file = NULL; 1231 1194 1232 1195 assert(bkpinfo != NULL); 1233 malloc_string(command); 1234 malloc_string(tmpfile); 1235 malloc_string(data_disks_file); 1236 sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir); 1237 1238 snprintf(g_serial_string, MAX_STR_LEN - 8, "%s", 1239 call_program_and_get_last_line_of_output("dd \ 1240 if=/dev/urandom bs=16 count=1 2> /dev/null | \ 1241 hexdump | tr -s ' ' '0' | head -n1")); 1196 mr_asprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir); 1197 1198 snprintf(g_serial_string, MAX_STR_LEN - 8, "%s", call_program_and_get_last_line_of_output("dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump | tr -s ' ' '0' | head -n1")); 1242 1199 strip_spaces(g_serial_string); 1243 1200 strcat(g_serial_string, "...word."); … … 1245 1202 assert(strlen(g_serial_string) < MAX_STR_LEN); 1246 1203 1247 sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);1204 mr_asprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir); 1248 1205 if (write_one_liner_data_file(tmpfile, g_serial_string)) { 1249 1206 log_msg(1, "%ld: Failed to write serial string", __LINE__); 1250 1207 } 1208 mr_free(tmpfile); 1251 1209 1252 1210 mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data"); … … 1269 1227 } 1270 1228 } 1271 1272 sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, 1273 1229 mr_free(data_disks_file); 1230 1231 mr_asprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix); 1274 1232 paranoid_system(command); 1233 mr_free(command); 1234 1275 1235 wipe_archives(bkpinfo->scratchdir); 1276 1236 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1281 1241 BLK_START_OF_BACKUP); 1282 1242 } 1283 paranoid_free(command);1284 paranoid_free(tmpfile);1285 paranoid_free(data_disks_file);1286 1243 return (retval); 1287 1244 } … … 1356 1313 1357 1314 /*@ buffers ********************************************** */ 1358 char *storing_filelist_fname ;1359 char *storing_afioball_fname ;1315 char *storing_filelist_fname = NULL; 1316 char *storing_afioball_fname = NULL; 1360 1317 char *tmp = NULL; 1361 1318 char *media_usage_comment = NULL; … … 1374 1331 assert(bkpinfo != NULL); 1375 1332 malloc_string(result_str); 1376 malloc_string(curr_xattr_list_fname); 1377 malloc_string(curr_acl_list_fname); 1378 malloc_string(storing_filelist_fname); 1379 malloc_string(storing_afioball_fname); 1380 transfer_block = 1381 malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); 1382 memset((void *) transfer_block, 0, 1383 sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); 1333 transfer_block = malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); 1334 memset((void *) transfer_block, 0, sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64); 1384 1335 p_last_set_archived = (int *) transfer_block; 1385 1336 p_archival_threads_running = (int *) (transfer_block + 4); 1386 1337 p_next_set_to_archive = (int *) (transfer_block + 8); 1387 1338 p_list_of_fileset_flags = (char *) (transfer_block + 12); 1388 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), 1389 (void *) bkpinfo, sizeof(struct s_bkpinfo)); 1339 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), (void *) bkpinfo, sizeof(struct s_bkpinfo)); 1390 1340 pvp = &vp; 1391 1341 vp = (void *) result_str; … … 1399 1349 "Please wait. This may take a couple of hours.", 1400 1350 "Working...", 1401 get_last_filelist_number() + 1);1351 (long)get_last_filelist_number() + 1L); 1402 1352 1403 1353 log_msg(5, "We're gonna party like it's your birthday."); … … 1438 1388 if (!get_bit_N_of_array 1439 1389 (p_list_of_fileset_flags, storing_set_no)) { 1440 misc_counter_that_is_not_important = 1441 (misc_counter_that_is_not_important + 1) % 5; 1390 misc_counter_that_is_not_important = (misc_counter_that_is_not_important + 1) % 5; 1442 1391 /* BCO the media_usage_comment is not really initialized there ! 1443 1392 if (!misc_counter_that_is_not_important) { … … 1446 1395 */ 1447 1396 sleep(1); 1448 } else 1397 } else { 1449 1398 // store set N 1450 { 1451 sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ, 1452 bkpinfo->tmpdir, storing_set_no); 1453 sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, 1454 bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix); 1399 mr_asprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no); 1400 mr_asprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix); 1455 1401 if (g_getfattr) { 1456 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 1457 bkpinfo->tmpdir, storing_set_no); 1402 mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no); 1458 1403 } 1459 1404 if (g_getfacl) { 1460 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 1461 bkpinfo->tmpdir, storing_set_no); 1405 mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no); 1462 1406 } 1463 1407 … … 1470 1414 sleep(5); 1471 1415 } 1472 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());1473 1416 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ 1474 1417 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1475 1418 register_in_tape_catalog(fileset, storing_set_no, -1, 1476 1419 storing_afioball_fname); 1477 maintain_collection_of_recent_archives(bkpinfo->tmpdir, 1478 storing_afioball_fname); 1420 maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname); 1479 1421 log_it("Writing EXAT files"); 1480 1422 res += … … 1510 1452 retval += res; 1511 1453 g_current_progress++; 1454 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment()); 1512 1455 update_progress_form(media_usage_comment); 1513 1456 mr_free(media_usage_comment); 1514 1457 if (res) { 1515 mr_asprintf(tmp, "Failed to add archive %ld's files to CD dir\n", 1516 storing_set_no); 1517 log_to_screen(tmp); 1518 paranoid_free(tmp); 1519 fatal_error 1520 ("Is your hard disk full? If not, please send the author the logfile."); 1458 log_to_screen("Failed to add archive %ld's files to CD dir\n", storing_set_no); 1459 fatal_error("Is your hard disk full? If not, please send the author the logfile."); 1521 1460 } 1522 1461 storing_set_no++; 1523 1462 // sleep(2); 1463 if (g_getfacl) { 1464 mr_free(curr_acl_list_fname); 1465 } 1466 if (g_getfattr) { 1467 mr_free(curr_xattr_list_fname); 1468 } 1469 mr_free(storing_filelist_fname); 1470 mr_free(storing_afioball_fname); 1524 1471 } 1525 1472 } … … 1540 1487 } 1541 1488 log_to_screen(tmp); 1542 paranoid_free(tmp);1489 mr_free(tmp); 1543 1490 1544 1491 paranoid_free(transfer_block); 1545 1492 paranoid_free(result_str); 1546 paranoid_free(storing_filelist_fname);1547 paranoid_free(storing_afioball_fname);1548 paranoid_free(curr_xattr_list_fname);1549 paranoid_free(curr_acl_list_fname);1550 1493 return (retval); 1551 1494 } … … 1598 1541 mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1599 1542 run_program_and_log_output(tmp, FALSE); 1600 paranoid_free(tmp);1543 mr_free(tmp); 1601 1544 if (chdir(bkpinfo->scratchdir)) { 1602 1545 // FIXME … … 1608 1551 log_msg(1, message_to_screen); 1609 1552 1610 mr_asprintf(tmp1, "%s1", bkpinfo->media_device); 1553 if (bkpinfo->media_device) { 1554 mr_asprintf(tmp1, "%s1", bkpinfo->media_device); 1555 } else { 1556 mr_asprintf(tmp1, ""); 1557 } 1611 1558 if (is_this_device_mounted(tmp1)) { 1612 1559 log_msg(1, "USB device mounted. Remounting it at the right place"); 1613 1560 mr_asprintf(tmp, "umount %s", tmp1); 1614 1561 run_program_and_log_output(tmp, FALSE); 1615 paranoid_free(tmp);1616 } 1617 paranoid_free(tmp1);1562 mr_free(tmp); 1563 } 1564 mr_free(tmp1); 1618 1565 1619 1566 log_msg(1, "Mounting USB device."); … … 1621 1568 mr_asprintf(tmp, "mkdir -p %s", tmp1); 1622 1569 run_program_and_log_output(tmp, FALSE); 1623 paranoid_free(tmp); 1570 mr_free(tmp); 1571 1624 1572 1625 1573 /* Mindi always create one single parition on the USB dev */ 1626 1574 mr_asprintf(tmp, "mount %s1 %s", bkpinfo->media_device, tmp1); 1627 1575 run_program_and_log_output(tmp, FALSE); 1628 paranoid_free(tmp);1576 mr_free(tmp); 1629 1577 1630 1578 if (bkpinfo->nonbootable_backup) { … … 1642 1590 } 1643 1591 log_to_screen(result_sz); 1644 paranoid_free(result_sz);1645 paranoid_free(tmp);1592 mr_free(result_sz); 1593 mr_free(tmp); 1646 1594 retval += res; 1647 1595 … … 1649 1597 mr_asprintf(tmp,"mkdir %s/archive", bkpinfo->scratchdir); 1650 1598 run_program_and_log_output(tmp, FALSE); 1651 paranoid_free(tmp);1599 mr_free(tmp); 1652 1600 } 1653 1601 paranoid_free(message_to_screen); … … 1657 1605 mr_asprintf(tmp, "umount %s1", bkpinfo->media_device); 1658 1606 run_program_and_log_output(tmp, FALSE); 1659 paranoid_free(tmp);1607 mr_free(tmp); 1660 1608 } 1661 1609 … … 1695 1643 1696 1644 /*@ buffers ****************************************** */ 1697 char *tmp; 1645 char *tmp = NULL; 1646 char *tmp2 = NULL; 1698 1647 char *old_pwd; 1699 1648 char *result_sz = NULL; 1700 1649 char *message_to_screen = NULL; 1701 1650 char *sz_blank_disk = NULL; 1702 char *fnam; 1703 char *tmp2; 1704 char *tmp3; 1651 char *fnam = NULL; 1652 char *tmp3 = NULL; 1705 1653 char *isofs_cmd = NULL; 1706 1654 char *full_isofs_cmd = NULL; … … 1710 1658 malloc_string(old_pwd); 1711 1659 malloc_string(fnam); 1712 tmp = malloc(1200);1713 tmp2 = malloc(1200);1714 tmp3 = malloc(1200);1715 1660 assert(bkpinfo != NULL); 1716 1661 assert_string_is_neither_NULL_nor_zerolength(destfile); 1717 1662 1718 sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir); 1719 sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir); 1663 /* Copy the files needed by isolinux in the right dir */ 1664 mr_asprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir); 1665 mr_asprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir); 1720 1666 if (does_file_exist(tmp)) { 1721 sprintf(tmp3, "cp -f %s %s", tmp, tmp2);1667 mr_asprintf(tmp3, "cp -f %s %s", tmp, tmp2); 1722 1668 paranoid_system(tmp3); 1669 mr_free(tmp3); 1723 1670 } 1724 1671 if (!does_file_exist(tmp) && does_file_exist(tmp2)) { 1725 sprintf(tmp3, "cp -f %s %s", tmp2, tmp);1672 mr_asprintf(tmp3, "cp -f %s %s", tmp2, tmp); 1726 1673 paranoid_system(tmp3); 1727 } 1728 free(tmp2); 1729 free(tmp3); 1730 tmp2 = NULL; 1731 tmp3 = NULL; 1674 mr_free(tmp3); 1675 } 1676 mr_free(tmp2); 1677 mr_free(tmp3); 1732 1678 if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) { 1733 1679 popup_and_OK("Please insert new media and press Enter."); 1734 1680 } 1735 1681 1736 log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", 1737 bkpinfo->scratchdir, destfile); 1682 log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", bkpinfo->scratchdir, destfile); 1738 1683 tmp2 = getcwd(old_pwd, MAX_STR_LEN - 1); 1739 sprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1684 if (! tmp2) { 1685 //FIXME 1686 } 1687 mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1740 1688 run_program_and_log_output(tmp, FALSE); 1689 mr_free(tmp); 1690 1741 1691 if (chdir(bkpinfo->scratchdir)) { 1742 1692 // FIXME … … 1744 1694 1745 1695 if (bkpinfo->call_before_iso[0] != '\0') { 1746 mr_asprintf(message_to_screen, "Running pre-ISO call for CD#%d", 1747 g_current_media_number); 1748 res = 1749 eval_call_to_make_ISO(bkpinfo->call_before_iso, 1750 destfile, g_current_media_number, 1751 MONDO_LOGFILE, message_to_screen); 1696 mr_asprintf(message_to_screen, "Running pre-ISO call for CD#%d", g_current_media_number); 1697 res = eval_call_to_make_ISO(bkpinfo->call_before_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1752 1698 if (res) { 1753 1699 mr_strcat(message_to_screen, "...failed"); … … 1763 1709 if (bkpinfo->call_make_iso[0] != '\0') { 1764 1710 log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso); 1765 sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);1766 1711 mds = media_descriptor_string(bkpinfo->backup_media_type); 1767 1712 mr_asprintf(message_to_screen, "Making an ISO (%s #%d)", mds, g_current_media_number); … … 1774 1719 } else { 1775 1720 res = 1776 eval_call_to_make_ISO(bkpinfo->call_make_iso, 1777 bkpinfo->scratchdir, 1778 g_current_media_number, 1779 MONDO_LOGFILE, message_to_screen); 1721 eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1780 1722 if (res) { 1781 1723 log_to_screen("%s...failed to write", message_to_screen); 1782 1724 } else { 1783 1725 log_to_screen("%s...OK", message_to_screen); 1784 sprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);1726 mr_asprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE); 1785 1727 if (!run_program_and_log_output(tmp, 1)) { 1786 1728 log_to_screen 1787 1729 ("Despite nonfatal errors, growisofs confirms the write was successful."); 1788 1730 } 1731 mr_free(tmp); 1789 1732 } 1790 1733 retval += res; 1791 1734 #ifdef DVDRWFORMAT 1792 sprintf(tmp, 1793 "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", 1794 MONDO_LOGFILE); 1735 mr_asprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE); 1795 1736 if (g_backup_media_type == dvd 1796 1737 && (res || !run_program_and_log_output(tmp, 1))) { … … 1800 1741 /* reset error counter before trying to blank DVD */ 1801 1742 retval -= res; 1802 paranoid_system("sync");1743 sync(); 1803 1744 pause_for_N_seconds(5, "Letting DVD drive settle"); 1804 1745 … … 1810 1751 } 1811 1752 pause_for_N_seconds(5, "Letting DVD drive settle"); 1812 mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device); 1753 if (bkpinfo->media_device) { 1754 mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device); 1755 } else { 1756 mr_asprintf(sz_blank_disk, "dvd+rw-format"); 1757 } 1813 1758 log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk); 1814 res = 1815 run_external_binary_with_percentage_indicator_NEW 1816 ("Blanking DVD disk", sz_blank_disk); 1759 res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk); 1817 1760 if (res) { 1818 log_to_screen 1819 ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath..."); 1820 pause_for_N_seconds(5, 1821 "Letting DVD drive settle... and trying again."); 1822 res = 1823 run_external_binary_with_percentage_indicator_NEW 1824 ("Blanking DVD disk", sz_blank_disk); 1761 log_to_screen("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath..."); 1762 pause_for_N_seconds(5, "Letting DVD drive settle... and trying again."); 1763 res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk); 1825 1764 if (res) { 1826 1765 log_to_screen("Format failed a second time."); … … 1838 1777 } 1839 1778 pause_for_N_seconds(5, "Letting DVD drive settle"); 1840 res = 1841 eval_call_to_make_ISO(bkpinfo->call_make_iso, 1842 bkpinfo->scratchdir, 1843 g_current_media_number, 1844 MONDO_LOGFILE, 1845 message_to_screen); 1779 res = eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1846 1780 retval += res; 1847 1781 if (!bkpinfo->please_dont_eject) { … … 1856 1790 } 1857 1791 } 1792 mr_free(tmp); 1858 1793 #endif 1859 1794 if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) { … … 1876 1811 log_msg(1, "Making nonbootable backup"); 1877 1812 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS); 1878 res = eval_call_to_make_ISO(full_isofs_cmd, 1879 destfile, g_current_media_number, 1880 MONDO_LOGFILE, message_to_screen); 1813 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1881 1814 mr_free(full_isofs_cmd); 1882 1815 } else { … … 1888 1821 1889 1822 1890 log_msg(1, "make_cd_use_lilo is actually %d", 1891 bkpinfo->make_cd_use_lilo); 1823 log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo); 1892 1824 if (bkpinfo->make_cd_use_lilo) { 1893 1825 log_msg(1, "make_cd_use_lilo = TRUE"); … … 1895 1827 log_msg(1, "IA64 --> elilo"); 1896 1828 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_ELILO); 1897 res = eval_call_to_make_ISO(full_isofs_cmd, 1898 destfile, 1899 g_current_media_number, 1900 MONDO_LOGFILE, 1901 message_to_screen); 1829 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1902 1830 mr_free(full_isofs_cmd); 1903 1831 #else 1904 1832 log_msg(1, "Non-ia64 --> lilo"); 1905 1833 mr_asprintf(full_isofs_cmd, "%s%s-b images/mindi-bootroot.2880.img -c boot.cat -o '_ISO_' -J -V _CD#_ .",isofs_cmd,MONDO_MKISOFS); 1906 res = 1907 // FIXME: fixed boot size probably wrong. lilo to be removed 1908 eval_call_to_make_ISO(full_isofs_cmd, 1909 destfile, g_current_media_number, 1910 MONDO_LOGFILE, 1911 message_to_screen); 1834 // FIXME: fixed boot size probably wrong. lilo to be removed 1835 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1912 1836 mr_free(full_isofs_cmd); 1913 1837 #endif … … 1916 1840 log_msg(1, "Isolinux"); 1917 1841 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_SYSLINUX); 1918 res = 1919 eval_call_to_make_ISO(full_isofs_cmd, 1920 destfile, g_current_media_number, 1921 MONDO_LOGFILE, 1922 message_to_screen); 1842 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1923 1843 mr_free(full_isofs_cmd); 1924 1844 } … … 1940 1860 || bkpinfo->backup_media_type == cdrw) { 1941 1861 if (is_this_device_mounted(bkpinfo->media_device)) { 1942 log_msg(2, 1943 "Warning - %s mounted. I'm unmounting it before I burn to it.", 1944 bkpinfo->media_device); 1945 sprintf(tmp, "umount %s", bkpinfo->media_device); 1862 log_msg(2, "Warning - %s mounted. I'm unmounting it before I burn to it.", bkpinfo->media_device); 1863 mr_asprintf(tmp, "umount %s", bkpinfo->media_device); 1946 1864 run_program_and_log_output(tmp, FALSE); 1865 mr_free(tmp); 1947 1866 } 1948 1867 } … … 1954 1873 mr_free(mds); 1955 1874 pause_and_ask_for_cdr(2, &cd_is_mountable); 1956 res = 1957 eval_call_to_make_ISO(bkpinfo->call_burn_iso, 1958 destfile, g_current_media_number, 1959 MONDO_LOGFILE, message_to_screen); 1875 res = eval_call_to_make_ISO(bkpinfo->call_burn_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1960 1876 if (res) { 1961 1877 mr_strcat(message_to_screen, "...failed"); … … 1973 1889 mr_asprintf(message_to_screen, "Running post-ISO call (%s #%d)", mds, g_current_media_number); 1974 1890 mr_free(mds); 1975 res = 1976 eval_call_to_make_ISO(bkpinfo->call_after_iso, 1977 destfile, g_current_media_number, 1978 MONDO_LOGFILE, message_to_screen); 1891 res = eval_call_to_make_ISO(bkpinfo->call_after_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1979 1892 if (res) { 1980 1893 mr_strcat(message_to_screen, "...failed"); … … 2044 1957 2045 1958 /*@ pointers ******************************************* */ 2046 FILE *fin ;1959 FILE *fin = NULL; 2047 1960 char *p; 2048 1961 char *q; … … 2050 1963 /*@ buffers ******************************************** */ 2051 1964 char *tmp = NULL; 2052 char *bigfile_fname ;1965 char *bigfile_fname = NULL; 2053 1966 char *sz_devfile = NULL; 2054 1967 char *ntfsprog_fifo = NULL; … … 2086 1999 log_to_screen(tmp); 2087 2000 noof_biggie_files = count_lines_in_file(biggielist_fname); 2088 open_progress_form("Backing up big files", tmp, 2089 "Please wait. This may take some time.", "", 2090 estimated_total_noof_slices); 2091 paranoid_free(tmp); 2001 open_progress_form("Backing up big files", tmp, "Please wait. This may take some time.", "", estimated_total_noof_slices); 2002 mr_free(tmp); 2092 2003 2093 2004 if (!(fin = fopen(biggielist_fname, "r"))) { … … 2121 2032 log_msg(2, "bigfile_fname = %s", bigfile_fname); 2122 2033 use_ntfsprog = FALSE; 2123 if (!strncmp(bigfile_fname, "/dev/", 5) 2124 && is_dev_an_NTFS_dev(bigfile_fname)) { 2034 if (!strncmp(bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname)) { 2125 2035 use_ntfsprog = TRUE; 2126 log_msg(2, 2127 "Calling ntfsclone in background because %s is an NTFS partition", 2128 bigfile_fname); 2129 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, 2130 (int) (random() % 32768), 2131 (int) (random() % 32768)); 2036 log_msg(2, "Calling ntfsclone in background because %s is an NTFS partition", bigfile_fname); 2037 mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768)); 2132 2038 mkfifo(sz_devfile, 0x770); 2133 2039 ntfsprog_fifo = sz_devfile; … … 2137 2043 fatal_error("Fork failure"); 2138 2044 case 0: 2139 log_msg(2, 2140 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", 2141 bigfile_fname, sz_devfile); 2045 log_msg(2, "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", bigfile_fname, sz_devfile); 2142 2046 res = feed_into_ntfsprog(bigfile_fname, sz_devfile); 2143 2047 /* BCO/BERLIOS Does the child need to unalocate memory as well ? 2144 paranoid_free(bigfile_fname);2048 mr_free(bigfile_fname); 2145 2049 mr_free(sz_devfile); 2146 2050 */ … … 2148 2052 break; 2149 2053 default: 2150 log_msg(2, 2151 "feed_into_ntfsprog() called in background --- pid=%ld", 2152 (long int) (pid)); 2054 log_msg(2, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid)); 2153 2055 } 2154 2056 } … … 2160 2062 // Whether partition or biggiefile, just do your thang :-) 2161 2063 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2162 write_header_block_to_stream(biggie_fsize, bigfile_fname, 2163 use_ntfsprog ? 2164 BLK_START_A_PIHBIGGIE : 2165 BLK_START_A_NORMBIGGIE); 2166 } 2167 res = 2168 slice_up_file_etc(bigfile_fname, 2169 ntfsprog_fifo, biggie_file_number, 2170 noof_biggie_files, use_ntfsprog); 2064 write_header_block_to_stream(biggie_fsize, bigfile_fname, use_ntfsprog ? BLK_START_A_PIHBIGGIE : BLK_START_A_NORMBIGGIE); 2065 } 2066 res = slice_up_file_etc(bigfile_fname, ntfsprog_fifo, biggie_file_number, noof_biggie_files, use_ntfsprog); 2171 2067 2172 2068 /* Free it here as ntfsprog_fifo is not used anymore */ … … 2197 2093 } 2198 2094 } 2199 #ifndef _XWIN2200 2095 if (!g_text_mode) { 2201 2096 newtDrawRootText(0, g_noof_rows - 2, tmp); 2202 2097 newtRefresh(); 2203 2098 } 2204 #endif 2205 paranoid_free(tmp); 2206 } 2099 mr_free(tmp); 2100 } 2101 mr_free(bigfile_fname); 2102 2207 2103 log_msg(1, "Finished backing up bigfiles"); 2208 2104 log_msg(1, "estimated slices = %ld; actual slices = %ld", … … 2210 2106 close_progress_form(); 2211 2107 paranoid_fclose(fin); 2212 paranoid_free(bigfile_fname);2213 2108 return (retval); 2214 2109 } … … 2271 2166 retval += res; 2272 2167 if (res) { 2273 mr_asprintf(tmp, "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no); 2274 log_to_screen(tmp); 2275 mr_free(tmp); 2276 } 2277 2278 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment()); 2168 log_to_screen("Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no); 2169 } 2279 2170 2280 2171 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ … … 2319 2210 retval += res; 2320 2211 g_current_progress++; 2212 2213 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment()); 2321 2214 update_progress_form(media_usage_comment); 2322 2215 mr_free(media_usage_comment); 2323 2216 2324 2217 if (res) { 2325 mr_asprintf(tmp, "Failed to add archive %ld's files to CD dir\n", curr_set_no); 2326 log_to_screen(tmp); 2327 mr_free(tmp); 2328 fatal_error 2329 ("Is your hard disk is full? If not, please send the author the logfile."); 2218 log_to_screen("Failed to add archive %ld's files to CD dir\n", curr_set_no); 2219 fatal_error("Is your hard disk is full? If not, please send the author the logfile."); 2330 2220 } 2331 2221 mr_free(curr_filelist_fname); … … 2428 2318 } 2429 2319 2430 mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, 2431 biggielist); 2320 mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist); 2432 2321 paranoid_system(command); 2433 2322 mr_free(command); … … 2443 2332 if (g_getfattr) { 2444 2333 get_fattr_list(biggielist, xattr_fname); 2445 mr_asprintf(command, "cp %s %s/archives/", xattr_fname, 2446 bkpinfo->scratchdir); 2334 mr_asprintf(command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir); 2447 2335 paranoid_system(command); 2448 2336 mr_free(command); … … 2733 2621 /*@ buffers ********************************************* */ 2734 2622 char *tmp = NULL; 2735 char *cdrom_dev ;2736 char *cdrw_dev ;2623 char *cdrom_dev = NULL; 2624 char *cdrw_dev = NULL; 2737 2625 char *our_serial_str = NULL; 2738 2626 bool ok_go_ahead_burn_it; … … 2740 2628 int attempt_to_mount_returned_this = 999; 2741 2629 char *mtpt = NULL; 2742 char *szcdno ;2743 char *szserfname ;2744 char *szunmount ;2630 char *szcdno = NULL; 2631 char *szserfname = NULL; 2632 char *szunmount = NULL; 2745 2633 char *mds = NULL; 2746 2634 2747 2635 malloc_string(cdrom_dev); 2748 2636 malloc_string(cdrw_dev); 2749 malloc_string(szcdno);2750 malloc_string(szserfname);2751 malloc_string(szunmount);2752 malloc_string(mtpt);2753 2637 2754 2638 mds = media_descriptor_string(g_backup_media_type); 2755 mr_asprintf(tmp,"I am about to burn %s #%d", mds, g_current_media_number);2639 log_to_screen("I am about to burn %s #%d", mds, g_current_media_number); 2756 2640 mr_free(mds); 2757 log_to_screen(tmp);2758 mr_free(tmp);2759 2641 if (g_current_media_number < ask_for_one_if_more_than_this) { 2760 2642 return; 2761 2643 } 2762 2644 log_to_screen("Scanning CD-ROM drive..."); 2763 sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);2645 mr_asprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir); 2764 2646 make_hole_for_dir(mtpt); 2765 2647 … … 2767 2649 ok_go_ahead_burn_it = TRUE; 2768 2650 if (!find_cdrom_device(cdrom_dev, FALSE)) { 2769 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird2770 2771 2772 */2651 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird 2652 log_msg(2, "paafcd: Retracting CD-ROM drive if possible" ); 2653 retract_CD_tray_and_defeat_autorun(); 2654 */ 2773 2655 mr_asprintf(tmp, "umount %s", cdrom_dev); 2774 2656 run_program_and_log_output(tmp, 1); 2775 sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);2776 sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);2777 sprintf(szunmount, "umount %s", mtpt);2657 mr_asprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt); 2658 mr_asprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt); 2659 mr_asprintf(szunmount, "umount %s", mtpt); 2778 2660 cd_number = -1; 2779 2661 mr_asprintf(tmp, "mount %s %s", cdrom_dev, mtpt); … … 2781 2663 attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1); 2782 2664 mr_free(tmp); 2665 2783 2666 if (attempt_to_mount_returned_this) { 2784 2667 log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt); 2785 2668 log_to_screen("If there's a CD/DVD in the drive, it's blank."); 2786 /* 2787 if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) 2788 { 2789 ok_go_ahead_burn_it = FALSE; 2790 log_to_screen("There isn't a writable CD/DVD in the drive."); 2791 } 2792 else 2793 { 2794 log_to_screen("Confirmed. There is a blank CD/DVD in the drive."); 2795 } 2796 */ 2797 } else if (!does_file_exist(szcdno) 2798 || !does_file_exist(szserfname)) { 2669 } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) { 2799 2670 mds = media_descriptor_string(g_backup_media_type); 2800 log_to_screen 2801 ("%s has data on it but it's probably not a Mondo CD.", mds); 2671 log_to_screen("%s has data on it but it's probably not a Mondo CD.", mds); 2802 2672 mr_free(mds); 2803 2673 } else { … … 2809 2679 mr_asprintf(tmp, "cat %s 2> /dev/null", szserfname); 2810 2680 mr_free(our_serial_str); 2811 mr_asprintf(our_serial_str, "%s", 2812 call_program_and_get_last_line_of_output(tmp)); 2681 mr_asprintf(our_serial_str, "%s", call_program_and_get_last_line_of_output(tmp)); 2813 2682 mr_free(tmp); 2814 2683 // FIXME - should be able to use last_line_of_file(), surely? 2815 2684 } 2685 mr_free(szcdno); 2686 mr_free(szserfname); 2687 2816 2688 run_program_and_log_output(szunmount, 1); 2689 mr_free(szunmount); 2690 2817 2691 log_msg(2, "paafcd: cd_number = %d", cd_number); 2818 log_msg(2, "our serial str = %s; g_serial_string = %s", 2819 our_serial_str, g_serial_string); 2692 log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string); 2820 2693 if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) { 2821 2694 mds = media_descriptor_string(g_backup_media_type); … … 2849 2722 } 2850 2723 mds = media_descriptor_string(g_backup_media_type); 2851 mr_asprintf(tmp, "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.", 2852 mds, g_current_media_number, mds); 2724 mr_asprintf(tmp, "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.", mds, g_current_media_number, mds); 2853 2725 mr_free(mds); 2854 2726 … … 2861 2733 2862 2734 mds = media_descriptor_string(g_backup_media_type); 2863 log_msg(2, 2864 "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds); 2735 log_msg(2, "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds); 2865 2736 2866 2737 log_to_screen("Proceeding w/ %s in drive.", mds); … … 2869 2740 paranoid_free(cdrom_dev); 2870 2741 paranoid_free(cdrw_dev); 2871 paranoid_free(mtpt); 2872 paranoid_free(szcdno); 2873 paranoid_free(szserfname); 2874 paranoid_free(szunmount); 2742 mr_free(mtpt); 2875 2743 if (pmountable) { 2876 2744 if (attempt_to_mount_returned_this) { … … 2882 2750 2883 2751 } 2884 2885 2886 2887 2888 2889 2890 2752 2891 2753 … … 2917 2779 2918 2780 /* @} - end of utilityGroup */ 2919 2920 2921 2922 2923 2924 2925 2781 2926 2782 … … 2945 2801 */ 2946 2802 int 2947 slice_up_file_etc(char *biggie_filename, 2948 char *ntfsprog_fifo, long biggie_file_number, 2949 long noof_biggie_files, bool use_ntfsprog) 2950 { 2803 slice_up_file_etc(char *biggie_filename, char *ntfsprog_fifo, long biggie_file_number, long noof_biggie_files, bool use_ntfsprog) { 2951 2804 2952 2805 /*@ buffers ************************************************** */ 2953 2806 char *tmp = NULL; 2954 char *checksum_line, *command; 2955 char *tempblock; 2807 char *checksum_line = NULL; 2808 char *command = NULL; 2809 char *tempblock = NULL; 2956 2810 char *curr_slice_fname_uncompressed = NULL; 2957 2811 char *curr_slice_fname_compressed = NULL; 2958 2812 char *file_to_archive = NULL; 2959 char *file_to_openin ;2813 char *file_to_openin = NULL; 2960 2814 /*@ pointers ************************************************** */ 2961 char *pB; 2962 FILE *fin = NULL, *fout = NULL; 2815 char *pB = NULL; 2816 FILE *fin = NULL; 2817 FILE *fout = NULL; 2963 2818 2964 2819 /*@ bool ****************************************************** */ … … 2966 2821 2967 2822 /*@ long ****************************************************** */ 2968 size_t blksize = 0; 2969 long slice_num = 0; 2970 long i; 2971 long optimal_set_size; 2972 bool should_I_compress_slices; 2823 size_t blksize = (size_t)0; 2824 long slice_num = 0L; 2825 long i = 0L; 2826 bool should_I_compress_slices = TRUE; 2973 2827 char *suffix = NULL; // for compressed slices 2974 2828 … … 2983 2837 /*@ structures ************************************************** */ 2984 2838 struct s_filename_and_lstat_info biggiestruct; 2985 // struct stat statbuf;2986 2839 2987 2840 assert(bkpinfo != NULL); 2988 2841 assert_string_is_neither_NULL_nor_zerolength(biggie_filename); 2989 malloc_string(checksum_line);2990 2842 2991 2843 biggiestruct.for_backward_compatibility = '\n'; 2992 2844 biggiestruct.use_ntfsprog = use_ntfsprog; 2993 optimal_set_size = bkpinfo->optimal_set_size; 2994 if (is_this_file_compressed(biggie_filename) 2995 || bkpinfo->compression_level == 0) { 2845 if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0) { 2996 2846 mr_asprintf(suffix, "%s", ""); 2997 // log_it("%s is indeed compressed :-)", filename);2998 2847 should_I_compress_slices = FALSE; 2999 2848 } else { … … 3002 2851 } 3003 2852 3004 if ( optimal_set_size < 999) {2853 if (bkpinfo->optimal_set_size < 999L) { 3005 2854 fatal_error("bkpinfo->optimal_set_size is insanely small"); 3006 2855 } 2856 3007 2857 if (ntfsprog_fifo) { 3008 2858 file_to_openin = ntfsprog_fifo; 3009 strcpy(checksum_line, "IGNORE"); 3010 log_msg(2, 3011 "Not calculating checksum for %s: it would take too long", 3012 biggie_filename); 2859 mr_asprintf(checksum_line, "IGNORE"); 2860 log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename); 3013 2861 if ( !find_home_of_exe("ntfsresize")) { 3014 2862 fatal_error("ntfsresize not found"); … … 3020 2868 log_it("res of it = %s", tmp); 3021 2869 totallength = (off_t)atoll(tmp); 3022 paranoid_free(tmp);2870 mr_free(tmp); 3023 2871 } else { 3024 2872 file_to_openin = biggie_filename; … … 3034 2882 } 3035 2883 mr_free(command); 3036 tmp = fgets(checksum_line, MAX_STR_LEN, fin);2884 mr_getline(checksum_line, fin); 3037 2885 pclose(fin); 3038 2886 totallength = length_of_file (biggie_filename); … … 3048 2896 } 3049 2897 strcpy(biggiestruct.checksum, checksum_line); 2898 mr_free(checksum_line); 3050 2899 3051 2900 mr_asprintf(tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "")); … … 3053 2902 if (fout == NULL) { 3054 2903 log_msg(1, "Unable to open and write to %s\n", tmp); 3055 paranoid_free(tmp);2904 mr_free(tmp); 3056 2905 mr_free(suffix); 3057 2906 return (1); 3058 2907 } 3059 paranoid_free(tmp);2908 mr_free(tmp); 3060 2909 3061 2910 res = fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout); … … 3063 2912 paranoid_fclose(fout); 3064 2913 } 3065 log_msg(1, "Opening in %s; slicing it and writing to CD/tape", 3066 file_to_openin); 2914 log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin); 3067 2915 if (!(fin = fopen(file_to_openin, "r"))) { 3068 2916 log_OS_error("Unable to openin biggie_filename"); 3069 mr_asprintf(tmp, "Cannot archive bigfile '%s': not found", biggie_filename); 3070 log_to_screen(tmp); 3071 paranoid_free(tmp); 3072 3073 paranoid_free(checksum_line); 2917 log_to_screen("Cannot archive bigfile '%s': not found", biggie_filename); 2918 3074 2919 mr_free(suffix); 3075 2920 return (1); … … 3094 2939 mr_asprintf(tmp, "%s", percent_media_full_comment()); 3095 2940 update_progress_form(tmp); 3096 paranoid_free(tmp);2941 mr_free(tmp); 3097 2942 3098 2943 if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) { … … 3101 2946 return (1); 3102 2947 } 3103 if ((i == bkpinfo->optimal_set_size / 256) 3104 && (totalread < 1.1 * totallength)) { 3105 for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) { 2948 if ((i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength)) { 2949 for (i = 0L; i < bkpinfo->optimal_set_size / 256; i++) { 3106 2950 blksize = fread(tempblock, 1, 256 * 1024, fin); 3107 2951 if (blksize > 0) { … … 3112 2956 } 3113 2957 } 2958 mr_free(tempblock); 3114 2959 } else { 3115 i = 0 ;2960 i = 0L; 3116 2961 } 3117 2962 paranoid_fclose(fout); 3118 if (i > 0 ) // length_of_file (curr_slice_fname_uncompressed)2963 if (i > 0L) // length_of_file (curr_slice_fname_uncompressed) 3119 2964 { 3120 2965 if (!does_file_exist(curr_slice_fname_uncompressed)) { 3121 log_msg(2, 3122 "Warning - '%s' doesn't exist. How can I compress slice?", 3123 curr_slice_fname_uncompressed); 2966 log_msg(2, "Warning - '%s' doesn't exist. How can I compress slice?", curr_slice_fname_uncompressed); 3124 2967 } 3125 2968 if (should_I_compress_slices && bkpinfo->compression_level > 0) { … … 3141 2984 log_msg(2, "Failed to compress the slice"); 3142 2985 } 3143 if (bkpinfo->use_lzo 3144 && strcmp(curr_slice_fname_compressed, 3145 curr_slice_fname_uncompressed)) { 2986 if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed)) { 3146 2987 unlink(curr_slice_fname_uncompressed); 3147 2988 } … … 3149 2990 mr_asprintf(tmp, "Problem with slice # %ld", slice_num); 3150 2991 } else { 3151 mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK ", biggie_filename, biggie_file_number + 1, 3152 slice_num); 3153 } 3154 #ifndef _XWIN 2992 mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK ", biggie_filename, biggie_file_number + 1, slice_num); 2993 } 3155 2994 if (!g_text_mode) { 3156 2995 newtDrawRootText(0, g_noof_rows - 2, tmp); … … 3159 2998 log_msg(2, tmp); 3160 2999 } 3161 #else 3162 log_msg(2, tmp); 3163 #endif 3164 paranoid_free(tmp); 3000 mr_free(tmp); 3165 3001 3166 3002 mr_asprintf(file_to_archive, "%s", curr_slice_fname_compressed); … … 3178 3014 3179 3015 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3180 register_in_tape_catalog(biggieslice, biggie_file_number, 3181 slice_num, file_to_archive); 3182 maintain_collection_of_recent_archives(bkpinfo->tmpdir, 3183 file_to_archive); 3016 register_in_tape_catalog(biggieslice, biggie_file_number, slice_num, file_to_archive); 3017 maintain_collection_of_recent_archives(bkpinfo->tmpdir, file_to_archive); 3184 3018 res = move_files_to_stream(file_to_archive, NULL); 3185 3019 } else { … … 3190 3024 retval += res; 3191 3025 if (res) { 3192 mr_asprintf(tmp, "Failed to add slice %ld of bigfile %ld to scratchdir", slice_num, biggie_file_number + 1); 3193 log_to_screen(tmp); 3194 paranoid_free(tmp); 3195 fatal_error 3196 ("Hard disk full. You should have bought a bigger one."); 3197 } 3198 } 3199 mr_free(tempblock); 3026 log_to_screen("Failed to add slice %ld of bigfile %ld to scratchdir", slice_num, biggie_file_number + 1); 3027 fatal_error("Hard disk full. You should have bought a bigger one."); 3028 } 3029 } 3200 3030 mr_free(suffix); 3201 3031 paranoid_fclose(fin); … … 3207 3037 } 3208 3038 log_msg(1, tmp); 3209 paranoid_free(tmp); 3210 3211 paranoid_free(checksum_line); 3039 mr_free(tmp); 3040 3212 3041 return (retval); 3213 3042 } … … 3288 3117 log_msg(2, tmp); 3289 3118 center_string(tmp, 80); 3290 #ifndef _XWIN3291 3119 if (!g_text_mode) { 3292 3120 newtPushHelpLine(tmp); 3293 3121 } 3294 #endif3295 3122 res = write_iso_and_go_on(TRUE); 3296 #ifndef _XWIN3297 3123 if (!g_text_mode) { 3298 3124 newtPopHelpLine(); 3299 3125 } 3300 #endif3301 3126 log_msg(2, "Returning from writing final ISO (res=%d)", res); 3302 3127 paranoid_free(tmp); … … 3327 3152 3328 3153 /*@ buffers ***************************************************** */ 3329 char *tmp; 3330 char *cdno_fname; 3331 char *lastcd_fname; 3332 char *isofile; 3154 char *tmp = NULL; 3155 char *tmp1 = NULL; 3156 char *cdno_fname = NULL; 3157 char *lastcd_fname = NULL; 3158 char *isofile = NULL; 3333 3159 char *mds = NULL; 3334 3160 … … 3341 3167 3342 3168 malloc_string(tmp); 3343 malloc_string(cdno_fname);3344 malloc_string(lastcd_fname);3345 malloc_string(isofile);3346 3169 3347 3170 assert(bkpinfo != NULL); … … 3357 3180 /* label the ISO with its number */ 3358 3181 3359 sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);3182 mr_asprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir); 3360 3183 fout = fopen(cdno_fname, "w"); 3184 mr_free(cdno_fname); 3185 3361 3186 fprintf(fout, "%d", g_current_media_number); 3362 3187 paranoid_fclose(fout); 3363 3188 3364 sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home, 3365 bkpinfo->scratchdir); 3366 if (run_program_and_log_output(tmp, FALSE)) { 3189 mr_asprintf(tmp1, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir); 3190 if (run_program_and_log_output(tmp1, FALSE)) { 3367 3191 log_msg(2, "Warning - unable to copy autorun to scratchdir"); 3368 3192 } 3193 mr_free(tmp1); 3369 3194 3370 3195 /* last CD or not? Label accordingly */ 3371 sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);3196 mr_asprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir); 3372 3197 if (last_cd) { 3373 3198 unlink(lastcd_fname); … … 3380 3205 paranoid_fclose(fout); 3381 3206 } 3207 mr_free(lastcd_fname); 3208 3382 3209 if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) { 3383 sprintf(tmp, 3384 "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.", 3385 (long) space_occupied_by_cd(bkpinfo->scratchdir), 3386 (long) bkpinfo->media_size); 3387 log_to_screen(tmp); 3388 } 3389 sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, 3210 log_to_screen("Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",(long) space_occupied_by_cd(bkpinfo->scratchdir),(long) bkpinfo->media_size); 3211 } 3212 mr_asprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir, 3390 3213 bkpinfo->netfs_remote_dir, bkpinfo->prefix, 3391 3214 g_current_media_number); … … 3402 3225 { 3403 3226 log_msg(3, "*Sigh* Mike, I hate your computer."); 3227 // if it can't be found then force pausing 3404 3228 bkpinfo->manual_cd_tray = TRUE; 3405 } // if it can't be found then force pausing 3406 else { 3229 } else { 3407 3230 log_msg(3, "Great. Found Mike's CD-ROM drive."); 3408 3231 } … … 3410 3233 if (bkpinfo->verify_data && !res) { 3411 3234 mds = media_descriptor_string(g_backup_media_type); 3412 log_to_screen 3413 ("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds); 3235 log_to_screen("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds); 3414 3236 mr_free(mds); 3415 3237 if (chdir("/")) { … … 3428 3250 } else { 3429 3251 mds = media_descriptor_string(bkpinfo->backup_media_type); 3430 sprintf(tmp, "Failed to create %s #%d. Retry?", mds, g_current_media_number);3252 mr_asprintf(tmp1, "Failed to create %s #%d. Retry?", mds, g_current_media_number); 3431 3253 mr_free(mds); 3432 res = ask_me_yes_or_no(tmp); 3254 res = ask_me_yes_or_no(tmp1); 3255 mr_free(tmp1); 3256 3433 3257 if (!res) { 3434 3258 if (ask_me_yes_or_no("Abort the backup?")) { … … 3443 3267 } 3444 3268 } 3269 mr_free(isofile); 3270 3445 3271 g_current_media_number++; 3446 3272 wipe_archives(bkpinfo->scratchdir); 3447 sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img", 3448 bkpinfo->scratchdir, bkpinfo->scratchdir); 3449 if (system(tmp)) { 3450 log_msg 3451 (2, 3452 "Error occurred when I tried to delete the redundant IMGs and GZs"); 3453 } 3273 mr_asprintf(tmp1, "rm -Rf %s/images/*gz %s/images/*data*img", bkpinfo->scratchdir, bkpinfo->scratchdir); 3274 if (system(tmp1)) { 3275 log_msg(2, "Error occurred when I tried to delete the redundant IMGs and GZs"); 3276 } 3277 mr_free(tmp1); 3454 3278 3455 3279 if (last_cd) { … … 3461 3285 bkpinfo->verify_data = orig_vfy_flag_val; 3462 3286 paranoid_free(tmp); 3463 paranoid_free(cdno_fname);3464 paranoid_free(lastcd_fname);3465 paranoid_free(isofile);3466 3287 return (0); 3467 3288 } … … 3532 3353 if (res) { 3533 3354 mds = media_descriptor_string(bkpinfo->backup_media_type); 3534 mr_asprintf(tmp,"Warnings/errors were reported while checking %s #%d", mds, g_current_media_number);3355 log_to_screen("Warnings/errors were reported while checking %s #%d", mds, g_current_media_number); 3535 3356 mr_free(mds); 3536 log_to_screen(tmp);3537 mr_free(tmp);3538 3357 3539 3358 } -
branches/3.0/mondo/src/common/libmondo-cli.c
r3185 r3188 97 97 for (i = 0; i < 128; i++) { 98 98 if (flag_set[i]) { 99 mr_asprintf(tmp, "-%c %s", i, flag_val[i]); 100 log_msg(3, tmp); 101 mr_free(tmp); 99 log_msg(3, "-%c %s", i, flag_val[i]); 102 100 } 103 101 } … … 150 148 char *tmp = NULL; 151 149 char *tmp1 = NULL; 150 char *tmp2 = NULL; 152 151 char *psz = NULL; 153 152 char *p = NULL; … … 208 207 log_msg(1, "Using star instead of afio"); 209 208 } else { 210 fatal_error 211 ("Neither afio nor star is installed. Please install at least one."); 209 fatal_error("Neither afio nor star is installed. Please install at least one."); 212 210 } 213 211 } … … 219 217 } 220 218 if (!find_home_of_exe("star")) { 221 fatal_error 222 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 219 fatal_error("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 223 220 } 224 221 } … … 234 231 235 232 if (flag_set['I']) { 236 if (bkpinfo->include_paths [0] == '-') {233 if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') { 237 234 retval++; 238 235 log_to_screen("Please supply a sensible value with '-I'\n"); … … 268 265 } 269 266 } 270 paranoid_free(tmp1);267 mr_free(tmp1); 271 268 mr_make_devlist_from_pathlist(flag_val['I'], 'I'); 272 269 log_msg(4, "Finished with the -I option"); 273 270 } 274 271 275 if (g_kernel_version >= 2.6 && !flag_set['d'] 276 && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) { 277 fatal_error 278 ("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 272 if (g_kernel_version >= 2.6 && !flag_set['d'] && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) { 273 fatal_error("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 279 274 } 280 275 … … 283 278 if (flag_set['I']) { 284 279 retval++; 285 log_to_screen 286 ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 280 log_to_screen("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 287 281 } 288 282 bkpinfo->make_filelist = FALSE; 289 strcpy(bkpinfo->include_paths, flag_val['J']);283 mr_asprintf(bkpinfo->include_paths, "%s", flag_val['J']); 290 284 } 291 285 292 286 if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) { 293 if (!flag_set['r'] && g_kernel_version <= 2.5 294 && strstr(flag_val['d'], "/dev/")) { 295 fatal_error 296 ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); 297 } 298 if (flag_set['r'] && g_kernel_version <= 2.5 299 && !strstr(flag_val['d'], "/dev/")) { 300 fatal_error 301 ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); 287 if (!flag_set['r'] && g_kernel_version <= 2.5 && strstr(flag_val['d'], "/dev/")) { 288 fatal_error("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); 289 } 290 if (flag_set['r'] && g_kernel_version <= 2.5 && !strstr(flag_val['d'], "/dev/")) { 291 fatal_error("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); 302 292 } 303 293 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) { 304 log_to_screen 305 ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); 306 } 307 308 if (system("which cdrecord > /dev/null 2> /dev/null") 309 && system("which dvdrecord > /dev/null 2> /dev/null")) { 310 fatal_error 311 ("Please install dvdrecord/cdrecord and try again."); 294 log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); 295 } 296 297 if (system("which cdrecord > /dev/null 2> /dev/null") && system("which dvdrecord > /dev/null 2> /dev/null")) { 298 fatal_error("Please install dvdrecord/cdrecord and try again."); 312 299 } 313 300 if (flag_set['C']) { 314 301 bkpinfo->cdrw_speed = atoi(flag_val['C']); 315 302 if (bkpinfo->cdrw_speed < 1) { 316 fatal_error 317 ("You specified a silly speed for a CD-R[W] drive"); 303 fatal_error("You specified a silly speed for a CD-R[W] drive"); 318 304 } 319 305 if (!flag_set['L']) { 320 log_to_screen 321 ("You must use -L with -C. Therefore I am setting it for you."); 306 log_to_screen("You must use -L with -C. Therefore I am setting it for you."); 322 307 flag_set['L'] = 1; 323 308 flag_val['L'][0] = '\0'; … … 326 311 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 327 312 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 328 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );329 313 if (flag_set['c']) { 330 314 bkpinfo->cdrw_speed = atoi(flag_val['c']); … … 336 320 337 321 if (bkpinfo->cdrw_speed < 1) { 338 fatal_error 339 ("You specified a silly speed for a CD-R[W] drive"); 322 fatal_error("You specified a silly speed for a CD-R[W] drive"); 340 323 } 341 324 } … … 345 328 log_it("Hmm! No tape drive specified. Let's see what we can do."); 346 329 if (find_tape_device_and_size(flag_val['d'], tmp)) { 347 fatal_error 348 ("Tape device not specified. I couldn't find it either."); 330 fatal_error("Tape device not specified. I couldn't find it either."); 349 331 } 350 332 flag_set['d'] = TRUE; 351 sprintf(tmp, 352 "You didn't specify a tape streamer device. I'm assuming %s", 353 flag_val['d']); 354 log_to_screen(tmp); 333 log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']); 355 334 } 356 335 … … 358 337 { 359 338 if (! flag_set['d']) { 360 fatal_error 361 ("You need to specify a device file with -d for bootable USB device usage"); 339 fatal_error("You need to specify a device file with -d for bootable USB device usage"); 362 340 } 363 341 if ((!flag_set['s']) && (! bkpinfo->restore_data)) { … … 369 347 { 370 348 if (flag_set['m']) { 371 fatal_error 372 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 349 fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 373 350 } 374 351 if (!flag_set['d']) { … … 379 356 } 380 357 if (strchr(flag_val['d'], ',')) { 381 fatal_error 382 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 358 fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 383 359 } 384 360 if (! bkpinfo->restore_data) { 385 361 if (!find_home_of_exe("growisofs")) { 386 fatal_error 387 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 362 fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 388 363 } 389 364 if (!find_home_of_exe("dvd+rw-format")) { 390 fatal_error 391 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 365 fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 392 366 } 393 367 if (!flag_set['s']) { 394 368 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 395 369 strcat(flag_val['s'], "m"); 396 log_to_screen 397 ("You did not specify a size (-s) for DVD. I'm guessing %s.", 398 flag_val['s']); 370 log_to_screen("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']); 399 371 flag_set['s'] = 1; 400 372 } 401 373 } 402 /*403 if (flag_set['Z']) {404 bkpinfo->blank_dvd_first = TRUE;405 }406 */407 374 } 408 375 409 376 if (flag_set['t'] || flag_set['u']) { /* tape size */ 410 377 if (strchr(flag_val['d'], ',')) { 411 fatal_error 412 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 378 fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 413 379 } 414 380 if ((flag_set['O']) && (! bkpinfo->restore_data)) { 415 381 if (flag_set['s']) { 416 382 if (flag_set['t']) { 417 fatal_error 418 ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 383 fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 419 384 } 420 385 if (process_the_s_switch(flag_val['s'])) { … … 440 405 441 406 if (flag_set['n']) { 442 strncpy(bkpinfo->netfs_mount, flag_val['n'], MAX_STR_LEN); 407 mr_free(bkpinfo->netfs_mount); 408 mr_asprintf(bkpinfo->netfs_mount, "%s", flag_val['n']); 443 409 if (!flag_set['d']) { 444 strncpy(bkpinfo->netfs_remote_dir, "/", MAX_STR_LEN); 410 mr_free(bkpinfo->netfs_remote_dir); 411 mr_asprintf(bkpinfo->netfs_remote_dir, "/"); 445 412 } 446 413 /* test for protocol */ … … 473 440 /* Store the 2 values */ 474 441 /* using memmove instead of strcpy as per #584 */ 475 memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN); 442 /* memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN); */ 443 bkpinfo->netfs_mount = p; 476 444 477 445 /* test if we specified a user */ … … 479 447 if (p != NULL) { 480 448 /* User found. Store the 2 values */ 449 bkpinfo->netfs_user = bkpinfo->netfs_mount; 481 450 p++; 482 451 /* new netfs mount */ 483 strcpy(tmp,p); 452 mr_asprintf(bkpinfo->netfs_mount, "%s", p); 453 /* now that user is computed, create the right value by removing end of string */ 484 454 p--; 485 455 *p = '\0'; 486 mr_asprintf(q,"%s",bkpinfo->netfs_mount); 487 bkpinfo->netfs_user = q; 488 strcpy(bkpinfo->netfs_mount,tmp); 489 } 490 sprintf(tmp, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, 491 bkpinfo->netfs_mount); 492 strncpy(bkpinfo->isodir, 493 call_program_and_get_last_line_of_output(tmp), 494 MAX_STR_LEN / 4); 456 } 457 mr_asprintf(tmp1, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount); 458 strncpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp), MAX_STR_LEN / 4); 459 mr_free(tmp1); 460 495 461 if (strlen(bkpinfo->isodir) < 3) { 496 462 log_to_screen("Network share is not mounted. Trying to mount it for you.\n"); 497 463 if (bkpinfo->netfs_user) { 498 464 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 499 sprintf(tmp, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);465 mr_asprintf(tmp1, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount); 500 466 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) { 501 sprintf(tmp, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user);467 mr_asprintf(tmp1, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user); 502 468 } else if (strstr(bkpinfo->netfs_proto, "nfs")) { 503 sprintf(tmp, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);469 mr_asprintf(tmp1, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount); 504 470 } else { 505 471 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto); … … 508 474 } else { 509 475 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 510 sprintf(tmp, "sshfs %s", bkpinfo->netfs_mount);476 mr_asprintf(tmp1, "sshfs %s", bkpinfo->netfs_mount); 511 477 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) { 512 sprintf(tmp, "mount -t cifs %s", bkpinfo->netfs_mount);478 mr_asprintf(tmp1, "mount -t cifs %s", bkpinfo->netfs_mount); 513 479 } else if (strstr(bkpinfo->netfs_proto, "nfs")) { 514 sprintf(tmp, "mount %s", bkpinfo->netfs_mount);480 mr_asprintf(tmp1, "mount %s", bkpinfo->netfs_mount); 515 481 } else { 516 482 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto); … … 518 484 } 519 485 } 520 if (system(tmp)) { 486 i = system(tmp1); 487 mr_free(tmp1); 488 489 if (i) { 521 490 log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount); 522 491 retval++; 523 492 } else { 524 493 if (bkpinfo->netfs_user) { 525 sprintf(tmp, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, 526 bkpinfo->netfs_mount); 494 mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount); 527 495 } else { 528 sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);496 mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount); 529 497 } 530 strncpy(bkpinfo->isodir, 531 call_program_and_get_last_line_of_output(tmp), 532 MAX_STR_LEN / 4); 498 strncpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp), MAX_STR_LEN / 4); 533 499 if (strlen(bkpinfo->isodir) < 3) { 534 500 retval++; … … 624 590 } 625 591 } 626 paranoid_free(tmp1);592 mr_free(tmp1); 627 593 628 594 mr_make_devlist_from_pathlist(flag_val['E'], 'E'); … … 668 634 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 669 635 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) { 670 fatal_error 671 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 636 fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 672 637 } 673 638 bkpinfo->internal_tape_block_size = itbs; … … 678 643 // bkpinfo->differential = atoi (flag_val['D']); 679 644 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) { 680 fatal_error 681 ("The D option should be between 1 and 9 inclusive"); 645 fatal_error("The D option should be between 1 and 9 inclusive"); 682 646 } 683 647 } … … 702 666 && !does_file_exist(bkpinfo->kernel_path)) { 703 667 retval++; 704 sprintf(tmp, 705 "You specified kernel '%s', which does not exist\n", 706 bkpinfo->kernel_path); 707 log_to_screen(tmp); 668 log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path); 708 669 } 709 670 } … … 723 684 } 724 685 } else if (flag_set['n']) { 725 strncpy(bkpinfo->netfs_remote_dir, flag_val['d'], MAX_STR_LEN); 686 mr_free(bkpinfo->netfs_remote_dir); 687 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']); 726 688 } else { /* backup device (if tape/CD-R/CD-RW) */ 727 689 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4); … … 732 694 mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir); 733 695 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) { 734 sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);696 mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1); 735 697 } else { 736 sprintf(tmp, "echo hi > %s", tmp1);737 } 738 i f (run_program_and_log_output(tmp, 2)) {739 retval++;740 sprintf(tmp, 741 "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",742 bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);743 log_to_screen( tmp);698 mr_asprintf(tmp2, "echo hi > %s", tmp1); 699 } 700 i = run_program_and_log_output(tmp2, 2); 701 mr_free(tmp2); 702 703 if (i) { 704 retval++; 705 log_to_screen("Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount); 744 706 } 745 707 unlink(tmp1); 746 paranoid_free(tmp1); 747 } 748 749 if (!flag_set['d'] 750 && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 708 mr_free(tmp1); 709 } 710 711 if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 751 712 if (g_kernel_version >= 2.6) { 752 713 if (popup_and_get_string … … 769 730 retval++; 770 731 log_to_screen("Please specify the backup device/directory.\n"); 771 fatal_error 772 ("You didn't use -d to specify the backup device/directory."); 732 fatal_error("You didn't use -d to specify the backup device/directory."); 773 733 } 774 734 … … 781 741 if (flag_set['S']) { 782 742 setup_scratchdir(flag_val['S']); 783 sprintf(tmp, "touch %s/.foo.dat", bkpinfo->scratchdir); 784 if (run_program_and_log_output(tmp, 1)) { 785 retval++; 743 mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->scratchdir); 744 if (run_program_and_log_output(tmp1, 1)) { 745 retval++; 746 mr_free(tmp1); 786 747 log_to_screen("Please specify a scratchdir which I can write to. :)"); 787 748 fatal_error("I cannot write to the scratchdir you specified."); 788 749 } 789 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->scratchdir, bkpinfo->scratchdir); 790 if (run_program_and_log_output(tmp, 1)) { 791 retval++; 750 mr_free(tmp1); 751 752 mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->scratchdir, bkpinfo->scratchdir); 753 if (run_program_and_log_output(tmp1, 1)) { 754 retval++; 755 mr_free(tmp1); 792 756 log_to_screen("Please don't specify a SAMBA or VFAT or NFS scratchdir."); 793 757 fatal_error("I cannot write to the scratchdir you specified."); 794 758 } 759 mr_free(tmp1); 795 760 } 796 761 797 762 if (flag_set['T']) { 798 763 setup_tmpdir(flag_val['T']); 799 sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir); 800 if (run_program_and_log_output(tmp, 1)) { 764 mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir); 765 i = run_program_and_log_output(tmp1, 1); 766 mr_free(tmp1); 767 768 if (i) { 801 769 retval++; 802 770 log_to_screen("Please specify a tempdir which I can write to. :)"); 803 771 fatal_error("I cannot write to the tempdir you specified."); 804 772 } 805 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir); 806 if (run_program_and_log_output(tmp, 1)) { 773 mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir); 774 i = run_program_and_log_output(tmp1, 1); 775 mr_free(tmp1); 776 777 if (i) { 807 778 retval++; 808 779 log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir."); … … 833 804 # endif 834 805 #endif 835 if (!strchr 836 (BOOT_LOADER_CHARS, 837 (bkpinfo->boot_loader = flag_val['l'][0]))) { 838 log_msg(1, "%c? WTF is %c? I need G, L, E or R.", 839 bkpinfo->boot_loader, bkpinfo->boot_loader); 840 fatal_error 841 ("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 806 if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) { 807 log_msg(1, "%c? What is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader); 808 fatal_error("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 842 809 } 843 810 #undef BOOT_LOADER_CHARS … … 845 812 846 813 if (flag_set['f']) { 847 strncpy(bkpinfo->boot_device, 848 resolve_softlinks_to_get_to_actual_device_file(flag_val 849 ['f']), 850 MAX_STR_LEN / 4); 814 strncpy(bkpinfo->boot_device, resolve_softlinks_to_get_to_actual_device_file(flag_val['f']),MAX_STR_LEN / 4); 851 815 } 852 816 … … 866 830 if (run_program_and_log_output("which lzop", 2)) { 867 831 retval++; 868 log_to_screen 869 ("Please install LZOP. You can't use '-L' until you do.\n"); 832 log_to_screen("Please install LZOP. You can't use '-L' until you do.\n"); 870 833 } 871 834 } … … 880 843 if (run_program_and_log_output("which gzip", 2)) { 881 844 retval++; 882 log_to_screen 883 ("Please install gzip. You can't use '-G' until you do.\n"); 845 log_to_screen("Please install gzip. You can't use '-G' until you do.\n"); 846 } 847 } 848 849 if ((flag_set['Y']) && (! bkpinfo->restore_data)) { 850 bkpinfo->use_lzma = TRUE; 851 if (run_program_and_log_output("which lzma", 2)) { 852 retval++; 853 log_to_screen("Please install lzma. You can't use '-Y' until you do.\n"); 884 854 } 885 855 } … … 897 867 if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) { 898 868 bkpinfo->make_cd_use_lilo = TRUE; 899 log_to_screen 900 ("Your kernel appears not to support vfat filesystems. I am therefore"); 901 log_to_screen 902 ("using LILO instead of SYSLINUX as the media boot loader."); 869 log_to_screen("Your kernel appears not to support vfat filesystems. I am therefore"); 870 log_to_screen("using LILO instead of SYSLINUX as the media boot loader."); 903 871 } 904 872 if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) { 905 873 bkpinfo->make_cd_use_lilo = TRUE; 906 874 #ifdef __IA32__ 907 log_to_screen 908 ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 909 log_to_screen 910 ("your boot loader. I shall therefore use LILO instead."); 875 log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 876 log_to_screen("your boot loader. I shall therefore use LILO instead."); 911 877 #endif 912 878 #ifdef __IA64__ 913 log_to_screen 914 ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 879 log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 915 880 log_to_screen("environment correctly. Please install it."); 916 881 fatal_error("Aborting"); … … 932 897 933 898 if ((! bkpinfo->restore_data) && (flag_set['Z'])) { 934 fatal_error 935 ("The -Z switch is only valid in restore mode"); 899 fatal_error("The -Z switch is only valid in restore mode"); 936 900 } 937 901 … … 973 937 * @return The number of problems with the command line (0 for success). 974 938 */ 975 int 976 retrieve_switches_from_command_line(int argc, char *argv[], 977 char flag_val[128][MAX_STR_LEN], 978 bool flag_set[128]) 939 int retrieve_switches_from_command_line(int argc, char *argv[], char flag_val[128][MAX_STR_LEN], bool flag_set[128]) 979 940 { 980 941 /*@ ints ** */ 981 942 int opt = 0; 982 char *tmp = NULL;983 943 int i = 0; 984 944 int len; … … 994 954 flag_set[i] = FALSE; 995 955 } 996 while ((opt = 997 getopt(argc, argv, MONDO_OPTIONS)) 998 != -1) { 956 while ((opt = getopt(argc, argv, MONDO_OPTIONS)) != -1) { 999 957 if (opt == '?') { 1000 958 bad_switches = TRUE; 1001 /*log_it("Invalid option: %c\n",optopt); */1002 959 } else { 1003 960 if (flag_set[opt]) { 1004 961 bad_switches = TRUE; 1005 mr_asprintf(tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]); 1006 log_to_screen(tmp); 1007 paranoid_free(tmp); 962 log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]); 1008 963 } else { 1009 964 flag_set[opt] = TRUE; … … 1019 974 if (strchr(flag_val[opt], '/') 1020 975 && flag_val[opt][0] != '/') { 1021 mr_asprintf(tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 1022 log_to_screen(tmp); 1023 paranoid_free(tmp); 976 log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 1024 977 bad_switches = TRUE; 1025 978 } … … 1032 985 for (i = optind; i < argc; i++) { 1033 986 bad_switches = TRUE; 1034 mr_asprintf(tmp, "Invalid arg -- %s\n", argv[i]); 1035 log_to_screen(tmp); 1036 paranoid_free(tmp); 987 log_to_screen("Invalid arg -- %s\n", argv[i]); 1037 988 } 1038 989 return (bad_switches); … … 1097 1048 mr_strcat(tmp, " signal received from OS"); 1098 1049 log_to_screen(tmp); 1099 paranoid_free(tmp);1050 mr_free(tmp); 1100 1051 1101 1052 log_to_screen(tmp2); 1102 paranoid_free(tmp2);1053 mr_free(tmp2); 1103 1054 if (sig == SIGABRT) { 1104 1055 sleep(10); … … 1108 1059 free_MR_global_filenames(); 1109 1060 1110 fatal_error 1111 ("MondoRescue is terminating in response to a signal from the OS"); 1061 fatal_error("MondoRescue is terminating in response to a signal from the OS"); 1112 1062 finish(254); // just in case 1113 1063 } … … 1122 1072 void set_signals(int on) 1123 1073 { 1124 int signals[] = 1125 { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1074 int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1126 1075 int i; 1127 1076 -
branches/3.0/mondo/src/common/libmondo-devices-EXT.h
r3154 r3188 16 16 extern int find_device_in_mountlist(struct mountlist_itself *mountlist, 17 17 char *device); 18 extern int mount_CDROM_here(char *device, c har *mountpoint);18 extern int mount_CDROM_here(char *device, const char *mountpoint); 19 19 extern long long size_of_specific_device_in_mountlist(struct 20 20 mountlist_itself … … 57 57 extern int inject_device(char *dev); 58 58 extern bool does_nonMS_partition_exist(void); 59 extern char *resolve_softlinks_to_get_to_actual_device_file(char 60 *incoming); 59 extern char *resolve_softlinks_to_get_to_actual_device_file(char *incoming); 61 60 62 61 extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(); -
branches/3.0/mondo/src/common/libmondo-devices.c
r3185 r3188 21 21 #include "libmondo-stream-EXT.h" 22 22 23 extern void mr_strip_spaces(char *); 24 23 25 #include <sys/types.h> 24 26 #ifdef __FreeBSD__ … … 127 129 { 128 130 char *tmp = NULL; 129 char *comment;130 131 bool is_this_a_ramdisk = FALSE; 131 132 132 malloc_string(comment);133 133 mr_asprintf(tmp, "%s", where_is_root_mounted()); 134 sprintf(comment, "root is mounted at %s\n", tmp); 135 log_msg(0, comment); 136 log_msg(0, 137 "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", 138 tmp); 134 log_msg(0, "root is mounted at %s\n", tmp); 135 log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp); 139 136 140 137 #ifdef __FreeBSD__ … … 156 153 if (is_this_a_ramdisk) { 157 154 if (!does_file_exist("/THIS-IS-A-RAMDISK")) { 158 log_to_screen 159 ("Using /dev/root is stupid of you but I'll forgive you."); 155 log_to_screen("Using /dev/root is stupid of you but I'll forgive you."); 160 156 is_this_a_ramdisk = FALSE; 161 157 } … … 164 160 is_this_a_ramdisk = TRUE; 165 161 } 166 paranoid_free(comment); 167 log_msg(1, "Is this a ramdisk? result = % d", is_this_a_ramdisk);162 163 log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE"); 168 164 return (is_this_a_ramdisk); 169 165 } … … 229 225 int eject_device(char *dev) 230 226 { 231 char *command ;227 char *command = NULL; 232 228 int res1 = 0, res2 = 0; 233 229 234 malloc_string(command); 230 if (dev == NULL) { 231 return (1); 232 } 235 233 236 234 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 237 235 && g_backup_media_type != udev) { 238 sprintf(command, "mt -f %s offline", dev);236 mr_asprintf(command, "mt -f %s offline", dev); 239 237 res1 = run_program_and_log_output(command, 1); 238 mr_free(command); 240 239 } else { 241 240 res1 = 0; … … 244 243 #ifdef __FreeBSD__ 245 244 if (strstr(dev, "acd")) { 246 sprintf(command, "cdcontrol -f %s eject", dev);245 mr_asprintf(command, "cdcontrol -f %s eject", dev); 247 246 } else { 248 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 249 dev); 247 mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev); 250 248 } 251 249 #else 252 sprintf(command, "eject %s", dev);250 mr_asprintf(command, "eject %s", dev); 253 251 #endif 254 252 255 253 log_msg(3, "Ejecting %s", dev); 256 254 res2 = run_program_and_log_output(command, 1); 257 paranoid_free(command);255 mr_free(command); 258 256 if (res1 && res2) { 259 257 return (1); … … 270 268 int inject_device(char *dev) 271 269 { 272 char *command ;270 char *command = NULL; 273 271 int i; 274 272 275 malloc_string(command); 276 273 if (dev == NULL) { 274 return (1); 275 } 277 276 278 277 #ifdef __FreeBSD__ 279 278 if (strstr(dev, "acd")) { 280 sprintf(command, "cdcontrol -f %s close", dev);279 mr_asprintf(command, "cdcontrol -f %s close", dev); 281 280 } else { 282 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", 283 dev); 281 mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev); 284 282 } 285 283 #else 286 sprintf(command, "eject -t %s", dev);284 mr_asprintf(command, "eject -t %s", dev); 287 285 #endif 288 286 i = run_program_and_log_output(command, FALSE); 289 paranoid_free(command);287 mr_free(command); 290 288 return (i); 291 289 } … … 301 299 302 300 /*@ buffers *********************************************************** */ 303 char *tmp ;301 char *tmp = NULL; 304 302 bool ret; 305 303 306 malloc_string(tmp);307 304 assert_string_is_neither_NULL_nor_zerolength(device); 308 305 309 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);306 mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device); 310 307 311 308 if (system(tmp)) { … … 314 311 ret = TRUE; 315 312 } 316 paranoid_free(tmp);313 mr_free(tmp); 317 314 return (ret); 318 315 } … … 345 342 { 346 343 /*@ buffers **************************************************** */ 347 char *program ;348 char *incoming ;344 char *program = NULL; 345 char *incoming = NULL; 349 346 char *searchstr = NULL; 350 char *tmp;351 char *p;352 347 353 348 /*@ ints ******************************************************* */ … … 356 351 /*@ pointers *************************************************** */ 357 352 FILE *fin; 358 359 353 360 354 /*@ end vars *************************************************** */ … … 362 356 assert(partno >= 0 && partno < 999); 363 357 364 malloc_string(program);365 malloc_string(incoming);366 358 malloc_string(searchstr); 367 malloc_string(tmp);368 359 369 360 #ifdef __FreeBSD__ 370 361 // We assume here that this is running from mondorestore. (It is.) 371 sprintf(program, "ls %s %s >/dev/null 2>&1", drive, 372 build_partition_name(tmp, drive, partno)); 373 return system(program); 374 #else 375 tmp[0] = '\0'; 376 #endif 377 378 sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 362 mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno)); 363 res = system(program); 364 mr_free(program); 365 return(res); 366 #endif 367 368 mr_asprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 379 369 fin = popen(program, "r"); 380 370 if (!fin) { 381 371 log_it("program=%s", program); 382 372 log_OS_error("Cannot popen-in program"); 373 mr_free(program); 383 374 return (0); 384 375 } 376 mr_free(program); 377 385 378 (void) build_partition_name(searchstr, drive, partno); 386 379 strcat(searchstr, " "); 387 for (res = 0 ; !res && (p = fgets(incoming, MAX_STR_LEN - 1, fin));) {380 for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) { 388 381 if (strstr(incoming, searchstr)) { 389 382 res = 1; 390 383 } 391 } 384 mr_free(incoming); 385 } 386 mr_free(incoming); 387 392 388 if (pclose(fin)) { 393 389 log_OS_error("Cannot pclose fin"); 394 390 } 395 paranoid_free(program);396 paranoid_free(incoming);397 391 paranoid_free(searchstr); 398 paranoid_free(tmp);399 392 return (res); 400 393 } … … 413 406 { 414 407 /*@ buffers **************************************************** */ 415 char *command ;408 char *command = NULL; 416 409 417 410 /*@ end vars *************************************************** */ … … 421 414 assert_string_is_neither_NULL_nor_zerolength(str); 422 415 423 malloc_string(command); 424 sprintf(command, 425 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 426 dev, str); 416 /* For UEFI detection, this should be extended to count=2 */ 417 mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str); 427 418 i = system(command); 428 paranoid_free(command);419 mr_free(command); 429 420 if (i) { 430 421 return (FALSE); … … 444 435 { 445 436 /*@ buffers **************************************************** */ 446 char *command ;437 char *command = NULL; 447 438 /*@ end vars *************************************************** */ 448 439 int i; 449 440 450 malloc_string(command); 451 sprintf(command, 452 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 453 dev, n, str); 441 mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str); 454 442 i = system(command); 455 paranoid_free(command);443 mr_free(command); 456 444 if (i) { 457 445 return (FALSE); … … 466 454 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has 467 455 * not been specified, call find_cdrom_device() to find it. 468 * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.469 456 * @param mountpoint Where to mount the CD-ROM. 470 457 * @return 0 for success, nonzero for failure. 471 458 * @see mount_CDROM_here 472 459 */ 473 int find_and_mount_actual_cd(char *mountpoint) 474 { 460 int find_and_mount_actual_cd(char *mountpoint) { 461 475 462 /*@ buffers ***************************************************** */ 476 463 477 464 /*@ int's ****************************************************** */ 478 465 int res; 479 char *dev ;466 char *dev = NULL; 480 467 481 468 /*@ end vars **************************************************** */ … … 532 519 { 533 520 /*@ buffers ************************ */ 534 char *comment;535 521 char *tmp = NULL; 536 522 char *cdr_exe = NULL; 537 char *command; 538 539 malloc_string(comment); 540 malloc_string(command); 523 char *command = NULL; 524 541 525 if (g_cdrw_drive_is_here[0]) { 542 526 strcpy(cdrw_device, g_cdrw_drive_is_here); 543 527 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 544 paranoid_free(comment);545 paranoid_free(command);546 528 return (0); 547 529 } 548 530 if (g_backup_media_type == dvd) { 549 log_msg(1, 550 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 551 paranoid_free(comment); 552 paranoid_free(command); 531 log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 553 532 return (1); 554 533 } … … 560 539 } 561 540 if (find_home_of_exe(cdr_exe)) { 562 sprintf(command, 563 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", 564 cdr_exe); 541 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe); 565 542 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 543 mr_free(command); 566 544 } 567 545 if ((tmp == NULL) || (strlen(tmp) < 2)) { 568 paranoid_free(comment);569 546 mr_free(tmp); 570 547 mr_free(cdr_exe); 571 paranoid_free(command);572 548 return 1; 573 549 } else { 574 550 strcpy(cdrw_device, tmp); 575 sprintf(comment, "Found CDRW device - %s", cdrw_device); 576 log_it(comment); 551 log_it("Found CDRW device - %s", cdrw_device); 577 552 strcpy(g_cdrw_drive_is_here, cdrw_device); 578 paranoid_free(comment);579 553 mr_free(tmp); 580 554 mr_free(cdr_exe); 581 paranoid_free(command);582 555 return (0); 583 556 } 584 557 } 585 586 587 558 588 559 … … 609 580 610 581 /*@ buffers ***************************************************** */ 611 char *tmp ;582 char *tmp = NULL; 612 583 char *tmp1 = NULL; 613 584 char *cdr_exe = NULL; 614 585 char *phrase_one; 615 char *phrase_two; 616 char *command; 617 char *dvd_last_resort; 618 char *mountpoint; 586 char *phrase_two = NULL; 587 char *command = NULL; 588 #ifndef __FreeBSD__ 589 char *dvd_last_resort = NULL; 590 #endif 591 char *mountpoint = NULL; 619 592 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 620 593 … … 622 595 malloc_string(tmp); 623 596 malloc_string(phrase_one); 624 malloc_string(phrase_two);625 malloc_string(command);626 malloc_string(dvd_last_resort);627 597 malloc_string(mountpoint); 628 598 629 599 output[0] = '\0'; 630 600 phrase_one[0] = '\0'; 631 phrase_two[0] = '\0';632 dvd_last_resort[0] = '\0';633 601 634 602 /*@ end vars **************************************************** */ … … 642 610 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 643 611 strcpy(output, the_last_place_i_found_it); 644 log_msg(3, 645 "find_cdrom_device() --- returning last found location - '%s'", 646 output); 612 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output); 647 613 retval = 0; 648 614 goto end_of_find_cdrom_device; … … 671 637 } 672 638 673 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);639 mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 674 640 fin = popen(command, "r"); 675 641 if (!fin) { … … 677 643 log_OS_error("Cannot popen command"); 678 644 mr_free(cdr_exe); 645 mr_free(command); 679 646 return (1); 680 647 } 648 mr_free(command); 649 681 650 for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL); 682 651 tmp1 = fgets(tmp, MAX_STR_LEN, fin)) { … … 696 665 } 697 666 *q = '\0'; 698 strcpy(phrase_two, p);667 mr_asprintf(phrase_two, "%s", p); 699 668 } 700 669 } … … 705 674 706 675 #ifndef __FreeBSD__ 707 if ( strlen(phrase_two) == 0) {676 if (!phrase_two || strlen(phrase_two) == 0) { 708 677 log_msg(4, "Not running phase two. String is empty."); 709 678 } else { 710 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);679 mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 711 680 fin = popen(command, "r"); 681 mr_free(command); 682 712 683 if (!fin) { 713 684 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); … … 721 692 *p = '\0'; 722 693 if (strstr(tmp, "DVD")) { 723 sprintf(dvd_last_resort, "/dev/%s", tmp); 724 log_msg(4, 725 "Ignoring '%s' because it's a DVD drive", 726 tmp); 694 mr_free(dvd_last_resort); 695 mr_asprintf(dvd_last_resort, "/dev/%s", tmp); 696 log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp); 727 697 } else { 728 698 sprintf(output, "/dev/%s", tmp); … … 775 745 #else 776 746 if (!found_it && strlen(dvd_last_resort) > 0) { 777 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 778 dvd_last_resort); 747 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 779 748 strcpy(output, dvd_last_resort); 780 749 found_it = TRUE; 781 750 } 782 751 if (found_it) { 783 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 784 strrchr(output, '/') + 1); 752 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1); 785 753 if (system(tmp) == 0) { 786 log_msg(4, 787 "%s is not right. It's being SCSI-emulated. Continuing.", 788 output); 754 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); 789 755 found_it = FALSE; 790 756 output[0] = '\0'; … … 852 818 found_it = FALSE; 853 819 } else { 854 sprintf(command, "umount %s", output);820 mr_asprintf(command, "umount %s", output); 855 821 paranoid_system(command); 822 mr_free(command); 823 856 824 log_msg(4, "I'm confident the Mondo CD is in %s", output); 857 825 } … … 872 840 } 873 841 874 sprintf(command, 875 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 876 cdr_exe, g_cdrw_drive_is_here); 842 mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here); 843 877 844 log_msg(1, "command=%s", command); 878 845 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command)); 846 mr_free(command); 847 879 848 if (strlen(tmp1) > 0) { 880 849 strcpy(output, tmp1); … … 888 857 889 858 end_of_find_cdrom_device: 859 mr_free(cdr_exe); 860 mr_free(phrase_two); 861 mr_free(dvd_last_resort); 862 890 863 paranoid_free(tmp); 891 mr_free(cdr_exe);892 864 paranoid_free(phrase_one); 893 paranoid_free(phrase_two);894 paranoid_free(command);895 paranoid_free(dvd_last_resort);896 865 paranoid_free(mountpoint); 897 866 return (retval); … … 899 868 900 869 901 902 903 904 870 int find_dvd_device(char *output, bool try_to_mount) 905 871 { 906 char *command;907 872 char *tmp; 908 873 int retval = 0, devno = -1; 909 910 malloc_string(command);911 malloc_string(tmp);912 874 913 875 if (g_dvd_drive_is_here[0]) { … … 917 879 } 918 880 919 sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 881 malloc_string(tmp); 882 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 920 883 log_msg(5, "tmp = '%s'", tmp); 921 if (!tmp[0]) 922 sprintf(tmp, "%s", call_program_and_get_last_line_of_output923 ("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")924 );884 if (!tmp[0]) { 885 mr_free(tmp); 886 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 887 } 925 888 if (tmp[0]) { 926 889 devno = atoi(tmp) - 1; 927 890 } 891 mr_free(tmp); 892 928 893 if (devno >= 0) { 929 894 retval = 0; … … 936 901 } 937 902 938 if (try_to_mount) {939 log_msg(1, "Ignoring the fact that try_to_mount==TRUE");940 }941 903 return (retval); 942 904 } … … 1053 1015 { 1054 1016 char *good_formats = NULL; 1055 char *command ;1056 char *format_sz ;1017 char *command = NULL; 1018 char *format_sz = NULL; 1057 1019 char *p; 1058 1020 … … 1060 1022 int retval; 1061 1023 malloc_string(good_formats); 1062 malloc_string(command);1063 malloc_string(format_sz);1064 1024 1065 1025 assert_string_is_neither_NULL_nor_zerolength(format); 1066 1026 1067 sprintf(format_sz, "%s ", format);1027 mr_asprintf(format_sz, "%s ", format); 1068 1028 1069 1029 #ifdef __FreeBSD__ 1070 sprintf(command, 1071 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1030 mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1072 1031 #else 1073 sprintf(command, 1074 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1032 mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1075 1033 #endif 1076 1034 1077 1035 pin = popen(command, "r"); 1036 mr_free(command); 1037 1078 1038 if (!pin) { 1079 1039 log_OS_error("Unable to read good formats"); … … 1094 1054 } 1095 1055 paranoid_free(good_formats); 1096 paranoid_free(command);1097 paranoid_free(format_sz); 1056 mr_free(format_sz); 1057 1098 1058 return (retval); 1099 1059 } … … 1114 1074 1115 1075 /*@ buffers ***************************************************** */ 1116 char *incoming ;1076 char *incoming = NULL; 1117 1077 char *device_with_tab = NULL; 1118 1078 char *device_with_space = NULL; … … 1128 1088 /*@ end vars **************************************************** */ 1129 1089 1130 malloc_string(incoming); 1131 assert(device_raw != NULL); 1132 // assert_string_is_neither_NULL_nor_zerolength(device_raw); 1090 if (device_raw == NULL) { 1091 return(FALSE); 1092 } 1093 1133 1094 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) { 1134 1095 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", … … 1153 1114 return(FALSE); 1154 1115 } 1155 for (tmp = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (tmp != NULL); 1156 tmp = fgets(incoming, MAX_STR_LEN - 1, fin)) { 1157 if (strstr(incoming, device_with_space) //> incoming 1158 || strstr(incoming, device_with_tab)) // > incoming) 1159 { 1116 1117 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 1118 if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) { 1160 1119 paranoid_pclose(fin); 1161 paranoid_free(incoming);1120 mr_free(incoming); 1162 1121 return(TRUE); 1163 1122 } 1164 } 1123 mr_free(incoming); 1124 } 1125 mr_free(incoming); 1165 1126 mr_free(device_with_tab); 1166 1127 paranoid_pclose(fin); … … 1172 1133 } 1173 1134 mr_free(tmp); 1174 paranoid_free(incoming);1175 1135 return(retval); 1176 1136 } … … 1189 1149 char command[MAX_STR_LEN]; 1190 1150 int vndev = 2; 1191 if (atoi 1192 (call_program_and_get_last_line_of_output 1193 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1151 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) { 1194 1152 do { 1195 1153 sprintf(mddevice, "vn%ic", vndev++); … … 1223 1181 int kick_vn(char *dname) 1224 1182 { 1225 char command[MAX_STR_LEN]; 1183 char *command = NULL; 1184 int res = 0; 1226 1185 1227 1186 if (strncmp(dname, "/dev/", 5) == 0) { … … 1229 1188 } 1230 1189 1231 if (atoi 1232 (call_program_and_get_last_line_of_output 1233 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1234 sprintf(command, "vnconfig -d %s", dname); 1235 return system(command); 1190 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) { 1191 mr_asprintf(command, "vnconfig -d %s", dname); 1236 1192 } else { 1237 sprintf(command, "mdconfig -d -u %s", dname); 1238 return system(command); 1239 } 1240 /*NOTREACHED*/ return 255; 1193 mr_asprintf(command, "mdconfig -d -u %s", dname); 1194 } 1195 res = system(command); 1196 mr_free(command); 1197 return(res); 1241 1198 } 1242 1199 #endif … … 1252 1209 { 1253 1210 /*@ buffer ****************************************************** */ 1254 char *command ;1211 char *command = NULL; 1255 1212 int retval; 1256 1213 1257 malloc_string(command);1258 1214 assert_string_is_neither_NULL_nor_zerolength(device); 1259 1215 assert_string_is_neither_NULL_nor_zerolength(mountpoint); … … 1263 1219 return(1); 1264 1220 } 1265 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, 1266 mountpoint); 1221 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint); 1267 1222 1268 1223 #ifdef __FreeBSD__ 1269 sprintf(command, "mount_vfat %s %s 2>> %s", 1270 device, mountpoint, MONDO_LOGFILE); 1224 mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1271 1225 1272 1226 #else 1273 sprintf(command, "mount %s -t vfat %s 2>> %s", 1274 device, mountpoint, MONDO_LOGFILE); 1227 mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1275 1228 #endif 1276 1229 … … 1278 1231 retval = system(command); 1279 1232 log_msg(1, "system(%s) returned %d", command, retval); 1280 1281 paranoid_free(command); 1233 mr_free(command); 1234 1282 1235 return (retval); 1283 1236 } … … 1289 1242 * @return 0 for success, nonzero for failure. 1290 1243 */ 1291 int mount_CDROM_here(char *device, c har *mountpoint)1244 int mount_CDROM_here(char *device, const char *mountpoint) 1292 1245 { 1293 1246 /*@ buffer ****************************************************** */ … … 1327 1280 1328 1281 } 1329 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 1330 mountpoint); 1282 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint); 1331 1283 /*@ end vars *************************************************** */ 1332 1284 … … 1345 1297 retval = system(command); 1346 1298 log_msg(1, "system(%s) returned %d", command, retval); 1347 paranoid_free(command);1299 mr_free(command); 1348 1300 1349 1301 return (retval); … … 1362 1314 int mount_media() 1363 1315 { 1364 char *mount_cmd ;1316 char *mount_cmd = NULL; 1365 1317 char *mountdir = NULL; 1366 1318 int i, res; 1367 1319 #ifdef __FreeBSD__ 1368 char mdd[32]; 1369 char *mddev = mdd; 1370 #endif 1371 1372 malloc_string(mount_cmd); 1373 assert(bkpinfo != NULL); 1374 1375 if (bkpinfo->backup_media_type == tape 1376 || bkpinfo->backup_media_type == udev) { 1320 char mdd[32]; 1321 char *mddev = mdd; 1322 #endif 1323 1324 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 1377 1325 log_msg(8, "Tape/udev. Therefore, no need to mount a media."); 1378 paranoid_free(mount_cmd);1379 1326 return 0; 1380 1327 } … … 1382 1329 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 1383 1330 log_msg(2, "mount_media() - media already mounted. Fair enough."); 1384 paranoid_free(mount_cmd);1385 1331 return (0); 1386 1332 } … … 1389 1335 log_msg(2, "Mounting for Network thingy"); 1390 1336 log_msg(2, "isodir = %s", bkpinfo->isodir); 1391 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 1392 && am_I_in_disaster_recovery_mode()) { 1337 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) { 1393 1338 strcpy(bkpinfo->isodir, "/tmp/isodir"); 1394 1339 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 1395 1340 } 1396 1341 #ifdef __FreeBSD__ 1397 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,1342 mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 1398 1343 bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number); 1399 1344 mddev = make_vn(mount_cmd); 1400 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1345 mr_free(mount_cmd); 1346 1347 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1401 1348 #else 1402 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 1403 bkpinfo->isodir, bkpinfo->netfs_remote_dir, 1404 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1349 mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1405 1350 #endif 1406 1351 … … 1412 1357 } 1413 1358 #ifdef __FreeBSD__ 1414 sprintf(mount_cmd, "%s/%s-%d.iso", mountdir, 1415 bkpinfo->prefix, g_current_media_number); 1359 mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number); 1416 1360 mddev = make_vn(mount_cmd); 1417 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1361 mr_free(mount_cmd); 1362 1363 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1418 1364 #else 1419 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 1420 mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1365 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1421 1366 #endif 1422 1367 mr_free(mountdir); 1423 1368 } else if (bkpinfo->backup_media_type == usb) { 1424 sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);1369 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM); 1425 1370 } else if (strstr(bkpinfo->media_device, "/dev/")) { 1426 1371 #ifdef __FreeBSD__ 1427 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1428 MNT_CDROM); 1372 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1429 1373 #else 1430 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1431 bkpinfo->media_device, MNT_CDROM); 1374 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1432 1375 #endif 1433 1376 } else { … … 1441 1384 1442 1385 #ifdef __FreeBSD__ 1443 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1444 MNT_CDROM); 1386 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1445 1387 #else 1446 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1447 bkpinfo->media_device, MNT_CDROM); 1388 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1448 1389 #endif 1449 1390 } … … 1457 1398 log_msg(2, "Failed to mount device."); 1458 1399 sleep(5); 1459 run_program_and_log_output("sync", FALSE); 1460 } 1461 } 1400 sync(); 1401 } 1402 } 1403 mr_free(mount_cmd); 1462 1404 1463 1405 if (res) { … … 1466 1408 log_msg(2, "Mounted media drive OK"); 1467 1409 } 1468 paranoid_free(mount_cmd);1469 1410 return (res); 1470 1411 } … … 1496 1437 1497 1438 /*@ buffers ********************************************************* */ 1498 char *tmp ;1439 char *tmp = NULL; 1499 1440 char *mds = NULL; 1500 char *request ;1441 char *request = NULL; 1501 1442 1502 1443 assert(bkpinfo != NULL); … … 1510 1451 return; 1511 1452 } 1512 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1513 || bkpinfo->backup_media_type == netfs) { 1453 mr_asprintf(tmp, "mkdir -p " MNT_CDROM); 1454 run_program_and_log_output(tmp, 5); 1455 mr_free(tmp); 1456 1457 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) { 1514 1458 g_ISO_restore_mode = TRUE; 1515 1459 } 1516 malloc_string(tmp);1517 malloc_string(request);1518 sprintf(tmp, "mkdir -p " MNT_CDROM);1519 run_program_and_log_output(tmp, 5);1520 1460 if ((res = what_number_cd_is_this()) != cd_number_i_want) { 1521 log_msg(3, "Currently, we hold %d but we want %d", res, 1522 cd_number_i_want); 1461 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want); 1523 1462 1524 1463 /* Now we need to umount the current media to have the next mounted after */ … … 1529 1468 1530 1469 mds = media_descriptor_string(bkpinfo->backup_media_type); 1531 sprintf(tmp, "Insisting on %s #%d", mds, cd_number_i_want);1532 sprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);1470 log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want); 1471 mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want); 1533 1472 mr_free(mds); 1534 log_msg(3, tmp); 1473 1535 1474 while (what_number_cd_is_this() != cd_number_i_want) { 1536 paranoid_system("sync");1475 sync(); 1537 1476 if (is_this_device_mounted(MNT_CDROM)) { 1538 1477 res = … … 1556 1495 inject_device(bkpinfo->media_device); 1557 1496 } 1558 paranoid_system("sync"); 1559 } 1497 sync(); 1498 } 1499 mr_free(request); 1500 1560 1501 log_msg(1, "Thankyou. Proceeding..."); 1561 1502 g_current_media_number = cd_number_i_want; 1562 1503 } 1563 paranoid_free(tmp);1564 paranoid_free(request);1565 1504 } 1566 1505 … … 1676 1615 log_msg(5, "Running: %s", command); 1677 1616 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1678 paranoid_free(command);1617 mr_free(command); 1679 1618 1680 1619 mount_cnt = atoi(mounted_file_system); 1681 1620 log_msg (5, "mount_cnt: %d", mount_cnt); 1682 paranoid_free(mounted_file_system);1621 mr_free(mounted_file_system); 1683 1622 1684 1623 for (i=mount_cnt; i > 0; i--) { … … 1686 1625 log_msg(5, "Running: %s", command); 1687 1626 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1688 paranoid_free(command);1627 mr_free(command); 1689 1628 1690 1629 log_msg (5, "mounted_file_system: %s", mounted_file_system); 1691 1630 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) { 1692 1631 log_msg (4, "Could not get the list of mounted file systems"); 1693 paranoid_free(mounted_file_system);1632 mr_free(mounted_file_system); 1694 1633 mr_free(token); 1695 1634 return (1); … … 1719 1658 mr_free(mounted_file_system); 1720 1659 } 1721 /********1722 * DSFptr = DSF_Head;1723 * while (DSFptr != NULL) {1724 * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);1725 * DSFptr = DSFptr->next;1726 * }1727 ********/1728 1660 return (0); 1729 1661 } … … 1773 1705 log_msg(5, " Executing: %s", command); 1774 1706 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1775 paranoid_free(command);1707 mr_free(command); 1776 1708 1777 1709 log_msg(5, " Return value: %s", tmp); 1778 1710 c = atoi(tmp); 1779 paranoid_free(tmp);1711 mr_free(tmp); 1780 1712 1781 1713 if (!c) { … … 1799 1731 log_msg(5, "Executing: %s", command); 1800 1732 mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command)); 1801 paranoid_free(command);1733 mr_free(command); 1802 1734 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 1803 1735 if (!strlen(partition_list)) { … … 1862 1794 log_msg(4, "Processing partition: %s", partitions[i]); 1863 1795 /* See if it's swap. If it is, ignore it. */ 1864 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", 1865 ndsf, partitions[i]); 1796 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]); 1866 1797 log_msg(5, " Running: %s", command); 1867 1798 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1868 paranoid_free(command); 1799 mr_free(command); 1800 1869 1801 log_msg(5, " Return value: %s", tmp); 1870 1802 c = strlen(tmp); 1871 paranoid_free(tmp); 1803 mr_free(tmp); 1804 1872 1805 if (c) { 1873 1806 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); 1874 1807 continue; 1875 1808 } 1809 1876 1810 /* It's not swap. See if we can find the mount point from the mount command. */ 1877 1811 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 1878 1812 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1879 paranoid_free(command); 1813 mr_free(command); 1814 1880 1815 if (strlen(tmp)) { 1881 1816 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 1882 1817 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 1883 1818 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 1884 paranoid_free(tmp);1819 mr_free(tmp); 1885 1820 return (1); 1886 1821 } 1887 1822 DSFptr->check = 1; 1888 paranoid_free(tmp);1823 mr_free(tmp); 1889 1824 continue; 1890 1825 } 1891 paranoid_free(tmp); 1826 mr_free(tmp); 1827 1892 1828 /* It's not swap and it's not mounted. See if it's LVM */ 1893 1829 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); 1830 1894 1831 /* Check for LVM */ 1895 1832 mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]); 1896 1833 log_msg(5, " Running: %s", command); 1897 1834 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1898 paranoid_free(command); 1835 mr_free(command); 1836 1899 1837 if (strlen(tmp)) { 1900 1838 log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]); … … 1903 1841 log_msg(5, " Running: %s", command); 1904 1842 strcpy(VG, call_program_and_get_last_line_of_output(command)); 1905 paranoid_free(command); 1843 mr_free(command); 1844 1906 1845 log_msg(4, " Volume Group: %s", VG); 1907 1846 if (strlen(VG)) { … … 1911 1850 log_msg(5, " Running: %s", command); 1912 1851 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1913 paranoid_free(command); 1852 mr_free(command); 1853 1914 1854 log_msg(4, " VG %s mount_list: %s", VG, mount_list); 1915 1855 lastpos = 0; … … 1918 1858 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 1919 1859 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 1920 paranoid_free(tmp);1860 mr_free(tmp); 1921 1861 mr_free(token); 1922 1862 return (1); … … 1929 1869 * any of the Logical Volumes on the Volume Group. 1930 1870 *******/ 1931 paranoid_free(mount_list);1871 mr_free(mount_list); 1932 1872 1933 1873 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1934 1874 log_msg (5, "Running: %s", command); 1935 1875 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1936 paranoid_free(command);1876 mr_free(command); 1937 1877 log_msg(4, " Software raid device list: %s", mount_list); 1938 1878 lastpos = 0; … … 1940 1880 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 1941 1881 log_msg (5, "Running: %s", command); 1942 paranoid_free(tmp);1882 mr_free(tmp); 1943 1883 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1944 paranoid_free(command);1884 mr_free(command); 1945 1885 log_msg(4, "Number of Software raid device: %s", tmp); 1946 1886 if (atoi(tmp)) { … … 1948 1888 if ((DSFptr = find_device_in_list(token)) == NULL) { 1949 1889 log_msg (4, "Can't find device %s in mounted file systems list", token); 1950 paranoid_free(tmp);1890 mr_free(tmp); 1951 1891 mr_free(token); 1952 1892 return (1); … … 1959 1899 } else { 1960 1900 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 1961 paranoid_free(tmp);1901 mr_free(tmp); 1962 1902 return (1); 1963 1903 } 1964 paranoid_free(tmp);1904 mr_free(tmp); 1965 1905 continue; 1966 1906 } else { 1967 1907 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 1968 1908 } 1969 paranoid_free(tmp); 1909 mr_free(tmp); 1910 1970 1911 /******** 1971 1912 * It's not swap, mounted, or LVM. See if it's used in a software raid device. … … 1975 1916 log_msg(4, " Running: %s", command); 1976 1917 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1977 paranoid_free(command); 1918 mr_free(command); 1919 1978 1920 if (!strlen(tmp)) { 1979 1921 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 1980 paranoid_free(tmp);1922 mr_free(tmp); 1981 1923 continue; 1982 1924 } 1983 1925 log_msg (5, " UUID: %s", tmp); 1926 1984 1927 /* Get the Software raid device list */ 1985 1928 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1986 1929 log_msg (5, " Running: %s", command); 1987 1930 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1988 paranoid_free(command); 1931 mr_free(command); 1932 1989 1933 log_msg(4, " Software raid device list: %s", mount_list); 1990 1934 /* Loop through the software raid device list to see if we can find the partition */ … … 1993 1937 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 1994 1938 log_msg(4, " Running: %s", command); 1995 paranoid_free(tmp);1939 mr_free(tmp); 1996 1940 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1997 paranoid_free(command); 1941 mr_free(command); 1942 1998 1943 if (!atoi(tmp)) { 1999 1944 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); … … 2001 1946 if ((DSFptr = find_device_in_list(token)) == NULL) { 2002 1947 log_msg (4, "Can't find device %s in mounted file systems list", token); 2003 paranoid_free(tmp);1948 mr_free(tmp); 2004 1949 mr_free(token); 2005 1950 return (1); … … 2010 1955 mr_free(token); 2011 1956 } 2012 paranoid_free(tmp);2013 paranoid_free(mount_list);1957 mr_free(tmp); 1958 mr_free(mount_list); 2014 1959 } 2015 1960 … … 2047 1992 return (0); 2048 1993 } 2049 2050 2051 2052 1994 2053 1995 … … 2099 2041 log_to_screen("Archiving only the following file systems on %s:", token); 2100 2042 log_to_screen("==> %s", mounted_on_dsf); 2101 strcpy(bkpinfo->include_paths, "/"); 2043 mr_free(bkpinfo->include_paths); 2044 mr_asprintf(bkpinfo->include_paths, "%s", "/"); 2102 2045 if (strlen(not_mounted_on_dsf)) { 2103 2046 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf); … … 2136 2079 mr_asprintf(tmp,"|%s|",bkpinfo->include_paths); 2137 2080 if (strstr(tmp,tmp2) == NULL) { 2138 strcat(bkpinfo->include_paths,tmp1);2081 mr_strcat(bkpinfo->include_paths, "%s", tmp1); 2139 2082 } 2140 2083 mr_free(tmp1); … … 2181 2124 char *q = NULL; 2182 2125 char p[16*MAX_STR_LEN]; 2183 char *sz_size ;2184 char *command ;2126 char *sz_size = NULL; 2127 char *command = NULL; 2185 2128 char *compression_type = NULL; 2186 char *comment; 2187 char *prompt; 2129 char *comment = NULL; 2188 2130 int i; 2189 2131 FILE *fin; 2190 2132 2191 malloc_string(sz_size);2192 malloc_string(command);2193 malloc_string(comment);2194 malloc_string(prompt);2195 2133 malloc_string(tmp1); 2196 2134 assert(bkpinfo != NULL); 2197 sz_size[0] = '\0';2198 2135 bkpinfo->nonbootable_backup = FALSE; 2199 2136 … … 2232 2169 setup_scratchdir(tmp); 2233 2170 } 2234 log_msg(3, "media type = %s", 2235 bkptype_to_string(bkpinfo->backup_media_type)); 2171 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2236 2172 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 2237 bkpinfo->compression_level = 2238 (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2239 bkpinfo->use_lzo = 2240 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2173 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2174 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2241 2175 mvaddstr_and_log_it(2, 0, " "); 2242 2176 … … 2253 2187 if (archiving_to_media) { 2254 2188 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2255 if (ask_me_yes_or_no 2256 ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) 2257 { 2189 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) { 2258 2190 bkpinfo->manual_cd_tray = TRUE; 2259 2191 } … … 2263 2195 finish(1); 2264 2196 } 2265 if ((bkpinfo->compression_level = 2266 2197 2198 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2267 2199 log_to_screen("User has chosen not to backup the PC"); 2268 2200 finish(1); 2269 2201 } 2270 2202 mds = media_descriptor_string(bkpinfo->backup_media_type); 2271 sprintf(comment, "What speed is your %s (re)writer?", mds);2203 mr_asprintf(comment, "What speed is your %s (re)writer?", mds); 2272 2204 if (bkpinfo->backup_media_type == dvd) { 2273 2205 find_dvd_device(bkpinfo->media_device, FALSE); 2274 2206 strcpy(tmp1, "1"); 2275 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2207 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2276 2208 log_msg(1, "Setting to DVD defaults"); 2277 2209 } else { 2278 2210 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 2279 2211 strcpy(tmp1, "4"); 2280 strcpy(sz_size, "650");2212 mr_asprintf(sz_size, "%d", 650); 2281 2213 log_msg(1, "Setting to CD defaults"); 2282 2214 } … … 2284 2216 if (!popup_and_get_string("Speed", comment, tmp1, 4)) { 2285 2217 log_to_screen("User has chosen not to backup the PC"); 2218 mr_free(comment); 2286 2219 finish(1); 2287 2220 } 2288 2221 } 2222 mr_free(comment); 2289 2223 bkpinfo->cdrw_speed = atoi(tmp1); // if DVD then this shouldn't ever be used anyway :) 2290 2224 2291 s printf(comment,2292 2225 strcpy(tmp1, sz_size); 2226 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds); 2293 2227 mr_free(mds); 2294 if (!popup_and_get_string("Size", comment, sz_size, 5)) {2228 if (!popup_and_get_string("Size", comment, tmp1, 5)) { 2295 2229 log_to_screen("User has chosen not to backup the PC"); 2296 2230 finish(1); 2297 2231 } 2232 mr_asprintf(sz_size, "%s", tmp1); 2298 2233 bkpinfo->media_size = atoi(sz_size); 2234 2299 2235 if (bkpinfo->media_size <= 0) { 2300 2236 log_to_screen("User has chosen not to backup the PC"); … … 2308 2244 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) { 2309 2245 strcpy(bkpinfo->media_device, "/dev/cdrom"); 2310 log_msg(2, "CD-ROM device assumed to be at %s", 2311 bkpinfo->media_device); 2312 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) 2313 || bkpinfo->backup_media_type == dvd) { 2246 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device); 2247 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) { 2314 2248 if (!bkpinfo->media_device[0]) { 2315 2249 strcpy(bkpinfo->media_device, "/dev/cdrom"); 2316 2250 } // just for the heck of it :) 2317 log_msg(1, "bkpinfo->media_device = %s", 2318 bkpinfo->media_device); 2319 if (bkpinfo->backup_media_type == dvd 2320 || find_cdrom_device(bkpinfo->media_device, FALSE)) { 2321 log_msg(1, "bkpinfo->media_device = %s", 2322 bkpinfo->media_device); 2323 sprintf(comment, 2324 "Please specify your %s drive's /dev entry", mds); 2325 if (!popup_and_get_string 2326 ("Device?", comment, bkpinfo->media_device, 2327 MAX_STR_LEN / 4)) { 2251 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2252 if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) { 2253 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2254 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds); 2255 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) { 2328 2256 log_to_screen("User has chosen not to backup the PC"); 2329 2257 finish(1); … … 2399 2327 } else { 2400 2328 if (does_file_exist("/tmp/mondo-restore.cfg")) { 2401 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 2402 bkpinfo->media_device); 2329 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device); 2403 2330 } 2404 2331 } … … 2455 2382 finish(1); 2456 2383 } 2457 if ((bkpinfo->compression_level = 2458 which_compression_level()) == -1) { 2384 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2459 2385 log_to_screen("User has chosen not to backup the PC"); 2460 2386 finish(1); … … 2468 2394 /* Never try to eject a NETFS device */ 2469 2395 bkpinfo->please_dont_eject = TRUE; 2396 /* Force NFS to be the protocol by default */ 2397 if (bkpinfo->netfs_proto == NULL) { 2398 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 2399 } 2470 2400 2471 2401 /* Initiate bkpinfo netfs_mount path from running environment if not already done */ 2472 if (!bkpinfo->netfs_mount[0]) { 2473 strcpy(bkpinfo->netfs_mount, 2474 call_program_and_get_last_line_of_output 2475 ("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 2402 if (!bkpinfo->netfs_mount == NULL) { 2403 mr_asprintf(bkpinfo->netfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 2476 2404 } 2477 2405 #ifdef __FreeBSD__ … … 2484 2412 ("Network shared dir.", 2485 2413 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", 2486 bkpinfo->netfs_mount, MAX_STR_LEN / 4)) {2414 p, MAX_STR_LEN / 4)) { 2487 2415 log_to_screen("User has chosen not to backup the PC"); 2488 2416 finish(1); 2489 2417 } 2418 mr_free(bkpinfo->netfs_mount); 2419 mr_asprintf(bkpinfo->netfs_mount, "%s", p; 2490 2420 if (!bkpinfo->restore_data) { 2491 2421 if ((compression_type = which_compression_type()) == NULL) { … … 2493 2423 finish(1); 2494 2424 } 2495 if ((bkpinfo->compression_level = 2496 2425 2426 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2497 2427 log_to_screen("User has chosen not to backup the PC"); 2498 2428 finish(1); … … 2501 2431 // check whether already mounted - we better remove 2502 2432 // surrounding spaces and trailing '/' for this 2503 strip_spaces(bkpinfo->netfs_mount);2433 mr_strip_spaces(bkpinfo->netfs_mount); 2504 2434 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2505 2435 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; … … 2513 2443 strcpy(tmp1,bkpinfo->netfs_mount); 2514 2444 } 2515 sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);2445 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1); 2516 2446 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command)); 2447 mr_free(command); 2517 2448 2518 2449 if (!bkpinfo->restore_data) { 2519 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2520 sprintf(comment, 2521 "How much data (in Megabytes) will each media store?"); 2522 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 2450 mr_sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2451 mr_asprintf(comment, "How much data (in Megabytes) will each media store?"); 2452 strcpy(tmp1, sz_size); 2453 mr_free(sz_size); 2454 if (!popup_and_get_string("Size", comment, tmp1, 5)) { 2523 2455 log_to_screen("User has chosen not to backup the PC"); 2524 2456 finish(1); 2525 2457 } 2458 mr_free(comment); 2459 mr_asprintf(sz_size, "%s", tmp1); 2526 2460 } else { 2527 strcpy(sz_size, "0");2461 mr_asprintf(sz_size, "0"); 2528 2462 } 2529 2463 bkpinfo->media_size = atoi(sz_size); 2464 mr_free(sz_size); 2465 2530 2466 if (bkpinfo->media_size < 0) { 2531 2467 log_to_screen("User has chosen not to backup the PC"); … … 2533 2469 } 2534 2470 } 2535 /* Force NFS to be the protocol by default */2536 if (bkpinfo->netfs_proto == NULL) {2537 mr_asprintf(bkpinfo->netfs_proto, "nfs");2538 }2539 2471 if (bkpinfo->disaster_recovery) { 2540 sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);2472 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir); 2541 2473 paranoid_system(command); 2474 mr_free(command); 2475 2542 2476 } 2543 2477 strcpy(tmp1, bkpinfo->netfs_proto); 2544 if (!popup_and_get_string 2545 ("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?", 2546 tmp1, MAX_STR_LEN)) { 2478 if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) { 2547 2479 log_to_screen("User has chosen not to backup the PC"); 2548 2480 finish(1); … … 2550 2482 mr_free(bkpinfo->netfs_proto); 2551 2483 mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1); 2552 if (!popup_and_get_string 2553 ("Network share", "Which remote share should I mount?",2554 bkpinfo->netfs_mount, MAX_STR_LEN)) {2484 2485 strcpy(tmp1, bkpinfo->netfs_mount); 2486 if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) { 2555 2487 log_to_screen("User has chosen not to backup the PC"); 2556 2488 finish(1); 2557 2489 } 2490 mr_free(bkpinfo->netfs_mount); 2491 mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1); 2558 2492 2559 2493 if (bkpinfo->netfs_user) { … … 2562 2496 strcpy(tmp1, ""); 2563 2497 } 2564 if (!popup_and_get_string 2565 ("Network user", "Which user should I use if any ?", 2566 tmp1, MAX_STR_LEN)) { 2498 if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1)) { 2567 2499 log_to_screen("User has chosen not to backup the PC"); 2568 2500 finish(1); … … 2575 2507 /* Initiate bkpinfo isodir path from running environment if mount already done */ 2576 2508 if (is_this_device_mounted(bkpinfo->netfs_mount)) { 2577 strcpy(bkpinfo->isodir, 2578 call_program_and_get_last_line_of_output 2579 ("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2509 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2580 2510 } else { 2581 2511 sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir); 2582 sprintf(command, "mkdir -p %s", bkpinfo->isodir);2512 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir); 2583 2513 run_program_and_log_output(command, 5); 2514 mr_free(command); 2584 2515 2585 2516 if (bkpinfo->restore_data) { … … 2615 2546 } 2616 2547 if (!is_this_device_mounted(bkpinfo->netfs_mount)) { 2617 popup_and_OK 2618 ("Please mount that partition before you try to backup to or restore from it."); 2548 popup_and_OK("Please mount that partition before you try to backup to or restore from it."); 2619 2549 finish(1); 2620 2550 } … … 2640 2570 log_msg(3, "prefix set to %s", bkpinfo->prefix); 2641 2571 2642 log_msg(3, "Just set netfs_remote_dir to %s", 2643 bkpinfo->netfs_remote_dir); 2572 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir); 2644 2573 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2645 2574 break; … … 2659 2588 finish(1); 2660 2589 } 2661 if ((bkpinfo->compression_level = 2662 which_compression_level()) == -1) { 2590 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2663 2591 log_to_screen("User has chosen not to backup the PC"); 2664 2592 finish(1); 2665 2593 } 2666 sprintf( sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2594 sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2667 2595 if (!popup_and_get_string 2668 2596 ("ISO size.", 2669 2597 "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.", 2670 sz_size, 16)) {2598 tmp1, 16)) { 2671 2599 log_to_screen("User has chosen not to backup the PC"); 2672 2600 finish(1); 2673 2601 } 2674 bkpinfo->media_size = atoi( sz_size);2602 bkpinfo->media_size = atoi(tmp1); 2675 2603 } else { 2676 2604 bkpinfo->media_size = 650; … … 2723 2651 finish(1); 2724 2652 } 2725 if (does_string_exist_in_boot_block 2726 (bkpinfo->boot_device, "LILO")) { 2653 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { 2727 2654 i = 'L'; 2728 2655 } else 2729 if (does_string_exist_in_boot_block 2730 (bkpinfo->boot_device, "ELILO")) { 2656 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { 2731 2657 i = 'E'; 2732 2658 } else 2733 if (does_string_exist_in_boot_block 2734 (bkpinfo->boot_device, "GRUB")) { 2659 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { 2735 2660 i = 'G'; 2736 2661 } else { … … 2739 2664 #endif 2740 2665 if (i == 'U') { 2741 if (ask_me_yes_or_no 2742 ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) 2743 { 2666 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) { 2744 2667 i = 'R'; // raw 2745 2668 } else { 2746 log_to_screen 2747 ("I cannot find your boot loader. Please run mondoarchive with parameters."); 2669 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); 2748 2670 finish(1); 2749 2671 } … … 2751 2673 } 2752 2674 bkpinfo->boot_loader = i; 2753 strcpy(bkpinfo->include_paths, "/"); 2675 2676 mr_free(bkpinfo->include_paths); 2677 strcpy(tmp1, "/"); 2754 2678 if (!popup_and_get_string 2755 2679 ("Backup paths", 2756 2680 "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", 2757 bkpinfo->include_paths, MAX_STR_LEN)) {2681 tmp1, MAX_STR_LEN)) { 2758 2682 log_to_screen("User has chosen not to backup the PC"); 2759 2683 finish(1); 2760 2684 } 2685 mr_asprintf(bkpinfo->include_paths, "%s", tmp1); 2686 2761 2687 tmp = list_of_NETFS_mounts_only(); 2762 2688 if (strlen(tmp) > 2) { … … 2815 2741 if (ask_me_yes_or_no("Do you want to backup extended attributes?")) { 2816 2742 if (find_home_of_exe("getfattr")) { 2743 mr_free(g_getfattr); 2817 2744 mr_asprintf(g_getfattr,"getfattr"); 2818 2745 } 2819 2746 if (find_home_of_exe("getfacl")) { 2747 mr_free(g_getfacl); 2820 2748 mr_asprintf(g_getfacl,"getfacl"); 2821 2749 } … … 2835 2763 strcpy(bkpinfo->zip_exe, "gzip"); 2836 2764 strcpy(bkpinfo->zip_suffix, "gz"); 2837 //} else if (strcmp(compression_type,"lzma") == 0) {2765 } else if (strcmp(compression_type,"lzma") == 0) { 2838 2766 //strcpy(bkpinfo->zip_exe, "xy"); 2839 2767 //strcpy(bkpinfo->zip_suffix, "xy"); … … 2849 2777 ("Will you want to verify your backups after Mondo has created them?"); 2850 2778 2851 #ifndef __FreeBSD__2852 if (!ask_me_yes_or_no2853 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))2854 #endif2855 {2856 strcpy(bkpinfo->kernel_path, "FAILSAFE");2857 }2858 2859 2779 if (!ask_me_yes_or_no 2860 2780 ("Are you sure you want to proceed? Hit 'no' to abort.")) { … … 2875 2795 #else 2876 2796 if (bkpinfo->backup_media_type == netfs) { 2877 log_msg(3, "I think the Remote mount is mounted at %s", 2878 bkpinfo->isodir); 2797 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir); 2879 2798 } 2880 2799 log_it("isodir = %s", bkpinfo->isodir); 2881 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2800 if (bkpinfo->netfs_mount) { 2801 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2802 } 2803 if (bkpinfo->netfs_user) { 2804 log_it("netfs_user = '%s'", bkpinfo->netfs_user); 2805 } 2882 2806 if (bkpinfo->netfs_proto) { 2883 2807 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto); 2884 }2885 if (bkpinfo->netfs_user) {2886 log_it("netfs_user = '%s'", bkpinfo->netfs_user);2887 2808 } 2888 2809 #endif … … 2891 2812 log_it("media size = %ld", bkpinfo->media_size); 2892 2813 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2893 log_it("prefix = %s", bkpinfo->prefix); 2814 if (bkpinfo->prefix) { 2815 log_it("prefix = %s", bkpinfo->prefix); 2816 } 2894 2817 log_it("compression = %ld", bkpinfo->compression_level); 2895 2818 log_it("exclude_path = %s", bkpinfo->exclude_paths); … … 2897 2820 2898 2821 /* Handle devices passed in bkpinfo and print result */ 2899 /* the mr_make_devlist_from_pathlist function appends 2900 2822 /* the mr_make_devlist_from_pathlist function appends 2823 /* to the *_paths variables so copy before */ 2901 2824 mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E'); 2902 2825 mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I'); … … 2904 2827 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 2905 2828 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 2906 log_it("image_devs = '%s'", bkpinfo->image_devs); 2907 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, 2908 bkpinfo->boot_loader); 2829 if (bkpinfo->image_devs) { 2830 log_it("image_devs = '%s'", bkpinfo->image_devs); 2831 } 2832 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader); 2909 2833 if (bkpinfo->media_size < 0) { 2910 2834 if (archiving_to_media) { … … 2917 2841 paranoid_free(sz_size); 2918 2842 paranoid_free(tmp1); 2919 paranoid_free(command);2920 paranoid_free(comment);2921 paranoid_free(prompt);2922 2843 return (0); 2923 2844 } … … 3170 3091 3171 3092 malloc_string(current_drive); 3093 3094 /* UEFI is not supported here - but should be managed as a BIOS/UEFI option not a Boot Loader one per se */ 3172 3095 3173 3096 #ifdef __IA64__ -
branches/3.0/mondo/src/common/libmondo-fifo.c
r3185 r3188 85 85 wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32); 86 86 wise_lower_limit = 1; // wise_upper_limit/2 + 1; 87 paranoid_system("sync");87 sync(); 88 88 for (bufsize = wise_upper_limit, res = -1; 89 89 res != 0 && bufsize >= wise_lower_limit; bufsize--) { 90 mr_asprintf(tmp, 91 "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c", 92 internal_tape_block_size, bufsize, 'm'); 90 mr_asprintf(tmp,"dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c", internal_tape_block_size, bufsize, 'm'); 93 91 res = run_program_and_log_output(tmp, 2); 94 92 mr_free(tmp); … … 96 94 if (!res) { 97 95 bufsize++; 98 mr_asprintf(tmp, "Negotiated max buffer of %d MB ", bufsize); 99 log_to_screen(tmp); 100 mr_free(tmp); 96 log_to_screen(tmp, "Negotiated max buffer of %d MB ", bufsize); 101 97 } else { 102 98 bufsize = 0; … … 166 162 return; 167 163 } 168 paranoid_system("sync");164 sync(); 169 165 mr_asprintf(command, "ps %s | grep -F \"%s\" | grep -Fv grep | awk '{print $2;}' | grep -v PID | head -1", ps_options, g_sz_call_to_buffer); 170 166 log_msg(2, "kill_buffer() --- command = %s", command); -
branches/3.0/mondo/src/common/libmondo-filelist.c
r3185 r3188 86 86 87 87 /*@ pointers ********************** */ 88 char *ptr ;88 char *ptr = NULL; 89 89 FILE *fout; 90 90 … … 116 116 mr_free(tempfile); 117 117 118 log_it(bkpinfo->image_devs); 119 120 ptr = bkpinfo->image_devs; 121 122 malloc_string(dev); 123 while (ptr && *ptr) { 124 strcpy(dev, ptr); 125 log_it("Examining imagedev %s", dev); 126 for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++); 127 dev[i] = '\0'; 128 if (!strlen(dev)) { 129 continue; 130 } 131 fprintf(fout, "%s\n", dev); 132 log_it("Adding '%s' to biggielist", dev); 133 if ((ptr = strchr(ptr, ' '))) { 134 ptr++; 118 if (bkpinfo->image_devs) { 119 log_it("image_devs : %s", bkpinfo->image_devs); 120 121 ptr = bkpinfo->image_devs; 122 123 while (ptr && *ptr) { 124 mr_asprintf(dev, "%s", ptr); 125 log_it("Examining imagedev %s", dev); 126 for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++); 127 dev[i] = '\0'; 128 if (!strlen(dev)) { 129 mr_free(dev); 130 continue; 131 } 132 fprintf(fout, "%s\n", dev); 133 log_it("Adding '%s' to biggielist", dev); 134 if ((ptr = strchr(ptr, ' '))) { 135 ptr++; 136 } 137 mr_free(dev); 135 138 } 136 139 } … … 138 141 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 139 142 140 paranoid_free(dev);141 143 return (retval); 142 144 } … … 158 160 159 161 mr_asprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir); 160 161 162 mr_asprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE); 162 163 retval = system(command); … … 331 332 332 333 if (curr_set_no == 0) { 333 mr_asprintf(tmp, "Only one fileset. Fine.");334 log_msg(1, "Only one fileset. Fine."); 334 335 } else { 335 mr_asprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1); 336 } 337 log_msg(1, tmp); 338 mr_free(tmp); 336 log_msg(1, "Filelist divided into %ld sets", curr_set_no + 1); 337 } 339 338 close_evalcall_form(); 340 339 /* This is to work around an obscure bug in Newt; open a form, close it, … … 342 341 then update_progress_form() won't show the "time taken / time remaining" 343 342 line. The bug only crops up AFTER the call to chop_filelist(). Weird. */ 344 #ifndef _XWIN345 343 if (!g_text_mode) { 346 344 open_progress_form("", "", "", "", 100); … … 349 347 newtPopWindow(); 350 348 } 351 #endif352 349 return (err ? 0 : curr_set_no + 1); 353 350 } … … 410 407 int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout) 411 408 { 412 FILE *pattr; 413 char *tmp; 414 char *p; 409 FILE *pattr = NULL; 410 char *tmp = NULL; 415 411 416 412 pattr = popen(syscall, "r"); … … 424 420 return (2); 425 421 } 426 malloc_string(tmp); 427 for (p = fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr) && (p != NULL); 428 p = fgets(tmp, MAX_STR_LEN, pattr)) { 422 for (mr_getline(tmp, pattr); !feof(pattr); mr_getline(tmp, pattr)) { 429 423 fputs(tmp, pout); 430 } 424 mr_free(tmp); 425 } 426 mr_free(tmp); 431 427 paranoid_pclose(pattr); 432 paranoid_free(tmp);433 428 return (0); 434 429 } … … 439 434 char *auxlist_fname) 440 435 { 441 FILE *fin ;442 FILE *pout ;436 FILE *fin = NULL; 437 FILE *pout = NULL; 443 438 char *pout_command = NULL; 444 char *syscall ;445 char *file_to_analyze ;439 char *syscall = NULL; 440 char *file_to_analyze = NULL; 446 441 char *strtmp = NULL; 447 442 char *tmp = NULL; 448 char *p = NULL;449 443 int i; 450 444 … … 462 456 mr_free(pout_command); 463 457 464 malloc_string(file_to_analyze); 465 for (p = fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin) && (p != NULL); 466 p = fgets(file_to_analyze, MAX_STR_LEN, fin)) { 458 for (mr_getline(file_to_analyze, fin); !feof(fin); mr_getline(file_to_analyze, fin)) { 467 459 i = strlen(file_to_analyze); 468 460 if (i > 0 && file_to_analyze[i - 1] < 32) { … … 472 464 tmp = mr_stresc(file_to_analyze, "'", '\\', '\''); 473 465 mr_asprintf(syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp); // " MONDO_LOGFILE); 474 paranoid_free(tmp);466 mr_free(tmp); 475 467 log_msg(20,"calling %s\n",syscall); 476 468 call_exe_and_pipe_output_to_fd(syscall, pout); 477 paranoid_free(syscall); 478 } 469 mr_free(syscall); 470 mr_free(file_to_analyze); 471 } 472 mr_free(file_to_analyze); 479 473 paranoid_fclose(fin); 480 474 paranoid_pclose(pout); 481 paranoid_free(file_to_analyze);482 475 return (0); 483 476 } … … 522 515 char *syscall_pin = NULL; 523 516 char *syscall_pout = NULL; 524 char *incoming; 525 char *current_subset_file, *current_master_file; 517 char *incoming = NULL; 518 char *current_subset_file = NULL; 519 char *current_master_file = NULL; 526 520 char *masklist = NULL; 527 521 int retval = 0; 528 522 int i; 529 char *p, *q , *r;523 char *p, *q; 530 524 char *tmp = NULL; 531 525 FILE *pin, *pout, *faclin; 532 526 533 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 534 original_exat_fname, executable); 527 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable); 535 528 if (!orig_msklist || !orig_msklist[0] 536 529 || !does_file_exist(orig_msklist)) { … … 552 545 } 553 546 if (length_of_file(original_exat_fname) <= 0) { 554 log_msg(1, 555 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 556 original_exat_fname); 547 log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname); 557 548 return (0); 558 549 } 559 malloc_string(incoming);560 malloc_string(current_subset_file);561 malloc_string(current_master_file);562 550 mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir); 563 551 mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist); … … 566 554 567 555 sort_file(masklist); 568 current_subset_file[0] = current_master_file[0] = '\0';569 556 570 557 mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE); … … 599 586 // printf("Hi there. Starting the loop\n"); 600 587 601 r = fgets(current_subset_file, MAX_STR_LEN, faclin); 602 r = fgets(incoming, MAX_STR_LEN, pin); 603 while (!feof(pin) && !feof(faclin) && (r != NULL)) { 604 // printf("incoming = %s", incoming); 605 606 strcpy(current_master_file, incoming + 8); 588 mr_getline(current_subset_file, faclin); 589 mr_getline(incoming, pin); 590 while (!feof(pin) && !feof(faclin)) { 591 mr_asprintf(current_master_file, "%s", incoming + 8); 607 592 608 593 p = current_subset_file; … … 632 617 if (i < 0) { // read another subset file in. 633 618 log_msg(my_depth, "Reading next subset line in\n\n"); 634 r = fgets(current_subset_file, MAX_STR_LEN, faclin); 619 mr_free(current_subset_file); 620 mr_getline(current_subset_file, faclin); 635 621 continue; 636 622 } … … 639 625 fputs(incoming, pout); 640 626 } 641 r = fgets(incoming, MAX_STR_LEN, pin); 627 mr_free(incoming); 628 mr_getline(incoming, pin); 642 629 if (!i) { 643 630 log_msg(my_depth, "Copying master %s", q); 644 631 } 645 // if (!i) { printf("Match --- %s\n", q); }646 632 647 633 while (!feof(pin) && strncmp(incoming, "# file: ", 8)) { 648 634 if (!i) { 649 650 // printf("%s", incoming);651 652 635 fputs(incoming, pout); 653 636 } 654 r = fgets(incoming, MAX_STR_LEN, pin); 637 mr_free(incoming); 638 mr_getline(incoming, pin); 655 639 } 656 640 if (!i) { 657 r = fgets(current_subset_file, MAX_STR_LEN, faclin); 658 } 659 } 660 while (!feof(pin)) { 661 r = fgets(incoming, MAX_STR_LEN, pin); 662 } 641 mr_free(current_subset_file); 642 mr_getline(current_subset_file, faclin); 643 } 644 mr_free(current_master_file); 645 } 646 mr_free(current_subset_file); 647 mr_free(incoming); 663 648 fclose(faclin); 664 649 pclose(pin); 665 650 pclose(pout); 666 651 667 // printf("OK, loop is done\n");668 669 652 unlink(masklist); 670 653 mr_free(masklist); 671 654 672 paranoid_free(current_subset_file);673 paranoid_free(current_master_file);674 paranoid_free(incoming);675 655 return (retval); 676 656 } … … 770 750 noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */ 771 751 772 /* walk across tree if necessary */752 /* walk across tree if necessary */ 773 753 node = startnode; 774 754 char_to_add = string_to_add[0]; … … 779 759 } 780 760 781 /* walk down tree if appropriate */761 /* walk down tree if appropriate */ 782 762 if (node->down != NULL && node->ch == char_to_add) { 783 763 log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add); … … 793 773 } 794 774 795 /* add here */775 /* add here */ 796 776 if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) { 797 777 log_to_screen("failed to malloc"); … … 864 844 /*@ buffers **************************************************** */ 865 845 char *command_to_open_fname = NULL; 866 char fname[MAX_STR_LEN];867 char tmp[MAX_STR_LEN];846 char *fname = NULL; 847 char *tmp = NULL; 868 848 char *tmp1 = NULL; 869 849 int pos_in_fname; … … 911 891 912 892 open_evalcall_form("Loading filelist from disk"); 913 for (tmp1 = fgets(fname, MAX_STR_LEN, pin); !feof(pin); 914 tmp1 = fgets(fname, MAX_STR_LEN, pin)) { 915 if (((fname[strlen(fname) - 1] == 13) || (fname[strlen(fname) - 1] == 10)) && (strlen(fname) > 0)) { 893 for (mr_getline(fname, pin); !feof(pin); mr_getline(fname, pin)) { 894 if ((strlen(fname) > 0) && (fname[strlen(fname) - 1] == 13 || fname[strlen(fname) - 1] == 10)) { 916 895 fname[strlen(fname) - 1] = '\0'; 917 896 } 918 // strip_spaces (fname);919 897 if (!strlen(fname)) { 898 mr_free(fname); 920 899 continue; 921 900 } … … 924 903 continue; 925 904 } 926 strcpy(tmp, fname);905 mr_asprintf(tmp, "%s", fname); 927 906 tmp[pos_in_fname] = '\0'; 928 907 if (strlen(tmp)) { 929 908 add_string_at_node(filelist, tmp); 930 909 } 910 mr_free(tmp); 931 911 } 932 912 add_string_at_node(filelist, fname); 913 933 914 if (!(++lino % 1111)) { 934 915 percentage = (int) (lino * 100 / lines_in_filelist); 935 916 update_evalcall_form(percentage); 936 917 } 937 } 918 mr_free(fname); 919 } 920 mr_free(fname); 921 938 922 paranoid_pclose(pin); 939 923 close_evalcall_form(); … … 1297 1281 1298 1282 1299 1300 1301 1283 /** 1302 1284 * Number of entries in the skeleton filelist. … … 1314 1296 * @bug Return value should be @c void. 1315 1297 */ 1316 int open_and_list_dir(char *dir1, char *sth, FILE * fout, 1317 time_t time_of_last_full_backup) 1318 { 1298 int open_and_list_dir(char *dir1, char *sth, FILE * fout, time_t time_of_last_full_backup) { 1299 1319 1300 const char delims[] = "|"; 1320 1301 … … 1323 1304 struct stat statbuf; 1324 1305 char *new; 1325 char *tmp ;1306 char *tmp = NULL; 1326 1307 char *dir = NULL; 1327 1308 static int percentage = 0; 1328 char *skip_these ;1309 char *skip_these = NULL; 1329 1310 char *new_with_pipe; 1330 1311 char *strtmp = NULL; 1331 1312 char *token = NULL; 1332 1313 char *find_excludes = NULL; 1333 static char *name_of_evalcall_form; 1314 char *name_of_evalcall_form = NULL; 1315 char *find_skeleton_marker = NULL; 1334 1316 int i; 1335 1317 int lastpos = 0; … … 1338 1320 static int counter = 0; 1339 1321 static int uberctr = 0; 1340 static char *find_skeleton_marker; 1341 static long skeleton_lino = 0; 1342 static time_t last_time = 0; 1322 static long skeleton_lino = 0L; 1323 static time_t last_time = (time_t)0; 1343 1324 time_t this_time; 1344 1325 … … 1355 1336 1356 1337 if (!depth) { 1357 malloc_string(name_of_evalcall_form);1358 malloc_string(find_skeleton_marker);1359 1338 while((token = mr_strtok(sth, delims, &lastpos)) != NULL) { 1360 1339 mr_strcat(find_excludes," -path %s -prune -o", token); … … 1375 1354 mr_asprintf(strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist); 1376 1355 #endif 1377 paranoid_free(find_excludes); 1356 mr_free(find_excludes); 1357 1378 1358 log_msg(5, "find command = %s", strtmp); 1379 1359 paranoid_system(strtmp); 1380 paranoid_free(strtmp); 1360 mr_free(strtmp); 1361 1381 1362 mr_asprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist); 1382 g_skeleton_entries = 1383 1 + atol(call_program_and_get_last_line_of_output(tmp));1384 paranoid_free(tmp); 1385 sprintf(name_of_evalcall_form, "Making catalog of %s", dir1);1363 g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp)); 1364 mr_free(tmp); 1365 1366 mr_asprintf(name_of_evalcall_form, "Making catalog of %s", dir1); 1386 1367 open_evalcall_form(name_of_evalcall_form); 1387 find_skeleton_marker[0] = '\0'; 1368 mr_free(name_of_evalcall_form); 1369 1388 1370 skeleton_lino = 1; 1389 1371 log_msg(5, "entries = %ld", g_skeleton_entries); … … 1391 1373 } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate 1392 1374 { 1393 sprintf(find_skeleton_marker, 1394 "grep -Fv '%s' %s > %s.new 2> /dev/null", dir, 1395 g_skeleton_filelist, g_skeleton_filelist); 1396 // log_msg(0, "fsm = %s", find_skeleton_marker); 1375 mr_asprintf(find_skeleton_marker, "grep -Fv '%s' %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist); 1397 1376 if (!system(find_skeleton_marker)) { 1398 1377 percentage = (int) (skeleton_lino * 100 / g_skeleton_entries); 1399 1378 skeleton_lino++; 1400 // log_msg(5, "Found %s", dir); 1401 // log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage); 1402 sprintf(find_skeleton_marker, "mv -f %s.new %s", 1403 g_skeleton_filelist, g_skeleton_filelist); 1404 // log_msg(6, "fsm = %s", find_skeleton_marker); 1379 mr_free(find_skeleton_marker); 1380 1381 mr_asprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist); 1405 1382 paranoid_system(find_skeleton_marker); 1406 1383 time(&this_time); 1407 1384 if (this_time != last_time) { 1408 1385 last_time = this_time; 1409 #ifndef _XWIN1410 1386 if (!g_text_mode) { 1411 1387 int cols, rows; … … 1415 1391 mr_free(tmp); 1416 1392 } 1417 #endif1418 1393 update_evalcall_form(percentage); 1419 1394 } 1420 1395 } 1396 mr_free(find_skeleton_marker); 1421 1397 } 1422 1398 … … 1430 1406 mr_asprintf(tmp,"opendir %s", dir1); 1431 1407 log_OS_error(tmp); 1432 paranoid_free(tmp);1408 mr_free(tmp); 1433 1409 } else if (strstr(skip_these, new_with_pipe)) { 1434 1410 log_msg(10, "Found dir ***%s**** excluded", dir1); … … 1444 1420 mr_asprintf(new,"%s%s",dir1,dit->d_name); 1445 1421 } 1446 paranoid_free(new_with_pipe);1422 mr_free(new_with_pipe); 1447 1423 mr_asprintf(new_with_pipe, "|%s|", new); 1448 1424 if (strstr(skip_these, new_with_pipe)) { 1449 1425 fprintf(fout, "%s\n", new); 1450 1426 log_msg(10, "Found child dir ***%s**** excluded", new); 1451 paranoid_free(new_with_pipe);1427 mr_free(new_with_pipe); 1452 1428 } else { 1453 paranoid_free(new_with_pipe);1429 mr_free(new_with_pipe); 1454 1430 if (!lstat(new, &statbuf)) { 1455 1431 if (!S_ISLNK(statbuf.st_mode) 1456 1432 && S_ISDIR(statbuf.st_mode)) { 1457 1433 log_msg(10, "Found child dir ***%s**** parsed", new); 1458 open_and_list_dir(new, skip_these, fout, 1459 time_of_last_full_backup); 1434 open_and_list_dir(new, skip_these, fout, time_of_last_full_backup); 1460 1435 } else { 1461 if (time_of_last_full_backup == 0 1462 || time_of_last_full_backup < 1463 statbuf.st_ctime) { 1436 if (time_of_last_full_backup == 0 || time_of_last_full_backup < statbuf.st_ctime) { 1464 1437 log_msg(10, "Found child file ***%s**** parsed", new); 1465 1438 fprintf(fout, "%s\n", new); … … 1468 1441 uberctr++; 1469 1442 mr_asprintf(tmp, " %c ", special_dot_char(uberctr)); 1470 #ifndef _XWIN1471 1443 if (!g_text_mode) { 1472 newtDrawRootText(77, g_noof_rows - 3, 1473 tmp); 1444 newtDrawRootText(77, g_noof_rows - 3, tmp); 1474 1445 newtRefresh(); 1475 1446 } 1476 #endif 1477 paranoid_free(tmp); 1447 mr_free(tmp); 1478 1448 } 1479 1449 } … … 1481 1451 } 1482 1452 } 1483 paranoid_free(new);1484 } 1485 } 1486 paranoid_free(new_with_pipe);1487 paranoid_free(skip_these);1453 mr_free(new); 1454 } 1455 } 1456 mr_free(new_with_pipe); 1457 mr_free(skip_these); 1488 1458 mr_free(dir); 1489 1459 … … 1496 1466 if (!depth) { 1497 1467 close_evalcall_form(); 1498 paranoid_free(name_of_evalcall_form);1499 paranoid_free(find_skeleton_marker);1500 1468 unlink(g_skeleton_filelist); 1501 1469 log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries); … … 1525 1493 char *p, *q; 1526 1494 char *sz_datefile; 1527 char *sz_filelist , *tmp;1495 char *sz_filelist; 1528 1496 char *exclude_paths = NULL; 1529 1497 FILE *fout; … … 1534 1502 char *tmp2 = NULL; 1535 1503 1536 malloc_string(tmp);1537 malloc_string(g_skeleton_filelist);1538 1504 mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0); 1539 1505 if (!include_paths && !userdef_filelist) { 1540 fatal_error 1541 ("Please supply either include_paths or userdef_filelist"); 1542 } 1543 // make hole for filelist 1506 fatal_error("Please supply either include_paths or userdef_filelist"); 1507 } 1508 // make hole for filelist 1544 1509 mr_asprintf(command, "mkdir -p %s/archives", scratchdir); 1545 1510 paranoid_system(command); … … 1557 1522 // backup last known good datefile just in case :) 1558 1523 if (does_file_exist(sz_datefile)) { 1559 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, 1560 sz_datefile); 1524 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile); 1561 1525 paranoid_system(command); 1562 1526 mr_free(command); … … 1567 1531 ("date +%s")); 1568 1532 } else if (lstat(sz_datefile, &statbuf)) { 1569 log_msg(2, 1570 "Warning - unable to find date of previous backup. Full backup instead."); 1533 log_msg(2, "Warning - unable to find date of previous backup. Full backup instead."); 1571 1534 differential = 0; 1572 1535 time_of_last_full_backup = 0; … … 1579 1542 // use user-specified filelist (if specified) 1580 1543 if (userdef_filelist) { 1581 log_msg(1, 1582 "Using the user-specified filelist - %s - instead of calculating one", 1583 userdef_filelist); 1544 log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist); 1584 1545 mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist); 1585 1546 if (run_program_and_log_output(command, 3)) { … … 1589 1550 mr_free(command); 1590 1551 } else { 1591 log_msg(2, "include_paths = '%s'", include_paths); 1552 if (include_paths) { 1553 log_msg(2, "include_paths = '%s'", include_paths); 1554 } 1592 1555 log_msg(1, "Calculating filelist"); 1593 1556 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'")); … … 1597 1560 log_msg(2, "Found windows FS: %s",tmp2); 1598 1561 mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2); 1599 paranoid_free(tmp2);1562 mr_free(tmp2); 1600 1563 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1)); 1601 1564 log_msg(2, "Found windows files: %s",tmp2); 1602 1565 } 1603 paranoid_free(tmp1);1566 mr_free(tmp1); 1604 1567 1605 1568 mr_asprintf(exclude_paths, MONDO_CACHE"|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/run|/dev/shm|"MINDI_CACHE, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir); … … 1607 1570 mr_strcat(exclude_paths,"|%s",excp); 1608 1571 } 1609 paranoid_free(tmp2);1572 mr_free(tmp2); 1610 1573 1611 1574 log_msg(2, "Excluding paths = '%s'", exclude_paths); 1612 log_msg(2, 1613 "Generating skeleton filelist so that we can track our progress"); 1614 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir); 1575 log_msg(2, "Generating skeleton filelist so that we can track our progress"); 1576 mr_asprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir); 1615 1577 make_hole_for_file(g_skeleton_filelist); 1578 1616 1579 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries); 1617 1580 log_msg(2, "Opening out filelist to %s", sz_filelist); … … 1619 1582 fatal_error("Cannot openout to sz_filelist"); 1620 1583 } 1621 if ( strlen(include_paths) == 0) {1584 if ((include_paths != NULL) && (strlen(include_paths) == 0)) { 1622 1585 log_msg(1, "Including only '/' in %s", sz_filelist); 1623 1586 open_and_list_dir("/", exclude_paths, fout, … … 1637 1600 } 1638 1601 } 1602 mr_free(exclude_paths); 1639 1603 paranoid_fclose(fout); 1640 1604 } … … 1654 1618 paranoid_free(sz_filelist); 1655 1619 log_msg(2, "Freeing variables"); 1656 paranoid_free(exclude_paths); 1657 paranoid_free(tmp); 1658 paranoid_free(g_skeleton_filelist); 1620 mr_free(g_skeleton_filelist); 1659 1621 log_msg(2, "Exiting"); 1660 1622 return (0); 1661 1623 } 1624 1662 1625 1663 1626 /** … … 1680 1643 1681 1644 assert(bkpinfo != NULL); 1682 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, 1683 bkpinfo->scratchdir); 1645 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir); 1684 1646 if (bkpinfo->make_filelist) { 1685 1647 mvaddstr_and_log_it(g_currentY, 0, … … 1792 1754 FILE *fin; 1793 1755 FILE *fout; 1794 char *fname; 1795 char *tmp; 1796 size_t len = 0; // Scrub's patch doesn't work without that 1797 1798 // log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE"); 1799 malloc_string(fname); 1800 malloc_string(tmp); 1756 char *fname = NULL; 1757 char *tmp = NULL; 1758 1801 1759 log_msg(5, "starting"); 1802 1760 log_msg(5, "needles_list_fname = %s", needles_list_fname); … … 1809 1767 } 1810 1768 while (!feof(fin)) { 1811 // fscanf(fin, "%s\n", fname); 1812 len = MAX_STR_LEN - 1; 1813 if (getline(&fname, &len, fin)) { 1814 // FIXME 1815 } 1769 mr_getline(fname, fin); 1816 1770 if (!use_star) { 1817 1771 if (fname[0] == '/') { 1818 strcpy(tmp, fname);1772 mr_asprintf(tmp, "%s", fname); 1819 1773 } else { 1820 tmp[0] = '/'; 1821 strcpy(tmp + 1, fname); 1774 mr_asprintf(tmp, "/%s", fname); 1822 1775 } 1823 strcpy(fname, tmp); 1776 mr_free(fname); 1777 fname = tmp; 1824 1778 } 1825 1779 while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) { … … 1832 1786 if (found_node->selected) { 1833 1787 if (fname[0] == '/') { 1834 strcpy(tmp, fname + 1); 1835 strcpy(fname, tmp); 1788 mr_asprintf(tmp, "%s", fname + 1); 1789 mr_free(fname); 1790 fname = tmp; 1836 1791 } 1837 1792 log_msg(5, "Found '%s'", fname); 1838 turn_wildcard_chars_into_literal_chars(tmp, fname); 1839 fprintf(fout, "%s\n", tmp); 1793 tmp = mr_stresc(fname, "[]*?", '\\', "'"); 1794 mr_free(fname); 1795 fname = tmp; 1796 fprintf(fout, "%s\n", fname); 1840 1797 retval++; 1841 1798 } 1842 1799 } 1800 mr_free(fname); 1843 1801 } 1844 1802 paranoid_fclose(fout); 1845 1803 paranoid_fclose(fin); 1846 paranoid_free(fname);1847 paranoid_free(tmp);1848 1804 return (retval); 1849 1805 } 1850 1851 1852 1853 1806 1854 1807 … … 1865 1818 char *list_of_files_fname, bool flag_em) 1866 1819 { 1867 FILE *fin; 1868 char *tmp; 1869 char *p; 1870 struct s_node *nod; 1871 1872 malloc_string(tmp); 1820 FILE *fin = NULL; 1821 char *tmp = NULL; 1822 struct s_node *nod = NULL; 1823 1873 1824 log_msg(3, "Adding %s to filelist", list_of_files_fname); 1874 1825 if (!(fin = fopen(list_of_files_fname, "r"))) { … … 1876 1827 return (1); 1877 1828 } 1878 for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL); 1879 p = fgets(tmp, MAX_STR_LEN, fin)) { 1829 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) { 1880 1830 if (!tmp[0]) { 1831 mr_free(tmp); 1881 1832 continue; 1882 1833 } 1883 if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10) 1884 && strlen(tmp) > 0) { 1834 if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)) { 1885 1835 tmp[strlen(tmp) - 1] = '\0'; 1886 1836 } 1887 1837 log_msg(2, "tmp = '%s'", tmp); 1888 1838 if (!tmp[0]) { 1839 mr_free(tmp); 1889 1840 continue; 1890 1841 } … … 1900 1851 log_msg(5, "Flagged '%s'", tmp); 1901 1852 } 1902 } 1853 mr_free(tmp); 1854 } 1855 mr_free(tmp); 1903 1856 paranoid_fclose(fin); 1904 paranoid_free(tmp);1905 1857 return (0); 1906 1858 } -
branches/3.0/mondo/src/common/libmondo-files-EXT.h
r2904 r3188 41 41 42 42 43 extern int make_hole_for_dir(c har *outdir_fname);43 extern int make_hole_for_dir(const char *outdir_fname); 44 44 45 45 extern long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); -
branches/3.0/mondo/src/common/libmondo-files.c
r3150 r3188 47 47 /*@ buffers ***************************************************** */ 48 48 static char output[MAX_STR_LEN]; 49 char command[MAX_STR_LEN * 2]; 50 char tmp[MAX_STR_LEN]; 49 char *command = NULL; 51 50 52 51 /*@ pointers **************************************************** */ 53 char *p ;52 char *p = NULL; 54 53 char *q; 55 54 FILE *fin; … … 63 62 assert_string_is_neither_NULL_nor_zerolength(filename); 64 63 if (does_file_exist(filename)) { 65 sprintf(command, "md5sum \"%s\"", filename);64 mr_asprintf(command, "md5sum \"%s\"", filename); 66 65 fin = popen(command, "r"); 67 66 if (fin) { … … 73 72 paranoid_pclose(fin); 74 73 } 74 mr_free(command); 75 75 } else { 76 sprintf(tmp, "File '%s' not found; cannot calc checksum", 77 filename); 78 log_it(tmp); 76 log_it("File '%s' not found; cannot calc checksum", filename); 79 77 } 80 78 if (p) { … … 130 128 131 129 /*@ buffers ***************************************************** */ 132 char command[MAX_STR_LEN * 2]; 133 char incoming[MAX_STR_LEN]; 134 char tmp[MAX_STR_LEN]; 135 char *q; 130 char *command = NULL; 131 char *incoming = NULL; 136 132 137 133 /*@ long ******************************************************** */ … … 141 137 FILE *fin; 142 138 143 /*@ initialize [0] to null ******************************************** */144 incoming[0] = '\0';145 146 139 assert_string_is_neither_NULL_nor_zerolength(filename); 147 140 if (!does_file_exist(filename)) { 148 sprintf(tmp, 149 "%s does not exist, so I cannot found the number of lines in it", 150 filename); 151 log_it(tmp); 141 log_it("%s does not exist, so I cannot found the number of lines in it", filename); 152 142 return (0); 153 143 } 154 sprintf(command, "cat %s | wc -l", filename);144 mr_asprintf(command, "cat %s | wc -l", filename); 155 145 if (!does_file_exist(filename)) { 146 mr_free(command); 156 147 return (-1); 157 148 } 158 149 fin = popen(command, "r"); 150 mr_free(command); 151 159 152 if (fin) { 160 153 if (feof(fin)) { 161 154 noof_lines = 0; 162 155 } else { 163 q = fgets(incoming, MAX_STR_LEN - 1, fin); 164 if (!q) { 165 // FIXME 166 } 167 while (strlen(incoming) > 0 && (q != NULL) 168 && incoming[strlen(incoming) - 1] < 32) { 156 mr_getline(incoming, fin); 157 while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) { 169 158 incoming[strlen(incoming) - 1] = '\0'; 170 159 } 171 160 noof_lines = atol(incoming); 161 mr_free(incoming); 172 162 } 173 163 paranoid_pclose(fin); … … 215 205 void exclude_nonexistent_files(char *inout) 216 206 { 217 char infname[MAX_STR_LEN]; 218 char outfname[MAX_STR_LEN]; 219 char tmp[MAX_STR_LEN]; 220 char incoming[MAX_STR_LEN]; 221 char *q; 207 char *infname = NULL; 208 char *outfname = NULL; 209 char *tmp = NULL; 210 char *incoming = NULL; 222 211 223 212 /*@ int ********************************************************* */ … … 231 220 232 221 assert_string_is_neither_NULL_nor_zerolength(inout); 233 sprintf(infname, "%s.in", inout); 234 sprintf(outfname, "%s", inout); 235 sprintf(tmp, "cp -f %s %s", inout, infname); 222 mr_asprintf(infname, "%s.in", inout); 223 mr_asprintf(tmp, "cp -f %s %s", inout, infname); 236 224 run_program_and_log_output(tmp, FALSE); 225 mr_free(tmp); 226 237 227 if (!(fin = fopen(infname, "r"))) { 238 228 log_OS_error("Unable to openin infname"); 229 mr_free(infname); 239 230 return; 240 231 } 232 233 mr_asprintf(outfname, "%s", inout); 241 234 if (!(fout = fopen(outfname, "w"))) { 242 235 log_OS_error("Unable to openout outfname"); 236 mr_free(infname); 237 mr_free(outfname); 243 238 return; 244 239 } 245 for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); 246 q = fgets(incoming, MAX_STR_LEN, fin)) { 240 mr_free(outfname); 241 242 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 247 243 i = strlen(incoming) - 1; 248 244 if (i >= 0 && incoming[i] < 32) { … … 252 248 fprintf(fout, "%s\n", incoming); 253 249 } else { 254 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming); 255 log_it(tmp); 256 } 257 } 250 log_it("Excluding '%s'-nonexistent\n", incoming); 251 } 252 mr_free(incoming); 253 } 254 mr_free(incoming); 255 258 256 paranoid_fclose(fout); 259 257 paranoid_fclose(fin); 260 258 unlink(infname); 261 } 262 263 264 265 266 267 268 259 mr_free(infname); 260 } 269 261 270 262 … … 278 270 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 279 271 { 280 char tmp[MAX_STR_LEN];281 char *command ;272 char *tmp = NULL; 273 char *command = NULL; 282 274 283 275 if (!kernel[0]) { 284 strcpy(kernel, 285 call_program_and_get_last_line_of_output 286 ("mindi --findkernel 2> /dev/null")); 276 strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null")); 287 277 } 288 278 // If we didn't get anything back, check whether mindi raised a fatal error 289 279 if (!kernel[0]) { 290 malloc_string(command); 291 strcpy(command, "grep 'Fatal error' /var/log/mindi.log"); 292 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 280 mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log"); 281 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 293 282 if (strlen(tmp) > 1) { 294 283 popup_and_OK(tmp); 284 mr_free(tmp); 285 mr_free(command); 295 286 fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'."); 296 287 } 297 paranoid_free(command); 288 mr_free(tmp); 289 mr_free(command); 298 290 } 299 291 log_it("Calling Mindi with kernel path of '%s'", kernel); … … 310 302 ("Kernel not found. Please specify with the '-k' flag."); 311 303 } 312 sprintf(tmp, "User says kernel is at %s", kernel); 313 log_it(tmp); 304 log_it("User says kernel is at %s", kernel); 314 305 } 315 306 return (0); 316 307 } 317 318 319 320 321 308 322 309 … … 334 321 /*@ buffers ********************* */ 335 322 static char output[MAX_STR_LEN]; 336 char *incoming; 337 char *command; 338 339 malloc_string(incoming); 340 malloc_string(command); 341 incoming[0] = '\0'; 323 char *incoming = NULL; 324 char *command = NULL; 325 342 326 /*@******************************* */ 343 327 344 328 assert_string_is_neither_NULL_nor_zerolength(fname); 345 sprintf(command, "which %s 2> /dev/null", fname); 346 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 329 mr_asprintf(command, "which %s 2> /dev/null", fname); 330 mr_asprintf(incoming, call_program_and_get_last_line_of_output(command)); 331 mr_free(command); 332 347 333 if (incoming[0] == '\0') { 348 334 if (system("which file > /dev/null 2> /dev/null")) { 349 paranoid_free(incoming); 350 paranoid_free(command); 335 mr_free(incoming); 351 336 output[0] = '\0'; 352 337 return (NULL); // forget it :) 353 338 } 354 sprintf(command, 355 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", 356 incoming); 357 strcpy(incoming, 358 call_program_and_get_last_line_of_output(command)); 359 } 360 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 361 { 362 sprintf(command, "dirname %s 2> /dev/null", incoming); 363 strcpy(incoming, 364 call_program_and_get_last_line_of_output(command)); 339 mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming); 340 mr_free(incomig); 341 342 mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command)); 343 mr_free(command); 344 } 345 if (incoming[0] == '\0') { 346 mr_asprintf(command, "dirname %s 2> /dev/null", incoming); 347 mr_free(incoming); 348 349 mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command)); 350 mr_free(command); 365 351 } 366 352 strcpy(output, incoming); 367 353 if (output[0] != '\0' && does_file_exist(output)) { 368 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 369 incoming); 354 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming); 370 355 } else { 371 356 output[0] = '\0'; 372 357 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 373 358 } 374 paranoid_free(incoming); 375 paranoid_free(command); 359 mr_free(incoming); 376 360 if (!output[0]) { 377 361 return (NULL); … … 382 366 383 367 384 385 386 387 388 389 390 368 /** 391 369 * Get the last sequence of digits surrounded by non-digits in the first 32k of … … 421 399 for (; len > 0 && isdigit(datablock[len - 1]); len--); 422 400 trackno = atoi(datablock + len); 423 /*424 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);425 log_it(tmp);426 */427 401 return (trackno); 428 402 } … … 444 418 445 419 /*@ buffers ***************************************************** */ 446 char tmp[MAX_STR_LEN]; 447 char lastline[MAX_STR_LEN]; 448 char command[MAX_STR_LEN]; 420 char *lastline = NULL; 421 char *command = NULL; 449 422 /*@ pointers **************************************************** */ 450 char *p ;423 char *p = NULL; 451 424 452 425 /*@ int's ******************************************************* */ 453 int i; 454 455 for (i = NOOF_ERR_LINES - 1; 456 i >= 0 && !strstr(err_log_lines[i], "% Done") 457 && !strstr(err_log_lines[i], "% done"); i--); 426 int i = 0; 427 428 for (i = NOOF_ERR_LINES - 1; i >= 0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--); 458 429 if (i < 0) { 459 sprintf(command, 460 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", 461 filename, '%'); 462 strcpy(lastline, 463 call_program_and_get_last_line_of_output(command)); 430 mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%'); 431 mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command)); 432 mr_free(command); 464 433 if (!lastline[0]) { 434 mr_free(lastline); 465 435 return (0); 466 436 } 467 437 } else { 468 strcpy(lastline, err_log_lines[i]);438 mr_asprintf(lastline, "%s", err_log_lines[i]); 469 439 } 470 440 … … 472 442 if (p) { 473 443 *p = '\0'; 474 } 475 // log_msg(2, "lastline='%s', ", p, lastline); 476 if (!p) { 444 } else { 445 mr_free(lastline); 477 446 return (0); 478 447 } 479 *p = '\0'; 480 for (p--; *p != ' '&& p != lastline; p--);448 449 for (p--; isdigit(*p) && p != lastline; p--); 481 450 if (p != lastline) { 482 451 p++; 483 452 } 484 453 i = atoi(p); 485 486 sprintf(tmp, "'%s' --> %d", p, i); 487 // log_to_screen(tmp); 488 454 mr_free(lastline); 489 455 return (i); 490 456 } … … 504 470 /*@ buffers ***************************************************** */ 505 471 static char output[MAX_STR_LEN]; 506 static char command[MAX_STR_LEN * 2]; 507 static char tmp[MAX_STR_LEN]; 508 char *p = NULL; 472 char *command = NULL; 509 473 510 474 /*@ pointers **************************************************** */ … … 514 478 515 479 if (!does_file_exist(filename)) { 516 sprintf(tmp, "Tring to get last line of nonexistent file (%s)", 517 filename); 518 log_it(tmp); 480 log_it("Tring to get last line of nonexistent file (%s)", filename); 519 481 output[0] = '\0'; 520 482 return (output); 521 483 } 522 sprintf(command, "tail -n1 %s", filename);484 mr_asprintf(command, "tail -n1 %s", filename); 523 485 fin = popen(command, "r"); 486 mr_free(command); 524 487 p = fgets(output, MAX_STR_LEN, fin); 525 488 if (p == NULL) { … … 564 527 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed. 565 528 */ 566 int 567 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) 568 { 529 int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) { 569 530 /*@ pointers **************************************************** */ 570 531 FILE *fin; … … 577 538 578 539 /*@ buffer ****************************************************** */ 579 char stub_fname[1000]; 580 char curr_fname[1000]; 581 char curr_cksum[1000]; 582 char tmp[1000]; 583 char *q; 540 char *stub_fname = NULL; 541 char *curr_fname = NULL; 542 char *curr_cksum = NULL; 543 char *tmp = NULL; 584 544 585 545 /*@ long [long] ************************************************* */ … … 595 555 start_time = get_time(); 596 556 filelist_length = length_of_file(filelist); 597 sprintf(tmp,"filelist = %s; cksumlist = %s", filelist, cksumlist);598 log_it(tmp); 557 log_it("filelist = %s; cksumlist = %s", filelist, cksumlist); 558 599 559 fin = fopen(filelist, "r"); 600 560 if (fin == NULL) { … … 610 570 return (1); 611 571 } 612 for (q = fgets(stub_fname, 999, fin); !feof(fin) && (q != NULL); 613 q = fgets(stub_fname, 999, fin)) { 572 for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) { 614 573 if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) { 615 574 stub_fname[i] = '\0'; 616 575 } 617 sprintf(tmp, "%s%s", comppath, stub_fname); 618 strcpy(curr_fname, tmp + 1); 619 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname)); 576 mr_asprintf(tmp, "%s%s", comppath, stub_fname); 577 mr_free(stub_fname); 578 579 mr_asprintf(curr_fname, "%s", tmp + 1); 580 mr_free(tmp); 581 582 mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname)); 620 583 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum); 584 mr_free(curr_cksum); 585 621 586 if (counter++ > 12) { 622 587 current_time = get_time(); 623 588 counter = 0; 589 /* BERLIOS: 37 really ? */ 624 590 curr_fname[37] = '\0'; 625 591 curr_pos = ftello(fin) / 1024; 626 592 percentage = (int) (curr_pos * 100 / filelist_length); 627 593 time_taken = current_time - start_time; 628 if (percentage == 0) { 629 /* printf("%0d%% done \r",percentage); */ 630 } else { 631 time_remaining = 632 time_taken * 100 / (long) (percentage) - time_taken; 633 sprintf(tmp, 634 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", 635 percentage, (int) (time_taken / 60), 636 (int) (time_taken % 60), 637 (int) (time_remaining / 60), 638 (int) (time_remaining % 60), curr_fname); 639 log_to_screen(tmp); 594 if (percentage != 0) { 595 time_remaining = time_taken * 100 / (long) (percentage) - time_taken; 596 log_to_screen("%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname); 640 597 } 641 598 sync(); 642 599 } 643 } 600 mr_free(curr_fname); 601 } 602 mr_free(stub_fname); 603 644 604 paranoid_fclose(fout); 645 605 paranoid_fclose(fin); … … 654 614 * @return The return value of @c mkdir. 655 615 */ 656 int make_hole_for_dir(c har *outdir_fname)657 { 658 char tmp[MAX_STR_LEN * 2];616 int make_hole_for_dir(const char *outdir_fname) 617 { 618 char *tmp = NULL; 659 619 int res = 0; 660 620 661 621 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 662 sprintf(tmp, "mkdir -p %s", outdir_fname);622 mr_asprintf(tmp, "mkdir -p %s", outdir_fname); 663 623 res = system(tmp); 624 mr_free(tmp); 664 625 return (res); 665 626 } … … 675 636 { 676 637 /*@ buffer ****************************************************** */ 677 char command[MAX_STR_LEN * 2];638 char *command = NULL; 678 639 679 640 /*@ int ******************************************************** */ … … 685 646 assert(!strstr(outfile_fname, MNT_CDROM)); 686 647 assert(!strstr(outfile_fname, "/dev/cdrom")); 687 sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);648 mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 688 649 res += system(command); 689 sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 650 mr_free(command); 651 652 mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 690 653 res += system(command); 691 sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 654 mr_free(command); 655 656 mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 692 657 res += system(command); 658 mr_free(command); 659 693 660 unlink(outfile_fname); 694 661 return (0); 695 662 } 696 697 698 663 699 664 … … 713 678 714 679 /*@ buffers **************************************************** */ 715 char incoming[MAX_STR_LEN]; 716 char *p = NULL; 680 char *incoming = NULL; 717 681 718 682 /*@ end vars *************************************************** */ … … 725 689 return (0); 726 690 } 727 p = fgets(incoming, MAX_STR_LEN - 1, fin);728 while (!feof(fin) && (p != NULL)) {691 mr_getline(incoming, fin); 692 while (!feof(fin)) { 729 693 if (strstr(incoming, wildcard)) { 730 694 matches++; 731 695 } 732 p = fgets(incoming, MAX_STR_LEN - 1, fin); 733 } 696 mr_free(incoming); 697 mr_getline(incoming, fin); 698 } 699 mr_free(incoming); 734 700 paranoid_fclose(fin); 735 701 return (matches); … … 746 712 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 747 713 { 748 char command[MAX_STR_LEN];749 char mountlist[MAX_STR_LEN];750 char sz_res[MAX_STR_LEN];714 char *command = NULL; 715 char *mountlist = NULL; 716 char *sz_res = NULL; 751 717 long file_len_K; 752 718 753 sprintf(mountlist, "%s/mountlist.txt", tmpdir);754 sprintf(command,755 "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'",756 dev, tmpdir); 719 mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir); 720 mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir); 721 mr_free(mountlist); 722 757 723 log_it(command); 758 strcpy(sz_res, call_program_and_get_last_line_of_output(command));724 mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command)); 759 725 file_len_K = atol(sz_res); 760 726 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 727 mr_free(sz_res); 728 mr_free(command); 729 761 730 return (file_len_K); 762 731 } … … 770 739 { 771 740 /*@ buffers ***************************************************** */ 772 char *fname; 773 char *biggielist; 774 char *comment; 775 char *tmp; 776 char *q; 777 char *command; 741 char *fname = NULL; 742 char *biggielist = NULL; 743 char *tmp = NULL; 744 char *command = NULL; 778 745 779 746 /*@ long ******************************************************** */ … … 786 753 /*@ end vars *************************************************** */ 787 754 788 malloc_string(fname);789 malloc_string(biggielist);790 malloc_string(comment);791 malloc_string(tmp);792 malloc_string(command);793 755 log_it("Calculating size of all biggiefiles (in total)"); 794 sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);756 mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 795 757 log_it("biggielist = %s", biggielist); 796 if (!(fin = fopen(biggielist, "r"))) { 797 log_OS_error 798 ("Cannot open biggielist. OK, so estimate is based on filesets only."); 758 fin = fopen(biggielist, "r"); 759 mr_free(biggielist); 760 761 if (!(fin)) { 762 log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only."); 799 763 } else { 800 764 log_msg(4, "Reading it..."); 801 for (q = fgets(fname, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); 802 q = fgets(fname, MAX_STR_LEN, fin)) { 765 for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) { 803 766 if (fname[strlen(fname) - 1] <= 32) { 804 767 fname[strlen(fname) - 1] = '\0'; … … 807 770 if (is_dev_an_NTFS_dev(fname)) { 808 771 if ( !find_home_of_exe("ntfsresize")) { 772 mr_free(tmp); 773 mr_free(fname); 809 774 fatal_error("ntfsresize not found"); 810 775 } 811 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 776 mr_free(tmp); 777 778 mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 812 779 log_it("command = %s", command); 813 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 780 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 781 mr_free(command); 782 814 783 log_it("res of it = %s", tmp); 815 784 file_len_K = atoll(tmp) / 1024L; 785 mr_free(tmp); 816 786 } else { 817 787 file_len_K = get_phys_size_of_drive(fname) * 1024L; … … 825 795 log_msg(4, "%s --> %ld K", fname, file_len_K); 826 796 } 827 sprintf(comment, 828 "After adding %s, scratchL+%ld now equals %ld", fname, 829 file_len_K, scratchL); 830 log_msg(4, comment); 797 log_msg(4, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL); 831 798 if (feof(fin)) { 832 799 break; 833 800 } 834 } 801 mr_free(fname); 802 } 803 mr_free(fname); 835 804 } 836 805 log_it("Closing..."); 837 806 paranoid_fclose(fin); 838 807 log_it("Finished calculating total size of all biggiefiles"); 839 paranoid_free(fname);840 paranoid_free(biggielist);841 paranoid_free(comment);842 paranoid_free(tmp);843 paranoid_free(command);844 808 return (scratchL); 845 809 } … … 854 818 { 855 819 /*@ buffer ****************************************************** */ 856 char tmp[MAX_STR_LEN];857 char command[MAX_STR_LEN * 2];820 char *tmp = NULL; 821 char *command = NULL; 858 822 long long llres; 859 823 /*@ pointers **************************************************** */ … … 863 827 /*@ end vars *************************************************** */ 864 828 865 sprintf(command, "du -sk %s", mountpt);829 mr_asprintf(command, "du -sk %s", mountpt); 866 830 errno = 0; 867 831 fin = popen(command, "r"); … … 870 834 llres = 0; 871 835 } else { 872 p = fgets(tmp, MAX_STR_LEN, fin);836 mr_getline(tmp, fin); 873 837 paranoid_pclose(fin); 874 838 p = strchr(tmp, '\t'); … … 880 844 llres += (int) (*p - '0'); 881 845 } 882 } 846 mr_free(tmp); 847 } 848 mr_free(command); 883 849 884 850 return (llres); … … 928 894 { 929 895 /*@ buffers *** */ 930 char command[MAX_STR_LEN * 2]; 931 char errorstr[MAX_STR_LEN]; 932 933 934 sprintf(command, "which %s > /dev/null 2> /dev/null", fname); 935 sprintf(errorstr, 936 "Please install '%s'. I cannot find it on your system.", 937 fname); 938 if (system(command)) { 939 log_to_screen(errorstr); 940 log_to_screen 941 ("There may be hyperlink at http://www.mondorescue.org/downloads.shtml which"); 896 char *command = NULL; 897 int res = 0; 898 899 mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname); 900 res = system(command); 901 mr_free(command); 902 903 if (res) { 904 log_to_screen("Please install '%s'. I cannot find it on your system.", fname); 905 log_to_screen("There may be hyperlink at http://www.mondorescue.org which"); 942 906 log_to_screen("will take you to the relevant (missing) package."); 943 907 return (1); … … 1038 1002 { 1039 1003 /*@ Char buffers ** */ 1040 char command[MAX_STR_LEN * 2];1041 char tmp[MAX_STR_LEN];1004 char *command = NULL; 1005 char *tmp = NULL; 1042 1006 char old_pwd[MAX_STR_LEN]; 1043 1044 mvaddstr_and_log_it(g_currentY, 0, 1045 1007 int res = 0; 1008 1009 mvaddstr_and_log_it(g_currentY, 0, "Copying Mondo's core files to the scratch directory"); 1046 1010 1047 1011 log_msg(4, "g_mondo_home='%s'", g_mondo_home); … … 1049 1013 find_and_store_mondoarchives_home(g_mondo_home); 1050 1014 } 1051 sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1052 bkpinfo->scratchdir); 1015 mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir); 1053 1016 1054 1017 log_msg(4, "command = %s", command); 1055 if (run_program_and_log_output(command, 1)) { 1018 res = run_program_and_log_output(command, 1); 1019 mr_free(command); 1020 1021 if (res) { 1056 1022 fatal_error("Failed to copy Mondo's stuff to scratchdir"); 1057 1023 } 1058 1024 1059 sprintf(tmp, "%s/payload.tgz", g_mondo_home);1025 mr_asprintf(tmp, "%s/payload.tgz", g_mondo_home); 1060 1026 if (does_file_exist(tmp)) { 1061 log_it("Untarring payload %s to scratchdir %s", tmp, 1062 bkpinfo->scratchdir); 1027 log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir); 1063 1028 if (getcwd(old_pwd, MAX_STR_LEN - 1)) { 1064 1029 // FIXME … … 1067 1032 // FIXME 1068 1033 } 1069 sprintf(command, "tar -zxvf %s", tmp); 1070 if (run_program_and_log_output(command, FALSE)) { 1034 mr_asprintf(command, "tar -zxvf %s", tmp); 1035 res = run_program_and_log_output(command, FALSE); 1036 if (res) { 1037 mr_free(command); 1038 mr_free(tmp); 1071 1039 fatal_error("Failed to untar payload"); 1072 1040 } 1041 mr_free(command); 1073 1042 if (chdir(old_pwd)) { 1074 1043 // FIXME 1075 1044 } 1076 1045 } 1077 1078 sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1079 1046 mr_free(tmp); 1047 1048 mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 1080 1049 1081 1050 if (run_program_and_log_output(command, FALSE)) { 1082 1051 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1083 1052 } 1084 1085 strcpy(tmp, 1086 1053 mr_free(command); 1054 1055 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("which mondorestore")); 1087 1056 if (!tmp[0]) { 1088 fatal_error 1089 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1090 } 1091 sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1092 if (run_program_and_log_output(command, FALSE)) { 1057 mr_free(tmp); 1058 fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1059 } 1060 1061 mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1062 mr_free(tmp); 1063 res = run_program_and_log_output(command, FALSE); 1064 if (res) { 1065 mr_free(command); 1093 1066 fatal_error("Failed to copy mondorestore to tmpdir"); 1094 1067 } 1095 1096 sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1068 mr_free(command); 1069 1070 mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1097 1071 paranoid_system(command); 1072 mr_free(command); 1098 1073 1099 1074 if (bkpinfo->postnuke_tarball[0]) { 1100 sprintf(command, "cp -f %s %s/post-nuke.tgz", 1101 bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1102 if (run_program_and_log_output(command, FALSE)) { 1075 mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1076 res = run_program_and_log_output(command, FALSE); 1077 mr_free(command); 1078 1079 if (res) { 1103 1080 fatal_error("Unable to copy post-nuke tarball to tmpdir"); 1104 1081 } 1105 1082 } 1106 1107 1083 1108 1084 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1125 1101 1126 1102 /*@ buffers ******** */ 1127 char netfs_dev[MAX_STR_LEN];1128 char netfs_mount[MAX_STR_LEN];1129 char netfs_client_hwaddr[MAX_STR_LEN];1130 char netfs_client_ipaddr[MAX_STR_LEN];1131 char netfs_client_netmask[MAX_STR_LEN];1132 char netfs_client_broadcast[MAX_STR_LEN];1133 char netfs_client_defgw[MAX_STR_LEN];1134 char netfs_server_ipaddr[MAX_STR_LEN];1135 char tmp[MAX_STR_LEN];1136 char command[MAX_STR_LEN * 2];1103 char *netfs_dev = NULL; 1104 char *netfs_client_hwaddr = NULL; 1105 char *netfs_mount = NULL; 1106 char *netfs_client_ipaddr = NULL; 1107 char *netfs_client_netmask = NULL; 1108 char *netfs_client_broadcast = NULL; 1109 char *netfs_client_defgw = NULL; 1110 char *netfs_server_ipaddr = NULL; 1111 char *tmp = NULL; 1112 char *command = NULL; 1137 1113 1138 1114 /*@ pointers ***** */ 1139 1115 char *p; 1140 1116 1117 if (! bkpinfo->netfs_mount) { 1118 fatal_error("No netfs_mount found !"); 1119 } 1120 1141 1121 log_it("Storing Network configuration"); 1142 strcpy(tmp, bkpinfo->netfs_mount);1122 mr_asprintf(tmp, "%s", bkpinfo->netfs_mount); 1143 1123 p = strchr(tmp, ':'); 1144 1124 if (!p) { 1145 fatal_error 1146 ("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1125 fatal_error("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1147 1126 } 1148 1127 *(p++) = '\0'; 1149 strcpy(netfs_server_ipaddr, tmp); 1150 strcpy(netfs_mount, p); 1128 mr_asprintf(netfs_server_ipaddr, "%s", tmp); 1129 mr_asprintf(netfs_mount, "%s", p); 1130 mr_free(tmp); 1151 1131 1152 1132 /* BERLIOS : there is a bug #67 here as it only considers the first NIC */ 1153 sprintf(command,1154 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");1155 strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));1156 sprintf(command, 1157 "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);1158 strcpy(netfs_client_hwaddr, call_program_and_get_last_line_of_output(command));1159 sprintf(command,1160 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1161 strcpy(netfs_client_ipaddr,1162 1163 sprintf(command,1164 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1165 strcpy(netfs_client_netmask,1166 1167 sprintf(command,1168 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1169 strcpy(netfs_client_broadcast,1170 1171 sprintf(command,1172 "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1173 strcpy(netfs_client_defgw,1174 1175 sprintf(tmp,1176 "netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s", 1177 1133 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1134 mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command)); 1135 mr_free(command); 1136 1137 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1138 mr_asprintf(netfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command)); 1139 mr_free(command); 1140 1141 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1142 mr_asprintf(netfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command)); 1143 mr_free(command); 1144 1145 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1146 mr_asprintf(netfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command)); 1147 mr_free(command); 1148 1149 mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1150 mr_asprintf(netfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command)); 1151 mr_free(command); 1152 1153 mr_asprintf(command, "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev); 1154 mr_asprintf(netfs_client_hwaddr, "%s" call_program_and_get_last_line_of_output(command)); 1155 mr_free(command); 1156 1157 log_it("netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s", netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount); 1178 1158 if (strlen(netfs_dev) < 2) { 1179 fatal_error 1180 ("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");1181 } 1159 fatal_error("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified."); 1160 } 1161 1182 1162 /******** 1183 * If the Network device thatfound above is a bonded device,1163 * If the Network device found above is a bonded device, 1184 1164 * we need to replace it with an ethN device or the 1185 1165 * networking will not start during an Network restore. … … 1191 1171 if (!strncmp(netfs_dev, "bond", 4) || !strncmp(netfs_dev, "alb", 3) || !strncmp(netfs_dev, "aft", 3)) { 1192 1172 log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", netfs_dev); 1193 sprintf(command,1194 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);1195 strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));1173 mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev); 1174 mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command)); 1175 mr_free(command); 1196 1176 log_to_screen("Replacing it with %s\n", netfs_dev); 1197 1177 } 1198 1178 1199 sprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);1179 mr_asprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir); 1200 1180 write_one_liner_data_file(tmp, netfs_dev); 1181 mr_free(netfs_dev); 1182 mr_free(tmp); 1183 1184 mr_asprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir); 1185 write_one_liner_data_file(tmp, netfs_client_hwaddr); 1186 mr_free(netfs_client_hwaddr); 1187 mr_free(tmp); 1188 1189 mr_asprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1190 write_one_liner_data_file(tmp, netfs_client_ipaddr); 1191 mr_free(netfs_client_ipaddr); 1192 mr_free(tmp); 1193 1194 mr_asprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1195 write_one_liner_data_file(tmp, netfs_client_netmask); 1196 mr_free(netfs_client_netmask); 1197 mr_free(tmp); 1198 1199 mr_asprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1200 write_one_liner_data_file(tmp, netfs_client_broadcast); 1201 mr_free(netfs_client_broadcast); 1202 mr_free(tmp); 1203 1204 mr_asprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1205 write_one_liner_data_file(tmp, netfs_client_defgw); 1206 mr_free(netfs_client_defgw); 1207 mr_free(tmp); 1208 1209 mr_asprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir); 1210 write_one_liner_data_file(tmp, netfs_server_ipaddr); 1211 mr_free(netfs_server_ipaddr); 1212 mr_free(tmp); 1213 1214 mr_asprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir); 1215 write_one_liner_data_file(tmp, bkpinfo->netfs_mount); 1216 mr_free(tmp); 1217 1218 if (bkpinfo->netfs_user) { 1219 mr_asprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir); 1220 write_one_liner_data_file(tmp, bkpinfo->netfs_user); 1221 mr_free(tmp); 1222 } 1223 mr_asprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir); 1224 write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir); 1225 mr_free(tmp); 1226 1227 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1228 write_one_liner_data_file(tmp, bkpinfo->prefix); 1229 mr_free(tmp); 1201 1230 1202 1231 sprintf(tmp, "%s/NETFS-PROTO", bkpinfo->tmpdir); 1203 1232 write_one_liner_data_file(tmp, bkpinfo->netfs_proto); 1204 1205 sprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir); 1206 write_one_liner_data_file(tmp, netfs_client_hwaddr); 1207 sprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1208 write_one_liner_data_file(tmp, netfs_client_ipaddr); 1209 sprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1210 write_one_liner_data_file(tmp, netfs_client_netmask); 1211 sprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1212 write_one_liner_data_file(tmp, netfs_client_broadcast); 1213 sprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1214 write_one_liner_data_file(tmp, netfs_client_defgw); 1215 sprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir); 1216 write_one_liner_data_file(tmp, netfs_server_ipaddr); 1217 sprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir); 1218 write_one_liner_data_file(tmp, bkpinfo->netfs_mount); 1219 if (bkpinfo->netfs_user) { 1220 sprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir); 1221 write_one_liner_data_file(tmp, bkpinfo->netfs_user); 1222 } 1223 sprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir); 1224 write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir); 1225 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1226 write_one_liner_data_file(tmp, bkpinfo->prefix); 1233 mr_free(tmp); 1234 1235 1227 1236 log_it("Finished storing Network configuration"); 1228 1237 } 1229 1230 1231 1232 1233 1238 1234 1239 … … 1253 1258 { 1254 1259 /*@ buffers *************** */ 1255 char tmp[MAX_STR_LEN];1260 char *tmp = NULL; 1256 1261 char *mds = NULL; 1257 1262 … … 1265 1270 1266 1271 log_it("Estimating number of media required..."); 1267 scratchLL = 1268 (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) 1269 + (long long) (size_of_all_biggiefiles_K()); 1272 scratchLL = (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) + (long long) (size_of_all_biggiefiles_K()); 1270 1273 scratchLL = (scratchLL / 1024) / bkpinfo->media_size; 1271 1274 scratchLL++; … … 1274 1277 } else if (bkpinfo->use_gzip) { 1275 1278 scratchLL = (scratchLL * 2) / 3; 1279 } else if (bkpinfo->use_lzma) { 1280 scratchLL = (scratchLL * 2) / 3; 1276 1281 } else { 1277 1282 scratchLL = scratchLL / 2; … … 1282 1287 if (scratchLL <= 1) { 1283 1288 mds = media_descriptor_string(bkpinfo->backup_media_type); 1284 sprintf(tmp, 1285 "Your backup will probably occupy a single %s. Maybe two.", mds); 1289 mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds); 1286 1290 mr_free(mds); 1287 1291 } else if (scratchLL > 4) { 1288 sprintf(tmp, 1289 "Your backup will occupy one meeeeellion media! (maybe %s)", 1290 number_to_text((int) (scratchLL + 1))); 1292 mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1))); 1291 1293 } else { 1292 sprintf(tmp, "Your backup will occupy approximately %s media.", 1293 number_to_text((int) (scratchLL + 1))); 1294 } 1295 if (!bkpinfo->image_devs[0] && (scratchLL < 50)) { 1294 mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1))); 1295 } 1296 if (scratchLL < 50) { 1296 1297 log_to_screen(tmp); 1297 1298 } 1298 } 1299 1300 1301 /** 1302 * Get the last suffix of @p instr. 1303 * If @p instr was "httpd.log.gz", we would return "gz". 1304 * @param instr The filename to get the suffix of. 1305 * @return The suffix (without a dot), or "" if none. 1306 * @note The returned string points to static storage that will be overwritten with each call. 1307 */ 1308 char *sz_last_suffix(char *instr) 1309 { 1310 static char outstr[MAX_STR_LEN]; 1311 char *p; 1312 1313 p = strrchr(instr, '.'); 1314 if (!p) { 1315 outstr[0] = '\0'; 1316 } else { 1317 strcpy(outstr, p); 1318 } 1319 return (outstr); 1299 mr_free(tmp); 1320 1300 } 1321 1301 … … 1329 1309 bool is_this_file_compressed(char *filename) 1330 1310 { 1331 char do_not_compress_these[MAX_STR_LEN];1332 char tmp[MAX_STR_LEN];1311 char *do_not_compress_these = NULL; 1312 char *tmp = NULL; 1333 1313 char *p; 1334 1314 char *q = NULL; … … 1339 1319 } 1340 1320 1341 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);1321 mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 1342 1322 if (!does_file_exist(tmp)) { 1323 mr_free(tmp); 1343 1324 return (FALSE); 1344 1325 } 1345 1326 /* BERLIOS: This is just plain WRONG !! */ 1346 strcpy(do_not_compress_these,last_line_of_file(tmp)); 1327 mr_asprintf(do_not_compress_these,"%s", last_line_of_file(tmp)); 1328 mr_free(tmp); 1347 1329 1348 1330 for (p = do_not_compress_these; p != NULL; p++) { 1349 strcpy(tmp, p);1331 mr_asprintf(tmp, "%s", p); 1350 1332 if (strchr(tmp, ' ')) { 1351 1333 *(strchr(tmp, ' ')) = '\0'; 1352 1334 } 1353 1335 if (!strcmp(q, tmp)) { 1336 mr_free(tmp); 1337 mr_free(do_not_compress_these); 1354 1338 return (TRUE); 1355 1339 } … … 1357 1341 break; 1358 1342 } 1359 } 1343 mr_free(tmp); 1344 } 1345 mr_free(do_not_compress_these); 1360 1346 return (FALSE); 1361 1347 } -
branches/3.0/mondo/src/common/libmondo-files.h
r2904 r3188 42 42 43 43 44 int make_hole_for_dir(c har *outdir_fname);44 int make_hole_for_dir(const char *outdir_fname); 45 45 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); 46 46 int read_one_liner_data_file(char *fname, char *contents); -
branches/3.0/mondo/src/common/libmondo-fork.c
r3185 r3188 8 8 #include "my-stuff.h" 9 9 #include "mr_mem.h" 10 #include "mr_str.h" 10 11 #include "mondostructures.h" 11 12 #include "libmondo-fork.h" … … 38 39 /*@ buffers ***************************************************** */ 39 40 static char result[MAX_STR_LEN]; 40 char *tmp; 41 char *p; 41 char *tmp = NULL; 42 42 43 43 /*@ pointers **************************************************** */ 44 FILE *fin; 44 FILE *fin = NULL; 45 int res = 0; 45 46 46 47 /*@ initialize data ********************************************* */ 47 malloc_string(tmp);48 48 result[0] = '\0'; 49 tmp[0] = '\0';50 49 51 50 /*@******************************************************************** */ … … 53 52 assert_string_is_neither_NULL_nor_zerolength(call); 54 53 if ((fin = popen(call, "r"))) { 55 for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL); 56 p = fgets(tmp, MAX_STR_LEN, fin)) { 54 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) { 57 55 if (strlen(tmp) > 1) { 58 56 strcpy(result, tmp); 59 57 } 58 mr_free(tmp); 60 59 } 61 60 paranoid_pclose(fin); 62 61 } else { 63 log_OS_error("Unable to popen call");62 log_OS_error("Unable to open resulting file"); 64 63 } 65 64 strip_spaces(result); 66 paranoid_free(tmp); 67 return (result); 68 } 69 70 71 72 65 mr_free(tmp); 66 return(result); 67 } 73 68 74 69 … … 86 81 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs). 87 82 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number. 88 * @param logstub Unused.89 83 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog. 90 84 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure). 91 * @bug @p logstub is unused.92 85 */ 93 86 int … … 101 94 102 95 /*@ buffers *** */ 103 char *midway_call, *ultimate_call, *tmp, *command, *incoming, 104 *old_stderr, *cd_number_str; 105 char *p; 96 char *midway_call = NULL; 97 char *ultimate_call = NULL; 98 char *tmp = NULL; 99 100 char *cd_number_str = NULL; 101 char *command = NULL; 102 char *p= NULL; 106 103 char *tmp1 = NULL; 104 char *tmp2 = NULL; 107 105 108 106 /*@*********** End Variables ***************************************/ … … 110 108 log_msg(3, "Starting"); 111 109 assert(bkpinfo != NULL); 112 // BERLIOS: doesn't work even if the string is correct !113 //assert_string_is_neither_NULL_nor_zerolength(basic_call);114 110 assert_string_is_neither_NULL_nor_zerolength(isofile); 115 assert_string_is_neither_NULL_nor_zerolength(logstub); 111 116 112 if (!(midway_call = malloc(1200))) { 117 113 fatal_error("Cannot malloc midway_call"); … … 123 119 fatal_error("Cannot malloc tmp"); 124 120 } 125 if (!(command = malloc(1200))) {126 fatal_error("Cannot malloc command");127 }128 malloc_string(incoming);129 malloc_string(old_stderr);130 malloc_string(cd_number_str);131 132 incoming[0] = '\0';133 old_stderr[0] = '\0';134 121 135 122 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) { … … 139 126 } 140 127 141 sprintf(cd_number_str, "%d", cd_no);128 mr_asprintf(cd_number_str, "%d", cd_no); 142 129 resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_"); 130 log_msg(4, "basic call = '%s'", tmp1); 131 mr_free(tmp1); 132 143 133 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_"); 134 log_msg(4, "midway_call = '%s'", midway_call); 135 mr_free(cd_number_str); 136 144 137 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 145 log_msg(4, "basic call = '%s'", tmp1);146 log_msg(4, "midway_call = '%s'", midway_call);147 log_msg(4, "tmp = '%s'", tmp);148 138 log_msg(4, "ultimate call = '%s'", ultimate_call); 149 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 150 151 log_to_screen 152 ("Please be patient. Do not be alarmed by on-screen inactivity."); 153 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", 154 what_i_am_doing); 155 strcpy(tmp, command); 139 mr_asprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 140 141 log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity."); 142 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing); 156 143 if (bkpinfo->manual_cd_tray) { 157 p = strstr(tmp, "2>>"); 144 mr_asprintf(tmp2, "%s", command); 145 p = strstr(tmp2, "2>>"); 158 146 if (p) { 159 147 sprintf(p, " "); … … 161 149 p++; 162 150 } 163 for (; *p != ' '; p++) {151 for (; (*p != ' ') && (*p != '\0'); p++) { 164 152 *p = ' '; 165 153 } 166 154 } 167 strcpy(command, tmp);168 #ifndef _XWIN 155 mr_free(command); 156 command = tmp2; 169 157 if (!g_text_mode) { 170 158 newtSuspend(); 171 159 } 172 #endif173 160 log_msg(1, "command = '%s'", command); 174 161 retval += system(command); … … 177 164 } 178 165 if (retval) { 179 log_msg(2, "Basic call '%s' returned an error.", tmp1); 180 popup_and_OK("Press ENTER to continue."); 181 popup_and_OK 182 ("mkisofs and/or cdrecord returned an error. CD was not created"); 166 popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created"); 183 167 } 184 168 } … … 186 170 else { 187 171 log_msg(3, "command = '%s'", command); 188 // yes_this_is_a_goto: 189 retval = 190 run_external_binary_with_percentage_indicator_NEW 191 (what_i_am_doing, command); 192 } 193 194 mr_free(tmp1); 172 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command); 173 } 174 mr_free(command); 195 175 paranoid_free(midway_call); 196 176 paranoid_free(ultimate_call); 197 177 paranoid_free(tmp); 198 paranoid_free(command);199 paranoid_free(incoming);200 paranoid_free(old_stderr);201 paranoid_free(cd_number_str);202 178 return (retval); 203 179 } … … 232 208 log_msg(1, "command = '%s'", command); 233 209 if (!g_text_mode) { 234 retval = run_external_binary_with_percentage_indicator_NEW 235 (what_i_am_doing, command); 210 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command); 236 211 } else { 237 212 retval += system(command); … … 277 252 return (1); 278 253 } 279 // if (debug_level == TRUE) { debug_level=5; }280 281 // assert_string_is_neither_NULL_nor_zerolength(program);282 254 283 255 if (debug_level <= g_loglevel) { … … 322 294 } 323 295 } 324 /* end of patch */325 296 strip_spaces(incoming); 326 297 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) { … … 342 313 } 343 314 } 344 // else345 // { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); }346 315 return (res); 347 316 } … … 368 337 369 338 /*@ buffers **************************************************** */ 370 char *tmp = NULL;371 339 char *command = NULL; 372 char lockfile[MAX_STR_LEN];340 char *lockfile = NULL; 373 341 374 342 /*@ end vars *************************************************** */ … … 376 344 assert_string_is_neither_NULL_nor_zerolength(basic_call); 377 345 378 sprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir); 379 380 mr_asprintf(command, 381 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", 382 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 346 mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir); 347 348 mr_asprintf(command, "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 383 349 open_evalcall_form(what_i_am_doing); 384 mr_asprintf(tmp, "Executing %s", basic_call); 385 log_msg(2, tmp); 386 mr_free(tmp); 350 log_msg(2, "Executing %s", basic_call); 387 351 388 352 if (!(fin = popen(command, "r"))) { 389 353 log_OS_error("Unable to popen-in command"); 390 mr_asprintf(tmp, "Failed utterly to call '%s'", command); 391 log_to_screen(tmp); 392 mr_free(tmp); 354 log_to_screen("Failed utterly to call '%s'", command); 393 355 mr_free(command); 356 mr_free(lockfile); 394 357 return (1); 395 358 } 359 396 360 if (!does_file_exist(lockfile)) { 397 361 log_to_screen("Waiting for '%s' to start",command); … … 401 365 } 402 366 mr_free(command); 403 #ifdef _XWIN 404 /* This only can update when newline goes into the file, 405 but it's *much* prettier/faster on Qt. */ 406 while (does_file_exist(lockfile)) { 407 while (!feof(fin)) { 408 /* TODO: Dead and wrong code */ 409 if (!fgets(tmp, 512, fin)) 410 break; 411 log_to_screen(tmp); 412 } 413 usleep(500000); 414 } 415 #else 416 /* This works on Newt, and it gives quicker updates. */ 367 417 368 for (; does_file_exist(lockfile); sleep(1)) { 418 369 log_file_end_to_screen(MONDO_LOGFILE, ""); 419 370 update_evalcall_form(1); 420 371 } 421 #endif 372 422 373 /* Evaluate the status returned by pclose to get the exit code of the called program. */ 423 374 errno = 0; … … 434 385 close_evalcall_form(); 435 386 unlink(lockfile); 387 mr_free(lockfile); 388 436 389 return (retval); 437 390 } … … 453 406 // if dir=='w' then copy from orig to archived 454 407 // if dir=='r' then copy from archived to orig 455 char *tmp; 456 char *buf; 457 char filestr[MAX_STR_LEN]; 408 char *tmp = NULL; 409 char *tmp1 = NULL; 410 char *buf = NULL; 411 char *filestr = NULL; 458 412 long int bytes_to_be_read, bytes_read_in, bytes_written_out = 459 413 0, bufcap, subsliceno = 0; … … 465 419 466 420 log_msg(5, "Opening."); 467 if (!(tmp = malloc(tmpcap))) { 468 fatal_error("Failed to malloc() tmp"); 469 } 470 tmp[0] = '\0'; 421 471 422 bufcap = 256L * 1024L; 472 423 if (!(buf = malloc(bufcap))) { … … 477 428 fin = f_orig; 478 429 fout = f_archived; 479 sprintf(tmp, "%-64s", PIMP_START_SZ);430 mr_asprintf(tmp, "%-64s", PIMP_START_SZ); 480 431 if (fwrite(tmp, 1, 64, fout) != 64) { 432 mr_free(tmp); 481 433 fatal_error("Can't write the introductory block"); 482 434 } 435 mr_free(tmp); 436 483 437 while (1) { 484 438 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin); … … 486 440 break; 487 441 } 488 sprintf(tmp, "%-64ld", bytes_read_in);442 mr_asprintf(tmp, "%-64ld", bytes_read_in); 489 443 if (fwrite(tmp, 1, 64, fout) != 64) { 444 mr_free(tmp); 490 445 fatal_error("Cannot write introductory block"); 491 446 } 447 mr_free(tmp); 448 492 449 log_msg(7, 493 450 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", 494 451 subsliceno, bytes_read_in, bytes_to_be_read); 495 452 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 496 sprintf(tmp, "%-64ld", subsliceno);453 mr_asprintf(tmp, "%-64ld", subsliceno); 497 454 if (fwrite(tmp, 1, 64, fout) != 64) { 455 mr_free(tmp); 498 456 fatal_error("Cannot write post-thingy block"); 499 457 } 458 mr_free(tmp); 500 459 log_msg(7, "Subslice #%d written OK", subsliceno); 501 460 subsliceno++; 502 461 } 503 sprintf(tmp, "%-64ld", 0L);462 mr_asprintf(tmp, "%-64ld", 0L); 504 463 if (fwrite(tmp, 1, 64L, fout) != 64L) { 464 mr_free(tmp); 505 465 fatal_error("Cannot write final introductory block"); 506 466 } 467 mr_free(tmp); 468 469 mr_asprintf(tmp, "%-64s", PIMP_END_SZ); 470 if (fwrite(tmp, 1, 64, fout) != 64) { 471 mr_free(tmp); 472 fatal_error("Can't write the final block"); 473 } 474 mr_free(tmp); 507 475 } else { 508 476 fin = f_archived; 509 477 fout = f_orig; 510 if (fread(tmp, 1, 64L, fin) != 64L) { 478 if (!(tmp1 = malloc(tmpcap))) { 479 fatal_error("Failed to malloc() tmp"); 480 } 481 if (fread(tmp1, 1, 64L, fin) != 64L) { 482 mr_free(tmp1); 511 483 fatal_error("Cannot read the introductory block"); 512 484 } 513 log_msg(5, "tmp is %s", tmp); 514 if (!strstr(tmp, PIMP_START_SZ)) { 485 log_msg(5, "tmp1 is %s", tmp1); 486 if (!strstr(tmp1, PIMP_START_SZ)) { 487 mr_free(tmp1); 515 488 fatal_error("Can't find intro blk"); 516 489 } 517 if (fread(tmp, 1, 64L, fin) != 64L) { 490 if (fread(tmp1, 1, 64L, fin) != 64L) { 491 mr_free(tmp1); 518 492 fatal_error("Cannot read introductory blk"); 519 493 } 520 bytes_to_be_read = atol(tmp );494 bytes_to_be_read = atol(tmp1); 521 495 while (bytes_to_be_read > 0) { 522 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, 523 bytes_to_be_read); 496 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read); 524 497 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin); 525 498 if (bytes_read_in != bytes_to_be_read) { 526 fatal_error527 499 mr_free(tmp1); 500 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives."); 528 501 } 529 502 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 530 if (fread(tmp, 1, 64, fin) != 64) { 503 if (fread(tmp1, 1, 64, fin) != 64) { 504 mr_free(tmp1); 531 505 fatal_error("Cannot read post-thingy block"); 532 506 } 533 if (atol(tmp) != subsliceno) { 534 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", 535 subsliceno, atol(tmp), tmp); 507 if (atol(tmp1) != subsliceno) { 508 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1); 536 509 } 537 510 log_msg(7, "Subslice #%ld read OK", subsliceno); 538 511 subsliceno++; 539 if (fread(tmp, 1, 64, fin) != 64) { 512 if (fread(tmp1, 1, 64, fin) != 64) { 513 mr_free(tmp1); 540 514 fatal_error("Cannot read introductory block"); 541 515 } 542 bytes_to_be_read = atol(tmp); 543 } 544 } 545 546 // log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in); 516 bytes_to_be_read = atol(tmp1); 517 } 518 } 547 519 548 520 if (direction == 'w') { 549 sprintf(tmp, "%-64s", PIMP_END_SZ);521 mr_asprintf(tmp, "%-64s", PIMP_END_SZ); 550 522 if (fwrite(tmp, 1, 64, fout) != 64) { 523 mr_free(tmp); 551 524 fatal_error("Can't write the final block"); 552 525 } 526 mr_free(tmp); 553 527 } else { 554 log_msg(1, "tmpA is %s", tmp); 555 if (!strstr(tmp, PIMP_END_SZ)) { 556 if (fread(tmp, 1, 64, fin) != 64) { 528 log_msg(1, "tmpA is %s", tmp1); 529 if (!strstr(tmp1, PIMP_END_SZ)) { 530 if (fread(tmp1, 1, 64, fin) != 64) { 531 mr_free(tmp1); 557 532 fatal_error("Can't read the final block"); 558 533 } 559 log_msg(5, "tmpB is %s", tmp );560 if (!strstr(tmp , PIMP_END_SZ)) {561 sprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);534 log_msg(5, "tmpB is %s", tmp1); 535 if (!strstr(tmp1, PIMP_END_SZ)) { 536 mr_asprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir); 562 537 ftmp = fopen(filestr, "w"); 563 bytes_read_in = fread(tmp, 1, 64, fin); 538 mr_free(filestr); 539 540 bytes_read_in = fread(tmp1, 1, 64, fin); 564 541 log_msg(1, "bytes_read_in = %ld", bytes_read_in); 565 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } 542 566 543 if (fwrite(tmp, 1, bytes_read_in, ftmp)) { 567 544 fatal_error("Can't fwrite here"); 568 545 } 569 sprintf(tmp, "I am here - %lld", (long long)ftello(fin)); 570 // log_msg(0, tmp);546 547 mr_asprintf(tmp, "I am here - %lld", (long long)ftello(fin)); 571 548 if (fread(tmp, 1, tmpcap, fin)) { 549 mr_free(tmp); 572 550 fatal_error("Can't fread here"); 573 551 } 574 552 log_msg(0, "tmp = '%s'", tmp); 575 553 if (fwrite(tmp, 1, tmpcap, ftmp)) { 554 mr_free(tmp); 576 555 fatal_error("Can't fwrite there"); 577 556 } 578 557 fclose(ftmp); 558 mr_free(tmp); 579 559 fatal_error("Missing terminating block"); 580 560 } 581 561 } 582 562 } 563 mr_free(tmp1); 583 564 584 565 paranoid_free(buf); 585 paranoid_free(tmp);586 566 log_msg(3, "Successfully copied %ld bytes", bytes_written_out); 587 567 return (retval); … … 601 581 // BACKUP 602 582 int res = -1; 603 char *command;583 char *command = NULL; 604 584 605 585 if (!does_file_exist(input_device)) { … … 609 589 fatal_error("ntfsclone not found"); 610 590 } 611 malloc_string(command); 612 sprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device); 591 mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device); 613 592 res = run_program_and_log_output(command, 5); 614 paranoid_free(command); 593 mr_free(command); 594 615 595 unlink(output_fname); 616 596 return (res); … … 638 618 639 619 640 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) 641 { 620 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) { 642 621 643 622 /*@ int *************************************************************** */ … … 650 629 651 630 /*@ buffers *********************************************************** */ 652 char *command; 653 char *title; 631 char *command = NULL; 654 632 /*@ pointers ********************************************************** */ 655 633 static int chldres = 0; … … 662 640 *pchild_result = 999; 663 641 664 malloc_string(title); 665 malloc_string(command); 666 strcpy(title, tt); 667 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 642 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 668 643 log_msg(3, "command = '%s'", command); 669 if ((res = 670 pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, 671 (void *) command))) { 644 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) { 672 645 fatal_error("Unable to create an archival thread"); 673 646 } 674 647 675 648 log_msg(8, "Parent running"); 676 open_evalcall_form(title); 649 open_evalcall_form(tt); 650 677 651 for (sleep(1); command[0] != '\0'; sleep(1)) { 678 652 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE); 679 if (pcno < =0 || pcno > 100) {680 log_msg(8, "Weird pc# ");653 if (pcno < 0 || pcno > 100) { 654 log_msg(8, "Weird pc# %d", pcno); 681 655 continue; 682 656 } … … 684 658 if (pcno <= 5 && last_pcno >= 40) { 685 659 close_evalcall_form(); 686 strcpy(title, "Verifying..."); 687 open_evalcall_form(title); 660 open_evalcall_form("Verifying..."); 688 661 } 689 662 if (counter++ >= 5) { … … 694 667 update_evalcall_form(percentage); 695 668 } 669 mr_free(command); 670 696 671 log_file_end_to_screen(MONDO_LOGFILE, ""); 697 672 close_evalcall_form(); … … 703 678 } 704 679 log_msg(3, "Parent res = %d", res); 705 paranoid_free(command);706 paranoid_free(title);707 680 return (res); 708 681 } 709 710 711 682 712 683 … … 721 692 // RESTORE 722 693 int res = -1; 723 char *command ;694 char *command = NULL; 724 695 725 696 if ( !find_home_of_exe("ntfsclone")) { 726 697 fatal_error("ntfsclone not found"); 727 698 } 728 malloc_string(command); 729 sprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo); 699 mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo); 730 700 res = run_program_and_log_output(command, 5); 731 paranoid_free(command);701 mr_free(command); 732 702 return (res); 733 703 } -
branches/3.0/mondo/src/common/libmondo-gui-EXT.h
r541 r3188 1 1 /* libmondo-gui-EXT.h */ 2 2 3 #ifdef _XWIN4 #include "X-specific-EXT.h"5 #else6 3 #include "newt-specific-EXT.h" 7 #endif -
branches/3.0/mondo/src/common/libmondo-gui.c
r541 r3188 9 9 */ 10 10 11 #ifdef _XWIN12 #include "X-specific.c"13 #else14 11 #include "newt-specific.c" 15 #endif -
branches/3.0/mondo/src/common/libmondo-gui.h
r541 r3188 3 3 */ 4 4 5 #ifdef _XWIN6 #include "X-specific.h"7 #else8 5 #include "newt-specific.h" 9 #endif -
branches/3.0/mondo/src/common/libmondo-mountlist.c
r3185 r3188 59 59 char tmp = NULL; 60 60 char device[MAX_STR_LEN]; 61 char mountpoint[MAX_STR_LEN];62 61 63 62 char *flaws_str = NULL; … … 100 99 continue; 101 100 } 102 strcpy(mountpoint, mountlist->el[pos].mountpoint);103 101 /* is it too big? */ 104 102 if (curr_part_no > 'h') { … … 176 174 177 175 build_partition_name(device, drive, curr_part_no); 178 strcpy(mountpoint, mountlist->el[pos].mountpoint);179 176 if (pos > 0 && !npos) { 180 177 /* gap in the partition list? */ … … 260 257 continue; 261 258 } 262 strcpy(mountpoint, mountlist->el[pos].mountpoint);263 259 /* is it too big? */ 264 260 if (curr_part_no > 'h') { … … 327 323 if (amount_allocated > physical_drive_size) { 328 324 // Used to be +1, but what if you're 1 MB too high? 329 mr_asprintf(tmp, " %ld MB over-allocated on %s.", 330 amount_allocated - physical_drive_size, drive); 325 mr_asprintf(tmp, " %ld MB over-allocated on %s.",amount_allocated - physical_drive_size, drive); 331 326 log_it(tmp); 332 327 … … 348 343 349 344 /* Over-allocated the disk? Unallocated space on disk? */ 350 if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 351 mr_asprintf(tmp, " %ld MB unallocated on %s.", 352 physical_drive_size - amount_allocated, drive); 345 if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high? 346 { 347 mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive); 348 log_it(tmp); 349 mr_strcat(flaws_str, "%s", tmp); 350 mr_free(tmp); 351 res++; 352 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 353 mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive); 353 354 log_it(tmp); 354 355 mr_strcat(flaws_str, "%s", tmp); … … 405 406 goto endoffunc; 406 407 } else { 407 mr_asprintf(tmp, " %s (dm) will be setup later on", drive); 408 log_it(tmp); 409 mr_free(tmp); 408 log_it(" %s (dm) will be setup later on", drive); 410 409 } 411 410 } else { 412 mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size); 413 log_it(tmp); 414 mr_free(tmp); 411 log_it("%s is %ld MB", drive, physical_drive_size); 415 412 } 416 413 … … 432 429 } else if (curr_part_no > 5 433 430 || (curr_part_no <= 4 && prev_part_no > 0)) { 434 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, 435 prev_part_no, curr_part_no); 431 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, prev_part_no, curr_part_no); 436 432 log_it(tmp); 437 433 mr_strcat(flaws_str, "%s", tmp); … … 443 439 part_table_fmt = which_partition_format(drive); 444 440 /* no spare primary partitions to help accommodate the logical(s)? */ 445 if ((curr_part_no >= 5 && prev_part_no == 4) 446 && (strcmp(part_table_fmt, "MBR") == 0)) { 441 if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt, "MBR") == 0)) { 447 442 mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive); 448 443 log_it(tmp); … … 451 446 res++; 452 447 } 448 mr_free(part_table_fmt); 449 453 450 /* does partition /dev/hdNX exist more than once in the mountlist? */ 454 451 for (i = 0, device_copies = 0; … … 459 456 } 460 457 if (device_copies > 1) { 461 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), 462 device); 458 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device); 463 459 if (!strstr(flaws_str, tmp)) { 464 460 log_it(tmp); … … 504 500 /* Over-allocated the disk? Unallocated space on disk? */ 505 501 if (amount_allocated > physical_drive_size + 1) { 506 mr_asprintf(tmp, " %ld MB over-allocated on %s.", 507 amount_allocated - physical_drive_size, drive); 502 mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive); 508 503 log_it(tmp); 509 504 mr_strcat(flaws_str, "%s", tmp); … … 511 506 res++; 512 507 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 513 mr_asprintf(tmp, " %ld MB unallocated on %s.", 514 physical_drive_size - amount_allocated, drive); 508 mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive); 515 509 log_it(tmp); 516 510 mr_strcat(flaws_str, "%s", tmp); … … 570 564 (drivelist->el[i].device, 571 565 DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) { 572 mr_asprintf(tmp, " Not evaluating %s (I don't know how yet)", drivelist->el[i].device); 573 log_it(tmp); 574 paranoid_free(tmp); 566 log_it(" Not evaluating %s (I don't know how yet)", drivelist->el[i].device); 575 567 } else { 576 568 log_msg(8, "Evaluating drive #%d (%s) within mountlist", i, drivelist->el[i].device); … … 582 574 log_msg(8,"Adding: %s to flaws_str", tmp); 583 575 mr_strcat(flaws_str, "%s", tmp); 584 paranoid_free(tmp);576 mr_free(tmp); 585 577 } 586 578 } … … 602 594 mr_strcat(flaws_str, "%s", tmp); 603 595 log_msg(8,"Adding: %s to flaws_str", tmp); 604 paranoid_free(tmp);605 } 606 paranoid_free(curr_mountpoint);596 mr_free(tmp); 597 } 598 mr_free(curr_mountpoint); 607 599 } 608 600 … … 669 661 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 670 662 log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive); 671 paranoid_free(drive);663 mr_free(drive); 672 664 continue; 673 665 } … … 676 668 if (size == 0) { 677 669 log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive); 678 paranoid_free(drive);670 mr_free(drive); 679 671 continue; 680 672 } … … 684 676 /* memory allocation */ 685 677 truncdrive = truncate_to_drive_name(drive); 686 paranoid_free(drive);678 mr_free(drive); 687 679 688 680 log_msg(8, "drive truncated to %s", truncdrive); … … 733 725 int used_by = 0; 734 726 735 /*@ buffers ********************************************************* */736 char *tmp = NULL;737 738 727 assert(output_list != NULL); 739 728 assert(mountlist != NULL); … … 745 734 for (i = 0; i < mountlist->entries; i++) { 746 735 if (strstr(mountlist->el[i].mountpoint, "raid")) { 747 used_by = 748 which_raid_device_is_using_this_partition(raidlist, 749 mountlist->el[i]. 750 device); 736 used_by = which_raid_device_is_using_this_partition(raidlist, mountlist->el[i].device); 751 737 if (used_by < 0) { 752 738 memcpy((void *) &output_list->el[items++], 753 739 (void *) &mountlist->el[i], 754 740 sizeof(struct mountlist_line)); 755 mr_asprintf(tmp, "%s is available; user may choose to add it to raid device", output_list->el[items - 1].device); 756 log_it(tmp); 757 paranoid_free(tmp); 741 log_it("%s is available; user may choose to add it to raid device", output_list->el[items - 1].device); 758 742 } 759 743 } … … 810 794 char *tmp = NULL; 811 795 char *p = NULL; 812 char *q = NULL;813 796 814 797 int items = 0; … … 824 807 return (1); 825 808 } 826 malloc_string(incoming);827 809 malloc_string(siz); 828 q = fgets(incoming, MAX_STR_LEN - 1, fin);829 810 log_it("Loading mountlist..."); 830 while (!feof(fin) && (q != NULL)) { 811 mr_getline(incoming, fin); 812 while (!feof(fin)) { 831 813 #if linux 832 res = sscanf(incoming, 833 "%s %s %s %s %s", 834 mountlist->el[items].device, 835 mountlist->el[items].mountpoint, 836 mountlist->el[items].format, 837 siz, mountlist->el[items].label); 814 res = sscanf(incoming, "%s %s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz, mountlist->el[items].label); 838 815 if (res < 5) { 839 816 /* no label found */ … … 842 819 } 843 820 #elif __FreeBSD__ 844 res = sscanf(incoming, 845 "%s %s %s %s", 846 mountlist->el[items].device, 847 mountlist->el[items].mountpoint, 848 mountlist->el[items].format, siz); 821 res = sscanf(incoming, "%s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz); 849 822 strcpy(mountlist->el[items].label,""); 850 823 #endif … … 859 832 !strcmp(mountlist->el[items].device, "devpts") 860 833 ) { 861 log_msg(1, 862 "Ignoring %s in mountlist - not loading that line :) ", 863 mountlist->el[items].device); 864 q = fgets(incoming, MAX_STR_LEN - 1, fin); 834 log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device); 835 mr_free(incoming); 836 mr_getline(incoming, fin); 865 837 continue; 866 838 } … … 874 846 if (j < items) { 875 847 strcat(mountlist->el[items].device, "_dup"); 876 mr_asprintf(tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device); 877 log_it(tmp); 878 paranoid_free(tmp); 848 log_it("Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device); 879 849 } 880 850 mr_asprintf(tmp, "%s", mountlist->el[items].device); … … 887 857 *(p + 2) = *(p + 3); 888 858 } 889 log_it("It was %s; it is now %s", 890 mountlist->el[items].device, tmp); 859 log_it("It was %s; it is now %s", mountlist->el[items].device, tmp); 891 860 strcpy(mountlist->el[items].device, tmp); 892 861 } 893 862 paranoid_free(tmp); 894 863 895 log_it("%s %s %s %lld %s", 896 mountlist->el[items].device, 897 mountlist->el[items].mountpoint, 898 mountlist->el[items].format, 899 mountlist->el[items].size, 900 mountlist->el[items].label); 864 log_it("%s %s %s %lld %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, mountlist->el[items].size, mountlist->el[items].label); 901 865 items++; 902 866 if (items >= MAX_MOUNTLIST_ENTRIES) { … … 905 869 } 906 870 } 907 q = fgets(incoming, MAX_STR_LEN - 1, fin); 908 } 871 mr_free(incoming); 872 mr_getline(incoming, fin); 873 } 874 mr_free(incoming); 909 875 paranoid_fclose(fin); 910 876 mountlist->entries = items; … … 913 879 log_it("%d entries in mountlist", items); 914 880 915 paranoid_free(incoming);916 881 paranoid_free(siz); 917 882 return (0); … … 1050 1015 1051 1016 mountlist->el[b].size = size; 1052 paranoid_free(device);1053 paranoid_free(mountpoint);1054 paranoid_free(format);1017 mr_free(device); 1018 mr_free(mountpoint); 1019 mr_free(format); 1055 1020 } 1056 1021 -
branches/3.0/mondo/src/common/libmondo-raid.c
r3185 r3188 335 335 #ifdef __FreeBSD__ 336 336 int i, j; 337 char *org = NULL; 337 338 338 339 fprintf(fout, "\nvolume %s\n", raidrec->volname); 339 340 for (i = 0; i < raidrec->plexes; ++i) { 340 char org[24];341 341 switch (raidrec->plex[i].raidlevel) { 342 342 case -1: 343 strcpy(org, "concat");343 mr_asprintf(org, "concat"); 344 344 break; 345 345 case 0: 346 strcpy(org, "striped");346 mr_asprintf(org, "striped"); 347 347 break; 348 348 case 5: 349 strcpy(org, "raid5");349 mr_asprintf(org, "raid5"); 350 350 break; 351 351 } 352 352 fprintf(fout, " plex org %s", org); 353 mr_free(org); 354 353 355 if (raidrec->plex[i].raidlevel != -1) { 354 356 fprintf(fout, " %ik", raidrec->plex[i].stripesize); … … 357 359 358 360 for (j = 0; j < raidrec->plex[i].subdisks; ++j) { 359 fprintf(fout, " sd drive %s size 0\n", 360 raidrec->plex[i].sd[j].which_device); 361 fprintf(fout, " sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device); 361 362 } 362 363 } … … 427 428 int get_next_raidtab_line(FILE * fin, char *label, char *value) 428 429 { 429 char *incoming ;430 char *incoming = NULL; 430 431 char *p; 431 char *q; 432 433 malloc_string(incoming); 432 434 433 assert(fin != NULL); 435 434 assert(label != NULL); … … 438 437 label[0] = value[0] = '\0'; 439 438 if (feof(fin)) { 440 paranoid_free(incoming);441 439 return (1); 442 440 } 443 for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL); 444 q = fgets(incoming, MAX_STR_LEN - 1, fin)) { 445 strip_spaces(incoming); 441 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 442 mr_strip_spaces(incoming); 446 443 p = strchr(incoming, ' '); 447 444 if (strlen(incoming) < 3 || incoming[0] == '#' || !p) { 445 mr_free(incoming); 448 446 continue; 449 447 } … … 454 452 strcpy(label, incoming); 455 453 strcpy(value, p); 456 paranoid_free(incoming);454 mr_free(incoming); 457 455 return (0); 458 456 } 457 mr_free(incoming); 459 458 return (1); 460 459 } … … 473 472 { 474 473 FILE *fin; 475 char *tmp1 = NULL;476 474 int items; 477 475 … … 504 502 505 503 if (get_option_state(argc, argv, "hotspare")) { 506 strcpy(raidlist->spares.el[raidlist->spares.entries].name, 507 drivename); 508 strcpy(raidlist->spares.el[raidlist->spares.entries]. 509 device, devname); 504 strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename); 505 strcpy(raidlist->spares.el[raidlist->spares.entries]. device, devname); 510 506 raidlist->spares.el[raidlist->spares.entries].index = 511 507 raidlist->disks.entries; 512 508 raidlist->spares.entries++; 513 509 } else { 514 strcpy(raidlist->disks.el[raidlist->disks.entries].name, 515 drivename); 516 strcpy(raidlist->disks.el[raidlist->disks.entries].device, 517 devname); 510 strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename); 511 strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname); 518 512 raidlist->disks.el[raidlist->disks.entries].index = 519 513 raidlist->disks.entries; … … 587 581 fclose(fin); 588 582 log_it("Raidtab loaded successfully."); 589 mr_asprintf(tmp1, "%d RAID devices in raidtab", raidlist->entries); 590 log_it(tmp1); 591 mr_free(tmp1); 583 log_it("%d RAID devices in raidtab", raidlist->entries); 592 584 return (0); 593 585 } … … 596 588 #else 597 589 598 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, 599 char *fname) 600 { 601 FILE *fin; 602 char *label; 603 char *value; 590 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) { 591 592 FILE *fin = NULL; 593 char *label = NULL; 594 char *value = NULL; 604 595 int items; 605 596 int v; … … 680 671 681 672 /*@ add mallocs * */ 682 char *tmp = NULL;683 673 char *labelB; 684 674 char *valueB; … … 739 729 } 740 730 if (!disklist) { 741 mr_asprintf(tmp, "Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 742 log_it(tmp); 743 mr_free(tmp); 731 log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 744 732 } else { 745 733 index = atoi(valueB); … … 811 799 static char *argv[64]; 812 800 char **ap; 813 char *q; 814 char *line = (char *) malloc(MAX_STR_LEN); 815 816 if (!line) 817 errx(1, 818 "unable to allocate %i bytes of memory for `char *line' at %s:%i", 819 MAX_STR_LEN, __FILE__, __LINE__); 820 q = fgets(line, MAX_STR_LEN, f); 821 if (feof(f) && (q != NULL)) { 801 char *line = NULL; 802 803 mr_getline(line, f); 804 if (feof(f)) { 822 805 log_it("[GNVCL] Uh... I reached the EOF."); 823 806 return 0; … … 830 813 cnt++; 831 814 } 815 mr_free(line); 832 816 833 817 if (strchr(argv[cnt - 1], '\n')) { … … 1119 1103 while((token = mr_strtok (string, delims, &lastpos))) { 1120 1104 if ((pos = strstr(token, "("))) { 1121 1105 type = *(pos+1); 1122 1106 } else { 1123 1107 type = ' '; 1124 1108 } 1125 1109 pos = strstr(token, "["); … … 1127 1111 switch(type) { 1128 1112 case ' ': // normal data disks 1129 1130 1131 1132 1133 1134 1113 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1); 1114 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1115 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp); 1116 mr_free(strtmp); 1117 raidlist->el[raidlist->entries].data_disks.entries++; 1118 break; 1135 1119 case 'S': // spare disks 1136 1137 1138 1139 1140 1141 1120 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1); 1121 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1122 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp); 1123 mr_free(strtmp); 1124 raidlist->el[raidlist->entries].spare_disks.entries++; 1125 break; 1142 1126 case 'F': // failed disks 1143 1144 1145 1146 1147 1148 1149 1127 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1); 1128 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1129 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp); 1130 mr_free(strtmp); 1131 raidlist->el[raidlist->entries].failed_disks.entries++; 1132 log_it("At least one failed disk found in RAID array.\n"); 1133 break; 1150 1134 default: // error 1151 1152 1153 1154 1155 1135 log_msg(1, "Unknown device type '%c'\n", type); 1136 mr_free(string); 1137 mr_free(token); 1138 return 1; 1139 break; 1156 1140 } 1157 1141 mr_free(token); … … 1162 1146 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1163 1147 if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) { 1164 1148 index_min = raidlist->el[raidlist->entries].data_disks.el[i].index; 1165 1149 } 1166 1150 } 1167 1151 if (index_min > 0) { 1168 1152 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1169 1153 raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min; 1170 1154 } 1171 1155 } … … 1173 1157 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1174 1158 if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) { 1175 1159 index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index; 1176 1160 } 1177 1161 } 1178 1162 if (index_min > 0) { 1179 1163 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1180 1164 raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 1181 1165 } 1182 1166 } … … 1184 1168 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1185 1169 if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) { 1186 1170 index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index; 1187 1171 } 1188 1172 } 1189 1173 if (index_min > 0) { 1190 1174 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1191 1175 raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min; 1192 1176 } 1193 1177 } … … 1205 1189 } else { 1206 1190 while (*pos != ' ') { 1207 1208 1209 1210 1211 1212 1191 pos -= 1; 1192 if (pos < string) { 1193 log_it("String underflow!\n"); 1194 mr_free(string); 1195 return 1; 1196 } 1213 1197 } 1214 1198 raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1); … … 1224 1208 if (!(pos = strchr(string, '\%'))) { 1225 1209 if (strcasestr(string, "delayed")) { 1226 1210 raidlist->el[raidlist->entries].progress = -1; // delayed (therefore, stuck at 0%) 1227 1211 } else { 1228 1212 raidlist->el[raidlist->entries].progress = 999; // not found 1229 1213 } 1230 1214 } else { 1231 1215 while (*pos != ' ') { 1232 1233 1234 1235 1236 1237 1216 pos -= 1; 1217 if (pos < string) { 1218 printf("ERROR: String underflow!\n"); 1219 mr_free(string); 1220 return 1; 1221 } 1238 1222 } 1239 1223 raidlist->el[raidlist->entries].progress = atoi(pos); 1240 1224 } 1241 1225 break; 1242 1226 default: // error or IN PROGRESS 1243 1227 if (raidlist->el[raidlist->entries].progress != -1 && 1244 1228 raidlist->el[raidlist->entries].progress != 999) { … … 1246 1230 } 1247 1231 break; 1248 1249 1232 } 1233 row++; 1250 1234 } 1251 1235 // free string -
branches/3.0/mondo/src/common/libmondo-stream.c
r3185 r3188 138 138 } 139 139 sleep(1); 140 paranoid_system("sync");140 sync(); 141 141 sleep(1); 142 142 paranoid_pclose(g_tape_stream); 143 143 log_it("closein_tape() -- leaving"); 144 /*145 for(i=0; i < g_tapecatalog->entries; i++)146 {147 log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);148 }149 */150 144 if (!bkpinfo->please_dont_eject) { 151 145 eject_device(bkpinfo->media_device); … … 183 177 184 178 sleep(1); 185 paranoid_system("sync");179 sync(); 186 180 sleep(1); 187 181 log_it("closeout_tape() -- entering"); … … 228 222 g_tapecatalog->el[i].tape_posK); 229 223 } 230 // if (!bkpinfo->please_dont_eject)231 // { eject_device(bkpinfo->media_device); }232 224 paranoid_free(blk); 233 225 paranoid_free(g_tapecatalog); … … 266 258 char tmp[MAX_STR_LEN]; 267 259 char *command = NULL; 268 char cdr_exe[MAX_STR_LEN];260 char *cdr_exe = NULL; 269 261 int res; 270 262 … … 272 264 dev[0] = siz[0] = '\0'; 273 265 if (find_home_of_exe("cdrecord")) { 274 strcpy(cdr_exe, "cdrecord"); 275 } else { 276 strcpy(cdr_exe, "dvdrecord"); 277 } 278 mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", 279 cdr_exe); 280 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 266 mr_asprintf(cdr_exe, "cdrecord"); 267 } else { 268 mr_asprintf(cdr_exe, "dvdrecord"); 269 } 270 mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe); 271 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 281 272 mr_free(command); 282 273 283 274 if (atoi(tmp) != 1) { 284 log_it 285 ("Either too few or too many tape streamers for me to detect..."); 275 log_it("Either too few or too many tape streamers for me to detect..."); 286 276 strcpy(dev, VANILLA_SCSI_TAPE); 277 mr_free(tmp); 278 mr_free(cdr_exe); 287 279 return 1; 288 280 } 289 mr_ asprintf(command,290 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", 291 292 strcpy(tmp, call_program_and_get_last_line_of_output(command));281 mr_free(tmp); 282 283 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", cdr_exe); 284 mr_asprintf(tmp, "%s", all_program_and_get_last_line_of_output(command)); 293 285 mr_free(command); 294 286 295 287 if (strlen(tmp) < 2) { 296 288 log_it("Could not find tape device"); 289 mr_free(cdr_exe); 290 mr_free(tmp); 297 291 return 1; 298 292 } 299 mr_asprintf(command, 300 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1",301 cdr_exe); 302 strcpy(tmp, call_program_and_get_last_line_of_output(command));293 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe); 294 mr_free(cdr_exe); 295 296 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 303 297 mr_free(command); 304 298 … … 306 300 dev[strlen(dev) - 1] = '\0'; 307 301 strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN' 302 mr_free(tmp); 303 308 304 res = 0; 309 305 if (!mt_says_tape_exists(dev)) { … … 324 320 } 325 321 326 log_it("At this point, dev = %s and res = %d", dev, res); 327 328 strcpy(tmp, call_program_and_get_last_line_of_output("\ 329 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \ 330 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \ 331 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'")); 322 if (dev) { 323 log_it("At this point, dev = %s and res = %d", dev, res); 324 } else { 325 log_it("At this point, dev is NULL and res = %d", dev, res); 326 } 327 328 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'")); 332 329 333 330 if (mt_says_tape_exists(dev)) { … … 335 332 } else { 336 333 log_it("Turning %s", dev); 337 strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 334 mr_free(tmp); 335 mr_asprintf(tmp, "%s", (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 338 336 sprintf(dev, "/dev/os%s", tmp); 339 337 log_it("...into %s", dev); … … 355 353 siz[0] = '\0'; 356 354 log_it("Warning - size of tape unknown"); 357 return (0);358 355 } else { 359 356 strcpy(siz, tmp); 360 return (0); 361 } 362 } 363 364 365 366 357 } 358 mr_free(tmp); 359 return (0); 360 } 367 361 368 362 … … 479 473 log_it("Insisting on tape #%d", tapeno); 480 474 if (g_current_media_number != tapeno) { 481 mr_asprintf(tmp, 482 "When the tape drive goes quiet, please insert volume %d in this series.", 483 tapeno); 475 mr_asprintf(tmp, "When the tape drive goes quiet, please insert volume %d in this series.", tapeno); 484 476 popup_and_OK(tmp); 485 477 mr_free(tmp); … … 614 606 int res; 615 607 608 if (bkpinfo->media_device == NULL) { 609 return(1); 610 } 611 616 612 if (strncmp(bkpinfo->media_device, "/dev/", 5)) { 617 log_msg(1, 618 "Not using 'mt setblk'. This isn't an actual /dev entry."); 613 log_msg(1, "Not using 'mt setblk'. This isn't an actual /dev entry."); 619 614 return (0); 620 615 } … … 687 682 int res = 0; 688 683 684 if (bkpinfo->media_device == NULL) { 685 return(1); 686 } 687 689 688 log_it("Skipping OBDR headers"); 690 689 mr_asprintf(command, "mt -f %s rewind",bkpinfo->media_device); … … 712 711 char *command = NULL; 713 712 int res = 0; 713 714 if (bkpinfo->media_device == NULL) { 715 return(1); 716 } 714 717 715 718 log_it("Creating OBDR headers"); … … 780 783 /*@ end vars *************************************************** */ 781 784 782 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 783 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 784 fatal_error("Cannot alloc mem for tape catalog"); 785 } 785 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 786 786 g_tapecatalog->entries = 0; 787 787 g_tape_posK = 0; … … 800 800 if (bkpinfo->media_device == NULL) { 801 801 log_it("Not able to skip OBDR - Restore will have to be done manually"); 802 return (1); 802 803 } 803 804 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); … … 808 809 make_hole_for_file(outfname); 809 810 810 // start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);811 811 log_it("Opening IN tape"); 812 if (! 813 (g_tape_stream = 814 open_device_via_buffer(bkpinfo->media_device, 'r', 815 bkpinfo->internal_tape_block_size))) { 812 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { 816 813 log_OS_error(g_tape_fifo); 817 814 log_to_screen("Cannot openin stream device"); … … 821 818 log_to_screen("Reading stream"); 822 819 log_it("stream device = '%s'", bkpinfo->media_device); 823 /* skip data disks */820 /* skip data disks */ 824 821 open_evalcall_form("Skipping data disks on stream"); 825 822 log_to_screen("Skipping data disks on stream"); … … 874 871 // FIXME 875 872 } 876 mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", 877 outfname); 873 mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", outfname); 878 874 paranoid_system(tmp); 879 875 mr_free(tmp); … … 903 899 /*@ end vars *************************************************** */ 904 900 901 if (cddev == NULL) { 902 log_to_screen("Failed to openout NULL cddev"); 903 return (1); 904 } 905 905 /* add 'dummy' if testing */ 906 906 mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE); … … 942 942 return (0); 943 943 } 944 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 945 fatal_error("Cannot alloc mem for tape catalog"); 946 } 944 if (bkpinfo->media_device == NULL) { 945 log_it("Unable to openout NULL device"); 946 return(1); 947 } 948 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 947 949 g_tapecatalog->entries = 0; 948 950 g_tape_posK = 0; … … 954 956 } 955 957 log_it("Opening OUT tape"); 956 if (! 957 (g_tape_stream = 958 open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 958 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 959 959 log_OS_error(g_tape_fifo); 960 960 log_to_screen("Cannot openin stream device"); … … 969 969 /** 970 970 * Copy a file from the opened stream (CD or tape) to @p outfile. 971 * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used.972 971 * @param outfile The file to write to. 973 972 * @param size The size of the file in the input stream. … … 1031 1030 { 1032 1031 /*@ buffers ***************************************************** */ 1033 char *tmp = NULL;1034 1032 char *datablock; 1035 1033 char *temp_fname; 1036 1034 char *temp_cksum; 1037 1035 char *actual_cksum = NULL; 1038 // char *pA, *pB;1039 1036 1040 1037 /*@ int ********************************************************* */ … … 1078 1075 } 1079 1076 if (orig_size != temp_size && orig_size != -1) { 1080 mr_asprintf(tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10); 1081 log_to_screen(tmp); 1082 mr_free(tmp); 1077 log_to_screen("output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10); 1083 1078 } 1084 1079 if (ctrl_chr != BLK_START_FILE) { … … 1151 1146 } 1152 1147 if (strcmp(temp_cksum, actual_cksum)) { 1153 mr_asprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum, 1154 temp_cksum); 1155 log_to_screen(tmp); 1156 mr_free(tmp); 1157 1158 mr_asprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1159 (long) orig_size >> 10); 1160 log_to_screen(tmp); 1161 mr_free(tmp); 1162 1148 log_to_screen("actual cksum=%s; recorded cksum=%s", actual_cksum, temp_cksum); 1149 log_to_screen("%s (%ld K) is corrupt on tape", temp_fname, (long) orig_size >> 10); 1163 1150 retval++; 1164 1151 } … … 1204 1191 g_tape_posK += fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024; 1205 1192 } 1206 /* memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */1207 /* for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */1208 1193 memcpy((char *) plen, tempblock + 7001, sizeof(long long)); 1209 1194 if (strcmp(tempblock + 6000 + *pcontrol_char, STR_HEADER)) { … … 1211 1196 } 1212 1197 strcpy(filename, tempblock + 1000); 1213 /* strcpy(cksum,tempblock+5555);*/1214 /* log_it( "%s (reading) fname=%s, filesize=%ld K",1215 marker_to_string (*pcontrol_char), filename,1216 (long) ((*plen) >> 10));1217 */1218 1198 if (*pcontrol_char == BLK_ABORTED_BACKUP) { 1219 1199 log_to_screen("I can't verify an aborted backup."); … … 1363 1343 while (ctrl_chr != BLK_START_FILE) { 1364 1344 res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr); 1345 if (res) { 1346 //FIXME 1347 } 1365 1348 if (ctrl_chr == BLK_START_FILE) { 1366 1349 break; … … 1383 1366 } 1384 1367 while (strcmp(pA, pB)) { 1385 log_msg(6, "Skipping %s (it's not %s)", temp_fname, 1386 the_file_I_was_reading); 1368 log_msg(6, "Skipping %s (it's not %s)", temp_fname, the_file_I_was_reading); 1387 1369 for (size = temp_size; size > 0; size -= bytes_to_write) { 1388 1370 bytes_to_write = … … 1421 1403 } 1422 1404 } 1423 log_msg(2, "Reading %s (it matches %s)", temp_fname, 1424 the_file_I_was_reading); 1405 log_msg(2, "Reading %s (it matches %s)", temp_fname, the_file_I_was_reading); 1425 1406 paranoid_free(temp_fname); 1426 1407 paranoid_free(datablock); … … 1444 1425 /*@ end vars *************************************************** */ 1445 1426 1427 if (bkpinfo->media_device == NULL) { 1428 log_it("Unable to open in from NULL device"); 1429 return (1); 1430 } 1431 1446 1432 paranoid_pclose(g_tape_stream); 1447 1433 sync(); … … 1451 1437 insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too 1452 1438 log_it("Opening IN the next tape"); 1453 if (! 1454 (g_tape_stream = 1455 open_device_via_buffer(bkpinfo->media_device, 'r', 1456 bkpinfo->internal_tape_block_size))) { 1439 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { 1457 1440 log_OS_error(g_tape_fifo); 1458 1441 log_to_screen("Cannot openin stream device"); … … 1487 1470 char *command = NULL; 1488 1471 1472 if (bkpinfo->media_device == NULL) { 1473 log_it("Unable to open out from NULL device"); 1474 return (1); 1475 } 1476 1489 1477 paranoid_pclose(g_tape_stream); 1490 paranoid_system("sync");1491 paranoid_system("sync");1492 paranoid_system("sync");1478 sync(); 1479 sync(); 1480 sync(); 1493 1481 log_it("New tape requested."); 1494 1482 insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too 1495 1483 if (bkpinfo->backup_media_type == cdstream) { 1496 mr_asprintf(command, 1497 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 1498 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, 1499 MONDO_LOGFILE); 1484 mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, MONDO_LOGFILE); 1500 1485 log_it("Opening OUT to next CD with the command"); 1501 1486 log_it(command); … … 1510 1495 } else { 1511 1496 log_it("Opening OUT to next tape"); 1512 if (! 1513 (g_tape_stream = 1514 open_device_via_buffer(bkpinfo->media_device, 'w', 1515 bkpinfo->internal_tape_block_size))) { 1497 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 1516 1498 log_OS_error(g_tape_fifo); 1517 1499 log_to_screen("Cannot openin stream device"); … … 1584 1566 /*@ pointers *************************************************** */ 1585 1567 FILE *fin; 1586 char *tmp = NULL;1587 1568 1588 1569 /*@ long ******************************************************* */ … … 1602 1583 log_it("Data disks = %s", fname); 1603 1584 if (!does_file_exist(fname)) { 1604 mr_asprintf(tmp, "Cannot find %s", fname); 1605 log_to_screen(tmp); 1606 mr_free(tmp); 1585 log_to_screen("Cannot find %s", fname); 1607 1586 return (1); 1608 1587 } … … 1647 1626 { 1648 1627 /*@ buffers **************************************************** */ 1649 char *tmp = NULL;1650 1628 char datablock[TAPE_BLOCK_SIZE]; 1651 1629 char *checksum = NULL; … … 1700 1678 p++; 1701 1679 } 1702 mr_asprintf(tmp, "Writing file '%s' to tape (%ld KB)", p, 1703 (long) filesize >> 10); 1704 log_it(tmp); 1705 mr_free(tmp); 1680 log_it("Writing file '%s' to tape (%ld KB)", p, (long) filesize >> 10); 1706 1681 write_header_block_to_stream(filesize, infile_basename, 1707 1682 BLK_START_FILE); … … 1775 1750 /*@ buffers **************************************************** */ 1776 1751 char tempblock[TAPE_BLOCK_SIZE]; 1777 char *tmp = NULL;1778 1752 char *p; 1779 1753 … … 1794 1768 } 1795 1769 if (!g_tape_stream) { 1796 log_to_screen 1797 ("You're not backing up to tape. Why write a tape header?"); 1770 log_to_screen("You're not backing up to tape. Why write a tape header?"); 1798 1771 return (1); 1799 1772 } … … 1805 1778 memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t)); 1806 1779 strcpy(tempblock + 1000, filename); 1807 g_tape_posK += 1808 fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, 1809 g_tape_stream) / 1024; 1810 mr_asprintf(tmp, "%s (fname=%s, size=%ld K)", 1811 marker_to_string(control_char), p, 1812 (long) length_of_incoming_file >> 10); 1813 log_msg(6, tmp); 1814 mr_free(tmp); 1780 g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024; 1781 log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string(control_char), p, (long) length_of_incoming_file >> 10); 1815 1782 return (0); 1816 1783 } … … 1832 1799 void wrong_marker(int should_be, int it_is) 1833 1800 { 1834 /*@ buffer ***************************************************** */ 1835 char *tmp = NULL; 1836 1837 1838 /*@ end vars *************************************************** */ 1839 mr_asprintf(tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is)); 1840 log_to_screen(tmp); 1841 mr_free(tmp); 1801 log_to_screen("Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is)); 1842 1802 } 1843 1803 -
branches/3.0/mondo/src/common/libmondo-string.c
r3185 r3188 51 51 if (c && strncmp(c, "/disc", 5) == 0) { 52 52 /* yup it's devfs, return the "part" path */ 53 /* This strcpy is safe */ 53 54 strcpy(c + 1, "part"); 54 55 p = c + 5; … … 65 66 } 66 67 sprintf(p, "%d", partno); 67 return (partition); 68 } 69 70 71 72 73 74 75 76 77 78 79 68 return(partition); 69 } 80 70 81 71 … … 118 108 119 109 120 121 122 inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin)123 {124 char *p, *q;125 126 for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) {127 if (strchr("[]*?", *p)) {128 *(q++) = '\\';129 }130 }131 *q = *p; // for the final '\0'132 }133 134 135 136 110 /** 137 111 * Add commas every third place in @p input. … … 155 129 tmp[j - 6] = ','; 156 130 strcpy(tmp + j - 5, pos_w_commas + j - 6); 157 // tmp[j-2] = ',';158 // strcpy(tmp+j-1, pos_w_commas+j-3);159 131 strcpy(pos_w_commas, tmp); 160 132 } … … 170 142 return (output); 171 143 } 172 173 174 175 176 177 178 179 144 180 145 … … 217 182 long outval; 218 183 int i; 219 char *tmp ;184 char *tmp = NULL; 220 185 char ch; 221 186 … … 228 193 fatal_error("Please use integers only. No decimal points."); 229 194 } 230 malloc_string(tmp); 231 strcpy(tmp, incoming);195 196 mr_asprintf(tmp, "%s", incoming); 232 197 i = (int) strlen(tmp); 233 198 if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') { … … 238 203 tmp[i] = '\0'; 239 204 outval = atol(tmp); 205 mr_free(tmp); 206 240 207 if (ch == 'g' || ch == 'G') { 241 208 outval = outval * 1024; … … 253 220 fatal_error("Integer overflow."); 254 221 } else if (ch != 'm' && ch != 'M') { 255 sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", 256 incoming, ch); 222 mr_asprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch); 257 223 fatal_error(tmp); 258 224 } 259 paranoid_free(tmp);260 225 return (outval); 261 226 } … … 516 481 517 482 input = malloc(2000); 518 // BERLIOS: seems to cause invalid errors519 //assert_string_is_neither_NULL_nor_zerolength(ip);520 assert_string_is_neither_NULL_nor_zerolength(token);521 483 assert(value != NULL); 522 484 … … 557 519 /*@ buffers **************************************************** */ 558 520 static char output[MAX_STR_LEN]; 559 static char suffix[MAX_STR_LEN];521 char *suffix = NULL; 560 522 561 523 /*@ end vars *************************************************** */ … … 563 525 assert_string_is_neither_NULL_nor_zerolength(path); 564 526 if (s[0] != '\0') { 565 sprintf(suffix, ".%s", s);527 mr_asprintf(suffix, ".%s", s); 566 528 } else { 567 suffix[0] = '\0';568 } 569 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, 570 529 mr_asprintf(suffix, ""); 530 } 531 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, suffix); 532 mr_free(suffix); 571 533 return (output); 572 534 } … … 646 608 numA = atol(stringA + start_of_numbers_in_A); 647 609 numB = atol(stringB + start_of_numbers_in_B); 648 /*649 sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);650 log_to_screen(tmp);651 */652 610 return ((int) (numA - numB)); 653 611 } … … 775 733 in_out[i] = '\0'; 776 734 paranoid_free(tmp); 777 /* for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */778 735 } 779 736 … … 909 866 * @return The severity (1-3). 910 867 */ 911 int severity_of_difference(char *fn, char *out_reason) 912 { 913 int sev; 914 char *reason; 915 char *filename; 916 917 malloc_string(reason); 918 malloc_string(filename); 919 // out_reason might be null on purpose, so don't bomb if it is :) OK? 868 int severity_of_difference(char *fn, char *out_reason) { 869 870 int sev = 3; 871 char *reason = NULL; 872 char *filename = NULL; 873 874 // out_reason might be null on purpose, so don't bomb if it is :) OK? 920 875 assert_string_is_neither_NULL_nor_zerolength(fn); 921 876 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 922 strcpy(filename, fn + strlen(MNT_RESTORING));877 mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING)); 923 878 } else if (fn[0] != '/') { 924 sprintf(filename, "/%s", fn);879 mr_asprintf(filename, "/%s", fn); 925 880 } else { 926 strcpy(filename, fn); 927 } 928 929 sev = 3; 930 sprintf(reason, 931 "Changed since backup. Consider running a differential backup in a day or two."); 881 mr_asprintf(filename, "%s", fn); 882 } 883 884 mr_asprintf(reason, "Changed since backup. Consider running a differential backup in a day or two."); 885 932 886 if (!strncmp(filename, "/var/", 5)) { 933 887 sev = 2; 934 sprintf(reason,935 888 mr_free(reason); 889 mr_asprintf(reason, "/var's contents will change regularly, inevitably."); 936 890 } 937 891 if (!strncmp(filename, "/home", 5)) { 938 892 sev = 2; 939 sprintf(reason,940 893 mr_free(reason); 894 mr_asprintf(reason, "It's in your /home directory. Therefore, it is important."); 941 895 } 942 896 if (!strncmp(filename, "/usr/", 5)) { 943 897 sev = 3; 944 sprintf(reason,945 898 mr_free(reason); 899 mr_asprintf(reason, "You may have installed/removed software during the backup."); 946 900 } 947 901 if (!strncmp(filename, "/etc/", 5)) { 948 902 sev = 3; 949 sprintf(reason,950 903 mr_free(reason); 904 mr_asprintf(reason, "Do not edit config files while backing up your PC."); 951 905 } 952 906 if (!strcmp(filename, "/etc/adjtime") 953 907 || !strcmp(filename, "/etc/mtab")) { 954 908 sev = 1; 955 sprintf(reason, "This file changes all the time. It's OK."); 909 mr_free(reason); 910 mr_asprintf(reason, "This file changes all the time. It's OK."); 956 911 } 957 912 if (!strncmp(filename, "/root/", 6)) { 958 913 sev = 3; 959 sprintf(reason, "Were you compiling/editing something in /root?"); 914 mr_free(reason); 915 mr_asprintf(reason, "Were you compiling/editing something in /root?"); 960 916 } 961 917 if (!strncmp(filename, "/root/.", 7)) { 962 918 sev = 2; 963 sprintf(reason, "Temp or 'dot' files changed in /root."); 919 mr_free(reason); 920 mr_asprintf(reason, "Temp or 'dot' files changed in /root."); 964 921 } 965 922 if (!strncmp(filename, "/var/lib/", 9)) { 966 923 sev = 2; 967 sprintf(reason, "Did you add/remove software during backing?"); 924 mr_free(reason); 925 mr_asprintf(reason, "Did you add/remove software during backing?"); 968 926 } 969 927 if (!strncmp(filename, "/var/lib/rpm", 12)) { 970 928 sev = 3; 971 sprintf(reason, "Did you add/remove software during backing?"); 929 mr_free(reason); 930 mr_asprintf(reason, "Did you add/remove software during backing?"); 972 931 } 973 932 if (!strncmp(filename, "/var/lib/slocate", 16)) { 974 933 sev = 1; 975 sprintf(reason,976 934 mr_free(reason); 935 mr_asprintf(reason, "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); 977 936 } 978 937 if (!strncmp(filename, "/var/log/", 9) … … 980 939 || !strcmp(filename + strlen(filename) - 4, ".log")) { 981 940 sev = 1; 982 sprintf(reason,983 941 mr_free(reason); 942 mr_asprintf(reason, "Log files change frequently as the computer runs. Fret not."); 984 943 } 985 944 if (!strncmp(filename, "/var/spool", 10)) { 986 945 sev = 1; 987 sprintf(reason,988 946 mr_free(reason); 947 mr_asprintf(reason, "Background processes or printers were active. This does not affect the integrity of your backup."); 989 948 } 990 949 if (!strncmp(filename, "/var/spool/mail", 10)) { 991 950 sev = 2; 992 sprintf(reason, "Mail was sent/received during backup."); 951 mr_free(reason); 952 mr_asprintf(reason, "Mail was sent/received during backup."); 993 953 } 994 954 if (filename[strlen(filename) - 1] == '~') { 995 955 sev = 1; 996 sprintf(reason,997 956 mr_free(reason); 957 mr_asprintf(reason, "Backup copy of another file which was modified recently."); 998 958 } 999 959 if (strstr(filename, "cache")) { 1000 960 sev = 1; 1001 sprintf(reason,1002 961 mr_free(reason); 962 mr_asprintf(reason, "Part of a cache of data. Caches change from time to time. Don't worry."); 1003 963 } 1004 964 if (!strncmp(filename, "/var/run/", 9) … … 1007 967 || strstr(filename, "/.Xauthority")) { 1008 968 sev = 1; 1009 sprintf(reason,1010 969 mr_free(reason); 970 mr_asprintf(reason, "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 1011 971 } 1012 972 if (out_reason) { 1013 973 strcpy(out_reason, reason); 1014 974 } 1015 paranoid_free(filename);1016 paranoid_free(reason);975 mr_free(filename); 976 mr_free(reason); 1017 977 return (sev); 1018 978 } … … 1064 1024 /*@ buffers ******************************************* */ 1065 1025 static char outstr[MAX_STR_LEN]; 1066 char *pos_w_commas , *tmp;1026 char *pos_w_commas = NULL; 1067 1027 char *mds = NULL; 1028 char *tmp = NULL; 1068 1029 1069 1030 assert(bkpinfo != NULL); 1070 malloc_string(pos_w_commas); 1071 malloc_string(tmp); 1072 sprintf(tmp, "%lld", g_tape_posK); 1073 strcpy(pos_w_commas, commarize(tmp)); 1074 1075 1076 1077 if (bkpinfo->media_size <= 0) 1078 // { fatal_error( "percentage_media_full_comment() - unknown media size"); } 1079 { 1080 sprintf(outstr, "Volume %d: %s kilobytes archived so far", 1081 g_current_media_number, pos_w_commas); 1031 1032 if (bkpinfo->media_size <= 0) { 1033 mr_asprintf(tmp, "%lld", g_tape_posK); 1034 mr_asprintf(pos_w_commas, "%s", commarize(tmp)); 1035 mr_free(tmp); 1036 sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas); 1037 mr_free(pos_w_commas); 1082 1038 return (outstr); 1083 1039 } 1084 1040 1085 /* update screen */1041 /* update screen */ 1086 1042 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1087 1043 percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size); … … 1091 1047 sprintf(outstr, "Volume %d: [", g_current_media_number); 1092 1048 } else { 1093 percentage = 1094 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1049 percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1095 1050 mds = media_descriptor_string(bkpinfo->backup_media_type); 1096 1051 sprintf(outstr, "%s %d: [", mds, g_current_media_number); … … 1105 1060 j = (int) strlen(outstr); 1106 1061 sprintf(outstr + j, "] %d%% used", percentage); 1107 paranoid_free(pos_w_commas);1108 paranoid_free(tmp);1109 1062 return (outstr); 1110 1063 } -
branches/3.0/mondo/src/common/libmondo-tools.c
r3185 r3188 30 30 31 31 extern int g_tape_buffer_size_MB; 32 extern char *g_serial_string;33 32 extern bool g_text_mode; 34 33 extern int g_currentY; 35 34 extern int g_current_media_number; 36 35 extern char *MONDO_LOGFILE; 36 extern char *g_serial_string; 37 37 38 38 /* Reference to global bkpinfo */ … … 113 113 return; 114 114 } 115 #ifndef _XWIN116 115 if (!g_text_mode) 117 116 newtSuspend(); 118 #endif119 117 printf("ASSERTION FAILED: `%s'\n", exp); 120 118 printf("\tat %s:%d in %s\n\n", file, line, function); … … 163 161 getchar(); // skip \n 164 162 165 #ifndef _XWIN166 163 if (!g_text_mode) 167 164 newtResume(); 168 #endif169 165 } 170 166 … … 175 171 void clean_up_KDE_desktop_if_necessary(void) 176 172 { 177 char *tmp; 178 179 malloc_string(tmp); 180 strcpy(tmp, 181 "for i in `find /root /home -maxdepth 2 -type d -name Desktop`; do \ 182 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \ 183 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \ 184 else { print $0;};}' $file.old > $file ; fi ; done"); 173 char *tmp = NULL; 174 175 mr_asprintf(tmp, "for i in `find /root /home -maxdepth 2 -type d -name Desktop -maxdepth 2`; do file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } else { print $0;};}' $file.old > $file ; fi ; done"); 185 176 run_program_and_log_output(tmp, 5); 186 paranoid_free(tmp);177 mr_free(tmp); 187 178 } 188 179 … … 232 223 double get_kernel_version(void) 233 224 { 234 char *p, tmp[200]; 225 char *p = NULL; 226 char *tmp = NULL; 235 227 double d; 236 228 #ifdef __FreeBSD__ … … 238 230 d = 5.2; // :-) 239 231 #else 240 strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));232 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r")); 241 233 p = strchr(tmp, '.'); 242 234 if (p) { … … 249 241 } 250 242 } 251 // log_msg(1, "tmp = '%s'", tmp);252 243 d = atof(tmp); 244 mr_free(tmp); 253 245 #endif 254 246 log_msg(1, "g_kernel_version = %f", d); … … 257 249 258 250 259 260 261 262 251 /** 263 252 * Get the current time. … … 268 257 return (long) time((void *) 0); 269 258 } 270 271 272 273 274 275 259 276 260 … … 368 352 char *mondo_mkisofs_sz = NULL; 369 353 char *command = NULL; 370 char *mtpt; 371 char *hostname; 354 char *hostname = NULL; 372 355 char *isofs_cmd = NULL; 373 356 char *ip_address = NULL; 374 357 int retval = 0; 375 358 char *colon; 376 char *cdr_exe ;359 char *cdr_exe = NULL; 377 360 char *tmp = NULL; 378 char call_before_iso_user[MAX_STR_LEN] = "\0"; 379 /* 380 long avm = 0; 381 int rdsiz_MB; 382 */ 361 char *p = NULL; 362 char *call_before_iso_user = NULL; 383 363 char *iso_dev = NULL; 384 364 char *iso_mnt = NULL; … … 387 367 388 368 assert(bkpinfo != NULL); 389 malloc_string(mtpt); 390 malloc_string(hostname); 391 malloc_string(cdr_exe); 369 392 370 bkpinfo->optimal_set_size = 393 371 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 400 378 } 401 379 log_msg(1, "Tape"); 380 if (bkpinfo->media_device == NULL) { 381 return(1); 382 } 402 383 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 403 384 log_msg(1, "tmp = '%s'", tmp); … … 429 410 strcpy(bkpinfo->zip_exe, "gzip"); 430 411 strcpy(bkpinfo->zip_suffix, "gz"); 412 } else if (bkpinfo->use_lzma) { 413 strcpy(bkpinfo->zip_exe, "lzma"); 414 strcpy(bkpinfo->zip_suffix, "lzma"); 431 415 } else if (bkpinfo->compression_level != 0) { 432 416 strcpy(bkpinfo->zip_exe, "bzip2"); … … 440 424 if (bkpinfo->backup_media_type == dvd) { 441 425 if (find_home_of_exe("growisofs")) { 442 strcpy(cdr_exe, "growisofs");426 mr_asprintf(cdr_exe, "growisofs"); 443 427 } // unlikely to be used 444 428 else { … … 462 446 } 463 447 #endif 464 else 465 { 448 else { 466 449 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 467 450 } 468 451 if (bkpinfo->manual_cd_tray) { 469 paranoid_free(mondo_mkisofs_sz);470 452 fatal_error("Manual CD tray + DVD not supported yet."); 471 453 // -m isn't supported by growisofs, BTW... … … 475 457 mondo_mkisofs_sz, 476 458 "", bkpinfo->media_device); 477 paranoid_free(mondo_mkisofs_sz);478 }459 } 460 mr_free(mondo_mkisofs_sz); 479 461 if (getenv ("SUDO_COMMAND")) { 480 462 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); … … 486 468 mr_free(command); 487 469 } 488 log_msg(2, "call_make_iso (DVD res) is ... %s", 489 bkpinfo->call_make_iso); 470 log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso); 490 471 } // end of DVD code 491 472 … … 504 485 } 505 486 if (find_home_of_exe("cdrecord")) { 506 strcpy(cdr_exe, "cdrecord");487 mr_asprintf(cdr_exe, "cdrecord"); 507 488 } else if (find_home_of_exe("dvdrecord")) { 508 strcpy(cdr_exe, "dvdrecord");489 mr_asprintf(cdr_exe, "dvdrecord"); 509 490 } else { 510 491 fatal_error("Please install either cdrecord or dvdrecord."); … … 544 525 mondo_mkisofs_sz, bkpinfo->tmpdir); 545 526 } else { 546 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN); 547 sprintf (bkpinfo->call_before_iso, 548 "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", 549 mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 527 mr_asprintf(call_before_iso_user, "%s", bkpinfo->call_before_iso); 528 sprintf(bkpinfo->call_before_iso, "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 529 mr_free(call_before_iso_user); 550 530 } 551 531 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso); 552 sprintf(bkpinfo->call_make_iso, 553 "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, 554 cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", 555 extra_cdrom_params, bkpinfo->media_device, 556 bkpinfo->cdrw_speed, bkpinfo->tmpdir); 532 sprintf(bkpinfo->call_make_iso, "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed, bkpinfo->tmpdir); 557 533 } else { 558 sprintf(bkpinfo->call_make_iso, 559 "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", 560 mondo_mkisofs_sz, cdr_exe, 561 (bkpinfo->please_dont_eject) ? " " : "-eject", 562 extra_cdrom_params, bkpinfo->media_device, 563 bkpinfo->cdrw_speed); 564 } 565 paranoid_free(mondo_mkisofs_sz); 566 paranoid_free(extra_cdrom_params); 534 sprintf(bkpinfo->call_make_iso, "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", mondo_mkisofs_sz, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed); 535 } 536 mr_free(cdr_exe); 537 mr_free(mondo_mkisofs_sz); 538 mr_free(extra_cdrom_params); 567 539 } // end of CD code 568 540 … … 577 549 578 550 log_it("isodir = %s", bkpinfo->isodir); 579 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", 580 bkpinfo->isodir); 551 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir); 581 552 log_it("command = %s", command); 582 log_it("res of it = %s", call_program_and_get_last_line_of_output(command));583 553 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 554 log_it("res of it = %s", iso_dev); 584 555 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 585 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));556 write_one_liner_data_file(tmp, iso_dev); 586 557 mr_free(tmp); 587 558 mr_free(command); … … 591 562 592 563 log_it("command = %s", command); 593 log_it("res of it = %s", call_program_and_get_last_line_of_output(command));594 564 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 565 log_it("res of it = %s", iso_mnt); 595 566 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 596 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));567 write_one_liner_data_file(tmp, iso_mnt); 597 568 mr_free(tmp); 598 569 mr_free(command); … … 612 583 } 613 584 } 585 mr_free(iso_mnt); 614 586 mr_free(iso_tmp); 615 mr_free(iso_mnt);616 587 617 588 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); … … 632 603 633 604 if (bkpinfo->backup_media_type == netfs) { 634 strcpy(hostname, bkpinfo->netfs_mount); 605 if (bkpinfo->netfs_mount) { 606 mr_asprintf(hostname, "%s", bkpinfo->netfs_mount); 607 } else { 608 log_it("netfs_mount is NULL"); 609 retval++; 610 mr_asprintf(hostname, ""); 611 } 635 612 colon = strchr(hostname, ':'); 636 613 if (!colon) { … … 651 628 } 652 629 if (!hent) { 653 log_it("Can't resolve Network mount (%s): %s", hostname, 654 hstrerror(h_errno)); 630 log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno)); 655 631 retval++; 656 632 } else { … … 658 634 mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':')); 659 635 strcpy(bkpinfo->netfs_mount, ip_address); 660 paranoid_free(ip_address);636 mr_free(ip_address); 661 637 } 662 638 } 639 mr_free(hostname); 663 640 store_netfs_config(); 664 641 } … … 668 645 fprintf(stderr, "Type 'man mondoarchive' for help.\n"); 669 646 } 670 if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) { 671 log_it("tmpdir or scratchdir are blank/missing"); 672 retval++; 673 } 674 if (bkpinfo->include_paths[0] == '\0') { 675 // fatal_error ("Why no backup path?"); 676 strcpy(bkpinfo->include_paths, "/"); 677 } 678 chmod(bkpinfo->scratchdir, 0700); 647 if (bkpinfo->include_paths == NULL) { 648 mr_asprintf(bkpinfo->include_paths, "/"); 649 } 679 650 g_backup_media_type = bkpinfo->backup_media_type; 680 paranoid_free(mtpt);681 paranoid_free(hostname);682 paranoid_free(cdr_exe);683 651 return (retval); 684 652 } … … 704 672 if (bkpinfo->disaster_recovery) { 705 673 if (!does_nonMS_partition_exist()) { 706 fatal_error 707 ("I am in disaster recovery mode\nPlease don't run mondoarchive."); 674 fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive."); 708 675 } 709 676 } … … 713 680 paranoid_free(tmp); 714 681 if (find_and_store_mondoarchives_home(g_mondo_home)) { 715 fprintf(stderr, 716 "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 682 fprintf(stderr, "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 717 683 res++; 718 684 return (res); … … 723 689 } 724 690 g_current_media_number = 1; 725 bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] ='\0';691 bkpinfo->postnuke_tarball[0] = '\0'; 726 692 return (res); 727 693 } … … 772 738 if (p == NULL) { 773 739 log_it("Failed to create global tmp directory %s for Mondo.",tmp); 740 mr_free(tmp); 774 741 finish(-1); 775 742 } 743 mr_free(tmp); 744 776 745 strcpy(bkpinfo->tmpdir,p); 777 paranoid_free(tmp);746 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 778 747 779 748 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); … … 817 786 } 818 787 strcpy(bkpinfo->scratchdir,p); 788 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 819 789 paranoid_free(tmp); 820 790 … … 832 802 { 833 803 int i; 834 835 log_msg(1, "Hi"); 804 log_msg(1, "Initializing bkpinfo"); 805 836 806 assert(bkpinfo != NULL); 837 807 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); … … 847 817 bkpinfo->use_lzo = FALSE; 848 818 bkpinfo->use_gzip = FALSE; 849 bkpinfo-> do_not_compress_these[0] = '\0';819 bkpinfo->use_lzma = FALSE; 850 820 bkpinfo->verify_data = FALSE; 851 821 bkpinfo->backup_data = FALSE; … … 853 823 bkpinfo->use_star = FALSE; 854 824 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 855 bkpinfo->disaster_recovery = 856 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 825 826 /* We need tmpdir as early as possible for further function calls */ 827 bkpinfo->tmpdir = NULL; // Really setup after 828 setup_tmpdir(NULL); 829 setup_scratchdir(NULL); 830 831 bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode(); 857 832 if (bkpinfo->disaster_recovery) { 858 833 strcpy(bkpinfo->isodir, "/"); … … 861 836 } 862 837 strcpy(bkpinfo->prefix, STD_PREFIX); 863 setup_tmpdir(NULL);864 setup_scratchdir(NULL);865 866 838 bkpinfo->optimal_set_size = 0; 867 strcpy(bkpinfo->include_paths, "/");839 bkpinfo->backup_media_type = none; 868 840 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 869 bkpinfo->include_paths[0] = '\0'; 841 bkpinfo->exclude_paths = NULL; 842 bkpinfo->include_paths = NULL; 870 843 bkpinfo->exclude_devs = NULL; 871 844 bkpinfo->restore_path[0] = '\0'; … … 879 852 bkpinfo->netfs_user = NULL; 880 853 bkpinfo->netfs_remote_dir[0] = '\0'; 881 bkpinfo-> exclude_paths = NULL;854 bkpinfo->postnuke_tarball[0] = '\0'; 882 855 bkpinfo->subdir = NULL; 883 bkpinfo->postnuke_tarball[0] = '\0';884 856 bkpinfo->wipe_media_first = FALSE; 885 857 bkpinfo->differential = 0; … … 894 866 895 867 896 897 898 868 /** 899 869 * Get the remaining free space (in MB) on @p partition. … … 916 886 mr_free(command); 917 887 918 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 919 partition); 888 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition); 920 889 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 921 890 mr_free(command); … … 957 926 if (system("which mkfs.vfat 2> /dev/null 1> /dev/null") 958 927 && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) { 959 log_it 960 ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 961 run_program_and_log_output 962 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 963 } 964 mr_asprintf(tmp, "%s", 965 call_program_and_get_last_line_of_output 966 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 928 log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 929 run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 930 } 931 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 967 932 if (atol(tmp) < 35000) { 968 933 retval++; … … 970 935 } 971 936 if (atol(tmp) < 66000) { 972 log_to_screen 973 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 937 log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 974 938 } 975 939 mr_free(tmp); … … 1026 990 whine_if_not_found("cmp"); 1027 991 } 1028 run_program_and_log_output 1029 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 1030 mr_asprintf(tmp, "%s", 1031 call_program_and_get_last_line_of_output 1032 ("mount | grep -E \"cdr(om|w)\"")); 992 run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 993 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"")); 1033 994 if (strcmp("", tmp)) { 1034 995 if (strstr(tmp, "autofs")) { … … 1104 1065 /*@ buffer ****************************************************** */ 1105 1066 char *command = NULL; 1106 char *tmp = NULL;1107 1067 1108 1068 /*@ end vars *************************************************** */ … … 1111 1071 assert_string_is_neither_NULL_nor_zerolength(label); 1112 1072 if (!does_file_exist(config_file)) { 1113 mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", 1114 config_file); 1115 log_to_screen(tmp); 1116 mr_free(tmp); 1117 1073 log_to_screen("(read_cfg_var) Cannot find %s config file", config_file); 1118 1074 value[0] = '\0'; 1119 1075 return (1); … … 1127 1083 mr_free(command); 1128 1084 1085 log_msg(4, "Configuration item %s is %s", label, value); 1129 1086 if (strlen(value) == 0) { 1130 1087 return (1); … … 1242 1199 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1243 1200 */ 1244 void mount_boot_if_necessary() 1245 { 1201 void mount_boot_if_necessary() { 1246 1202 char *tmp = NULL; 1247 1203 char *command = NULL; … … 1251 1207 g_boot_mountpt[0] = '\0'; 1252 1208 log_msg(4, "Done. Great. Seeting command to something"); 1253 mr_asprintf(command, "%s", 1254 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1209 mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1255 1210 log_msg(4, "Cool. Command = '%s'", command); 1256 1211 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); … … 1258 1213 1259 1214 log_msg(4, "tmp = '%s'", tmp); 1260 if (tmp[0]) { 1261 log_it("/boot is at %s according to /etc/fstab", tmp); 1262 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1263 mr_free(tmp); 1264 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1265 mr_free(command); 1266 1267 if (!strcmp(tmp,"")) { 1268 if (((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")) != NULL)) { 1269 if (!run_program_and_log_output("mount /boot", 5)) { 1270 strcpy(g_boot_mountpt, "/boot"); 1271 log_msg(1, "Mounted /boot"); 1272 } else { 1273 log_it("...ignored cos it's a label or uuid :-)"); 1215 log_it("/boot is at %s according to /etc/fstab", tmp); 1216 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1217 mr_free(tmp); 1218 1219 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1220 mr_free(command); 1221 1222 if (!strcmp(tmp,"")) { 1223 if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) { 1224 if (!run_program_and_log_output("mount /boot", 5)) { 1225 strcpy(g_boot_mountpt, "/boot"); 1226 log_msg(1, "Mounted /boot"); 1227 } else { 1228 log_it("...ignored cos it's a label or uuid :-)"); 1229 } 1230 } else { 1231 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1232 log_msg(3, "command = %s", command); 1233 if (run_program_and_log_output(command, 5)) { 1234 strcpy(g_boot_mountpt, tmp); 1235 mr_free(tmp); 1236 log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt); 1237 1238 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1239 if (run_program_and_log_output(tmp, 5)) { 1240 g_boot_mountpt[0] = '\0'; 1241 log_msg(1, "Plan B"); 1242 if (!run_program_and_log_output("mount /boot", 5)) { 1243 strcpy(g_boot_mountpt, "/boot"); 1244 log_msg(1, "Plan B worked"); 1245 } else { 1246 log_msg(1, 1247 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition."); 1248 } 1274 1249 } 1275 } else {1276 mr_asprintf(command, "mount | grep -E '^%s'", tmp);1277 log_msg(3, "command = %s", command);1278 if (run_program_and_log_output(command, 5)) {1279 strcpy(g_boot_mountpt, tmp);1280 mr_free(tmp);1281 mr_asprintf(tmp,1282 "%s (your /boot partition) is not mounted. I'll mount it before backing up",1283 g_boot_mountpt);1284 log_it(tmp);1285 mr_free(tmp);1286 1287 mr_asprintf(tmp, "mount %s", g_boot_mountpt);1288 if (run_program_and_log_output(tmp, 5)) {1289 g_boot_mountpt[0] = '\0';1290 log_msg(1, "Plan B");1291 if (!run_program_and_log_output("mount /boot", 5)) {1292 strcpy(g_boot_mountpt, "/boot");1293 log_msg(1, "Plan B worked");1294 } else {1295 log_msg(1,1296 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");1297 }1298 }1299 mr_free(tmp);1300 }1301 mr_free(command);1302 1250 } 1303 } 1304 } 1251 mr_free(command); 1252 } 1253 } 1254 mr_free(tmp); 1305 1255 log_msg(1, "Ended sub"); 1306 1256 } … … 1340 1290 char *command = NULL; 1341 1291 char *tempfile = NULL; 1342 char *tmp = NULL;1343 1292 1344 1293 … … 1348 1297 assert(value != NULL); 1349 1298 if (!does_file_exist(config_file)) { 1350 mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", 1351 config_file); 1352 log_to_screen(tmp); 1353 mr_free(tmp); 1299 log_to_screen("(write_cfg_file) Cannot find %s config file", config_file); 1354 1300 return (1); 1355 1301 } 1356 1302 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1357 1303 if (does_file_exist(config_file)) { 1358 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", 1359 label, config_file, tempfile); 1304 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile); 1360 1305 paranoid_system(command); 1361 1306 mr_free(command); … … 1378 1323 * information to the logfile. 1379 1324 */ 1380 void standard_log_debug_msg(int debug_level, const char *szFile, 1381 const char *szFunction, int nLine, 1382 const char *fmt, ...) 1383 { 1325 void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) { 1326 1384 1327 va_list args; 1385 int i;1386 1328 static int depth = 0; 1387 1329 FILE *fout; … … 1396 1338 if (!(fout = fopen(MONDO_LOGFILE, "a"))) { 1397 1339 return; 1398 } // fatal_error("Failed to openout to logfile - sheesh..."); }1340 } 1399 1341 1400 1342 // add tabs to distinguish log levels 1401 1343 if (debug_level > 0) { 1402 for (i = 1; i < debug_level; i++) 1403 fprintf(fout, "\t"); 1344 fprintf(fout, "DBG%d: ", debug_level); 1404 1345 if (getpid() == g_main_pid) 1405 1346 fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine); … … 1408 1349 else 1409 1350 fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine); 1351 } else { 1352 fprintf(fout, "INFO: "); 1410 1353 } 1411 1354 va_start(args, fmt); … … 1413 1356 va_end(args); 1414 1357 1415 // do not slow down the progran if standard debug level1416 // must be enabled: if no flush, the log won't be up-to-date if there1417 // is a segfault1418 //if (g_dwDebugLevel != 1)1419 1420 1358 fprintf(fout, "\n"); 1421 1359 paranoid_fclose(fout); … … 1430 1368 ...) = standard_log_debug_msg; 1431 1369 1432 1433 /**1434 * If @p y, malloc @p x, else free @p x.1435 * @bug This function seems orphaned. Please remove.1436 */1437 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }1438 1370 1439 1371 /** … … 1446 1378 malloc_string(g_boot_mountpt); 1447 1379 malloc_string(g_mondo_home); 1448 /*1449 malloc_string(g_tmpfs_mountpt);1450 */1451 1380 malloc_string(g_serial_string); 1452 1381 malloc_string(g_magicdev_command); … … 1454 1383 paranoid_free(g_boot_mountpt); 1455 1384 paranoid_free(g_mondo_home); 1456 /*1457 paranoid_free(g_tmpfs_mountpt);1458 */1459 paranoid_free(g_serial_string);1460 1385 paranoid_free(g_magicdev_command); 1461 1386 1462 } 1463 1464 /* 1465 char**list_of_arrays[] = { 1466 &g_boot_mountpt, 1467 &g_mondo_home, 1468 &g_tmpfs_mountpt, 1469 &g_serial_string, 1470 &g_magicdev_command, 1471 NULL}; 1472 1473 char**ppcurr; 1474 int i; 1475 1476 for(i=0;list_of_arrays[i];i++) 1477 { 1478 log_msg(5, "Allocating %d", i); 1479 ppcurr = list_of_arrays[i]; 1480 if (mal) 1481 { *ppcurr = malloc(MAX_STR_LEN); } 1482 else 1483 { 1484 if (*ppcurr) 1485 { 1486 free(*ppcurr); 1487 } 1488 } 1489 } 1490 log_msg(5, "Returning"); 1491 */ 1387 mr_free(g_serial_string); 1388 } 1492 1389 } 1493 1390 … … 1518 1415 void stop_magicdev_if_necessary() 1519 1416 { 1520 strcpy(g_magicdev_command, 1521 call_program_and_get_last_line_of_output 1522 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1417 strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1523 1418 if (g_magicdev_command[0]) { 1524 1419 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command); -
branches/3.0/mondo/src/common/libmondo-verify.c
r3185 r3188 55 55 assert(bkpinfo != NULL); 56 56 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 57 sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno, 58 bkpinfo->zip_suffix); 57 sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno, bkpinfo->zip_suffix); 59 58 if (!does_file_exist(output)) { 60 sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno, 61 bkpinfo->zip_suffix); 59 sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno, bkpinfo->zip_suffix); 62 60 } 63 61 return (output); … … 80 78 { 81 79 /*@ buffer ********************************************************** */ 82 char *command ;83 char *afio_found_changes ;80 char *command = NULL; 81 char *afio_found_changes = NULL; 84 82 85 83 /*@ int ************************************************************* */ … … 89 87 long afio_diffs = 0; 90 88 91 command = malloc(2000);92 afio_found_changes = malloc(500);93 89 assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname); 94 90 assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname); 95 91 assert_string_is_neither_NULL_nor_zerolength(stderr_fname); 96 92 97 sprintf(afio_found_changes, "%s.afio", ignorefiles_fname); 98 paranoid_system("sync"); 99 100 /* sprintf (command, 101 "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s", 102 stderr_fname, afio_found_changes); 103 */ 93 mr_asprintf(afio_found_changes, "%s.afio", ignorefiles_fname); 94 sync(); 104 95 105 96 log_msg(1, "Now scanning log file for 'afio: ' stuff"); 106 sprintf(command, 107 "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s", 108 stderr_fname, afio_found_changes); 97 mr_asprintf(command, "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes); 109 98 log_msg(2, command); 110 99 res = system(command); 100 mr_free(command); 101 111 102 if (res) { 112 103 log_msg(2, "Warning - failed to think"); … … 114 105 115 106 log_msg(1, "Now scanning log file for 'star: ' stuff"); 116 sprintf(command, 117 "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s", 118 stderr_fname, afio_found_changes); 107 mr_asprintf(command, "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes); 119 108 log_msg(2, command); 120 109 res = system(command); 110 mr_free(command); 111 121 112 if (res) { 122 113 log_msg(2, "Warning - failed to think"); 123 114 } 124 // exclude_nonexistent_files (afio_found_changes);125 115 afio_diffs = count_lines_in_file(afio_found_changes); 126 sprintf(command, 127 "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", 128 ignorefiles_fname, afio_found_changes, afio_found_changes, 129 changedfiles_fname); 116 mr_asprintf(command, "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", ignorefiles_fname, afio_found_changes, afio_found_changes, changedfiles_fname); 117 mr_free(afio_found_changes); 130 118 log_msg(2, command); 131 119 paranoid_system(command); 132 paranoid_free(command); 133 paranoid_free(afio_found_changes); 120 mr_free(command); 134 121 return (afio_diffs); 135 122 } … … 151 138 152 139 /*@ buffers ********************************************************* */ 153 char *tmp ;140 char *tmp = NULL; 154 141 char *mds = NULL; 155 142 … … 162 149 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 163 150 assert(bkpinfo != NULL); 164 malloc_string(tmp);165 151 166 152 for (set_number = 0; … … 175 161 if (g_last_afioball_number != set_number - 1) { 176 162 if (set_number == 0) { 177 log_msg(1, 178 "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 163 log_msg(1, "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 179 164 } else { 180 165 retval++; 181 sprintf(tmp, "Warning - missing set(s) between %d and %d\n", 182 g_last_afioball_number, set_number - 1); 183 log_to_screen(tmp); 166 log_to_screen("Warning - missing set(s) between %d and %d\n", g_last_afioball_number, set_number - 1); 184 167 } 185 168 } 186 169 mds = media_descriptor_string(bkpinfo->backup_media_type); 187 sprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number);170 mr_asprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number); 188 171 mr_free(mds); 189 172 190 173 open_evalcall_form(tmp); 174 mr_free(tmp); 191 175 192 176 for (total_sets = set_number; … … 208 192 g_last_afioball_number = set_number - 1; 209 193 close_evalcall_form(); 210 paranoid_free(tmp);211 194 return (retval); 212 195 } … … 227 210 228 211 /*@ buffer ********************************************************** */ 229 char *tmp; 230 char *mountpoint; 231 // char ca, cb; 232 char *command; 212 char *tmp = NULL; 213 char *mountpoint = NULL; 214 char *command = NULL; 233 215 char *mds = NULL; 234 char *sz_exe ;216 char *sz_exe = NULL; 235 217 static char *bufblkA = NULL; 236 218 static char *bufblkB = NULL; … … 252 234 FILE *fin; 253 235 int retval = 0; 254 // long long outlen; 255 256 malloc_string(tmp); 257 malloc_string(mountpoint); 258 malloc_string(command); 259 malloc_string(sz_exe); 236 260 237 if (!bufblkA) { 261 238 if (!(bufblkA = malloc(maxbufsize))) { … … 274 251 if (bkpinfo->compression_level > 0) { 275 252 if (bkpinfo->use_lzo) { 276 strcpy(sz_exe, "lzop");253 mr_asprintf(sz_exe, "lzop"); 277 254 } else if (bkpinfo->use_gzip) { 278 strcpy(sz_exe, "gzip"); 255 mr_asprintf(sz_exe, "gzip"); 256 } else if (bkpinfo->use_lzma) { 257 mr_asprintf(sz_exe, "lzma"); 279 258 } else { 280 strcpy(sz_exe, "bzip2"); 281 } 282 } else { 283 sz_exe[0] = '\0'; 259 mr_asprintf(sz_exe, "bzip2"); 260 } 284 261 } 285 262 286 263 log_it("before vsbf"); 287 264 mds = media_descriptor_string(bkpinfo->backup_media_type); 288 sprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number);265 mr_asprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number); 289 266 mr_free(mds); 290 267 291 268 open_evalcall_form(tmp); 269 mr_free(tmp); 270 292 271 log_it("after vsbf"); 293 sprintf(mountpoint, "%s/archives", mtpt);272 mr_asprintf(mountpoint, "%s/archives", mtpt); 294 273 if (last_bigfile_num == -1) { 295 274 bigfile_num = 0; … … 302 281 slice_num = last_slice_num + 1; 303 282 } 304 while (does_file_exist 305 (slice_fname 306 (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 283 while (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 307 284 || 308 does_file_exist(slice_fname 309 (bigfile_num, slice_num, mountpoint, ""))) { 285 does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 310 286 // handle slices until end of CD 311 287 if (slice_num == 0) { 312 log_msg(2, "ISO=%d bigfile=%ld --START--", 313 g_current_media_number, bigfile_num); 314 if (! 315 (fin = 316 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), 317 "r"))) { 288 log_msg(2, "ISO=%d bigfile=%ld --START--", g_current_media_number, bigfile_num); 289 if (! (fin = fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), "r"))) { 318 290 log_msg(2, "Cannot open bigfile's info file"); 319 291 } else { 320 if (fread 321 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 322 fin) < sizeof(biggiestruct)) { 292 if (fread ((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) { 323 293 log_msg(2, "Unable to get biggiestruct"); 324 294 } 325 295 paranoid_fclose(fin); 326 296 } 327 sprintf(tmp, "%s/%s", bkpinfo->restore_path, 328 biggiestruct.filename); 329 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 330 if (!(forig = fopen(tmp, "r"))) { 331 log_msg(2, "Failed to open bigfile. Darn."); 332 log_to_screen("%s/%s not found on live filesystem", 333 bkpinfo->restore_path, 334 biggiestruct.filename); 335 mr_asprintf(mds, "echo \"%s/%s not found\" >> %s/biggies.changed", 336 bkpinfo->restore_path, 337 biggiestruct.filename, 338 bkpinfo->tmpdir); 339 paranoid_system(mds); 340 paranoid_free(mds); 341 342 bigfile_num++; 343 slice_num = 0; 344 retval++; 297 if (bkpinfo->restore_path) { 298 mr_asprintf(tmp, "%s/%s", bkpinfo->restore_path, biggiestruct.filename); 299 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 300 forig = fopen(tmp, "r"); 301 mr_free(tmp); 302 303 if (!forig) { 304 log_msg(2, "Failed to open bigfile. Darn."); 305 log_to_screen("%s/%s not found on live filesystem", bkpinfo->restore_path, biggiestruct.filename); 306 mr_asprintf(tmp, "echo \"%s/%s not found\" >> %s/biggies.changed", bkpinfo->restore_path, biggiestruct.filename, bkpinfo->tmpdir); 307 paranoid_system(tmp); 308 mr_free(tmp); 309 310 bigfile_num++; 311 slice_num = 0; 312 retval++; 313 } else { 314 slice_num++; 315 } 345 316 } else { 346 slice_num++;317 log_it("Unable to open bigfile as restore_path is NULL"); 347 318 } 348 319 } else if (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, "")) && … … 354 325 slice_num = 0; 355 326 } else { 356 log_msg(2, "ISO=%d bigfile=%ld slice=%ld", 357 g_current_media_number, bigfile_num, slice_num); 358 if (!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 359 sprintf(command, "%s -dc %s 2>> %s", 360 sz_exe, 361 slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), 362 MONDO_LOGFILE); 327 log_msg(2, "ISO=%d bigfile=%ld slice=%ld", g_current_media_number, bigfile_num, slice_num); 328 if ((!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) && (sz_exe != NULL)) { 329 mr_asprintf(command, "%s -dc %s 2>> %s", sz_exe, slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), MONDO_LOGFILE); 363 330 } else { 364 sprintf(command, "cat %s 2>> %s", 365 slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE); 331 mr_asprintf(command, "cat %s 2>> %s", slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE); 366 332 } 367 if ((pin = popen(command, "r"))) { 333 pin = popen(command, "r"); 334 mr_free(command); 335 if (pin) { 368 336 res = 0; 369 337 while (!feof(pin)) { … … 404 372 } 405 373 } 374 mr_free(mountpoint); 375 mr_free(sz_exe); 376 406 377 last_bigfile_num = bigfile_num; 407 378 last_slice_num = slice_num - 1; … … 416 387 paranoid_free(bufblkB); 417 388 } 418 paranoid_free(tmp);419 paranoid_free(command);420 paranoid_free(sz_exe);421 paranoid_free(mountpoint);422 389 return (0); 423 390 } … … 442 409 { 443 410 /*@ buffers ********************************************************* */ 444 char *command ;445 char *outlog ;446 char *tmp ;447 char *p ;411 char *command = NULL; 412 char *outlog = NULL; 413 char *tmp = NULL; 414 char *p = NULL; 448 415 449 416 /*@ pointers ******************************************************* */ … … 462 429 463 430 log_it("Verifying fileset '%s'", tarball_fname); 464 /* chdir("/"); */ 465 sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir); 466 /* if programmer forgot to say which compression thingy to use then find out */ 467 if (strstr(tarball_fname, ".lzo") 468 && strcmp(bkpinfo->zip_suffix, "lzo")) { 431 mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir); 432 /* if programmer forgot to say which compression thingy to use then find out */ 433 if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) { 469 434 log_msg(2, "OK, I'm going to start using lzop."); 470 435 strcpy(bkpinfo->zip_exe, "lzop"); … … 472 437 bkpinfo->use_lzo = TRUE; 473 438 bkpinfo->use_gzip = FALSE; 474 }475 if (strstr(tarball_fname, ".gz")476 439 bkpinfo->use_lzma = FALSE; 440 } 441 if (strstr(tarball_fname, ".gz") && strcmp(bkpinfo->zip_suffix, "gz")) { 477 442 log_msg(2, "OK, I'm going to start using gzip."); 478 443 strcpy(bkpinfo->zip_exe, "gzip"); … … 480 445 bkpinfo->use_lzo = FALSE; 481 446 bkpinfo->use_gzip = TRUE; 482 }483 if (strstr(tarball_fname, ".bz2")484 447 bkpinfo->use_lzma = FALSE; 448 } 449 if (strstr(tarball_fname, ".bz2") && strcmp(bkpinfo->zip_suffix, "bz2")) { 485 450 log_msg(2, "OK, I'm going to start using bzip2."); 486 451 strcpy(bkpinfo->zip_exe, "bzip2"); … … 488 453 bkpinfo->use_lzo = FALSE; 489 454 bkpinfo->use_gzip = FALSE; 455 bkpinfo->use_lzma = FALSE; 456 } 457 if (strstr(tarball_fname, ".lzma") && strcmp(bkpinfo->zip_suffix, "lzma")) { 458 log_msg(2, "OK, I'm going to start using lzma."); 459 strcpy(bkpinfo->zip_exe, "lzma"); 460 strcpy(bkpinfo->zip_suffix, "lzma"); 461 bkpinfo->use_lzo = FALSE; 462 bkpinfo->use_gzip = FALSE; 463 bkpinfo->use_lzma = TRUE; 464 } 465 if (bkpinfo->zip_exe == NULL) { 466 strcpy(bkpinfo->zip_exe, "none"); 467 } 468 if (bkpinfo->zip_suffix == NULL) { 469 strcpy(bkpinfo->zip_suffix, ""); 490 470 } 491 471 unlink(outlog); … … 493 473 bkpinfo->use_star = TRUE; 494 474 if (strstr(tarball_fname, ".bz2")) 495 sprintf(command, 496 "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", 497 tarball_fname, 498 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, 499 outlog); 475 mr_asprintf(command, "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", tarball_fname, (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, outlog); 500 476 } else { 501 477 bkpinfo->use_star = FALSE; 502 sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", 503 bkpinfo->zip_exe, tarball_fname, outlog, outlog); 478 /* Here we suppose that there is always a compression program called */ 479 if (bkpinfo->zip_exe) { 480 mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog); 481 } else { 482 mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog); 483 } 504 484 } 505 485 log_msg(6, "command=%s", command); 506 486 paranoid_system(command); 487 mr_free(command); 488 507 489 if (length_of_file(outlog) < 10) { 508 sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);490 mr_asprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE); 509 491 } else { 510 sprintf(command, "cut -d: -f%d %s | sort -u", 511 (bkpinfo->use_star) ? 1 : 2, outlog); 492 mr_asprintf(command, "cut -d: -f%d %s | sort -u", (bkpinfo->use_star) ? 1 : 2, outlog); 512 493 pin = popen(command, "r"); 513 494 if (pin) { 514 for (p = fgets(tmp, MAX_STR_LEN, pin); !feof(pin) && (p != NULL); 515 p = fgets(tmp, MAX_STR_LEN, pin)) { 495 for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) { 516 496 if (bkpinfo->use_star) { 517 497 if (!strstr(tmp, "diffopts=")) { 518 while (strlen(tmp) > 0 519 && tmp[strlen(tmp) - 1] < 32) { 498 while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) { 520 499 tmp[strlen(tmp) - 1] = '\0'; 521 500 } 522 501 if (strchr(tmp, '/')) { 523 502 if (!diffs) { 524 log_msg(0, "'%s' - differences found", 525 tarball_fname); 503 log_msg(0, "'%s' - differences found", tarball_fname); 526 504 } 527 log_msg(0, "star: /%s", 528 strip_afio_output_line(tmp)); 505 log_msg(0, "star: /%s", strip_afio_output_line(tmp)); 529 506 diffs++; 530 507 } … … 532 509 } else { 533 510 if (!diffs) { 534 log_msg(0, "'%s' - differences found", 535 tarball_fname); 511 log_msg(0, "'%s' - differences found", tarball_fname); 536 512 } 537 513 log_msg(0, "afio: /%s", strip_afio_output_line(tmp)); 538 514 diffs++; 539 515 } 516 mr_free(tmp); 540 517 } 518 mr_free(tmp); 541 519 paranoid_pclose(pin); 542 520 } else { … … 544 522 } 545 523 } 546 /* chdir(old_pwd); */ 547 // sprintf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE); 548 // paranoid_system (tmp); 549 // unlink ("/tmp/mondo-verify.err"); 550 paranoid_free(command); 551 paranoid_free(outlog); 552 paranoid_free(tmp); 524 mr_free(command); 525 mr_free(outlog); 553 526 return (0); 554 527 } … … 604 577 605 578 /*@ buffers ********************************************************** */ 606 char *tmp ;607 char *tarball_fname ;579 char *tmp = NULL; 580 char *tarball_fname = NULL; 608 581 609 582 /*@ pointers ********************************************************* */ 610 583 char *p; 611 584 612 malloc_string(tmp);613 malloc_string(tarball_fname);614 585 assert(bkpinfo != NULL); 615 586 assert_string_is_neither_NULL_nor_zerolength(orig_fname); … … 621 592 p++; 622 593 } 623 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);594 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 624 595 paranoid_system(tmp); 625 sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 626 sprintf(tmp, "Temporarily copying file from tape to '%s'", 627 tarball_fname); 628 /* log_it(tmp); */ 596 mr_free(tmp); 597 598 mr_asprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 629 599 read_file_from_stream_to_file(tarball_fname, size); 630 600 res = verify_a_tarball(tarball_fname); 631 601 if (res) { 632 sprintf(tmp, 633 "Afioball '%s' no longer matches your live filesystem", p); 634 log_msg(0, tmp); 602 log_msg(0, "Afioball '%s' no longer matches your live filesystem", p); 635 603 retval++; 636 604 } 637 605 unlink(tarball_fname); 638 paranoid_free(tmp); 639 paranoid_free(tarball_fname); 606 mr_free(tarball_fname); 640 607 return (retval); 641 608 } … … 660 627 661 628 /*@ char ************************************************************ */ 662 char *test_file ;663 char *biggie_cksum ;664 char *orig_cksum ;665 char *tmp ;666 char *slice_fnam ;629 char *test_file = NULL; 630 char *biggie_cksum = NULL; 631 char *orig_cksum = NULL; 632 char *tmp = NULL; 633 char *slice_fnam = NULL; 667 634 668 635 /*@ pointers ******************************************************** */ … … 672 639 long long slice_siz; 673 640 674 malloc_string(test_file);675 malloc_string(biggie_cksum);676 malloc_string(orig_cksum);677 malloc_string(tmp);678 641 malloc_string(slice_fnam); 679 642 assert(bkpinfo != NULL); … … 686 649 p++; 687 650 } 688 sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 689 sprintf(tmp, 690 "Temporarily copying biggiefile %s's slices from tape to '%s'", 691 p, test_file); 692 /* log_it(tmp); */ 651 mr_asprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 693 652 for (res = 694 653 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 695 654 ctrl_chr != BLK_STOP_A_BIGGIE; 696 655 res = 697 read_header_block_from_stream(&slice_siz, slice_fnam, 698 &ctrl_chr)) { 656 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) { 699 657 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 700 658 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); … … 703 661 unlink(test_file); 704 662 res = 705 read_header_block_from_stream(&slice_siz, slice_fnam, 706 &ctrl_chr); 663 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 707 664 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 708 665 log_msg(2, "test_file = %s", test_file); … … 712 669 retval += res; 713 670 } 714 strcpy(biggie_cksum, slice_fnam);671 mr_asprintf(biggie_cksum, "%s", slice_fnam); 715 672 if (biggie_cksum[0] != '\0') { 716 strcpy(orig_cksum, calc_checksum_of_file(biggie_fname));673 mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname)); 717 674 if (strcmp(biggie_cksum, orig_cksum)) { 718 sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, 719 orig_cksum); 720 log_msg(2, tmp); 721 sprintf(tmp, "%s has changed on live filesystem", 722 biggie_fname); 723 log_to_screen(tmp); 724 sprintf(tmp, "echo \"%s\" >> %s/biggies.changed", 725 biggie_fname, bkpinfo->tmpdir); 675 log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum); 676 log_to_screen("%s has changed on live filesystem", biggie_fname); 677 678 mr_asprintf(tmp, "echo \"%s\" >> %s/biggies.changed", biggie_fname, bkpinfo->tmpdir); 726 679 paranoid_system(tmp); 727 }728 }729 paranoid_free(test_file);730 paranoid_free(biggie_cksum);731 paranoid_free(orig_cksum);732 paranoid_free(tmp);680 mr_free(tmp); 681 } 682 mr_free(orig_cksum); 683 } 684 mr_free(biggie_cksum); 685 mr_free(test_file); 733 686 paranoid_free(slice_fnam); 734 687 return (retval); … … 739 692 * Verify all afioballs from the opened tape/CD stream. 740 693 * @param bkpinfo The backup information structure. Fields used: 741 * - @c bkpinfo->restore_path742 694 * - @c bkpinfo->tmpdir 743 695 * … … 754 706 755 707 /*@ buffers ***************************************************** */ 756 char *tmp ;708 char *tmp = NULL; 757 709 char *fname; 758 710 char *curr_xattr_list_fname; … … 763 715 764 716 assert(bkpinfo != NULL); 765 malloc_string(tmp);766 717 malloc_string(fname); 767 718 malloc_string(curr_xattr_list_fname); … … 816 767 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 817 768 } 818 sprintf(tmp, "Verifying fileset #%ld", current_afioball_number); 819 /*log_it(tmp); */ 769 mr_asprintf(tmp, "Verifying fileset #%ld", current_afioball_number); 820 770 update_progress_form(tmp); 771 mr_free(tmp); 772 821 773 res = verify_an_afioball_from_stream(fname, size); 822 774 if (res) { 823 sprintf(tmp, "Afioball %ld differs from live filesystem", 824 current_afioball_number); 825 log_to_screen(tmp); 775 log_to_screen("Afioball %ld differs from live filesystem", current_afioball_number); 826 776 } 827 777 retval += res; … … 835 785 log_msg(1, "All done with afioballs"); 836 786 close_progress_form(); 837 paranoid_free(tmp);838 787 paranoid_free(fname); 839 788 paranoid_free(curr_xattr_list_fname); … … 863 812 864 813 /*@ buffers ******************************************************** */ 865 char * tmp;866 char * orig_fname, *logical_fname;867 char *comment ;868 char *curr_xattr_list_fname ;869 char *curr_acl_list_fname ;814 char *orig_fname; 815 char *logical_fname = NULL; 816 char *comment = NULL; 817 char *curr_xattr_list_fname = NULL; 818 char *curr_acl_list_fname = NULL; 870 819 /*@ pointers ******************************************************* */ 871 820 char *p; … … 875 824 876 825 assert(bkpinfo != NULL); 877 malloc_string(tmp);878 826 malloc_string(orig_fname); 879 malloc_string(logical_fname);880 malloc_string(comment);881 827 malloc_string(curr_xattr_list_fname); 882 828 malloc_string(curr_acl_list_fname); … … 890 836 bkpinfo->tmpdir); 891 837 } 892 sprintf(comment, "Verifying all bigfiles.");838 mr_asprintf(comment, "Verifying all bigfiles."); 893 839 log_to_screen(comment); 894 sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir);895 // noof_biggiefiles = count_lines_in_file (tmp); // pointless896 840 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 897 841 if (ctrl_chr != BLK_START_BIGGIEFILES) { … … 911 855 "Please wait. This may take some time.", "", 912 856 noof_biggiefiles); 857 mr_free(comment); 858 913 859 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 914 860 ctrl_chr != BLK_STOP_BIGGIEFILES; … … 925 871 p++; 926 872 } 927 sprintf(comment, "Verifying bigfile #%ld (%ld K)", 928 current_biggiefile_number, (long) size >> 10); 873 mr_asprintf(comment, "Verifying bigfile #%ld (%ld K)", current_biggiefile_number, (long) size >> 10); 929 874 update_progress_form(comment); 930 sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 931 res = 932 verify_a_biggiefile_from_stream(logical_fname, size); 933 retval += res; 875 mr_free(comment); 876 877 if (bkpinfo->restore_path) { 878 mr_asprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 879 res = verify_a_biggiefile_from_stream(logical_fname, size); 880 mr_free(logical_fname); 881 retval += res; 882 } else { 883 log_it("Unable to verify bigfile as restore_path is NULL"); 884 } 885 934 886 current_biggiefile_number++; 935 887 g_current_progress++; … … 937 889 close_progress_form(); 938 890 paranoid_free(orig_fname); 939 paranoid_free(logical_fname);940 891 paranoid_free(curr_xattr_list_fname); 941 892 paranoid_free(curr_acl_list_fname); 942 paranoid_free(comment);943 paranoid_free(tmp);944 893 return (retval); 945 894 } … … 951 900 * Verify the USB device 952 901 * @param bkpinfo The backup information structure. Fields used: 953 * - @c bkpinfo->isodir954 902 * - @c bkpinfo->media_device 955 903 * - @c bkpinfo->tmpdir … … 981 929 assert(bkpinfo != NULL); 982 930 931 if (bkpinfo->media_device == NULL) { 932 return(1); 933 } 934 983 935 mr_asprintf(fname, "%s1", bkpinfo->media_device); 984 936 if (is_this_device_mounted(fname)) { … … 1032 984 #endif 1033 985 { 1034 mr_asprintf(tmp, "%s failed; unable to unmount USB device\n", tmp1); 1035 log_to_screen(tmp); 1036 paranoid_free(tmp); 986 log_to_screen("%s failed; unable to unmount USB device\n", tmp1); 1037 987 retval++; 1038 988 } else { 1039 989 log_msg(2, "OK, I've unmounted the USB device\n"); 1040 990 } 1041 paranoid_free(tmp1);1042 paranoid_free(mountpoint);991 mr_free(tmp1); 992 mr_free(mountpoint); 1043 993 return (retval); 1044 994 } … … 1066 1016 1067 1017 /*@ buffers ******************************************************** */ 1068 char *mountpoint ;1069 char *command ;1070 char *tmp ;1071 char *fname ;1018 char *mountpoint = NULL; 1019 char *command = NULL; 1020 char *tmp = NULL; 1021 char *fname = NULL; 1072 1022 #ifdef __FreeBSD__ 1073 1023 char mdd[32]; … … 1079 1029 #endif 1080 1030 1081 command = malloc(2000);1082 malloc_string(mountpoint);1083 malloc_string(tmp);1084 malloc_string(fname);1085 1086 1031 assert(bkpinfo != NULL); 1087 1032 1088 sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir); 1089 sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, 1090 bkpinfo->prefix, g_current_media_number); 1033 if (bkpinfo->media_device == NULL) { 1034 return(1); 1035 } 1036 1037 mr_asprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir); 1038 if (((bkpinfo->isodir == NULL) && (bkpinfo->netfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) { 1039 fatal_error("No iso filename preparation possible"); 1040 } 1041 if (bkpinfo->netfs_remote_dir) { 1042 // NETFS 1043 mr_asprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number); 1044 } else { 1045 // ISO 1046 mr_asprintf(fname, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number); 1047 } 1091 1048 1092 1049 mkdir(mountpoint, 1777); 1093 1050 sync(); 1094 1051 if (!does_file_exist(fname)) { 1095 sprintf(tmp, 1096 "%s not found; assuming you backed up to CD; verifying CD...", 1097 fname); 1098 log_msg(2, tmp); 1052 log_msg(2, "%s not found; assuming you backed up to CD; verifying CD...", fname); 1099 1053 if (bkpinfo->manual_cd_tray) { 1100 1054 popup_and_OK("Please push CD tray closed."); … … 1102 1056 if (find_and_mount_actual_cd(mountpoint)) { 1103 1057 log_to_screen("failed to mount actual CD"); 1058 mr_free(mountpoint); 1059 mr_free(fname); 1104 1060 return (1); 1105 1061 } 1106 1062 } else { 1107 sprintf(tmp, "%s found; verifying ISO...", fname);1063 log_msg(2, "%s found; verifying ISO...", fname); 1108 1064 #ifdef __FreeBSD__ 1109 1065 ret = 0; … … 1111 1067 mddevice = make_vn(fname); 1112 1068 if (ret) { 1113 sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n",1114 fname);1115 log_to_screen(tmp);1069 log_to_screen("make_vn of %s failed; unable to verify ISO\n", fname); 1070 mr_free(mountpoint); 1071 mr_free(fname); 1116 1072 return (1); 1117 1073 } 1118 sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);1074 mr_asprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint); 1119 1075 #else 1120 sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname, 1121 mountpoint); 1076 mr_asprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname, mountpoint); 1122 1077 #endif 1123 1078 if (run_program_and_log_output(command, FALSE)) { 1124 sprintf(tmp, "%s failed; unable to mount ISO image\n", 1125 command); 1126 log_to_screen(tmp); 1079 log_to_screen("%s failed; unable to mount ISO image\n", command); 1080 mr_free(mountpoint); 1081 mr_free(command); 1082 mr_free(fname); 1127 1083 return (1); 1128 1084 } 1085 mr_free(command); 1129 1086 } 1130 1087 log_msg(2, "OK, I've mounted the ISO/CD\n"); 1131 sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);1088 mr_asprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint); 1132 1089 if (!does_file_exist(tmp)) { 1133 1090 log_msg … … 1141 1098 */ 1142 1099 } 1100 mr_free(tmp); 1101 1143 1102 verify_afioballs_on_CD(mountpoint); 1144 1103 log_it("before verify_all_slices"); … … 1147 1106 #ifdef __FreeBSD__ 1148 1107 ret = 0; 1149 sprintf(command, "umount -d %s", mountpoint);1108 mr_asprintf(command, "umount -d %s", mountpoint); 1150 1109 ret += system(command); 1151 1110 ret += kick_vn(mddevice); 1152 if (ret) 1111 if (ret) { 1153 1112 #else 1154 sprintf(command, "umount -d %s", mountpoint);1155 if (system(command)) 1113 mr_asprintf(command, "umount -d %s", mountpoint); 1114 if (system(command)) { 1156 1115 #endif 1157 { 1158 sprintf(tmp, "%s failed; unable to unmount ISO image\n", command); 1159 log_to_screen(tmp); 1116 log_to_screen("%s failed; unable to unmount ISO image\n", command); 1117 1160 1118 retval++; 1161 1119 } else { 1162 1120 log_msg(2, "OK, I've unmounted the ISO file\n"); 1163 1121 } 1122 mr_free(mountpoint); 1123 mr_free(command); 1124 1164 1125 if (!does_file_exist(fname)) { 1165 sprintf(command, "umount -d %s", bkpinfo->media_device);1126 mr_asprintf(command, "umount -d %s", bkpinfo->media_device); 1166 1127 run_program_and_log_output(command, 2); 1167 if (!bkpinfo->please_dont_eject 1168 && eject_device(bkpinfo->media_device)) { 1128 mr_free(command); 1129 1130 if (!bkpinfo->please_dont_eject && eject_device(bkpinfo->media_device)) { 1169 1131 log_msg(2, "Failed to eject CD-ROM drive"); 1170 1132 } 1171 1133 } 1172 paranoid_free(command); 1173 paranoid_free(mountpoint); 1174 paranoid_free(tmp); 1175 paranoid_free(fname); 1134 mr_free(fname); 1176 1135 return (retval); 1177 1136 } … … 1191 1150 1192 1151 /*@ buffers ******************************************************** */ 1193 char tmp[MAX_STR_LEN];1194 char changed_files_fname[MAX_STR_LEN];1152 char *tmp = NULL; 1153 char *changed_files_fname = NULL; 1195 1154 1196 1155 /*@ long *********************************************************** */ … … 1206 1165 retval += verify_biggiefiles_from_stream(); 1207 1166 /* find the final blocks */ 1208 paranoid_system("sync");1167 sync(); 1209 1168 sleep(2); 1210 1169 closein_tape(); 1211 1170 /* close tape; exit */ 1212 1171 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape() 1213 sprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);1172 mr_asprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir); 1214 1173 paranoid_system(tmp); 1215 sprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir); 1216 sprintf(tmp, 1217 "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$' > %s", 1218 (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE, 1219 changed_files_fname); 1174 mr_free(tmp); 1175 1176 mr_asprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir); 1177 mr_asprintf(tmp, "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$' > %s", (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE, changed_files_fname); 1220 1178 log_msg(2, "Running command to derive list of changed files"); 1221 1179 log_msg(2, tmp); 1222 1180 if (system(tmp)) { 1223 if (does_file_exist(changed_files_fname) 1224 && length_of_file(changed_files_fname) > 2) { 1225 log_to_screen 1226 ("Warning - unable to check logfile to derive list of changed files"); 1181 if (does_file_exist(changed_files_fname) && length_of_file(changed_files_fname) > 2) { 1182 log_to_screen("Warning - unable to check logfile to derive list of changed files"); 1227 1183 } else { 1228 log_to_screen 1229 ("No differences found. Therefore, no 'changed.files' text file."); 1230 } 1231 } 1232 sprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname); 1184 log_to_screen("No differences found. Therefore, no 'changed.files' text file."); 1185 } 1186 } 1187 mr_free(tmp); 1188 1189 mr_asprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname); 1233 1190 paranoid_system(tmp); 1191 mr_free(tmp); 1234 1192 1235 1193 diffs = count_lines_in_file(changed_files_fname); 1236 1194 if (diffs > 0) { 1237 sprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname, 1238 MONDO_CACHE); 1195 mr_asprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname, MONDO_CACHE); 1239 1196 run_program_and_log_output(tmp, FALSE); 1240 sprintf(tmp, 1241 "%ld files differed from live filesystem; type less %s or less %s/changed.files to see", 1242 diffs, changed_files_fname, MONDO_CACHE); 1243 log_msg(0, tmp); 1197 mr_free(tmp); 1198 1199 log_msg(0, "%ld files differed from live filesystem; type less %s or less %s/changed.files to see", diffs, changed_files_fname, MONDO_CACHE); 1244 1200 log_to_screen("See "MONDO_CACHE"/changed.files for a list of nonmatching files."); 1245 1201 log_to_screen("The files probably changed on filesystem, not on backup media."); 1246 // retval++;1247 }1202 } 1203 mr_free(changed_files_fname); 1248 1204 return (retval); 1249 1205 } -
branches/3.0/mondo/src/common/mondostructures.h
r3150 r3188 412 412 bool use_gzip; 413 413 414 415 * A filename containing a list of extensions, one per line, to not416 * compress. If this is set to "", afio will still exclude a set of well-known417 * compressed files from compression, but biggiefiles that are compressed418 * will be recompressed again.419 */ 420 char do_not_compress_these[MAX_STR_LEN / 2];414 /** 415 * If TRUE, then use @c lzma to compress data. 416 * This is used mainly in estimates. The backup/restore may or may 417 * not work if you do not set this. You should also set @p zip_exe 418 * and @p zip_suffix. 419 */ 420 bool use_lzma; 421 421 422 422 /** … … 492 492 */ 493 493 t_bkptype backup_media_type; 494 // bool blank_dvd_first;495 494 496 495 /** … … 506 505 * If you do nothing, "/" will be used. 507 506 */ 508 char include_paths[MAX_STR_LEN*4];507 char *include_paths; 509 508 510 509 /** … … 560 559 * address form. (Domain names will be resolved in post_param_configuration().) 561 560 */ 562 char netfs_mount[MAX_STR_LEN];561 char *netfs_mount; 563 562 564 563 /** … … 566 565 * the backups in. 567 566 */ 568 char netfs_remote_dir[MAX_STR_LEN];567 char *netfs_remote_dir; 569 568 570 569 /** … … 674 673 */ 675 674 bool expanded; 676 };677 678 679 680 /**681 * A structure to wrap a FIFO device for writing to a tape/CD stream.682 * @bug Is this structure used (w/the move to a standalone @c buffer and all)?683 */684 struct s_wrapfifo {685 /**686 * The device we write to or read from (a FIFO).687 */688 char public_device[MAX_STR_LEN / 4];689 690 /**691 * The actual device that data from the FIFO should be buffered and written to.692 */693 char private_device[MAX_STR_LEN / 4];694 695 /**696 * A buffer for holding data read from the FIFO.697 */698 char internal_buffer_IN_fifo[MAX_STR_LEN / 4];699 700 /**701 * A buffer for holding data to be written to the FIFO.702 */703 char internal_buffer_OUT_fifo[MAX_STR_LEN / 4];704 705 /**706 * If TRUE, then we're writing directly to the tape streamer; if FALSE, we're writing to the FIFO.707 */708 bool writing_to_private_device;709 675 }; 710 676 -
branches/3.0/mondo/src/common/newt-specific.c
r3185 r3188 97 97 extern int g_current_media_number; 98 98 pid_t g_main_pid = 0; ///< The PID of the main Mondo process. 99 long g_maximum_progress = 999 ; ///< The maximum amount of progress (100%) for the currently opened progress form.99 long g_maximum_progress = 999L; ///< The maximum amount of progress (100%) for the currently opened progress form. 100 100 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form. 101 long g_start_time = 0 ; ///< The time (in seconds since the epoch) that the progress form was opened.101 long g_start_time = 0L; ///< The time (in seconds since the epoch) that the progress form was opened. 102 102 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 103 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo.104 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo.105 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo.106 103 char *g_selfmounted_isodir; ///< Holds the NETFS mountpoint if mounted via mondoarchive. 107 104 108 105 /* @} - end of globalGroup */ 109 110 //int g_fd_in=-1, g_fd_out=-1;111 106 112 107 void popup_and_OK(char *); … … 125 120 126 121 /*@ buffers ********************************************************** */ 127 int i ;128 char * p;122 int i = 0; 123 char *tmp = NULL; 129 124 130 125 assert_string_is_neither_NULL_nor_zerolength(prompt); … … 136 131 } 137 132 if (g_text_mode) { 138 139 char *tmp;140 tmp = malloc(MAX_NEWT_COMMENT_LEN);141 142 133 while (1) { 143 paranoid_system("sync"); 144 printf 145 ("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", 146 prompt); 147 p= fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 148 if (!p) { 149 //FIXME 150 } 134 sync(); 135 printf("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", prompt); 136 mr_getline(tmp, stdin); 151 137 if (tmp[strlen(tmp) - 1] == '\n') 152 138 tmp[strlen(tmp) - 1] = '\0'; … … 157 143 } 158 144 if (strstr("yesYES", tmp)) { 159 paranoid_free(tmp);145 mr_free(tmp); 160 146 return (TRUE); 161 147 } else if (strstr("NOno", tmp)) { 162 paranoid_free(tmp);148 mr_free(tmp); 163 149 return (FALSE); 164 150 } else { 165 paranoid_system("sync"); 166 printf 167 ("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 151 sync(); 152 printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 168 153 } 169 154 } … … 183 168 184 169 /*@ buffer *********************************************************** */ 185 char *tmp; 186 char *p; 170 char *tmp = NULL; 187 171 int i; 188 172 … … 193 177 finish(1); 194 178 } 195 tmp = malloc(MAX_NEWT_COMMENT_LEN); 179 196 180 if (g_text_mode) { 197 paranoid_system("sync"); 198 printf 199 ("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", 200 prompt); 201 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 202 if (!p) { 203 // FIXME 204 } 181 sync(); 182 printf("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", prompt); 183 mr_getline(tmp, stdin); 205 184 if (tmp[strlen(tmp) - 1] == '\n') 206 185 tmp[strlen(tmp) - 1] = '\0'; … … 211 190 } 212 191 if (strstr("okOKOkYESyes", tmp)) { 213 paranoid_free(tmp);192 mr_free(tmp); 214 193 return (TRUE); 215 194 } else { 216 paranoid_free(tmp);195 mr_free(tmp); 217 196 return (FALSE); 218 197 } 219 198 } else { 220 paranoid_free(tmp);221 199 return (popup_with_buttons(prompt, " Okay ", "Cancel")); 222 200 } … … 264 242 } 265 243 if (g_current_progress == -999) { 266 log_msg(2, 267 "Trying to close the progress form when it ain't open!"); 244 log_msg(2, "Trying to close the progress form when it ain't open!"); 268 245 return; 269 246 } … … 301 278 mr_asprintf(tmp1,"kill `%s`", tmp); 302 279 run_program_and_log_output(tmp1, TRUE); 303 paranoid_free(tmp1);304 } 305 paranoid_free(tmp);280 mr_free(tmp1); 281 } 282 mr_free(tmp); 306 283 } 307 284 … … 312 289 * @note This function never returns. 313 290 */ 314 void 315 fatal_error(char *error_string) { 291 void fatal_error(char *error_string) { 292 316 293 /*@ buffers ***************************************************** */ 317 char fatalstr[MAX_NEWT_COMMENT_LEN] = 318 "-------FATAL ERROR---------"; 319 char *tmp; 320 char *command; 294 char *command = NULL; 321 295 static bool already_exiting = FALSE; 322 296 323 297 /*@ end vars **************************************************** */ 324 298 325 malloc_string(command);326 tmp = malloc(MAX_NEWT_COMMENT_LEN);327 299 set_signals(FALSE); // link to external func 328 300 g_exiting = TRUE; … … 332 304 log_msg(2, "mastermind %d is exiting", (int) getpid()); 333 305 kill(g_main_pid, SIGTERM); 334 paranoid_free(tmp);335 306 finish(1); 336 307 } … … 340 311 log_msg(2, "non-m/m %d is exiting", (int) getpid()); 341 312 kill(g_main_pid, SIGTERM); 342 paranoid_free(tmp);343 313 finish(1); 344 314 } … … 348 318 if (already_exiting) { 349 319 log_msg(3, "...I'm already exiting. Give me time, Julian!"); 350 paranoid_free(tmp);351 320 finish(1); 352 321 } … … 359 328 kill_anything_like_this("ntfsclone"); 360 329 sync(); 361 /*362 sprintf(tmp, "umount %s", g_tmpfs_mountpt);363 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) {364 log_msg(2, "Waiting for child processes to terminate");365 sleep(1);366 run_program_and_log_output(tmp, 5);367 }368 */369 330 370 331 if (chdir("/")) { … … 372 333 } 373 334 if (g_selfmounted_isodir) { 374 sprintf(command, "umount -d %s", g_selfmounted_isodir);335 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir); 375 336 run_program_and_log_output(command, 5); 376 sprintf(command, "rmdir %s", g_selfmounted_isodir); 337 mr_free(command); 338 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 377 339 run_program_and_log_output(command, 5); 340 mr_free(command); 378 341 } 379 342 380 343 if (!g_text_mode) { 381 log_msg(0, fatalstr);344 log_msg(0, "-------FATAL ERROR---------"); 382 345 log_msg(0, error_string); 383 // popup_and_OK (error_string);384 newtFinished();385 346 } 386 347 387 348 printf("---FATALERROR--- %s\n", error_string); 388 printf 389 ("If you require technical support, please contact the mailing list.\n"); 349 printf("If you require technical support, please contact the mailing list.\n"); 390 350 printf("See http://www.mondorescue.org for details.\n"); 391 printf 392 ("The list's members can help you, if you attach that file to your e-mail.\n"); 351 printf("The list's members can help you, if you attach that file to your e-mail.\n"); 393 352 printf("Log file: %s\n", MONDO_LOGFILE); 394 353 printf("Mondo has aborted.\n"); … … 396 355 log_msg(3, "FYI - g_main_pid is blank"); 397 356 } 398 paranoid_free(tmp);399 paranoid_free(command);400 357 finish(254); 401 358 } … … 420 377 * @note This function never returns. 421 378 */ 422 void 423 finish(int signal) { 379 void finish(int signal) { 380 424 381 char *command = NULL; 425 426 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */427 428 /* newtPopHelpLine(); */429 382 430 383 /* Before removing dir, make sure we're out of them */ … … 436 389 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir); 437 390 run_program_and_log_output(command, 1); 438 paranoid_free(command); 391 mr_free(command); 392 439 393 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 440 394 run_program_and_log_output(command, 1); 441 paranoid_free(command); 442 } 395 mr_free(command); 396 } 397 if (bkpinfo->tmpdir) { 398 log_msg(8,"tempdir is %s",bkpinfo->tmpdir); 399 if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) { 400 log_msg(8,"erasing tempdir %s",bkpinfo->tmpdir); 401 mr_asprintf(command, "rm -Rf %s", bkpinfo->tmpdir); 402 paranoid_system(command); 403 mr_free(command); 404 } 405 } 406 if (bkpinfo->scratchdir) { 407 log_msg(8,"scratchdir is %s", bkpinfo->scratchdir); 408 if (strstr(bkpinfo->scratchdir ,"mondo.scratch.") != NULL) { 409 log_msg(8,"erasing scratchdir %s",bkpinfo->scratchdir); 410 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir); 411 paranoid_system(command); 412 mr_free(command); 413 } 414 } 415 /* Free all allocated strings in bkpinfo */ 416 mr_free(bkpinfo->netfs_user); 417 mr_free(bkpinfo->netfs_proto); 418 mr_free(bkpinfo->exclude_devs); 419 mr_free(bkpinfo->exclude_paths); 420 mr_free(bkpinfo->subdir); 421 /* Then free the structure */ 422 paranoid_free(bkpinfo); 423 424 free_libmondo_global_strings(); 425 free_newt_stuff(); 443 426 if (!g_text_mode) { 444 427 if (does_file_exist("/THIS-IS-A-RAMDISK")) { … … 452 435 printf("Execution run ended; result=%d\n", signal); 453 436 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 454 if (bkpinfo->tmpdir) {455 log_msg(8,"tempdir is %s",bkpinfo->tmpdir);456 if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {457 log_msg(8,"erasing tempdir %s",bkpinfo->tmpdir);458 mr_asprintf(command, "rm -Rf %s", bkpinfo->tmpdir);459 paranoid_system(command);460 mr_free(command);461 }462 }463 if (bkpinfo->scratchdir) {464 log_msg(8,"scratchdir is %s", bkpinfo->scratchdir);465 if (strstr(bkpinfo->scratchdir ,"mondo.scratch.") != NULL) {466 log_msg(8,"erasing scratchdir %s",bkpinfo->scratchdir);467 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir);468 paranoid_system(command);469 mr_free(command);470 }471 }472 /* Free all allocated strings in bkpinfo */473 mr_free(bkpinfo->netfs_user);474 mr_free(bkpinfo->netfs_proto);475 mr_free(bkpinfo->exclude_devs);476 mr_free(bkpinfo->exclude_paths);477 mr_free(bkpinfo->subdir);478 479 /* Then free the structure */480 paranoid_free(bkpinfo);481 free_libmondo_global_strings();482 free_newt_stuff();483 437 exit(signal); 484 438 } 485 486 487 488 439 489 440 … … 494 445 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression. 495 446 */ 496 void 497 log_file_end_to_screen(char *filename, char *grep_for_me) { 447 void log_file_end_to_screen(char *filename, char *grep_for_me) { 498 448 499 449 /*@ buffers ********************************************************** */ … … 515 465 } 516 466 if (grep_for_me[0] != '\0') { 517 mr_asprintf(command, "grep '%s' %s | tail -n%d", 518 grep_for_me, filename, g_noof_log_lines); 519 } else { 520 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, 521 filename); 467 mr_asprintf(command, "grep '%s' %s | tail -n%d", grep_for_me, filename, g_noof_log_lines); 468 } else { 469 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, filename); 522 470 } 523 471 fin = popen(command, "r"); … … 557 505 * @note The message is also written to the logfile. 558 506 */ 559 void 560 log_to_screen(const char *fmt, ...) { 507 void log_to_screen(const char *fmt, ...) { 561 508 562 509 /*@ int ************************************************************** */ … … 614 561 * @param output The string to write. 615 562 */ 616 void 617 mvaddstr_and_log_it(int y, int x, char *output) { 563 void mvaddstr_and_log_it(int y, int x, char *output) { 564 618 565 assert_string_is_neither_NULL_nor_zerolength(output); 619 566 log_msg(0, output); … … 633 580 * @param ttl The title to use for the evalcall form. 634 581 */ 635 void 636 open_evalcall_form(char *ttl) { 582 void open_evalcall_form(char *ttl) { 637 583 638 584 /*@ buffers ********************************************************* */ 639 char *title; 640 char *tmp; 585 char *tmp = NULL; 641 586 642 587 /*@ initialize ****************************************************** */ 643 588 g_isoform_old_progress = -1; 644 589 g_mysterious_dot_counter = 0; 645 malloc_string(title); 590 591 assert(ttl != NULL); 646 592 malloc_string(tmp); 647 648 assert(ttl != NULL); 649 strcpy(title, ttl); 650 strcpy(g_isoform_header_str, title); 651 // center_string (title, 80); 593 strcpy(g_isoform_header_str, ttl); 652 594 if (g_text_mode) { 653 log_msg(0, t itle);654 } else { 655 strcpy(tmp, t itle);595 log_msg(0, ttl); 596 } else { 597 strcpy(tmp, ttl); 656 598 center_string(tmp, 80); 657 599 newtPushHelpLine(tmp); … … 664 606 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 665 607 g_isoform_scale = newtScale(3, 3, 34, 100); 666 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 667 newtCenteredWindow(40, 7, title); 608 newtCenteredWindow(40, 7, ttl); 668 609 g_isoform_main = newtForm(NULL, NULL, 0); 669 610 g_isoform_timeline = newtLabel(1, 5, " "); … … 677 618 update_evalcall_form(0); 678 619 paranoid_free(tmp); 679 paranoid_free(title);680 620 } 681 621 … … 691 631 * @param max_val The maximum amount of progress (number of filesets, etc.) 692 632 */ 693 void 694 open_progress_form(char *title, char *b1, char *b2, char *b3, 695 long max_val) { 633 void open_progress_form(char *title, char *b1, char *b2, char *b3, long max_val) { 696 634 697 635 /*@ buffers ********************************************************* */ 698 636 char *b1c; 699 char *blurb1 ;700 char *blurb2 ;701 char *blurb3 ;637 char *blurb1 = NULL; 638 char *blurb2 = NULL; 639 char *blurb3 = NULL; 702 640 703 641 /*@ initialize ****************************************************** */ … … 705 643 706 644 malloc_string(b1c); 707 malloc_string(blurb1);708 malloc_string(blurb2);709 malloc_string(blurb3);710 645 711 646 assert(title != NULL); … … 714 649 assert(b3 != NULL); 715 650 716 strcpy(blurb1, b1); 717 strcpy(blurb2, b2); 718 strcpy(blurb3, b3); 651 mr_asprintf(blurb1, "%s", b1); 652 mr_asprintf(blurb2, "%s", b2); 653 mr_asprintf(blurb3, "%s", b3); 654 719 655 strcpy(b1c, b1); 720 656 center_string(b1c, 80); … … 737 673 g_blurb2 = newtLabel(2, 2, blurb3); 738 674 g_blurb3 = newtLabel(2, 4, blurb2); 739 // newtOpenWindow (10, 4, 60, 11, title);740 675 newtCenteredWindow(60, 11, title); 741 g_scale = newtScale(3, 6, 54, g_maximum_progress);676 g_scale = newtScale(3, 6, 54, (long long)g_maximum_progress); 742 677 g_progressForm = newtForm(NULL, NULL, 0); 743 678 g_percentline = newtLabel(10, 9, " "); 744 679 g_timeline = newtLabel(10, 8, " "); 745 newtFormAddComponents(g_progressForm, g_percentline, 746 g_timeline, g_scale, g_blurb1, g_blurb3, 747 g_blurb2, NULL); 680 newtFormAddComponents(g_progressForm, g_percentline, g_timeline, g_scale, g_blurb1, g_blurb3, g_blurb2, NULL); 748 681 newtPushHelpLine(b1c); 749 682 newtDrawForm(g_progressForm); … … 752 685 update_progress_form_full(blurb1, blurb2, blurb3); 753 686 paranoid_free(b1c); 754 paranoid_free(blurb1);755 paranoid_free(blurb2);756 paranoid_free(blurb3);687 mr_free(blurb1); 688 mr_free(blurb2); 689 mr_free(blurb3); 757 690 } 758 691 … … 761 694 * @param prompt The message. 762 695 */ 763 void 764 popup_and_OK(char *prompt) { 696 void popup_and_OK(char *prompt) { 697 765 698 char ch; 766 699 … … 769 702 log_msg(0, prompt); 770 703 if (g_text_mode) { 771 printf 772 ("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", 773 prompt); 704 printf("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", prompt); 774 705 while (((ch = getchar()) != '\n') && (ch != EOF)); 775 706 } else { … … 786 717 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 787 718 */ 788 bool popup_and_get_string(char *title, char *b, char *output, 789 int maxsize) { 719 bool popup_and_get_string(char *title, char *b, char *output, int maxsize) { 790 720 791 721 /*@ newt ************************************************************ */ … … 801 731 802 732 /*@ buffers ********************************************************** */ 803 char *blurb ;733 char *blurb = NULL; 804 734 char *p; 805 char *original_contents; 806 807 blurb = malloc(MAX_NEWT_COMMENT_LEN); 808 original_contents = malloc(MAX_NEWT_COMMENT_LEN); 735 char *original_contents = NULL; 736 809 737 assert_string_is_neither_NULL_nor_zerolength(title); 810 738 assert(b != NULL); … … 812 740 813 741 if (g_text_mode) { 814 printf 815 ("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", 816 title, b); 742 printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", title, b); 817 743 p = fgets(output, maxsize, stdin); 818 744 if (!p) { … … 821 747 if (output[strlen(output) - 1] == '\n') 822 748 output[strlen(output) - 1] = '\0'; 823 paranoid_free(blurb);824 paranoid_free(original_contents);825 749 return (TRUE); 826 750 } 751 752 blurb = malloc(MAX_NEWT_COMMENT_LEN); 827 753 strcpy(blurb, b); 828 754 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 829 strcpy(original_contents, output);755 mr_asprintf(original_contents, "%s", output); 830 756 output[0] = '\0'; 831 type_here = 832 newtEntry(2, newtTextboxGetNumLines(text) + 2, 833 original_contents, 50, 757 type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, original_contents, 50, 834 758 #ifdef __cplusplus 835 759 0, NEWT_FLAG_RETURNEXIT … … 840 764 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, " OK "); 841 765 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel"); 842 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);843 766 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 844 767 myForm = newtForm(NULL, NULL, 0); … … 851 774 newtFormDestroy(myForm); 852 775 newtPopWindow(); 776 paranoid_free(blurb); 777 853 778 if (b_res == b_2) { 854 779 strcpy(output, original_contents); 855 paranoid_free(blurb); 856 paranoid_free(original_contents); 780 mr_free(original_contents); 857 781 return (FALSE); 858 782 } else { 859 paranoid_free(blurb); 860 paranoid_free(original_contents); 783 mr_free(original_contents); 861 784 return (TRUE); 862 785 } … … 871 794 * @return TRUE if @p button1 was pushed, FALSE otherwise. 872 795 */ 873 796 bool popup_with_buttons(char *p, char *button1, char *button2) { 874 797 875 798 /*@ buffers *********************************************************** */ 876 char *prompt; 877 char *q; 799 char *prompt = NULL; 878 800 879 801 /*@ newt ************************************************************** */ … … 887 809 assert(button1 != NULL); 888 810 assert(button2 != NULL); 889 prompt = malloc(MAX_NEWT_COMMENT_LEN);890 811 if (g_text_mode) { 891 812 if (strlen(button2) == 0) { … … 894 815 printf("%s (%s or %s) --> ", p, button1, button2); 895 816 } 896 for (prompt[0] = '\0'; 897 strcmp(prompt, button1) && (strlen(button2) == 0 898 || strcmp(prompt, button2));) { 817 mr_getline(prompt, stdin); 818 while (strcmp(prompt, button1) && (strlen(button2) == 0 || strcmp(prompt, button2))) { 899 819 printf("--> "); 900 q = fgets(prompt, MAX_NEWT_COMMENT_LEN, stdin); 901 if (!q) { 902 // FIXME 903 } 820 mr_free(prompt); 821 mr_getline(prompt, stdin); 904 822 } 905 823 if (!strcmp(prompt, button1)) { 906 paranoid_free(prompt);824 mr_free(prompt); 907 825 return (TRUE); 908 826 } else { 909 paranoid_free(prompt);827 mr_free(prompt); 910 828 return (FALSE); 911 829 } 912 830 } 913 831 832 prompt = malloc(MAX_NEWT_COMMENT_LEN); 914 833 strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1); 915 834 prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0'; 916 835 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 917 b_1 = 918 newtButton(20 - 919 ((button2[0] != 920 '\0') ? strlen(button1) + 921 2 : strlen(button1) / 2), 922 newtTextboxGetNumLines(text) + 3, button1); 836 b_1 = newtButton(20 - ((button2[0] != '\0') ? strlen(button1) + 2 : strlen(button1) / 2), newtTextboxGetNumLines(text) + 3, button1); 923 837 if (button2[0] != '\0') { 924 b_2 = 925 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 838 b_2 = newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 926 839 } else { 927 840 b_2 = NULL; 928 841 } 929 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert");930 842 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert"); 931 843 myForm = newtForm(NULL, NULL, 0); … … 953 865 * on the screen. 954 866 */ 955 void 956 refresh_log_screen() { 867 void refresh_log_screen() { 957 868 958 869 /*@ int *********************************************************** */ … … 981 892 * only allocate some memory. 982 893 */ 983 void 984 setup_newt_stuff() { 894 void setup_newt_stuff() { 985 895 986 896 /*@ int *********************************************************** */ … … 991 901 newtInit(); 992 902 newtCls(); 993 newtPushHelpLine 994 ("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 995 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 903 newtPushHelpLine("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 996 904 newtDrawRootText(18, 0, WELCOME_STRING); 997 905 newtRefresh(); … … 1000 908 } 1001 909 1002 err_log_lines = 1003 (char **) malloc(sizeof(char *) * g_noof_log_lines); 1004 if (!err_log_lines) { 1005 fatal_error("Out of memory"); 1006 } 910 err_log_lines = (char **) mr_malloc(sizeof(char *) * g_noof_log_lines); 1007 911 1008 912 for (i = 0; i < g_noof_log_lines; i++) { 1009 err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN); 1010 if (!err_log_lines[i]) { 1011 fatal_error("Out of memory"); 1012 } 913 err_log_lines[i] = (char *) mr_malloc(MAX_NEWT_COMMENT_LEN); 1013 914 } 1014 915 … … 1024 925 * @param denom The denomenator of the ratio. 1025 926 */ 1026 void 1027 update_evalcall_form_ratio(int num, int denom) { 927 void update_evalcall_form_ratio(int num, int denom) { 1028 928 1029 929 /*@ long ************************************************************ */ 1030 long current_time = 0 ;1031 long time_taken = 0 ;1032 long time_total_est = 0 ;1033 long time_remaining = 0 ;930 long current_time = 0L; 931 long time_taken = 0L; 932 long time_total_est = 0L; 933 long time_remaining = 0L; 1034 934 1035 935 /*@ buffers ********************************************************** */ 1036 char *timeline_str ;936 char *timeline_str = NULL; 1037 937 char *pcline_str = NULL; 1038 938 char *taskprogress = NULL; … … 1043 943 int j = 0; 1044 944 1045 malloc_string(timeline_str);1046 timeline_str[0] = '\0';1047 // log_it("update_eval_call_form called");1048 945 if (num * 100 < denom) { 1049 946 percentage = 1; … … 1058 955 time_remaining = time_total_est - time_taken; 1059 956 } else { 1060 time_remaining = 0 ;957 time_remaining = 0L; 1061 958 } 1062 959 if (!g_text_mode) { … … 1069 966 || percentage > g_isoform_old_progress) { 1070 967 g_isoform_old_progress = percentage; 1071 sprintf(timeline_str, 1072 "%2ld:%02ld taken %2ld:%02ld remaining", 1073 (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, 1074 (long) time_remaining % 60); 968 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60); 1075 969 if (percentage < 3) { 1076 970 mr_asprintf(pcline_str, " Working"); … … 1083 977 mr_strcat(pcline_str, " %c", special_dot_char(g_mysterious_dot_counter)); 1084 978 } else { 1085 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", 1086 percentage, 100 - percentage); 979 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); 1087 980 } 1088 981 if (g_text_mode) { … … 1095 988 } 1096 989 if (percentage >= 3) { 1097 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1098 (long) time_remaining / 60, (long) time_remaining % 60); 1099 printf("---evalcall---1--- %s\n", 1100 g_isoform_header_str); 990 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 991 printf("---evalcall---1--- %s\n", g_isoform_header_str); 1101 992 printf("---evalcall---2--- %s\n", taskprogress); 1102 993 printf("---evalcall---E---\n"); 1103 994 } 1104 paranoid_free(taskprogress);995 mr_free(taskprogress); 1105 996 } else { 1106 newtScaleSet(g_isoform_scale, 1107 (unsigned long long) percentage); 997 newtScaleSet(g_isoform_scale, (unsigned long long) percentage); 1108 998 if (g_isoform_pcline) { 1109 999 newtLabelSetText(g_isoform_pcline, pcline_str); … … 1113 1003 } 1114 1004 } 1115 paranoid_free(pcline_str); 1005 mr_free(pcline_str); 1006 mr_free(timeline_str); 1116 1007 } 1117 1008 if (!g_text_mode) { 1118 // log_it("refreshing");1119 1009 newtDrawForm(g_isoform_main); 1120 1010 newtRefresh(); 1121 1011 } 1122 paranoid_free(timeline_str);1123 1012 } 1124 1013 … … 1129 1018 * @param curr The current amount of progress (percentage) in the evalcall form. 1130 1019 */ 1131 void 1132 update_evalcall_form(int curr) { 1020 void update_evalcall_form(int curr) { 1021 1133 1022 update_evalcall_form_ratio(curr, 100); 1134 1023 } 1135 1024 1136 1025 … … 1141 1030 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same. 1142 1031 */ 1143 void 1144 update_progress_form(char *blurb3) { 1145 /* log_it("update_progress_form --- called"); */ 1032 void update_progress_form(char *blurb3) { 1033 1146 1034 if (g_current_progress == -999) { 1147 /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */1148 1035 return; 1149 1036 } 1150 1037 strcpy(g_blurb_str_2, blurb3); 1151 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1152 g_blurb_str_3); 1153 } 1038 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, g_blurb_str_3); 1039 } 1154 1040 1155 1041 … … 1160 1046 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. 1161 1047 */ 1162 void 1163 update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1048 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1049 1164 1050 /*@ long ***************************************************** */ 1165 1051 long current_time = 0L; … … 1173 1059 1174 1060 /*@ buffers *************************************************** */ 1175 char *percentline_str ;1176 char *timeline_str ;1061 char *percentline_str = NULL; 1062 char *timeline_str = NULL; 1177 1063 char *taskprogress = NULL; 1178 char *tmp; 1179 1180 // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1181 percentline_str = malloc(MAX_NEWT_COMMENT_LEN); 1182 timeline_str = malloc(MAX_NEWT_COMMENT_LEN); 1183 malloc_string(tmp); 1064 1184 1065 if (!g_text_mode) { 1185 1066 assert(blurb1 != NULL); … … 1189 1070 } 1190 1071 1191 percentline_str[0] = '\0';1192 1193 1072 current_time = get_time(); 1194 1073 time_taken = current_time - g_start_time; … … 1197 1076 } else { 1198 1077 if (g_current_progress > g_maximum_progress) { 1199 sprintf(tmp, 1200 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1201 blurb1, blurb2, blurb3, g_current_progress, 1202 g_maximum_progress); 1203 log_msg(0, tmp); 1078 log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress); 1204 1079 g_current_progress = g_maximum_progress; 1205 1080 } 1206 percentage = 1207 (int) ((g_current_progress * 100L) / g_maximum_progress); 1081 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); 1208 1082 } 1209 1083 if (percentage < 1) { … … 1214 1088 } 1215 1089 if (g_current_progress) { 1216 time_total_est = 1217 time_taken * (long) g_maximum_progress / 1218 (long) (g_current_progress); 1090 time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress; 1219 1091 time_remaining = time_total_est - time_taken; 1220 1092 } else { … … 1222 1094 } 1223 1095 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1224 sprintf(timeline_str,1225 "%2ld:%02ld taken %2ld:%02ld remaining ",1226 (long) time_taken / 60, time_taken % 60, time_remaining / 60,1227 time_remaining % 60);1228 sprintf(percentline_str, " %3d%% done %3d%% to go",1229 percentage, 100 - percentage);1230 1231 1096 if (g_text_mode) { 1232 1097 printf("---progress-form---1--- %s\n", blurb1); … … 1244 1109 log_msg(2, "percentage = %d", percentage); 1245 1110 } 1246 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1247 (long) time_remaining / 60, (long) time_remaining % 60); 1111 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 1248 1112 printf("---progress-form---4--- %s\n", taskprogress); 1249 1113 paranoid_free(taskprogress); 1250 1114 } else { 1115 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60); 1116 mr_asprintf(percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); 1117 1251 1118 center_string(blurb1, 54); 1252 1119 center_string(blurb2, 54); … … 1265 1132 newtLabelSetText(g_timeline, timeline_str); 1266 1133 } 1134 mr_free(timeline_str); 1135 1267 1136 if (g_percentline) { 1268 1137 newtLabelSetText(g_percentline, percentline_str); 1269 1138 } 1139 mr_free(percentline_str); 1140 1270 1141 newtDrawForm(g_progressForm); 1271 1142 newtRefresh(); 1272 1143 } 1273 paranoid_free(percentline_str); 1274 paranoid_free(timeline_str); 1275 paranoid_free(tmp); 1276 } 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1144 } 1289 1145 1290 1146 … … 1297 1153 * @return The backup type chosen, or @c none if the user chose "Exit to shell". 1298 1154 */ 1299 1155 t_bkptype which_backup_media_type(bool restoring) { 1300 1156 1301 1157 /*@ char ************************************************************ */ … … 1304 1160 1305 1161 /*@ newt ************************************************************ */ 1306 char *title_sz; 1307 char *minimsg_sz; 1308 static t_bkptype possible_bkptypes[] = 1309 { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1310 static char *possible_responses[] = 1311 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1312 "netfs", "iso", NULL }; 1313 char *outstr; 1314 char *p; 1162 char *title_sz = NULL; 1163 char *minimsg_sz = NULL; 1164 static t_bkptype possible_bkptypes[] = { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1165 static char *possible_responses[] = { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "netfs", "iso", NULL }; 1166 char *outstr = NULL; 1315 1167 t_bkptype backup_type; 1316 1168 int i; … … 1327 1179 newtComponent myForm; 1328 1180 1329 title_sz = malloc(MAX_NEWT_COMMENT_LEN);1330 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN);1331 outstr = malloc(MAX_NEWT_COMMENT_LEN);1332 1181 if (g_text_mode) { 1333 1182 for (backup_type = none; backup_type == none;) { … … 1338 1187 } 1339 1188 printf(")\n--> "); 1340 p = fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin); 1341 if (!p) { 1342 // FIXME 1343 } 1344 strip_spaces(outstr); 1189 mr_getline(outstr, stdin); 1190 mr_strip_spaces(outstr); 1345 1191 for (i = 0; possible_responses[i]; i++) { 1346 1192 if (!strcmp(possible_responses[i], outstr)) { … … 1348 1194 } 1349 1195 } 1350 } 1351 paranoid_free(title_sz); 1352 paranoid_free(minimsg_sz); 1353 paranoid_free(outstr); 1196 mr_free(outstr); 1197 } 1354 1198 return (backup_type); 1355 1199 } 1356 1200 newtDrawRootText(18, 0, WELCOME_STRING); 1357 1201 if (restoring) { 1358 strcpy(title_sz, 1359 "Please choose the backup media from which you want to read data."); 1360 strcpy(minimsg_sz, "Read from:"); 1361 } else { 1362 strcpy(title_sz, 1363 "Please choose the backup media to which you want to archive data."); 1364 strcpy(minimsg_sz, "Backup to:"); 1202 mr_asprintf(title_sz, "Please choose the backup media from which you want to read data."); 1203 mr_asprintf(minimsg_sz, "Read from:"); 1204 } else { 1205 mr_asprintf(title_sz, "Please choose the backup media to which you want to archive data."); 1206 mr_asprintf(minimsg_sz, "Backup to:"); 1365 1207 } 1366 1208 newtPushHelpLine(title_sz); 1367 // newtOpenWindow (23, 3, 34, 17, minimsg_sz);1368 1209 newtCenteredWindow(34, 17, minimsg_sz); 1369 1210 b1 = newtButton(1, 1, "CD-R disks "); … … 1399 1240 } 1400 1241 newtPopHelpLine(); 1401 paranoid_free(title_sz); 1402 paranoid_free(minimsg_sz); 1403 paranoid_free(outstr); 1242 mr_free(title_sz); 1243 mr_free(minimsg_sz); 1404 1244 return (output); 1405 1245 } … … 1423 1263 newtComponent b2; 1424 1264 newtComponent b3; 1425 //newtComponent b4;1265 newtComponent b4; 1426 1266 newtComponent b5; 1427 1267 newtComponent b_res; … … 1435 1275 b2 = newtButton(18, 1, "gzip"); 1436 1276 b3 = newtButton(4, 5, "lzo"); 1437 //b4 = newtButton(18, 5, "lzma");1277 b4 = newtButton(18, 5, "lzma"); 1438 1278 b5 = newtButton(4, 9, " Exit "); 1439 1279 myForm = newtForm(NULL, NULL, 0); … … 1448 1288 } else if (b_res == b3) { 1449 1289 mr_asprintf(output, "%s", "lzo"); 1450 //} else if (b_res == b4) {1451 //mr_asprintf(output, "%s", "lzma");1290 } else if (b_res == b4) { 1291 mr_asprintf(output, "%s", "lzma"); 1452 1292 } 1453 1293 newtPopHelpLine(); … … 1461 1301 * @return The compression level (0-9) chosen, or -1 for "Exit". 1462 1302 */ 1463 int 1464 which_compression_level() { 1303 int which_compression_level() { 1465 1304 1466 1305 /*@ char ************************************************************ */ … … 1479 1318 1480 1319 newtDrawRootText(18, 0, WELCOME_STRING); 1481 newtPushHelpLine 1482 (" Please specify the level of compression that you want."); 1483 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1320 newtPushHelpLine(" Please specify the level of compression that you want."); 1484 1321 newtCenteredWindow(34, 13, "How much compression?"); 1485 1322 b1 = newtButton(4, 1, "Maximum (9)"); … … 1518 1355 * @param source_file The file containing a list of filenames to load into @p filelist. 1519 1356 */ 1520 int load_filelist_into_array(struct s_filelist *filelist, 1521 char *source_file) { 1357 int load_filelist_into_array(struct s_filelist *filelist, char *source_file) { 1358 1522 1359 int i; 1523 1360 int j = 0; 1524 1361 bool done; 1525 char *tmp; 1526 char *p; 1362 char *tmp = NULL; 1527 1363 char *tmp1 = NULL; 1528 1364 FILE *fin, *fout; … … 1543 1379 if (!(fout = fopen(tmp1, "a"))) { 1544 1380 log_msg(2, "Can't write to %s", tmp1); 1381 mr_free(tmp1); 1545 1382 return(1); 1546 1383 } 1547 1384 1548 malloc_string(tmp);1549 1385 log_msg(2, "Loading %s", source_file); 1550 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1551 filelist->entries++) { 1552 god_i_hate_gotos: 1386 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; ) { 1387 mr_free(tmp); 1553 1388 if (feof(fin)) { 1554 1389 break; 1555 1390 } 1556 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, fin); 1557 if (!p) { 1558 // FIXME 1559 } 1391 mr_getline(tmp, fin); 1560 1392 i = (int) strlen(tmp); 1561 1393 if (i < 2) { 1562 goto god_i_hate_gotos;1394 continue; 1563 1395 } 1564 1396 if (tmp[i - 1] < 32) { … … 1566 1398 } 1567 1399 if (i < 2) { 1568 goto god_i_hate_gotos;1400 continue; 1569 1401 } 1570 1402 if (!does_file_exist(tmp) && !feof(fin)) { 1571 1403 j++; 1572 1404 fprintf(fout, "%s\n", tmp); 1573 1574 goto god_i_hate_gotos; 1575 } 1576 filelist->el[filelist->entries].severity = 1577 severity_of_difference(tmp, NULL); 1405 continue; 1406 } 1407 filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL); 1578 1408 strcpy(filelist->el[filelist->entries].filename, tmp); 1579 1409 if (feof(fin)) { 1580 1410 break; 1581 1411 } 1582 } 1412 filelist->entries++; 1413 } 1414 mr_free(tmp); 1583 1415 paranoid_fclose(fin); 1584 1416 paranoid_fclose(fout); … … 1586 1418 log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1); 1587 1419 } 1588 paranoid_free(tmp1);1420 mr_free(tmp1); 1589 1421 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1590 1422 log_to_screen("Arbitrary limits suck, man!"); 1591 paranoid_free(tmp);1592 1423 return (1); 1593 1424 } … … 1617 1448 } 1618 1449 } 1619 paranoid_free(tmp);1620 1450 log_it("leaving"); 1621 1451 return (0); 1622 1452 } 1623 1624 1453 1625 1454 … … 1630 1459 * @note The returned value points to static storage that will be overwritten with each call. 1631 1460 */ 1632 1461 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1633 1462 static char comment[100]; 1634 1463 char *tmp = NULL; 1635 1464 1636 log_ it("entering");1465 log_msg(8, "entering"); 1637 1466 assert(flentry != NULL); 1638 1467 if (flentry->severity == 0) { … … 1648 1477 mr_strcat(tmp, flentry->filename); 1649 1478 strncpy(comment, tmp, 99); 1650 paranoid_free(tmp);1479 mr_free(tmp); 1651 1480 1652 1481 log_it("leaving"); 1653 1482 return (comment); 1654 1483 } 1655 1656 1657 1658 1484 1659 1485 … … 1663 1489 * @param source_file The file containing a list of changed files. 1664 1490 */ 1665 void popup_changelist_from_file(char *source_file) { 1666 char *reason; 1491 void popup_changelist_from_file(char *source_file) { 1492 1493 char *reason = NULL; 1667 1494 newtComponent myForm; 1668 1495 newtComponent bClose; … … 1685 1512 1686 1513 /*@ buffers ********************************************************* */ 1687 char *tmp ;1688 char *differ_sz ;1514 char *tmp = NULL; 1515 char *differ_sz = NULL; 1689 1516 1690 1517 struct s_filelist *filelist; 1691 malloc_string(reason);1692 tmp = malloc(5000);1693 malloc_string(differ_sz);1694 1518 assert_string_is_neither_NULL_nor_zerolength(source_file); 1695 1519 if (g_text_mode) { 1696 1520 log_msg(2, "Text mode. Therefore, no popup list."); 1697 goto free_to_go;1521 return; 1698 1522 } 1699 1523 log_msg(2, "Examining file %s", source_file); … … 1702 1526 if (lng < 1) { 1703 1527 log_msg(2, "No lines in file. Therefore, no popup list."); 1704 paranoid_free(reason); 1705 goto free_to_go; 1528 return; 1706 1529 } else if (lng >= ARBITRARY_MAXIMUM) { 1707 1530 log_msg(2, "Too many files differ for me to list."); 1708 goto free_to_go;1531 return; 1709 1532 } 1710 1533 … … 1715 1538 1716 1539 if (load_filelist_into_array(filelist, source_file)) { 1717 log_msg(2, "Can't open %s; therefore, cannot popup list", 1718 source_file); 1719 paranoid_free(reason); 1540 log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); 1720 1541 return; 1721 1542 } 1722 log_msg(2, "%d files loaded into filelist array", 1723 filelist->entries); 1543 log_msg(2, "%d files loaded into filelist array", filelist->entries); 1724 1544 for (i = 0; i < filelist->entries; i++) { 1725 1545 keylist[i] = (void *) i; … … 1730 1550 keylist[i]); 1731 1551 } 1732 sprintf(differ_sz, 1733 " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", 1734 i); 1552 mr_asprintf(differ_sz, " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i); 1735 1553 newtPushHelpLine(differ_sz); 1554 mr_free(differ_sz); 1555 1736 1556 bClose = newtCompactButton(10, 15, " Close "); 1737 1557 bSelect = newtCompactButton(30, 15, " Select "); 1738 sprintf(tmp, "%-10s %-20s", "Priority", "Filename");1558 mr_asprintf(tmp, "%-10s %-20s", "Priority", "Filename"); 1739 1559 headerMsg = newtLabel(2, 1, tmp); 1560 mr_free(tmp); 1561 1740 1562 newtOpenWindow(5, 4, 70, 16, "Non-matching files"); 1741 1563 myForm = newtForm(NULL, NULL, 0); 1742 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, 1743 bSelect, NULL); 1564 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, bSelect, NULL); 1565 1744 1566 while (!finished) { 1745 1567 b_res = newtRunForm(myForm); … … 1756 1578 currline = i; 1757 1579 if (filelist->entries > 0) { 1758 severity_of_difference(filelist->el[currline].1759 filename,reason);1760 sprintf(tmp, "%s --- %s",1761 filelist->el[currline].filename, reason); 1580 malloc_string(reason); 1581 severity_of_difference(filelist->el[currline]. filename, &reason); 1582 mr_asprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason); 1583 1762 1584 popup_and_OK(tmp); 1585 mr_free(tmp); 1586 paranoid_free(reason); 1763 1587 } 1764 1588 } … … 1768 1592 newtPopWindow(); 1769 1593 newtPopHelpLine(); 1770 free_to_go:1771 paranoid_free(reason);1772 paranoid_free(tmp);1773 paranoid_free(differ_sz);1774 1594 return; 1775 1595 }
Note:
See TracChangeset
for help on using the changeset viewer.