Changeset 3191 in MondoRescue
- Timestamp:
- Sep 25, 2013, 8:55:45 AM (7 years ago)
- Location:
- branches/3.2
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi/mindi
r3184 r3191 376 376 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share/kbd # Slackware 377 377 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/lib/kbd 378 [ ! -e "$KEYDIR" ] && KEYDIR=/lib/kbd 378 379 [ ! -e "$KEYDIR" ] && KEYDIR=/usr/share 379 380 [ ! -e "$KEYDIR" ] && KEYDIR=/etc/condole … … 423 424 LogFile "INFO: Gentoo-style config detected." 424 425 keyfile=/etc/conf.d/keymaps 426 elif [ -e "/etc/X11/xorg.conf.d/00-keyboard.conf" ] ; then 427 LogFile "INFO: X11-style config detected." 428 keyfile=/etc/X11/xorg.conf.d/00-keyboard.conf 425 429 else 426 430 LogFile "Searching for rc.config ..." … … 442 446 [ ! "$locale" ] && locale=`grep '.map$' "$keyfile" | sed 's/^.* //'` # Slackware 443 447 [ ! "$locale" ] && locale=`grep -E '^KEYMAP=' "$keyfile" | grep -v '^#' | tr -d '"' |cut -d'=' -f2` # Gentoo & ArchLinux 448 [ ! "$locale" ] && locale=`grep -E 'XkbLayout' "$keyfile" | grep -v '^#' | awk '{print $3}' | tr -d '"'` # Fedora 19 444 449 LogFile "INFO: locale=$locale" 445 450 # … … 707 712 local lcMagicExt2fs="EXT2-fs: blocksize too small for device." 708 713 local lcMagicExt3fs="<3>EXT3-fs: blocksize too small for journal device." 709 local lcMagicInitfs="<6>checking if image is initramfs...| <6>Unpacking initramfs...|<6>Trying to unpack rootfs image as initramfs"714 local lcMagicInitfs="<6>checking if image is initramfs...|[<]6[>]Unpacking initramfs...|<6>Trying to unpack rootfs image as initramfs" 710 715 711 716 # local variables … … 2351 2356 if [ "$?" -eq "0" ] ; then 2352 2357 # Used by ia64 2353 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep -E '[2-9]+[.][0-9]+[.][0-9]+[^\@]*@'`2358 fkern_ver=`gzip -cd $fname | strings 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"` 2354 2359 else 2355 fkern_ver=`strings $fname 2> /dev/null | grep -E '[2-9]+[.][0-9]+[.][0-9]+[^\@]*@'`2360 fkern_ver=`strings $fname 2> /dev/null | grep "[2-9]+*[.][0-9]+*[.][0-9]+*[^\@]*@"` 2356 2361 fi 2357 2362 echo "$fkern_ver" -
branches/3.2/mondo/src/common/libmondo-archive.c
r3185 r3191 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.2/mondo/src/common/libmondo-cli.c
r3185 r3191 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.2/mondo/src/common/libmondo-devices-EXT.h
r3154 r3191 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.2/mondo/src/common/libmondo-devices.c
r3185 r3191 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.2/mondo/src/common/libmondo-fifo.c
r3185 r3191 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.2/mondo/src/common/libmondo-filelist.c
r3185 r3191 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);