Changeset 900 in MondoRescue for trunk/mondo/src/common/libmondo-devices.c
- Timestamp:
- Oct 24, 2006, 8:49:18 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/common/libmondo-devices.c
r839 r900 17 17 #include "libmondo-fork-EXT.h" 18 18 #include "libmondo-stream-EXT.h" 19 #include "mr_mem.h" 19 20 20 21 #include <sys/ioctl.h> … … 62 63 { 63 64 if (bkpinfo->media_device != NULL) { 64 paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case65 paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case65 mr_allocstr(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 66 mr_allocstr(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 66 67 } 67 68 } … … 113 114 make_hole_for_dir(mountpoint); 114 115 if (isdigit(device[0])) { 115 paranoid_free(device);116 mr_free(device); 116 117 device = find_cdrom_device(FALSE); 117 118 } … … 123 124 dev = make_vn(device)); 124 125 if (!dev) { 125 asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)",126 mr_asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)", 126 127 device); 127 128 fatal_error(command); 128 129 } 129 paranoid_free(device);130 mr_free(device); 130 131 device = dev; 131 132 #endif … … 137 138 138 139 #ifdef __FreeBSD__ 139 asprintf(&command, "mount_cd9660 -r %s %s 2>> %s",140 mr_asprintf(&command, "mount_cd9660 -r %s %s 2>> %s", 140 141 device, mountpoint, MONDO_LOGFILE); 141 142 #else 142 asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s",143 mr_asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s", 143 144 device, mountpoint, MONDO_LOGFILE); 144 145 #endif … … 150 151 retval = system(command); 151 152 log_msg(1, "system(%s) returned %d", command, retval); 152 paranoid_free(command);153 mr_free(command); 153 154 154 155 if (retval == 0) { … … 171 172 bool is_this_a_ramdisk = FALSE; 172 173 173 asprintf(&tmp, where_is_root_mounted());174 asprintf(&comment, "root is mounted at %s\n", tmp);174 mr_asprintf(&tmp, where_is_root_mounted()); 175 mr_asprintf(&comment, "root is mounted at %s\n", tmp); 175 176 log_msg(0, comment); 176 paranoid_free(comment);177 mr_free(comment); 177 178 178 179 log_msg(0, … … 194 195 } 195 196 #endif 196 paranoid_free(tmp);197 mr_free(tmp); 197 198 198 199 if (is_this_a_ramdisk) { … … 222 223 char *output = NULL; 223 224 224 paranoid_free(output);225 mr_free(output); 225 226 226 227 switch (bt) { 227 228 case none: 228 asprintf(&output, _("none"));229 mr_asprintf(&output, _("none")); 229 230 break; 230 231 case iso: 231 asprintf(&output, _("iso"));232 mr_asprintf(&output, _("iso")); 232 233 break; 233 234 case cdr: 234 asprintf(&output, _("cdr"));235 mr_asprintf(&output, _("cdr")); 235 236 break; 236 237 case cdrw: 237 asprintf(&output, _("cdrw"));238 mr_asprintf(&output, _("cdrw")); 238 239 break; 239 240 case cdstream: 240 asprintf(&output, _("cdstream"));241 mr_asprintf(&output, _("cdstream")); 241 242 break; 242 243 case nfs: 243 asprintf(&output, _("nfs"));244 mr_asprintf(&output, _("nfs")); 244 245 break; 245 246 case tape: 246 asprintf(&output, _("tape"));247 mr_asprintf(&output, _("tape")); 247 248 break; 248 249 case udev: 249 asprintf(&output, _("udev"));250 mr_asprintf(&output, _("udev")); 250 251 break; 251 252 default: 252 asprintf(&output, _("default"));253 mr_asprintf(&output, _("default")); 253 254 } 254 255 return (output); … … 272 273 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 273 274 && g_backup_media_type != udev) { 274 asprintf(&command, "mt -f %s offline", dev);275 mr_asprintf(&command, "mt -f %s offline", dev); 275 276 res1 = run_program_and_log_output(command, 1); 276 paranoid_free(command);277 mr_free(command); 277 278 } else { 278 279 res1 = 0; … … 281 282 #ifdef __FreeBSD__ 282 283 if (strstr(dev, "acd")) { 283 asprintf(&command, "cdcontrol -f %s eject", dev);284 } else { 285 asprintf(&command, "camcontrol eject `echo %s | sed 's|/dev/||'`",284 mr_asprintf(&command, "cdcontrol -f %s eject", dev); 285 } else { 286 mr_asprintf(&command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 286 287 dev); 287 288 } 288 289 #else 289 asprintf(&command, "eject %s", dev);290 mr_asprintf(&command, "eject %s", dev); 290 291 #endif 291 292 292 293 log_msg(3, "Ejecting %s", dev); 293 294 res2 = run_program_and_log_output(command, 1); 294 paranoid_free(command);295 mr_free(command); 295 296 if (res1 && res2) { 296 297 return (1); … … 313 314 #ifdef __FreeBSD__ 314 315 if (strstr(dev, "acd")) { 315 asprintf(&command, "cdcontrol -f %s close", dev);316 } else { 317 asprintf(&command, "camcontrol load `echo %s | sed 's|/dev/||'`",316 mr_asprintf(&command, "cdcontrol -f %s close", dev); 317 } else { 318 mr_asprintf(&command, "camcontrol load `echo %s | sed 's|/dev/||'`", 318 319 dev); 319 320 } 320 321 #else 321 asprintf(&command, "eject -t %s", dev);322 mr_asprintf(&command, "eject -t %s", dev); 322 323 #endif 323 324 i = run_program_and_log_output(command, FALSE); 324 paranoid_free(command);325 mr_free(command); 325 326 return (i); 326 327 } … … 341 342 assert_string_is_neither_NULL_nor_zerolength(device); 342 343 343 asprintf(&tmp, "ls %s > /dev/null 2> /dev/null", device);344 mr_asprintf(&tmp, "ls %s > /dev/null 2> /dev/null", device); 344 345 345 346 if (system(tmp)) { … … 348 349 ret = TRUE; 349 350 } 350 paranoid_free(tmp);351 mr_free(tmp); 351 352 return(ret); 352 353 } … … 398 399 #ifdef __FreeBSD__ 399 400 // We assume here that this is running from mondorestore. (It is.) 400 asprintf(&program, "ls %s >/dev/null 2>&1", drive);401 mr_asprintf(&program, "ls %s >/dev/null 2>&1", drive); 401 402 res = system(program); 402 paranoid_free(program);403 mr_free(program); 403 404 return(res); 404 405 #endif 405 406 406 asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive);407 mr_asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive); 407 408 fin = popen(program, "r"); 408 409 if (!fin) { 409 410 log_it("program=%s", program); 410 411 log_OS_error("Cannot popen-in program"); 411 paranoid_free(program);412 mr_free(program); 412 413 return (0); 413 414 } 414 paranoid_free(program);415 mr_free(program); 415 416 416 417 searchstr = build_partition_name(drive, partno); 417 asprintf(&tmp, "%s ", searchstr); 418 paranoid_free(searchstr); 419 420 for (res = 0; !res && getline(&incoming, &n, fin);) { 418 mr_asprintf(&tmp, "%s ", searchstr); 419 mr_free(searchstr); 420 421 for (res = 0; !res ;) { 422 mr_getline(&incoming, &n, fin); 421 423 if (strstr(incoming, tmp)) { 422 424 res = 1; 423 425 } 424 426 } 425 paranoid_free(incoming);427 mr_free(incoming); 426 428 427 429 if (pclose(fin)) { 428 430 log_OS_error("Cannot pclose fin"); 429 431 } 430 paranoid_free(tmp);432 mr_free(tmp); 431 433 return (res); 432 434 } … … 450 452 assert_string_is_neither_NULL_nor_zerolength(str); 451 453 452 asprintf(&command,454 mr_asprintf(&command, 453 455 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 454 456 dev, str); 455 457 ret = system(command); 456 paranoid_free(command);458 mr_free(command); 457 459 if (ret) { 458 460 return (FALSE); … … 477 479 int ret; 478 480 479 asprintf(&command,481 mr_asprintf(&command, 480 482 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 481 483 dev, n, str); 482 484 ret = system(command); 483 paranoid_free(command);485 mr_free(command); 484 486 485 487 if (ret) { … … 514 516 if (g_backup_media_type == dvd) { 515 517 if (g_dvd_drive_is_here != NULL) { 516 asprintf(&dev, g_dvd_drive_is_here);518 mr_asprintf(&dev, g_dvd_drive_is_here); 517 519 } else { 518 520 dev = find_dvd_device(); … … 520 522 } else { 521 523 if (g_cdrom_drive_is_here != NULL) { 522 asprintf(&dev, g_cdrom_drive_is_here);524 mr_asprintf(&dev, g_cdrom_drive_is_here); 523 525 } else { 524 526 // find_cdrom_device allocates the string … … 532 534 533 535 if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) { 534 paranoid_free(dev);536 mr_free(dev); 535 537 if (!popup_and_get_string 536 538 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) { … … 545 547 log_msg(1, _("mount succeeded with %s"), dev); 546 548 } 547 paranoid_free(dev);549 mr_free(dev); 548 550 return(res); 549 551 } … … 565 567 566 568 if (g_cdrw_drive_is_here != NULL) { 567 asprintf(&cdrw_device, g_cdrw_drive_is_here);569 mr_asprintf(&cdrw_device, g_cdrw_drive_is_here); 568 570 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 569 571 return(cdrw_device); … … 577 579 tmp = find_home_of_exe("cdrecord"); 578 580 if (tmp) { 579 asprintf(&cdr_exe, "cdrecord");580 } else { 581 asprintf(&cdr_exe, "dvdrecord");582 } 583 paranoid_free(tmp);581 mr_asprintf(&cdr_exe, "cdrecord"); 582 } else { 583 mr_asprintf(&cdr_exe, "dvdrecord"); 584 } 585 mr_free(tmp); 584 586 585 587 tmp1 = find_home_of_exe(cdr_exe); 586 588 if (tmp1) { 587 asprintf(&command,589 mr_asprintf(&command, 588 590 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", 589 591 cdr_exe); 590 asprintf(&tmp, call_program_and_get_last_line_of_output(command));591 paranoid_free(command);592 } else { 593 asprintf(&tmp, " ");594 } 595 paranoid_free(tmp1);596 paranoid_free(cdr_exe);592 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 593 mr_free(command); 594 } else { 595 mr_asprintf(&tmp, " "); 596 } 597 mr_free(tmp1); 598 mr_free(cdr_exe); 597 599 598 600 if (strlen(tmp) < 2) { 599 paranoid_free(tmp);601 mr_free(tmp); 600 602 return(NULL); 601 603 } else { 602 604 cdrw_device = tmp; 603 605 604 asprintf(&comment, "Found CDRW device - %s", cdrw_device);606 mr_asprintf(&comment, "Found CDRW device - %s", cdrw_device); 605 607 log_it(comment); 606 paranoid_free(comment);607 608 paranoid_free(g_cdrw_drive_is_here);609 asprintf(&g_cdrw_drive_is_here, cdrw_device);608 mr_free(comment); 609 610 mr_free(g_cdrw_drive_is_here); 611 mr_asprintf(&g_cdrw_drive_is_here, cdrw_device); 610 612 return(cdrw_device); 611 613 } … … 649 651 650 652 if ((g_cdrom_drive_is_here != NULL) && !isdigit(g_cdrom_drive_is_here[0])) { 651 asprintf(&output, g_cdrom_drive_is_here);653 mr_asprintf(&output, g_cdrom_drive_is_here); 652 654 log_msg(3, "Been there, done that. Returning %s", output); 653 655 return(output); 654 656 } 655 657 if ((the_last_place_i_found_it != NULL) && !try_to_mount) { 656 asprintf(&output, the_last_place_i_found_it);658 mr_asprintf(&output, the_last_place_i_found_it); 657 659 log_msg(3, 658 660 "find_cdrom_device() --- returning last found location - '%s'", … … 663 665 tmp = find_home_of_exe("cdrecord"); 664 666 if (tmp) { 665 asprintf(&cdr_exe, "cdrecord");666 } else { 667 asprintf(&cdr_exe, "dvdrecord");668 } 669 paranoid_free(tmp);667 mr_asprintf(&cdr_exe, "cdrecord"); 668 } else { 669 mr_asprintf(&cdr_exe, "dvdrecord"); 670 } 671 mr_free(tmp); 670 672 671 673 tmp = find_home_of_exe(cdr_exe); 672 674 if (!tmp) { 673 asprintf(&output, "/dev/cdrom");675 mr_asprintf(&output, "/dev/cdrom"); 674 676 log_msg(4, "Can't find cdrecord; assuming %s", output); 675 677 if (!does_device_exist(output)) { 676 678 log_msg(4, "That didn't work. Sorry."); 677 paranoid_free(cdr_exe);678 paranoid_free(output);679 mr_free(cdr_exe); 680 mr_free(output); 679 681 return(NULL); 680 682 } else { 681 paranoid_free(cdr_exe);683 mr_free(cdr_exe); 682 684 return(output); 683 685 } 684 686 } 685 paranoid_free(tmp);686 687 asprintf(&command, "%s -scanbus 2> /dev/null", cdr_exe);687 mr_free(tmp); 688 689 mr_asprintf(&command, "%s -scanbus 2> /dev/null", cdr_exe); 688 690 fin = popen(command, "r"); 689 691 if (!fin) { 690 692 log_msg(4, "command=%s", command); 691 693 log_OS_error("Cannot popen command"); 692 paranoid_free(cdr_exe);693 paranoid_free(command);694 mr_free(cdr_exe); 695 mr_free(command); 694 696 return (NULL); 695 697 } 696 paranoid_free(command);697 698 for ( getline(&tmp, &n, fin); !feof(fin);699 getline(&tmp, &n, fin)) {698 mr_free(command); 699 700 for (mr_getline(&tmp, &n, fin); !feof(fin); 701 mr_getline(&tmp, &n, fin)) { 700 702 p = strchr(tmp, '\''); 701 703 if (p) { … … 713 715 *q = '\0'; 714 716 #ifndef __FreeBSD__ 715 paranoid_free(phrase_two);716 asprintf(&phrase_two, p);717 mr_free(phrase_two); 718 mr_asprintf(&phrase_two, p); 717 719 #endif 718 720 } … … 722 724 } 723 725 paranoid_pclose(fin); 724 paranoid_free(tmp);726 mr_free(tmp); 725 727 tmp = NULL; 726 728 n = 0; … … 730 732 log_msg(4, "Not running phase two. String is empty."); 731 733 } else { 732 asprintf(&command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);734 mr_asprintf(&command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 733 735 fin = popen(command, "r"); 734 736 if (!fin) { 735 737 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); 736 738 } else { 737 for ( getline(&tmp, &n, fin); !feof(fin);738 getline(&tmp, &n, fin)) {739 for (mr_getline(&tmp, &n, fin); !feof(fin); 740 mr_getline(&tmp, &n, fin)) { 739 741 log_msg(5, "--> '%s'", tmp); 740 742 if (tmp[0] != ' ' && tmp[1] != ' ') { … … 743 745 *p = '\0'; 744 746 if (strstr(tmp, "DVD")) { 745 paranoid_free(dvd_last_resort);746 asprintf(&dvd_last_resort, "/dev/%s", tmp);747 mr_free(dvd_last_resort); 748 mr_asprintf(&dvd_last_resort, "/dev/%s", tmp); 747 749 log_msg(4, 748 750 "Ignoring '%s' because it's a DVD drive", 749 751 tmp); 750 752 } else { 751 asprintf(&output, "/dev/%s", tmp);753 mr_asprintf(&output, "/dev/%s", tmp); 752 754 found_it = TRUE; 753 755 } … … 755 757 } 756 758 } 757 paranoid_free(tmp);759 mr_free(tmp); 758 760 paranoid_pclose(fin); 759 761 } 760 paranoid_free(command);761 } 762 paranoid_free(phrase_two);762 mr_free(command); 763 } 764 mr_free(phrase_two); 763 765 764 766 #endif … … 789 791 "/dev/cd1"))) 790 792 { 791 paranoid_free(cdr_exe);793 mr_free(cdr_exe); 792 794 return(NULL); 793 795 } … … 804 806 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 805 807 dvd_last_resort); 806 paranoid_free(output);807 asprintf(&output, dvd_last_resort);808 mr_free(output); 809 mr_asprintf(&output, dvd_last_resort); 808 810 found_it = TRUE; 809 811 } 810 812 } 811 paranoid_free(dvd_last_resort);813 mr_free(dvd_last_resort); 812 814 813 815 if (found_it) { 814 asprintf(&tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",816 mr_asprintf(&tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 815 817 strrchr(output, '/') + 1); 816 818 if (system(tmp) == 0) { … … 819 821 output); 820 822 found_it = FALSE; 821 paranoid_free(output);822 } 823 paranoid_free(tmp);823 mr_free(output); 824 } 825 mr_free(tmp); 824 826 } 825 827 … … 829 831 log_msg(4, "OK, I was wrong, I haven't found it... yet."); 830 832 found_it = FALSE; 831 paranoid_free(output);833 mr_free(output); 832 834 } 833 835 } … … 862 864 g_cdrw_drive_is_here))) 863 865 { 864 paranoid_free(cdr_exe);866 mr_free(cdr_exe); 865 867 return(NULL); 866 868 } … … 875 877 #endif 876 878 877 asprintf(&mountpoint, "/tmp/cd.%d", (int) (random() % 32767));879 mr_asprintf(&mountpoint, "/tmp/cd.%d", (int) (random() % 32767)); 878 880 make_hole_for_dir(mountpoint); 879 881 … … 882 884 log_msg(4, "[Cardigans] I've changed my mind"); 883 885 found_it = FALSE; 884 paranoid_free(output);886 mr_free(output); 885 887 } else { 886 asprintf(&tmp, "%s/archives", mountpoint);888 mr_asprintf(&tmp, "%s/archives", mountpoint); 887 889 if (!does_file_exist(tmp)) { 888 890 log_msg(4, "[Cardigans] I'll take it back"); 889 891 found_it = FALSE; 890 paranoid_free(output);892 mr_free(output); 891 893 } else { 892 asprintf(&command, "umount %s", output);894 mr_asprintf(&command, "umount %s", output); 893 895 paranoid_system(command); 894 paranoid_free(command);896 mr_free(command); 895 897 log_msg(4, "I'm confident the Mondo CD is in %s", output); 896 898 } 897 paranoid_free(tmp);899 mr_free(tmp); 898 900 } 899 901 } 900 902 unlink(mountpoint); 901 paranoid_free(mountpoint);903 mr_free(mountpoint); 902 904 903 905 if (found_it) { 904 906 if (!does_file_exist(output)) { 905 907 log_msg(3, "I still haven't found it."); 906 paranoid_free(output);908 mr_free(output); 907 909 return(NULL); 908 910 } 909 911 log_msg(3, "(find_cdrom_device) --> '%s'", output); 910 asprintf(&the_last_place_i_found_it, output);911 paranoid_free(g_cdrom_drive_is_here);912 asprintf(&g_cdrom_drive_is_here, output);912 mr_asprintf(&the_last_place_i_found_it, output); 913 mr_free(g_cdrom_drive_is_here); 914 mr_asprintf(&g_cdrom_drive_is_here, output); 913 915 return(output); 914 916 } 915 917 916 asprintf(&command,918 mr_asprintf(&command, 917 919 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 918 920 cdr_exe, g_cdrw_drive_is_here); 919 paranoid_free(cdr_exe);921 mr_free(cdr_exe); 920 922 921 923 log_msg(1, "command=%s", command); 922 asprintf(&tmp, call_program_and_get_last_line_of_output(command));923 paranoid_free(command);924 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 925 mr_free(command); 924 926 925 927 if (tmp[0]) { … … 927 929 log_msg(4, "Finally found it at %s", output); 928 930 } else { 929 paranoid_free(tmp);930 paranoid_free(output);931 mr_free(tmp); 932 mr_free(output); 931 933 log_msg(4, "Still couldn't find it."); 932 934 } … … 942 944 943 945 if (g_dvd_drive_is_here != NULL) { 944 asprintf(&output, g_dvd_drive_is_here);946 mr_asprintf(&output, g_dvd_drive_is_here); 945 947 log_msg(3, "Been there, done that. Returning %s", output); 946 948 return (output); 947 949 } 948 950 949 asprintf(&tmp, call_program_and_get_last_line_of_output951 mr_asprintf(&tmp, call_program_and_get_last_line_of_output 950 952 ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 951 953 ); 952 954 log_msg(5, "tmp = '%s'", tmp); 953 955 if (!tmp[0]) { 954 paranoid_free(tmp);955 asprintf(&tmp, call_program_and_get_last_line_of_output956 mr_free(tmp); 957 mr_asprintf(&tmp, call_program_and_get_last_line_of_output 956 958 ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 957 959 ); … … 960 962 devno = atoi(tmp) - 1; 961 963 } 962 paranoid_free(tmp);964 mr_free(tmp); 963 965 964 966 if (devno >= 0) { 965 967 retval = 0; 966 asprintf(&output, "/dev/scd%d", devno);967 paranoid_free(g_dvd_drive_is_here);968 asprintf(&g_dvd_drive_is_here, output);968 mr_asprintf(&output, "/dev/scd%d", devno); 969 mr_free(g_dvd_drive_is_here); 970 mr_asprintf(&g_dvd_drive_is_here, output); 969 971 log_msg(2, "I think DVD is at %s", output); 970 972 } else { … … 1092 1094 assert_string_is_neither_NULL_nor_zerolength(format); 1093 1095 1094 asprintf(&format_sz, "%s ", format);1096 mr_asprintf(&format_sz, "%s ", format); 1095 1097 1096 1098 #ifdef __FreeBSD__ 1097 asprintf(&command,1099 mr_asprintf(&command, 1098 1100 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1099 1101 #else 1100 asprintf(&command,1102 mr_asprintf(&command, 1101 1103 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1102 1104 #endif 1103 1105 1104 1106 pin = popen(command, "r"); 1105 paranoid_free(command);1107 mr_free(command); 1106 1108 1107 1109 if (!pin) { … … 1109 1111 retval = FALSE; 1110 1112 } else { 1111 getline(&good_formats, &n , pin);1113 mr_getline(&good_formats, &n , pin); 1112 1114 if (pclose(pin)) { 1113 1115 log_OS_error("Cannot pclose good formats"); … … 1115 1117 strip_spaces(good_formats); 1116 1118 // " ntfs 7 " -- um, cheating much? :) 1117 asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);1118 paranoid_free(good_formats);1119 mr_asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats); 1120 mr_free(good_formats); 1119 1121 good_formats = tmp; 1120 1122 … … 1124 1126 retval = FALSE; 1125 1127 } 1126 paranoid_free(good_formats);1127 } 1128 paranoid_free(format_sz);1128 mr_free(good_formats); 1129 } 1130 mr_free(format_sz); 1129 1131 return (retval); 1130 1132 } … … 1164 1166 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", 1165 1167 device_raw); 1166 asprintf(&tmp, "/%s", device_raw);1167 } else { 1168 asprintf(&tmp, device_raw);1168 mr_asprintf(&tmp, "/%s", device_raw); 1169 } else { 1170 mr_asprintf(&tmp, device_raw); 1169 1171 } 1170 1172 log_msg(1, "Is %s mounted?", tmp); … … 1174 1176 return (FALSE); 1175 1177 } 1176 asprintf(&device_with_tab, "%s\t", tmp);1177 asprintf(&device_with_space, "%s ", tmp);1178 paranoid_free(tmp);1178 mr_asprintf(&device_with_tab, "%s\t", tmp); 1179 mr_asprintf(&device_with_space, "%s ", tmp); 1180 mr_free(tmp); 1179 1181 1180 1182 if (!(fin = popen("mount", "r"))) { … … 1182 1184 return (FALSE); 1183 1185 } 1184 for ( getline(&incoming, &n, fin); !feof(fin);1185 getline(&incoming, &n, fin)) {1186 for (mr_getline(&incoming, &n, fin); !feof(fin); 1187 mr_getline(&incoming, &n, fin)) { 1186 1188 if (strstr(incoming, device_with_space) //> incoming 1187 1189 || strstr(incoming, device_with_tab)) // > incoming) … … 1191 1193 } 1192 1194 } 1193 paranoid_free(incoming);1194 paranoid_free(device_with_tab);1195 mr_free(incoming); 1196 mr_free(device_with_tab); 1195 1197 paranoid_pclose(fin); 1196 1198 1197 asprintf(&tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",1199 mr_asprintf(&tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null", 1198 1200 SWAPLIST_COMMAND, device_with_space); 1199 paranoid_free(device_with_space);1201 mr_free(device_with_space); 1200 1202 1201 1203 log_msg(4, "tmp (command) = '%s'", tmp); 1202 1204 if (!system(tmp)) { 1203 paranoid_free(tmp);1205 mr_free(tmp); 1204 1206 return(TRUE); 1205 1207 } 1206 paranoid_free(tmp);1208 mr_free(tmp); 1207 1209 return (FALSE); 1208 1210 } … … 1228 1230 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1229 1231 do { 1230 paranoid_free(mddevice);1231 asprintf(&mddevice, "vn%ic", vndev++);1232 1233 paranoid_free(command);1234 asprintf(&command, "vnconfig %s %s", mddevice, fname);1232 mr_free(mddevice); 1233 mr_asprintf(&mddevice, "vn%ic", vndev++); 1234 1235 mr_free(command); 1236 mr_asprintf(&command, "vnconfig %s %s", mddevice, fname); 1235 1237 1236 1238 if (vndev > 10) { 1237 paranoid_free(command);1238 paranoid_free(mddevice);1239 mr_free(command); 1240 mr_free(mddevice); 1239 1241 return NULL; 1240 1242 } 1241 1243 } 1242 1244 while (system(command)); 1243 paranoid_free(command);1244 } else { 1245 asprintf(&command, "mdconfig -a -t vnode -f %s", fname);1246 asprintf(&mddevice, call_program_and_get_last_line_of_output(command));1247 paranoid_free(command);1245 mr_free(command); 1246 } else { 1247 mr_asprintf(&command, "mdconfig -a -t vnode -f %s", fname); 1248 mr_asprintf(&mddevice, call_program_and_get_last_line_of_output(command)); 1249 mr_free(command); 1248 1250 1249 1251 if (!strstr(mddevice, "md")) { 1250 paranoid_free(mddevice);1252 mr_free(mddevice); 1251 1253 return NULL; 1252 1254 } 1253 1255 } 1254 asprintf(&device, "/dev/%s", mddevice);1255 paranoid_free(mddevice);1256 mr_asprintf(&device, "/dev/%s", mddevice); 1257 mr_free(mddevice); 1256 1258 return(device); 1257 1259 } … … 1278 1280 (call_program_and_get_last_line_of_output 1279 1281 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1280 asprintf(&command, "vnconfig -d %s", dname);1282 mr_asprintf(&command, "vnconfig -d %s", dname); 1281 1283 ret = system(command); 1282 paranoid_free(command);1284 mr_free(command); 1283 1285 return(ret); 1284 1286 } else { 1285 asprintf(&command, "mdconfig -d -u %s", dname);1287 mr_asprintf(&command, "mdconfig -d -u %s", dname); 1286 1288 ret = system(command); 1287 paranoid_free(command);1289 mr_free(command); 1288 1290 return(ret); 1289 1291 } … … 1327 1329 } 1328 1330 1329 asprintf(&tmp, "mkdir -p " MNT_CDROM);1331 mr_asprintf(&tmp, "mkdir -p " MNT_CDROM); 1330 1332 run_program_and_log_output(tmp, 5); 1331 paranoid_free(tmp);1333 mr_free(tmp); 1332 1334 1333 1335 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso … … 1341 1343 } 1342 1344 system("mkdir -p /tmp/isodir &> /dev/null"); 1343 asprintf(&tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,1345 mr_asprintf(&tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, 1344 1346 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1345 1347 cd_number_i_want); 1346 1348 if (!does_file_exist(tmp)) { 1347 paranoid_free(tmp);1348 asprintf(&tmp, "/tmp/isodir/%s/%s-%d.iso",1349 mr_free(tmp); 1350 mr_asprintf(&tmp, "/tmp/isodir/%s/%s-%d.iso", 1349 1351 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1350 1352 cd_number_i_want); … … 1353 1355 "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", 1354 1356 bkpinfo->isodir); 1355 paranoid_alloc(bkpinfo->isodir, "/tmp/isodir");1357 mr_allocstr(bkpinfo->isodir, "/tmp/isodir"); 1356 1358 } 1357 1359 } … … 1360 1362 fatal_error("Mommy!"); 1361 1363 } 1362 paranoid_free(tmp);1364 mr_free(tmp); 1363 1365 } 1364 1366 if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) { 1365 1367 log_msg(3, "Currently, we hold %d but we want %d", res, 1366 1368 cd_number_i_want); 1367 asprintf(&tmp, "Insisting on %s #%d",1369 mr_asprintf(&tmp, "Insisting on %s #%d", 1368 1370 bkpinfo->backup_media_string, 1369 1371 cd_number_i_want); 1370 asprintf(&request, "Please insert %s #%d and press Enter.",1372 mr_asprintf(&request, "Please insert %s #%d and press Enter.", 1371 1373 bkpinfo->backup_media_string, 1372 1374 cd_number_i_want); 1373 1375 log_msg(3, tmp); 1374 paranoid_free(tmp);1376 mr_free(tmp); 1375 1377 1376 1378 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) { … … 1399 1401 sync(); 1400 1402 } 1401 paranoid_free(request);1403 mr_free(request); 1402 1404 1403 1405 log_msg(1, "Thankyou. Proceeding..."); … … 1494 1496 finish(1); 1495 1497 } 1496 asprintf(&comment, _("What speed is your %s (re)writer?"),1498 mr_asprintf(&comment, _("What speed is your %s (re)writer?"), 1497 1499 bkpinfo->backup_media_string); 1498 1500 if (bkpinfo->backup_media_type == dvd) { 1499 paranoid_free(bkpinfo->media_device);1501 mr_free(bkpinfo->media_device); 1500 1502 bkpinfo->media_device = find_dvd_device(); 1501 asprintf(&tmp, "1");1502 asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB1503 mr_asprintf(&tmp, "1"); 1504 mr_asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 1503 1505 log_msg(1, "Setting to DVD defaults"); 1504 1506 } else { 1505 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_CDROM );1506 asprintf(&tmp, "4");1507 asprintf(&sz_size, "650");1507 mr_allocstr(bkpinfo->media_device,VANILLA_SCSI_CDROM ); 1508 mr_asprintf(&tmp, "4"); 1509 mr_asprintf(&sz_size, "650"); 1508 1510 log_msg(1, "Setting to CD defaults"); 1509 1511 } … … 1514 1516 } 1515 1517 } 1516 paranoid_free(comment);1518 mr_free(comment); 1517 1519 1518 1520 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1519 paranoid_free(tmp);1520 1521 asprintf(&comment,1521 mr_free(tmp); 1522 1523 mr_asprintf(&comment, 1522 1524 _("How much data (in Megabytes) will each %s store?"), 1523 1525 bkpinfo->backup_media_string); … … 1527 1529 finish(1); 1528 1530 } 1529 paranoid_free(comment);1531 mr_free(comment); 1530 1532 1531 1533 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1532 1534 bkpinfo->media_size[i] = atoi(sz_size); 1533 1535 } 1534 paranoid_free(sz_size);1536 mr_free(sz_size); 1535 1537 1536 1538 if (bkpinfo->media_size[0] <= 0) { … … 1541 1543 case cdstream: 1542 1544 if (bkpinfo->disaster_recovery) { 1543 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");1545 mr_allocstr(bkpinfo->media_device, "/dev/cdrom"); 1544 1546 log_msg(2, "CD-ROM device assumed to be at %s", 1545 1547 bkpinfo->media_device); … … 1547 1549 || bkpinfo->backup_media_type == dvd) { 1548 1550 if (bkpinfo->media_device == NULL) { 1549 asprintf(&bkpinfo->media_device, "/dev/cdrom");1551 mr_asprintf(&bkpinfo->media_device, "/dev/cdrom"); 1550 1552 } // just for the heck of it :) 1551 1553 log_msg(1, "bkpinfo->media_device = %s", … … 1554 1556 if ((bkpinfo->backup_media_type == dvd) 1555 1557 || (tmp != NULL)) { 1556 paranoid_alloc(bkpinfo->media_device, tmp);1558 mr_allocstr(bkpinfo->media_device, tmp); 1557 1559 log_msg(1, "bkpinfo->media_device = %s", 1558 1560 bkpinfo->media_device); 1559 asprintf(&comment,1561 mr_asprintf(&comment, 1560 1562 _("Please specify your %s drive's /dev entry"), 1561 1563 bkpinfo->backup_media_string); … … 1565 1567 finish(1); 1566 1568 } 1567 paranoid_free(comment);1568 } 1569 paranoid_free(tmp);1569 mr_free(comment); 1570 } 1571 mr_free(tmp); 1570 1572 1571 1573 log_msg(2, "%s device found at %s", … … 1575 1577 bkpinfo->media_device = find_cdrw_device(); 1576 1578 if (bkpinfo->media_device != NULL) { 1577 asprintf(&tmp,1579 mr_asprintf(&tmp, 1578 1580 _("I think I've found your %s burner at SCSI node %s; am I right on the money? Say no if you have an IDE burner and you are running a 2.6 kernel. Instead, specify the IDE burner's /dev address at the next screen."), 1579 1581 bkpinfo->backup_media_string, 1580 1582 bkpinfo->media_device); 1581 1583 if (!ask_me_yes_or_no(tmp)) { 1582 paranoid_free(bkpinfo->media_device);1584 mr_free(bkpinfo->media_device); 1583 1585 } 1584 paranoid_free(tmp);1586 mr_free(tmp); 1585 1587 } else { 1586 1588 if (g_kernel_version < 2.6) { … … 1613 1615 case tape: 1614 1616 1615 paranoid_free(bkpinfo->media_device);1617 mr_free(bkpinfo->media_device); 1616 1618 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) { 1617 1619 log_msg(3, _("Ok, using vanilla scsi tape.")); 1618 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" );1620 mr_allocstr(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" ); 1619 1621 if ((fin = fopen(bkpinfo->media_device, "r"))) { 1620 1622 paranoid_fclose(fin); 1621 1623 } else { 1622 paranoid_alloc(bkpinfo->media_device,"/dev/osst0");1624 mr_allocstr(bkpinfo->media_device,"/dev/osst0"); 1623 1625 } 1624 1626 } … … 1628 1630 } else { 1629 1631 if (does_file_exist("/tmp/mondo-restore.cfg")) { 1630 paranoid_free(bkpinfo->media_device);1632 mr_free(bkpinfo->media_device); 1631 1633 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 1632 1634 bkpinfo->media_device); 1633 1635 } 1634 1636 } 1635 asprintf(&tmp,1637 mr_asprintf(&tmp, 1636 1638 _("I think I've found your tape streamer at %s; am I right on the money?"), 1637 1639 bkpinfo->media_device); 1638 1640 if (!ask_me_yes_or_no(tmp)) { 1639 paranoid_free(bkpinfo->media_device);1640 } 1641 paranoid_free(tmp);1641 mr_free(bkpinfo->media_device); 1642 } 1643 mr_free(tmp); 1642 1644 } else { 1643 1645 if (!popup_and_get_string … … 1649 1651 } 1650 1652 } 1651 asprintf(&tmp, "ls -l %s", bkpinfo->media_device);1653 mr_asprintf(&tmp, "ls -l %s", bkpinfo->media_device); 1652 1654 if (run_program_and_log_output(tmp, FALSE)) { 1653 1655 log_to_screen(_("User has not specified a valid /dev entry")); 1654 1656 finish(1); 1655 1657 } 1656 paranoid_free(tmp);1658 mr_free(tmp); 1657 1659 log_msg(4, "sz_size = %s", sz_size); 1658 paranoid_free(sz_size);1660 mr_free(sz_size); 1659 1661 bkpinfo->media_size[0] = 0; 1660 1662 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); … … 1708 1710 if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/') 1709 1711 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0'; 1710 asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3",1712 mr_asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3", 1711 1713 bkpinfo->nfs_mount); 1712 paranoid_free(bkpinfo->isodir);1714 mr_free(bkpinfo->isodir); 1713 1715 bkpinfo->isodir = call_program_and_get_last_line_of_output(command); 1714 paranoid_free(command);1715 1716 asprintf(&comment,1716 mr_free(command); 1717 1718 mr_asprintf(&comment, 1717 1719 _("How much data (in Megabytes) will each media store?")); 1718 1720 if (!popup_and_get_string(_("Size"), comment, sz_size)) { … … 1727 1729 finish(1); 1728 1730 } 1729 paranoid_free(comment);1731 mr_free(comment); 1730 1732 } 1731 1733 if (bkpinfo->disaster_recovery) { … … 1739 1741 } 1740 1742 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { 1741 paranoid_free(bkpinfo->isodir);1742 asprintf(&bkpinfo->isodir, "/tmp/isodir.mondo.%d",1743 mr_free(bkpinfo->isodir); 1744 mr_asprintf(&bkpinfo->isodir, "/tmp/isodir.mondo.%d", 1743 1745 (int) (random() % 32768)); 1744 asprintf(&command, "mkdir -p %s", bkpinfo->isodir);1746 mr_asprintf(&command, "mkdir -p %s", bkpinfo->isodir); 1745 1747 run_program_and_log_output(command, 5); 1746 paranoid_free(command);1747 1748 asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount,1748 mr_free(command); 1749 1750 mr_asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount, 1749 1751 bkpinfo->isodir); 1750 1752 run_program_and_log_output(tmp, 5); 1751 paranoid_free(tmp);1752 asprintf(&g_selfmounted_isodir, bkpinfo->isodir);1753 mr_free(tmp); 1754 mr_asprintf(&g_selfmounted_isodir, bkpinfo->isodir); 1753 1755 } 1754 1756 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { … … 1763 1765 } 1764 1766 1765 asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir,1767 mr_asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir, 1766 1768 bkpinfo->nfs_remote_dir); 1767 1769 while (run_program_and_log_output(command, FALSE)) { 1768 asprintf(&prompt,1770 mr_asprintf(&prompt, 1769 1771 _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."), 1770 1772 bkpinfo->nfs_remote_dir, bkpinfo->isodir); … … 1774 1776 finish(1); 1775 1777 } 1776 paranoid_free(prompt);1777 1778 paranoid_free(command);1779 asprintf(&command, "echo hi > %s/%s/.dummy.txt",1778 mr_free(prompt); 1779 1780 mr_free(command); 1781 mr_asprintf(&command, "echo hi > %s/%s/.dummy.txt", 1780 1782 bkpinfo->isodir, bkpinfo->nfs_remote_dir); 1781 1783 } 1782 paranoid_free(command);1784 mr_free(command); 1783 1785 1784 1786 if (!popup_and_get_string … … 1845 1847 1846 1848 if (bkpinfo->boot_device) { 1847 paranoid_free(bkpinfo->boot_device);1849 mr_free(bkpinfo->boot_device); 1848 1850 } 1849 1851 #ifdef __FreeBSD__ … … 1903 1905 } 1904 1906 bkpinfo->boot_loader = i; 1905 asprintf(&bkpinfo->include_paths, "/");1907 mr_asprintf(&bkpinfo->include_paths, "/"); 1906 1908 if (!popup_and_get_string 1907 1909 (_("Backup paths"), … … 1916 1918 if (bkpinfo->exclude_paths != NULL) { 1917 1919 tmp1 = bkpinfo->exclude_paths; 1918 asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp);1919 paranoid_free(tmp1);1920 mr_asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp); 1921 mr_free(tmp1); 1920 1922 } else { 1921 1923 bkpinfo->exclude_paths = tmp; 1922 1924 } 1923 1925 } 1924 paranoid_free(tmp);1926 mr_free(tmp); 1925 1927 // NTFS 1926 1928 tmp = call_program_and_get_last_line_of_output … … 1936 1938 if (bkpinfo->image_devs != NULL) { 1937 1939 tmp2 = bkpinfo->image_devs; 1938 asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1);1939 paranoid_free(tmp2);1940 mr_asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1); 1941 mr_free(tmp2); 1940 1942 } else { 1941 1943 bkpinfo->image_devs = tmp1; 1942 1944 } 1943 paranoid_free(tmp1);1944 } 1945 paranoid_free(tmp);1945 mr_free(tmp1); 1946 } 1947 mr_free(tmp); 1946 1948 1947 1949 if (!popup_and_get_string … … 1961 1963 if (!ask_me_yes_or_no 1962 1964 (_("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."))){ 1963 paranoid_alloc(bkpinfo->kernel_path, "FAILSAFE");1965 mr_allocstr(bkpinfo->kernel_path, "FAILSAFE"); 1964 1966 } 1965 1967 #endif … … 1992 1994 log_it("media size = %ld", bkpinfo->media_size[1]); 1993 1995 log_it("media type = %s", bkpinfo->backup_media_string); 1994 paranoid_free(tmp);1996 mr_free(tmp); 1995 1997 log_it("prefix = %s", bkpinfo->prefix); 1996 1998 log_it("compression = %ld", bkpinfo->compression_level); … … 2024 2026 ("mount -t coda,ncpfs,nfs,smbfs,cifs,afs,mvfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2025 2027 /* BERLIOS : Useless 2026 asprintf(&exclude_these_devices,2028 mr_asprintf(&exclude_these_devices, 2027 2029 call_program_and_get_last_line_of_output 2028 2030 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs|mvfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); … … 2057 2059 2058 2060 if (tmp[0] != '/') { 2059 asprintf(&sz, "/%s", tmp);2060 paranoid_free(tmp);2061 mr_asprintf(&sz, "/%s", tmp); 2062 mr_free(tmp); 2061 2063 tmp = sz; 2062 2064 } … … 2065 2067 } 2066 2068 i = (int) (random() % 32768); 2067 paranoid_free(bkpinfo->tmpdir);2068 asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i);2069 mr_free(bkpinfo->tmpdir); 2070 mr_asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i); 2069 2071 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2070 2072 2071 paranoid_free(bkpinfo->scratchdir);2072 asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);2073 mr_free(bkpinfo->scratchdir); 2074 mr_asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i); 2073 2075 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2074 2076 2075 asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,2077 mr_asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 2076 2078 bkpinfo->scratchdir); 2077 2079 2078 asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp);2079 paranoid_free(tmp);2080 mr_asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp); 2081 mr_free(tmp); 2080 2082 2081 2083 paranoid_system(command); 2082 paranoid_free(command);2084 mr_free(command); 2083 2085 } 2084 2086 … … 2099 2101 char *command; 2100 2102 2101 paranoid_free(output);2103 mr_free(output); 2102 2104 if (!dev || dev[0] == '\0') { 2103 2105 return (FALSE); … … 2109 2111 return (FALSE); 2110 2112 } 2111 asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",2113 mr_asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 2112 2114 512L, dev); 2113 2115 if (!run_program_and_log_output(command, FALSE) 2114 2116 && !run_program_and_log_output(command, FALSE)) { 2115 asprintf(&output, dev);2117 mr_asprintf(&output, dev); 2116 2118 log_msg(4, "Found it - %s", dev); 2117 paranoid_free(command);2119 mr_free(command); 2118 2120 return (TRUE); 2119 2121 } else { 2120 2122 log_msg(4, "It's not %s", dev); 2121 paranoid_free(command);2123 mr_free(command); 2122 2124 return (FALSE); 2123 2125 } … … 2141 2143 assert(bkpinfo != NULL); 2142 2144 if (g_ISO_restore_mode) { 2143 asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");2145 mr_asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2144 2146 2145 2147 tmp1 = call_program_and_get_last_line_of_output(tmp); 2146 paranoid_free(tmp);2147 2148 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1);2149 paranoid_free(tmp1);2148 mr_free(tmp); 2149 2150 mr_asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1); 2151 mr_free(tmp1); 2150 2152 2151 2153 tmp = last_line_of_file(mountdev); 2152 2154 cd_number = atoi(tmp); 2153 paranoid_free(mountdev);2154 paranoid_free(tmp);2155 mr_free(mountdev); 2156 mr_free(tmp); 2155 2157 2156 2158 return (cd_number); … … 2167 2169 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"); 2168 2170 cd_number = atoi(tmp); 2169 paranoid_free(tmp);2171 mr_free(tmp); 2170 2172 return (cd_number); 2171 2173 } … … 2190 2192 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"); 2191 2193 if (strstr(tmp, "/dev/cciss/")) { 2192 paranoid_free(tmp);2194 mr_free(tmp); 2193 2195 tmp = call_program_and_get_last_line_of_output 2194 2196 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"); 2195 2197 } 2196 2198 if (strstr(tmp, "/dev/md")) { 2197 paranoid_free(tmp);2199 mr_free(tmp); 2198 2200 tmp = call_program_and_get_last_line_of_output 2199 2201 ("mount | grep \" on / \" | cut -d' ' -f1"); … … 2278 2280 #endif 2279 2281 assert(which_device != NULL); 2280 asprintf(&list_drives_cmd,2282 mr_asprintf(&list_drives_cmd, 2281 2283 "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", 2282 2284 where_is_root_mounted()); … … 2285 2287 if (!(pdrives = popen(list_drives_cmd, "r"))) { 2286 2288 log_OS_error("Unable to open list of drives"); 2287 paranoid_free(list_drives_cmd);2289 mr_free(list_drives_cmd); 2288 2290 return ('\0'); 2289 2291 } 2290 paranoid_free(list_drives_cmd);2291 2292 for ( getline(¤t_drive, &n, pdrives); !feof(pdrives);2293 getline(¤t_drive, &n, pdrives)) {2292 mr_free(list_drives_cmd); 2293 2294 for (mr_getline(¤t_drive, &n, pdrives); !feof(pdrives); 2295 mr_getline(¤t_drive, &n, pdrives)) { 2294 2296 strip_spaces(current_drive); 2295 2297 log_it("looking at drive %s's MBR", current_drive); 2296 2298 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2297 2299 count_grubs++; 2298 paranoid_alloc(which_device,current_drive);2300 mr_allocstr(which_device,current_drive); 2299 2301 break; 2300 2302 } 2301 2303 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2302 2304 count_lilos++; 2303 paranoid_alloc(which_device,current_drive);2305 mr_allocstr(which_device,current_drive); 2304 2306 break; 2305 2307 } … … 2371 2373 log_it 2372 2374 ("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2373 asprintf(&output, incoming);2374 } else { 2375 asprintf(&curr_fname, incoming);2375 mr_asprintf(&output, incoming); 2376 } else { 2377 mr_asprintf(&curr_fname, incoming); 2376 2378 lstat(curr_fname, &statbuf); 2377 2379 while (S_ISLNK(statbuf.st_mode)) { 2378 2380 log_msg(1, "curr_fname = %s", curr_fname); 2379 asprintf(&command, "file %s", curr_fname);2381 mr_asprintf(&command, "file %s", curr_fname); 2380 2382 tmp = call_program_and_get_last_line_of_output(command); 2381 paranoid_free(command);2383 mr_free(command); 2382 2384 2383 2385 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2384 2386 p--); 2385 2387 p++; 2386 asprintf(&scratch, p);2388 mr_asprintf(&scratch, p); 2387 2389 for (p = scratch; *p != '\0' && *p != '\''; p++); 2388 2390 *p = '\0'; 2389 2391 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 2390 paranoid_free(tmp);2392 mr_free(tmp); 2391 2393 2392 2394 if (scratch[0] == '/') { 2393 paranoid_free(curr_fname);2394 asprintf(&curr_fname, scratch); // copy whole thing because it's an absolute softlink2395 mr_free(curr_fname); 2396 mr_asprintf(&curr_fname, scratch); // copy whole thing because it's an absolute softlink 2395 2397 } else { // copy over the basename cos it's a relative softlink 2396 2398 p = curr_fname + strlen(curr_fname); … … 2402 2404 } 2403 2405 *p = '\0'; 2404 asprintf(&tmp, "%s%s", curr_fname, scratch);2405 paranoid_free(curr_fname);2406 mr_asprintf(&tmp, "%s%s", curr_fname, scratch); 2407 mr_free(curr_fname); 2406 2408 curr_fname = tmp; 2407 2409 } 2408 paranoid_free(scratch);2410 mr_free(scratch); 2409 2411 lstat(curr_fname, &statbuf); 2410 2412 } 2411 asprintf(&output, curr_fname);2413 mr_asprintf(&output, curr_fname); 2412 2414 log_it("resolved %s to %s", incoming, output); 2413 paranoid_free(curr_fname);2415 mr_free(curr_fname); 2414 2416 } 2415 2417 return (output); … … 2431 2433 2432 2434 log_msg(0, "Looking for partition table format type"); 2433 asprintf(&fdisk, "/sbin/parted2fdisk");2435 mr_asprintf(&fdisk, "/sbin/parted2fdisk"); 2434 2436 log_msg(1, "Using %s", fdisk); 2435 asprintf(&command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);2436 paranoid_free(fdisk);2437 mr_asprintf(&command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2438 mr_free(fdisk); 2437 2439 2438 2440 tmp = call_program_and_get_last_line_of_output(command); 2439 paranoid_free(command);2441 mr_free(command); 2440 2442 2441 2443 if (strstr(tmp, "GPT") == NULL) { 2442 asprintf(&output, "MBR");2443 } else { 2444 asprintf(&output, "GPT");2445 } 2446 paranoid_free(tmp);2444 mr_asprintf(&output, "MBR"); 2445 } else { 2446 mr_asprintf(&output, "GPT"); 2447 } 2448 mr_free(tmp); 2447 2449 log_msg(0, "Found %s partition table format type", output); 2448 2450 return (output);
Note:
See TracChangeset
for help on using the changeset viewer.