- Timestamp:
- Sep 25, 2013, 9:03:25 AM (11 years ago)
- Location:
- branches/3.0/mondo/src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-archive.c
r3188 r3192 64 64 extern bool g_cd_recovery; 65 65 extern char *g_mondo_home; 66 67 /** 68 * The serial string (used to differentiate between backups) of the current backup. 69 */ 70 char *g_serial_string = NULL; 71 66 /* 67 extern char *g_tmpfs_mountpt; 68 */ 69 extern char *g_serial_string; 72 70 extern char *g_getfacl; 73 71 extern char *g_getfattr; … … 202 200 203 201 if (!does_file_exist(filelist)) { 204 log_to_screen("(archive_this_fileset) - filelist %s does not exist", filelist); 202 mr_asprintf(tmp, "(archive_this_fileset) - filelist %s does not exist", filelist); 203 log_to_screen(tmp); 204 paranoid_free(tmp); 205 205 return (1); 206 206 } … … 208 208 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 209 209 if (system(tmp)) { 210 mr_free(tmp);210 paranoid_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", filelist, fname); 215 mr_asprintf(command, "star H=exustar list=%s -c -sparse " STAR_ACL_SZ " file=%s", 216 filelist, fname); 216 217 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 mr_free(tmp);237 paranoid_free(tmp); 238 238 239 239 if (res) { … … 251 251 } 252 252 } 253 mr_free(command);253 paranoid_free(command); 254 254 255 255 retval += res; … … 307 307 308 308 if (!does_file_exist(filelist)) { 309 log_to_screen("(archive_this_fileset) - filelist %s does not 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); 310 313 return (1); 311 314 } 312 315 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 313 316 if (system(tmp)) { 314 mr_free(tmp);317 paranoid_free(tmp); 315 318 fatal_error("Unable to write tarball to scratchdir"); 316 319 } 317 mr_free(tmp);320 paranoid_free(tmp); 318 321 319 322 … … 321 324 mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 322 325 // -b %ld, TAPE_BLOCK_SIZE 323 mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, bkpinfo->compression_level); 326 mr_asprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe, 327 bkpinfo->compression_level); 324 328 if (does_file_exist(tmp)) { 325 329 mr_strcat(zipparams, " -E %s",tmp); … … 327 331 log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); 328 332 } 329 mr_free(tmp);333 paranoid_free(tmp); 330 334 } else { 331 335 mr_asprintf(zipparams, ""); 332 336 } 337 338 // make_hole_for_file(fname); 333 339 334 340 if (!does_file_exist(bkpinfo->tmpdir)) { … … 340 346 fatal_error("scratchdir not found"); 341 347 } 342 mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, fname, bkpinfo->zip_suffix); 348 mr_asprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname, 349 fname, bkpinfo->zip_suffix); 343 350 paranoid_system(command); 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); 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); 348 356 349 357 mr_asprintf(tmp, "echo hi > %s 2> /dev/null", fname); 350 358 if (system(tmp)) { 351 mr_free(tmp);359 paranoid_free(tmp); 352 360 fatal_error("Unable to write tarball to scratchdir"); 353 361 } 354 mr_free(tmp);362 paranoid_free(tmp); 355 363 356 364 for (res = 99, tries = 0; tries < 3 && res != 0; tries++) { … … 398 406 { 399 407 int retval = 0, res = 0; 400 char *tmp = NULL;408 char *tmp; 401 409 402 410 assert(bkpinfo != NULL); 403 411 set_g_cdrom_and_g_dvd_to_bkpinfo_value(); 412 malloc_string(tmp); 404 413 if (bkpinfo->backup_media_type == dvd) { 405 414 #ifdef DVDRWFORMAT … … 422 431 } 423 432 424 mr_asprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir); 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); 425 439 if (run_program_and_log_output(tmp, 2)) { 426 mr_free(tmp);427 440 fatal_error("Failed to gzip filelist.full"); 428 441 } 429 mr_free(tmp); 430 431 mr_asprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir); 442 sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir, 443 bkpinfo->tmpdir); 432 444 if (run_program_and_log_output(tmp, 2)) { 433 mr_free(tmp);434 445 fatal_error("Failed to copy to tmpdir"); 435 446 } 436 mr_free(tmp);437 447 438 448 copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists … … 454 464 } 455 465 retval += do_that_initial_phase(); // prepare 456 mr_asprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);466 sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir); 457 467 run_program_and_log_output(tmp, 1); 458 mr_free(tmp);459 460 468 retval += make_those_afios_phase(); // backup regular files 461 469 retval += make_those_slices_phase(); // backup BIG files … … 465 473 sleep(2); 466 474 } 475 paranoid_free(tmp); 467 476 return (retval); 468 477 } … … 505 514 char *use_lzo_sz = NULL; 506 515 char *use_gzip_sz = NULL; 507 char *use_lzma_sz = NULL;508 516 char *use_comp_sz = NULL; 509 517 char *use_star_sz = NULL; … … 534 542 assert(bkpinfo != NULL); 535 543 536 mvaddstr_and_log_it(g_currentY, 0, "Calling MINDI to create boot+data disks"); 544 mvaddstr_and_log_it(g_currentY, 0, 545 "Calling MINDI to create boot+data disks"); 537 546 open_evalcall_form("Calling MINDI to create boot+data disks"); 538 547 mr_asprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir); … … 541 550 mr_asprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir); 542 551 if (!does_file_exist(tmp)) { 543 mr_free(tmp);544 fatal_error("Cannot find filelist.full, so I cannot count its lines");552 fatal_error 553 ("Cannot find filelist.full, so I cannot count its lines"); 545 554 } 546 555 } … … 562 571 } 563 572 } 564 mr_free(ntapedev);573 paranoid_free(ntapedev); 565 574 mr_asprintf(tape_device, "%s", bkpinfo->media_device); 566 575 } else { … … 577 586 } else { 578 587 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");584 588 } 585 589 if (bkpinfo->use_star) { … … 656 660 ch = 'U'; 657 661 if (bkpinfo->boot_loader != '\0') { 658 log_msg(2, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader); 662 mr_asprintf(tmp, "User specified boot loader. It is '%c'.", bkpinfo->boot_loader); 663 log_msg(2, tmp); 664 mr_free(tmp); 659 665 } else { 660 666 bkpinfo->boot_loader = ch; 661 667 } 662 668 if (bkpinfo->boot_device[0] != '\0') { 663 log_msg(2, "User specified boot device. It is '%s'.", bkpinfo->boot_device); 669 mr_asprintf(tmp, "User specified boot device. It is '%s'.", bkpinfo->boot_device); 670 log_msg(2, tmp); 671 mr_free(tmp); 664 672 } else { 665 673 strcpy(bkpinfo->boot_device, bootdev); … … 684 692 mr_asprintf(bootldr_str, "LILO"); 685 693 if (!does_file_exist("/etc/lilo.conf")) { 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?"); 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?"); 687 696 } 688 697 } else if (bkpinfo->boot_loader == 'G') { 689 698 mr_asprintf(bootldr_str, "GRUB"); 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); 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); 692 703 } 693 704 if ((!does_file_exist("/boot/grub/menu.lst")) && (!does_file_exist("/boot/grub/grub.cfg")) && (!does_file_exist("/boot/grub2/grub.cfg"))) { 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?"); 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?"); 695 707 } 696 708 mr_asprintf(bootldr_ver, "%s", call_program_and_get_last_line_of_output("grub --version")); … … 698 710 mr_asprintf(bootldr_str, "ELILO"); 699 711 /* BCO: fix it for Debian, Mandrake, ... */ 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); 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); 711 735 } 712 736 if (!does_file_exist("/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'"); 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'"); 714 739 } 715 740 } else if (bkpinfo->boot_loader == 'R') { … … 728 753 mr_asprintf(bootldr_str, "unknown"); 729 754 } 730 log_to_screen("Your boot loader is %s and it boots from %s", bootldr_str, bkpinfo->boot_device); 731 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); 732 758 if (bootldr_ver != NULL) { 733 log_to_screen("Boot loader version string: %s", bootldr_ver); 759 mr_asprintf(tmp, "Boot loader version string: %s", bootldr_ver); 760 log_to_screen(tmp); 761 mr_free(tmp); 734 762 } 735 763 … … 771 799 fatal_error("Unknown backup_media_type"); 772 800 } 773 774 if ((bkpinfo->backup_media_type == usb) && (bkpinfo->media_device)) { 801 if (bkpinfo->backup_media_type == usb) { 775 802 mr_asprintf(tmp2, "--usb %s", bkpinfo->media_device); 776 803 } else { … … 781 808 if (write_one_liner_data_file(tmp, value)) { 782 809 res++; 783 log_msg(1, "%ld: Unable to write one-liner backup-media-type", __LINE__); 810 log_msg(1, "%ld: Unable to write one-liner backup-media-type", 811 __LINE__); 784 812 } 785 813 mr_free(value); … … 789 817 if (write_one_liner_data_file(tmp, bootldr_str)) { 790 818 res++; 791 log_msg(1, "%ld: Unable to write one-liner bootloader.name", __LINE__); 819 log_msg(1, "%ld: Unable to write one-liner bootloader.name", 820 __LINE__); 792 821 } 793 822 mr_free(bootldr_str); … … 836 865 } 837 866 838 estimated_total_noof_slices = size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;839 840 /* TODO:add netfs stuff here? */867 estimated_total_noof_slices = 868 size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1; 869 /* add netfs stuff here? */ 841 870 mr_asprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir); 842 871 if (system(command)) { … … 844 873 log_OS_error("Unable to make images directory"); 845 874 } 846 mr_free(command);875 paranoid_free(command); 847 876 log_msg(1, "lines_in_filelist = %ld", lines_in_filelist); 848 877 update_evalcall_form(3); … … 861 890 use_lzo_sz, // parameter #8 862 891 cd_recovery_sz, // parameter #9 863 (bkpinfo->image_devs == NULL) ? "\"\"" :bkpinfo->image_devs, // parameter #10892 bkpinfo->image_devs, // parameter #10 864 893 broken_bios_sz, // parameter #11 865 894 last_filelist_number, // parameter #12 (STRING) … … 871 900 bkpinfo->internal_tape_block_size, // parameter #18 (LONG) 872 901 bkpinfo->differential, // parameter #19 (INT) 873 use_gzip_sz, // parameter #19 (STRING) 874 use_lzma_sz, // parameter #20 (STRING) 875 value, // parameter #21 (STRING) 876 MONDO_LOGFILE); 902 use_gzip_sz); // parameter #20 (STRING) 877 903 878 904 mr_free(last_filelist_number); … … 880 906 mr_free(use_lzo_sz); 881 907 mr_free(use_gzip_sz); 882 mr_free(use_lzma_sz);883 908 mr_free(use_star_sz); 884 909 mr_free(use_comp_sz); … … 888 913 mr_free(tape_size_sz); 889 914 890 /* This parameter is always the last one and optional */891 915 if (bkpinfo->nonbootable_backup) { 892 916 mr_strcat(command, " NONBOOTABLE"); … … 905 929 if (!res) { 906 930 log_to_screen("Boot+data disks were created OK"); 907 mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso", bkpinfo->scratchdir, MINDI_CACHE); 931 mr_asprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso", 932 bkpinfo->scratchdir, MINDI_CACHE); 908 933 log_msg(2, command); 909 934 run_program_and_log_output(command, FALSE); 910 mr_free(command);935 paranoid_free(command); 911 936 912 937 if (bkpinfo->nonbootable_backup) { 913 mr_asprintf(command, "cp -f %s/all.tar.gz %s/images", bkpinfo->tmpdir, bkpinfo->scratchdir); 938 mr_asprintf(command, "cp -f %s/all.tar.gz %s/images", 939 bkpinfo->tmpdir, bkpinfo->scratchdir); 914 940 if (system(command)) { 915 mr_free(command);941 paranoid_free(command); 916 942 fatal_error("Unable to create temporary all tarball"); 917 943 } 918 mr_free(command);944 paranoid_free(command); 919 945 } 920 946 /* For USB we already have everything on the key */ … … 922 948 mr_asprintf(command, "rm -rf %s/images", bkpinfo->scratchdir); 923 949 run_program_and_log_output(command, FALSE); 924 mr_free(command);950 paranoid_free(command); 925 951 } else { 926 mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, bkpinfo->tmpdir); 952 mr_asprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir, 953 bkpinfo->tmpdir); 927 954 if (system(tmp)) { 928 955 fatal_error("Cannot find all.tar.gz in tmpdir"); … … 939 966 mr_asprintf(command, "grep 'Fatal error' /var/log/mindi.log"); 940 967 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 941 mr_free(command);968 paranoid_free(command); 942 969 943 970 if (strlen(tmp) > 1) { … … 990 1017 void *create_afio_files_in_background(void *inbuf) 991 1018 { 992 long int archiving_set_no = 0L;993 char *archiving_filelist_fname = NULL;994 char *archiving_afioball_fname = NULL;1019 long int archiving_set_no; 1020 char *archiving_filelist_fname; 1021 char *archiving_afioball_fname; 995 1022 char *curr_xattr_list_fname = NULL; 996 char *curr_acl_list_fname = NULL;997 998 char *tmp = NULL;1023 char *curr_acl_list_fname; 1024 1025 char *tmp; 999 1026 int res = 0, retval = 0; 1000 1027 int *p_archival_threads_running; … … 1004 1031 int this_thread_no = g_current_thread_no++; 1005 1032 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); 1006 1038 p_last_set_archived = (int *) inbuf; 1007 1039 p_archival_threads_running = (int *) (inbuf + 4); … … 1009 1041 p_list_of_fileset_flags = (char *) (inbuf + 12); 1010 1042 1011 mr_asprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir, 0L); 1012 1013 while (does_file_exist(archiving_filelist_fname)) { 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)) { 1014 1048 if (g_exiting) { 1015 mr_free(archiving_filelist_fname);1016 1049 fatal_error("Execution run aborted (pthread)"); 1017 1050 } 1018 1051 if (archiving_set_no >= MAX_NOOF_SETS_HERE) { 1019 mr_free(archiving_filelist_fname);1020 fatal_error("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");1052 fatal_error 1053 ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please."); 1021 1054 } 1022 1055 if (!semaphore_p()) { 1023 1056 log_msg(3, "P sem failed (pid=%d)", (int) getpid()); 1024 mr_free(archiving_filelist_fname);1025 1057 fatal_error("Cannot get semaphore P"); 1026 1058 } … … 1030 1062 *p_next_set_to_archive = *p_next_set_to_archive + 1; 1031 1063 if (!semaphore_v()) { 1032 mr_free(archiving_filelist_fname);1033 1064 fatal_error("Cannot get semaphore V"); 1034 1065 } 1035 1066 1036 1067 /* backup this set of files */ 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); 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); 1040 1072 if (!does_file_exist(archiving_filelist_fname)) { 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); 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); 1043 1077 break; 1044 1078 } 1045 1079 1046 mr_asprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix); 1080 sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir, 1081 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix); 1047 1082 if (does_file_exist(tmp)) { 1048 log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, getpid(), this_thread_no); 1083 log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES, 1084 getpid(), this_thread_no); 1049 1085 while (does_file_exist(tmp)) { 1050 1086 sleep(1); … … 1052 1088 log_msg(4, "[%d] - continuing", getpid()); 1053 1089 } 1054 mr_free(tmp); 1055 1056 log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1057 1090 1091 log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(), 1092 this_thread_no, archiving_set_no); 1058 1093 if (g_getfattr) { 1059 mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1094 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 1095 bkpinfo->tmpdir, archiving_set_no); 1060 1096 get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname); 1061 mr_free(curr_xattr_list_fname);1062 1097 } 1063 1098 if (g_getfacl) { 1064 mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, archiving_set_no); 1099 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 1100 bkpinfo->tmpdir, archiving_set_no); 1065 1101 get_acl_list(archiving_filelist_fname, curr_acl_list_fname); 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 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); 1073 1110 retval += res; 1074 1111 1075 1112 if (res) { 1076 log_to_screen("Errors occurred while archiving set %ld. Please review logs.", archiving_set_no); 1077 } 1078 1113 sprintf(tmp, 1114 "Errors occurred while archiving set %ld. Please review logs.", 1115 archiving_set_no); 1116 log_to_screen(tmp); 1117 } 1079 1118 if (!semaphore_p()) { 1080 mr_free(archiving_filelist_fname);1081 1119 fatal_error("Cannot get semaphore P"); 1082 1120 } … … 1089 1127 1090 1128 if (!semaphore_v()) { 1091 mr_free(archiving_filelist_fname);1092 1129 fatal_error("Cannot get semaphore V"); 1093 1130 } 1094 log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), this_thread_no, archiving_set_no); 1131 log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(), 1132 this_thread_no, archiving_set_no); 1095 1133 archiving_set_no++; 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 1134 } 1102 1135 if (!semaphore_p()) { 1103 1136 fatal_error("Cannot get semaphore P"); … … 1107 1140 fatal_error("Cannot get semaphore V"); 1108 1141 } 1109 log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(), this_thread_no); 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); 1110 1149 pthread_exit(NULL); 1111 1150 } … … 1189 1228 1190 1229 /*@ buffers *********************************** */ 1191 char *command = NULL; 1192 char *tmpfile = NULL; 1193 char *data_disks_file = NULL; 1230 char *command, *tmpfile, *data_disks_file; 1194 1231 1195 1232 assert(bkpinfo != NULL); 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")); 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")); 1199 1242 strip_spaces(g_serial_string); 1200 1243 strcat(g_serial_string, "...word."); … … 1202 1245 assert(strlen(g_serial_string) < MAX_STR_LEN); 1203 1246 1204 mr_asprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);1247 sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir); 1205 1248 if (write_one_liner_data_file(tmpfile, g_serial_string)) { 1206 1249 log_msg(1, "%ld: Failed to write serial string", __LINE__); 1207 1250 } 1208 mr_free(tmpfile);1209 1251 1210 1252 mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data"); … … 1227 1269 } 1228 1270 } 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);1271 1272 sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir, 1273 bkpinfo->netfs_remote_dir, bkpinfo->prefix); 1232 1274 paranoid_system(command); 1233 mr_free(command);1234 1235 1275 wipe_archives(bkpinfo->scratchdir); 1236 1276 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1241 1281 BLK_START_OF_BACKUP); 1242 1282 } 1283 paranoid_free(command); 1284 paranoid_free(tmpfile); 1285 paranoid_free(data_disks_file); 1243 1286 return (retval); 1244 1287 } … … 1313 1356 1314 1357 /*@ buffers ********************************************** */ 1315 char *storing_filelist_fname = NULL;1316 char *storing_afioball_fname = NULL;1358 char *storing_filelist_fname; 1359 char *storing_afioball_fname; 1317 1360 char *tmp = NULL; 1318 1361 char *media_usage_comment = NULL; … … 1331 1374 assert(bkpinfo != NULL); 1332 1375 malloc_string(result_str); 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); 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); 1335 1384 p_last_set_archived = (int *) transfer_block; 1336 1385 p_archival_threads_running = (int *) (transfer_block + 4); 1337 1386 p_next_set_to_archive = (int *) (transfer_block + 8); 1338 1387 p_list_of_fileset_flags = (char *) (transfer_block + 12); 1339 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), (void *) bkpinfo, sizeof(struct s_bkpinfo)); 1388 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), 1389 (void *) bkpinfo, sizeof(struct s_bkpinfo)); 1340 1390 pvp = &vp; 1341 1391 vp = (void *) result_str; … … 1349 1399 "Please wait. This may take a couple of hours.", 1350 1400 "Working...", 1351 (long)get_last_filelist_number() + 1L);1401 get_last_filelist_number() + 1); 1352 1402 1353 1403 log_msg(5, "We're gonna party like it's your birthday."); … … 1388 1438 if (!get_bit_N_of_array 1389 1439 (p_list_of_fileset_flags, storing_set_no)) { 1390 misc_counter_that_is_not_important = (misc_counter_that_is_not_important + 1) % 5; 1440 misc_counter_that_is_not_important = 1441 (misc_counter_that_is_not_important + 1) % 5; 1391 1442 /* BCO the media_usage_comment is not really initialized there ! 1392 1443 if (!misc_counter_that_is_not_important) { … … 1395 1446 */ 1396 1447 sleep(1); 1397 } else {1448 } else 1398 1449 // store set N 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); 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); 1401 1455 if (g_getfattr) { 1402 mr_asprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no); 1456 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 1457 bkpinfo->tmpdir, storing_set_no); 1403 1458 } 1404 1459 if (g_getfacl) { 1405 mr_asprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, bkpinfo->tmpdir, storing_set_no); 1460 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 1461 bkpinfo->tmpdir, storing_set_no); 1406 1462 } 1407 1463 … … 1414 1470 sleep(5); 1415 1471 } 1472 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment()); 1416 1473 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ 1417 1474 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1418 1475 register_in_tape_catalog(fileset, storing_set_no, -1, 1419 1476 storing_afioball_fname); 1420 maintain_collection_of_recent_archives(bkpinfo->tmpdir, storing_afioball_fname); 1477 maintain_collection_of_recent_archives(bkpinfo->tmpdir, 1478 storing_afioball_fname); 1421 1479 log_it("Writing EXAT files"); 1422 1480 res += … … 1452 1510 retval += res; 1453 1511 g_current_progress++; 1454 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());1455 1512 update_progress_form(media_usage_comment); 1456 1513 mr_free(media_usage_comment); 1457 1514 if (res) { 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."); 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."); 1460 1521 } 1461 1522 storing_set_no++; 1462 1523 // 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);1471 1524 } 1472 1525 } … … 1487 1540 } 1488 1541 log_to_screen(tmp); 1489 mr_free(tmp);1542 paranoid_free(tmp); 1490 1543 1491 1544 paranoid_free(transfer_block); 1492 1545 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); 1493 1550 return (retval); 1494 1551 } … … 1541 1598 mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1542 1599 run_program_and_log_output(tmp, FALSE); 1543 mr_free(tmp);1600 paranoid_free(tmp); 1544 1601 if (chdir(bkpinfo->scratchdir)) { 1545 1602 // FIXME … … 1551 1608 log_msg(1, message_to_screen); 1552 1609 1553 if (bkpinfo->media_device) { 1554 mr_asprintf(tmp1, "%s1", bkpinfo->media_device); 1555 } else { 1556 mr_asprintf(tmp1, ""); 1557 } 1610 mr_asprintf(tmp1, "%s1", bkpinfo->media_device); 1558 1611 if (is_this_device_mounted(tmp1)) { 1559 1612 log_msg(1, "USB device mounted. Remounting it at the right place"); 1560 1613 mr_asprintf(tmp, "umount %s", tmp1); 1561 1614 run_program_and_log_output(tmp, FALSE); 1562 mr_free(tmp);1563 } 1564 mr_free(tmp1);1615 paranoid_free(tmp); 1616 } 1617 paranoid_free(tmp1); 1565 1618 1566 1619 log_msg(1, "Mounting USB device."); … … 1568 1621 mr_asprintf(tmp, "mkdir -p %s", tmp1); 1569 1622 run_program_and_log_output(tmp, FALSE); 1570 mr_free(tmp); 1571 1623 paranoid_free(tmp); 1572 1624 1573 1625 /* Mindi always create one single parition on the USB dev */ 1574 1626 mr_asprintf(tmp, "mount %s1 %s", bkpinfo->media_device, tmp1); 1575 1627 run_program_and_log_output(tmp, FALSE); 1576 mr_free(tmp);1628 paranoid_free(tmp); 1577 1629 1578 1630 if (bkpinfo->nonbootable_backup) { … … 1590 1642 } 1591 1643 log_to_screen(result_sz); 1592 mr_free(result_sz);1593 mr_free(tmp);1644 paranoid_free(result_sz); 1645 paranoid_free(tmp); 1594 1646 retval += res; 1595 1647 … … 1597 1649 mr_asprintf(tmp,"mkdir %s/archive", bkpinfo->scratchdir); 1598 1650 run_program_and_log_output(tmp, FALSE); 1599 mr_free(tmp);1651 paranoid_free(tmp); 1600 1652 } 1601 1653 paranoid_free(message_to_screen); … … 1605 1657 mr_asprintf(tmp, "umount %s1", bkpinfo->media_device); 1606 1658 run_program_and_log_output(tmp, FALSE); 1607 mr_free(tmp);1659 paranoid_free(tmp); 1608 1660 } 1609 1661 … … 1643 1695 1644 1696 /*@ buffers ****************************************** */ 1645 char *tmp = NULL; 1646 char *tmp2 = NULL; 1697 char *tmp; 1647 1698 char *old_pwd; 1648 1699 char *result_sz = NULL; 1649 1700 char *message_to_screen = NULL; 1650 1701 char *sz_blank_disk = NULL; 1651 char *fnam = NULL; 1652 char *tmp3 = NULL; 1702 char *fnam; 1703 char *tmp2; 1704 char *tmp3; 1653 1705 char *isofs_cmd = NULL; 1654 1706 char *full_isofs_cmd = NULL; … … 1658 1710 malloc_string(old_pwd); 1659 1711 malloc_string(fnam); 1712 tmp = malloc(1200); 1713 tmp2 = malloc(1200); 1714 tmp3 = malloc(1200); 1660 1715 assert(bkpinfo != NULL); 1661 1716 assert_string_is_neither_NULL_nor_zerolength(destfile); 1662 1717 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); 1718 sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir); 1719 sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir); 1666 1720 if (does_file_exist(tmp)) { 1667 mr_asprintf(tmp3, "cp -f %s %s", tmp, tmp2);1721 sprintf(tmp3, "cp -f %s %s", tmp, tmp2); 1668 1722 paranoid_system(tmp3); 1669 mr_free(tmp3);1670 1723 } 1671 1724 if (!does_file_exist(tmp) && does_file_exist(tmp2)) { 1672 mr_asprintf(tmp3, "cp -f %s %s", tmp2, tmp);1725 sprintf(tmp3, "cp -f %s %s", tmp2, tmp); 1673 1726 paranoid_system(tmp3); 1674 mr_free(tmp3); 1675 } 1676 mr_free(tmp2); 1677 mr_free(tmp3); 1727 } 1728 free(tmp2); 1729 free(tmp3); 1730 tmp2 = NULL; 1731 tmp3 = NULL; 1678 1732 if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) { 1679 1733 popup_and_OK("Please insert new media and press Enter."); 1680 1734 } 1681 1735 1682 log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", bkpinfo->scratchdir, destfile); 1736 log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s", 1737 bkpinfo->scratchdir, destfile); 1683 1738 tmp2 = getcwd(old_pwd, MAX_STR_LEN - 1); 1684 if (! tmp2) { 1685 //FIXME 1686 } 1687 mr_asprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1739 sprintf(tmp, "chmod 700 %s", bkpinfo->scratchdir); 1688 1740 run_program_and_log_output(tmp, FALSE); 1689 mr_free(tmp);1690 1691 1741 if (chdir(bkpinfo->scratchdir)) { 1692 1742 // FIXME … … 1694 1744 1695 1745 if (bkpinfo->call_before_iso[0] != '\0') { 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); 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); 1698 1752 if (res) { 1699 1753 mr_strcat(message_to_screen, "...failed"); … … 1709 1763 if (bkpinfo->call_make_iso[0] != '\0') { 1710 1764 log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso); 1765 sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir); 1711 1766 mds = media_descriptor_string(bkpinfo->backup_media_type); 1712 1767 mr_asprintf(message_to_screen, "Making an ISO (%s #%d)", mds, g_current_media_number); … … 1719 1774 } else { 1720 1775 res = 1721 eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1776 eval_call_to_make_ISO(bkpinfo->call_make_iso, 1777 bkpinfo->scratchdir, 1778 g_current_media_number, 1779 MONDO_LOGFILE, message_to_screen); 1722 1780 if (res) { 1723 1781 log_to_screen("%s...failed to write", message_to_screen); 1724 1782 } else { 1725 1783 log_to_screen("%s...OK", message_to_screen); 1726 mr_asprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);1784 sprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE); 1727 1785 if (!run_program_and_log_output(tmp, 1)) { 1728 1786 log_to_screen 1729 1787 ("Despite nonfatal errors, growisofs confirms the write was successful."); 1730 1788 } 1731 mr_free(tmp);1732 1789 } 1733 1790 retval += res; 1734 1791 #ifdef DVDRWFORMAT 1735 mr_asprintf(tmp, "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", MONDO_LOGFILE); 1792 sprintf(tmp, 1793 "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'", 1794 MONDO_LOGFILE); 1736 1795 if (g_backup_media_type == dvd 1737 1796 && (res || !run_program_and_log_output(tmp, 1))) { … … 1741 1800 /* reset error counter before trying to blank DVD */ 1742 1801 retval -= res; 1743 sync();1802 paranoid_system("sync"); 1744 1803 pause_for_N_seconds(5, "Letting DVD drive settle"); 1745 1804 … … 1751 1810 } 1752 1811 pause_for_N_seconds(5, "Letting DVD drive settle"); 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 } 1812 mr_asprintf(sz_blank_disk, "dvd+rw-format -force %s", bkpinfo->media_device); 1758 1813 log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk); 1759 res = run_external_binary_with_percentage_indicator_NEW("Blanking DVD disk", sz_blank_disk); 1814 res = 1815 run_external_binary_with_percentage_indicator_NEW 1816 ("Blanking DVD disk", sz_blank_disk); 1760 1817 if (res) { 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); 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); 1764 1825 if (res) { 1765 1826 log_to_screen("Format failed a second time."); … … 1777 1838 } 1778 1839 pause_for_N_seconds(5, "Letting DVD drive settle"); 1779 res = eval_call_to_make_ISO(bkpinfo->call_make_iso, bkpinfo->scratchdir, g_current_media_number, MONDO_LOGFILE, message_to_screen); 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); 1780 1846 retval += res; 1781 1847 if (!bkpinfo->please_dont_eject) { … … 1790 1856 } 1791 1857 } 1792 mr_free(tmp);1793 1858 #endif 1794 1859 if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) { … … 1811 1876 log_msg(1, "Making nonbootable backup"); 1812 1877 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS); 1813 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1878 res = eval_call_to_make_ISO(full_isofs_cmd, 1879 destfile, g_current_media_number, 1880 MONDO_LOGFILE, message_to_screen); 1814 1881 mr_free(full_isofs_cmd); 1815 1882 } else { … … 1821 1888 1822 1889 1823 log_msg(1, "make_cd_use_lilo is actually %d", bkpinfo->make_cd_use_lilo); 1890 log_msg(1, "make_cd_use_lilo is actually %d", 1891 bkpinfo->make_cd_use_lilo); 1824 1892 if (bkpinfo->make_cd_use_lilo) { 1825 1893 log_msg(1, "make_cd_use_lilo = TRUE"); … … 1827 1895 log_msg(1, "IA64 --> elilo"); 1828 1896 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_ELILO); 1829 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1897 res = eval_call_to_make_ISO(full_isofs_cmd, 1898 destfile, 1899 g_current_media_number, 1900 MONDO_LOGFILE, 1901 message_to_screen); 1830 1902 mr_free(full_isofs_cmd); 1831 1903 #else 1832 1904 log_msg(1, "Non-ia64 --> lilo"); 1833 1905 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); 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); 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); 1836 1912 mr_free(full_isofs_cmd); 1837 1913 #endif … … 1840 1916 log_msg(1, "Isolinux"); 1841 1917 mr_asprintf(full_isofs_cmd, "%s%s-o '_ISO_' -V _CD#_ .",isofs_cmd,MONDO_MKISOFS_REGULAR_SYSLINUX); 1842 res = eval_call_to_make_ISO(full_isofs_cmd, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1918 res = 1919 eval_call_to_make_ISO(full_isofs_cmd, 1920 destfile, g_current_media_number, 1921 MONDO_LOGFILE, 1922 message_to_screen); 1843 1923 mr_free(full_isofs_cmd); 1844 1924 } … … 1860 1940 || bkpinfo->backup_media_type == cdrw) { 1861 1941 if (is_this_device_mounted(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); 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); 1864 1946 run_program_and_log_output(tmp, FALSE); 1865 mr_free(tmp);1866 1947 } 1867 1948 } … … 1873 1954 mr_free(mds); 1874 1955 pause_and_ask_for_cdr(2, &cd_is_mountable); 1875 res = eval_call_to_make_ISO(bkpinfo->call_burn_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1956 res = 1957 eval_call_to_make_ISO(bkpinfo->call_burn_iso, 1958 destfile, g_current_media_number, 1959 MONDO_LOGFILE, message_to_screen); 1876 1960 if (res) { 1877 1961 mr_strcat(message_to_screen, "...failed"); … … 1889 1973 mr_asprintf(message_to_screen, "Running post-ISO call (%s #%d)", mds, g_current_media_number); 1890 1974 mr_free(mds); 1891 res = eval_call_to_make_ISO(bkpinfo->call_after_iso, destfile, g_current_media_number, MONDO_LOGFILE, message_to_screen); 1975 res = 1976 eval_call_to_make_ISO(bkpinfo->call_after_iso, 1977 destfile, g_current_media_number, 1978 MONDO_LOGFILE, message_to_screen); 1892 1979 if (res) { 1893 1980 mr_strcat(message_to_screen, "...failed"); … … 1957 2044 1958 2045 /*@ pointers ******************************************* */ 1959 FILE *fin = NULL;2046 FILE *fin; 1960 2047 char *p; 1961 2048 char *q; … … 1963 2050 /*@ buffers ******************************************** */ 1964 2051 char *tmp = NULL; 1965 char *bigfile_fname = NULL;2052 char *bigfile_fname; 1966 2053 char *sz_devfile = NULL; 1967 2054 char *ntfsprog_fifo = NULL; … … 1999 2086 log_to_screen(tmp); 2000 2087 noof_biggie_files = count_lines_in_file(biggielist_fname); 2001 open_progress_form("Backing up big files", tmp, "Please wait. This may take some time.", "", estimated_total_noof_slices); 2002 mr_free(tmp); 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); 2003 2092 2004 2093 if (!(fin = fopen(biggielist_fname, "r"))) { … … 2032 2121 log_msg(2, "bigfile_fname = %s", bigfile_fname); 2033 2122 use_ntfsprog = FALSE; 2034 if (!strncmp(bigfile_fname, "/dev/", 5) && is_dev_an_NTFS_dev(bigfile_fname)) { 2123 if (!strncmp(bigfile_fname, "/dev/", 5) 2124 && is_dev_an_NTFS_dev(bigfile_fname)) { 2035 2125 use_ntfsprog = TRUE; 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)); 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)); 2038 2132 mkfifo(sz_devfile, 0x770); 2039 2133 ntfsprog_fifo = sz_devfile; … … 2043 2137 fatal_error("Fork failure"); 2044 2138 case 0: 2045 log_msg(2, "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", bigfile_fname, sz_devfile); 2139 log_msg(2, 2140 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)", 2141 bigfile_fname, sz_devfile); 2046 2142 res = feed_into_ntfsprog(bigfile_fname, sz_devfile); 2047 2143 /* BCO/BERLIOS Does the child need to unalocate memory as well ? 2048 mr_free(bigfile_fname);2144 paranoid_free(bigfile_fname); 2049 2145 mr_free(sz_devfile); 2050 2146 */ … … 2052 2148 break; 2053 2149 default: 2054 log_msg(2, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid)); 2150 log_msg(2, 2151 "feed_into_ntfsprog() called in background --- pid=%ld", 2152 (long int) (pid)); 2055 2153 } 2056 2154 } … … 2062 2160 // Whether partition or biggiefile, just do your thang :-) 2063 2161 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2064 write_header_block_to_stream(biggie_fsize, bigfile_fname, use_ntfsprog ? BLK_START_A_PIHBIGGIE : BLK_START_A_NORMBIGGIE); 2162 write_header_block_to_stream(biggie_fsize, bigfile_fname, 2163 use_ntfsprog ? 2164 BLK_START_A_PIHBIGGIE : 2165 BLK_START_A_NORMBIGGIE); 2065 2166 } 2066 res = slice_up_file_etc(bigfile_fname, ntfsprog_fifo, biggie_file_number, noof_biggie_files, use_ntfsprog); 2167 res = 2168 slice_up_file_etc(bigfile_fname, 2169 ntfsprog_fifo, biggie_file_number, 2170 noof_biggie_files, use_ntfsprog); 2067 2171 2068 2172 /* Free it here as ntfsprog_fifo is not used anymore */ … … 2093 2197 } 2094 2198 } 2199 #ifndef _XWIN 2095 2200 if (!g_text_mode) { 2096 2201 newtDrawRootText(0, g_noof_rows - 2, tmp); 2097 2202 newtRefresh(); 2098 2203 } 2099 mr_free(tmp); 2100 } 2101 mr_free(bigfile_fname); 2102 2204 #endif 2205 paranoid_free(tmp); 2206 } 2103 2207 log_msg(1, "Finished backing up bigfiles"); 2104 2208 log_msg(1, "estimated slices = %ld; actual slices = %ld", … … 2106 2210 close_progress_form(); 2107 2211 paranoid_fclose(fin); 2212 paranoid_free(bigfile_fname); 2108 2213 return (retval); 2109 2214 } … … 2166 2271 retval += res; 2167 2272 if (res) { 2168 log_to_screen("Errors occurred while archiving set %ld. Perhaps your live filesystem changed?", curr_set_no); 2169 } 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()); 2170 2279 2171 2280 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */ … … 2210 2319 retval += res; 2211 2320 g_current_progress++; 2212 2213 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());2214 2321 update_progress_form(media_usage_comment); 2215 2322 mr_free(media_usage_comment); 2216 2323 2217 2324 if (res) { 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."); 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."); 2220 2330 } 2221 2331 mr_free(curr_filelist_fname); … … 2318 2428 } 2319 2429 2320 mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist); 2430 mr_asprintf(command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, 2431 biggielist); 2321 2432 paranoid_system(command); 2322 2433 mr_free(command); … … 2332 2443 if (g_getfattr) { 2333 2444 get_fattr_list(biggielist, xattr_fname); 2334 mr_asprintf(command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir); 2445 mr_asprintf(command, "cp %s %s/archives/", xattr_fname, 2446 bkpinfo->scratchdir); 2335 2447 paranoid_system(command); 2336 2448 mr_free(command); … … 2621 2733 /*@ buffers ********************************************* */ 2622 2734 char *tmp = NULL; 2623 char *cdrom_dev = NULL;2624 char *cdrw_dev = NULL;2735 char *cdrom_dev; 2736 char *cdrw_dev; 2625 2737 char *our_serial_str = NULL; 2626 2738 bool ok_go_ahead_burn_it; … … 2628 2740 int attempt_to_mount_returned_this = 999; 2629 2741 char *mtpt = NULL; 2630 char *szcdno = NULL;2631 char *szserfname = NULL;2632 char *szunmount = NULL;2742 char *szcdno; 2743 char *szserfname; 2744 char *szunmount; 2633 2745 char *mds = NULL; 2634 2746 2635 2747 malloc_string(cdrom_dev); 2636 2748 malloc_string(cdrw_dev); 2749 malloc_string(szcdno); 2750 malloc_string(szserfname); 2751 malloc_string(szunmount); 2752 malloc_string(mtpt); 2637 2753 2638 2754 mds = media_descriptor_string(g_backup_media_type); 2639 log_to_screen("I am about to burn %s #%d", mds, g_current_media_number);2755 mr_asprintf(tmp, "I am about to burn %s #%d", mds, g_current_media_number); 2640 2756 mr_free(mds); 2757 log_to_screen(tmp); 2758 mr_free(tmp); 2641 2759 if (g_current_media_number < ask_for_one_if_more_than_this) { 2642 2760 return; 2643 2761 } 2644 2762 log_to_screen("Scanning CD-ROM drive..."); 2645 mr_asprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);2763 sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir); 2646 2764 make_hole_for_dir(mtpt); 2647 2765 … … 2649 2767 ok_go_ahead_burn_it = TRUE; 2650 2768 if (!find_cdrom_device(cdrom_dev, FALSE)) { 2651 2652 2653 2654 2769 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird 2770 log_msg(2, "paafcd: Retracting CD-ROM drive if possible" ); 2771 retract_CD_tray_and_defeat_autorun(); 2772 */ 2655 2773 mr_asprintf(tmp, "umount %s", cdrom_dev); 2656 2774 run_program_and_log_output(tmp, 1); 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);2775 sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt); 2776 sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt); 2777 sprintf(szunmount, "umount %s", mtpt); 2660 2778 cd_number = -1; 2661 2779 mr_asprintf(tmp, "mount %s %s", cdrom_dev, mtpt); … … 2663 2781 attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1); 2664 2782 mr_free(tmp); 2665 2666 2783 if (attempt_to_mount_returned_this) { 2667 2784 log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt); 2668 2785 log_to_screen("If there's a CD/DVD in the drive, it's blank."); 2669 } else if (!does_file_exist(szcdno) || !does_file_exist(szserfname)) { 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)) { 2670 2799 mds = media_descriptor_string(g_backup_media_type); 2671 log_to_screen("%s has data on it but it's probably not a Mondo CD.", mds); 2800 log_to_screen 2801 ("%s has data on it but it's probably not a Mondo CD.", mds); 2672 2802 mr_free(mds); 2673 2803 } else { … … 2679 2809 mr_asprintf(tmp, "cat %s 2> /dev/null", szserfname); 2680 2810 mr_free(our_serial_str); 2681 mr_asprintf(our_serial_str, "%s", call_program_and_get_last_line_of_output(tmp)); 2811 mr_asprintf(our_serial_str, "%s", 2812 call_program_and_get_last_line_of_output(tmp)); 2682 2813 mr_free(tmp); 2683 2814 // FIXME - should be able to use last_line_of_file(), surely? 2684 2815 } 2685 mr_free(szcdno);2686 mr_free(szserfname);2687 2688 2816 run_program_and_log_output(szunmount, 1); 2689 mr_free(szunmount);2690 2691 2817 log_msg(2, "paafcd: cd_number = %d", cd_number); 2692 log_msg(2, "our serial str = %s; g_serial_string = %s", our_serial_str, g_serial_string); 2818 log_msg(2, "our serial str = %s; g_serial_string = %s", 2819 our_serial_str, g_serial_string); 2693 2820 if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) { 2694 2821 mds = media_descriptor_string(g_backup_media_type); … … 2722 2849 } 2723 2850 mds = media_descriptor_string(g_backup_media_type); 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); 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); 2725 2853 mr_free(mds); 2726 2854 … … 2733 2861 2734 2862 mds = media_descriptor_string(g_backup_media_type); 2735 log_msg(2, "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds); 2863 log_msg(2, 2864 "paafcd: OK, I assume I have a blank/reusable %s in the drive...", mds); 2736 2865 2737 2866 log_to_screen("Proceeding w/ %s in drive.", mds); … … 2740 2869 paranoid_free(cdrom_dev); 2741 2870 paranoid_free(cdrw_dev); 2742 mr_free(mtpt); 2871 paranoid_free(mtpt); 2872 paranoid_free(szcdno); 2873 paranoid_free(szserfname); 2874 paranoid_free(szunmount); 2743 2875 if (pmountable) { 2744 2876 if (attempt_to_mount_returned_this) { … … 2750 2882 2751 2883 } 2884 2885 2886 2887 2888 2889 2752 2890 2753 2891 … … 2779 2917 2780 2918 /* @} - end of utilityGroup */ 2919 2920 2921 2922 2923 2924 2781 2925 2782 2926 … … 2801 2945 */ 2802 2946 int 2803 slice_up_file_etc(char *biggie_filename, char *ntfsprog_fifo, long biggie_file_number, long noof_biggie_files, bool use_ntfsprog) { 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 { 2804 2951 2805 2952 /*@ buffers ************************************************** */ 2806 2953 char *tmp = NULL; 2807 char *checksum_line = NULL; 2808 char *command = NULL; 2809 char *tempblock = NULL; 2954 char *checksum_line, *command; 2955 char *tempblock; 2810 2956 char *curr_slice_fname_uncompressed = NULL; 2811 2957 char *curr_slice_fname_compressed = NULL; 2812 2958 char *file_to_archive = NULL; 2813 char *file_to_openin = NULL;2959 char *file_to_openin; 2814 2960 /*@ pointers ************************************************** */ 2815 char *pB = NULL; 2816 FILE *fin = NULL; 2817 FILE *fout = NULL; 2961 char *pB; 2962 FILE *fin = NULL, *fout = NULL; 2818 2963 2819 2964 /*@ bool ****************************************************** */ … … 2821 2966 2822 2967 /*@ long ****************************************************** */ 2823 size_t blksize = (size_t)0; 2824 long slice_num = 0L; 2825 long i = 0L; 2826 bool should_I_compress_slices = TRUE; 2968 size_t blksize = 0; 2969 long slice_num = 0; 2970 long i; 2971 long optimal_set_size; 2972 bool should_I_compress_slices; 2827 2973 char *suffix = NULL; // for compressed slices 2828 2974 … … 2837 2983 /*@ structures ************************************************** */ 2838 2984 struct s_filename_and_lstat_info biggiestruct; 2985 // struct stat statbuf; 2839 2986 2840 2987 assert(bkpinfo != NULL); 2841 2988 assert_string_is_neither_NULL_nor_zerolength(biggie_filename); 2989 malloc_string(checksum_line); 2842 2990 2843 2991 biggiestruct.for_backward_compatibility = '\n'; 2844 2992 biggiestruct.use_ntfsprog = use_ntfsprog; 2845 if (is_this_file_compressed(biggie_filename) || bkpinfo->compression_level == 0) { 2993 optimal_set_size = bkpinfo->optimal_set_size; 2994 if (is_this_file_compressed(biggie_filename) 2995 || bkpinfo->compression_level == 0) { 2846 2996 mr_asprintf(suffix, "%s", ""); 2997 // log_it("%s is indeed compressed :-)", filename); 2847 2998 should_I_compress_slices = FALSE; 2848 2999 } else { … … 2851 3002 } 2852 3003 2853 if ( bkpinfo->optimal_set_size < 999L) {3004 if (optimal_set_size < 999) { 2854 3005 fatal_error("bkpinfo->optimal_set_size is insanely small"); 2855 3006 } 2856 2857 3007 if (ntfsprog_fifo) { 2858 3008 file_to_openin = ntfsprog_fifo; 2859 mr_asprintf(checksum_line, "IGNORE"); 2860 log_msg(2, "Not calculating checksum for %s: it would take too long", biggie_filename); 3009 strcpy(checksum_line, "IGNORE"); 3010 log_msg(2, 3011 "Not calculating checksum for %s: it would take too long", 3012 biggie_filename); 2861 3013 if ( !find_home_of_exe("ntfsresize")) { 2862 3014 fatal_error("ntfsresize not found"); … … 2868 3020 log_it("res of it = %s", tmp); 2869 3021 totallength = (off_t)atoll(tmp); 2870 mr_free(tmp);3022 paranoid_free(tmp); 2871 3023 } else { 2872 3024 file_to_openin = biggie_filename; … … 2882 3034 } 2883 3035 mr_free(command); 2884 mr_getline(checksum_line, fin);3036 tmp = fgets(checksum_line, MAX_STR_LEN, fin); 2885 3037 pclose(fin); 2886 3038 totallength = length_of_file (biggie_filename); … … 2896 3048 } 2897 3049 strcpy(biggiestruct.checksum, checksum_line); 2898 mr_free(checksum_line);2899 3050 2900 3051 mr_asprintf(tmp, "%s", slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "")); … … 2902 3053 if (fout == NULL) { 2903 3054 log_msg(1, "Unable to open and write to %s\n", tmp); 2904 mr_free(tmp);3055 paranoid_free(tmp); 2905 3056 mr_free(suffix); 2906 3057 return (1); 2907 3058 } 2908 mr_free(tmp);3059 paranoid_free(tmp); 2909 3060 2910 3061 res = fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout); … … 2912 3063 paranoid_fclose(fout); 2913 3064 } 2914 log_msg(1, "Opening in %s; slicing it and writing to CD/tape", file_to_openin); 3065 log_msg(1, "Opening in %s; slicing it and writing to CD/tape", 3066 file_to_openin); 2915 3067 if (!(fin = fopen(file_to_openin, "r"))) { 2916 3068 log_OS_error("Unable to openin biggie_filename"); 2917 log_to_screen("Cannot archive bigfile '%s': not found", biggie_filename); 2918 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); 2919 3074 mr_free(suffix); 2920 3075 return (1); … … 2939 3094 mr_asprintf(tmp, "%s", percent_media_full_comment()); 2940 3095 update_progress_form(tmp); 2941 mr_free(tmp);3096 paranoid_free(tmp); 2942 3097 2943 3098 if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) { … … 2946 3101 return (1); 2947 3102 } 2948 if ((i == bkpinfo->optimal_set_size / 256) && (totalread < 1.1 * totallength)) { 2949 for (i = 0L; i < bkpinfo->optimal_set_size / 256; i++) { 3103 if ((i == bkpinfo->optimal_set_size / 256) 3104 && (totalread < 1.1 * totallength)) { 3105 for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) { 2950 3106 blksize = fread(tempblock, 1, 256 * 1024, fin); 2951 3107 if (blksize > 0) { … … 2956 3112 } 2957 3113 } 2958 mr_free(tempblock);2959 3114 } else { 2960 i = 0 L;3115 i = 0; 2961 3116 } 2962 3117 paranoid_fclose(fout); 2963 if (i > 0 L) // length_of_file (curr_slice_fname_uncompressed)3118 if (i > 0) // length_of_file (curr_slice_fname_uncompressed) 2964 3119 { 2965 3120 if (!does_file_exist(curr_slice_fname_uncompressed)) { 2966 log_msg(2, "Warning - '%s' doesn't exist. How can I compress slice?", curr_slice_fname_uncompressed); 3121 log_msg(2, 3122 "Warning - '%s' doesn't exist. How can I compress slice?", 3123 curr_slice_fname_uncompressed); 2967 3124 } 2968 3125 if (should_I_compress_slices && bkpinfo->compression_level > 0) { … … 2984 3141 log_msg(2, "Failed to compress the slice"); 2985 3142 } 2986 if (bkpinfo->use_lzo && strcmp(curr_slice_fname_compressed, curr_slice_fname_uncompressed)) { 3143 if (bkpinfo->use_lzo 3144 && strcmp(curr_slice_fname_compressed, 3145 curr_slice_fname_uncompressed)) { 2987 3146 unlink(curr_slice_fname_uncompressed); 2988 3147 } … … 2990 3149 mr_asprintf(tmp, "Problem with slice # %ld", slice_num); 2991 3150 } else { 2992 mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK ", biggie_filename, biggie_file_number + 1, slice_num); 3151 mr_asprintf(tmp, "%s - Bigfile #%ld, slice #%ld compressed OK ", biggie_filename, biggie_file_number + 1, 3152 slice_num); 2993 3153 } 3154 #ifndef _XWIN 2994 3155 if (!g_text_mode) { 2995 3156 newtDrawRootText(0, g_noof_rows - 2, tmp); … … 2998 3159 log_msg(2, tmp); 2999 3160 } 3000 mr_free(tmp); 3161 #else 3162 log_msg(2, tmp); 3163 #endif 3164 paranoid_free(tmp); 3001 3165 3002 3166 mr_asprintf(file_to_archive, "%s", curr_slice_fname_compressed); … … 3014 3178 3015 3179 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 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); 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); 3018 3184 res = move_files_to_stream(file_to_archive, NULL); 3019 3185 } else { … … 3024 3190 retval += res; 3025 3191 if (res) { 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 } 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); 3030 3200 mr_free(suffix); 3031 3201 paranoid_fclose(fin); … … 3037 3207 } 3038 3208 log_msg(1, tmp); 3039 mr_free(tmp); 3040 3209 paranoid_free(tmp); 3210 3211 paranoid_free(checksum_line); 3041 3212 return (retval); 3042 3213 } … … 3117 3288 log_msg(2, tmp); 3118 3289 center_string(tmp, 80); 3290 #ifndef _XWIN 3119 3291 if (!g_text_mode) { 3120 3292 newtPushHelpLine(tmp); 3121 3293 } 3294 #endif 3122 3295 res = write_iso_and_go_on(TRUE); 3296 #ifndef _XWIN 3123 3297 if (!g_text_mode) { 3124 3298 newtPopHelpLine(); 3125 3299 } 3300 #endif 3126 3301 log_msg(2, "Returning from writing final ISO (res=%d)", res); 3127 3302 paranoid_free(tmp); … … 3152 3327 3153 3328 /*@ buffers ***************************************************** */ 3154 char *tmp = NULL; 3155 char *tmp1 = NULL; 3156 char *cdno_fname = NULL; 3157 char *lastcd_fname = NULL; 3158 char *isofile = NULL; 3329 char *tmp; 3330 char *cdno_fname; 3331 char *lastcd_fname; 3332 char *isofile; 3159 3333 char *mds = NULL; 3160 3334 … … 3167 3341 3168 3342 malloc_string(tmp); 3343 malloc_string(cdno_fname); 3344 malloc_string(lastcd_fname); 3345 malloc_string(isofile); 3169 3346 3170 3347 assert(bkpinfo != NULL); … … 3180 3357 /* label the ISO with its number */ 3181 3358 3182 mr_asprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);3359 sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir); 3183 3360 fout = fopen(cdno_fname, "w"); 3184 mr_free(cdno_fname);3185 3186 3361 fprintf(fout, "%d", g_current_media_number); 3187 3362 paranoid_fclose(fout); 3188 3363 3189 mr_asprintf(tmp1, "cp -f %s/autorun %s/", g_mondo_home, bkpinfo->scratchdir); 3190 if (run_program_and_log_output(tmp1, FALSE)) { 3364 sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home, 3365 bkpinfo->scratchdir); 3366 if (run_program_and_log_output(tmp, FALSE)) { 3191 3367 log_msg(2, "Warning - unable to copy autorun to scratchdir"); 3192 3368 } 3193 mr_free(tmp1);3194 3369 3195 3370 /* last CD or not? Label accordingly */ 3196 mr_asprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);3371 sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir); 3197 3372 if (last_cd) { 3198 3373 unlink(lastcd_fname); … … 3205 3380 paranoid_fclose(fout); 3206 3381 } 3207 mr_free(lastcd_fname);3208 3209 3382 if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) { 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, 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, 3213 3390 bkpinfo->netfs_remote_dir, bkpinfo->prefix, 3214 3391 g_current_media_number); … … 3225 3402 { 3226 3403 log_msg(3, "*Sigh* Mike, I hate your computer."); 3227 // if it can't be found then force pausing3228 3404 bkpinfo->manual_cd_tray = TRUE; 3229 } else { 3405 } // if it can't be found then force pausing 3406 else { 3230 3407 log_msg(3, "Great. Found Mike's CD-ROM drive."); 3231 3408 } … … 3233 3410 if (bkpinfo->verify_data && !res) { 3234 3411 mds = media_descriptor_string(g_backup_media_type); 3235 log_to_screen("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds); 3412 log_to_screen 3413 ("Please reboot from the 1st %s in Compare Mode, as a precaution.", mds); 3236 3414 mr_free(mds); 3237 3415 if (chdir("/")) { … … 3250 3428 } else { 3251 3429 mds = media_descriptor_string(bkpinfo->backup_media_type); 3252 mr_asprintf(tmp1, "Failed to create %s #%d. Retry?", mds, g_current_media_number);3430 sprintf(tmp, "Failed to create %s #%d. Retry?", mds, g_current_media_number); 3253 3431 mr_free(mds); 3254 res = ask_me_yes_or_no(tmp1); 3255 mr_free(tmp1); 3256 3432 res = ask_me_yes_or_no(tmp); 3257 3433 if (!res) { 3258 3434 if (ask_me_yes_or_no("Abort the backup?")) { … … 3267 3443 } 3268 3444 } 3269 mr_free(isofile);3270 3271 3445 g_current_media_number++; 3272 3446 wipe_archives(bkpinfo->scratchdir); 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); 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 } 3278 3454 3279 3455 if (last_cd) { … … 3285 3461 bkpinfo->verify_data = orig_vfy_flag_val; 3286 3462 paranoid_free(tmp); 3463 paranoid_free(cdno_fname); 3464 paranoid_free(lastcd_fname); 3465 paranoid_free(isofile); 3287 3466 return (0); 3288 3467 } … … 3353 3532 if (res) { 3354 3533 mds = media_descriptor_string(bkpinfo->backup_media_type); 3355 log_to_screen("Warnings/errors were reported while checking %s #%d", mds, g_current_media_number);3534 mr_asprintf(tmp, "Warnings/errors were reported while checking %s #%d", mds, g_current_media_number); 3356 3535 mr_free(mds); 3536 log_to_screen(tmp); 3537 mr_free(tmp); 3357 3538 3358 3539 } -
branches/3.0/mondo/src/common/libmondo-cli.c
r3188 r3192 97 97 for (i = 0; i < 128; i++) { 98 98 if (flag_set[i]) { 99 log_msg(3, "-%c %s", i, flag_val[i]); 99 mr_asprintf(tmp, "-%c %s", i, flag_val[i]); 100 log_msg(3, tmp); 101 mr_free(tmp); 100 102 } 101 103 } … … 148 150 char *tmp = NULL; 149 151 char *tmp1 = NULL; 150 char *tmp2 = NULL;151 152 char *psz = NULL; 152 153 char *p = NULL; … … 207 208 log_msg(1, "Using star instead of afio"); 208 209 } else { 209 fatal_error("Neither afio nor star is installed. Please install at least one."); 210 fatal_error 211 ("Neither afio nor star is installed. Please install at least one."); 210 212 } 211 213 } … … 217 219 } 218 220 if (!find_home_of_exe("star")) { 219 fatal_error("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 221 fatal_error 222 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 220 223 } 221 224 } … … 231 234 232 235 if (flag_set['I']) { 233 if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') {236 if (bkpinfo->include_paths[0] == '-') { 234 237 retval++; 235 238 log_to_screen("Please supply a sensible value with '-I'\n"); … … 265 268 } 266 269 } 267 mr_free(tmp1);270 paranoid_free(tmp1); 268 271 mr_make_devlist_from_pathlist(flag_val['I'], 'I'); 269 272 log_msg(4, "Finished with the -I option"); 270 273 } 271 274 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."); 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."); 274 279 } 275 280 … … 278 283 if (flag_set['I']) { 279 284 retval++; 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. :-)"); 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. :-)"); 281 287 } 282 288 bkpinfo->make_filelist = FALSE; 283 mr_asprintf(bkpinfo->include_paths, "%s", flag_val['J']);289 strcpy(bkpinfo->include_paths, flag_val['J']); 284 290 } 285 291 286 292 if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) { 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."); 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."); 292 302 } 293 303 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) { 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."); 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."); 299 312 } 300 313 if (flag_set['C']) { 301 314 bkpinfo->cdrw_speed = atoi(flag_val['C']); 302 315 if (bkpinfo->cdrw_speed < 1) { 303 fatal_error("You specified a silly speed for a CD-R[W] drive"); 316 fatal_error 317 ("You specified a silly speed for a CD-R[W] drive"); 304 318 } 305 319 if (!flag_set['L']) { 306 log_to_screen("You must use -L with -C. Therefore I am setting it for you."); 320 log_to_screen 321 ("You must use -L with -C. Therefore I am setting it for you."); 307 322 flag_set['L'] = 1; 308 323 flag_val['L'][0] = '\0'; … … 311 326 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 312 327 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 328 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] ); 313 329 if (flag_set['c']) { 314 330 bkpinfo->cdrw_speed = atoi(flag_val['c']); … … 320 336 321 337 if (bkpinfo->cdrw_speed < 1) { 322 fatal_error("You specified a silly speed for a CD-R[W] drive"); 338 fatal_error 339 ("You specified a silly speed for a CD-R[W] drive"); 323 340 } 324 341 } … … 328 345 log_it("Hmm! No tape drive specified. Let's see what we can do."); 329 346 if (find_tape_device_and_size(flag_val['d'], tmp)) { 330 fatal_error("Tape device not specified. I couldn't find it either."); 347 fatal_error 348 ("Tape device not specified. I couldn't find it either."); 331 349 } 332 350 flag_set['d'] = TRUE; 333 log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']); 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); 334 355 } 335 356 … … 337 358 { 338 359 if (! flag_set['d']) { 339 fatal_error("You need to specify a device file with -d for bootable USB device usage"); 360 fatal_error 361 ("You need to specify a device file with -d for bootable USB device usage"); 340 362 } 341 363 if ((!flag_set['s']) && (! bkpinfo->restore_data)) { … … 347 369 { 348 370 if (flag_set['m']) { 349 fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 371 fatal_error 372 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 350 373 } 351 374 if (!flag_set['d']) { … … 356 379 } 357 380 if (strchr(flag_val['d'], ',')) { 358 fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 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."); 359 383 } 360 384 if (! bkpinfo->restore_data) { 361 385 if (!find_home_of_exe("growisofs")) { 362 fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 386 fatal_error 387 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 363 388 } 364 389 if (!find_home_of_exe("dvd+rw-format")) { 365 fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 390 fatal_error 391 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 366 392 } 367 393 if (!flag_set['s']) { 368 394 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 369 395 strcat(flag_val['s'], "m"); 370 log_to_screen("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']); 396 log_to_screen 397 ("You did not specify a size (-s) for DVD. I'm guessing %s.", 398 flag_val['s']); 371 399 flag_set['s'] = 1; 372 400 } 373 401 } 402 /* 403 if (flag_set['Z']) { 404 bkpinfo->blank_dvd_first = TRUE; 405 } 406 */ 374 407 } 375 408 376 409 if (flag_set['t'] || flag_set['u']) { /* tape size */ 377 410 if (strchr(flag_val['d'], ',')) { 378 fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 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."); 379 413 } 380 414 if ((flag_set['O']) && (! bkpinfo->restore_data)) { 381 415 if (flag_set['s']) { 382 416 if (flag_set['t']) { 383 fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 417 fatal_error 418 ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 384 419 } 385 420 if (process_the_s_switch(flag_val['s'])) { … … 405 440 406 441 if (flag_set['n']) { 407 mr_free(bkpinfo->netfs_mount); 408 mr_asprintf(bkpinfo->netfs_mount, "%s", flag_val['n']); 442 strncpy(bkpinfo->netfs_mount, flag_val['n'], MAX_STR_LEN); 409 443 if (!flag_set['d']) { 410 mr_free(bkpinfo->netfs_remote_dir); 411 mr_asprintf(bkpinfo->netfs_remote_dir, "/"); 444 strncpy(bkpinfo->netfs_remote_dir, "/", MAX_STR_LEN); 412 445 } 413 446 /* test for protocol */ … … 440 473 /* Store the 2 values */ 441 474 /* using memmove instead of strcpy as per #584 */ 442 /* memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN); */ 443 bkpinfo->netfs_mount = p; 475 memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN); 444 476 445 477 /* test if we specified a user */ … … 447 479 if (p != NULL) { 448 480 /* User found. Store the 2 values */ 449 bkpinfo->netfs_user = bkpinfo->netfs_mount;450 481 p++; 451 482 /* new netfs mount */ 452 mr_asprintf(bkpinfo->netfs_mount, "%s", p); 453 /* now that user is computed, create the right value by removing end of string */ 483 strcpy(tmp,p); 454 484 p--; 455 485 *p = '\0'; 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 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); 461 495 if (strlen(bkpinfo->isodir) < 3) { 462 496 log_to_screen("Network share is not mounted. Trying to mount it for you.\n"); 463 497 if (bkpinfo->netfs_user) { 464 498 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 465 mr_asprintf(tmp1, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);499 sprintf(tmp, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount); 466 500 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) { 467 mr_asprintf(tmp1, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user);501 sprintf(tmp, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user); 468 502 } else if (strstr(bkpinfo->netfs_proto, "nfs")) { 469 mr_asprintf(tmp1, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);503 sprintf(tmp, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount); 470 504 } else { 471 505 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto); … … 474 508 } else { 475 509 if (strstr(bkpinfo->netfs_proto, "sshfs")) { 476 mr_asprintf(tmp1, "sshfs %s", bkpinfo->netfs_mount);510 sprintf(tmp, "sshfs %s", bkpinfo->netfs_mount); 477 511 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) { 478 mr_asprintf(tmp1, "mount -t cifs %s", bkpinfo->netfs_mount);512 sprintf(tmp, "mount -t cifs %s", bkpinfo->netfs_mount); 479 513 } else if (strstr(bkpinfo->netfs_proto, "nfs")) { 480 mr_asprintf(tmp1, "mount %s", bkpinfo->netfs_mount);514 sprintf(tmp, "mount %s", bkpinfo->netfs_mount); 481 515 } else { 482 516 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto); … … 484 518 } 485 519 } 486 i = system(tmp1); 487 mr_free(tmp1); 488 489 if (i) { 520 if (system(tmp)) { 490 521 log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount); 491 522 retval++; 492 523 } else { 493 524 if (bkpinfo->netfs_user) { 494 mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount); 525 sprintf(tmp, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, 526 bkpinfo->netfs_mount); 495 527 } else { 496 mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);528 sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount); 497 529 } 498 strncpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp), MAX_STR_LEN / 4); 530 strncpy(bkpinfo->isodir, 531 call_program_and_get_last_line_of_output(tmp), 532 MAX_STR_LEN / 4); 499 533 if (strlen(bkpinfo->isodir) < 3) { 500 534 retval++; … … 590 624 } 591 625 } 592 mr_free(tmp1);626 paranoid_free(tmp1); 593 627 594 628 mr_make_devlist_from_pathlist(flag_val['E'], 'E'); … … 634 668 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 635 669 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) { 636 fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 670 fatal_error 671 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 637 672 } 638 673 bkpinfo->internal_tape_block_size = itbs; … … 643 678 // bkpinfo->differential = atoi (flag_val['D']); 644 679 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) { 645 fatal_error("The D option should be between 1 and 9 inclusive"); 680 fatal_error 681 ("The D option should be between 1 and 9 inclusive"); 646 682 } 647 683 } … … 666 702 && !does_file_exist(bkpinfo->kernel_path)) { 667 703 retval++; 668 log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path); 704 sprintf(tmp, 705 "You specified kernel '%s', which does not exist\n", 706 bkpinfo->kernel_path); 707 log_to_screen(tmp); 669 708 } 670 709 } … … 684 723 } 685 724 } else if (flag_set['n']) { 686 mr_free(bkpinfo->netfs_remote_dir); 687 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']); 725 strncpy(bkpinfo->netfs_remote_dir, flag_val['d'], MAX_STR_LEN); 688 726 } else { /* backup device (if tape/CD-R/CD-RW) */ 689 727 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4); … … 694 732 mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir); 695 733 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) { 696 mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);734 sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1); 697 735 } else { 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);736 sprintf(tmp, "echo hi > %s", tmp1); 737 } 738 if (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); 706 744 } 707 745 unlink(tmp1); 708 mr_free(tmp1); 709 } 710 711 if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 746 paranoid_free(tmp1); 747 } 748 749 if (!flag_set['d'] 750 && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 712 751 if (g_kernel_version >= 2.6) { 713 752 if (popup_and_get_string … … 730 769 retval++; 731 770 log_to_screen("Please specify the backup device/directory.\n"); 732 fatal_error("You didn't use -d to specify the backup device/directory."); 771 fatal_error 772 ("You didn't use -d to specify the backup device/directory."); 733 773 } 734 774 … … 741 781 if (flag_set['S']) { 742 782 setup_scratchdir(flag_val['S']); 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); 783 sprintf(tmp, "touch %s/.foo.dat", bkpinfo->scratchdir); 784 if (run_program_and_log_output(tmp, 1)) { 785 retval++; 747 786 log_to_screen("Please specify a scratchdir which I can write to. :)"); 748 787 fatal_error("I cannot write to the scratchdir you specified."); 749 788 } 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); 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++; 756 792 log_to_screen("Please don't specify a SAMBA or VFAT or NFS scratchdir."); 757 793 fatal_error("I cannot write to the scratchdir you specified."); 758 794 } 759 mr_free(tmp1);760 795 } 761 796 762 797 if (flag_set['T']) { 763 798 setup_tmpdir(flag_val['T']); 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) { 799 sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir); 800 if (run_program_and_log_output(tmp, 1)) { 769 801 retval++; 770 802 log_to_screen("Please specify a tempdir which I can write to. :)"); 771 803 fatal_error("I cannot write to the tempdir you specified."); 772 804 } 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) { 805 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir); 806 if (run_program_and_log_output(tmp, 1)) { 778 807 retval++; 779 808 log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir."); … … 804 833 # endif 805 834 #endif 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"); 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"); 809 842 } 810 843 #undef BOOT_LOADER_CHARS … … 812 845 813 846 if (flag_set['f']) { 814 strncpy(bkpinfo->boot_device, resolve_softlinks_to_get_to_actual_device_file(flag_val['f']),MAX_STR_LEN / 4); 847 strncpy(bkpinfo->boot_device, 848 resolve_softlinks_to_get_to_actual_device_file(flag_val 849 ['f']), 850 MAX_STR_LEN / 4); 815 851 } 816 852 … … 830 866 if (run_program_and_log_output("which lzop", 2)) { 831 867 retval++; 832 log_to_screen("Please install LZOP. You can't use '-L' until you do.\n"); 868 log_to_screen 869 ("Please install LZOP. You can't use '-L' until you do.\n"); 833 870 } 834 871 } … … 843 880 if (run_program_and_log_output("which gzip", 2)) { 844 881 retval++; 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"); 882 log_to_screen 883 ("Please install gzip. You can't use '-G' until you do.\n"); 854 884 } 855 885 } … … 867 897 if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) { 868 898 bkpinfo->make_cd_use_lilo = TRUE; 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."); 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."); 871 903 } 872 904 if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) { 873 905 bkpinfo->make_cd_use_lilo = TRUE; 874 906 #ifdef __IA32__ 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."); 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."); 877 911 #endif 878 912 #ifdef __IA64__ 879 log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 913 log_to_screen 914 ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 880 915 log_to_screen("environment correctly. Please install it."); 881 916 fatal_error("Aborting"); … … 897 932 898 933 if ((! bkpinfo->restore_data) && (flag_set['Z'])) { 899 fatal_error("The -Z switch is only valid in restore mode"); 934 fatal_error 935 ("The -Z switch is only valid in restore mode"); 900 936 } 901 937 … … 937 973 * @return The number of problems with the command line (0 for success). 938 974 */ 939 int retrieve_switches_from_command_line(int argc, char *argv[], char flag_val[128][MAX_STR_LEN], bool flag_set[128]) 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]) 940 979 { 941 980 /*@ ints ** */ 942 981 int opt = 0; 982 char *tmp = NULL; 943 983 int i = 0; 944 984 int len; … … 954 994 flag_set[i] = FALSE; 955 995 } 956 while ((opt = getopt(argc, argv, MONDO_OPTIONS)) != -1) { 996 while ((opt = 997 getopt(argc, argv, MONDO_OPTIONS)) 998 != -1) { 957 999 if (opt == '?') { 958 1000 bad_switches = TRUE; 1001 /*log_it("Invalid option: %c\n",optopt); */ 959 1002 } else { 960 1003 if (flag_set[opt]) { 961 1004 bad_switches = TRUE; 962 log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]); 1005 mr_asprintf(tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]); 1006 log_to_screen(tmp); 1007 paranoid_free(tmp); 963 1008 } else { 964 1009 flag_set[opt] = TRUE; … … 974 1019 if (strchr(flag_val[opt], '/') 975 1020 && flag_val[opt][0] != '/') { 976 log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 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); 977 1024 bad_switches = TRUE; 978 1025 } … … 985 1032 for (i = optind; i < argc; i++) { 986 1033 bad_switches = TRUE; 987 log_to_screen("Invalid arg -- %s\n", argv[i]); 1034 mr_asprintf(tmp, "Invalid arg -- %s\n", argv[i]); 1035 log_to_screen(tmp); 1036 paranoid_free(tmp); 988 1037 } 989 1038 return (bad_switches); … … 1048 1097 mr_strcat(tmp, " signal received from OS"); 1049 1098 log_to_screen(tmp); 1050 mr_free(tmp);1099 paranoid_free(tmp); 1051 1100 1052 1101 log_to_screen(tmp2); 1053 mr_free(tmp2);1102 paranoid_free(tmp2); 1054 1103 if (sig == SIGABRT) { 1055 1104 sleep(10); … … 1059 1108 free_MR_global_filenames(); 1060 1109 1061 fatal_error("MondoRescue is terminating in response to a signal from the OS"); 1110 fatal_error 1111 ("MondoRescue is terminating in response to a signal from the OS"); 1062 1112 finish(254); // just in case 1063 1113 } … … 1072 1122 void set_signals(int on) 1073 1123 { 1074 int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1124 int signals[] = 1125 { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1075 1126 int i; 1076 1127 -
branches/3.0/mondo/src/common/libmondo-devices-EXT.h
r3188 r3192 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 onst char *mountpoint);18 extern int mount_CDROM_here(char *device, 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 *incoming); 59 extern char *resolve_softlinks_to_get_to_actual_device_file(char 60 *incoming); 60 61 61 62 extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(); -
branches/3.0/mondo/src/common/libmondo-devices.c
r3188 r3192 21 21 #include "libmondo-stream-EXT.h" 22 22 23 extern void mr_strip_spaces(char *);24 25 23 #include <sys/types.h> 26 24 #ifdef __FreeBSD__ … … 129 127 { 130 128 char *tmp = NULL; 129 char *comment; 131 130 bool is_this_a_ramdisk = FALSE; 132 131 132 malloc_string(comment); 133 133 mr_asprintf(tmp, "%s", where_is_root_mounted()); 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); 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); 136 139 137 140 #ifdef __FreeBSD__ … … 153 156 if (is_this_a_ramdisk) { 154 157 if (!does_file_exist("/THIS-IS-A-RAMDISK")) { 155 log_to_screen("Using /dev/root is stupid of you but I'll forgive you."); 158 log_to_screen 159 ("Using /dev/root is stupid of you but I'll forgive you."); 156 160 is_this_a_ramdisk = FALSE; 157 161 } … … 160 164 is_this_a_ramdisk = TRUE; 161 165 } 162 163 log_msg(1, "Is this a ramdisk? result = % s", (is_this_a_ramdisk) ? "TRUE" : "FALSE");166 paranoid_free(comment); 167 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); 164 168 return (is_this_a_ramdisk); 165 169 } … … 225 229 int eject_device(char *dev) 226 230 { 227 char *command = NULL;231 char *command; 228 232 int res1 = 0, res2 = 0; 229 233 230 if (dev == NULL) { 231 return (1); 232 } 234 malloc_string(command); 233 235 234 236 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 235 237 && g_backup_media_type != udev) { 236 mr_asprintf(command, "mt -f %s offline", dev);238 sprintf(command, "mt -f %s offline", dev); 237 239 res1 = run_program_and_log_output(command, 1); 238 mr_free(command);239 240 } else { 240 241 res1 = 0; … … 243 244 #ifdef __FreeBSD__ 244 245 if (strstr(dev, "acd")) { 245 mr_asprintf(command, "cdcontrol -f %s eject", dev);246 sprintf(command, "cdcontrol -f %s eject", dev); 246 247 } else { 247 mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev); 248 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 249 dev); 248 250 } 249 251 #else 250 mr_asprintf(command, "eject %s", dev);252 sprintf(command, "eject %s", dev); 251 253 #endif 252 254 253 255 log_msg(3, "Ejecting %s", dev); 254 256 res2 = run_program_and_log_output(command, 1); 255 mr_free(command);257 paranoid_free(command); 256 258 if (res1 && res2) { 257 259 return (1); … … 268 270 int inject_device(char *dev) 269 271 { 270 char *command = NULL;272 char *command; 271 273 int i; 272 274 273 if (dev == NULL) { 274 return (1); 275 } 275 malloc_string(command); 276 276 277 277 278 #ifdef __FreeBSD__ 278 279 if (strstr(dev, "acd")) { 279 mr_asprintf(command, "cdcontrol -f %s close", dev);280 sprintf(command, "cdcontrol -f %s close", dev); 280 281 } else { 281 mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev); 282 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", 283 dev); 282 284 } 283 285 #else 284 mr_asprintf(command, "eject -t %s", dev);286 sprintf(command, "eject -t %s", dev); 285 287 #endif 286 288 i = run_program_and_log_output(command, FALSE); 287 mr_free(command);289 paranoid_free(command); 288 290 return (i); 289 291 } … … 299 301 300 302 /*@ buffers *********************************************************** */ 301 char *tmp = NULL;303 char *tmp; 302 304 bool ret; 303 305 306 malloc_string(tmp); 304 307 assert_string_is_neither_NULL_nor_zerolength(device); 305 308 306 mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);309 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device); 307 310 308 311 if (system(tmp)) { … … 311 314 ret = TRUE; 312 315 } 313 mr_free(tmp);316 paranoid_free(tmp); 314 317 return (ret); 315 318 } … … 342 345 { 343 346 /*@ buffers **************************************************** */ 344 char *program = NULL;345 char *incoming = NULL;347 char *program; 348 char *incoming; 346 349 char *searchstr = NULL; 350 char *tmp; 351 char *p; 347 352 348 353 /*@ ints ******************************************************* */ … … 351 356 /*@ pointers *************************************************** */ 352 357 FILE *fin; 358 353 359 354 360 /*@ end vars *************************************************** */ … … 356 362 assert(partno >= 0 && partno < 999); 357 363 364 malloc_string(program); 365 malloc_string(incoming); 358 366 malloc_string(searchstr); 367 malloc_string(tmp); 359 368 360 369 #ifdef __FreeBSD__ 361 370 // We assume here that this is running from mondorestore. (It is.) 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); 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); 369 379 fin = popen(program, "r"); 370 380 if (!fin) { 371 381 log_it("program=%s", program); 372 382 log_OS_error("Cannot popen-in program"); 373 mr_free(program);374 383 return (0); 375 384 } 376 mr_free(program);377 378 385 (void) build_partition_name(searchstr, drive, partno); 379 386 strcat(searchstr, " "); 380 for (res = 0 , mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {387 for (res = 0; !res && (p = fgets(incoming, MAX_STR_LEN - 1, fin));) { 381 388 if (strstr(incoming, searchstr)) { 382 389 res = 1; 383 390 } 384 mr_free(incoming); 385 } 386 mr_free(incoming); 387 391 } 388 392 if (pclose(fin)) { 389 393 log_OS_error("Cannot pclose fin"); 390 394 } 395 paranoid_free(program); 396 paranoid_free(incoming); 391 397 paranoid_free(searchstr); 398 paranoid_free(tmp); 392 399 return (res); 393 400 } … … 406 413 { 407 414 /*@ buffers **************************************************** */ 408 char *command = NULL;415 char *command; 409 416 410 417 /*@ end vars *************************************************** */ … … 414 421 assert_string_is_neither_NULL_nor_zerolength(str); 415 422 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); 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); 418 427 i = system(command); 419 mr_free(command);428 paranoid_free(command); 420 429 if (i) { 421 430 return (FALSE); … … 435 444 { 436 445 /*@ buffers **************************************************** */ 437 char *command = NULL;446 char *command; 438 447 /*@ end vars *************************************************** */ 439 448 int i; 440 449 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); 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); 442 454 i = system(command); 443 mr_free(command);455 paranoid_free(command); 444 456 if (i) { 445 457 return (FALSE); … … 454 466 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has 455 467 * 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. 456 469 * @param mountpoint Where to mount the CD-ROM. 457 470 * @return 0 for success, nonzero for failure. 458 471 * @see mount_CDROM_here 459 472 */ 460 int find_and_mount_actual_cd(char *mountpoint) {461 473 int find_and_mount_actual_cd(char *mountpoint) 474 { 462 475 /*@ buffers ***************************************************** */ 463 476 464 477 /*@ int's ****************************************************** */ 465 478 int res; 466 char *dev = NULL;479 char *dev; 467 480 468 481 /*@ end vars **************************************************** */ … … 519 532 { 520 533 /*@ buffers ************************ */ 534 char *comment; 521 535 char *tmp = NULL; 522 536 char *cdr_exe = NULL; 523 char *command = NULL; 524 537 char *command; 538 539 malloc_string(comment); 540 malloc_string(command); 525 541 if (g_cdrw_drive_is_here[0]) { 526 542 strcpy(cdrw_device, g_cdrw_drive_is_here); 527 543 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 544 paranoid_free(comment); 545 paranoid_free(command); 528 546 return (0); 529 547 } 530 548 if (g_backup_media_type == dvd) { 531 log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 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); 532 553 return (1); 533 554 } … … 539 560 } 540 561 if (find_home_of_exe(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); 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); 542 565 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 543 mr_free(command);544 566 } 545 567 if ((tmp == NULL) || (strlen(tmp) < 2)) { 568 paranoid_free(comment); 546 569 mr_free(tmp); 547 570 mr_free(cdr_exe); 571 paranoid_free(command); 548 572 return 1; 549 573 } else { 550 574 strcpy(cdrw_device, tmp); 551 log_it("Found CDRW device - %s", cdrw_device); 575 sprintf(comment, "Found CDRW device - %s", cdrw_device); 576 log_it(comment); 552 577 strcpy(g_cdrw_drive_is_here, cdrw_device); 578 paranoid_free(comment); 553 579 mr_free(tmp); 554 580 mr_free(cdr_exe); 581 paranoid_free(command); 555 582 return (0); 556 583 } 557 584 } 585 586 558 587 559 588 … … 580 609 581 610 /*@ buffers ***************************************************** */ 582 char *tmp = NULL;611 char *tmp; 583 612 char *tmp1 = NULL; 584 613 char *cdr_exe = NULL; 585 614 char *phrase_one; 586 char *phrase_two = NULL; 587 char *command = NULL; 588 #ifndef __FreeBSD__ 589 char *dvd_last_resort = NULL; 590 #endif 591 char *mountpoint = NULL; 615 char *phrase_two; 616 char *command; 617 char *dvd_last_resort; 618 char *mountpoint; 592 619 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 593 620 … … 595 622 malloc_string(tmp); 596 623 malloc_string(phrase_one); 624 malloc_string(phrase_two); 625 malloc_string(command); 626 malloc_string(dvd_last_resort); 597 627 malloc_string(mountpoint); 598 628 599 629 output[0] = '\0'; 600 630 phrase_one[0] = '\0'; 631 phrase_two[0] = '\0'; 632 dvd_last_resort[0] = '\0'; 601 633 602 634 /*@ end vars **************************************************** */ … … 610 642 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 611 643 strcpy(output, the_last_place_i_found_it); 612 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output); 644 log_msg(3, 645 "find_cdrom_device() --- returning last found location - '%s'", 646 output); 613 647 retval = 0; 614 648 goto end_of_find_cdrom_device; … … 637 671 } 638 672 639 mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);673 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 640 674 fin = popen(command, "r"); 641 675 if (!fin) { … … 643 677 log_OS_error("Cannot popen command"); 644 678 mr_free(cdr_exe); 645 mr_free(command);646 679 return (1); 647 680 } 648 mr_free(command);649 650 681 for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL); 651 682 tmp1 = fgets(tmp, MAX_STR_LEN, fin)) { … … 665 696 } 666 697 *q = '\0'; 667 mr_asprintf(phrase_two, "%s", p);698 strcpy(phrase_two, p); 668 699 } 669 700 } … … 674 705 675 706 #ifndef __FreeBSD__ 676 if ( !phrase_two ||strlen(phrase_two) == 0) {707 if (strlen(phrase_two) == 0) { 677 708 log_msg(4, "Not running phase two. String is empty."); 678 709 } else { 679 mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);710 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 680 711 fin = popen(command, "r"); 681 mr_free(command);682 683 712 if (!fin) { 684 713 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); … … 692 721 *p = '\0'; 693 722 if (strstr(tmp, "DVD")) { 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); 723 sprintf(dvd_last_resort, "/dev/%s", tmp); 724 log_msg(4, 725 "Ignoring '%s' because it's a DVD drive", 726 tmp); 697 727 } else { 698 728 sprintf(output, "/dev/%s", tmp); … … 745 775 #else 746 776 if (!found_it && strlen(dvd_last_resort) > 0) { 747 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 777 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 778 dvd_last_resort); 748 779 strcpy(output, dvd_last_resort); 749 780 found_it = TRUE; 750 781 } 751 782 if (found_it) { 752 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1); 783 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 784 strrchr(output, '/') + 1); 753 785 if (system(tmp) == 0) { 754 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); 786 log_msg(4, 787 "%s is not right. It's being SCSI-emulated. Continuing.", 788 output); 755 789 found_it = FALSE; 756 790 output[0] = '\0'; … … 818 852 found_it = FALSE; 819 853 } else { 820 mr_asprintf(command, "umount %s", output);854 sprintf(command, "umount %s", output); 821 855 paranoid_system(command); 822 mr_free(command);823 824 856 log_msg(4, "I'm confident the Mondo CD is in %s", output); 825 857 } … … 840 872 } 841 873 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 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); 844 877 log_msg(1, "command=%s", command); 845 878 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command)); 846 mr_free(command);847 848 879 if (strlen(tmp1) > 0) { 849 880 strcpy(output, tmp1); … … 857 888 858 889 end_of_find_cdrom_device: 890 paranoid_free(tmp); 859 891 mr_free(cdr_exe); 860 mr_free(phrase_two);861 mr_free(dvd_last_resort);862 863 paranoid_free(tmp);864 892 paranoid_free(phrase_one); 893 paranoid_free(phrase_two); 894 paranoid_free(command); 895 paranoid_free(dvd_last_resort); 865 896 paranoid_free(mountpoint); 866 897 return (retval); … … 868 899 869 900 901 902 903 870 904 int find_dvd_device(char *output, bool try_to_mount) 871 905 { 906 char *command; 872 907 char *tmp; 873 908 int retval = 0, devno = -1; 909 910 malloc_string(command); 911 malloc_string(tmp); 874 912 875 913 if (g_dvd_drive_is_here[0]) { … … 879 917 } 880 918 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")); 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")); 883 920 log_msg(5, "tmp = '%s'", tmp); 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 }921 if (!tmp[0]) 922 sprintf(tmp, "%s", call_program_and_get_last_line_of_output 923 ("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1") 924 ); 888 925 if (tmp[0]) { 889 926 devno = atoi(tmp) - 1; 890 927 } 891 mr_free(tmp);892 893 928 if (devno >= 0) { 894 929 retval = 0; … … 901 936 } 902 937 938 if (try_to_mount) { 939 log_msg(1, "Ignoring the fact that try_to_mount==TRUE"); 940 } 903 941 return (retval); 904 942 } … … 1015 1053 { 1016 1054 char *good_formats = NULL; 1017 char *command = NULL;1018 char *format_sz = NULL;1055 char *command; 1056 char *format_sz; 1019 1057 char *p; 1020 1058 … … 1022 1060 int retval; 1023 1061 malloc_string(good_formats); 1062 malloc_string(command); 1063 malloc_string(format_sz); 1024 1064 1025 1065 assert_string_is_neither_NULL_nor_zerolength(format); 1026 1066 1027 mr_asprintf(format_sz, "%s ", format);1067 sprintf(format_sz, "%s ", format); 1028 1068 1029 1069 #ifdef __FreeBSD__ 1030 mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1070 sprintf(command, 1071 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1031 1072 #else 1032 mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1073 sprintf(command, 1074 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1033 1075 #endif 1034 1076 1035 1077 pin = popen(command, "r"); 1036 mr_free(command);1037 1038 1078 if (!pin) { 1039 1079 log_OS_error("Unable to read good formats"); … … 1054 1094 } 1055 1095 paranoid_free(good_formats); 1056 mr_free(format_sz);1057 1096 paranoid_free(command); 1097 paranoid_free(format_sz); 1058 1098 return (retval); 1059 1099 } … … 1074 1114 1075 1115 /*@ buffers ***************************************************** */ 1076 char *incoming = NULL;1116 char *incoming; 1077 1117 char *device_with_tab = NULL; 1078 1118 char *device_with_space = NULL; … … 1088 1128 /*@ end vars **************************************************** */ 1089 1129 1090 if (device_raw == NULL) { 1091 return(FALSE); 1092 } 1093 1130 malloc_string(incoming); 1131 assert(device_raw != NULL); 1132 // assert_string_is_neither_NULL_nor_zerolength(device_raw); 1094 1133 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) { 1095 1134 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", … … 1114 1153 return(FALSE); 1115 1154 } 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)) { 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 { 1119 1160 paranoid_pclose(fin); 1120 mr_free(incoming);1161 paranoid_free(incoming); 1121 1162 return(TRUE); 1122 1163 } 1123 mr_free(incoming); 1124 } 1125 mr_free(incoming); 1164 } 1126 1165 mr_free(device_with_tab); 1127 1166 paranoid_pclose(fin); … … 1133 1172 } 1134 1173 mr_free(tmp); 1174 paranoid_free(incoming); 1135 1175 return(retval); 1136 1176 } … … 1149 1189 char command[MAX_STR_LEN]; 1150 1190 int vndev = 2; 1151 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) { 1191 if (atoi 1192 (call_program_and_get_last_line_of_output 1193 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1152 1194 do { 1153 1195 sprintf(mddevice, "vn%ic", vndev++); … … 1181 1223 int kick_vn(char *dname) 1182 1224 { 1183 char *command = NULL; 1184 int res = 0; 1225 char command[MAX_STR_LEN]; 1185 1226 1186 1227 if (strncmp(dname, "/dev/", 5) == 0) { … … 1188 1229 } 1189 1230 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); 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); 1192 1236 } else { 1193 mr_asprintf(command, "mdconfig -d -u %s", dname); 1194 } 1195 res = system(command); 1196 mr_free(command); 1197 return(res); 1237 sprintf(command, "mdconfig -d -u %s", dname); 1238 return system(command); 1239 } 1240 /*NOTREACHED*/ return 255; 1198 1241 } 1199 1242 #endif … … 1209 1252 { 1210 1253 /*@ buffer ****************************************************** */ 1211 char *command = NULL;1254 char *command; 1212 1255 int retval; 1213 1256 1257 malloc_string(command); 1214 1258 assert_string_is_neither_NULL_nor_zerolength(device); 1215 1259 assert_string_is_neither_NULL_nor_zerolength(mountpoint); … … 1219 1263 return(1); 1220 1264 } 1221 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint); 1265 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, 1266 mountpoint); 1222 1267 1223 1268 #ifdef __FreeBSD__ 1224 mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1269 sprintf(command, "mount_vfat %s %s 2>> %s", 1270 device, mountpoint, MONDO_LOGFILE); 1225 1271 1226 1272 #else 1227 mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1273 sprintf(command, "mount %s -t vfat %s 2>> %s", 1274 device, mountpoint, MONDO_LOGFILE); 1228 1275 #endif 1229 1276 … … 1231 1278 retval = system(command); 1232 1279 log_msg(1, "system(%s) returned %d", command, retval); 1233 mr_free(command); 1234 1280 1281 paranoid_free(command); 1235 1282 return (retval); 1236 1283 } … … 1242 1289 * @return 0 for success, nonzero for failure. 1243 1290 */ 1244 int mount_CDROM_here(char *device, c onst char *mountpoint)1291 int mount_CDROM_here(char *device, char *mountpoint) 1245 1292 { 1246 1293 /*@ buffer ****************************************************** */ … … 1280 1327 1281 1328 } 1282 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint); 1329 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 1330 mountpoint); 1283 1331 /*@ end vars *************************************************** */ 1284 1332 … … 1297 1345 retval = system(command); 1298 1346 log_msg(1, "system(%s) returned %d", command, retval); 1299 mr_free(command);1347 paranoid_free(command); 1300 1348 1301 1349 return (retval); … … 1314 1362 int mount_media() 1315 1363 { 1316 char *mount_cmd = NULL;1364 char *mount_cmd; 1317 1365 char *mountdir = NULL; 1318 1366 int i, res; 1319 1367 #ifdef __FreeBSD__ 1320 char mdd[32]; 1321 char *mddev = mdd; 1322 #endif 1323 1324 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 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) { 1325 1377 log_msg(8, "Tape/udev. Therefore, no need to mount a media."); 1378 paranoid_free(mount_cmd); 1326 1379 return 0; 1327 1380 } … … 1329 1382 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 1330 1383 log_msg(2, "mount_media() - media already mounted. Fair enough."); 1384 paranoid_free(mount_cmd); 1331 1385 return (0); 1332 1386 } … … 1335 1389 log_msg(2, "Mounting for Network thingy"); 1336 1390 log_msg(2, "isodir = %s", bkpinfo->isodir); 1337 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) { 1391 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 1392 && am_I_in_disaster_recovery_mode()) { 1338 1393 strcpy(bkpinfo->isodir, "/tmp/isodir"); 1339 1394 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 1340 1395 } 1341 1396 #ifdef __FreeBSD__ 1342 mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,1397 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 1343 1398 bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number); 1344 1399 mddev = make_vn(mount_cmd); 1345 mr_free(mount_cmd); 1346 1347 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1400 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1348 1401 #else 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); 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); 1350 1405 #endif 1351 1406 … … 1357 1412 } 1358 1413 #ifdef __FreeBSD__ 1359 mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number); 1414 sprintf(mount_cmd, "%s/%s-%d.iso", mountdir, 1415 bkpinfo->prefix, g_current_media_number); 1360 1416 mddev = make_vn(mount_cmd); 1361 mr_free(mount_cmd); 1362 1363 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1417 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1364 1418 #else 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); 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); 1366 1421 #endif 1367 1422 mr_free(mountdir); 1368 1423 } else if (bkpinfo->backup_media_type == usb) { 1369 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);1424 sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM); 1370 1425 } else if (strstr(bkpinfo->media_device, "/dev/")) { 1371 1426 #ifdef __FreeBSD__ 1372 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1427 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1428 MNT_CDROM); 1373 1429 #else 1374 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1430 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1431 bkpinfo->media_device, MNT_CDROM); 1375 1432 #endif 1376 1433 } else { … … 1384 1441 1385 1442 #ifdef __FreeBSD__ 1386 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1443 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1444 MNT_CDROM); 1387 1445 #else 1388 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1446 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1447 bkpinfo->media_device, MNT_CDROM); 1389 1448 #endif 1390 1449 } … … 1398 1457 log_msg(2, "Failed to mount device."); 1399 1458 sleep(5); 1400 sync(); 1401 } 1402 } 1403 mr_free(mount_cmd); 1459 run_program_and_log_output("sync", FALSE); 1460 } 1461 } 1404 1462 1405 1463 if (res) { … … 1408 1466 log_msg(2, "Mounted media drive OK"); 1409 1467 } 1468 paranoid_free(mount_cmd); 1410 1469 return (res); 1411 1470 } … … 1437 1496 1438 1497 /*@ buffers ********************************************************* */ 1439 char *tmp = NULL;1498 char *tmp; 1440 1499 char *mds = NULL; 1441 char *request = NULL;1500 char *request; 1442 1501 1443 1502 assert(bkpinfo != NULL); … … 1451 1510 return; 1452 1511 } 1453 mr_asprintf(tmp, "mkdir -p " MNT_CDROM); 1512 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1513 || bkpinfo->backup_media_type == netfs) { 1514 g_ISO_restore_mode = TRUE; 1515 } 1516 malloc_string(tmp); 1517 malloc_string(request); 1518 sprintf(tmp, "mkdir -p " MNT_CDROM); 1454 1519 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) {1458 g_ISO_restore_mode = TRUE;1459 }1460 1520 if ((res = what_number_cd_is_this()) != cd_number_i_want) { 1461 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want); 1521 log_msg(3, "Currently, we hold %d but we want %d", res, 1522 cd_number_i_want); 1462 1523 1463 1524 /* Now we need to umount the current media to have the next mounted after */ … … 1468 1529 1469 1530 mds = media_descriptor_string(bkpinfo->backup_media_type); 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);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); 1472 1533 mr_free(mds); 1473 1534 log_msg(3, tmp); 1474 1535 while (what_number_cd_is_this() != cd_number_i_want) { 1475 sync();1536 paranoid_system("sync"); 1476 1537 if (is_this_device_mounted(MNT_CDROM)) { 1477 1538 res = … … 1495 1556 inject_device(bkpinfo->media_device); 1496 1557 } 1497 sync(); 1498 } 1499 mr_free(request); 1500 1558 paranoid_system("sync"); 1559 } 1501 1560 log_msg(1, "Thankyou. Proceeding..."); 1502 1561 g_current_media_number = cd_number_i_want; 1503 1562 } 1563 paranoid_free(tmp); 1564 paranoid_free(request); 1504 1565 } 1505 1566 … … 1615 1676 log_msg(5, "Running: %s", command); 1616 1677 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1617 mr_free(command);1678 paranoid_free(command); 1618 1679 1619 1680 mount_cnt = atoi(mounted_file_system); 1620 1681 log_msg (5, "mount_cnt: %d", mount_cnt); 1621 mr_free(mounted_file_system);1682 paranoid_free(mounted_file_system); 1622 1683 1623 1684 for (i=mount_cnt; i > 0; i--) { … … 1625 1686 log_msg(5, "Running: %s", command); 1626 1687 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1627 mr_free(command);1688 paranoid_free(command); 1628 1689 1629 1690 log_msg (5, "mounted_file_system: %s", mounted_file_system); 1630 1691 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) { 1631 1692 log_msg (4, "Could not get the list of mounted file systems"); 1632 mr_free(mounted_file_system);1693 paranoid_free(mounted_file_system); 1633 1694 mr_free(token); 1634 1695 return (1); … … 1658 1719 mr_free(mounted_file_system); 1659 1720 } 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 ********/ 1660 1728 return (0); 1661 1729 } … … 1705 1773 log_msg(5, " Executing: %s", command); 1706 1774 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1707 mr_free(command);1775 paranoid_free(command); 1708 1776 1709 1777 log_msg(5, " Return value: %s", tmp); 1710 1778 c = atoi(tmp); 1711 mr_free(tmp);1779 paranoid_free(tmp); 1712 1780 1713 1781 if (!c) { … … 1731 1799 log_msg(5, "Executing: %s", command); 1732 1800 mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command)); 1733 mr_free(command);1801 paranoid_free(command); 1734 1802 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 1735 1803 if (!strlen(partition_list)) { … … 1794 1862 log_msg(4, "Processing partition: %s", partitions[i]); 1795 1863 /* See if it's swap. If it is, ignore it. */ 1796 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]); 1864 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", 1865 ndsf, partitions[i]); 1797 1866 log_msg(5, " Running: %s", command); 1798 1867 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1799 mr_free(command); 1800 1868 paranoid_free(command); 1801 1869 log_msg(5, " Return value: %s", tmp); 1802 1870 c = strlen(tmp); 1803 mr_free(tmp); 1804 1871 paranoid_free(tmp); 1805 1872 if (c) { 1806 1873 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); 1807 1874 continue; 1808 1875 } 1809 1810 1876 /* It's not swap. See if we can find the mount point from the mount command. */ 1811 1877 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 1812 1878 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1813 mr_free(command); 1814 1879 paranoid_free(command); 1815 1880 if (strlen(tmp)) { 1816 1881 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 1817 1882 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 1818 1883 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 1819 mr_free(tmp);1884 paranoid_free(tmp); 1820 1885 return (1); 1821 1886 } 1822 1887 DSFptr->check = 1; 1823 mr_free(tmp);1888 paranoid_free(tmp); 1824 1889 continue; 1825 1890 } 1826 mr_free(tmp); 1827 1891 paranoid_free(tmp); 1828 1892 /* It's not swap and it's not mounted. See if it's LVM */ 1829 1893 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); 1830 1831 1894 /* Check for LVM */ 1832 1895 mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]); 1833 1896 log_msg(5, " Running: %s", command); 1834 1897 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1835 mr_free(command); 1836 1898 paranoid_free(command); 1837 1899 if (strlen(tmp)) { 1838 1900 log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]); … … 1841 1903 log_msg(5, " Running: %s", command); 1842 1904 strcpy(VG, call_program_and_get_last_line_of_output(command)); 1843 mr_free(command); 1844 1905 paranoid_free(command); 1845 1906 log_msg(4, " Volume Group: %s", VG); 1846 1907 if (strlen(VG)) { … … 1850 1911 log_msg(5, " Running: %s", command); 1851 1912 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1852 mr_free(command); 1853 1913 paranoid_free(command); 1854 1914 log_msg(4, " VG %s mount_list: %s", VG, mount_list); 1855 1915 lastpos = 0; … … 1858 1918 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 1859 1919 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 1860 mr_free(tmp);1920 paranoid_free(tmp); 1861 1921 mr_free(token); 1862 1922 return (1); … … 1869 1929 * any of the Logical Volumes on the Volume Group. 1870 1930 *******/ 1871 mr_free(mount_list);1931 paranoid_free(mount_list); 1872 1932 1873 1933 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1874 1934 log_msg (5, "Running: %s", command); 1875 1935 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1876 mr_free(command);1936 paranoid_free(command); 1877 1937 log_msg(4, " Software raid device list: %s", mount_list); 1878 1938 lastpos = 0; … … 1880 1940 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 1881 1941 log_msg (5, "Running: %s", command); 1882 mr_free(tmp);1942 paranoid_free(tmp); 1883 1943 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1884 mr_free(command);1944 paranoid_free(command); 1885 1945 log_msg(4, "Number of Software raid device: %s", tmp); 1886 1946 if (atoi(tmp)) { … … 1888 1948 if ((DSFptr = find_device_in_list(token)) == NULL) { 1889 1949 log_msg (4, "Can't find device %s in mounted file systems list", token); 1890 mr_free(tmp);1950 paranoid_free(tmp); 1891 1951 mr_free(token); 1892 1952 return (1); … … 1899 1959 } else { 1900 1960 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 1901 mr_free(tmp);1961 paranoid_free(tmp); 1902 1962 return (1); 1903 1963 } 1904 mr_free(tmp);1964 paranoid_free(tmp); 1905 1965 continue; 1906 1966 } else { 1907 1967 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 1908 1968 } 1909 mr_free(tmp); 1910 1969 paranoid_free(tmp); 1911 1970 /******** 1912 1971 * It's not swap, mounted, or LVM. See if it's used in a software raid device. … … 1916 1975 log_msg(4, " Running: %s", command); 1917 1976 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1918 mr_free(command); 1919 1977 paranoid_free(command); 1920 1978 if (!strlen(tmp)) { 1921 1979 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 1922 mr_free(tmp);1980 paranoid_free(tmp); 1923 1981 continue; 1924 1982 } 1925 1983 log_msg (5, " UUID: %s", tmp); 1926 1927 1984 /* Get the Software raid device list */ 1928 1985 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1929 1986 log_msg (5, " Running: %s", command); 1930 1987 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1931 mr_free(command); 1932 1988 paranoid_free(command); 1933 1989 log_msg(4, " Software raid device list: %s", mount_list); 1934 1990 /* Loop through the software raid device list to see if we can find the partition */ … … 1937 1993 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 1938 1994 log_msg(4, " Running: %s", command); 1939 mr_free(tmp);1995 paranoid_free(tmp); 1940 1996 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1941 mr_free(command); 1942 1997 paranoid_free(command); 1943 1998 if (!atoi(tmp)) { 1944 1999 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); … … 1946 2001 if ((DSFptr = find_device_in_list(token)) == NULL) { 1947 2002 log_msg (4, "Can't find device %s in mounted file systems list", token); 1948 mr_free(tmp);2003 paranoid_free(tmp); 1949 2004 mr_free(token); 1950 2005 return (1); … … 1955 2010 mr_free(token); 1956 2011 } 1957 mr_free(tmp);1958 mr_free(mount_list);2012 paranoid_free(tmp); 2013 paranoid_free(mount_list); 1959 2014 } 1960 2015 … … 1992 2047 return (0); 1993 2048 } 2049 2050 2051 1994 2052 1995 2053 … … 2041 2099 log_to_screen("Archiving only the following file systems on %s:", token); 2042 2100 log_to_screen("==> %s", mounted_on_dsf); 2043 mr_free(bkpinfo->include_paths); 2044 mr_asprintf(bkpinfo->include_paths, "%s", "/"); 2101 strcpy(bkpinfo->include_paths, "/"); 2045 2102 if (strlen(not_mounted_on_dsf)) { 2046 2103 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf); … … 2079 2136 mr_asprintf(tmp,"|%s|",bkpinfo->include_paths); 2080 2137 if (strstr(tmp,tmp2) == NULL) { 2081 mr_strcat(bkpinfo->include_paths, "%s",tmp1);2138 strcat(bkpinfo->include_paths,tmp1); 2082 2139 } 2083 2140 mr_free(tmp1); … … 2124 2181 char *q = NULL; 2125 2182 char p[16*MAX_STR_LEN]; 2126 char *sz_size = NULL;2127 char *command = NULL;2183 char *sz_size; 2184 char *command; 2128 2185 char *compression_type = NULL; 2129 char *comment = NULL; 2186 char *comment; 2187 char *prompt; 2130 2188 int i; 2131 2189 FILE *fin; 2132 2190 2191 malloc_string(sz_size); 2192 malloc_string(command); 2193 malloc_string(comment); 2194 malloc_string(prompt); 2133 2195 malloc_string(tmp1); 2134 2196 assert(bkpinfo != NULL); 2197 sz_size[0] = '\0'; 2135 2198 bkpinfo->nonbootable_backup = FALSE; 2136 2199 … … 2169 2232 setup_scratchdir(tmp); 2170 2233 } 2171 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2234 log_msg(3, "media type = %s", 2235 bkptype_to_string(bkpinfo->backup_media_type)); 2172 2236 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 2173 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2174 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2237 bkpinfo->compression_level = 2238 (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2239 bkpinfo->use_lzo = 2240 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2175 2241 mvaddstr_and_log_it(2, 0, " "); 2176 2242 … … 2187 2253 if (archiving_to_media) { 2188 2254 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2189 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) { 2255 if (ask_me_yes_or_no 2256 ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) 2257 { 2190 2258 bkpinfo->manual_cd_tray = TRUE; 2191 2259 } … … 2195 2263 finish(1); 2196 2264 } 2197 2198 if ((bkpinfo->compression_level =which_compression_level()) == -1) {2265 if ((bkpinfo->compression_level = 2266 which_compression_level()) == -1) { 2199 2267 log_to_screen("User has chosen not to backup the PC"); 2200 2268 finish(1); 2201 2269 } 2202 2270 mds = media_descriptor_string(bkpinfo->backup_media_type); 2203 mr_asprintf(comment, "What speed is your %s (re)writer?", mds);2271 sprintf(comment, "What speed is your %s (re)writer?", mds); 2204 2272 if (bkpinfo->backup_media_type == dvd) { 2205 2273 find_dvd_device(bkpinfo->media_device, FALSE); 2206 2274 strcpy(tmp1, "1"); 2207 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2275 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2208 2276 log_msg(1, "Setting to DVD defaults"); 2209 2277 } else { 2210 2278 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 2211 2279 strcpy(tmp1, "4"); 2212 mr_asprintf(sz_size, "%d", 650);2280 strcpy(sz_size, "650"); 2213 2281 log_msg(1, "Setting to CD defaults"); 2214 2282 } … … 2216 2284 if (!popup_and_get_string("Speed", comment, tmp1, 4)) { 2217 2285 log_to_screen("User has chosen not to backup the PC"); 2218 mr_free(comment);2219 2286 finish(1); 2220 2287 } 2221 2288 } 2222 mr_free(comment);2223 2289 bkpinfo->cdrw_speed = atoi(tmp1); // if DVD then this shouldn't ever be used anyway :) 2224 2290 2225 s trcpy(tmp1, sz_size);2226 mr_asprintf(comment,"How much data (in Megabytes) will each %s store?", mds);2291 sprintf(comment, 2292 "How much data (in Megabytes) will each %s store?", mds); 2227 2293 mr_free(mds); 2228 if (!popup_and_get_string("Size", comment, tmp1, 5)) {2294 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 2229 2295 log_to_screen("User has chosen not to backup the PC"); 2230 2296 finish(1); 2231 2297 } 2232 mr_asprintf(sz_size, "%s", tmp1);2233 2298 bkpinfo->media_size = atoi(sz_size); 2234 2235 2299 if (bkpinfo->media_size <= 0) { 2236 2300 log_to_screen("User has chosen not to backup the PC"); … … 2244 2308 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) { 2245 2309 strcpy(bkpinfo->media_device, "/dev/cdrom"); 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) { 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) { 2248 2314 if (!bkpinfo->media_device[0]) { 2249 2315 strcpy(bkpinfo->media_device, "/dev/cdrom"); 2250 2316 } // just for the heck of it :) 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)) { 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)) { 2256 2328 log_to_screen("User has chosen not to backup the PC"); 2257 2329 finish(1); … … 2327 2399 } else { 2328 2400 if (does_file_exist("/tmp/mondo-restore.cfg")) { 2329 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device); 2401 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 2402 bkpinfo->media_device); 2330 2403 } 2331 2404 } … … 2382 2455 finish(1); 2383 2456 } 2384 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2457 if ((bkpinfo->compression_level = 2458 which_compression_level()) == -1) { 2385 2459 log_to_screen("User has chosen not to backup the PC"); 2386 2460 finish(1); … … 2394 2468 /* Never try to eject a NETFS device */ 2395 2469 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 }2400 2470 2401 2471 /* Initiate bkpinfo netfs_mount path from running environment if not already done */ 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")); 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")); 2404 2476 } 2405 2477 #ifdef __FreeBSD__ … … 2412 2484 ("Network shared dir.", 2413 2485 "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.)", 2414 p, MAX_STR_LEN / 4)) {2486 bkpinfo->netfs_mount, MAX_STR_LEN / 4)) { 2415 2487 log_to_screen("User has chosen not to backup the PC"); 2416 2488 finish(1); 2417 2489 } 2418 mr_free(bkpinfo->netfs_mount);2419 mr_asprintf(bkpinfo->netfs_mount, "%s", p;2420 2490 if (!bkpinfo->restore_data) { 2421 2491 if ((compression_type = which_compression_type()) == NULL) { … … 2423 2493 finish(1); 2424 2494 } 2425 2426 if ((bkpinfo->compression_level =which_compression_level()) == -1) {2495 if ((bkpinfo->compression_level = 2496 which_compression_level()) == -1) { 2427 2497 log_to_screen("User has chosen not to backup the PC"); 2428 2498 finish(1); … … 2431 2501 // check whether already mounted - we better remove 2432 2502 // surrounding spaces and trailing '/' for this 2433 mr_strip_spaces(bkpinfo->netfs_mount);2503 strip_spaces(bkpinfo->netfs_mount); 2434 2504 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2435 2505 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; … … 2443 2513 strcpy(tmp1,bkpinfo->netfs_mount); 2444 2514 } 2445 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);2515 sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1); 2446 2516 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command)); 2447 mr_free(command);2448 2517 2449 2518 if (!bkpinfo->restore_data) { 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)) { 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)) { 2455 2523 log_to_screen("User has chosen not to backup the PC"); 2456 2524 finish(1); 2457 2525 } 2458 mr_free(comment);2459 mr_asprintf(sz_size, "%s", tmp1);2460 2526 } else { 2461 mr_asprintf(sz_size, "0");2527 strcpy(sz_size, "0"); 2462 2528 } 2463 2529 bkpinfo->media_size = atoi(sz_size); 2464 mr_free(sz_size);2465 2466 2530 if (bkpinfo->media_size < 0) { 2467 2531 log_to_screen("User has chosen not to backup the PC"); … … 2469 2533 } 2470 2534 } 2535 /* Force NFS to be the protocol by default */ 2536 if (bkpinfo->netfs_proto == NULL) { 2537 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 2538 } 2471 2539 if (bkpinfo->disaster_recovery) { 2472 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);2540 sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir); 2473 2541 paranoid_system(command); 2474 mr_free(command);2475 2476 2542 } 2477 2543 strcpy(tmp1, bkpinfo->netfs_proto); 2478 if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) { 2544 if (!popup_and_get_string 2545 ("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?", 2546 tmp1, MAX_STR_LEN)) { 2479 2547 log_to_screen("User has chosen not to backup the PC"); 2480 2548 finish(1); … … 2482 2550 mr_free(bkpinfo->netfs_proto); 2483 2551 mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1); 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)) {2552 if (!popup_and_get_string 2553 ("Network share", "Which remote share should I mount?", 2554 bkpinfo->netfs_mount, MAX_STR_LEN)) { 2487 2555 log_to_screen("User has chosen not to backup the PC"); 2488 2556 finish(1); 2489 2557 } 2490 mr_free(bkpinfo->netfs_mount);2491 mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1);2492 2558 2493 2559 if (bkpinfo->netfs_user) { … … 2496 2562 strcpy(tmp1, ""); 2497 2563 } 2498 if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1)) { 2564 if (!popup_and_get_string 2565 ("Network user", "Which user should I use if any ?", 2566 tmp1, MAX_STR_LEN)) { 2499 2567 log_to_screen("User has chosen not to backup the PC"); 2500 2568 finish(1); … … 2507 2575 /* Initiate bkpinfo isodir path from running environment if mount already done */ 2508 2576 if (is_this_device_mounted(bkpinfo->netfs_mount)) { 2509 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2577 strcpy(bkpinfo->isodir, 2578 call_program_and_get_last_line_of_output 2579 ("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2510 2580 } else { 2511 2581 sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir); 2512 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);2582 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 2513 2583 run_program_and_log_output(command, 5); 2514 mr_free(command);2515 2584 2516 2585 if (bkpinfo->restore_data) { … … 2546 2615 } 2547 2616 if (!is_this_device_mounted(bkpinfo->netfs_mount)) { 2548 popup_and_OK("Please mount that partition before you try to backup to or restore from it."); 2617 popup_and_OK 2618 ("Please mount that partition before you try to backup to or restore from it."); 2549 2619 finish(1); 2550 2620 } … … 2570 2640 log_msg(3, "prefix set to %s", bkpinfo->prefix); 2571 2641 2572 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir); 2642 log_msg(3, "Just set netfs_remote_dir to %s", 2643 bkpinfo->netfs_remote_dir); 2573 2644 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2574 2645 break; … … 2588 2659 finish(1); 2589 2660 } 2590 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2661 if ((bkpinfo->compression_level = 2662 which_compression_level()) == -1) { 2591 2663 log_to_screen("User has chosen not to backup the PC"); 2592 2664 finish(1); 2593 2665 } 2594 sprintf( tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2666 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2595 2667 if (!popup_and_get_string 2596 2668 ("ISO size.", 2597 2669 "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.", 2598 tmp1, 16)) {2670 sz_size, 16)) { 2599 2671 log_to_screen("User has chosen not to backup the PC"); 2600 2672 finish(1); 2601 2673 } 2602 bkpinfo->media_size = atoi( tmp1);2674 bkpinfo->media_size = atoi(sz_size); 2603 2675 } else { 2604 2676 bkpinfo->media_size = 650; … … 2651 2723 finish(1); 2652 2724 } 2653 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { 2725 if (does_string_exist_in_boot_block 2726 (bkpinfo->boot_device, "LILO")) { 2654 2727 i = 'L'; 2655 2728 } else 2656 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { 2729 if (does_string_exist_in_boot_block 2730 (bkpinfo->boot_device, "ELILO")) { 2657 2731 i = 'E'; 2658 2732 } else 2659 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { 2733 if (does_string_exist_in_boot_block 2734 (bkpinfo->boot_device, "GRUB")) { 2660 2735 i = 'G'; 2661 2736 } else { … … 2664 2739 #endif 2665 2740 if (i == 'U') { 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?")) { 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 { 2667 2744 i = 'R'; // raw 2668 2745 } else { 2669 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); 2746 log_to_screen 2747 ("I cannot find your boot loader. Please run mondoarchive with parameters."); 2670 2748 finish(1); 2671 2749 } … … 2673 2751 } 2674 2752 bkpinfo->boot_loader = i; 2675 2676 mr_free(bkpinfo->include_paths); 2677 strcpy(tmp1, "/"); 2753 strcpy(bkpinfo->include_paths, "/"); 2678 2754 if (!popup_and_get_string 2679 2755 ("Backup paths", 2680 2756 "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", 2681 tmp1, MAX_STR_LEN)) {2757 bkpinfo->include_paths, MAX_STR_LEN)) { 2682 2758 log_to_screen("User has chosen not to backup the PC"); 2683 2759 finish(1); 2684 2760 } 2685 mr_asprintf(bkpinfo->include_paths, "%s", tmp1);2686 2687 2761 tmp = list_of_NETFS_mounts_only(); 2688 2762 if (strlen(tmp) > 2) { … … 2741 2815 if (ask_me_yes_or_no("Do you want to backup extended attributes?")) { 2742 2816 if (find_home_of_exe("getfattr")) { 2743 mr_free(g_getfattr);2744 2817 mr_asprintf(g_getfattr,"getfattr"); 2745 2818 } 2746 2819 if (find_home_of_exe("getfacl")) { 2747 mr_free(g_getfacl);2748 2820 mr_asprintf(g_getfacl,"getfacl"); 2749 2821 } … … 2763 2835 strcpy(bkpinfo->zip_exe, "gzip"); 2764 2836 strcpy(bkpinfo->zip_suffix, "gz"); 2765 } else if (strcmp(compression_type,"lzma") == 0) {2837 //} else if (strcmp(compression_type,"lzma") == 0) { 2766 2838 //strcpy(bkpinfo->zip_exe, "xy"); 2767 2839 //strcpy(bkpinfo->zip_suffix, "xy"); … … 2777 2849 ("Will you want to verify your backups after Mondo has created them?"); 2778 2850 2851 #ifndef __FreeBSD__ 2852 if (!ask_me_yes_or_no 2853 ("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 #endif 2855 { 2856 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 2857 } 2858 2779 2859 if (!ask_me_yes_or_no 2780 2860 ("Are you sure you want to proceed? Hit 'no' to abort.")) { … … 2795 2875 #else 2796 2876 if (bkpinfo->backup_media_type == netfs) { 2797 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir); 2877 log_msg(3, "I think the Remote mount is mounted at %s", 2878 bkpinfo->isodir); 2798 2879 } 2799 2880 log_it("isodir = %s", bkpinfo->isodir); 2800 if (bkpinfo->netfs_mount) { 2801 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2881 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2882 if (bkpinfo->netfs_proto) { 2883 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto); 2802 2884 } 2803 2885 if (bkpinfo->netfs_user) { 2804 2886 log_it("netfs_user = '%s'", bkpinfo->netfs_user); 2805 }2806 if (bkpinfo->netfs_proto) {2807 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);2808 2887 } 2809 2888 #endif … … 2812 2891 log_it("media size = %ld", bkpinfo->media_size); 2813 2892 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2814 if (bkpinfo->prefix) { 2815 log_it("prefix = %s", bkpinfo->prefix); 2816 } 2893 log_it("prefix = %s", bkpinfo->prefix); 2817 2894 log_it("compression = %ld", bkpinfo->compression_level); 2818 2895 log_it("exclude_path = %s", bkpinfo->exclude_paths); … … 2820 2897 2821 2898 /* Handle devices passed in bkpinfo and print result */ 2822 /* the mr_make_devlist_from_pathlist function appends 2823 /* to the *_paths variables so copy before */2899 /* the mr_make_devlist_from_pathlist function appends 2900 * to the *_paths variables so copy before */ 2824 2901 mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E'); 2825 2902 mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I'); … … 2827 2904 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 2828 2905 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 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); 2906 log_it("image_devs = '%s'", bkpinfo->image_devs); 2907 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, 2908 bkpinfo->boot_loader); 2833 2909 if (bkpinfo->media_size < 0) { 2834 2910 if (archiving_to_media) { … … 2841 2917 paranoid_free(sz_size); 2842 2918 paranoid_free(tmp1); 2919 paranoid_free(command); 2920 paranoid_free(comment); 2921 paranoid_free(prompt); 2843 2922 return (0); 2844 2923 } … … 3091 3170 3092 3171 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 */3095 3172 3096 3173 #ifdef __IA64__ -
branches/3.0/mondo/src/common/libmondo-fifo.c
r3188 r3192 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 sync();87 paranoid_system("sync"); 88 88 for (bufsize = wise_upper_limit, res = -1; 89 89 res != 0 && bufsize >= wise_lower_limit; bufsize--) { 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'); 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'); 91 93 res = run_program_and_log_output(tmp, 2); 92 94 mr_free(tmp); … … 94 96 if (!res) { 95 97 bufsize++; 96 log_to_screen(tmp, "Negotiated max buffer of %d MB ", bufsize); 98 mr_asprintf(tmp, "Negotiated max buffer of %d MB ", bufsize); 99 log_to_screen(tmp); 100 mr_free(tmp); 97 101 } else { 98 102 bufsize = 0; … … 162 166 return; 163 167 } 164 sync();168 paranoid_system("sync"); 165 169 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); 166 170 log_msg(2, "kill_buffer() --- command = %s", command); -
branches/3.0/mondo/src/common/libmondo-filelist.c
r3188 r3192 86 86 87 87 /*@ pointers ********************** */ 88 char *ptr = NULL;88 char *ptr; 89 89 FILE *fout; 90 90 … … 116 116 mr_free(tempfile); 117 117 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); 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++; 138 135 } 139 136 } … … 141 138 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 142 139 140 paranoid_free(dev); 143 141 return (retval); 144 142 } … … 160 158 161 159 mr_asprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir); 160 162 161 mr_asprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE); 163 162 retval = system(command); … … 332 331 333 332 if (curr_set_no == 0) { 334 log_msg(1, "Only one fileset. Fine.");333 mr_asprintf(tmp, "Only one fileset. Fine."); 335 334 } else { 336 log_msg(1, "Filelist divided into %ld sets", curr_set_no + 1); 337 } 335 mr_asprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1); 336 } 337 log_msg(1, tmp); 338 mr_free(tmp); 338 339 close_evalcall_form(); 339 340 /* This is to work around an obscure bug in Newt; open a form, close it, … … 341 342 then update_progress_form() won't show the "time taken / time remaining" 342 343 line. The bug only crops up AFTER the call to chop_filelist(). Weird. */ 344 #ifndef _XWIN 343 345 if (!g_text_mode) { 344 346 open_progress_form("", "", "", "", 100); … … 347 349 newtPopWindow(); 348 350 } 351 #endif 349 352 return (err ? 0 : curr_set_no + 1); 350 353 } … … 407 410 int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout) 408 411 { 409 FILE *pattr = NULL; 410 char *tmp = NULL; 412 FILE *pattr; 413 char *tmp; 414 char *p; 411 415 412 416 pattr = popen(syscall, "r"); … … 420 424 return (2); 421 425 } 422 for (mr_getline(tmp, pattr); !feof(pattr); mr_getline(tmp, pattr)) { 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)) { 423 429 fputs(tmp, pout); 424 mr_free(tmp); 425 } 426 mr_free(tmp); 430 } 427 431 paranoid_pclose(pattr); 432 paranoid_free(tmp); 428 433 return (0); 429 434 } … … 434 439 char *auxlist_fname) 435 440 { 436 FILE *fin = NULL;437 FILE *pout = NULL;441 FILE *fin; 442 FILE *pout; 438 443 char *pout_command = NULL; 439 char *syscall = NULL;440 char *file_to_analyze = NULL;444 char *syscall; 445 char *file_to_analyze; 441 446 char *strtmp = NULL; 442 447 char *tmp = NULL; 448 char *p = NULL; 443 449 int i; 444 450 … … 456 462 mr_free(pout_command); 457 463 458 for (mr_getline(file_to_analyze, fin); !feof(fin); mr_getline(file_to_analyze, fin)) { 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)) { 459 467 i = strlen(file_to_analyze); 460 468 if (i > 0 && file_to_analyze[i - 1] < 32) { … … 464 472 tmp = mr_stresc(file_to_analyze, "'", '\\', '\''); 465 473 mr_asprintf(syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp); // " MONDO_LOGFILE); 466 mr_free(tmp);474 paranoid_free(tmp); 467 475 log_msg(20,"calling %s\n",syscall); 468 476 call_exe_and_pipe_output_to_fd(syscall, pout); 469 mr_free(syscall); 470 mr_free(file_to_analyze); 471 } 472 mr_free(file_to_analyze); 477 paranoid_free(syscall); 478 } 473 479 paranoid_fclose(fin); 474 480 paranoid_pclose(pout); 481 paranoid_free(file_to_analyze); 475 482 return (0); 476 483 } … … 515 522 char *syscall_pin = NULL; 516 523 char *syscall_pout = NULL; 517 char *incoming = NULL; 518 char *current_subset_file = NULL; 519 char *current_master_file = NULL; 524 char *incoming; 525 char *current_subset_file, *current_master_file; 520 526 char *masklist = NULL; 521 527 int retval = 0; 522 528 int i; 523 char *p, *q ;529 char *p, *q, *r; 524 530 char *tmp = NULL; 525 531 FILE *pin, *pout, *faclin; 526 532 527 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable); 533 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 534 original_exat_fname, executable); 528 535 if (!orig_msklist || !orig_msklist[0] 529 536 || !does_file_exist(orig_msklist)) { … … 545 552 } 546 553 if (length_of_file(original_exat_fname) <= 0) { 547 log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname); 554 log_msg(1, 555 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 556 original_exat_fname); 548 557 return (0); 549 558 } 559 malloc_string(incoming); 560 malloc_string(current_subset_file); 561 malloc_string(current_master_file); 550 562 mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir); 551 563 mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist); … … 554 566 555 567 sort_file(masklist); 568 current_subset_file[0] = current_master_file[0] = '\0'; 556 569 557 570 mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE); … … 586 599 // printf("Hi there. Starting the loop\n"); 587 600 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); 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); 592 607 593 608 p = current_subset_file; … … 617 632 if (i < 0) { // read another subset file in. 618 633 log_msg(my_depth, "Reading next subset line in\n\n"); 619 mr_free(current_subset_file); 620 mr_getline(current_subset_file, faclin); 634 r = fgets(current_subset_file, MAX_STR_LEN, faclin); 621 635 continue; 622 636 } … … 625 639 fputs(incoming, pout); 626 640 } 627 mr_free(incoming); 628 mr_getline(incoming, pin); 641 r = fgets(incoming, MAX_STR_LEN, pin); 629 642 if (!i) { 630 643 log_msg(my_depth, "Copying master %s", q); 631 644 } 645 // if (!i) { printf("Match --- %s\n", q); } 632 646 633 647 while (!feof(pin) && strncmp(incoming, "# file: ", 8)) { 634 648 if (!i) { 649 650 // printf("%s", incoming); 651 635 652 fputs(incoming, pout); 636 653 } 637 mr_free(incoming); 638 mr_getline(incoming, pin); 654 r = fgets(incoming, MAX_STR_LEN, pin); 639 655 } 640 656 if (!i) { 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); 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 } 648 663 fclose(faclin); 649 664 pclose(pin); 650 665 pclose(pout); 651 666 667 // printf("OK, loop is done\n"); 668 652 669 unlink(masklist); 653 670 mr_free(masklist); 654 671 672 paranoid_free(current_subset_file); 673 paranoid_free(current_master_file); 674 paranoid_free(incoming); 655 675 return (retval); 656 676 } … … 750 770 noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */ 751 771 752 772 /* walk across tree if necessary */ 753 773 node = startnode; 754 774 char_to_add = string_to_add[0]; … … 759 779 } 760 780 761 781 /* walk down tree if appropriate */ 762 782 if (node->down != NULL && node->ch == char_to_add) { 763 783 log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add); … … 773 793 } 774 794 775 795 /* add here */ 776 796 if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) { 777 797 log_to_screen("failed to malloc"); … … 844 864 /*@ buffers **************************************************** */ 845 865 char *command_to_open_fname = NULL; 846 char *fname = NULL;847 char *tmp = NULL;866 char fname[MAX_STR_LEN]; 867 char tmp[MAX_STR_LEN]; 848 868 char *tmp1 = NULL; 849 869 int pos_in_fname; … … 891 911 892 912 open_evalcall_form("Loading filelist from disk"); 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)) { 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)) { 895 916 fname[strlen(fname) - 1] = '\0'; 896 917 } 918 // strip_spaces (fname); 897 919 if (!strlen(fname)) { 898 mr_free(fname);899 920 continue; 900 921 } … … 903 924 continue; 904 925 } 905 mr_asprintf(tmp, "%s", fname);926 strcpy(tmp, fname); 906 927 tmp[pos_in_fname] = '\0'; 907 928 if (strlen(tmp)) { 908 929 add_string_at_node(filelist, tmp); 909 930 } 910 mr_free(tmp);911 931 } 912 932 add_string_at_node(filelist, fname); 913 914 933 if (!(++lino % 1111)) { 915 934 percentage = (int) (lino * 100 / lines_in_filelist); 916 935 update_evalcall_form(percentage); 917 936 } 918 mr_free(fname); 919 } 920 mr_free(fname); 921 937 } 922 938 paranoid_pclose(pin); 923 939 close_evalcall_form(); … … 1281 1297 1282 1298 1299 1300 1283 1301 /** 1284 1302 * Number of entries in the skeleton filelist. … … 1296 1314 * @bug Return value should be @c void. 1297 1315 */ 1298 int open_and_list_dir(char *dir1, char *sth, FILE * fout, time_t time_of_last_full_backup) { 1299 1316 int open_and_list_dir(char *dir1, char *sth, FILE * fout, 1317 time_t time_of_last_full_backup) 1318 { 1300 1319 const char delims[] = "|"; 1301 1320 … … 1304 1323 struct stat statbuf; 1305 1324 char *new; 1306 char *tmp = NULL;1325 char *tmp; 1307 1326 char *dir = NULL; 1308 1327 static int percentage = 0; 1309 char *skip_these = NULL;1328 char *skip_these; 1310 1329 char *new_with_pipe; 1311 1330 char *strtmp = NULL; 1312 1331 char *token = NULL; 1313 1332 char *find_excludes = NULL; 1314 char *name_of_evalcall_form = NULL; 1315 char *find_skeleton_marker = NULL; 1333 static char *name_of_evalcall_form; 1316 1334 int i; 1317 1335 int lastpos = 0; … … 1320 1338 static int counter = 0; 1321 1339 static int uberctr = 0; 1322 static long skeleton_lino = 0L; 1323 static time_t last_time = (time_t)0; 1340 static char *find_skeleton_marker; 1341 static long skeleton_lino = 0; 1342 static time_t last_time = 0; 1324 1343 time_t this_time; 1325 1344 … … 1336 1355 1337 1356 if (!depth) { 1357 malloc_string(name_of_evalcall_form); 1358 malloc_string(find_skeleton_marker); 1338 1359 while((token = mr_strtok(sth, delims, &lastpos)) != NULL) { 1339 1360 mr_strcat(find_excludes," -path %s -prune -o", token); … … 1354 1375 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); 1355 1376 #endif 1356 mr_free(find_excludes); 1357 1377 paranoid_free(find_excludes); 1358 1378 log_msg(5, "find command = %s", strtmp); 1359 1379 paranoid_system(strtmp); 1360 mr_free(strtmp); 1361 1380 paranoid_free(strtmp); 1362 1381 mr_asprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist); 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);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); 1367 1386 open_evalcall_form(name_of_evalcall_form); 1368 mr_free(name_of_evalcall_form); 1369 1387 find_skeleton_marker[0] = '\0'; 1370 1388 skeleton_lino = 1; 1371 1389 log_msg(5, "entries = %ld", g_skeleton_entries); … … 1373 1391 } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate 1374 1392 { 1375 mr_asprintf(find_skeleton_marker, "grep -Fv '%s' %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist); 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); 1376 1397 if (!system(find_skeleton_marker)) { 1377 1398 percentage = (int) (skeleton_lino * 100 / g_skeleton_entries); 1378 1399 skeleton_lino++; 1379 mr_free(find_skeleton_marker); 1380 1381 mr_asprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist); 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); 1382 1405 paranoid_system(find_skeleton_marker); 1383 1406 time(&this_time); 1384 1407 if (this_time != last_time) { 1385 1408 last_time = this_time; 1409 #ifndef _XWIN 1386 1410 if (!g_text_mode) { 1387 1411 int cols, rows; … … 1391 1415 mr_free(tmp); 1392 1416 } 1417 #endif 1393 1418 update_evalcall_form(percentage); 1394 1419 } 1395 1420 } 1396 mr_free(find_skeleton_marker);1397 1421 } 1398 1422 … … 1406 1430 mr_asprintf(tmp,"opendir %s", dir1); 1407 1431 log_OS_error(tmp); 1408 mr_free(tmp);1432 paranoid_free(tmp); 1409 1433 } else if (strstr(skip_these, new_with_pipe)) { 1410 1434 log_msg(10, "Found dir ***%s**** excluded", dir1); … … 1420 1444 mr_asprintf(new,"%s%s",dir1,dit->d_name); 1421 1445 } 1422 mr_free(new_with_pipe);1446 paranoid_free(new_with_pipe); 1423 1447 mr_asprintf(new_with_pipe, "|%s|", new); 1424 1448 if (strstr(skip_these, new_with_pipe)) { 1425 1449 fprintf(fout, "%s\n", new); 1426 1450 log_msg(10, "Found child dir ***%s**** excluded", new); 1427 mr_free(new_with_pipe);1451 paranoid_free(new_with_pipe); 1428 1452 } else { 1429 mr_free(new_with_pipe);1453 paranoid_free(new_with_pipe); 1430 1454 if (!lstat(new, &statbuf)) { 1431 1455 if (!S_ISLNK(statbuf.st_mode) 1432 1456 && S_ISDIR(statbuf.st_mode)) { 1433 1457 log_msg(10, "Found child dir ***%s**** parsed", new); 1434 open_and_list_dir(new, skip_these, fout, time_of_last_full_backup); 1458 open_and_list_dir(new, skip_these, fout, 1459 time_of_last_full_backup); 1435 1460 } else { 1436 if (time_of_last_full_backup == 0 || time_of_last_full_backup < statbuf.st_ctime) { 1461 if (time_of_last_full_backup == 0 1462 || time_of_last_full_backup < 1463 statbuf.st_ctime) { 1437 1464 log_msg(10, "Found child file ***%s**** parsed", new); 1438 1465 fprintf(fout, "%s\n", new); … … 1441 1468 uberctr++; 1442 1469 mr_asprintf(tmp, " %c ", special_dot_char(uberctr)); 1470 #ifndef _XWIN 1443 1471 if (!g_text_mode) { 1444 newtDrawRootText(77, g_noof_rows - 3, tmp); 1472 newtDrawRootText(77, g_noof_rows - 3, 1473 tmp); 1445 1474 newtRefresh(); 1446 1475 } 1447 mr_free(tmp); 1476 #endif 1477 paranoid_free(tmp); 1448 1478 } 1449 1479 } … … 1451 1481 } 1452 1482 } 1453 mr_free(new);1454 } 1455 } 1456 mr_free(new_with_pipe);1457 mr_free(skip_these);1483 paranoid_free(new); 1484 } 1485 } 1486 paranoid_free(new_with_pipe); 1487 paranoid_free(skip_these); 1458 1488 mr_free(dir); 1459 1489 … … 1466 1496 if (!depth) { 1467 1497 close_evalcall_form(); 1498 paranoid_free(name_of_evalcall_form); 1499 paranoid_free(find_skeleton_marker); 1468 1500 unlink(g_skeleton_filelist); 1469 1501 log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries); … … 1493 1525 char *p, *q; 1494 1526 char *sz_datefile; 1495 char *sz_filelist ;1527 char *sz_filelist, *tmp; 1496 1528 char *exclude_paths = NULL; 1497 1529 FILE *fout; … … 1502 1534 char *tmp2 = NULL; 1503 1535 1536 malloc_string(tmp); 1537 malloc_string(g_skeleton_filelist); 1504 1538 mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0); 1505 1539 if (!include_paths && !userdef_filelist) { 1506 fatal_error("Please supply either include_paths or userdef_filelist"); 1507 } 1508 // make hole for filelist 1540 fatal_error 1541 ("Please supply either include_paths or userdef_filelist"); 1542 } 1543 // make hole for filelist 1509 1544 mr_asprintf(command, "mkdir -p %s/archives", scratchdir); 1510 1545 paranoid_system(command); … … 1522 1557 // backup last known good datefile just in case :) 1523 1558 if (does_file_exist(sz_datefile)) { 1524 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile); 1559 mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, 1560 sz_datefile); 1525 1561 paranoid_system(command); 1526 1562 mr_free(command); … … 1531 1567 ("date +%s")); 1532 1568 } else if (lstat(sz_datefile, &statbuf)) { 1533 log_msg(2, "Warning - unable to find date of previous backup. Full backup instead."); 1569 log_msg(2, 1570 "Warning - unable to find date of previous backup. Full backup instead."); 1534 1571 differential = 0; 1535 1572 time_of_last_full_backup = 0; … … 1542 1579 // use user-specified filelist (if specified) 1543 1580 if (userdef_filelist) { 1544 log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist); 1581 log_msg(1, 1582 "Using the user-specified filelist - %s - instead of calculating one", 1583 userdef_filelist); 1545 1584 mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist); 1546 1585 if (run_program_and_log_output(command, 3)) { … … 1550 1589 mr_free(command); 1551 1590 } else { 1552 if (include_paths) { 1553 log_msg(2, "include_paths = '%s'", include_paths); 1554 } 1591 log_msg(2, "include_paths = '%s'", include_paths); 1555 1592 log_msg(1, "Calculating filelist"); 1556 1593 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'")); … … 1560 1597 log_msg(2, "Found windows FS: %s",tmp2); 1561 1598 mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2); 1562 mr_free(tmp2);1599 paranoid_free(tmp2); 1563 1600 mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1)); 1564 1601 log_msg(2, "Found windows files: %s",tmp2); 1565 1602 } 1566 mr_free(tmp1);1603 paranoid_free(tmp1); 1567 1604 1568 1605 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); … … 1570 1607 mr_strcat(exclude_paths,"|%s",excp); 1571 1608 } 1572 mr_free(tmp2);1609 paranoid_free(tmp2); 1573 1610 1574 1611 log_msg(2, "Excluding paths = '%s'", exclude_paths); 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); 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); 1577 1615 make_hole_for_file(g_skeleton_filelist); 1578 1579 1616 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries); 1580 1617 log_msg(2, "Opening out filelist to %s", sz_filelist); … … 1582 1619 fatal_error("Cannot openout to sz_filelist"); 1583 1620 } 1584 if ( (include_paths != NULL) && (strlen(include_paths) == 0)) {1621 if (strlen(include_paths) == 0) { 1585 1622 log_msg(1, "Including only '/' in %s", sz_filelist); 1586 1623 open_and_list_dir("/", exclude_paths, fout, … … 1600 1637 } 1601 1638 } 1602 mr_free(exclude_paths);1603 1639 paranoid_fclose(fout); 1604 1640 } … … 1618 1654 paranoid_free(sz_filelist); 1619 1655 log_msg(2, "Freeing variables"); 1620 mr_free(g_skeleton_filelist); 1656 paranoid_free(exclude_paths); 1657 paranoid_free(tmp); 1658 paranoid_free(g_skeleton_filelist); 1621 1659 log_msg(2, "Exiting"); 1622 1660 return (0); 1623 1661 } 1624 1625 1662 1626 1663 /** … … 1643 1680 1644 1681 assert(bkpinfo != NULL); 1645 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir); 1682 log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, 1683 bkpinfo->scratchdir); 1646 1684 if (bkpinfo->make_filelist) { 1647 1685 mvaddstr_and_log_it(g_currentY, 0, … … 1754 1792 FILE *fin; 1755 1793 FILE *fout; 1756 char *fname = NULL; 1757 char *tmp = NULL; 1758 1794 char *fname; 1795 char *tmp; 1796 size_t len = 0; // Scrub's patch doesn't work without that 1797 1798 // log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE"); 1799 malloc_string(fname); 1800 malloc_string(tmp); 1759 1801 log_msg(5, "starting"); 1760 1802 log_msg(5, "needles_list_fname = %s", needles_list_fname); … … 1767 1809 } 1768 1810 while (!feof(fin)) { 1769 mr_getline(fname, fin); 1811 // fscanf(fin, "%s\n", fname); 1812 len = MAX_STR_LEN - 1; 1813 if (getline(&fname, &len, fin)) { 1814 // FIXME 1815 } 1770 1816 if (!use_star) { 1771 1817 if (fname[0] == '/') { 1772 mr_asprintf(tmp, "%s", fname);1818 strcpy(tmp, fname); 1773 1819 } else { 1774 mr_asprintf(tmp, "/%s", fname); 1820 tmp[0] = '/'; 1821 strcpy(tmp + 1, fname); 1775 1822 } 1776 mr_free(fname); 1777 fname = tmp; 1823 strcpy(fname, tmp); 1778 1824 } 1779 1825 while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) { … … 1786 1832 if (found_node->selected) { 1787 1833 if (fname[0] == '/') { 1788 mr_asprintf(tmp, "%s", fname + 1); 1789 mr_free(fname); 1790 fname = tmp; 1834 strcpy(tmp, fname + 1); 1835 strcpy(fname, tmp); 1791 1836 } 1792 1837 log_msg(5, "Found '%s'", fname); 1793 tmp = mr_stresc(fname, "[]*?", '\\', "'"); 1794 mr_free(fname); 1795 fname = tmp; 1796 fprintf(fout, "%s\n", fname); 1838 turn_wildcard_chars_into_literal_chars(tmp, fname); 1839 fprintf(fout, "%s\n", tmp); 1797 1840 retval++; 1798 1841 } 1799 1842 } 1800 mr_free(fname);1801 1843 } 1802 1844 paranoid_fclose(fout); 1803 1845 paranoid_fclose(fin); 1846 paranoid_free(fname); 1847 paranoid_free(tmp); 1804 1848 return (retval); 1805 1849 } 1850 1851 1852 1806 1853 1807 1854 … … 1818 1865 char *list_of_files_fname, bool flag_em) 1819 1866 { 1820 FILE *fin = NULL; 1821 char *tmp = NULL; 1822 struct s_node *nod = NULL; 1823 1867 FILE *fin; 1868 char *tmp; 1869 char *p; 1870 struct s_node *nod; 1871 1872 malloc_string(tmp); 1824 1873 log_msg(3, "Adding %s to filelist", list_of_files_fname); 1825 1874 if (!(fin = fopen(list_of_files_fname, "r"))) { … … 1827 1876 return (1); 1828 1877 } 1829 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) { 1878 for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL); 1879 p = fgets(tmp, MAX_STR_LEN, fin)) { 1830 1880 if (!tmp[0]) { 1831 mr_free(tmp);1832 1881 continue; 1833 1882 } 1834 if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)) { 1883 if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10) 1884 && strlen(tmp) > 0) { 1835 1885 tmp[strlen(tmp) - 1] = '\0'; 1836 1886 } 1837 1887 log_msg(2, "tmp = '%s'", tmp); 1838 1888 if (!tmp[0]) { 1839 mr_free(tmp);1840 1889 continue; 1841 1890 } … … 1851 1900 log_msg(5, "Flagged '%s'", tmp); 1852 1901 } 1853 mr_free(tmp); 1854 } 1855 mr_free(tmp); 1902 } 1856 1903 paranoid_fclose(fin); 1904 paranoid_free(tmp); 1857 1905 return (0); 1858 1906 } -
branches/3.0/mondo/src/common/libmondo-files-EXT.h
r3188 r3192 41 41 42 42 43 extern int make_hole_for_dir(c onst char *outdir_fname);43 extern int make_hole_for_dir(char *outdir_fname); 44 44 45 45 extern long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); -
branches/3.0/mondo/src/common/libmondo-files.c
r3188 r3192 47 47 /*@ buffers ***************************************************** */ 48 48 static char output[MAX_STR_LEN]; 49 char *command = NULL; 49 char command[MAX_STR_LEN * 2]; 50 char tmp[MAX_STR_LEN]; 50 51 51 52 /*@ pointers **************************************************** */ 52 char *p = NULL;53 char *p; 53 54 char *q; 54 55 FILE *fin; … … 62 63 assert_string_is_neither_NULL_nor_zerolength(filename); 63 64 if (does_file_exist(filename)) { 64 mr_asprintf(command, "md5sum \"%s\"", filename);65 sprintf(command, "md5sum \"%s\"", filename); 65 66 fin = popen(command, "r"); 66 67 if (fin) { … … 72 73 paranoid_pclose(fin); 73 74 } 74 mr_free(command);75 75 } else { 76 log_it("File '%s' not found; cannot calc checksum", filename); 76 sprintf(tmp, "File '%s' not found; cannot calc checksum", 77 filename); 78 log_it(tmp); 77 79 } 78 80 if (p) { … … 128 130 129 131 /*@ buffers ***************************************************** */ 130 char *command = NULL; 131 char *incoming = NULL; 132 char command[MAX_STR_LEN * 2]; 133 char incoming[MAX_STR_LEN]; 134 char tmp[MAX_STR_LEN]; 135 char *q; 132 136 133 137 /*@ long ******************************************************** */ … … 137 141 FILE *fin; 138 142 143 /*@ initialize [0] to null ******************************************** */ 144 incoming[0] = '\0'; 145 139 146 assert_string_is_neither_NULL_nor_zerolength(filename); 140 147 if (!does_file_exist(filename)) { 141 log_it("%s does not exist, so I cannot found the number of lines in it", filename); 148 sprintf(tmp, 149 "%s does not exist, so I cannot found the number of lines in it", 150 filename); 151 log_it(tmp); 142 152 return (0); 143 153 } 144 mr_asprintf(command, "cat %s | wc -l", filename);154 sprintf(command, "cat %s | wc -l", filename); 145 155 if (!does_file_exist(filename)) { 146 mr_free(command);147 156 return (-1); 148 157 } 149 158 fin = popen(command, "r"); 150 mr_free(command);151 152 159 if (fin) { 153 160 if (feof(fin)) { 154 161 noof_lines = 0; 155 162 } else { 156 mr_getline(incoming, fin); 157 while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) { 163 q = fgets(incoming, MAX_STR_LEN - 1, fin); 164 if (!q) { 165 // FIXME 166 } 167 while (strlen(incoming) > 0 && (q != NULL) 168 && incoming[strlen(incoming) - 1] < 32) { 158 169 incoming[strlen(incoming) - 1] = '\0'; 159 170 } 160 171 noof_lines = atol(incoming); 161 mr_free(incoming);162 172 } 163 173 paranoid_pclose(fin); … … 205 215 void exclude_nonexistent_files(char *inout) 206 216 { 207 char *infname = NULL; 208 char *outfname = NULL; 209 char *tmp = NULL; 210 char *incoming = NULL; 217 char infname[MAX_STR_LEN]; 218 char outfname[MAX_STR_LEN]; 219 char tmp[MAX_STR_LEN]; 220 char incoming[MAX_STR_LEN]; 221 char *q; 211 222 212 223 /*@ int ********************************************************* */ … … 220 231 221 232 assert_string_is_neither_NULL_nor_zerolength(inout); 222 mr_asprintf(infname, "%s.in", inout); 223 mr_asprintf(tmp, "cp -f %s %s", inout, infname); 233 sprintf(infname, "%s.in", inout); 234 sprintf(outfname, "%s", inout); 235 sprintf(tmp, "cp -f %s %s", inout, infname); 224 236 run_program_and_log_output(tmp, FALSE); 225 mr_free(tmp);226 227 237 if (!(fin = fopen(infname, "r"))) { 228 238 log_OS_error("Unable to openin infname"); 229 mr_free(infname);230 239 return; 231 240 } 232 233 mr_asprintf(outfname, "%s", inout);234 241 if (!(fout = fopen(outfname, "w"))) { 235 242 log_OS_error("Unable to openout outfname"); 236 mr_free(infname);237 mr_free(outfname);238 243 return; 239 244 } 240 mr_free(outfname); 241 242 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 245 for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); 246 q = fgets(incoming, MAX_STR_LEN, fin)) { 243 247 i = strlen(incoming) - 1; 244 248 if (i >= 0 && incoming[i] < 32) { … … 248 252 fprintf(fout, "%s\n", incoming); 249 253 } else { 250 log_it("Excluding '%s'-nonexistent\n", incoming); 251 } 252 mr_free(incoming); 253 } 254 mr_free(incoming); 255 254 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming); 255 log_it(tmp); 256 } 257 } 256 258 paranoid_fclose(fout); 257 259 paranoid_fclose(fin); 258 260 unlink(infname); 259 mr_free(infname); 260 } 261 } 262 263 264 265 266 267 268 261 269 262 270 … … 270 278 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 271 279 { 272 char *tmp = NULL;273 char *command = NULL;280 char tmp[MAX_STR_LEN]; 281 char *command; 274 282 275 283 if (!kernel[0]) { 276 strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null")); 284 strcpy(kernel, 285 call_program_and_get_last_line_of_output 286 ("mindi --findkernel 2> /dev/null")); 277 287 } 278 288 // If we didn't get anything back, check whether mindi raised a fatal error 279 289 if (!kernel[0]) { 280 mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log"); 281 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 290 malloc_string(command); 291 strcpy(command, "grep 'Fatal error' /var/log/mindi.log"); 292 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 282 293 if (strlen(tmp) > 1) { 283 294 popup_and_OK(tmp); 284 mr_free(tmp);285 mr_free(command);286 295 fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'."); 287 296 } 288 mr_free(tmp); 289 mr_free(command); 297 paranoid_free(command); 290 298 } 291 299 log_it("Calling Mindi with kernel path of '%s'", kernel); … … 302 310 ("Kernel not found. Please specify with the '-k' flag."); 303 311 } 304 log_it("User says kernel is at %s", kernel); 312 sprintf(tmp, "User says kernel is at %s", kernel); 313 log_it(tmp); 305 314 } 306 315 return (0); 307 316 } 317 318 319 320 308 321 309 322 … … 321 334 /*@ buffers ********************* */ 322 335 static char output[MAX_STR_LEN]; 323 char *incoming = NULL; 324 char *command = NULL; 325 336 char *incoming; 337 char *command; 338 339 malloc_string(incoming); 340 malloc_string(command); 341 incoming[0] = '\0'; 326 342 /*@******************************* */ 327 343 328 344 assert_string_is_neither_NULL_nor_zerolength(fname); 329 mr_asprintf(command, "which %s 2> /dev/null", fname); 330 mr_asprintf(incoming, call_program_and_get_last_line_of_output(command)); 331 mr_free(command); 332 345 sprintf(command, "which %s 2> /dev/null", fname); 346 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 333 347 if (incoming[0] == '\0') { 334 348 if (system("which file > /dev/null 2> /dev/null")) { 335 mr_free(incoming); 349 paranoid_free(incoming); 350 paranoid_free(command); 336 351 output[0] = '\0'; 337 352 return (NULL); // forget it :) 338 353 } 339 mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming); 340 mr_free(incomig); 341 342 mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command)); 343 mr_free(command); 344 } 345 if (incoming[0] == '\0') { 346 mr_asprintf(command, "dirname %s 2> /dev/null", incoming); 347 mr_free(incoming); 348 349 mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command)); 350 mr_free(command); 354 sprintf(command, 355 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", 356 incoming); 357 strcpy(incoming, 358 call_program_and_get_last_line_of_output(command)); 359 } 360 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 361 { 362 sprintf(command, "dirname %s 2> /dev/null", incoming); 363 strcpy(incoming, 364 call_program_and_get_last_line_of_output(command)); 351 365 } 352 366 strcpy(output, incoming); 353 367 if (output[0] != '\0' && does_file_exist(output)) { 354 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming); 368 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 369 incoming); 355 370 } else { 356 371 output[0] = '\0'; 357 372 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 358 373 } 359 mr_free(incoming); 374 paranoid_free(incoming); 375 paranoid_free(command); 360 376 if (!output[0]) { 361 377 return (NULL); … … 366 382 367 383 384 385 386 387 388 389 368 390 /** 369 391 * Get the last sequence of digits surrounded by non-digits in the first 32k of … … 399 421 for (; len > 0 && isdigit(datablock[len - 1]); len--); 400 422 trackno = atoi(datablock + len); 423 /* 424 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno); 425 log_it(tmp); 426 */ 401 427 return (trackno); 402 428 } … … 418 444 419 445 /*@ buffers ***************************************************** */ 420 char *lastline = NULL; 421 char *command = NULL; 446 char tmp[MAX_STR_LEN]; 447 char lastline[MAX_STR_LEN]; 448 char command[MAX_STR_LEN]; 422 449 /*@ pointers **************************************************** */ 423 char *p = NULL;450 char *p; 424 451 425 452 /*@ int's ******************************************************* */ 426 int i = 0; 427 428 for (i = NOOF_ERR_LINES - 1; i >= 0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--); 453 int i; 454 455 for (i = NOOF_ERR_LINES - 1; 456 i >= 0 && !strstr(err_log_lines[i], "% Done") 457 && !strstr(err_log_lines[i], "% done"); i--); 429 458 if (i < 0) { 430 mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%'); 431 mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command)); 432 mr_free(command); 459 sprintf(command, 460 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", 461 filename, '%'); 462 strcpy(lastline, 463 call_program_and_get_last_line_of_output(command)); 433 464 if (!lastline[0]) { 434 mr_free(lastline);435 465 return (0); 436 466 } 437 467 } else { 438 mr_asprintf(lastline, "%s", err_log_lines[i]);468 strcpy(lastline, err_log_lines[i]); 439 469 } 440 470 … … 442 472 if (p) { 443 473 *p = '\0'; 444 } else { 445 mr_free(lastline); 474 } 475 // log_msg(2, "lastline='%s', ", p, lastline); 476 if (!p) { 446 477 return (0); 447 478 } 448 449 for (p--; isdigit(*p)&& p != lastline; p--);479 *p = '\0'; 480 for (p--; *p != ' ' && p != lastline; p--); 450 481 if (p != lastline) { 451 482 p++; 452 483 } 453 484 i = atoi(p); 454 mr_free(lastline); 485 486 sprintf(tmp, "'%s' --> %d", p, i); 487 // log_to_screen(tmp); 488 455 489 return (i); 456 490 } … … 470 504 /*@ buffers ***************************************************** */ 471 505 static char output[MAX_STR_LEN]; 472 char *command = NULL; 506 static char command[MAX_STR_LEN * 2]; 507 static char tmp[MAX_STR_LEN]; 508 char *p = NULL; 473 509 474 510 /*@ pointers **************************************************** */ … … 478 514 479 515 if (!does_file_exist(filename)) { 480 log_it("Tring to get last line of nonexistent file (%s)", filename); 516 sprintf(tmp, "Tring to get last line of nonexistent file (%s)", 517 filename); 518 log_it(tmp); 481 519 output[0] = '\0'; 482 520 return (output); 483 521 } 484 mr_asprintf(command, "tail -n1 %s", filename);522 sprintf(command, "tail -n1 %s", filename); 485 523 fin = popen(command, "r"); 486 mr_free(command);487 524 p = fgets(output, MAX_STR_LEN, fin); 488 525 if (p == NULL) { … … 527 564 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed. 528 565 */ 529 int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) { 566 int 567 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) 568 { 530 569 /*@ pointers **************************************************** */ 531 570 FILE *fin; … … 538 577 539 578 /*@ buffer ****************************************************** */ 540 char *stub_fname = NULL; 541 char *curr_fname = NULL; 542 char *curr_cksum = NULL; 543 char *tmp = NULL; 579 char stub_fname[1000]; 580 char curr_fname[1000]; 581 char curr_cksum[1000]; 582 char tmp[1000]; 583 char *q; 544 584 545 585 /*@ long [long] ************************************************* */ … … 555 595 start_time = get_time(); 556 596 filelist_length = length_of_file(filelist); 557 log_it("filelist = %s; cksumlist = %s", filelist, cksumlist);558 597 sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist); 598 log_it(tmp); 559 599 fin = fopen(filelist, "r"); 560 600 if (fin == NULL) { … … 570 610 return (1); 571 611 } 572 for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) { 612 for (q = fgets(stub_fname, 999, fin); !feof(fin) && (q != NULL); 613 q = fgets(stub_fname, 999, fin)) { 573 614 if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) { 574 615 stub_fname[i] = '\0'; 575 616 } 576 mr_asprintf(tmp, "%s%s", comppath, stub_fname); 577 mr_free(stub_fname); 578 579 mr_asprintf(curr_fname, "%s", tmp + 1); 580 mr_free(tmp); 581 582 mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname)); 617 sprintf(tmp, "%s%s", comppath, stub_fname); 618 strcpy(curr_fname, tmp + 1); 619 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname)); 583 620 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum); 584 mr_free(curr_cksum);585 586 621 if (counter++ > 12) { 587 622 current_time = get_time(); 588 623 counter = 0; 589 /* BERLIOS: 37 really ? */590 624 curr_fname[37] = '\0'; 591 625 curr_pos = ftello(fin) / 1024; 592 626 percentage = (int) (curr_pos * 100 / filelist_length); 593 627 time_taken = current_time - start_time; 594 if (percentage != 0) { 595 time_remaining = time_taken * 100 / (long) (percentage) - time_taken; 596 log_to_screen("%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname); 628 if (percentage == 0) { 629 /* printf("%0d%% done \r",percentage); */ 630 } else { 631 time_remaining = 632 time_taken * 100 / (long) (percentage) - time_taken; 633 sprintf(tmp, 634 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", 635 percentage, (int) (time_taken / 60), 636 (int) (time_taken % 60), 637 (int) (time_remaining / 60), 638 (int) (time_remaining % 60), curr_fname); 639 log_to_screen(tmp); 597 640 } 598 641 sync(); 599 642 } 600 mr_free(curr_fname); 601 } 602 mr_free(stub_fname); 603 643 } 604 644 paranoid_fclose(fout); 605 645 paranoid_fclose(fin); … … 614 654 * @return The return value of @c mkdir. 615 655 */ 616 int make_hole_for_dir(c onst char *outdir_fname)617 { 618 char *tmp = NULL;656 int make_hole_for_dir(char *outdir_fname) 657 { 658 char tmp[MAX_STR_LEN * 2]; 619 659 int res = 0; 620 660 621 661 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 622 mr_asprintf(tmp, "mkdir -p %s", outdir_fname);662 sprintf(tmp, "mkdir -p %s", outdir_fname); 623 663 res = system(tmp); 624 mr_free(tmp);625 664 return (res); 626 665 } … … 636 675 { 637 676 /*@ buffer ****************************************************** */ 638 char *command = NULL;677 char command[MAX_STR_LEN * 2]; 639 678 640 679 /*@ int ******************************************************** */ … … 646 685 assert(!strstr(outfile_fname, MNT_CDROM)); 647 686 assert(!strstr(outfile_fname, "/dev/cdrom")); 648 mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);687 sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 649 688 res += system(command); 650 mr_free(command); 651 652 mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 689 sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 653 690 res += system(command); 654 mr_free(command); 655 656 mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 691 sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 657 692 res += system(command); 658 mr_free(command);659 660 693 unlink(outfile_fname); 661 694 return (0); 662 695 } 696 697 663 698 664 699 … … 678 713 679 714 /*@ buffers **************************************************** */ 680 char *incoming = NULL; 715 char incoming[MAX_STR_LEN]; 716 char *p = NULL; 681 717 682 718 /*@ end vars *************************************************** */ … … 689 725 return (0); 690 726 } 691 mr_getline(incoming, fin);692 while (!feof(fin) ) {727 p = fgets(incoming, MAX_STR_LEN - 1, fin); 728 while (!feof(fin) && (p != NULL)) { 693 729 if (strstr(incoming, wildcard)) { 694 730 matches++; 695 731 } 696 mr_free(incoming); 697 mr_getline(incoming, fin); 698 } 699 mr_free(incoming); 732 p = fgets(incoming, MAX_STR_LEN - 1, fin); 733 } 700 734 paranoid_fclose(fin); 701 735 return (matches); … … 712 746 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 713 747 { 714 char *command = NULL;715 char *mountlist = NULL;716 char *sz_res = NULL;748 char command[MAX_STR_LEN]; 749 char mountlist[MAX_STR_LEN]; 750 char sz_res[MAX_STR_LEN]; 717 751 long file_len_K; 718 752 719 mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir);720 mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);721 mr_free(mountlist);722 753 sprintf(mountlist, "%s/mountlist.txt", tmpdir); 754 sprintf(command, 755 "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", 756 dev, tmpdir); 723 757 log_it(command); 724 mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command));758 strcpy(sz_res, call_program_and_get_last_line_of_output(command)); 725 759 file_len_K = atol(sz_res); 726 760 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 727 mr_free(sz_res);728 mr_free(command);729 730 761 return (file_len_K); 731 762 } … … 739 770 { 740 771 /*@ buffers ***************************************************** */ 741 char *fname = NULL; 742 char *biggielist = NULL; 743 char *tmp = NULL; 744 char *command = NULL; 772 char *fname; 773 char *biggielist; 774 char *comment; 775 char *tmp; 776 char *q; 777 char *command; 745 778 746 779 /*@ long ******************************************************** */ … … 753 786 /*@ end vars *************************************************** */ 754 787 788 malloc_string(fname); 789 malloc_string(biggielist); 790 malloc_string(comment); 791 malloc_string(tmp); 792 malloc_string(command); 755 793 log_it("Calculating size of all biggiefiles (in total)"); 756 mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);794 sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 757 795 log_it("biggielist = %s", biggielist); 758 fin = fopen(biggielist, "r"); 759 mr_free(biggielist); 760 761 if (!(fin)) { 762 log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only."); 796 if (!(fin = fopen(biggielist, "r"))) { 797 log_OS_error 798 ("Cannot open biggielist. OK, so estimate is based on filesets only."); 763 799 } else { 764 800 log_msg(4, "Reading it..."); 765 for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) { 801 for (q = fgets(fname, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); 802 q = fgets(fname, MAX_STR_LEN, fin)) { 766 803 if (fname[strlen(fname) - 1] <= 32) { 767 804 fname[strlen(fname) - 1] = '\0'; … … 770 807 if (is_dev_an_NTFS_dev(fname)) { 771 808 if ( !find_home_of_exe("ntfsresize")) { 772 mr_free(tmp);773 mr_free(fname);774 809 fatal_error("ntfsresize not found"); 775 810 } 776 mr_free(tmp); 777 778 mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 811 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 779 812 log_it("command = %s", command); 780 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 781 mr_free(command); 782 813 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 783 814 log_it("res of it = %s", tmp); 784 815 file_len_K = atoll(tmp) / 1024L; 785 mr_free(tmp);786 816 } else { 787 817 file_len_K = get_phys_size_of_drive(fname) * 1024L; … … 795 825 log_msg(4, "%s --> %ld K", fname, file_len_K); 796 826 } 797 log_msg(4, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL); 827 sprintf(comment, 828 "After adding %s, scratchL+%ld now equals %ld", fname, 829 file_len_K, scratchL); 830 log_msg(4, comment); 798 831 if (feof(fin)) { 799 832 break; 800 833 } 801 mr_free(fname); 802 } 803 mr_free(fname); 834 } 804 835 } 805 836 log_it("Closing..."); 806 837 paranoid_fclose(fin); 807 838 log_it("Finished calculating total size of all biggiefiles"); 839 paranoid_free(fname); 840 paranoid_free(biggielist); 841 paranoid_free(comment); 842 paranoid_free(tmp); 843 paranoid_free(command); 808 844 return (scratchL); 809 845 } … … 818 854 { 819 855 /*@ buffer ****************************************************** */ 820 char *tmp = NULL;821 char *command = NULL;856 char tmp[MAX_STR_LEN]; 857 char command[MAX_STR_LEN * 2]; 822 858 long long llres; 823 859 /*@ pointers **************************************************** */ … … 827 863 /*@ end vars *************************************************** */ 828 864 829 mr_asprintf(command, "du -sk %s", mountpt);865 sprintf(command, "du -sk %s", mountpt); 830 866 errno = 0; 831 867 fin = popen(command, "r"); … … 834 870 llres = 0; 835 871 } else { 836 mr_getline(tmp, fin);872 p = fgets(tmp, MAX_STR_LEN, fin); 837 873 paranoid_pclose(fin); 838 874 p = strchr(tmp, '\t'); … … 844 880 llres += (int) (*p - '0'); 845 881 } 846 mr_free(tmp); 847 } 848 mr_free(command); 882 } 849 883 850 884 return (llres); … … 894 928 { 895 929 /*@ buffers *** */ 896 char *command = NULL; 897 int res = 0; 898 899 mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname); 900 res = system(command); 901 mr_free(command); 902 903 if (res) { 904 log_to_screen("Please install '%s'. I cannot find it on your system.", fname); 905 log_to_screen("There may be hyperlink at http://www.mondorescue.org which"); 930 char command[MAX_STR_LEN * 2]; 931 char errorstr[MAX_STR_LEN]; 932 933 934 sprintf(command, "which %s > /dev/null 2> /dev/null", fname); 935 sprintf(errorstr, 936 "Please install '%s'. I cannot find it on your system.", 937 fname); 938 if (system(command)) { 939 log_to_screen(errorstr); 940 log_to_screen 941 ("There may be hyperlink at http://www.mondorescue.org/downloads.shtml which"); 906 942 log_to_screen("will take you to the relevant (missing) package."); 907 943 return (1); … … 1002 1038 { 1003 1039 /*@ Char buffers ** */ 1004 char *command = NULL;1005 char *tmp = NULL;1040 char command[MAX_STR_LEN * 2]; 1041 char tmp[MAX_STR_LEN]; 1006 1042 char old_pwd[MAX_STR_LEN]; 1007 int res = 0; 1008 1009 mvaddstr_and_log_it(g_currentY, 0,"Copying Mondo's core files to the scratch directory");1043 1044 mvaddstr_and_log_it(g_currentY, 0, 1045 "Copying Mondo's core files to the scratch directory"); 1010 1046 1011 1047 log_msg(4, "g_mondo_home='%s'", g_mondo_home); … … 1013 1049 find_and_store_mondoarchives_home(g_mondo_home); 1014 1050 } 1015 mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir); 1051 sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1052 bkpinfo->scratchdir); 1016 1053 1017 1054 log_msg(4, "command = %s", command); 1018 res = run_program_and_log_output(command, 1); 1019 mr_free(command); 1020 1021 if (res) { 1055 if (run_program_and_log_output(command, 1)) { 1022 1056 fatal_error("Failed to copy Mondo's stuff to scratchdir"); 1023 1057 } 1024 1058 1025 mr_asprintf(tmp, "%s/payload.tgz", g_mondo_home);1059 sprintf(tmp, "%s/payload.tgz", g_mondo_home); 1026 1060 if (does_file_exist(tmp)) { 1027 log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir); 1061 log_it("Untarring payload %s to scratchdir %s", tmp, 1062 bkpinfo->scratchdir); 1028 1063 if (getcwd(old_pwd, MAX_STR_LEN - 1)) { 1029 1064 // FIXME … … 1032 1067 // FIXME 1033 1068 } 1034 mr_asprintf(command, "tar -zxvf %s", tmp); 1035 res = run_program_and_log_output(command, FALSE); 1036 if (res) { 1037 mr_free(command); 1038 mr_free(tmp); 1069 sprintf(command, "tar -zxvf %s", tmp); 1070 if (run_program_and_log_output(command, FALSE)) { 1039 1071 fatal_error("Failed to untar payload"); 1040 1072 } 1041 mr_free(command);1042 1073 if (chdir(old_pwd)) { 1043 1074 // FIXME 1044 1075 } 1045 1076 } 1046 mr_free(tmp); 1047 1048 mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,bkpinfo->scratchdir);1077 1078 sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1079 bkpinfo->scratchdir); 1049 1080 1050 1081 if (run_program_and_log_output(command, FALSE)) { 1051 1082 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1052 1083 } 1053 mr_free(command); 1054 1055 mr_asprintf(tmp, "%s",call_program_and_get_last_line_of_output("which mondorestore"));1084 1085 strcpy(tmp, 1086 call_program_and_get_last_line_of_output("which mondorestore")); 1056 1087 if (!tmp[0]) { 1057 mr_free(tmp); 1058 fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1059 } 1060 1061 mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1062 mr_free(tmp); 1063 res = run_program_and_log_output(command, FALSE); 1064 if (res) { 1065 mr_free(command); 1088 fatal_error 1089 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1090 } 1091 sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1092 if (run_program_and_log_output(command, FALSE)) { 1066 1093 fatal_error("Failed to copy mondorestore to tmpdir"); 1067 1094 } 1068 mr_free(command); 1069 1070 mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1095 1096 sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1071 1097 paranoid_system(command); 1072 mr_free(command);1073 1098 1074 1099 if (bkpinfo->postnuke_tarball[0]) { 1075 mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1076 res = run_program_and_log_output(command, FALSE); 1077 mr_free(command); 1078 1079 if (res) { 1100 sprintf(command, "cp -f %s %s/post-nuke.tgz", 1101 bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1102 if (run_program_and_log_output(command, FALSE)) { 1080 1103 fatal_error("Unable to copy post-nuke tarball to tmpdir"); 1081 1104 } 1082 1105 } 1106 1083 1107 1084 1108 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1101 1125 1102 1126 /*@ buffers ******** */ 1103 char *netfs_dev = NULL;1104 char *netfs_client_hwaddr = NULL;1105 char *netfs_mount = NULL;1106 char *netfs_client_ipaddr = NULL;1107 char *netfs_client_netmask = NULL;1108 char *netfs_client_broadcast = NULL;1109 char *netfs_client_defgw = NULL;1110 char *netfs_server_ipaddr = NULL;1111 char *tmp = NULL;1112 char *command = NULL;1127 char netfs_dev[MAX_STR_LEN]; 1128 char netfs_mount[MAX_STR_LEN]; 1129 char netfs_client_hwaddr[MAX_STR_LEN]; 1130 char netfs_client_ipaddr[MAX_STR_LEN]; 1131 char netfs_client_netmask[MAX_STR_LEN]; 1132 char netfs_client_broadcast[MAX_STR_LEN]; 1133 char netfs_client_defgw[MAX_STR_LEN]; 1134 char netfs_server_ipaddr[MAX_STR_LEN]; 1135 char tmp[MAX_STR_LEN]; 1136 char command[MAX_STR_LEN * 2]; 1113 1137 1114 1138 /*@ pointers ***** */ 1115 1139 char *p; 1116 1140 1117 if (! bkpinfo->netfs_mount) {1118 fatal_error("No netfs_mount found !");1119 }1120 1121 1141 log_it("Storing Network configuration"); 1122 mr_asprintf(tmp, "%s", bkpinfo->netfs_mount);1142 strcpy(tmp, bkpinfo->netfs_mount); 1123 1143 p = strchr(tmp, ':'); 1124 1144 if (!p) { 1125 fatal_error("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1145 fatal_error 1146 ("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1126 1147 } 1127 1148 *(p++) = '\0'; 1128 mr_asprintf(netfs_server_ipaddr, "%s", tmp); 1129 mr_asprintf(netfs_mount, "%s", p); 1130 mr_free(tmp); 1149 strcpy(netfs_server_ipaddr, tmp); 1150 strcpy(netfs_mount, p); 1131 1151 1132 1152 /* BERLIOS : there is a bug #67 here as it only considers the first NIC */ 1133 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");1134 mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));1135 mr_free(command);1136 1137 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");1138 mr_asprintf(netfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));1139 mr_free(command);1140 1141 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");1142 mr_asprintf(netfs_client_netmask, "%s",call_program_and_get_last_line_of_output(command));1143 mr_free(command);1144 1145 mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");1146 mr_asprintf(netfs_client_broadcast, "%s",call_program_and_get_last_line_of_output(command));1147 mr_free(command);1148 1149 mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");1150 mr_asprintf(netfs_client_defgw, "%s",call_program_and_get_last_line_of_output(command));1151 mr_free(command);1152 1153 mr_asprintf(command, "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);1154 mr_asprintf(netfs_client_hwaddr, "%s"call_program_and_get_last_line_of_output(command));1155 mr_free(command);1156 1157 log_it("netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s",netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount);1153 sprintf(command, 1154 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1155 strcpy(netfs_dev, call_program_and_get_last_line_of_output(command)); 1156 sprintf(command, 1157 "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev); 1158 strcpy(netfs_client_hwaddr, call_program_and_get_last_line_of_output(command)); 1159 sprintf(command, 1160 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1161 strcpy(netfs_client_ipaddr, 1162 call_program_and_get_last_line_of_output(command)); 1163 sprintf(command, 1164 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1165 strcpy(netfs_client_netmask, 1166 call_program_and_get_last_line_of_output(command)); 1167 sprintf(command, 1168 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1169 strcpy(netfs_client_broadcast, 1170 call_program_and_get_last_line_of_output(command)); 1171 sprintf(command, 1172 "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1173 strcpy(netfs_client_defgw, 1174 call_program_and_get_last_line_of_output(command)); 1175 sprintf(tmp, 1176 "netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s", 1177 netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount); 1158 1178 if (strlen(netfs_dev) < 2) { 1159 fatal_error ("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");1160 }1161 1179 fatal_error 1180 ("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified."); 1181 } 1162 1182 /******** 1163 * If the Network device found above is a bonded device,1183 * If the Network device that found above is a bonded device, 1164 1184 * we need to replace it with an ethN device or the 1165 1185 * networking will not start during an Network restore. … … 1171 1191 if (!strncmp(netfs_dev, "bond", 4) || !strncmp(netfs_dev, "alb", 3) || !strncmp(netfs_dev, "aft", 3)) { 1172 1192 log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", netfs_dev); 1173 mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);1174 mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));1175 mr_free(command);1193 sprintf(command, 1194 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev); 1195 strcpy(netfs_dev, call_program_and_get_last_line_of_output(command)); 1176 1196 log_to_screen("Replacing it with %s\n", netfs_dev); 1177 1197 } 1178 1198 1179 mr_asprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);1199 sprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir); 1180 1200 write_one_liner_data_file(tmp, netfs_dev); 1181 mr_free(netfs_dev);1182 mr_free(tmp);1183 1184 mr_asprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir);1185 write_one_liner_data_file(tmp, netfs_client_hwaddr);1186 mr_free(netfs_client_hwaddr);1187 mr_free(tmp);1188 1189 mr_asprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir);1190 write_one_liner_data_file(tmp, netfs_client_ipaddr);1191 mr_free(netfs_client_ipaddr);1192 mr_free(tmp);1193 1194 mr_asprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir);1195 write_one_liner_data_file(tmp, netfs_client_netmask);1196 mr_free(netfs_client_netmask);1197 mr_free(tmp);1198 1199 mr_asprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir);1200 write_one_liner_data_file(tmp, netfs_client_broadcast);1201 mr_free(netfs_client_broadcast);1202 mr_free(tmp);1203 1204 mr_asprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir);1205 write_one_liner_data_file(tmp, netfs_client_defgw);1206 mr_free(netfs_client_defgw);1207 mr_free(tmp);1208 1209 mr_asprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir);1210 write_one_liner_data_file(tmp, netfs_server_ipaddr);1211 mr_free(netfs_server_ipaddr);1212 mr_free(tmp);1213 1214 mr_asprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir);1215 write_one_liner_data_file(tmp, bkpinfo->netfs_mount);1216 mr_free(tmp);1217 1218 if (bkpinfo->netfs_user) {1219 mr_asprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir);1220 write_one_liner_data_file(tmp, bkpinfo->netfs_user);1221 mr_free(tmp);1222 }1223 mr_asprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir);1224 write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir);1225 mr_free(tmp);1226 1227 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);1228 write_one_liner_data_file(tmp, bkpinfo->prefix);1229 mr_free(tmp);1230 1201 1231 1202 sprintf(tmp, "%s/NETFS-PROTO", bkpinfo->tmpdir); 1232 1203 write_one_liner_data_file(tmp, bkpinfo->netfs_proto); 1233 mr_free(tmp); 1234 1235 1204 1205 sprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir); 1206 write_one_liner_data_file(tmp, netfs_client_hwaddr); 1207 sprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1208 write_one_liner_data_file(tmp, netfs_client_ipaddr); 1209 sprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1210 write_one_liner_data_file(tmp, netfs_client_netmask); 1211 sprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1212 write_one_liner_data_file(tmp, netfs_client_broadcast); 1213 sprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1214 write_one_liner_data_file(tmp, netfs_client_defgw); 1215 sprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir); 1216 write_one_liner_data_file(tmp, netfs_server_ipaddr); 1217 sprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir); 1218 write_one_liner_data_file(tmp, bkpinfo->netfs_mount); 1219 if (bkpinfo->netfs_user) { 1220 sprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir); 1221 write_one_liner_data_file(tmp, bkpinfo->netfs_user); 1222 } 1223 sprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir); 1224 write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir); 1225 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1226 write_one_liner_data_file(tmp, bkpinfo->prefix); 1236 1227 log_it("Finished storing Network configuration"); 1237 1228 } 1229 1230 1231 1232 1238 1233 1239 1234 … … 1258 1253 { 1259 1254 /*@ buffers *************** */ 1260 char *tmp = NULL;1255 char tmp[MAX_STR_LEN]; 1261 1256 char *mds = NULL; 1262 1257 … … 1270 1265 1271 1266 log_it("Estimating number of media required..."); 1272 scratchLL = (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) + (long long) (size_of_all_biggiefiles_K()); 1267 scratchLL = 1268 (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) 1269 + (long long) (size_of_all_biggiefiles_K()); 1273 1270 scratchLL = (scratchLL / 1024) / bkpinfo->media_size; 1274 1271 scratchLL++; … … 1277 1274 } else if (bkpinfo->use_gzip) { 1278 1275 scratchLL = (scratchLL * 2) / 3; 1279 } else if (bkpinfo->use_lzma) {1280 scratchLL = (scratchLL * 2) / 3;1281 1276 } else { 1282 1277 scratchLL = scratchLL / 2; … … 1287 1282 if (scratchLL <= 1) { 1288 1283 mds = media_descriptor_string(bkpinfo->backup_media_type); 1289 mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds); 1284 sprintf(tmp, 1285 "Your backup will probably occupy a single %s. Maybe two.", mds); 1290 1286 mr_free(mds); 1291 1287 } else if (scratchLL > 4) { 1292 mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1))); 1288 sprintf(tmp, 1289 "Your backup will occupy one meeeeellion media! (maybe %s)", 1290 number_to_text((int) (scratchLL + 1))); 1293 1291 } else { 1294 mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1))); 1295 } 1296 if (scratchLL < 50) { 1292 sprintf(tmp, "Your backup will occupy approximately %s media.", 1293 number_to_text((int) (scratchLL + 1))); 1294 } 1295 if (!bkpinfo->image_devs[0] && (scratchLL < 50)) { 1297 1296 log_to_screen(tmp); 1298 1297 } 1299 mr_free(tmp); 1298 } 1299 1300 1301 /** 1302 * Get the last suffix of @p instr. 1303 * If @p instr was "httpd.log.gz", we would return "gz". 1304 * @param instr The filename to get the suffix of. 1305 * @return The suffix (without a dot), or "" if none. 1306 * @note The returned string points to static storage that will be overwritten with each call. 1307 */ 1308 char *sz_last_suffix(char *instr) 1309 { 1310 static char outstr[MAX_STR_LEN]; 1311 char *p; 1312 1313 p = strrchr(instr, '.'); 1314 if (!p) { 1315 outstr[0] = '\0'; 1316 } else { 1317 strcpy(outstr, p); 1318 } 1319 return (outstr); 1300 1320 } 1301 1321 … … 1309 1329 bool is_this_file_compressed(char *filename) 1310 1330 { 1311 char *do_not_compress_these = NULL;1312 char *tmp = NULL;1331 char do_not_compress_these[MAX_STR_LEN]; 1332 char tmp[MAX_STR_LEN]; 1313 1333 char *p; 1314 1334 char *q = NULL; … … 1319 1339 } 1320 1340 1321 mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);1341 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 1322 1342 if (!does_file_exist(tmp)) { 1323 mr_free(tmp);1324 1343 return (FALSE); 1325 1344 } 1326 1345 /* BERLIOS: This is just plain WRONG !! */ 1327 mr_asprintf(do_not_compress_these,"%s", last_line_of_file(tmp)); 1328 mr_free(tmp); 1346 strcpy(do_not_compress_these,last_line_of_file(tmp)); 1329 1347 1330 1348 for (p = do_not_compress_these; p != NULL; p++) { 1331 mr_asprintf(tmp, "%s", p);1349 strcpy(tmp, p); 1332 1350 if (strchr(tmp, ' ')) { 1333 1351 *(strchr(tmp, ' ')) = '\0'; 1334 1352 } 1335 1353 if (!strcmp(q, tmp)) { 1336 mr_free(tmp);1337 mr_free(do_not_compress_these);1338 1354 return (TRUE); 1339 1355 } … … 1341 1357 break; 1342 1358 } 1343 mr_free(tmp); 1344 } 1345 mr_free(do_not_compress_these); 1359 } 1346 1360 return (FALSE); 1347 1361 } -
branches/3.0/mondo/src/common/libmondo-files.h
r3188 r3192 42 42 43 43 44 int make_hole_for_dir(c onst char *outdir_fname);44 int make_hole_for_dir(char *outdir_fname); 45 45 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); 46 46 int read_one_liner_data_file(char *fname, char *contents); -
branches/3.0/mondo/src/common/libmondo-fork.c
r3188 r3192 8 8 #include "my-stuff.h" 9 9 #include "mr_mem.h" 10 #include "mr_str.h"11 10 #include "mondostructures.h" 12 11 #include "libmondo-fork.h" … … 39 38 /*@ buffers ***************************************************** */ 40 39 static char result[MAX_STR_LEN]; 41 char *tmp = NULL; 40 char *tmp; 41 char *p; 42 42 43 43 /*@ pointers **************************************************** */ 44 FILE *fin = NULL; 45 int res = 0; 44 FILE *fin; 46 45 47 46 /*@ initialize data ********************************************* */ 47 malloc_string(tmp); 48 48 result[0] = '\0'; 49 tmp[0] = '\0'; 49 50 50 51 /*@******************************************************************** */ … … 52 53 assert_string_is_neither_NULL_nor_zerolength(call); 53 54 if ((fin = popen(call, "r"))) { 54 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) { 55 for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL); 56 p = fgets(tmp, MAX_STR_LEN, fin)) { 55 57 if (strlen(tmp) > 1) { 56 58 strcpy(result, tmp); 57 59 } 58 mr_free(tmp);59 60 } 60 61 paranoid_pclose(fin); 61 62 } else { 62 log_OS_error("Unable to open resulting file");63 log_OS_error("Unable to popen call"); 63 64 } 64 65 strip_spaces(result); 65 mr_free(tmp); 66 return(result); 67 } 66 paranoid_free(tmp); 67 return (result); 68 } 69 70 71 72 68 73 69 74 … … 81 86 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs). 82 87 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number. 88 * @param logstub Unused. 83 89 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog. 84 90 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure). 91 * @bug @p logstub is unused. 85 92 */ 86 93 int … … 94 101 95 102 /*@ buffers *** */ 96 char *midway_call = NULL; 97 char *ultimate_call = NULL; 98 char *tmp = NULL; 99 100 char *cd_number_str = NULL; 101 char *command = NULL; 102 char *p= NULL; 103 char *midway_call, *ultimate_call, *tmp, *command, *incoming, 104 *old_stderr, *cd_number_str; 105 char *p; 103 106 char *tmp1 = NULL; 104 char *tmp2 = NULL;105 107 106 108 /*@*********** End Variables ***************************************/ … … 108 110 log_msg(3, "Starting"); 109 111 assert(bkpinfo != NULL); 112 // BERLIOS: doesn't work even if the string is correct ! 113 //assert_string_is_neither_NULL_nor_zerolength(basic_call); 110 114 assert_string_is_neither_NULL_nor_zerolength(isofile); 111 115 assert_string_is_neither_NULL_nor_zerolength(logstub); 112 116 if (!(midway_call = malloc(1200))) { 113 117 fatal_error("Cannot malloc midway_call"); … … 119 123 fatal_error("Cannot malloc tmp"); 120 124 } 125 if (!(command = malloc(1200))) { 126 fatal_error("Cannot malloc command"); 127 } 128 malloc_string(incoming); 129 malloc_string(old_stderr); 130 malloc_string(cd_number_str); 131 132 incoming[0] = '\0'; 133 old_stderr[0] = '\0'; 121 134 122 135 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) { … … 126 139 } 127 140 128 mr_asprintf(cd_number_str, "%d", cd_no);141 sprintf(cd_number_str, "%d", cd_no); 129 142 resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_"); 143 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_"); 144 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 130 145 log_msg(4, "basic call = '%s'", tmp1); 131 mr_free(tmp1);132 133 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");134 146 log_msg(4, "midway_call = '%s'", midway_call); 135 mr_free(cd_number_str); 136 137 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 147 log_msg(4, "tmp = '%s'", tmp); 138 148 log_msg(4, "ultimate call = '%s'", ultimate_call); 139 mr_asprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 140 141 log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity."); 142 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing); 149 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 150 151 log_to_screen 152 ("Please be patient. Do not be alarmed by on-screen inactivity."); 153 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", 154 what_i_am_doing); 155 strcpy(tmp, command); 143 156 if (bkpinfo->manual_cd_tray) { 144 mr_asprintf(tmp2, "%s", command); 145 p = strstr(tmp2, "2>>"); 157 p = strstr(tmp, "2>>"); 146 158 if (p) { 147 159 sprintf(p, " "); … … 149 161 p++; 150 162 } 151 for (; (*p != ' ') && (*p != '\0'); p++) {163 for (; *p != ' '; p++) { 152 164 *p = ' '; 153 165 } 154 166 } 155 mr_free(command);156 command = tmp2; 167 strcpy(command, tmp); 168 #ifndef _XWIN 157 169 if (!g_text_mode) { 158 170 newtSuspend(); 159 171 } 172 #endif 160 173 log_msg(1, "command = '%s'", command); 161 174 retval += system(command); … … 164 177 } 165 178 if (retval) { 166 popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created"); 179 log_msg(2, "Basic call '%s' returned an error.", tmp1); 180 popup_and_OK("Press ENTER to continue."); 181 popup_and_OK 182 ("mkisofs and/or cdrecord returned an error. CD was not created"); 167 183 } 168 184 } … … 170 186 else { 171 187 log_msg(3, "command = '%s'", command); 172 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command); 173 } 174 mr_free(command); 188 // yes_this_is_a_goto: 189 retval = 190 run_external_binary_with_percentage_indicator_NEW 191 (what_i_am_doing, command); 192 } 193 194 mr_free(tmp1); 175 195 paranoid_free(midway_call); 176 196 paranoid_free(ultimate_call); 177 197 paranoid_free(tmp); 198 paranoid_free(command); 199 paranoid_free(incoming); 200 paranoid_free(old_stderr); 201 paranoid_free(cd_number_str); 178 202 return (retval); 179 203 } … … 208 232 log_msg(1, "command = '%s'", command); 209 233 if (!g_text_mode) { 210 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command); 234 retval = run_external_binary_with_percentage_indicator_NEW 235 (what_i_am_doing, command); 211 236 } else { 212 237 retval += system(command); … … 252 277 return (1); 253 278 } 279 // if (debug_level == TRUE) { debug_level=5; } 280 281 // assert_string_is_neither_NULL_nor_zerolength(program); 254 282 255 283 if (debug_level <= g_loglevel) { … … 294 322 } 295 323 } 324 /* end of patch */ 296 325 strip_spaces(incoming); 297 326 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) { … … 313 342 } 314 343 } 344 // else 345 // { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); } 315 346 return (res); 316 347 } … … 337 368 338 369 /*@ buffers **************************************************** */ 370 char *tmp = NULL; 339 371 char *command = NULL; 340 char *lockfile = NULL;372 char lockfile[MAX_STR_LEN]; 341 373 342 374 /*@ end vars *************************************************** */ … … 344 376 assert_string_is_neither_NULL_nor_zerolength(basic_call); 345 377 346 mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir); 347 348 mr_asprintf(command, "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 378 sprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir); 379 380 mr_asprintf(command, 381 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", 382 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 349 383 open_evalcall_form(what_i_am_doing); 350 log_msg(2, "Executing %s", basic_call); 384 mr_asprintf(tmp, "Executing %s", basic_call); 385 log_msg(2, tmp); 386 mr_free(tmp); 351 387 352 388 if (!(fin = popen(command, "r"))) { 353 389 log_OS_error("Unable to popen-in command"); 354 log_to_screen("Failed utterly to call '%s'", command); 390 mr_asprintf(tmp, "Failed utterly to call '%s'", command); 391 log_to_screen(tmp); 392 mr_free(tmp); 355 393 mr_free(command); 356 mr_free(lockfile);357 394 return (1); 358 395 } 359 360 396 if (!does_file_exist(lockfile)) { 361 397 log_to_screen("Waiting for '%s' to start",command); … … 365 401 } 366 402 mr_free(command); 367 403 #ifdef _XWIN 404 /* This only can update when newline goes into the file, 405 but it's *much* prettier/faster on Qt. */ 406 while (does_file_exist(lockfile)) { 407 while (!feof(fin)) { 408 /* TODO: Dead and wrong code */ 409 if (!fgets(tmp, 512, fin)) 410 break; 411 log_to_screen(tmp); 412 } 413 usleep(500000); 414 } 415 #else 416 /* This works on Newt, and it gives quicker updates. */ 368 417 for (; does_file_exist(lockfile); sleep(1)) { 369 418 log_file_end_to_screen(MONDO_LOGFILE, ""); 370 419 update_evalcall_form(1); 371 420 } 372 421 #endif 373 422 /* Evaluate the status returned by pclose to get the exit code of the called program. */ 374 423 errno = 0; … … 385 434 close_evalcall_form(); 386 435 unlink(lockfile); 387 mr_free(lockfile);388 389 436 return (retval); 390 437 } … … 406 453 // if dir=='w' then copy from orig to archived 407 454 // if dir=='r' then copy from archived to orig 408 char *tmp = NULL; 409 char *tmp1 = NULL; 410 char *buf = NULL; 411 char *filestr = NULL; 455 char *tmp; 456 char *buf; 457 char filestr[MAX_STR_LEN]; 412 458 long int bytes_to_be_read, bytes_read_in, bytes_written_out = 413 459 0, bufcap, subsliceno = 0; … … 419 465 420 466 log_msg(5, "Opening."); 421 467 if (!(tmp = malloc(tmpcap))) { 468 fatal_error("Failed to malloc() tmp"); 469 } 470 tmp[0] = '\0'; 422 471 bufcap = 256L * 1024L; 423 472 if (!(buf = malloc(bufcap))) { … … 428 477 fin = f_orig; 429 478 fout = f_archived; 430 mr_asprintf(tmp, "%-64s", PIMP_START_SZ);479 sprintf(tmp, "%-64s", PIMP_START_SZ); 431 480 if (fwrite(tmp, 1, 64, fout) != 64) { 432 mr_free(tmp);433 481 fatal_error("Can't write the introductory block"); 434 482 } 435 mr_free(tmp);436 437 483 while (1) { 438 484 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin); … … 440 486 break; 441 487 } 442 mr_asprintf(tmp, "%-64ld", bytes_read_in);488 sprintf(tmp, "%-64ld", bytes_read_in); 443 489 if (fwrite(tmp, 1, 64, fout) != 64) { 444 mr_free(tmp);445 490 fatal_error("Cannot write introductory block"); 446 491 } 447 mr_free(tmp);448 449 492 log_msg(7, 450 493 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", 451 494 subsliceno, bytes_read_in, bytes_to_be_read); 452 495 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 453 mr_asprintf(tmp, "%-64ld", subsliceno);496 sprintf(tmp, "%-64ld", subsliceno); 454 497 if (fwrite(tmp, 1, 64, fout) != 64) { 455 mr_free(tmp);456 498 fatal_error("Cannot write post-thingy block"); 457 499 } 458 mr_free(tmp);459 500 log_msg(7, "Subslice #%d written OK", subsliceno); 460 501 subsliceno++; 461 502 } 462 mr_asprintf(tmp, "%-64ld", 0L);503 sprintf(tmp, "%-64ld", 0L); 463 504 if (fwrite(tmp, 1, 64L, fout) != 64L) { 464 mr_free(tmp);465 505 fatal_error("Cannot write final introductory block"); 466 506 } 467 mr_free(tmp);468 469 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);470 if (fwrite(tmp, 1, 64, fout) != 64) {471 mr_free(tmp);472 fatal_error("Can't write the final block");473 }474 mr_free(tmp);475 507 } else { 476 508 fin = f_archived; 477 509 fout = f_orig; 478 if (!(tmp1 = malloc(tmpcap))) { 479 fatal_error("Failed to malloc() tmp"); 480 } 481 if (fread(tmp1, 1, 64L, fin) != 64L) { 482 mr_free(tmp1); 510 if (fread(tmp, 1, 64L, fin) != 64L) { 483 511 fatal_error("Cannot read the introductory block"); 484 512 } 485 log_msg(5, "tmp1 is %s", tmp1); 486 if (!strstr(tmp1, PIMP_START_SZ)) { 487 mr_free(tmp1); 513 log_msg(5, "tmp is %s", tmp); 514 if (!strstr(tmp, PIMP_START_SZ)) { 488 515 fatal_error("Can't find intro blk"); 489 516 } 490 if (fread(tmp1, 1, 64L, fin) != 64L) { 491 mr_free(tmp1); 517 if (fread(tmp, 1, 64L, fin) != 64L) { 492 518 fatal_error("Cannot read introductory blk"); 493 519 } 494 bytes_to_be_read = atol(tmp 1);520 bytes_to_be_read = atol(tmp); 495 521 while (bytes_to_be_read > 0) { 496 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read); 522 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, 523 bytes_to_be_read); 497 524 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin); 498 525 if (bytes_read_in != bytes_to_be_read) { 499 mr_free(tmp1);500 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives.");526 fatal_error 527 ("Danger, WIll Robinson. Failed to read whole subvol from archives."); 501 528 } 502 529 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 503 if (fread(tmp1, 1, 64, fin) != 64) { 504 mr_free(tmp1); 530 if (fread(tmp, 1, 64, fin) != 64) { 505 531 fatal_error("Cannot read post-thingy block"); 506 532 } 507 if (atol(tmp1) != subsliceno) { 508 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1); 533 if (atol(tmp) != subsliceno) { 534 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", 535 subsliceno, atol(tmp), tmp); 509 536 } 510 537 log_msg(7, "Subslice #%ld read OK", subsliceno); 511 538 subsliceno++; 512 if (fread(tmp1, 1, 64, fin) != 64) { 513 mr_free(tmp1); 539 if (fread(tmp, 1, 64, fin) != 64) { 514 540 fatal_error("Cannot read introductory block"); 515 541 } 516 bytes_to_be_read = atol(tmp1); 517 } 518 } 542 bytes_to_be_read = atol(tmp); 543 } 544 } 545 546 // log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in); 519 547 520 548 if (direction == 'w') { 521 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);549 sprintf(tmp, "%-64s", PIMP_END_SZ); 522 550 if (fwrite(tmp, 1, 64, fout) != 64) { 523 mr_free(tmp);524 551 fatal_error("Can't write the final block"); 525 552 } 526 mr_free(tmp);527 553 } else { 528 log_msg(1, "tmpA is %s", tmp1); 529 if (!strstr(tmp1, PIMP_END_SZ)) { 530 if (fread(tmp1, 1, 64, fin) != 64) { 531 mr_free(tmp1); 554 log_msg(1, "tmpA is %s", tmp); 555 if (!strstr(tmp, PIMP_END_SZ)) { 556 if (fread(tmp, 1, 64, fin) != 64) { 532 557 fatal_error("Can't read the final block"); 533 558 } 534 log_msg(5, "tmpB is %s", tmp 1);535 if (!strstr(tmp 1, PIMP_END_SZ)) {536 mr_asprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);559 log_msg(5, "tmpB is %s", tmp); 560 if (!strstr(tmp, PIMP_END_SZ)) { 561 sprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir); 537 562 ftmp = fopen(filestr, "w"); 538 mr_free(filestr); 539 540 bytes_read_in = fread(tmp1, 1, 64, fin); 563 bytes_read_in = fread(tmp, 1, 64, fin); 541 564 log_msg(1, "bytes_read_in = %ld", bytes_read_in); 542 565 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } 543 566 if (fwrite(tmp, 1, bytes_read_in, ftmp)) { 544 567 fatal_error("Can't fwrite here"); 545 568 } 546 547 mr_asprintf(tmp, "I am here - %lld", (long long)ftello(fin));569 sprintf(tmp, "I am here - %lld", (long long)ftello(fin)); 570 // log_msg(0, tmp); 548 571 if (fread(tmp, 1, tmpcap, fin)) { 549 mr_free(tmp);550 572 fatal_error("Can't fread here"); 551 573 } 552 574 log_msg(0, "tmp = '%s'", tmp); 553 575 if (fwrite(tmp, 1, tmpcap, ftmp)) { 554 mr_free(tmp);555 576 fatal_error("Can't fwrite there"); 556 577 } 557 578 fclose(ftmp); 558 mr_free(tmp);559 579 fatal_error("Missing terminating block"); 560 580 } 561 581 } 562 582 } 563 mr_free(tmp1);564 583 565 584 paranoid_free(buf); 585 paranoid_free(tmp); 566 586 log_msg(3, "Successfully copied %ld bytes", bytes_written_out); 567 587 return (retval); … … 581 601 // BACKUP 582 602 int res = -1; 583 char *command = NULL;603 char*command; 584 604 585 605 if (!does_file_exist(input_device)) { … … 589 609 fatal_error("ntfsclone not found"); 590 610 } 591 mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device); 611 malloc_string(command); 612 sprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device); 592 613 res = run_program_and_log_output(command, 5); 593 mr_free(command); 594 614 paranoid_free(command); 595 615 unlink(output_fname); 596 616 return (res); … … 618 638 619 639 620 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) { 640 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) 641 { 621 642 622 643 /*@ int *************************************************************** */ … … 629 650 630 651 /*@ buffers *********************************************************** */ 631 char *command = NULL; 652 char *command; 653 char *title; 632 654 /*@ pointers ********************************************************** */ 633 655 static int chldres = 0; … … 640 662 *pchild_result = 999; 641 663 642 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 664 malloc_string(title); 665 malloc_string(command); 666 strcpy(title, tt); 667 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 643 668 log_msg(3, "command = '%s'", command); 644 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) { 669 if ((res = 670 pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, 671 (void *) command))) { 645 672 fatal_error("Unable to create an archival thread"); 646 673 } 647 674 648 675 log_msg(8, "Parent running"); 649 open_evalcall_form(tt); 650 676 open_evalcall_form(title); 651 677 for (sleep(1); command[0] != '\0'; sleep(1)) { 652 678 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE); 653 if (pcno < 0 || pcno > 100) {654 log_msg(8, "Weird pc# %d", pcno);679 if (pcno <= 0 || pcno > 100) { 680 log_msg(8, "Weird pc#"); 655 681 continue; 656 682 } … … 658 684 if (pcno <= 5 && last_pcno >= 40) { 659 685 close_evalcall_form(); 660 open_evalcall_form("Verifying..."); 686 strcpy(title, "Verifying..."); 687 open_evalcall_form(title); 661 688 } 662 689 if (counter++ >= 5) { … … 667 694 update_evalcall_form(percentage); 668 695 } 669 mr_free(command);670 671 696 log_file_end_to_screen(MONDO_LOGFILE, ""); 672 697 close_evalcall_form(); … … 678 703 } 679 704 log_msg(3, "Parent res = %d", res); 705 paranoid_free(command); 706 paranoid_free(title); 680 707 return (res); 681 708 } 709 710 682 711 683 712 … … 692 721 // RESTORE 693 722 int res = -1; 694 char *command = NULL;723 char *command; 695 724 696 725 if ( !find_home_of_exe("ntfsclone")) { 697 726 fatal_error("ntfsclone not found"); 698 727 } 699 mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo); 728 malloc_string(command); 729 sprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo); 700 730 res = run_program_and_log_output(command, 5); 701 mr_free(command);731 paranoid_free(command); 702 732 return (res); 703 733 } -
branches/3.0/mondo/src/common/libmondo-gui-EXT.h
r3188 r3192 1 1 /* libmondo-gui-EXT.h */ 2 2 3 #ifdef _XWIN 4 #include "X-specific-EXT.h" 5 #else 3 6 #include "newt-specific-EXT.h" 7 #endif -
branches/3.0/mondo/src/common/libmondo-gui.c
r3188 r3192 9 9 */ 10 10 11 #ifdef _XWIN 12 #include "X-specific.c" 13 #else 11 14 #include "newt-specific.c" 15 #endif -
branches/3.0/mondo/src/common/libmondo-gui.h
r3188 r3192 3 3 */ 4 4 5 #ifdef _XWIN 6 #include "X-specific.h" 7 #else 5 8 #include "newt-specific.h" 9 #endif -
branches/3.0/mondo/src/common/libmondo-mountlist.c
r3188 r3192 59 59 char tmp = NULL; 60 60 char device[MAX_STR_LEN]; 61 char mountpoint[MAX_STR_LEN]; 61 62 62 63 char *flaws_str = NULL; … … 99 100 continue; 100 101 } 102 strcpy(mountpoint, mountlist->el[pos].mountpoint); 101 103 /* is it too big? */ 102 104 if (curr_part_no > 'h') { … … 174 176 175 177 build_partition_name(device, drive, curr_part_no); 178 strcpy(mountpoint, mountlist->el[pos].mountpoint); 176 179 if (pos > 0 && !npos) { 177 180 /* gap in the partition list? */ … … 257 260 continue; 258 261 } 262 strcpy(mountpoint, mountlist->el[pos].mountpoint); 259 263 /* is it too big? */ 260 264 if (curr_part_no > 'h') { … … 323 327 if (amount_allocated > physical_drive_size) { 324 328 // Used to be +1, but what if you're 1 MB too high? 325 mr_asprintf(tmp, " %ld MB over-allocated on %s.",amount_allocated - physical_drive_size, drive); 329 mr_asprintf(tmp, " %ld MB over-allocated on %s.", 330 amount_allocated - physical_drive_size, drive); 326 331 log_it(tmp); 327 332 … … 343 348 344 349 /* Over-allocated the disk? Unallocated space on disk? */ 345 if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high? 346 { 347 mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive); 348 log_it(tmp); 349 mr_strcat(flaws_str, "%s", tmp); 350 mr_free(tmp); 351 res++; 352 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 353 mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive); 350 if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 351 mr_asprintf(tmp, " %ld MB unallocated on %s.", 352 physical_drive_size - amount_allocated, drive); 354 353 log_it(tmp); 355 354 mr_strcat(flaws_str, "%s", tmp); … … 406 405 goto endoffunc; 407 406 } else { 408 log_it(" %s (dm) will be setup later on", drive); 407 mr_asprintf(tmp, " %s (dm) will be setup later on", drive); 408 log_it(tmp); 409 mr_free(tmp); 409 410 } 410 411 } else { 411 log_it("%s is %ld MB", drive, physical_drive_size); 412 mr_asprintf(tmp, "%s is %ld MB", drive, physical_drive_size); 413 log_it(tmp); 414 mr_free(tmp); 412 415 } 413 416 … … 429 432 } else if (curr_part_no > 5 430 433 || (curr_part_no <= 4 && prev_part_no > 0)) { 431 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, prev_part_no, curr_part_no); 434 mr_asprintf(tmp, " Gap on %s between %d and %d.", drive, 435 prev_part_no, curr_part_no); 432 436 log_it(tmp); 433 437 mr_strcat(flaws_str, "%s", tmp); … … 439 443 part_table_fmt = which_partition_format(drive); 440 444 /* no spare primary partitions to help accommodate the logical(s)? */ 441 if ((curr_part_no >= 5 && prev_part_no == 4) && (strcmp(part_table_fmt, "MBR") == 0)) { 445 if ((curr_part_no >= 5 && prev_part_no == 4) 446 && (strcmp(part_table_fmt, "MBR") == 0)) { 442 447 mr_asprintf(tmp, " Partition 4 of %s is occupied.", drive); 443 448 log_it(tmp); … … 446 451 res++; 447 452 } 448 mr_free(part_table_fmt);449 450 453 /* does partition /dev/hdNX exist more than once in the mountlist? */ 451 454 for (i = 0, device_copies = 0; … … 456 459 } 457 460 if (device_copies > 1) { 458 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device); 461 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), 462 device); 459 463 if (!strstr(flaws_str, tmp)) { 460 464 log_it(tmp); … … 500 504 /* Over-allocated the disk? Unallocated space on disk? */ 501 505 if (amount_allocated > physical_drive_size + 1) { 502 mr_asprintf(tmp, " %ld MB over-allocated on %s.", amount_allocated - physical_drive_size, drive); 506 mr_asprintf(tmp, " %ld MB over-allocated on %s.", 507 amount_allocated - physical_drive_size, drive); 503 508 log_it(tmp); 504 509 mr_strcat(flaws_str, "%s", tmp); … … 506 511 res++; 507 512 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 508 mr_asprintf(tmp, " %ld MB unallocated on %s.", physical_drive_size - amount_allocated, drive); 513 mr_asprintf(tmp, " %ld MB unallocated on %s.", 514 physical_drive_size - amount_allocated, drive); 509 515 log_it(tmp); 510 516 mr_strcat(flaws_str, "%s", tmp); … … 564 570 (drivelist->el[i].device, 565 571 DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) { 566 log_it(" Not evaluating %s (I don't know how yet)", drivelist->el[i].device); 572 mr_asprintf(tmp, " Not evaluating %s (I don't know how yet)", drivelist->el[i].device); 573 log_it(tmp); 574 paranoid_free(tmp); 567 575 } else { 568 576 log_msg(8, "Evaluating drive #%d (%s) within mountlist", i, drivelist->el[i].device); … … 574 582 log_msg(8,"Adding: %s to flaws_str", tmp); 575 583 mr_strcat(flaws_str, "%s", tmp); 576 mr_free(tmp);584 paranoid_free(tmp); 577 585 } 578 586 } … … 594 602 mr_strcat(flaws_str, "%s", tmp); 595 603 log_msg(8,"Adding: %s to flaws_str", tmp); 596 mr_free(tmp);597 } 598 mr_free(curr_mountpoint);604 paranoid_free(tmp); 605 } 606 paranoid_free(curr_mountpoint); 599 607 } 600 608 … … 661 669 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 662 670 log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive); 663 mr_free(drive);671 paranoid_free(drive); 664 672 continue; 665 673 } … … 668 676 if (size == 0) { 669 677 log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive); 670 mr_free(drive);678 paranoid_free(drive); 671 679 continue; 672 680 } … … 676 684 /* memory allocation */ 677 685 truncdrive = truncate_to_drive_name(drive); 678 mr_free(drive);686 paranoid_free(drive); 679 687 680 688 log_msg(8, "drive truncated to %s", truncdrive); … … 725 733 int used_by = 0; 726 734 735 /*@ buffers ********************************************************* */ 736 char *tmp = NULL; 737 727 738 assert(output_list != NULL); 728 739 assert(mountlist != NULL); … … 734 745 for (i = 0; i < mountlist->entries; i++) { 735 746 if (strstr(mountlist->el[i].mountpoint, "raid")) { 736 used_by = which_raid_device_is_using_this_partition(raidlist, mountlist->el[i].device); 747 used_by = 748 which_raid_device_is_using_this_partition(raidlist, 749 mountlist->el[i]. 750 device); 737 751 if (used_by < 0) { 738 752 memcpy((void *) &output_list->el[items++], 739 753 (void *) &mountlist->el[i], 740 754 sizeof(struct mountlist_line)); 741 log_it("%s is available; user may choose to add it to raid device", output_list->el[items - 1].device); 755 mr_asprintf(tmp, "%s is available; user may choose to add it to raid device", output_list->el[items - 1].device); 756 log_it(tmp); 757 paranoid_free(tmp); 742 758 } 743 759 } … … 794 810 char *tmp = NULL; 795 811 char *p = NULL; 812 char *q = NULL; 796 813 797 814 int items = 0; … … 807 824 return (1); 808 825 } 826 malloc_string(incoming); 809 827 malloc_string(siz); 828 q = fgets(incoming, MAX_STR_LEN - 1, fin); 810 829 log_it("Loading mountlist..."); 811 mr_getline(incoming, fin); 812 while (!feof(fin)) { 830 while (!feof(fin) && (q != NULL)) { 813 831 #if linux 814 res = sscanf(incoming, "%s %s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz, mountlist->el[items].label); 832 res = sscanf(incoming, 833 "%s %s %s %s %s", 834 mountlist->el[items].device, 835 mountlist->el[items].mountpoint, 836 mountlist->el[items].format, 837 siz, mountlist->el[items].label); 815 838 if (res < 5) { 816 839 /* no label found */ … … 819 842 } 820 843 #elif __FreeBSD__ 821 res = sscanf(incoming, "%s %s %s %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, siz); 844 res = sscanf(incoming, 845 "%s %s %s %s", 846 mountlist->el[items].device, 847 mountlist->el[items].mountpoint, 848 mountlist->el[items].format, siz); 822 849 strcpy(mountlist->el[items].label,""); 823 850 #endif … … 832 859 !strcmp(mountlist->el[items].device, "devpts") 833 860 ) { 834 log_msg(1, "Ignoring %s in mountlist - not loading that line :) ", mountlist->el[items].device); 835 mr_free(incoming); 836 mr_getline(incoming, fin); 861 log_msg(1, 862 "Ignoring %s in mountlist - not loading that line :) ", 863 mountlist->el[items].device); 864 q = fgets(incoming, MAX_STR_LEN - 1, fin); 837 865 continue; 838 866 } … … 846 874 if (j < items) { 847 875 strcat(mountlist->el[items].device, "_dup"); 848 log_it("Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device); 876 mr_asprintf(tmp, "Duplicate entry in mountlist - renaming to %s", mountlist->el[items].device); 877 log_it(tmp); 878 paranoid_free(tmp); 849 879 } 850 880 mr_asprintf(tmp, "%s", mountlist->el[items].device); … … 857 887 *(p + 2) = *(p + 3); 858 888 } 859 log_it("It was %s; it is now %s", mountlist->el[items].device, tmp); 889 log_it("It was %s; it is now %s", 890 mountlist->el[items].device, tmp); 860 891 strcpy(mountlist->el[items].device, tmp); 861 892 } 862 893 paranoid_free(tmp); 863 894 864 log_it("%s %s %s %lld %s", mountlist->el[items].device, mountlist->el[items].mountpoint, mountlist->el[items].format, mountlist->el[items].size, mountlist->el[items].label); 895 log_it("%s %s %s %lld %s", 896 mountlist->el[items].device, 897 mountlist->el[items].mountpoint, 898 mountlist->el[items].format, 899 mountlist->el[items].size, 900 mountlist->el[items].label); 865 901 items++; 866 902 if (items >= MAX_MOUNTLIST_ENTRIES) { … … 869 905 } 870 906 } 871 mr_free(incoming); 872 mr_getline(incoming, fin); 873 } 874 mr_free(incoming); 907 q = fgets(incoming, MAX_STR_LEN - 1, fin); 908 } 875 909 paranoid_fclose(fin); 876 910 mountlist->entries = items; … … 879 913 log_it("%d entries in mountlist", items); 880 914 915 paranoid_free(incoming); 881 916 paranoid_free(siz); 882 917 return (0); … … 1015 1050 1016 1051 mountlist->el[b].size = size; 1017 mr_free(device);1018 mr_free(mountpoint);1019 mr_free(format);1052 paranoid_free(device); 1053 paranoid_free(mountpoint); 1054 paranoid_free(format); 1020 1055 } 1021 1056 -
branches/3.0/mondo/src/common/libmondo-raid.c
r3188 r3192 335 335 #ifdef __FreeBSD__ 336 336 int i, j; 337 char *org = NULL;338 337 339 338 fprintf(fout, "\nvolume %s\n", raidrec->volname); 340 339 for (i = 0; i < raidrec->plexes; ++i) { 340 char org[24]; 341 341 switch (raidrec->plex[i].raidlevel) { 342 342 case -1: 343 mr_asprintf(org, "concat");343 strcpy(org, "concat"); 344 344 break; 345 345 case 0: 346 mr_asprintf(org, "striped");346 strcpy(org, "striped"); 347 347 break; 348 348 case 5: 349 mr_asprintf(org, "raid5");349 strcpy(org, "raid5"); 350 350 break; 351 351 } 352 352 fprintf(fout, " plex org %s", org); 353 mr_free(org);354 355 353 if (raidrec->plex[i].raidlevel != -1) { 356 354 fprintf(fout, " %ik", raidrec->plex[i].stripesize); … … 359 357 360 358 for (j = 0; j < raidrec->plex[i].subdisks; ++j) { 361 fprintf(fout, " sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device); 359 fprintf(fout, " sd drive %s size 0\n", 360 raidrec->plex[i].sd[j].which_device); 362 361 } 363 362 } … … 428 427 int get_next_raidtab_line(FILE * fin, char *label, char *value) 429 428 { 430 char *incoming = NULL;429 char *incoming; 431 430 char *p; 432 431 char *q; 432 433 malloc_string(incoming); 433 434 assert(fin != NULL); 434 435 assert(label != NULL); … … 437 438 label[0] = value[0] = '\0'; 438 439 if (feof(fin)) { 440 paranoid_free(incoming); 439 441 return (1); 440 442 } 441 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 442 mr_strip_spaces(incoming); 443 for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL); 444 q = fgets(incoming, MAX_STR_LEN - 1, fin)) { 445 strip_spaces(incoming); 443 446 p = strchr(incoming, ' '); 444 447 if (strlen(incoming) < 3 || incoming[0] == '#' || !p) { 445 mr_free(incoming);446 448 continue; 447 449 } … … 452 454 strcpy(label, incoming); 453 455 strcpy(value, p); 454 mr_free(incoming);456 paranoid_free(incoming); 455 457 return (0); 456 458 } 457 mr_free(incoming);458 459 return (1); 459 460 } … … 472 473 { 473 474 FILE *fin; 475 char *tmp1 = NULL; 474 476 int items; 475 477 … … 502 504 503 505 if (get_option_state(argc, argv, "hotspare")) { 504 strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename); 505 strcpy(raidlist->spares.el[raidlist->spares.entries]. device, devname); 506 strcpy(raidlist->spares.el[raidlist->spares.entries].name, 507 drivename); 508 strcpy(raidlist->spares.el[raidlist->spares.entries]. 509 device, devname); 506 510 raidlist->spares.el[raidlist->spares.entries].index = 507 511 raidlist->disks.entries; 508 512 raidlist->spares.entries++; 509 513 } else { 510 strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename); 511 strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname); 514 strcpy(raidlist->disks.el[raidlist->disks.entries].name, 515 drivename); 516 strcpy(raidlist->disks.el[raidlist->disks.entries].device, 517 devname); 512 518 raidlist->disks.el[raidlist->disks.entries].index = 513 519 raidlist->disks.entries; … … 581 587 fclose(fin); 582 588 log_it("Raidtab loaded successfully."); 583 log_it("%d RAID devices in raidtab", raidlist->entries); 589 mr_asprintf(tmp1, "%d RAID devices in raidtab", raidlist->entries); 590 log_it(tmp1); 591 mr_free(tmp1); 584 592 return (0); 585 593 } … … 588 596 #else 589 597 590 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) { 591 592 FILE *fin = NULL; 593 char *label = NULL; 594 char *value = NULL; 598 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, 599 char *fname) 600 { 601 FILE *fin; 602 char *label; 603 char *value; 595 604 int items; 596 605 int v; … … 671 680 672 681 /*@ add mallocs * */ 682 char *tmp = NULL; 673 683 char *labelB; 674 684 char *valueB; … … 729 739 } 730 740 if (!disklist) { 731 log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 741 mr_asprintf(tmp, "Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 742 log_it(tmp); 743 mr_free(tmp); 732 744 } else { 733 745 index = atoi(valueB); … … 799 811 static char *argv[64]; 800 812 char **ap; 801 char *line = NULL; 802 803 mr_getline(line, f); 804 if (feof(f)) { 813 char *q; 814 char *line = (char *) malloc(MAX_STR_LEN); 815 816 if (!line) 817 errx(1, 818 "unable to allocate %i bytes of memory for `char *line' at %s:%i", 819 MAX_STR_LEN, __FILE__, __LINE__); 820 q = fgets(line, MAX_STR_LEN, f); 821 if (feof(f) && (q != NULL)) { 805 822 log_it("[GNVCL] Uh... I reached the EOF."); 806 823 return 0; … … 813 830 cnt++; 814 831 } 815 mr_free(line);816 832 817 833 if (strchr(argv[cnt - 1], '\n')) { … … 1103 1119 while((token = mr_strtok (string, delims, &lastpos))) { 1104 1120 if ((pos = strstr(token, "("))) { 1105 1121 type = *(pos+1); 1106 1122 } else { 1107 1123 type = ' '; 1108 1124 } 1109 1125 pos = strstr(token, "["); … … 1111 1127 switch(type) { 1112 1128 case ' ': // normal data disks 1113 1114 1115 1116 1117 1118 1129 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1); 1130 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1131 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp); 1132 mr_free(strtmp); 1133 raidlist->el[raidlist->entries].data_disks.entries++; 1134 break; 1119 1135 case 'S': // spare disks 1120 1121 1122 1123 1124 1125 1136 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1); 1137 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1138 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp); 1139 mr_free(strtmp); 1140 raidlist->el[raidlist->entries].spare_disks.entries++; 1141 break; 1126 1142 case 'F': // failed disks 1127 1128 1129 1130 1131 1132 1133 1143 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1); 1144 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1145 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp); 1146 mr_free(strtmp); 1147 raidlist->el[raidlist->entries].failed_disks.entries++; 1148 log_it("At least one failed disk found in RAID array.\n"); 1149 break; 1134 1150 default: // error 1135 1136 1137 1138 1139 1151 log_msg(1, "Unknown device type '%c'\n", type); 1152 mr_free(string); 1153 mr_free(token); 1154 return 1; 1155 break; 1140 1156 } 1141 1157 mr_free(token); … … 1146 1162 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1147 1163 if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) { 1148 index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;1164 index_min = raidlist->el[raidlist->entries].data_disks.el[i].index; 1149 1165 } 1150 1166 } 1151 1167 if (index_min > 0) { 1152 1168 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1153 1169 raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min; 1154 1170 } 1155 1171 } … … 1157 1173 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1158 1174 if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) { 1159 index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;1175 index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index; 1160 1176 } 1161 1177 } 1162 1178 if (index_min > 0) { 1163 1179 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1164 1180 raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 1165 1181 } 1166 1182 } … … 1168 1184 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1169 1185 if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) { 1170 index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;1186 index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index; 1171 1187 } 1172 1188 } 1173 1189 if (index_min > 0) { 1174 1190 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1175 1191 raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min; 1176 1192 } 1177 1193 } … … 1189 1205 } else { 1190 1206 while (*pos != ' ') { 1191 pos -= 1;1192 if (pos < string) {1193 1194 1195 1196 }1207 pos -= 1; 1208 if (pos < string) { 1209 log_it("String underflow!\n"); 1210 mr_free(string); 1211 return 1; 1212 } 1197 1213 } 1198 1214 raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1); … … 1208 1224 if (!(pos = strchr(string, '\%'))) { 1209 1225 if (strcasestr(string, "delayed")) { 1210 raidlist->el[raidlist->entries].progress = -1; // delayed (therefore, stuck at 0%)1226 raidlist->el[raidlist->entries].progress = -1; // delayed (therefore, stuck at 0%) 1211 1227 } else { 1212 raidlist->el[raidlist->entries].progress = 999; // not found1228 raidlist->el[raidlist->entries].progress = 999; // not found 1213 1229 } 1214 1230 } else { 1215 1231 while (*pos != ' ') { 1216 pos -= 1;1217 if (pos < string) {1218 1219 mr_free(string);1220 return 1;1221 }1232 pos -= 1; 1233 if (pos < string) { 1234 printf("ERROR: String underflow!\n"); 1235 mr_free(string); 1236 return 1; 1237 } 1222 1238 } 1223 1239 raidlist->el[raidlist->entries].progress = atoi(pos); 1224 1240 } 1225 1241 break; 1226 default: // error or IN PROGRESS1242 default: // error or IN PROGRESS 1227 1243 if (raidlist->el[raidlist->entries].progress != -1 && 1228 1244 raidlist->el[raidlist->entries].progress != 999) { … … 1230 1246 } 1231 1247 break; 1232 }1233 row++;1248 } 1249 row++; 1234 1250 } 1235 1251 // free string -
branches/3.0/mondo/src/common/libmondo-stream.c
r3188 r3192 138 138 } 139 139 sleep(1); 140 sync();140 paranoid_system("sync"); 141 141 sleep(1); 142 142 paranoid_pclose(g_tape_stream); 143 143 log_it("closein_tape() -- leaving"); 144 /* 145 for(i=0; i < g_tapecatalog->entries; i++) 146 { 147 log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux); 148 } 149 */ 144 150 if (!bkpinfo->please_dont_eject) { 145 151 eject_device(bkpinfo->media_device); … … 177 183 178 184 sleep(1); 179 sync();185 paranoid_system("sync"); 180 186 sleep(1); 181 187 log_it("closeout_tape() -- entering"); … … 222 228 g_tapecatalog->el[i].tape_posK); 223 229 } 230 // if (!bkpinfo->please_dont_eject) 231 // { eject_device(bkpinfo->media_device); } 224 232 paranoid_free(blk); 225 233 paranoid_free(g_tapecatalog); … … 258 266 char tmp[MAX_STR_LEN]; 259 267 char *command = NULL; 260 char *cdr_exe = NULL;268 char cdr_exe[MAX_STR_LEN]; 261 269 int res; 262 270 … … 264 272 dev[0] = siz[0] = '\0'; 265 273 if (find_home_of_exe("cdrecord")) { 266 mr_asprintf(cdr_exe, "cdrecord"); 267 } else { 268 mr_asprintf(cdr_exe, "dvdrecord"); 269 } 270 mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe); 271 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 274 strcpy(cdr_exe, "cdrecord"); 275 } else { 276 strcpy(cdr_exe, "dvdrecord"); 277 } 278 mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", 279 cdr_exe); 280 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 272 281 mr_free(command); 273 282 274 283 if (atoi(tmp) != 1) { 275 log_it("Either too few or too many tape streamers for me to detect..."); 284 log_it 285 ("Either too few or too many tape streamers for me to detect..."); 276 286 strcpy(dev, VANILLA_SCSI_TAPE); 277 mr_free(tmp);278 mr_free(cdr_exe);279 287 return 1; 280 288 } 281 mr_ free(tmp);282 283 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",cdr_exe);284 mr_asprintf(tmp, "%s",all_program_and_get_last_line_of_output(command));289 mr_asprintf(command, 290 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", 291 cdr_exe); 292 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 285 293 mr_free(command); 286 294 287 295 if (strlen(tmp) < 2) { 288 296 log_it("Could not find tape device"); 289 mr_free(cdr_exe);290 mr_free(tmp);291 297 return 1; 292 298 } 293 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe);294 mr_free(cdr_exe);295 296 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));299 mr_asprintf(command, 300 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", 301 cdr_exe); 302 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 297 303 mr_free(command); 298 304 … … 300 306 dev[strlen(dev) - 1] = '\0'; 301 307 strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN' 302 mr_free(tmp);303 304 308 res = 0; 305 309 if (!mt_says_tape_exists(dev)) { … … 320 324 } 321 325 322 if (dev) { 323 log_it("At this point, dev = %s and res = %d", dev, res); 324 } else { 325 log_it("At this point, dev is NULL and res = %d", dev, res); 326 } 327 328 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'")); 326 log_it("At this point, dev = %s and res = %d", dev, res); 327 328 strcpy(tmp, call_program_and_get_last_line_of_output("\ 329 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \ 330 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \ 331 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'")); 329 332 330 333 if (mt_says_tape_exists(dev)) { … … 332 335 } else { 333 336 log_it("Turning %s", dev); 334 mr_free(tmp); 335 mr_asprintf(tmp, "%s", (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 337 strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 336 338 sprintf(dev, "/dev/os%s", tmp); 337 339 log_it("...into %s", dev); … … 353 355 siz[0] = '\0'; 354 356 log_it("Warning - size of tape unknown"); 357 return (0); 355 358 } else { 356 359 strcpy(siz, tmp); 357 } 358 mr_free(tmp); 359 return (0); 360 } 360 return (0); 361 } 362 } 363 364 365 366 361 367 362 368 … … 473 479 log_it("Insisting on tape #%d", tapeno); 474 480 if (g_current_media_number != tapeno) { 475 mr_asprintf(tmp, "When the tape drive goes quiet, please insert volume %d in this series.", tapeno); 481 mr_asprintf(tmp, 482 "When the tape drive goes quiet, please insert volume %d in this series.", 483 tapeno); 476 484 popup_and_OK(tmp); 477 485 mr_free(tmp); … … 606 614 int res; 607 615 608 if (bkpinfo->media_device == NULL) {609 return(1);610 }611 612 616 if (strncmp(bkpinfo->media_device, "/dev/", 5)) { 613 log_msg(1, "Not using 'mt setblk'. This isn't an actual /dev entry."); 617 log_msg(1, 618 "Not using 'mt setblk'. This isn't an actual /dev entry."); 614 619 return (0); 615 620 } … … 682 687 int res = 0; 683 688 684 if (bkpinfo->media_device == NULL) {685 return(1);686 }687 688 689 log_it("Skipping OBDR headers"); 689 690 mr_asprintf(command, "mt -f %s rewind",bkpinfo->media_device); … … 711 712 char *command = NULL; 712 713 int res = 0; 713 714 if (bkpinfo->media_device == NULL) {715 return(1);716 }717 714 718 715 log_it("Creating OBDR headers"); … … 783 780 /*@ end vars *************************************************** */ 784 781 785 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 782 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 783 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 784 fatal_error("Cannot alloc mem for tape catalog"); 785 } 786 786 g_tapecatalog->entries = 0; 787 787 g_tape_posK = 0; … … 800 800 if (bkpinfo->media_device == NULL) { 801 801 log_it("Not able to skip OBDR - Restore will have to be done manually"); 802 return (1);803 802 } 804 803 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size); … … 809 808 make_hole_for_file(outfname); 810 809 810 // start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE); 811 811 log_it("Opening IN tape"); 812 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { 812 if (! 813 (g_tape_stream = 814 open_device_via_buffer(bkpinfo->media_device, 'r', 815 bkpinfo->internal_tape_block_size))) { 813 816 log_OS_error(g_tape_fifo); 814 817 log_to_screen("Cannot openin stream device"); … … 818 821 log_to_screen("Reading stream"); 819 822 log_it("stream device = '%s'", bkpinfo->media_device); 820 823 /* skip data disks */ 821 824 open_evalcall_form("Skipping data disks on stream"); 822 825 log_to_screen("Skipping data disks on stream"); … … 871 874 // FIXME 872 875 } 873 mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", outfname); 876 mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", 877 outfname); 874 878 paranoid_system(tmp); 875 879 mr_free(tmp); … … 899 903 /*@ end vars *************************************************** */ 900 904 901 if (cddev == NULL) {902 log_to_screen("Failed to openout NULL cddev");903 return (1);904 }905 905 /* add 'dummy' if testing */ 906 906 mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE); … … 942 942 return (0); 943 943 } 944 if (bkpinfo->media_device == NULL) { 945 log_it("Unable to openout NULL device"); 946 return(1); 947 } 948 g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog)); 944 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { 945 fatal_error("Cannot alloc mem for tape catalog"); 946 } 949 947 g_tapecatalog->entries = 0; 950 948 g_tape_posK = 0; … … 956 954 } 957 955 log_it("Opening OUT tape"); 958 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 956 if (! 957 (g_tape_stream = 958 open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 959 959 log_OS_error(g_tape_fifo); 960 960 log_to_screen("Cannot openin stream device"); … … 969 969 /** 970 970 * Copy a file from the opened stream (CD or tape) to @p outfile. 971 * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used. 971 972 * @param outfile The file to write to. 972 973 * @param size The size of the file in the input stream. … … 1030 1031 { 1031 1032 /*@ buffers ***************************************************** */ 1033 char *tmp = NULL; 1032 1034 char *datablock; 1033 1035 char *temp_fname; 1034 1036 char *temp_cksum; 1035 1037 char *actual_cksum = NULL; 1038 // char *pA, *pB; 1036 1039 1037 1040 /*@ int ********************************************************* */ … … 1075 1078 } 1076 1079 if (orig_size != temp_size && orig_size != -1) { 1077 log_to_screen("output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10); 1080 mr_asprintf(tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10); 1081 log_to_screen(tmp); 1082 mr_free(tmp); 1078 1083 } 1079 1084 if (ctrl_chr != BLK_START_FILE) { … … 1146 1151 } 1147 1152 if (strcmp(temp_cksum, actual_cksum)) { 1148 log_to_screen("actual cksum=%s; recorded cksum=%s", actual_cksum, temp_cksum); 1149 log_to_screen("%s (%ld K) is corrupt on tape", temp_fname, (long) orig_size >> 10); 1153 mr_asprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum, 1154 temp_cksum); 1155 log_to_screen(tmp); 1156 mr_free(tmp); 1157 1158 mr_asprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1159 (long) orig_size >> 10); 1160 log_to_screen(tmp); 1161 mr_free(tmp); 1162 1150 1163 retval++; 1151 1164 } … … 1191 1204 g_tape_posK += fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024; 1192 1205 } 1206 /* memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */ 1207 /* for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */ 1193 1208 memcpy((char *) plen, tempblock + 7001, sizeof(long long)); 1194 1209 if (strcmp(tempblock + 6000 + *pcontrol_char, STR_HEADER)) { … … 1196 1211 } 1197 1212 strcpy(filename, tempblock + 1000); 1213 /* strcpy(cksum,tempblock+5555);*/ 1214 /* log_it( "%s (reading) fname=%s, filesize=%ld K", 1215 marker_to_string (*pcontrol_char), filename, 1216 (long) ((*plen) >> 10)); 1217 */ 1198 1218 if (*pcontrol_char == BLK_ABORTED_BACKUP) { 1199 1219 log_to_screen("I can't verify an aborted backup."); … … 1343 1363 while (ctrl_chr != BLK_START_FILE) { 1344 1364 res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr); 1345 if (res) {1346 //FIXME1347 }1348 1365 if (ctrl_chr == BLK_START_FILE) { 1349 1366 break; … … 1366 1383 } 1367 1384 while (strcmp(pA, pB)) { 1368 log_msg(6, "Skipping %s (it's not %s)", temp_fname, the_file_I_was_reading); 1385 log_msg(6, "Skipping %s (it's not %s)", temp_fname, 1386 the_file_I_was_reading); 1369 1387 for (size = temp_size; size > 0; size -= bytes_to_write) { 1370 1388 bytes_to_write = … … 1403 1421 } 1404 1422 } 1405 log_msg(2, "Reading %s (it matches %s)", temp_fname, the_file_I_was_reading); 1423 log_msg(2, "Reading %s (it matches %s)", temp_fname, 1424 the_file_I_was_reading); 1406 1425 paranoid_free(temp_fname); 1407 1426 paranoid_free(datablock); … … 1425 1444 /*@ end vars *************************************************** */ 1426 1445 1427 if (bkpinfo->media_device == NULL) {1428 log_it("Unable to open in from NULL device");1429 return (1);1430 }1431 1432 1446 paranoid_pclose(g_tape_stream); 1433 1447 sync(); … … 1437 1451 insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too 1438 1452 log_it("Opening IN the next tape"); 1439 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'r', bkpinfo->internal_tape_block_size))) { 1453 if (! 1454 (g_tape_stream = 1455 open_device_via_buffer(bkpinfo->media_device, 'r', 1456 bkpinfo->internal_tape_block_size))) { 1440 1457 log_OS_error(g_tape_fifo); 1441 1458 log_to_screen("Cannot openin stream device"); … … 1470 1487 char *command = NULL; 1471 1488 1472 if (bkpinfo->media_device == NULL) {1473 log_it("Unable to open out from NULL device");1474 return (1);1475 }1476 1477 1489 paranoid_pclose(g_tape_stream); 1478 sync();1479 sync();1480 sync();1490 paranoid_system("sync"); 1491 paranoid_system("sync"); 1492 paranoid_system("sync"); 1481 1493 log_it("New tape requested."); 1482 1494 insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too 1483 1495 if (bkpinfo->backup_media_type == cdstream) { 1484 mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, MONDO_LOGFILE); 1496 mr_asprintf(command, 1497 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 1498 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, 1499 MONDO_LOGFILE); 1485 1500 log_it("Opening OUT to next CD with the command"); 1486 1501 log_it(command); … … 1495 1510 } else { 1496 1511 log_it("Opening OUT to next tape"); 1497 if (!(g_tape_stream = open_device_via_buffer(bkpinfo->media_device, 'w', bkpinfo->internal_tape_block_size))) { 1512 if (! 1513 (g_tape_stream = 1514 open_device_via_buffer(bkpinfo->media_device, 'w', 1515 bkpinfo->internal_tape_block_size))) { 1498 1516 log_OS_error(g_tape_fifo); 1499 1517 log_to_screen("Cannot openin stream device"); … … 1566 1584 /*@ pointers *************************************************** */ 1567 1585 FILE *fin; 1586 char *tmp = NULL; 1568 1587 1569 1588 /*@ long ******************************************************* */ … … 1583 1602 log_it("Data disks = %s", fname); 1584 1603 if (!does_file_exist(fname)) { 1585 log_to_screen("Cannot find %s", fname); 1604 mr_asprintf(tmp, "Cannot find %s", fname); 1605 log_to_screen(tmp); 1606 mr_free(tmp); 1586 1607 return (1); 1587 1608 } … … 1626 1647 { 1627 1648 /*@ buffers **************************************************** */ 1649 char *tmp = NULL; 1628 1650 char datablock[TAPE_BLOCK_SIZE]; 1629 1651 char *checksum = NULL; … … 1678 1700 p++; 1679 1701 } 1680 log_it("Writing file '%s' to tape (%ld KB)", p, (long) filesize >> 10); 1702 mr_asprintf(tmp, "Writing file '%s' to tape (%ld KB)", p, 1703 (long) filesize >> 10); 1704 log_it(tmp); 1705 mr_free(tmp); 1681 1706 write_header_block_to_stream(filesize, infile_basename, 1682 1707 BLK_START_FILE); … … 1750 1775 /*@ buffers **************************************************** */ 1751 1776 char tempblock[TAPE_BLOCK_SIZE]; 1777 char *tmp = NULL; 1752 1778 char *p; 1753 1779 … … 1768 1794 } 1769 1795 if (!g_tape_stream) { 1770 log_to_screen("You're not backing up to tape. Why write a tape header?"); 1796 log_to_screen 1797 ("You're not backing up to tape. Why write a tape header?"); 1771 1798 return (1); 1772 1799 } … … 1778 1805 memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t)); 1779 1806 strcpy(tempblock + 1000, filename); 1780 g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024; 1781 log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string(control_char), p, (long) length_of_incoming_file >> 10); 1807 g_tape_posK += 1808 fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, 1809 g_tape_stream) / 1024; 1810 mr_asprintf(tmp, "%s (fname=%s, size=%ld K)", 1811 marker_to_string(control_char), p, 1812 (long) length_of_incoming_file >> 10); 1813 log_msg(6, tmp); 1814 mr_free(tmp); 1782 1815 return (0); 1783 1816 } … … 1799 1832 void wrong_marker(int should_be, int it_is) 1800 1833 { 1801 log_to_screen("Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is)); 1834 /*@ buffer ***************************************************** */ 1835 char *tmp = NULL; 1836 1837 1838 /*@ end vars *************************************************** */ 1839 mr_asprintf(tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is)); 1840 log_to_screen(tmp); 1841 mr_free(tmp); 1802 1842 } 1803 1843 -
branches/3.0/mondo/src/common/libmondo-string.c
r3188 r3192 51 51 if (c && strncmp(c, "/disc", 5) == 0) { 52 52 /* yup it's devfs, return the "part" path */ 53 /* This strcpy is safe */54 53 strcpy(c + 1, "part"); 55 54 p = c + 5; … … 66 65 } 67 66 sprintf(p, "%d", partno); 68 return(partition); 69 } 67 return (partition); 68 } 69 70 71 72 73 74 75 76 77 78 79 70 80 71 81 … … 108 118 109 119 120 121 122 inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin) 123 { 124 char *p, *q; 125 126 for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) { 127 if (strchr("[]*?", *p)) { 128 *(q++) = '\\'; 129 } 130 } 131 *q = *p; // for the final '\0' 132 } 133 134 135 110 136 /** 111 137 * Add commas every third place in @p input. … … 129 155 tmp[j - 6] = ','; 130 156 strcpy(tmp + j - 5, pos_w_commas + j - 6); 157 // tmp[j-2] = ','; 158 // strcpy(tmp+j-1, pos_w_commas+j-3); 131 159 strcpy(pos_w_commas, tmp); 132 160 } … … 142 170 return (output); 143 171 } 172 173 174 175 176 177 178 144 179 145 180 … … 182 217 long outval; 183 218 int i; 184 char *tmp = NULL;219 char *tmp; 185 220 char ch; 186 221 … … 193 228 fatal_error("Please use integers only. No decimal points."); 194 229 } 195 196 mr_asprintf(tmp, "%s", incoming);230 malloc_string(tmp); 231 strcpy(tmp, incoming); 197 232 i = (int) strlen(tmp); 198 233 if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') { … … 203 238 tmp[i] = '\0'; 204 239 outval = atol(tmp); 205 mr_free(tmp);206 207 240 if (ch == 'g' || ch == 'G') { 208 241 outval = outval * 1024; … … 220 253 fatal_error("Integer overflow."); 221 254 } else if (ch != 'm' && ch != 'M') { 222 mr_asprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", incoming, ch); 255 sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')", 256 incoming, ch); 223 257 fatal_error(tmp); 224 258 } 259 paranoid_free(tmp); 225 260 return (outval); 226 261 } … … 481 516 482 517 input = malloc(2000); 518 // BERLIOS: seems to cause invalid errors 519 //assert_string_is_neither_NULL_nor_zerolength(ip); 520 assert_string_is_neither_NULL_nor_zerolength(token); 483 521 assert(value != NULL); 484 522 … … 519 557 /*@ buffers **************************************************** */ 520 558 static char output[MAX_STR_LEN]; 521 char *suffix = NULL;559 static char suffix[MAX_STR_LEN]; 522 560 523 561 /*@ end vars *************************************************** */ … … 525 563 assert_string_is_neither_NULL_nor_zerolength(path); 526 564 if (s[0] != '\0') { 527 mr_asprintf(suffix, ".%s", s);565 sprintf(suffix, ".%s", s); 528 566 } else { 529 mr_asprintf(suffix, "");530 } 531 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, suffix);532 mr_free(suffix);567 suffix[0] = '\0'; 568 } 569 sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno, 570 suffix); 533 571 return (output); 534 572 } … … 608 646 numA = atol(stringA + start_of_numbers_in_A); 609 647 numB = atol(stringB + start_of_numbers_in_B); 648 /* 649 sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB); 650 log_to_screen(tmp); 651 */ 610 652 return ((int) (numA - numB)); 611 653 } … … 733 775 in_out[i] = '\0'; 734 776 paranoid_free(tmp); 777 /* for(i=strlen(in_out); i>0 && in_out[i-1]<=32; i--) {in_out[i-1]='\0';} */ 735 778 } 736 779 … … 866 909 * @return The severity (1-3). 867 910 */ 868 int severity_of_difference(char *fn, char *out_reason) { 869 870 int sev = 3; 871 char *reason = NULL; 872 char *filename = NULL; 873 874 // out_reason might be null on purpose, so don't bomb if it is :) OK? 911 int severity_of_difference(char *fn, char *out_reason) 912 { 913 int sev; 914 char *reason; 915 char *filename; 916 917 malloc_string(reason); 918 malloc_string(filename); 919 // out_reason might be null on purpose, so don't bomb if it is :) OK? 875 920 assert_string_is_neither_NULL_nor_zerolength(fn); 876 921 if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) { 877 mr_asprintf(filename, "%s", fn + strlen(MNT_RESTORING));922 strcpy(filename, fn + strlen(MNT_RESTORING)); 878 923 } else if (fn[0] != '/') { 879 mr_asprintf(filename, "/%s", fn);924 sprintf(filename, "/%s", fn); 880 925 } else { 881 mr_asprintf(filename, "%s", fn); 882 } 883 884 mr_asprintf(reason, "Changed since backup. Consider running a differential backup in a day or two."); 885 926 strcpy(filename, fn); 927 } 928 929 sev = 3; 930 sprintf(reason, 931 "Changed since backup. Consider running a differential backup in a day or two."); 886 932 if (!strncmp(filename, "/var/", 5)) { 887 933 sev = 2; 888 mr_free(reason);889 mr_asprintf(reason,"/var's contents will change regularly, inevitably.");934 sprintf(reason, 935 "/var's contents will change regularly, inevitably."); 890 936 } 891 937 if (!strncmp(filename, "/home", 5)) { 892 938 sev = 2; 893 mr_free(reason);894 mr_asprintf(reason,"It's in your /home directory. Therefore, it is important.");939 sprintf(reason, 940 "It's in your /home directory. Therefore, it is important."); 895 941 } 896 942 if (!strncmp(filename, "/usr/", 5)) { 897 943 sev = 3; 898 mr_free(reason);899 mr_asprintf(reason,"You may have installed/removed software during the backup.");944 sprintf(reason, 945 "You may have installed/removed software during the backup."); 900 946 } 901 947 if (!strncmp(filename, "/etc/", 5)) { 902 948 sev = 3; 903 mr_free(reason);904 mr_asprintf(reason,"Do not edit config files while backing up your PC.");949 sprintf(reason, 950 "Do not edit config files while backing up your PC."); 905 951 } 906 952 if (!strcmp(filename, "/etc/adjtime") 907 953 || !strcmp(filename, "/etc/mtab")) { 908 954 sev = 1; 909 mr_free(reason); 910 mr_asprintf(reason, "This file changes all the time. It's OK."); 955 sprintf(reason, "This file changes all the time. It's OK."); 911 956 } 912 957 if (!strncmp(filename, "/root/", 6)) { 913 958 sev = 3; 914 mr_free(reason); 915 mr_asprintf(reason, "Were you compiling/editing something in /root?"); 959 sprintf(reason, "Were you compiling/editing something in /root?"); 916 960 } 917 961 if (!strncmp(filename, "/root/.", 7)) { 918 962 sev = 2; 919 mr_free(reason); 920 mr_asprintf(reason, "Temp or 'dot' files changed in /root."); 963 sprintf(reason, "Temp or 'dot' files changed in /root."); 921 964 } 922 965 if (!strncmp(filename, "/var/lib/", 9)) { 923 966 sev = 2; 924 mr_free(reason); 925 mr_asprintf(reason, "Did you add/remove software during backing?"); 967 sprintf(reason, "Did you add/remove software during backing?"); 926 968 } 927 969 if (!strncmp(filename, "/var/lib/rpm", 12)) { 928 970 sev = 3; 929 mr_free(reason); 930 mr_asprintf(reason, "Did you add/remove software during backing?"); 971 sprintf(reason, "Did you add/remove software during backing?"); 931 972 } 932 973 if (!strncmp(filename, "/var/lib/slocate", 16)) { 933 974 sev = 1; 934 mr_free(reason);935 mr_asprintf(reason,"The 'update' daemon ran during backup. This does not affect the integrity of your backup.");975 sprintf(reason, 976 "The 'update' daemon ran during backup. This does not affect the integrity of your backup."); 936 977 } 937 978 if (!strncmp(filename, "/var/log/", 9) … … 939 980 || !strcmp(filename + strlen(filename) - 4, ".log")) { 940 981 sev = 1; 941 mr_free(reason);942 mr_asprintf(reason,"Log files change frequently as the computer runs. Fret not.");982 sprintf(reason, 983 "Log files change frequently as the computer runs. Fret not."); 943 984 } 944 985 if (!strncmp(filename, "/var/spool", 10)) { 945 986 sev = 1; 946 mr_free(reason);947 mr_asprintf(reason,"Background processes or printers were active. This does not affect the integrity of your backup.");987 sprintf(reason, 988 "Background processes or printers were active. This does not affect the integrity of your backup."); 948 989 } 949 990 if (!strncmp(filename, "/var/spool/mail", 10)) { 950 991 sev = 2; 951 mr_free(reason); 952 mr_asprintf(reason, "Mail was sent/received during backup."); 992 sprintf(reason, "Mail was sent/received during backup."); 953 993 } 954 994 if (filename[strlen(filename) - 1] == '~') { 955 995 sev = 1; 956 mr_free(reason);957 mr_asprintf(reason,"Backup copy of another file which was modified recently.");996 sprintf(reason, 997 "Backup copy of another file which was modified recently."); 958 998 } 959 999 if (strstr(filename, "cache")) { 960 1000 sev = 1; 961 mr_free(reason);962 mr_asprintf(reason,"Part of a cache of data. Caches change from time to time. Don't worry.");1001 sprintf(reason, 1002 "Part of a cache of data. Caches change from time to time. Don't worry."); 963 1003 } 964 1004 if (!strncmp(filename, "/var/run/", 9) … … 967 1007 || strstr(filename, "/.Xauthority")) { 968 1008 sev = 1; 969 mr_free(reason);970 mr_asprintf(reason,"Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");1009 sprintf(reason, 1010 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."); 971 1011 } 972 1012 if (out_reason) { 973 1013 strcpy(out_reason, reason); 974 1014 } 975 mr_free(filename);976 mr_free(reason);1015 paranoid_free(filename); 1016 paranoid_free(reason); 977 1017 return (sev); 978 1018 } … … 1024 1064 /*@ buffers ******************************************* */ 1025 1065 static char outstr[MAX_STR_LEN]; 1026 char *pos_w_commas = NULL;1066 char *pos_w_commas, *tmp; 1027 1067 char *mds = NULL; 1028 char *tmp = NULL;1029 1068 1030 1069 assert(bkpinfo != NULL); 1031 1032 if (bkpinfo->media_size <= 0) { 1033 mr_asprintf(tmp, "%lld", g_tape_posK); 1034 mr_asprintf(pos_w_commas, "%s", commarize(tmp)); 1035 mr_free(tmp); 1036 sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas); 1037 mr_free(pos_w_commas); 1070 malloc_string(pos_w_commas); 1071 malloc_string(tmp); 1072 sprintf(tmp, "%lld", g_tape_posK); 1073 strcpy(pos_w_commas, commarize(tmp)); 1074 1075 1076 1077 if (bkpinfo->media_size <= 0) 1078 // { fatal_error( "percentage_media_full_comment() - unknown media size"); } 1079 { 1080 sprintf(outstr, "Volume %d: %s kilobytes archived so far", 1081 g_current_media_number, pos_w_commas); 1038 1082 return (outstr); 1039 1083 } 1040 1084 1041 1085 /* update screen */ 1042 1086 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1043 1087 percentage = (int) (g_tape_posK / 10 / bkpinfo->media_size); … … 1047 1091 sprintf(outstr, "Volume %d: [", g_current_media_number); 1048 1092 } else { 1049 percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1093 percentage = 1094 (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size); 1050 1095 mds = media_descriptor_string(bkpinfo->backup_media_type); 1051 1096 sprintf(outstr, "%s %d: [", mds, g_current_media_number); … … 1060 1105 j = (int) strlen(outstr); 1061 1106 sprintf(outstr + j, "] %d%% used", percentage); 1107 paranoid_free(pos_w_commas); 1108 paranoid_free(tmp); 1062 1109 return (outstr); 1063 1110 } -
branches/3.0/mondo/src/common/libmondo-tools.c
r3188 r3192 30 30 31 31 extern int g_tape_buffer_size_MB; 32 extern char *g_serial_string; 32 33 extern bool g_text_mode; 33 34 extern int g_currentY; 34 35 extern int g_current_media_number; 35 36 extern char *MONDO_LOGFILE; 36 extern char *g_serial_string;37 37 38 38 /* Reference to global bkpinfo */ … … 113 113 return; 114 114 } 115 #ifndef _XWIN 115 116 if (!g_text_mode) 116 117 newtSuspend(); 118 #endif 117 119 printf("ASSERTION FAILED: `%s'\n", exp); 118 120 printf("\tat %s:%d in %s\n\n", file, line, function); … … 161 163 getchar(); // skip \n 162 164 165 #ifndef _XWIN 163 166 if (!g_text_mode) 164 167 newtResume(); 168 #endif 165 169 } 166 170 … … 171 175 void clean_up_KDE_desktop_if_necessary(void) 172 176 { 173 char *tmp = NULL; 174 175 mr_asprintf(tmp, "for i in `find /root /home -maxdepth 2 -type d -name Desktop -maxdepth 2`; do file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } else { print $0;};}' $file.old > $file ; fi ; done"); 177 char *tmp; 178 179 malloc_string(tmp); 180 strcpy(tmp, 181 "for i in `find /root /home -maxdepth 2 -type d -name Desktop`; do \ 182 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \ 183 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \ 184 else { print $0;};}' $file.old > $file ; fi ; done"); 176 185 run_program_and_log_output(tmp, 5); 177 mr_free(tmp);186 paranoid_free(tmp); 178 187 } 179 188 … … 223 232 double get_kernel_version(void) 224 233 { 225 char *p = NULL; 226 char *tmp = NULL; 234 char *p, tmp[200]; 227 235 double d; 228 236 #ifdef __FreeBSD__ … … 230 238 d = 5.2; // :-) 231 239 #else 232 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));240 strcpy(tmp, call_program_and_get_last_line_of_output("uname -r")); 233 241 p = strchr(tmp, '.'); 234 242 if (p) { … … 241 249 } 242 250 } 251 // log_msg(1, "tmp = '%s'", tmp); 243 252 d = atof(tmp); 244 mr_free(tmp);245 253 #endif 246 254 log_msg(1, "g_kernel_version = %f", d); … … 249 257 250 258 259 260 261 251 262 /** 252 263 * Get the current time. … … 257 268 return (long) time((void *) 0); 258 269 } 270 271 272 273 274 259 275 260 276 … … 352 368 char *mondo_mkisofs_sz = NULL; 353 369 char *command = NULL; 354 char *hostname = NULL; 370 char *mtpt; 371 char *hostname; 355 372 char *isofs_cmd = NULL; 356 373 char *ip_address = NULL; 357 374 int retval = 0; 358 375 char *colon; 359 char *cdr_exe = NULL;376 char *cdr_exe; 360 377 char *tmp = NULL; 361 char *p = NULL; 362 char *call_before_iso_user = NULL; 378 char call_before_iso_user[MAX_STR_LEN] = "\0"; 379 /* 380 long avm = 0; 381 int rdsiz_MB; 382 */ 363 383 char *iso_dev = NULL; 364 384 char *iso_mnt = NULL; … … 367 387 368 388 assert(bkpinfo != NULL); 369 389 malloc_string(mtpt); 390 malloc_string(hostname); 391 malloc_string(cdr_exe); 370 392 bkpinfo->optimal_set_size = 371 393 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 378 400 } 379 401 log_msg(1, "Tape"); 380 if (bkpinfo->media_device == NULL) {381 return(1);382 }383 402 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 384 403 log_msg(1, "tmp = '%s'", tmp); … … 410 429 strcpy(bkpinfo->zip_exe, "gzip"); 411 430 strcpy(bkpinfo->zip_suffix, "gz"); 412 } else if (bkpinfo->use_lzma) {413 strcpy(bkpinfo->zip_exe, "lzma");414 strcpy(bkpinfo->zip_suffix, "lzma");415 431 } else if (bkpinfo->compression_level != 0) { 416 432 strcpy(bkpinfo->zip_exe, "bzip2"); … … 424 440 if (bkpinfo->backup_media_type == dvd) { 425 441 if (find_home_of_exe("growisofs")) { 426 mr_asprintf(cdr_exe, "growisofs");442 strcpy(cdr_exe, "growisofs"); 427 443 } // unlikely to be used 428 444 else { … … 446 462 } 447 463 #endif 448 else { 464 else 465 { 449 466 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 450 467 } 451 468 if (bkpinfo->manual_cd_tray) { 469 paranoid_free(mondo_mkisofs_sz); 452 470 fatal_error("Manual CD tray + DVD not supported yet."); 453 471 // -m isn't supported by growisofs, BTW... … … 457 475 mondo_mkisofs_sz, 458 476 "", bkpinfo->media_device); 459 }460 mr_free(mondo_mkisofs_sz);477 paranoid_free(mondo_mkisofs_sz); 478 } 461 479 if (getenv ("SUDO_COMMAND")) { 462 480 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); … … 468 486 mr_free(command); 469 487 } 470 log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso); 488 log_msg(2, "call_make_iso (DVD res) is ... %s", 489 bkpinfo->call_make_iso); 471 490 } // end of DVD code 472 491 … … 485 504 } 486 505 if (find_home_of_exe("cdrecord")) { 487 mr_asprintf(cdr_exe, "cdrecord");506 strcpy(cdr_exe, "cdrecord"); 488 507 } else if (find_home_of_exe("dvdrecord")) { 489 mr_asprintf(cdr_exe, "dvdrecord");508 strcpy(cdr_exe, "dvdrecord"); 490 509 } else { 491 510 fatal_error("Please install either cdrecord or dvdrecord."); … … 525 544 mondo_mkisofs_sz, bkpinfo->tmpdir); 526 545 } else { 527 mr_asprintf(call_before_iso_user, "%s", bkpinfo->call_before_iso); 528 sprintf(bkpinfo->call_before_iso, "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 529 mr_free(call_before_iso_user); 546 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN); 547 sprintf (bkpinfo->call_before_iso, 548 "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", 549 mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 530 550 } 531 551 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso); 532 sprintf(bkpinfo->call_make_iso, "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed, bkpinfo->tmpdir); 552 sprintf(bkpinfo->call_make_iso, 553 "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, 554 cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", 555 extra_cdrom_params, bkpinfo->media_device, 556 bkpinfo->cdrw_speed, bkpinfo->tmpdir); 533 557 } else { 534 sprintf(bkpinfo->call_make_iso, "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", mondo_mkisofs_sz, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed); 535 } 536 mr_free(cdr_exe); 537 mr_free(mondo_mkisofs_sz); 538 mr_free(extra_cdrom_params); 558 sprintf(bkpinfo->call_make_iso, 559 "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", 560 mondo_mkisofs_sz, cdr_exe, 561 (bkpinfo->please_dont_eject) ? " " : "-eject", 562 extra_cdrom_params, bkpinfo->media_device, 563 bkpinfo->cdrw_speed); 564 } 565 paranoid_free(mondo_mkisofs_sz); 566 paranoid_free(extra_cdrom_params); 539 567 } // end of CD code 540 568 … … 549 577 550 578 log_it("isodir = %s", bkpinfo->isodir); 551 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir); 579 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", 580 bkpinfo->isodir); 552 581 log_it("command = %s", command); 582 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 553 583 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 554 log_it("res of it = %s", iso_dev);555 584 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 556 write_one_liner_data_file(tmp, iso_dev);585 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 557 586 mr_free(tmp); 558 587 mr_free(command); … … 562 591 563 592 log_it("command = %s", command); 593 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 564 594 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 565 log_it("res of it = %s", iso_mnt);566 595 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 567 write_one_liner_data_file(tmp, iso_mnt);596 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 568 597 mr_free(tmp); 569 598 mr_free(command); … … 583 612 } 584 613 } 614 mr_free(iso_tmp); 585 615 mr_free(iso_mnt); 586 mr_free(iso_tmp);587 616 588 617 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); … … 603 632 604 633 if (bkpinfo->backup_media_type == netfs) { 605 if (bkpinfo->netfs_mount) { 606 mr_asprintf(hostname, "%s", bkpinfo->netfs_mount); 607 } else { 608 log_it("netfs_mount is NULL"); 609 retval++; 610 mr_asprintf(hostname, ""); 611 } 634 strcpy(hostname, bkpinfo->netfs_mount); 612 635 colon = strchr(hostname, ':'); 613 636 if (!colon) { … … 628 651 } 629 652 if (!hent) { 630 log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno)); 653 log_it("Can't resolve Network mount (%s): %s", hostname, 654 hstrerror(h_errno)); 631 655 retval++; 632 656 } else { … … 634 658 mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':')); 635 659 strcpy(bkpinfo->netfs_mount, ip_address); 636 mr_free(ip_address);660 paranoid_free(ip_address); 637 661 } 638 662 } 639 mr_free(hostname);640 663 store_netfs_config(); 641 664 } … … 645 668 fprintf(stderr, "Type 'man mondoarchive' for help.\n"); 646 669 } 647 if (bkpinfo->include_paths == NULL) { 648 mr_asprintf(bkpinfo->include_paths, "/"); 649 } 670 if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) { 671 log_it("tmpdir or scratchdir are blank/missing"); 672 retval++; 673 } 674 if (bkpinfo->include_paths[0] == '\0') { 675 // fatal_error ("Why no backup path?"); 676 strcpy(bkpinfo->include_paths, "/"); 677 } 678 chmod(bkpinfo->scratchdir, 0700); 650 679 g_backup_media_type = bkpinfo->backup_media_type; 680 paranoid_free(mtpt); 681 paranoid_free(hostname); 682 paranoid_free(cdr_exe); 651 683 return (retval); 652 684 } … … 672 704 if (bkpinfo->disaster_recovery) { 673 705 if (!does_nonMS_partition_exist()) { 674 fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive."); 706 fatal_error 707 ("I am in disaster recovery mode\nPlease don't run mondoarchive."); 675 708 } 676 709 } … … 680 713 paranoid_free(tmp); 681 714 if (find_and_store_mondoarchives_home(g_mondo_home)) { 682 fprintf(stderr, "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 715 fprintf(stderr, 716 "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 683 717 res++; 684 718 return (res); … … 689 723 } 690 724 g_current_media_number = 1; 691 bkpinfo->postnuke_tarball[0] = '\0';725 bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] = '\0'; 692 726 return (res); 693 727 } … … 738 772 if (p == NULL) { 739 773 log_it("Failed to create global tmp directory %s for Mondo.",tmp); 740 mr_free(tmp);741 774 finish(-1); 742 775 } 743 mr_free(tmp);744 745 776 strcpy(bkpinfo->tmpdir,p); 746 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);777 paranoid_free(tmp); 747 778 748 779 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); … … 786 817 } 787 818 strcpy(bkpinfo->scratchdir,p); 788 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);789 819 paranoid_free(tmp); 790 820 … … 802 832 { 803 833 int i; 804 log_msg(1, "Initializing bkpinfo"); 805 834 835 log_msg(1, "Hi"); 806 836 assert(bkpinfo != NULL); 807 837 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); … … 817 847 bkpinfo->use_lzo = FALSE; 818 848 bkpinfo->use_gzip = FALSE; 819 bkpinfo-> use_lzma = FALSE;849 bkpinfo->do_not_compress_these[0] = '\0'; 820 850 bkpinfo->verify_data = FALSE; 821 851 bkpinfo->backup_data = FALSE; … … 823 853 bkpinfo->use_star = FALSE; 824 854 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 825 826 /* We need tmpdir as early as possible for further function calls */ 827 bkpinfo->tmpdir = NULL; // Really setup after 828 setup_tmpdir(NULL); 829 setup_scratchdir(NULL); 830 831 bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode(); 855 bkpinfo->disaster_recovery = 856 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 832 857 if (bkpinfo->disaster_recovery) { 833 858 strcpy(bkpinfo->isodir, "/"); … … 836 861 } 837 862 strcpy(bkpinfo->prefix, STD_PREFIX); 863 setup_tmpdir(NULL); 864 setup_scratchdir(NULL); 865 838 866 bkpinfo->optimal_set_size = 0; 839 bkpinfo->backup_media_type = none;867 strcpy(bkpinfo->include_paths, "/"); 840 868 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 841 bkpinfo->exclude_paths = NULL; 842 bkpinfo->include_paths = NULL; 869 bkpinfo->include_paths[0] = '\0'; 843 870 bkpinfo->exclude_devs = NULL; 844 871 bkpinfo->restore_path[0] = '\0'; … … 852 879 bkpinfo->netfs_user = NULL; 853 880 bkpinfo->netfs_remote_dir[0] = '\0'; 881 bkpinfo->exclude_paths = NULL; 882 bkpinfo->subdir = NULL; 854 883 bkpinfo->postnuke_tarball[0] = '\0'; 855 bkpinfo->subdir = NULL;856 884 bkpinfo->wipe_media_first = FALSE; 857 885 bkpinfo->differential = 0; … … 866 894 867 895 896 897 868 898 /** 869 899 * Get the remaining free space (in MB) on @p partition. … … 886 916 mr_free(command); 887 917 888 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition); 918 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 919 partition); 889 920 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 890 921 mr_free(command); … … 926 957 if (system("which mkfs.vfat 2> /dev/null 1> /dev/null") 927 958 && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) { 928 log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 929 run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 930 } 931 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 959 log_it 960 ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 961 run_program_and_log_output 962 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 963 } 964 mr_asprintf(tmp, "%s", 965 call_program_and_get_last_line_of_output 966 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 932 967 if (atol(tmp) < 35000) { 933 968 retval++; … … 935 970 } 936 971 if (atol(tmp) < 66000) { 937 log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 972 log_to_screen 973 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 938 974 } 939 975 mr_free(tmp); … … 990 1026 whine_if_not_found("cmp"); 991 1027 } 992 run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 993 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"")); 1028 run_program_and_log_output 1029 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 1030 mr_asprintf(tmp, "%s", 1031 call_program_and_get_last_line_of_output 1032 ("mount | grep -E \"cdr(om|w)\"")); 994 1033 if (strcmp("", tmp)) { 995 1034 if (strstr(tmp, "autofs")) { … … 1065 1104 /*@ buffer ****************************************************** */ 1066 1105 char *command = NULL; 1106 char *tmp = NULL; 1067 1107 1068 1108 /*@ end vars *************************************************** */ … … 1071 1111 assert_string_is_neither_NULL_nor_zerolength(label); 1072 1112 if (!does_file_exist(config_file)) { 1073 log_to_screen("(read_cfg_var) Cannot find %s config file", config_file); 1113 mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", 1114 config_file); 1115 log_to_screen(tmp); 1116 mr_free(tmp); 1117 1074 1118 value[0] = '\0'; 1075 1119 return (1); … … 1083 1127 mr_free(command); 1084 1128 1085 log_msg(4, "Configuration item %s is %s", label, value);1086 1129 if (strlen(value) == 0) { 1087 1130 return (1); … … 1199 1242 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1200 1243 */ 1201 void mount_boot_if_necessary() { 1244 void mount_boot_if_necessary() 1245 { 1202 1246 char *tmp = NULL; 1203 1247 char *command = NULL; … … 1207 1251 g_boot_mountpt[0] = '\0'; 1208 1252 log_msg(4, "Done. Great. Seeting command to something"); 1209 mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1253 mr_asprintf(command, "%s", 1254 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1210 1255 log_msg(4, "Cool. Command = '%s'", command); 1211 1256 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); … … 1213 1258 1214 1259 log_msg(4, "tmp = '%s'", tmp); 1215 log_it("/boot is at %s according to /etc/fstab", tmp); 1216 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1217 mr_free(tmp); 1218 1219 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1220 mr_free(command); 1221 1222 if (!strcmp(tmp,"")) { 1223 if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) { 1224 if (!run_program_and_log_output("mount /boot", 5)) { 1225 strcpy(g_boot_mountpt, "/boot"); 1226 log_msg(1, "Mounted /boot"); 1260 if (tmp[0]) { 1261 log_it("/boot is at %s according to /etc/fstab", tmp); 1262 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1263 mr_free(tmp); 1264 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1265 mr_free(command); 1266 1267 if (!strcmp(tmp,"")) { 1268 if (((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")) != NULL)) { 1269 if (!run_program_and_log_output("mount /boot", 5)) { 1270 strcpy(g_boot_mountpt, "/boot"); 1271 log_msg(1, "Mounted /boot"); 1272 } else { 1273 log_it("...ignored cos it's a label or uuid :-)"); 1274 } 1227 1275 } else { 1228 log_it("...ignored cos it's a label or uuid :-)"); 1276 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1277 log_msg(3, "command = %s", command); 1278 if (run_program_and_log_output(command, 5)) { 1279 strcpy(g_boot_mountpt, tmp); 1280 mr_free(tmp); 1281 mr_asprintf(tmp, 1282 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1283 g_boot_mountpt); 1284 log_it(tmp); 1285 mr_free(tmp); 1286 1287 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1288 if (run_program_and_log_output(tmp, 5)) { 1289 g_boot_mountpt[0] = '\0'; 1290 log_msg(1, "Plan B"); 1291 if (!run_program_and_log_output("mount /boot", 5)) { 1292 strcpy(g_boot_mountpt, "/boot"); 1293 log_msg(1, "Plan B worked"); 1294 } else { 1295 log_msg(1, 1296 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition."); 1297 } 1298 } 1299 mr_free(tmp); 1300 } 1301 mr_free(command); 1229 1302 } 1230 } else { 1231 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1232 log_msg(3, "command = %s", command); 1233 if (run_program_and_log_output(command, 5)) { 1234 strcpy(g_boot_mountpt, tmp); 1235 mr_free(tmp); 1236 log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt); 1237 1238 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1239 if (run_program_and_log_output(tmp, 5)) { 1240 g_boot_mountpt[0] = '\0'; 1241 log_msg(1, "Plan B"); 1242 if (!run_program_and_log_output("mount /boot", 5)) { 1243 strcpy(g_boot_mountpt, "/boot"); 1244 log_msg(1, "Plan B worked"); 1245 } else { 1246 log_msg(1, 1247 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition."); 1248 } 1249 } 1250 } 1251 mr_free(command); 1252 } 1253 } 1254 mr_free(tmp); 1303 } 1304 } 1255 1305 log_msg(1, "Ended sub"); 1256 1306 } … … 1290 1340 char *command = NULL; 1291 1341 char *tempfile = NULL; 1342 char *tmp = NULL; 1292 1343 1293 1344 … … 1297 1348 assert(value != NULL); 1298 1349 if (!does_file_exist(config_file)) { 1299 log_to_screen("(write_cfg_file) Cannot find %s config file", config_file); 1350 mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", 1351 config_file); 1352 log_to_screen(tmp); 1353 mr_free(tmp); 1300 1354 return (1); 1301 1355 } 1302 1356 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1303 1357 if (does_file_exist(config_file)) { 1304 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile); 1358 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", 1359 label, config_file, tempfile); 1305 1360 paranoid_system(command); 1306 1361 mr_free(command); … … 1323 1378 * information to the logfile. 1324 1379 */ 1325 void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) { 1326 1380 void standard_log_debug_msg(int debug_level, const char *szFile, 1381 const char *szFunction, int nLine, 1382 const char *fmt, ...) 1383 { 1327 1384 va_list args; 1385 int i; 1328 1386 static int depth = 0; 1329 1387 FILE *fout; … … 1338 1396 if (!(fout = fopen(MONDO_LOGFILE, "a"))) { 1339 1397 return; 1340 } 1398 } // fatal_error("Failed to openout to logfile - sheesh..."); } 1341 1399 1342 1400 // add tabs to distinguish log levels 1343 1401 if (debug_level > 0) { 1344 fprintf(fout, "DBG%d: ", debug_level); 1402 for (i = 1; i < debug_level; i++) 1403 fprintf(fout, "\t"); 1345 1404 if (getpid() == g_main_pid) 1346 1405 fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine); … … 1349 1408 else 1350 1409 fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine); 1351 } else {1352 fprintf(fout, "INFO: ");1353 1410 } 1354 1411 va_start(args, fmt); … … 1356 1413 va_end(args); 1357 1414 1415 // do not slow down the progran if standard debug level 1416 // must be enabled: if no flush, the log won't be up-to-date if there 1417 // is a segfault 1418 //if (g_dwDebugLevel != 1) 1419 1358 1420 fprintf(fout, "\n"); 1359 1421 paranoid_fclose(fout); … … 1368 1430 ...) = standard_log_debug_msg; 1369 1431 1432 1433 /** 1434 * If @p y, malloc @p x, else free @p x. 1435 * @bug This function seems orphaned. Please remove. 1436 */ 1437 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} } 1370 1438 1371 1439 /** … … 1378 1446 malloc_string(g_boot_mountpt); 1379 1447 malloc_string(g_mondo_home); 1448 /* 1449 malloc_string(g_tmpfs_mountpt); 1450 */ 1380 1451 malloc_string(g_serial_string); 1381 1452 malloc_string(g_magicdev_command); … … 1383 1454 paranoid_free(g_boot_mountpt); 1384 1455 paranoid_free(g_mondo_home); 1456 /* 1457 paranoid_free(g_tmpfs_mountpt); 1458 */ 1459 paranoid_free(g_serial_string); 1385 1460 paranoid_free(g_magicdev_command); 1386 1461 1387 mr_free(g_serial_string); 1388 } 1462 } 1463 1464 /* 1465 char**list_of_arrays[] = { 1466 &g_boot_mountpt, 1467 &g_mondo_home, 1468 &g_tmpfs_mountpt, 1469 &g_serial_string, 1470 &g_magicdev_command, 1471 NULL}; 1472 1473 char**ppcurr; 1474 int i; 1475 1476 for(i=0;list_of_arrays[i];i++) 1477 { 1478 log_msg(5, "Allocating %d", i); 1479 ppcurr = list_of_arrays[i]; 1480 if (mal) 1481 { *ppcurr = malloc(MAX_STR_LEN); } 1482 else 1483 { 1484 if (*ppcurr) 1485 { 1486 free(*ppcurr); 1487 } 1488 } 1489 } 1490 log_msg(5, "Returning"); 1491 */ 1389 1492 } 1390 1493 … … 1415 1518 void stop_magicdev_if_necessary() 1416 1519 { 1417 strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1520 strcpy(g_magicdev_command, 1521 call_program_and_get_last_line_of_output 1522 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1418 1523 if (g_magicdev_command[0]) { 1419 1524 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command); -
branches/3.0/mondo/src/common/libmondo-verify.c
r3188 r3192 55 55 assert(bkpinfo != NULL); 56 56 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 57 sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno, bkpinfo->zip_suffix); 57 sprintf(output, "%s/archives/%d.star.%s", mountpoint, setno, 58 bkpinfo->zip_suffix); 58 59 if (!does_file_exist(output)) { 59 sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno, bkpinfo->zip_suffix); 60 sprintf(output, "%s/archives/%d.afio.%s", mountpoint, setno, 61 bkpinfo->zip_suffix); 60 62 } 61 63 return (output); … … 78 80 { 79 81 /*@ buffer ********************************************************** */ 80 char *command = NULL;81 char *afio_found_changes = NULL;82 char *command; 83 char *afio_found_changes; 82 84 83 85 /*@ int ************************************************************* */ … … 87 89 long afio_diffs = 0; 88 90 91 command = malloc(2000); 92 afio_found_changes = malloc(500); 89 93 assert_string_is_neither_NULL_nor_zerolength(changedfiles_fname); 90 94 assert_string_is_neither_NULL_nor_zerolength(ignorefiles_fname); 91 95 assert_string_is_neither_NULL_nor_zerolength(stderr_fname); 92 96 93 mr_asprintf(afio_found_changes, "%s.afio", ignorefiles_fname); 94 sync(); 97 sprintf(afio_found_changes, "%s.afio", ignorefiles_fname); 98 paranoid_system("sync"); 99 100 /* sprintf (command, 101 "grep \"afio: \" %s | awk '{j=substr($0,8); i=index(j,\": \");printf \"/%%s\\n\",substr(j,1,i-2);}' | sort -u | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"/dev/.*\" > %s", 102 stderr_fname, afio_found_changes); 103 */ 95 104 96 105 log_msg(1, "Now scanning log file for 'afio: ' stuff"); 97 mr_asprintf(command, "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes); 106 sprintf(command, 107 "grep \"afio: \" %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s", 108 stderr_fname, afio_found_changes); 98 109 log_msg(2, command); 99 110 res = system(command); 100 mr_free(command);101 102 111 if (res) { 103 112 log_msg(2, "Warning - failed to think"); … … 105 114 106 115 log_msg(1, "Now scanning log file for 'star: ' stuff"); 107 mr_asprintf(command, "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s", stderr_fname, afio_found_changes); 116 sprintf(command, 117 "grep \"star: \" %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s", 118 stderr_fname, afio_found_changes); 108 119 log_msg(2, command); 109 120 res = system(command); 110 mr_free(command);111 112 121 if (res) { 113 122 log_msg(2, "Warning - failed to think"); 114 123 } 124 // exclude_nonexistent_files (afio_found_changes); 115 125 afio_diffs = count_lines_in_file(afio_found_changes); 116 mr_asprintf(command, "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", ignorefiles_fname, afio_found_changes, afio_found_changes, changedfiles_fname); 117 mr_free(afio_found_changes); 126 sprintf(command, 127 "sort %s %s %s | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", 128 ignorefiles_fname, afio_found_changes, afio_found_changes, 129 changedfiles_fname); 118 130 log_msg(2, command); 119 131 paranoid_system(command); 120 mr_free(command); 132 paranoid_free(command); 133 paranoid_free(afio_found_changes); 121 134 return (afio_diffs); 122 135 } … … 138 151 139 152 /*@ buffers ********************************************************* */ 140 char *tmp = NULL;153 char *tmp; 141 154 char *mds = NULL; 142 155 … … 149 162 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 150 163 assert(bkpinfo != NULL); 164 malloc_string(tmp); 151 165 152 166 for (set_number = 0; … … 161 175 if (g_last_afioball_number != set_number - 1) { 162 176 if (set_number == 0) { 163 log_msg(1, "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 177 log_msg(1, 178 "Weird error in verify_afioballs_on_CD() but it's really a cosmetic error, nothing more"); 164 179 } else { 165 180 retval++; 166 log_to_screen("Warning - missing set(s) between %d and %d\n", g_last_afioball_number, set_number - 1); 181 sprintf(tmp, "Warning - missing set(s) between %d and %d\n", 182 g_last_afioball_number, set_number - 1); 183 log_to_screen(tmp); 167 184 } 168 185 } 169 186 mds = media_descriptor_string(bkpinfo->backup_media_type); 170 mr_asprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number);187 sprintf(tmp, "Verifying %s #%d's tarballs", mds, g_current_media_number); 171 188 mr_free(mds); 172 189 173 190 open_evalcall_form(tmp); 174 mr_free(tmp);175 191 176 192 for (total_sets = set_number; … … 192 208 g_last_afioball_number = set_number - 1; 193 209 close_evalcall_form(); 210 paranoid_free(tmp); 194 211 return (retval); 195 212 } … … 210 227 211 228 /*@ buffer ********************************************************** */ 212 char *tmp = NULL; 213 char *mountpoint = NULL; 214 char *command = NULL; 229 char *tmp; 230 char *mountpoint; 231 // char ca, cb; 232 char *command; 215 233 char *mds = NULL; 216 char *sz_exe = NULL;234 char *sz_exe; 217 235 static char *bufblkA = NULL; 218 236 static char *bufblkB = NULL; … … 234 252 FILE *fin; 235 253 int retval = 0; 236 254 // long long outlen; 255 256 malloc_string(tmp); 257 malloc_string(mountpoint); 258 malloc_string(command); 259 malloc_string(sz_exe); 237 260 if (!bufblkA) { 238 261 if (!(bufblkA = malloc(maxbufsize))) { … … 251 274 if (bkpinfo->compression_level > 0) { 252 275 if (bkpinfo->use_lzo) { 253 mr_asprintf(sz_exe, "lzop");276 strcpy(sz_exe, "lzop"); 254 277 } else if (bkpinfo->use_gzip) { 255 mr_asprintf(sz_exe, "gzip"); 256 } else if (bkpinfo->use_lzma) { 257 mr_asprintf(sz_exe, "lzma"); 278 strcpy(sz_exe, "gzip"); 258 279 } else { 259 mr_asprintf(sz_exe, "bzip2"); 260 } 280 strcpy(sz_exe, "bzip2"); 281 } 282 } else { 283 sz_exe[0] = '\0'; 261 284 } 262 285 263 286 log_it("before vsbf"); 264 287 mds = media_descriptor_string(bkpinfo->backup_media_type); 265 mr_asprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number);288 sprintf(tmp, "Verifying %s#%d's big files", mds, g_current_media_number); 266 289 mr_free(mds); 267 290 268 291 open_evalcall_form(tmp); 269 mr_free(tmp);270 271 292 log_it("after vsbf"); 272 mr_asprintf(mountpoint, "%s/archives", mtpt);293 sprintf(mountpoint, "%s/archives", mtpt); 273 294 if (last_bigfile_num == -1) { 274 295 bigfile_num = 0; … … 281 302 slice_num = last_slice_num + 1; 282 303 } 283 while (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 304 while (does_file_exist 305 (slice_fname 306 (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 284 307 || 285 does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 308 does_file_exist(slice_fname 309 (bigfile_num, slice_num, mountpoint, ""))) { 286 310 // handle slices until end of CD 287 311 if (slice_num == 0) { 288 log_msg(2, "ISO=%d bigfile=%ld --START--", g_current_media_number, bigfile_num); 289 if (! (fin = fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), "r"))) { 312 log_msg(2, "ISO=%d bigfile=%ld --START--", 313 g_current_media_number, bigfile_num); 314 if (! 315 (fin = 316 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), 317 "r"))) { 290 318 log_msg(2, "Cannot open bigfile's info file"); 291 319 } else { 292 if (fread ((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) { 320 if (fread 321 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 322 fin) < sizeof(biggiestruct)) { 293 323 log_msg(2, "Unable to get biggiestruct"); 294 324 } 295 325 paranoid_fclose(fin); 296 326 } 297 if (bkpinfo->restore_path) { 298 mr_asprintf(tmp, "%s/%s", bkpinfo->restore_path, biggiestruct.filename); 299 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 300 forig = fopen(tmp, "r"); 301 mr_free(tmp); 302 303 if (!forig) { 304 log_msg(2, "Failed to open bigfile. Darn."); 305 log_to_screen("%s/%s not found on live filesystem", bkpinfo->restore_path, biggiestruct.filename); 306 mr_asprintf(tmp, "echo \"%s/%s not found\" >> %s/biggies.changed", bkpinfo->restore_path, biggiestruct.filename, bkpinfo->tmpdir); 307 paranoid_system(tmp); 308 mr_free(tmp); 309 310 bigfile_num++; 311 slice_num = 0; 312 retval++; 313 } else { 314 slice_num++; 315 } 327 sprintf(tmp, "%s/%s", bkpinfo->restore_path, 328 biggiestruct.filename); 329 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 330 if (!(forig = fopen(tmp, "r"))) { 331 log_msg(2, "Failed to open bigfile. Darn."); 332 log_to_screen("%s/%s not found on live filesystem", 333 bkpinfo->restore_path, 334 biggiestruct.filename); 335 mr_asprintf(mds, "echo \"%s/%s not found\" >> %s/biggies.changed", 336 bkpinfo->restore_path, 337 biggiestruct.filename, 338 bkpinfo->tmpdir); 339 paranoid_system(mds); 340 paranoid_free(mds); 341 342 bigfile_num++; 343 slice_num = 0; 344 retval++; 316 345 } else { 317 log_it("Unable to open bigfile as restore_path is NULL");346 slice_num++; 318 347 } 319 348 } else if (does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, "")) && … … 325 354 slice_num = 0; 326 355 } else { 327 log_msg(2, "ISO=%d bigfile=%ld slice=%ld", g_current_media_number, bigfile_num, slice_num); 328 if ((!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) && (sz_exe != NULL)) { 329 mr_asprintf(command, "%s -dc %s 2>> %s", sz_exe, slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), MONDO_LOGFILE); 356 log_msg(2, "ISO=%d bigfile=%ld slice=%ld", 357 g_current_media_number, bigfile_num, slice_num); 358 if (!does_file_exist(slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 359 sprintf(command, "%s -dc %s 2>> %s", 360 sz_exe, 361 slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix), 362 MONDO_LOGFILE); 330 363 } else { 331 mr_asprintf(command, "cat %s 2>> %s", slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE); 364 sprintf(command, "cat %s 2>> %s", 365 slice_fname(bigfile_num, slice_num, mountpoint, ""), MONDO_LOGFILE); 332 366 } 333 pin = popen(command, "r"); 334 mr_free(command); 335 if (pin) { 367 if ((pin = popen(command, "r"))) { 336 368 res = 0; 337 369 while (!feof(pin)) { … … 372 404 } 373 405 } 374 mr_free(mountpoint);375 mr_free(sz_exe);376 377 406 last_bigfile_num = bigfile_num; 378 407 last_slice_num = slice_num - 1; … … 387 416 paranoid_free(bufblkB); 388 417 } 418 paranoid_free(tmp); 419 paranoid_free(command); 420 paranoid_free(sz_exe); 421 paranoid_free(mountpoint); 389 422 return (0); 390 423 } … … 409 442 { 410 443 /*@ buffers ********************************************************* */ 411 char *command = NULL;412 char *outlog = NULL;413 char *tmp = NULL;414 char *p = NULL;444 char *command; 445 char *outlog; 446 char *tmp; 447 char *p; 415 448 416 449 /*@ pointers ******************************************************* */ … … 429 462 430 463 log_it("Verifying fileset '%s'", tarball_fname); 431 mr_asprintf(outlog, "%s/afio.log", bkpinfo->tmpdir); 432 /* if programmer forgot to say which compression thingy to use then find out */ 433 if (strstr(tarball_fname, ".lzo") && strcmp(bkpinfo->zip_suffix, "lzo")) { 464 /* chdir("/"); */ 465 sprintf(outlog, "%s/afio.log", bkpinfo->tmpdir); 466 /* if programmer forgot to say which compression thingy to use then find out */ 467 if (strstr(tarball_fname, ".lzo") 468 && strcmp(bkpinfo->zip_suffix, "lzo")) { 434 469 log_msg(2, "OK, I'm going to start using lzop."); 435 470 strcpy(bkpinfo->zip_exe, "lzop"); … … 437 472 bkpinfo->use_lzo = TRUE; 438 473 bkpinfo->use_gzip = FALSE; 439 bkpinfo->use_lzma = FALSE;440 }441 if (strstr(tarball_fname, ".gz")&& strcmp(bkpinfo->zip_suffix, "gz")) {474 } 475 if (strstr(tarball_fname, ".gz") 476 && strcmp(bkpinfo->zip_suffix, "gz")) { 442 477 log_msg(2, "OK, I'm going to start using gzip."); 443 478 strcpy(bkpinfo->zip_exe, "gzip"); … … 445 480 bkpinfo->use_lzo = FALSE; 446 481 bkpinfo->use_gzip = TRUE; 447 bkpinfo->use_lzma = FALSE;448 }449 if (strstr(tarball_fname, ".bz2")&& strcmp(bkpinfo->zip_suffix, "bz2")) {482 } 483 if (strstr(tarball_fname, ".bz2") 484 && strcmp(bkpinfo->zip_suffix, "bz2")) { 450 485 log_msg(2, "OK, I'm going to start using bzip2."); 451 486 strcpy(bkpinfo->zip_exe, "bzip2"); … … 453 488 bkpinfo->use_lzo = FALSE; 454 489 bkpinfo->use_gzip = FALSE; 455 bkpinfo->use_lzma = FALSE;456 }457 if (strstr(tarball_fname, ".lzma") && strcmp(bkpinfo->zip_suffix, "lzma")) {458 log_msg(2, "OK, I'm going to start using lzma.");459 strcpy(bkpinfo->zip_exe, "lzma");460 strcpy(bkpinfo->zip_suffix, "lzma");461 bkpinfo->use_lzo = FALSE;462 bkpinfo->use_gzip = FALSE;463 bkpinfo->use_lzma = TRUE;464 }465 if (bkpinfo->zip_exe == NULL) {466 strcpy(bkpinfo->zip_exe, "none");467 }468 if (bkpinfo->zip_suffix == NULL) {469 strcpy(bkpinfo->zip_suffix, "");470 490 } 471 491 unlink(outlog); … … 473 493 bkpinfo->use_star = TRUE; 474 494 if (strstr(tarball_fname, ".bz2")) 475 mr_asprintf(command, "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", tarball_fname, (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, outlog); 495 sprintf(command, 496 "star -sparse -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", 497 tarball_fname, 498 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, 499 outlog); 476 500 } else { 477 501 bkpinfo->use_star = FALSE; 478 /* Here we suppose that there is always a compression program called */ 479 if (bkpinfo->zip_exe) { 480 mr_asprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", bkpinfo->zip_exe, tarball_fname, outlog, outlog); 481 } else { 482 mr_asprintf(command, "afio -r -Z %s >> %s 2>> %s", tarball_fname, outlog, outlog); 483 } 502 sprintf(command, "afio -r -P %s -Z %s >> %s 2>> %s", 503 bkpinfo->zip_exe, tarball_fname, outlog, outlog); 484 504 } 485 505 log_msg(6, "command=%s", command); 486 506 paranoid_system(command); 487 mr_free(command);488 489 507 if (length_of_file(outlog) < 10) { 490 mr_asprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE);508 sprintf(command, "cat %s >> %s", outlog, MONDO_LOGFILE); 491 509 } else { 492 mr_asprintf(command, "cut -d: -f%d %s | sort -u", (bkpinfo->use_star) ? 1 : 2, outlog); 510 sprintf(command, "cut -d: -f%d %s | sort -u", 511 (bkpinfo->use_star) ? 1 : 2, outlog); 493 512 pin = popen(command, "r"); 494 513 if (pin) { 495 for (mr_getline(tmp, pin); !feof(pin); mr_getline(tmp, pin)) { 514 for (p = fgets(tmp, MAX_STR_LEN, pin); !feof(pin) && (p != NULL); 515 p = fgets(tmp, MAX_STR_LEN, pin)) { 496 516 if (bkpinfo->use_star) { 497 517 if (!strstr(tmp, "diffopts=")) { 498 while (strlen(tmp) > 0 && tmp[strlen(tmp) - 1] < 32) { 518 while (strlen(tmp) > 0 519 && tmp[strlen(tmp) - 1] < 32) { 499 520 tmp[strlen(tmp) - 1] = '\0'; 500 521 } 501 522 if (strchr(tmp, '/')) { 502 523 if (!diffs) { 503 log_msg(0, "'%s' - differences found", tarball_fname); 524 log_msg(0, "'%s' - differences found", 525 tarball_fname); 504 526 } 505 log_msg(0, "star: /%s", strip_afio_output_line(tmp)); 527 log_msg(0, "star: /%s", 528 strip_afio_output_line(tmp)); 506 529 diffs++; 507 530 } … … 509 532 } else { 510 533 if (!diffs) { 511 log_msg(0, "'%s' - differences found", tarball_fname); 534 log_msg(0, "'%s' - differences found", 535 tarball_fname); 512 536 } 513 537 log_msg(0, "afio: /%s", strip_afio_output_line(tmp)); 514 538 diffs++; 515 539 } 516 mr_free(tmp);517 540 } 518 mr_free(tmp);519 541 paranoid_pclose(pin); 520 542 } else { … … 522 544 } 523 545 } 524 mr_free(command); 525 mr_free(outlog); 546 /* chdir(old_pwd); */ 547 // sprintf (tmp, "uniq -u %s >> %s", "/tmp/mondo-verify.err", MONDO_LOGFILE); 548 // paranoid_system (tmp); 549 // unlink ("/tmp/mondo-verify.err"); 550 paranoid_free(command); 551 paranoid_free(outlog); 552 paranoid_free(tmp); 526 553 return (0); 527 554 } … … 577 604 578 605 /*@ buffers ********************************************************** */ 579 char *tmp = NULL;580 char *tarball_fname = NULL;606 char *tmp; 607 char *tarball_fname; 581 608 582 609 /*@ pointers ********************************************************* */ 583 610 char *p; 584 611 612 malloc_string(tmp); 613 malloc_string(tarball_fname); 585 614 assert(bkpinfo != NULL); 586 615 assert_string_is_neither_NULL_nor_zerolength(orig_fname); … … 592 621 p++; 593 622 } 594 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);623 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 595 624 paranoid_system(tmp); 596 mr_free(tmp); 597 598 mr_asprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 625 sprintf(tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 626 sprintf(tmp, "Temporarily copying file from tape to '%s'", 627 tarball_fname); 628 /* log_it(tmp); */ 599 629 read_file_from_stream_to_file(tarball_fname, size); 600 630 res = verify_a_tarball(tarball_fname); 601 631 if (res) { 602 log_msg(0, "Afioball '%s' no longer matches your live filesystem", p); 632 sprintf(tmp, 633 "Afioball '%s' no longer matches your live filesystem", p); 634 log_msg(0, tmp); 603 635 retval++; 604 636 } 605 637 unlink(tarball_fname); 606 mr_free(tarball_fname); 638 paranoid_free(tmp); 639 paranoid_free(tarball_fname); 607 640 return (retval); 608 641 } … … 627 660 628 661 /*@ char ************************************************************ */ 629 char *test_file = NULL;630 char *biggie_cksum = NULL;631 char *orig_cksum = NULL;632 char *tmp = NULL;633 char *slice_fnam = NULL;662 char *test_file; 663 char *biggie_cksum; 664 char *orig_cksum; 665 char *tmp; 666 char *slice_fnam; 634 667 635 668 /*@ pointers ******************************************************** */ … … 639 672 long long slice_siz; 640 673 674 malloc_string(test_file); 675 malloc_string(biggie_cksum); 676 malloc_string(orig_cksum); 677 malloc_string(tmp); 641 678 malloc_string(slice_fnam); 642 679 assert(bkpinfo != NULL); … … 649 686 p++; 650 687 } 651 mr_asprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 688 sprintf(test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 689 sprintf(tmp, 690 "Temporarily copying biggiefile %s's slices from tape to '%s'", 691 p, test_file); 692 /* log_it(tmp); */ 652 693 for (res = 653 694 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 654 695 ctrl_chr != BLK_STOP_A_BIGGIE; 655 696 res = 656 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) { 697 read_header_block_from_stream(&slice_siz, slice_fnam, 698 &ctrl_chr)) { 657 699 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 658 700 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); … … 661 703 unlink(test_file); 662 704 res = 663 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 705 read_header_block_from_stream(&slice_siz, slice_fnam, 706 &ctrl_chr); 664 707 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 665 708 log_msg(2, "test_file = %s", test_file); … … 669 712 retval += res; 670 713 } 671 mr_asprintf(biggie_cksum, "%s", slice_fnam);714 strcpy(biggie_cksum, slice_fnam); 672 715 if (biggie_cksum[0] != '\0') { 673 mr_asprintf(orig_cksum, "%s", calc_checksum_of_file(biggie_fname));716 strcpy(orig_cksum, calc_checksum_of_file(biggie_fname)); 674 717 if (strcmp(biggie_cksum, orig_cksum)) { 675 log_msg(2, "orig cksum=%s; curr cksum=%s", biggie_cksum, orig_cksum); 676 log_to_screen("%s has changed on live filesystem", biggie_fname); 677 678 mr_asprintf(tmp, "echo \"%s\" >> %s/biggies.changed", biggie_fname, bkpinfo->tmpdir); 718 sprintf(tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, 719 orig_cksum); 720 log_msg(2, tmp); 721 sprintf(tmp, "%s has changed on live filesystem", 722 biggie_fname); 723 log_to_screen(tmp); 724 sprintf(tmp, "echo \"%s\" >> %s/biggies.changed", 725 biggie_fname, bkpinfo->tmpdir); 679 726 paranoid_system(tmp); 680 mr_free(tmp);681 682 mr_free(orig_cksum);683 }684 mr_free(biggie_cksum);685 mr_free(test_file);727 } 728 } 729 paranoid_free(test_file); 730 paranoid_free(biggie_cksum); 731 paranoid_free(orig_cksum); 732 paranoid_free(tmp); 686 733 paranoid_free(slice_fnam); 687 734 return (retval); … … 692 739 * Verify all afioballs from the opened tape/CD stream. 693 740 * @param bkpinfo The backup information structure. Fields used: 741 * - @c bkpinfo->restore_path 694 742 * - @c bkpinfo->tmpdir 695 743 * … … 706 754 707 755 /*@ buffers ***************************************************** */ 708 char *tmp = NULL;756 char *tmp; 709 757 char *fname; 710 758 char *curr_xattr_list_fname; … … 715 763 716 764 assert(bkpinfo != NULL); 765 malloc_string(tmp); 717 766 malloc_string(fname); 718 767 malloc_string(curr_xattr_list_fname); … … 767 816 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 768 817 } 769 mr_asprintf(tmp, "Verifying fileset #%ld", current_afioball_number); 818 sprintf(tmp, "Verifying fileset #%ld", current_afioball_number); 819 /*log_it(tmp); */ 770 820 update_progress_form(tmp); 771 mr_free(tmp);772 773 821 res = verify_an_afioball_from_stream(fname, size); 774 822 if (res) { 775 log_to_screen("Afioball %ld differs from live filesystem", current_afioball_number); 823 sprintf(tmp, "Afioball %ld differs from live filesystem", 824 current_afioball_number); 825 log_to_screen(tmp); 776 826 } 777 827 retval += res; … … 785 835 log_msg(1, "All done with afioballs"); 786 836 close_progress_form(); 837 paranoid_free(tmp); 787 838 paranoid_free(fname); 788 839 paranoid_free(curr_xattr_list_fname); … … 812 863 813 864 /*@ buffers ******************************************************** */ 814 char * orig_fname;815 char * logical_fname = NULL;816 char *comment = NULL;817 char *curr_xattr_list_fname = NULL;818 char *curr_acl_list_fname = NULL;865 char *tmp; 866 char *orig_fname, *logical_fname; 867 char *comment; 868 char *curr_xattr_list_fname; 869 char *curr_acl_list_fname; 819 870 /*@ pointers ******************************************************* */ 820 871 char *p; … … 824 875 825 876 assert(bkpinfo != NULL); 877 malloc_string(tmp); 826 878 malloc_string(orig_fname); 879 malloc_string(logical_fname); 880 malloc_string(comment); 827 881 malloc_string(curr_xattr_list_fname); 828 882 malloc_string(curr_acl_list_fname); … … 836 890 bkpinfo->tmpdir); 837 891 } 838 mr_asprintf(comment, "Verifying all bigfiles.");892 sprintf(comment, "Verifying all bigfiles."); 839 893 log_to_screen(comment); 894 sprintf(tmp, "%s/biggielist.txt", bkpinfo->tmpdir); 895 // noof_biggiefiles = count_lines_in_file (tmp); // pointless 840 896 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 841 897 if (ctrl_chr != BLK_START_BIGGIEFILES) { … … 855 911 "Please wait. This may take some time.", "", 856 912 noof_biggiefiles); 857 mr_free(comment);858 859 913 for (res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 860 914 ctrl_chr != BLK_STOP_BIGGIEFILES; … … 871 925 p++; 872 926 } 873 mr_asprintf(comment, "Verifying bigfile #%ld (%ld K)", current_biggiefile_number, (long) size >> 10); 927 sprintf(comment, "Verifying bigfile #%ld (%ld K)", 928 current_biggiefile_number, (long) size >> 10); 874 929 update_progress_form(comment); 875 mr_free(comment); 876 877 if (bkpinfo->restore_path) { 878 mr_asprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 879 res = verify_a_biggiefile_from_stream(logical_fname, size); 880 mr_free(logical_fname); 881 retval += res; 882 } else { 883 log_it("Unable to verify bigfile as restore_path is NULL"); 884 } 885 930 sprintf(logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 931 res = 932 verify_a_biggiefile_from_stream(logical_fname, size); 933 retval += res; 886 934 current_biggiefile_number++; 887 935 g_current_progress++; … … 889 937 close_progress_form(); 890 938 paranoid_free(orig_fname); 939 paranoid_free(logical_fname); 891 940 paranoid_free(curr_xattr_list_fname); 892 941 paranoid_free(curr_acl_list_fname); 942 paranoid_free(comment); 943 paranoid_free(tmp); 893 944 return (retval); 894 945 } … … 900 951 * Verify the USB device 901 952 * @param bkpinfo The backup information structure. Fields used: 953 * - @c bkpinfo->isodir 902 954 * - @c bkpinfo->media_device 903 955 * - @c bkpinfo->tmpdir … … 929 981 assert(bkpinfo != NULL); 930 982 931 if (bkpinfo->media_device == NULL) {932 return(1);933 }934 935 983 mr_asprintf(fname, "%s1", bkpinfo->media_device); 936 984 if (is_this_device_mounted(fname)) { … … 984 1032 #endif 985 1033 { 986 log_to_screen("%s failed; unable to unmount USB device\n", tmp1); 1034 mr_asprintf(tmp, "%s failed; unable to unmount USB device\n", tmp1); 1035 log_to_screen(tmp); 1036 paranoid_free(tmp); 987 1037 retval++; 988 1038 } else { 989 1039 log_msg(2, "OK, I've unmounted the USB device\n"); 990 1040 } 991 mr_free(tmp1);992 mr_free(mountpoint);1041 paranoid_free(tmp1); 1042 paranoid_free(mountpoint); 993 1043 return (retval); 994 1044 } … … 1016 1066 1017 1067 /*@ buffers ******************************************************** */ 1018 char *mountpoint = NULL;1019 char *command = NULL;1020 char *tmp = NULL;1021 char *fname = NULL;1068 char *mountpoint; 1069 char *command; 1070 char *tmp; 1071 char *fname; 1022 1072 #ifdef __FreeBSD__ 1023 1073 char mdd[32]; … … 1029 1079 #endif 1030 1080 1081 command = malloc(2000); 1082 malloc_string(mountpoint); 1083 malloc_string(tmp); 1084 malloc_string(fname); 1085 1031 1086 assert(bkpinfo != NULL); 1032 1087 1033 if (bkpinfo->media_device == NULL) { 1034 return(1); 1035 } 1036 1037 mr_asprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir); 1038 if (((bkpinfo->isodir == NULL) && (bkpinfo->netfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) { 1039 fatal_error("No iso filename preparation possible"); 1040 } 1041 if (bkpinfo->netfs_remote_dir) { 1042 // NETFS 1043 mr_asprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number); 1044 } else { 1045 // ISO 1046 mr_asprintf(fname, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number); 1047 } 1088 sprintf(mountpoint, "%s/cdrom", bkpinfo->tmpdir); 1089 sprintf(fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, 1090 bkpinfo->prefix, g_current_media_number); 1048 1091 1049 1092 mkdir(mountpoint, 1777); 1050 1093 sync(); 1051 1094 if (!does_file_exist(fname)) { 1052 log_msg(2, "%s not found; assuming you backed up to CD; verifying CD...", fname); 1095 sprintf(tmp, 1096 "%s not found; assuming you backed up to CD; verifying CD...", 1097 fname); 1098 log_msg(2, tmp); 1053 1099 if (bkpinfo->manual_cd_tray) { 1054 1100 popup_and_OK("Please push CD tray closed."); … … 1056 1102 if (find_and_mount_actual_cd(mountpoint)) { 1057 1103 log_to_screen("failed to mount actual CD"); 1058 mr_free(mountpoint);1059 mr_free(fname);1060 1104 return (1); 1061 1105 } 1062 1106 } else { 1063 log_msg(2, "%s found; verifying ISO...", fname);1107 sprintf(tmp, "%s found; verifying ISO...", fname); 1064 1108 #ifdef __FreeBSD__ 1065 1109 ret = 0; … … 1067 1111 mddevice = make_vn(fname); 1068 1112 if (ret) { 1069 log_to_screen("make_vn of %s failed; unable to verify ISO\n", fname);1070 mr_free(mountpoint);1071 mr_free(fname);1113 sprintf(tmp, "make_vn of %s failed; unable to verify ISO\n", 1114 fname); 1115 log_to_screen(tmp); 1072 1116 return (1); 1073 1117 } 1074 mr_asprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint);1118 sprintf(command, "mount_cd9660 %s %s", mddevice, mountpoint); 1075 1119 #else 1076 mr_asprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname, mountpoint); 1120 sprintf(command, "mount -o loop,ro -t iso9660 %s %s", fname, 1121 mountpoint); 1077 1122 #endif 1078 1123 if (run_program_and_log_output(command, FALSE)) { 1079 log_to_screen("%s failed; unable to mount ISO image\n", command); 1080 mr_free(mountpoint); 1081 mr_free(command); 1082 mr_free(fname); 1124 sprintf(tmp, "%s failed; unable to mount ISO image\n", 1125 command); 1126 log_to_screen(tmp); 1083 1127 return (1); 1084 1128 } 1085 mr_free(command);1086 1129 } 1087 1130 log_msg(2, "OK, I've mounted the ISO/CD\n"); 1088 mr_asprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint);1131 sprintf(tmp, "%s/archives/NOT-THE-LAST", mountpoint); 1089 1132 if (!does_file_exist(tmp)) { 1090 1133 log_msg … … 1098 1141 */ 1099 1142 } 1100 mr_free(tmp);1101 1102 1143 verify_afioballs_on_CD(mountpoint); 1103 1144 log_it("before verify_all_slices"); … … 1106 1147 #ifdef __FreeBSD__ 1107 1148 ret = 0; 1108 mr_asprintf(command, "umount -d %s", mountpoint);1149 sprintf(command, "umount -d %s", mountpoint); 1109 1150 ret += system(command); 1110 1151 ret += kick_vn(mddevice); 1111 if (ret) {1152 if (ret) 1112 1153 #else 1113 mr_asprintf(command, "umount -d %s", mountpoint);1114 if (system(command)) {1154 sprintf(command, "umount -d %s", mountpoint); 1155 if (system(command)) 1115 1156 #endif 1116 log_to_screen("%s failed; unable to unmount ISO image\n", command); 1117 1157 { 1158 sprintf(tmp, "%s failed; unable to unmount ISO image\n", command); 1159 log_to_screen(tmp); 1118 1160 retval++; 1119 1161 } else { 1120 1162 log_msg(2, "OK, I've unmounted the ISO file\n"); 1121 1163 } 1122 mr_free(mountpoint);1123 mr_free(command);1124 1125 1164 if (!does_file_exist(fname)) { 1126 mr_asprintf(command, "umount -d %s", bkpinfo->media_device);1165 sprintf(command, "umount -d %s", bkpinfo->media_device); 1127 1166 run_program_and_log_output(command, 2); 1128 mr_free(command); 1129 1130 if (!bkpinfo->please_dont_eject && eject_device(bkpinfo->media_device)) { 1167 if (!bkpinfo->please_dont_eject 1168 && eject_device(bkpinfo->media_device)) { 1131 1169 log_msg(2, "Failed to eject CD-ROM drive"); 1132 1170 } 1133 1171 } 1134 mr_free(fname); 1172 paranoid_free(command); 1173 paranoid_free(mountpoint); 1174 paranoid_free(tmp); 1175 paranoid_free(fname); 1135 1176 return (retval); 1136 1177 } … … 1150 1191 1151 1192 /*@ buffers ******************************************************** */ 1152 char *tmp = NULL;1153 char *changed_files_fname = NULL;1193 char tmp[MAX_STR_LEN]; 1194 char changed_files_fname[MAX_STR_LEN]; 1154 1195 1155 1196 /*@ long *********************************************************** */ … … 1165 1206 retval += verify_biggiefiles_from_stream(); 1166 1207 /* find the final blocks */ 1167 sync();1208 paranoid_system("sync"); 1168 1209 sleep(2); 1169 1210 closein_tape(); 1170 1211 /* close tape; exit */ 1171 1212 // fclose(g_tape_stream); <-- not needed; is handled by closein_tape() 1172 mr_asprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);1213 sprintf(tmp, "rm -f %s/biggies.changed %s/changed.files 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir); 1173 1214 paranoid_system(tmp); 1174 mr_free(tmp); 1175 1176 mr_asprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir); 1177 mr_asprintf(tmp, "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$' > %s", (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE, changed_files_fname); 1215 sprintf(changed_files_fname, "%s/changed.files", bkpinfo->tmpdir); 1216 sprintf(tmp, 1217 "grep -E '^%s:.*$' %s | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vE '^/afio:.*$' | grep -vE '^dev/.*$' > %s", 1218 (bkpinfo->use_star) ? "star" : "afio", MONDO_LOGFILE, 1219 changed_files_fname); 1178 1220 log_msg(2, "Running command to derive list of changed files"); 1179 1221 log_msg(2, tmp); 1180 1222 if (system(tmp)) { 1181 if (does_file_exist(changed_files_fname) && length_of_file(changed_files_fname) > 2) { 1182 log_to_screen("Warning - unable to check logfile to derive list of changed files"); 1223 if (does_file_exist(changed_files_fname) 1224 && length_of_file(changed_files_fname) > 2) { 1225 log_to_screen 1226 ("Warning - unable to check logfile to derive list of changed files"); 1183 1227 } else { 1184 log_to_screen("No differences found. Therefore, no 'changed.files' text file."); 1185 } 1186 } 1187 mr_free(tmp); 1188 1189 mr_asprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname); 1228 log_to_screen 1229 ("No differences found. Therefore, no 'changed.files' text file."); 1230 } 1231 } 1232 sprintf(tmp, "cat %s/biggies.changed >> %s", bkpinfo->tmpdir, changed_files_fname); 1190 1233 paranoid_system(tmp); 1191 mr_free(tmp);1192 1234 1193 1235 diffs = count_lines_in_file(changed_files_fname); 1194 1236 if (diffs > 0) { 1195 mr_asprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname, MONDO_CACHE); 1237 sprintf(tmp, "cp -f %s %s/changed.files", changed_files_fname, 1238 MONDO_CACHE); 1196 1239 run_program_and_log_output(tmp, FALSE); 1197 mr_free(tmp); 1198 1199 log_msg(0, "%ld files differed from live filesystem; type less %s or less %s/changed.files to see", diffs, changed_files_fname, MONDO_CACHE); 1240 sprintf(tmp, 1241 "%ld files differed from live filesystem; type less %s or less %s/changed.files to see", 1242 diffs, changed_files_fname, MONDO_CACHE); 1243 log_msg(0, tmp); 1200 1244 log_to_screen("See "MONDO_CACHE"/changed.files for a list of nonmatching files."); 1201 1245 log_to_screen("The files probably changed on filesystem, not on backup media."); 1202 }1203 mr_free(changed_files_fname);1246 // retval++; 1247 } 1204 1248 return (retval); 1205 1249 } -
branches/3.0/mondo/src/common/mondostructures.h
r3188 r3192 412 412 bool use_gzip; 413 413 414 /**415 * If TRUE, then use @c lzma to compress data.416 * This is used mainly in estimates. The backup/restore may or may417 * not work if you do not set this. You should also set @p zip_exe418 * and @p zip_suffix.419 */ 420 bool use_lzma;414 /** 415 * A filename containing a list of extensions, one per line, to not 416 * compress. If this is set to "", afio will still exclude a set of well-known 417 * compressed files from compression, but biggiefiles that are compressed 418 * will be recompressed again. 419 */ 420 char do_not_compress_these[MAX_STR_LEN / 2]; 421 421 422 422 /** … … 492 492 */ 493 493 t_bkptype backup_media_type; 494 // bool blank_dvd_first; 494 495 495 496 /** … … 505 506 * If you do nothing, "/" will be used. 506 507 */ 507 char *include_paths;508 char include_paths[MAX_STR_LEN*4]; 508 509 509 510 /** … … 559 560 * address form. (Domain names will be resolved in post_param_configuration().) 560 561 */ 561 char *netfs_mount;562 char netfs_mount[MAX_STR_LEN]; 562 563 563 564 /** … … 565 566 * the backups in. 566 567 */ 567 char *netfs_remote_dir;568 char netfs_remote_dir[MAX_STR_LEN]; 568 569 569 570 /** … … 673 674 */ 674 675 bool expanded; 676 }; 677 678 679 680 /** 681 * A structure to wrap a FIFO device for writing to a tape/CD stream. 682 * @bug Is this structure used (w/the move to a standalone @c buffer and all)? 683 */ 684 struct s_wrapfifo { 685 /** 686 * The device we write to or read from (a FIFO). 687 */ 688 char public_device[MAX_STR_LEN / 4]; 689 690 /** 691 * The actual device that data from the FIFO should be buffered and written to. 692 */ 693 char private_device[MAX_STR_LEN / 4]; 694 695 /** 696 * A buffer for holding data read from the FIFO. 697 */ 698 char internal_buffer_IN_fifo[MAX_STR_LEN / 4]; 699 700 /** 701 * A buffer for holding data to be written to the FIFO. 702 */ 703 char internal_buffer_OUT_fifo[MAX_STR_LEN / 4]; 704 705 /** 706 * If TRUE, then we're writing directly to the tape streamer; if FALSE, we're writing to the FIFO. 707 */ 708 bool writing_to_private_device; 675 709 }; 676 710 -
branches/3.0/mondo/src/common/newt-specific.c
r3188 r3192 97 97 extern int g_current_media_number; 98 98 pid_t g_main_pid = 0; ///< The PID of the main Mondo process. 99 long g_maximum_progress = 999 L; ///< The maximum amount of progress (100%) for the currently opened progress form.99 long g_maximum_progress = 999; ///< The maximum amount of progress (100%) for the currently opened progress form. 100 100 long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form. 101 long g_start_time = 0 L; ///< The time (in seconds since the epoch) that the progress form was opened.101 long g_start_time = 0; ///< The time (in seconds since the epoch) that the progress form was opened. 102 102 bool g_text_mode = TRUE; ///< If FALSE, use a newt interface; if TRUE, use an ugly (but more compatible) dumb terminal interface. 103 char g_xmondo_stdin[MAX_NEWT_COMMENT_LEN], ///< ... @bug Unneeded w/current XMondo. 104 g_xmondo_stdout[MAX_NEWT_COMMENT_LEN]; ///< .... @bug Unneeded w/current XMondo. 105 bool g_called_by_xmondo = FALSE; ///< @bug Unneeded w/current XMondo. 103 106 char *g_selfmounted_isodir; ///< Holds the NETFS mountpoint if mounted via mondoarchive. 104 107 105 108 /* @} - end of globalGroup */ 109 110 //int g_fd_in=-1, g_fd_out=-1; 106 111 107 112 void popup_and_OK(char *); … … 120 125 121 126 /*@ buffers ********************************************************** */ 122 int i = 0;123 char * tmp = NULL;127 int i; 128 char *p; 124 129 125 130 assert_string_is_neither_NULL_nor_zerolength(prompt); … … 131 136 } 132 137 if (g_text_mode) { 138 139 char *tmp; 140 tmp = malloc(MAX_NEWT_COMMENT_LEN); 141 133 142 while (1) { 134 sync(); 135 printf("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", prompt); 136 mr_getline(tmp, stdin); 143 paranoid_system("sync"); 144 printf 145 ("---promptdialogYN---1--- %s\n---promptdialogYN---Q--- [yes] [no] ---\n--> ", 146 prompt); 147 p= fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 148 if (!p) { 149 //FIXME 150 } 137 151 if (tmp[strlen(tmp) - 1] == '\n') 138 152 tmp[strlen(tmp) - 1] = '\0'; … … 143 157 } 144 158 if (strstr("yesYES", tmp)) { 145 mr_free(tmp);159 paranoid_free(tmp); 146 160 return (TRUE); 147 161 } else if (strstr("NOno", tmp)) { 148 mr_free(tmp);162 paranoid_free(tmp); 149 163 return (FALSE); 150 164 } else { 151 sync(); 152 printf("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 165 paranoid_system("sync"); 166 printf 167 ("Please enter either YES or NO (or yes or no, or y or n, or...)\n"); 153 168 } 154 169 } … … 168 183 169 184 /*@ buffer *********************************************************** */ 170 char *tmp = NULL; 185 char *tmp; 186 char *p; 171 187 int i; 172 188 … … 177 193 finish(1); 178 194 } 179 195 tmp = malloc(MAX_NEWT_COMMENT_LEN); 180 196 if (g_text_mode) { 181 sync(); 182 printf("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", prompt); 183 mr_getline(tmp, stdin); 197 paranoid_system("sync"); 198 printf 199 ("---promptdialogOKC---1--- %s\n---promptdialogOKC---Q--- [OK] [Cancel] ---\n--> ", 200 prompt); 201 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, stdin); 202 if (!p) { 203 // FIXME 204 } 184 205 if (tmp[strlen(tmp) - 1] == '\n') 185 206 tmp[strlen(tmp) - 1] = '\0'; … … 190 211 } 191 212 if (strstr("okOKOkYESyes", tmp)) { 192 mr_free(tmp);213 paranoid_free(tmp); 193 214 return (TRUE); 194 215 } else { 195 mr_free(tmp);216 paranoid_free(tmp); 196 217 return (FALSE); 197 218 } 198 219 } else { 220 paranoid_free(tmp); 199 221 return (popup_with_buttons(prompt, " Okay ", "Cancel")); 200 222 } … … 242 264 } 243 265 if (g_current_progress == -999) { 244 log_msg(2, "Trying to close the progress form when it ain't open!"); 266 log_msg(2, 267 "Trying to close the progress form when it ain't open!"); 245 268 return; 246 269 } … … 278 301 mr_asprintf(tmp1,"kill `%s`", tmp); 279 302 run_program_and_log_output(tmp1, TRUE); 280 mr_free(tmp1);281 } 282 mr_free(tmp);303 paranoid_free(tmp1); 304 } 305 paranoid_free(tmp); 283 306 } 284 307 … … 289 312 * @note This function never returns. 290 313 */ 291 void fatal_error(char *error_string) { 292 314 void 315 fatal_error(char *error_string) { 293 316 /*@ buffers ***************************************************** */ 294 char *command = NULL; 317 char fatalstr[MAX_NEWT_COMMENT_LEN] = 318 "-------FATAL ERROR---------"; 319 char *tmp; 320 char *command; 295 321 static bool already_exiting = FALSE; 296 322 297 323 /*@ end vars **************************************************** */ 298 324 325 malloc_string(command); 326 tmp = malloc(MAX_NEWT_COMMENT_LEN); 299 327 set_signals(FALSE); // link to external func 300 328 g_exiting = TRUE; … … 304 332 log_msg(2, "mastermind %d is exiting", (int) getpid()); 305 333 kill(g_main_pid, SIGTERM); 334 paranoid_free(tmp); 306 335 finish(1); 307 336 } … … 311 340 log_msg(2, "non-m/m %d is exiting", (int) getpid()); 312 341 kill(g_main_pid, SIGTERM); 342 paranoid_free(tmp); 313 343 finish(1); 314 344 } … … 318 348 if (already_exiting) { 319 349 log_msg(3, "...I'm already exiting. Give me time, Julian!"); 350 paranoid_free(tmp); 320 351 finish(1); 321 352 } … … 328 359 kill_anything_like_this("ntfsclone"); 329 360 sync(); 361 /* 362 sprintf(tmp, "umount %s", g_tmpfs_mountpt); 363 for (i = 0; i < 10 && run_program_and_log_output(tmp, 5); i++) { 364 log_msg(2, "Waiting for child processes to terminate"); 365 sleep(1); 366 run_program_and_log_output(tmp, 5); 367 } 368 */ 330 369 331 370 if (chdir("/")) { … … 333 372 } 334 373 if (g_selfmounted_isodir) { 335 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir);374 sprintf(command, "umount -d %s", g_selfmounted_isodir); 336 375 run_program_and_log_output(command, 5); 337 mr_free(command); 338 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 376 sprintf(command, "rmdir %s", g_selfmounted_isodir); 339 377 run_program_and_log_output(command, 5); 340 mr_free(command);341 378 } 342 379 343 380 if (!g_text_mode) { 344 log_msg(0, "-------FATAL ERROR---------");381 log_msg(0, fatalstr); 345 382 log_msg(0, error_string); 383 // popup_and_OK (error_string); 384 newtFinished(); 346 385 } 347 386 348 387 printf("---FATALERROR--- %s\n", error_string); 349 printf("If you require technical support, please contact the mailing list.\n"); 388 printf 389 ("If you require technical support, please contact the mailing list.\n"); 350 390 printf("See http://www.mondorescue.org for details.\n"); 351 printf("The list's members can help you, if you attach that file to your e-mail.\n"); 391 printf 392 ("The list's members can help you, if you attach that file to your e-mail.\n"); 352 393 printf("Log file: %s\n", MONDO_LOGFILE); 353 394 printf("Mondo has aborted.\n"); … … 355 396 log_msg(3, "FYI - g_main_pid is blank"); 356 397 } 398 paranoid_free(tmp); 399 paranoid_free(command); 357 400 finish(254); 358 401 } … … 377 420 * @note This function never returns. 378 421 */ 379 void finish(int signal) { 380 422 void 423 finish(int signal) { 381 424 char *command = NULL; 425 426 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */ 427 428 /* newtPopHelpLine(); */ 382 429 383 430 /* Before removing dir, make sure we're out of them */ … … 389 436 mr_asprintf(command, "umount -d %s", g_selfmounted_isodir); 390 437 run_program_and_log_output(command, 1); 391 mr_free(command); 392 438 paranoid_free(command); 393 439 mr_asprintf(command, "rmdir %s", g_selfmounted_isodir); 394 440 run_program_and_log_output(command, 1); 395 mr_free(command); 396 } 441 paranoid_free(command); 442 } 443 if (!g_text_mode) { 444 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 445 log_msg(1, "Calling newtFinished()"); 446 newtFinished(); 447 } else { 448 log_msg(1, "Calling newtSuspend()"); 449 newtSuspend(); 450 } 451 } 452 printf("Execution run ended; result=%d\n", signal); 453 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE); 397 454 if (bkpinfo->tmpdir) { 398 455 log_msg(8,"tempdir is %s",bkpinfo->tmpdir); … … 419 476 mr_free(bkpinfo->exclude_paths); 420 477 mr_free(bkpinfo->subdir); 478 421 479 /* Then free the structure */ 422 480 paranoid_free(bkpinfo); 423 424 481 free_libmondo_global_strings(); 425 482 free_newt_stuff(); 426 if (!g_text_mode) {427 if (does_file_exist("/THIS-IS-A-RAMDISK")) {428 log_msg(1, "Calling newtFinished()");429 newtFinished();430 } else {431 log_msg(1, "Calling newtSuspend()");432 newtSuspend();433 }434 }435 printf("Execution run ended; result=%d\n", signal);436 printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);437 483 exit(signal); 438 484 } 485 486 487 439 488 440 489 … … 445 494 * @param grep_for_me If not "", then only give lines in @p filename that match this regular expression. 446 495 */ 447 void log_file_end_to_screen(char *filename, char *grep_for_me) { 496 void 497 log_file_end_to_screen(char *filename, char *grep_for_me) { 448 498 449 499 /*@ buffers ********************************************************** */ … … 465 515 } 466 516 if (grep_for_me[0] != '\0') { 467 mr_asprintf(command, "grep '%s' %s | tail -n%d", grep_for_me, filename, g_noof_log_lines); 468 } else { 469 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, filename); 517 mr_asprintf(command, "grep '%s' %s | tail -n%d", 518 grep_for_me, filename, g_noof_log_lines); 519 } else { 520 mr_asprintf(command, "tail -n%d %s", g_noof_log_lines, 521 filename); 470 522 } 471 523 fin = popen(command, "r"); … … 505 557 * @note The message is also written to the logfile. 506 558 */ 507 void log_to_screen(const char *fmt, ...) { 559 void 560 log_to_screen(const char *fmt, ...) { 508 561 509 562 /*@ int ************************************************************** */ … … 561 614 * @param output The string to write. 562 615 */ 563 void mvaddstr_and_log_it(int y, int x, char *output) { 564 616 void 617 mvaddstr_and_log_it(int y, int x, char *output) { 565 618 assert_string_is_neither_NULL_nor_zerolength(output); 566 619 log_msg(0, output); … … 580 633 * @param ttl The title to use for the evalcall form. 581 634 */ 582 void open_evalcall_form(char *ttl) { 635 void 636 open_evalcall_form(char *ttl) { 583 637 584 638 /*@ buffers ********************************************************* */ 585 char *tmp = NULL; 639 char *title; 640 char *tmp; 586 641 587 642 /*@ initialize ****************************************************** */ 588 643 g_isoform_old_progress = -1; 589 644 g_mysterious_dot_counter = 0; 645 malloc_string(title); 646 malloc_string(tmp); 590 647 591 648 assert(ttl != NULL); 592 malloc_string(tmp); 593 strcpy(g_isoform_header_str, ttl); 649 strcpy(title, ttl); 650 strcpy(g_isoform_header_str, title); 651 // center_string (title, 80); 594 652 if (g_text_mode) { 595 log_msg(0, t tl);596 } else { 597 strcpy(tmp, t tl);653 log_msg(0, title); 654 } else { 655 strcpy(tmp, title); 598 656 center_string(tmp, 80); 599 657 newtPushHelpLine(tmp); … … 606 664 g_isoform_header = newtLabel(1, 1, g_isoform_header_str); 607 665 g_isoform_scale = newtScale(3, 3, 34, 100); 608 newtCenteredWindow(40, 7, ttl); 666 // newtOpenWindow (20, 6, 40, 7, title); // "Please Wait"); 667 newtCenteredWindow(40, 7, title); 609 668 g_isoform_main = newtForm(NULL, NULL, 0); 610 669 g_isoform_timeline = newtLabel(1, 5, " "); … … 618 677 update_evalcall_form(0); 619 678 paranoid_free(tmp); 679 paranoid_free(title); 620 680 } 621 681 … … 631 691 * @param max_val The maximum amount of progress (number of filesets, etc.) 632 692 */ 633 void open_progress_form(char *title, char *b1, char *b2, char *b3, long max_val) { 693 void 694 open_progress_form(char *title, char *b1, char *b2, char *b3, 695 long max_val) { 634 696 635 697 /*@ buffers ********************************************************* */ 636 698 char *b1c; 637 char *blurb1 = NULL;638 char *blurb2 = NULL;639 char *blurb3 = NULL;699 char *blurb1; 700 char *blurb2; 701 char *blurb3; 640 702 641 703 /*@ initialize ****************************************************** */ … … 643 705 644 706 malloc_string(b1c); 707 malloc_string(blurb1); 708 malloc_string(blurb2); 709 malloc_string(blurb3); 645 710 646 711 assert(title != NULL); … … 649 714 assert(b3 != NULL); 650 715 651 mr_asprintf(blurb1, "%s", b1); 652 mr_asprintf(blurb2, "%s", b2); 653 mr_asprintf(blurb3, "%s", b3); 654 716 strcpy(blurb1, b1); 717 strcpy(blurb2, b2); 718 strcpy(blurb3, b3); 655 719 strcpy(b1c, b1); 656 720 center_string(b1c, 80); … … 673 737 g_blurb2 = newtLabel(2, 2, blurb3); 674 738 g_blurb3 = newtLabel(2, 4, blurb2); 739 // newtOpenWindow (10, 4, 60, 11, title); 675 740 newtCenteredWindow(60, 11, title); 676 g_scale = newtScale(3, 6, 54, (long long)g_maximum_progress);741 g_scale = newtScale(3, 6, 54, g_maximum_progress); 677 742 g_progressForm = newtForm(NULL, NULL, 0); 678 743 g_percentline = newtLabel(10, 9, " "); 679 744 g_timeline = newtLabel(10, 8, " "); 680 newtFormAddComponents(g_progressForm, g_percentline, g_timeline, g_scale, g_blurb1, g_blurb3, g_blurb2, NULL); 745 newtFormAddComponents(g_progressForm, g_percentline, 746 g_timeline, g_scale, g_blurb1, g_blurb3, 747 g_blurb2, NULL); 681 748 newtPushHelpLine(b1c); 682 749 newtDrawForm(g_progressForm); … … 685 752 update_progress_form_full(blurb1, blurb2, blurb3); 686 753 paranoid_free(b1c); 687 mr_free(blurb1);688 mr_free(blurb2);689 mr_free(blurb3);754 paranoid_free(blurb1); 755 paranoid_free(blurb2); 756 paranoid_free(blurb3); 690 757 } 691 758 … … 694 761 * @param prompt The message. 695 762 */ 696 void popup_and_OK(char *prompt) { 697 763 void 764 popup_and_OK(char *prompt) { 698 765 char ch; 699 766 … … 702 769 log_msg(0, prompt); 703 770 if (g_text_mode) { 704 printf("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", prompt); 771 printf 772 ("---promptpopup---1--- %s\n---promptpopup---Q--- [OK] ---\n--> ", 773 prompt); 705 774 while (((ch = getchar()) != '\n') && (ch != EOF)); 706 775 } else { … … 717 786 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 718 787 */ 719 bool popup_and_get_string(char *title, char *b, char *output, int maxsize) { 788 bool popup_and_get_string(char *title, char *b, char *output, 789 int maxsize) { 720 790 721 791 /*@ newt ************************************************************ */ … … 731 801 732 802 /*@ buffers ********************************************************** */ 733 char *blurb = NULL;803 char *blurb; 734 804 char *p; 735 char *original_contents = NULL; 736 805 char *original_contents; 806 807 blurb = malloc(MAX_NEWT_COMMENT_LEN); 808 original_contents = malloc(MAX_NEWT_COMMENT_LEN); 737 809 assert_string_is_neither_NULL_nor_zerolength(title); 738 810 assert(b != NULL); … … 740 812 741 813 if (g_text_mode) { 742 printf("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", title, b); 814 printf 815 ("---promptstring---1--- %s\n---promptstring---2--- %s\n---promptstring---Q---\n--> ", 816 title, b); 743 817 p = fgets(output, maxsize, stdin); 744 818 if (!p) { … … 747 821 if (output[strlen(output) - 1] == '\n') 748 822 output[strlen(output) - 1] = '\0'; 823 paranoid_free(blurb); 824 paranoid_free(original_contents); 749 825 return (TRUE); 750 826 } 751 752 blurb = malloc(MAX_NEWT_COMMENT_LEN);753 827 strcpy(blurb, b); 754 828 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 755 mr_asprintf(original_contents, "%s", output);829 strcpy(original_contents, output); 756 830 output[0] = '\0'; 757 type_here = newtEntry(2, newtTextboxGetNumLines(text) + 2, original_contents, 50, 831 type_here = 832 newtEntry(2, newtTextboxGetNumLines(text) + 2, 833 original_contents, 50, 758 834 #ifdef __cplusplus 759 835 0, NEWT_FLAG_RETURNEXIT … … 764 840 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, " OK "); 765 841 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, "Cancel"); 842 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title); 766 843 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 767 844 myForm = newtForm(NULL, NULL, 0); … … 774 851 newtFormDestroy(myForm); 775 852 newtPopWindow(); 776 paranoid_free(blurb);777 778 853 if (b_res == b_2) { 779 854 strcpy(output, original_contents); 780 mr_free(original_contents); 855 paranoid_free(blurb); 856 paranoid_free(original_contents); 781 857 return (FALSE); 782 858 } else { 783 mr_free(original_contents); 859 paranoid_free(blurb); 860 paranoid_free(original_contents); 784 861 return (TRUE); 785 862 } … … 794 871 * @return TRUE if @p button1 was pushed, FALSE otherwise. 795 872 */ 796 bool popup_with_buttons(char *p, char *button1, char *button2) {873 bool popup_with_buttons(char *p, char *button1, char *button2) { 797 874 798 875 /*@ buffers *********************************************************** */ 799 char *prompt = NULL; 876 char *prompt; 877 char *q; 800 878 801 879 /*@ newt ************************************************************** */ … … 809 887 assert(button1 != NULL); 810 888 assert(button2 != NULL); 889 prompt = malloc(MAX_NEWT_COMMENT_LEN); 811 890 if (g_text_mode) { 812 891 if (strlen(button2) == 0) { … … 815 894 printf("%s (%s or %s) --> ", p, button1, button2); 816 895 } 817 mr_getline(prompt, stdin); 818 while (strcmp(prompt, button1) && (strlen(button2) == 0 || strcmp(prompt, button2))) { 896 for (prompt[0] = '\0'; 897 strcmp(prompt, button1) && (strlen(button2) == 0 898 || strcmp(prompt, button2));) { 819 899 printf("--> "); 820 mr_free(prompt); 821 mr_getline(prompt, stdin); 900 q = fgets(prompt, MAX_NEWT_COMMENT_LEN, stdin); 901 if (!q) { 902 // FIXME 903 } 822 904 } 823 905 if (!strcmp(prompt, button1)) { 824 mr_free(prompt);906 paranoid_free(prompt); 825 907 return (TRUE); 826 908 } else { 827 mr_free(prompt);909 paranoid_free(prompt); 828 910 return (FALSE); 829 911 } 830 912 } 831 913 832 prompt = malloc(MAX_NEWT_COMMENT_LEN);833 914 strncpy(prompt, p, MAX_NEWT_COMMENT_LEN - 1); 834 915 prompt[MAX_NEWT_COMMENT_LEN - 1] = '\0'; 835 916 text = newtTextboxReflowed(1, 1, prompt, 40, 5, 5, 0); 836 b_1 = newtButton(20 - ((button2[0] != '\0') ? strlen(button1) + 2 : strlen(button1) / 2), newtTextboxGetNumLines(text) + 3, button1); 917 b_1 = 918 newtButton(20 - 919 ((button2[0] != 920 '\0') ? strlen(button1) + 921 2 : strlen(button1) / 2), 922 newtTextboxGetNumLines(text) + 3, button1); 837 923 if (button2[0] != '\0') { 838 b_2 = newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 924 b_2 = 925 newtButton(24, newtTextboxGetNumLines(text) + 3, button2); 839 926 } else { 840 927 b_2 = NULL; 841 928 } 929 // newtOpenWindow (25, 5, 46, newtTextboxGetNumLines (text) + 7, "Alert"); 842 930 newtCenteredWindow(46, newtTextboxGetNumLines(text) + 7, "Alert"); 843 931 myForm = newtForm(NULL, NULL, 0); … … 865 953 * on the screen. 866 954 */ 867 void refresh_log_screen() { 955 void 956 refresh_log_screen() { 868 957 869 958 /*@ int *********************************************************** */ … … 892 981 * only allocate some memory. 893 982 */ 894 void setup_newt_stuff() { 983 void 984 setup_newt_stuff() { 895 985 896 986 /*@ int *********************************************************** */ … … 901 991 newtInit(); 902 992 newtCls(); 903 newtPushHelpLine("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 993 newtPushHelpLine 994 ("Welcome to Mondo Rescue, by Dev Team and the Internet. All rights reversed."); 995 /* newtDrawRootText(28,0,"Welcome to Mondo Rescue"); */ 904 996 newtDrawRootText(18, 0, WELCOME_STRING); 905 997 newtRefresh(); … … 908 1000 } 909 1001 910 err_log_lines = (char **) mr_malloc(sizeof(char *) * g_noof_log_lines); 1002 err_log_lines = 1003 (char **) malloc(sizeof(char *) * g_noof_log_lines); 1004 if (!err_log_lines) { 1005 fatal_error("Out of memory"); 1006 } 911 1007 912 1008 for (i = 0; i < g_noof_log_lines; i++) { 913 err_log_lines[i] = (char *) mr_malloc(MAX_NEWT_COMMENT_LEN); 1009 err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN); 1010 if (!err_log_lines[i]) { 1011 fatal_error("Out of memory"); 1012 } 914 1013 } 915 1014 … … 925 1024 * @param denom The denomenator of the ratio. 926 1025 */ 927 void update_evalcall_form_ratio(int num, int denom) { 1026 void 1027 update_evalcall_form_ratio(int num, int denom) { 928 1028 929 1029 /*@ long ************************************************************ */ 930 long current_time = 0 L;931 long time_taken = 0 L;932 long time_total_est = 0 L;933 long time_remaining = 0 L;1030 long current_time = 0; 1031 long time_taken = 0; 1032 long time_total_est = 0; 1033 long time_remaining = 0; 934 1034 935 1035 /*@ buffers ********************************************************** */ 936 char *timeline_str = NULL;1036 char *timeline_str; 937 1037 char *pcline_str = NULL; 938 1038 char *taskprogress = NULL; … … 943 1043 int j = 0; 944 1044 1045 malloc_string(timeline_str); 1046 timeline_str[0] = '\0'; 1047 // log_it("update_eval_call_form called"); 945 1048 if (num * 100 < denom) { 946 1049 percentage = 1; … … 955 1058 time_remaining = time_total_est - time_taken; 956 1059 } else { 957 time_remaining = 0 L;1060 time_remaining = 0; 958 1061 } 959 1062 if (!g_text_mode) { … … 966 1069 || percentage > g_isoform_old_progress) { 967 1070 g_isoform_old_progress = percentage; 968 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60); 1071 sprintf(timeline_str, 1072 "%2ld:%02ld taken %2ld:%02ld remaining", 1073 (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, 1074 (long) time_remaining % 60); 969 1075 if (percentage < 3) { 970 1076 mr_asprintf(pcline_str, " Working"); … … 977 1083 mr_strcat(pcline_str, " %c", special_dot_char(g_mysterious_dot_counter)); 978 1084 } else { 979 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage); 1085 mr_asprintf(pcline_str, " %3d%% done %3d%% to go", 1086 percentage, 100 - percentage); 980 1087 } 981 1088 if (g_text_mode) { … … 988 1095 } 989 1096 if (percentage >= 3) { 990 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 991 printf("---evalcall---1--- %s\n", g_isoform_header_str); 1097 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1098 (long) time_remaining / 60, (long) time_remaining % 60); 1099 printf("---evalcall---1--- %s\n", 1100 g_isoform_header_str); 992 1101 printf("---evalcall---2--- %s\n", taskprogress); 993 1102 printf("---evalcall---E---\n"); 994 1103 } 995 mr_free(taskprogress);1104 paranoid_free(taskprogress); 996 1105 } else { 997 newtScaleSet(g_isoform_scale, (unsigned long long) percentage); 1106 newtScaleSet(g_isoform_scale, 1107 (unsigned long long) percentage); 998 1108 if (g_isoform_pcline) { 999 1109 newtLabelSetText(g_isoform_pcline, pcline_str); … … 1003 1113 } 1004 1114 } 1005 mr_free(pcline_str); 1006 mr_free(timeline_str); 1115 paranoid_free(pcline_str); 1007 1116 } 1008 1117 if (!g_text_mode) { 1118 // log_it("refreshing"); 1009 1119 newtDrawForm(g_isoform_main); 1010 1120 newtRefresh(); 1011 1121 } 1122 paranoid_free(timeline_str); 1012 1123 } 1013 1124 … … 1018 1129 * @param curr The current amount of progress (percentage) in the evalcall form. 1019 1130 */ 1020 void update_evalcall_form(int curr) { 1021 1131 void 1132 update_evalcall_form(int curr) { 1022 1133 update_evalcall_form_ratio(curr, 100); 1023 }1134 } 1024 1135 1025 1136 … … 1030 1141 * @param blurb3 The new third line of the blurb; use @p g_blurb_str_2 (no, that's not a typo) to keep it the same. 1031 1142 */ 1032 void update_progress_form(char *blurb3) { 1033 1143 void 1144 update_progress_form(char *blurb3) { 1145 /* log_it("update_progress_form --- called"); */ 1034 1146 if (g_current_progress == -999) { 1147 /* log_it("You're trying to update progress form when it ain't open. Aww, that's OK. I'll let it go. It's a bit naughty but it's a nonfatal error. No prob, Bob."); */ 1035 1148 return; 1036 1149 } 1037 1150 strcpy(g_blurb_str_2, blurb3); 1038 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, g_blurb_str_3); 1039 } 1151 update_progress_form_full(g_blurb_str_1, g_blurb_str_2, 1152 g_blurb_str_3); 1153 } 1040 1154 1041 1155 … … 1046 1160 * @param blurb3 The third line of the blurb. Use @p g_blurb_str_2 (no, that's not a typo either) to keep it the same. 1047 1161 */ 1048 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1049 1162 void 1163 update_progress_form_full(char *blurb1, char *blurb2, char *blurb3) { 1050 1164 /*@ long ***************************************************** */ 1051 1165 long current_time = 0L; … … 1059 1173 1060 1174 /*@ buffers *************************************************** */ 1061 char *percentline_str = NULL;1062 char *timeline_str = NULL;1175 char *percentline_str; 1176 char *timeline_str; 1063 1177 char *taskprogress = NULL; 1064 1178 char *tmp; 1179 1180 // log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3); 1181 percentline_str = malloc(MAX_NEWT_COMMENT_LEN); 1182 timeline_str = malloc(MAX_NEWT_COMMENT_LEN); 1183 malloc_string(tmp); 1065 1184 if (!g_text_mode) { 1066 1185 assert(blurb1 != NULL); … … 1070 1189 } 1071 1190 1191 percentline_str[0] = '\0'; 1192 1072 1193 current_time = get_time(); 1073 1194 time_taken = current_time - g_start_time; … … 1076 1197 } else { 1077 1198 if (g_current_progress > g_maximum_progress) { 1078 log_msg(0, "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", blurb1, blurb2, blurb3, g_current_progress, g_maximum_progress); 1199 sprintf(tmp, 1200 "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld", 1201 blurb1, blurb2, blurb3, g_current_progress, 1202 g_maximum_progress); 1203 log_msg(0, tmp); 1079 1204 g_current_progress = g_maximum_progress; 1080 1205 } 1081 percentage = (int) ((g_current_progress * 100L) / g_maximum_progress); 1206 percentage = 1207 (int) ((g_current_progress * 100L) / g_maximum_progress); 1082 1208 } 1083 1209 if (percentage < 1) { … … 1088 1214 } 1089 1215 if (g_current_progress) { 1090 time_total_est = time_taken * (long) g_maximum_progress / (long) g_current_progress; 1216 time_total_est = 1217 time_taken * (long) g_maximum_progress / 1218 (long) (g_current_progress); 1091 1219 time_remaining = time_total_est - time_taken; 1092 1220 } else { … … 1094 1222 } 1095 1223 g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27; 1224 sprintf(timeline_str, 1225 "%2ld:%02ld taken %2ld:%02ld remaining ", 1226 (long) time_taken / 60, time_taken % 60, time_remaining / 60, 1227 time_remaining % 60); 1228 sprintf(percentline_str, " %3d%% done %3d%% to go", 1229 percentage, 100 - percentage); 1230 1096 1231 if (g_text_mode) { 1097 1232 printf("---progress-form---1--- %s\n", blurb1); … … 1109 1244 log_msg(2, "percentage = %d", percentage); 1110 1245 } 1111 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, (long) time_remaining / 60, (long) time_remaining % 60); 1246 mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage, 1247 (long) time_remaining / 60, (long) time_remaining % 60); 1112 1248 printf("---progress-form---4--- %s\n", taskprogress); 1113 1249 paranoid_free(taskprogress); 1114 1250 } else { 1115 mr_asprintf(timeline_str, "%2ld:%02ld taken %2ld:%02ld remaining ", (long) time_taken / 60, (long) time_taken % 60, (long) time_remaining / 60, (long) time_remaining % 60);1116 mr_asprintf(percentline_str, " %3d%% done %3d%% to go", percentage, 100 - percentage);1117 1118 1251 center_string(blurb1, 54); 1119 1252 center_string(blurb2, 54); … … 1132 1265 newtLabelSetText(g_timeline, timeline_str); 1133 1266 } 1134 mr_free(timeline_str);1135 1136 1267 if (g_percentline) { 1137 1268 newtLabelSetText(g_percentline, percentline_str); 1138 1269 } 1139 mr_free(percentline_str);1140 1141 1270 newtDrawForm(g_progressForm); 1142 1271 newtRefresh(); 1143 1272 } 1144 } 1273 paranoid_free(percentline_str); 1274 paranoid_free(timeline_str); 1275 paranoid_free(tmp); 1276 } 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1145 1289 1146 1290 … … 1153 1297 * @return The backup type chosen, or @c none if the user chose "Exit to shell". 1154 1298 */ 1155 t_bkptype which_backup_media_type(bool restoring) {1299 t_bkptype which_backup_media_type(bool restoring) { 1156 1300 1157 1301 /*@ char ************************************************************ */ … … 1160 1304 1161 1305 /*@ newt ************************************************************ */ 1162 char *title_sz = NULL; 1163 char *minimsg_sz = NULL; 1164 static t_bkptype possible_bkptypes[] = { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1165 static char *possible_responses[] = { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", "netfs", "iso", NULL }; 1166 char *outstr = NULL; 1306 char *title_sz; 1307 char *minimsg_sz; 1308 static t_bkptype possible_bkptypes[] = 1309 { none, cdr, cdrw, dvd, tape, cdstream, udev, netfs, iso }; 1310 static char *possible_responses[] = 1311 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1312 "netfs", "iso", NULL }; 1313 char *outstr; 1314 char *p; 1167 1315 t_bkptype backup_type; 1168 1316 int i; … … 1179 1327 newtComponent myForm; 1180 1328 1329 title_sz = malloc(MAX_NEWT_COMMENT_LEN); 1330 minimsg_sz = malloc(MAX_NEWT_COMMENT_LEN); 1331 outstr = malloc(MAX_NEWT_COMMENT_LEN); 1181 1332 if (g_text_mode) { 1182 1333 for (backup_type = none; backup_type == none;) { … … 1187 1338 } 1188 1339 printf(")\n--> "); 1189 mr_getline(outstr, stdin); 1190 mr_strip_spaces(outstr); 1340 p = fgets(outstr, MAX_NEWT_COMMENT_LEN, stdin); 1341 if (!p) { 1342 // FIXME 1343 } 1344 strip_spaces(outstr); 1191 1345 for (i = 0; possible_responses[i]; i++) { 1192 1346 if (!strcmp(possible_responses[i], outstr)) { … … 1194 1348 } 1195 1349 } 1196 mr_free(outstr); 1197 } 1350 } 1351 paranoid_free(title_sz); 1352 paranoid_free(minimsg_sz); 1353 paranoid_free(outstr); 1198 1354 return (backup_type); 1199 1355 } 1200 1356 newtDrawRootText(18, 0, WELCOME_STRING); 1201 1357 if (restoring) { 1202 mr_asprintf(title_sz, "Please choose the backup media from which you want to read data."); 1203 mr_asprintf(minimsg_sz, "Read from:"); 1204 } else { 1205 mr_asprintf(title_sz, "Please choose the backup media to which you want to archive data."); 1206 mr_asprintf(minimsg_sz, "Backup to:"); 1358 strcpy(title_sz, 1359 "Please choose the backup media from which you want to read data."); 1360 strcpy(minimsg_sz, "Read from:"); 1361 } else { 1362 strcpy(title_sz, 1363 "Please choose the backup media to which you want to archive data."); 1364 strcpy(minimsg_sz, "Backup to:"); 1207 1365 } 1208 1366 newtPushHelpLine(title_sz); 1367 // newtOpenWindow (23, 3, 34, 17, minimsg_sz); 1209 1368 newtCenteredWindow(34, 17, minimsg_sz); 1210 1369 b1 = newtButton(1, 1, "CD-R disks "); … … 1240 1399 } 1241 1400 newtPopHelpLine(); 1242 mr_free(title_sz); 1243 mr_free(minimsg_sz); 1401 paranoid_free(title_sz); 1402 paranoid_free(minimsg_sz); 1403 paranoid_free(outstr); 1244 1404 return (output); 1245 1405 } … … 1263 1423 newtComponent b2; 1264 1424 newtComponent b3; 1265 newtComponent b4;1425 //newtComponent b4; 1266 1426 newtComponent b5; 1267 1427 newtComponent b_res; … … 1275 1435 b2 = newtButton(18, 1, "gzip"); 1276 1436 b3 = newtButton(4, 5, "lzo"); 1277 b4 = newtButton(18, 5, "lzma");1437 //b4 = newtButton(18, 5, "lzma"); 1278 1438 b5 = newtButton(4, 9, " Exit "); 1279 1439 myForm = newtForm(NULL, NULL, 0); … … 1288 1448 } else if (b_res == b3) { 1289 1449 mr_asprintf(output, "%s", "lzo"); 1290 } else if (b_res == b4) {1291 mr_asprintf(output, "%s", "lzma");1450 //} else if (b_res == b4) { 1451 //mr_asprintf(output, "%s", "lzma"); 1292 1452 } 1293 1453 newtPopHelpLine(); … … 1301 1461 * @return The compression level (0-9) chosen, or -1 for "Exit". 1302 1462 */ 1303 int which_compression_level() { 1463 int 1464 which_compression_level() { 1304 1465 1305 1466 /*@ char ************************************************************ */ … … 1318 1479 1319 1480 newtDrawRootText(18, 0, WELCOME_STRING); 1320 newtPushHelpLine(" Please specify the level of compression that you want."); 1481 newtPushHelpLine 1482 (" Please specify the level of compression that you want."); 1483 // newtOpenWindow (23, 3, 34, 13, "How much compression?"); 1321 1484 newtCenteredWindow(34, 13, "How much compression?"); 1322 1485 b1 = newtButton(4, 1, "Maximum (9)"); … … 1355 1518 * @param source_file The file containing a list of filenames to load into @p filelist. 1356 1519 */ 1357 int load_filelist_into_array(struct s_filelist *filelist, char *source_file) { 1358 1520 int load_filelist_into_array(struct s_filelist *filelist, 1521 char *source_file) { 1359 1522 int i; 1360 1523 int j = 0; 1361 1524 bool done; 1362 char *tmp = NULL; 1525 char *tmp; 1526 char *p; 1363 1527 char *tmp1 = NULL; 1364 1528 FILE *fin, *fout; … … 1379 1543 if (!(fout = fopen(tmp1, "a"))) { 1380 1544 log_msg(2, "Can't write to %s", tmp1); 1381 mr_free(tmp1);1382 1545 return(1); 1383 1546 } 1384 1547 1548 malloc_string(tmp); 1385 1549 log_msg(2, "Loading %s", source_file); 1386 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; ) { 1387 mr_free(tmp); 1550 for (filelist->entries = 0; filelist->entries <= ARBITRARY_MAXIMUM; 1551 filelist->entries++) { 1552 god_i_hate_gotos: 1388 1553 if (feof(fin)) { 1389 1554 break; 1390 1555 } 1391 mr_getline(tmp, fin); 1556 p = fgets(tmp, MAX_NEWT_COMMENT_LEN, fin); 1557 if (!p) { 1558 // FIXME 1559 } 1392 1560 i = (int) strlen(tmp); 1393 1561 if (i < 2) { 1394 continue;1562 goto god_i_hate_gotos; 1395 1563 } 1396 1564 if (tmp[i - 1] < 32) { … … 1398 1566 } 1399 1567 if (i < 2) { 1400 continue;1568 goto god_i_hate_gotos; 1401 1569 } 1402 1570 if (!does_file_exist(tmp) && !feof(fin)) { 1403 1571 j++; 1404 1572 fprintf(fout, "%s\n", tmp); 1405 continue; 1406 } 1407 filelist->el[filelist->entries].severity = severity_of_difference(tmp, NULL); 1573 1574 goto god_i_hate_gotos; 1575 } 1576 filelist->el[filelist->entries].severity = 1577 severity_of_difference(tmp, NULL); 1408 1578 strcpy(filelist->el[filelist->entries].filename, tmp); 1409 1579 if (feof(fin)) { 1410 1580 break; 1411 1581 } 1412 filelist->entries++; 1413 } 1414 mr_free(tmp); 1582 } 1415 1583 paranoid_fclose(fin); 1416 1584 paranoid_fclose(fout); … … 1418 1586 log_to_screen("%d files listed in %s/changed.files have been deleted since backup was made\nand are referenced in %s", j, bkpinfo->tmpdir,tmp1); 1419 1587 } 1420 mr_free(tmp1);1588 paranoid_free(tmp1); 1421 1589 if (filelist->entries >= ARBITRARY_MAXIMUM) { 1422 1590 log_to_screen("Arbitrary limits suck, man!"); 1591 paranoid_free(tmp); 1423 1592 return (1); 1424 1593 } … … 1448 1617 } 1449 1618 } 1619 paranoid_free(tmp); 1450 1620 log_it("leaving"); 1451 1621 return (0); 1452 1622 } 1623 1453 1624 1454 1625 … … 1459 1630 * @note The returned value points to static storage that will be overwritten with each call. 1460 1631 */ 1461 char *filelist_entry_to_string(struct s_filelist_entry *flentry) {1632 char *filelist_entry_to_string(struct s_filelist_entry *flentry) { 1462 1633 static char comment[100]; 1463 1634 char *tmp = NULL; 1464 1635 1465 log_ msg(8,"entering");1636 log_it("entering"); 1466 1637 assert(flentry != NULL); 1467 1638 if (flentry->severity == 0) { … … 1477 1648 mr_strcat(tmp, flentry->filename); 1478 1649 strncpy(comment, tmp, 99); 1479 mr_free(tmp);1650 paranoid_free(tmp); 1480 1651 1481 1652 log_it("leaving"); 1482 1653 return (comment); 1483 1654 } 1655 1656 1657 1484 1658 1485 1659 … … 1489 1663 * @param source_file The file containing a list of changed files. 1490 1664 */ 1491 void popup_changelist_from_file(char *source_file) { 1492 1493 char *reason = NULL; 1665 void popup_changelist_from_file(char *source_file) { 1666 char *reason; 1494 1667 newtComponent myForm; 1495 1668 newtComponent bClose; … … 1512 1685 1513 1686 /*@ buffers ********************************************************* */ 1514 char *tmp = NULL;1515 char *differ_sz = NULL;1687 char *tmp; 1688 char *differ_sz; 1516 1689 1517 1690 struct s_filelist *filelist; 1691 malloc_string(reason); 1692 tmp = malloc(5000); 1693 malloc_string(differ_sz); 1518 1694 assert_string_is_neither_NULL_nor_zerolength(source_file); 1519 1695 if (g_text_mode) { 1520 1696 log_msg(2, "Text mode. Therefore, no popup list."); 1521 return;1697 goto free_to_go; 1522 1698 } 1523 1699 log_msg(2, "Examining file %s", source_file); … … 1526 1702 if (lng < 1) { 1527 1703 log_msg(2, "No lines in file. Therefore, no popup list."); 1528 return; 1704 paranoid_free(reason); 1705 goto free_to_go; 1529 1706 } else if (lng >= ARBITRARY_MAXIMUM) { 1530 1707 log_msg(2, "Too many files differ for me to list."); 1531 return;1708 goto free_to_go; 1532 1709 } 1533 1710 … … 1538 1715 1539 1716 if (load_filelist_into_array(filelist, source_file)) { 1540 log_msg(2, "Can't open %s; therefore, cannot popup list", source_file); 1717 log_msg(2, "Can't open %s; therefore, cannot popup list", 1718 source_file); 1719 paranoid_free(reason); 1541 1720 return; 1542 1721 } 1543 log_msg(2, "%d files loaded into filelist array", filelist->entries); 1722 log_msg(2, "%d files loaded into filelist array", 1723 filelist->entries); 1544 1724 for (i = 0; i < filelist->entries; i++) { 1545 1725 keylist[i] = (void *) i; … … 1550 1730 keylist[i]); 1551 1731 } 1552 mr_asprintf(differ_sz, " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", i); 1732 sprintf(differ_sz, 1733 " %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.", 1734 i); 1553 1735 newtPushHelpLine(differ_sz); 1554 mr_free(differ_sz);1555 1556 1736 bClose = newtCompactButton(10, 15, " Close "); 1557 1737 bSelect = newtCompactButton(30, 15, " Select "); 1558 mr_asprintf(tmp, "%-10s %-20s", "Priority", "Filename");1738 sprintf(tmp, "%-10s %-20s", "Priority", "Filename"); 1559 1739 headerMsg = newtLabel(2, 1, tmp); 1560 mr_free(tmp);1561 1562 1740 newtOpenWindow(5, 4, 70, 16, "Non-matching files"); 1563 1741 myForm = newtForm(NULL, NULL, 0); 1564 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, bSelect, NULL);1565 1742 newtFormAddComponents(myForm, headerMsg, fileListbox, bClose, 1743 bSelect, NULL); 1566 1744 while (!finished) { 1567 1745 b_res = newtRunForm(myForm); … … 1578 1756 currline = i; 1579 1757 if (filelist->entries > 0) { 1580 malloc_string(reason);1581 severity_of_difference(filelist->el[currline]. filename, &reason);1582 mr_asprintf(tmp, "%s --- %s", filelist->el[currline].filename, reason);1583 1758 severity_of_difference(filelist->el[currline]. 1759 filename, reason); 1760 sprintf(tmp, "%s --- %s", 1761 filelist->el[currline].filename, reason); 1584 1762 popup_and_OK(tmp); 1585 mr_free(tmp);1586 paranoid_free(reason);1587 1763 } 1588 1764 } … … 1592 1768 newtPopWindow(); 1593 1769 newtPopHelpLine(); 1770 free_to_go: 1771 paranoid_free(reason); 1772 paranoid_free(tmp); 1773 paranoid_free(differ_sz); 1594 1774 return; 1595 1775 } -
branches/3.0/mondo/src/include/my-stuff.h
r3189 r3192 77 77 * The location where mindi media images are stored. 78 78 */ 79 #define MINDI_CACHE_REL "var/cache/mindi" /* Should be coherent with mindi */ 80 #define MINDI_CACHE "/"MINDI_CACHE_REL 79 #define MINDI_CACHE "/var/cache/mindi" 81 80 82 81 /** … … 89 88 */ 90 89 #define MDSTAT_FILE "/proc/mdstat" 91 92 #ifdef __FreeBSD__93 #define CMDLINE "/tmp/cmdline"94 #else95 // Default Linux96 #define CMDLINE "/proc/cmdline"97 #endif98 90 99 91 #undef assert -
branches/3.0/mondo/src/lib/mr_err.c
r3189 r3192 16 16 #include <stdio.h> 17 17 #include <stdlib.h> 18 #include "mr_msg.h"19 18 20 19 /* Pointer to the right cleanup function provided by each main */ 21 extern void (*mr_cleanup)( int);20 extern void (*mr_cleanup)(void); 22 21 23 22 /* … … 27 26 28 27 if (mr_cleanup != NULL) { 29 mr_cleanup( errorcode);28 mr_cleanup(); 30 29 } 31 30 if (message != NULL) { 32 31 fprintf(stderr,"%s\n",message); 33 32 } 34 mr_msg_close();35 33 exit(errorcode); 36 34 }
Note:
See TracChangeset
for help on using the changeset viewer.