Changeset 3191 in MondoRescue for branches/3.2/mondo/src/common/libmondo-devices.c
- Timestamp:
- Sep 25, 2013, 8:55:45 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-devices.c
r3185 r3191 21 21 #include "libmondo-stream-EXT.h" 22 22 23 extern void mr_strip_spaces(char *); 24 23 25 #include <sys/types.h> 24 26 #ifdef __FreeBSD__ … … 127 129 { 128 130 char *tmp = NULL; 129 char *comment;130 131 bool is_this_a_ramdisk = FALSE; 131 132 132 malloc_string(comment);133 133 mr_asprintf(tmp, "%s", where_is_root_mounted()); 134 sprintf(comment, "root is mounted at %s\n", tmp); 135 log_msg(0, comment); 136 log_msg(0, 137 "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", 138 tmp); 134 log_msg(0, "root is mounted at %s\n", tmp); 135 log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp); 139 136 140 137 #ifdef __FreeBSD__ … … 156 153 if (is_this_a_ramdisk) { 157 154 if (!does_file_exist("/THIS-IS-A-RAMDISK")) { 158 log_to_screen 159 ("Using /dev/root is stupid of you but I'll forgive you."); 155 log_to_screen("Using /dev/root is stupid of you but I'll forgive you."); 160 156 is_this_a_ramdisk = FALSE; 161 157 } … … 164 160 is_this_a_ramdisk = TRUE; 165 161 } 166 paranoid_free(comment); 167 log_msg(1, "Is this a ramdisk? result = % d", is_this_a_ramdisk);162 163 log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE"); 168 164 return (is_this_a_ramdisk); 169 165 } … … 229 225 int eject_device(char *dev) 230 226 { 231 char *command ;227 char *command = NULL; 232 228 int res1 = 0, res2 = 0; 233 229 234 malloc_string(command); 230 if (dev == NULL) { 231 return (1); 232 } 235 233 236 234 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 237 235 && g_backup_media_type != udev) { 238 sprintf(command, "mt -f %s offline", dev);236 mr_asprintf(command, "mt -f %s offline", dev); 239 237 res1 = run_program_and_log_output(command, 1); 238 mr_free(command); 240 239 } else { 241 240 res1 = 0; … … 244 243 #ifdef __FreeBSD__ 245 244 if (strstr(dev, "acd")) { 246 sprintf(command, "cdcontrol -f %s eject", dev);245 mr_asprintf(command, "cdcontrol -f %s eject", dev); 247 246 } else { 248 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 249 dev); 247 mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev); 250 248 } 251 249 #else 252 sprintf(command, "eject %s", dev);250 mr_asprintf(command, "eject %s", dev); 253 251 #endif 254 252 255 253 log_msg(3, "Ejecting %s", dev); 256 254 res2 = run_program_and_log_output(command, 1); 257 paranoid_free(command);255 mr_free(command); 258 256 if (res1 && res2) { 259 257 return (1); … … 270 268 int inject_device(char *dev) 271 269 { 272 char *command ;270 char *command = NULL; 273 271 int i; 274 272 275 malloc_string(command); 276 273 if (dev == NULL) { 274 return (1); 275 } 277 276 278 277 #ifdef __FreeBSD__ 279 278 if (strstr(dev, "acd")) { 280 sprintf(command, "cdcontrol -f %s close", dev);279 mr_asprintf(command, "cdcontrol -f %s close", dev); 281 280 } else { 282 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", 283 dev); 281 mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev); 284 282 } 285 283 #else 286 sprintf(command, "eject -t %s", dev);284 mr_asprintf(command, "eject -t %s", dev); 287 285 #endif 288 286 i = run_program_and_log_output(command, FALSE); 289 paranoid_free(command);287 mr_free(command); 290 288 return (i); 291 289 } … … 301 299 302 300 /*@ buffers *********************************************************** */ 303 char *tmp ;301 char *tmp = NULL; 304 302 bool ret; 305 303 306 malloc_string(tmp);307 304 assert_string_is_neither_NULL_nor_zerolength(device); 308 305 309 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);306 mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device); 310 307 311 308 if (system(tmp)) { … … 314 311 ret = TRUE; 315 312 } 316 paranoid_free(tmp);313 mr_free(tmp); 317 314 return (ret); 318 315 } … … 345 342 { 346 343 /*@ buffers **************************************************** */ 347 char *program ;348 char *incoming ;344 char *program = NULL; 345 char *incoming = NULL; 349 346 char *searchstr = NULL; 350 char *tmp;351 char *p;352 347 353 348 /*@ ints ******************************************************* */ … … 356 351 /*@ pointers *************************************************** */ 357 352 FILE *fin; 358 359 353 360 354 /*@ end vars *************************************************** */ … … 362 356 assert(partno >= 0 && partno < 999); 363 357 364 malloc_string(program);365 malloc_string(incoming);366 358 malloc_string(searchstr); 367 malloc_string(tmp);368 359 369 360 #ifdef __FreeBSD__ 370 361 // We assume here that this is running from mondorestore. (It is.) 371 sprintf(program, "ls %s %s >/dev/null 2>&1", drive, 372 build_partition_name(tmp, drive, partno)); 373 return system(program); 374 #else 375 tmp[0] = '\0'; 376 #endif 377 378 sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 362 mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno)); 363 res = system(program); 364 mr_free(program); 365 return(res); 366 #endif 367 368 mr_asprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 379 369 fin = popen(program, "r"); 380 370 if (!fin) { 381 371 log_it("program=%s", program); 382 372 log_OS_error("Cannot popen-in program"); 373 mr_free(program); 383 374 return (0); 384 375 } 376 mr_free(program); 377 385 378 (void) build_partition_name(searchstr, drive, partno); 386 379 strcat(searchstr, " "); 387 for (res = 0 ; !res && (p = fgets(incoming, MAX_STR_LEN - 1, fin));) {380 for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) { 388 381 if (strstr(incoming, searchstr)) { 389 382 res = 1; 390 383 } 391 } 384 mr_free(incoming); 385 } 386 mr_free(incoming); 387 392 388 if (pclose(fin)) { 393 389 log_OS_error("Cannot pclose fin"); 394 390 } 395 paranoid_free(program);396 paranoid_free(incoming);397 391 paranoid_free(searchstr); 398 paranoid_free(tmp);399 392 return (res); 400 393 } … … 413 406 { 414 407 /*@ buffers **************************************************** */ 415 char *command ;408 char *command = NULL; 416 409 417 410 /*@ end vars *************************************************** */ … … 421 414 assert_string_is_neither_NULL_nor_zerolength(str); 422 415 423 malloc_string(command); 424 sprintf(command, 425 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 426 dev, str); 416 /* For UEFI detection, this should be extended to count=2 */ 417 mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str); 427 418 i = system(command); 428 paranoid_free(command);419 mr_free(command); 429 420 if (i) { 430 421 return (FALSE); … … 444 435 { 445 436 /*@ buffers **************************************************** */ 446 char *command ;437 char *command = NULL; 447 438 /*@ end vars *************************************************** */ 448 439 int i; 449 440 450 malloc_string(command); 451 sprintf(command, 452 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 453 dev, n, str); 441 mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str); 454 442 i = system(command); 455 paranoid_free(command);443 mr_free(command); 456 444 if (i) { 457 445 return (FALSE); … … 466 454 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has 467 455 * not been specified, call find_cdrom_device() to find it. 468 * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.469 456 * @param mountpoint Where to mount the CD-ROM. 470 457 * @return 0 for success, nonzero for failure. 471 458 * @see mount_CDROM_here 472 459 */ 473 int find_and_mount_actual_cd(char *mountpoint) 474 { 460 int find_and_mount_actual_cd(char *mountpoint) { 461 475 462 /*@ buffers ***************************************************** */ 476 463 477 464 /*@ int's ****************************************************** */ 478 465 int res; 479 char *dev ;466 char *dev = NULL; 480 467 481 468 /*@ end vars **************************************************** */ … … 532 519 { 533 520 /*@ buffers ************************ */ 534 char *comment;535 521 char *tmp = NULL; 536 522 char *cdr_exe = NULL; 537 char *command; 538 539 malloc_string(comment); 540 malloc_string(command); 523 char *command = NULL; 524 541 525 if (g_cdrw_drive_is_here[0]) { 542 526 strcpy(cdrw_device, g_cdrw_drive_is_here); 543 527 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 544 paranoid_free(comment);545 paranoid_free(command);546 528 return (0); 547 529 } 548 530 if (g_backup_media_type == dvd) { 549 log_msg(1, 550 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 551 paranoid_free(comment); 552 paranoid_free(command); 531 log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 553 532 return (1); 554 533 } … … 560 539 } 561 540 if (find_home_of_exe(cdr_exe)) { 562 sprintf(command, 563 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", 564 cdr_exe); 541 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe); 565 542 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 543 mr_free(command); 566 544 } 567 545 if ((tmp == NULL) || (strlen(tmp) < 2)) { 568 paranoid_free(comment);569 546 mr_free(tmp); 570 547 mr_free(cdr_exe); 571 paranoid_free(command);572 548 return 1; 573 549 } else { 574 550 strcpy(cdrw_device, tmp); 575 sprintf(comment, "Found CDRW device - %s", cdrw_device); 576 log_it(comment); 551 log_it("Found CDRW device - %s", cdrw_device); 577 552 strcpy(g_cdrw_drive_is_here, cdrw_device); 578 paranoid_free(comment);579 553 mr_free(tmp); 580 554 mr_free(cdr_exe); 581 paranoid_free(command);582 555 return (0); 583 556 } 584 557 } 585 586 587 558 588 559 … … 609 580 610 581 /*@ buffers ***************************************************** */ 611 char *tmp ;582 char *tmp = NULL; 612 583 char *tmp1 = NULL; 613 584 char *cdr_exe = NULL; 614 585 char *phrase_one; 615 char *phrase_two; 616 char *command; 617 char *dvd_last_resort; 618 char *mountpoint; 586 char *phrase_two = NULL; 587 char *command = NULL; 588 #ifndef __FreeBSD__ 589 char *dvd_last_resort = NULL; 590 #endif 591 char *mountpoint = NULL; 619 592 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 620 593 … … 622 595 malloc_string(tmp); 623 596 malloc_string(phrase_one); 624 malloc_string(phrase_two);625 malloc_string(command);626 malloc_string(dvd_last_resort);627 597 malloc_string(mountpoint); 628 598 629 599 output[0] = '\0'; 630 600 phrase_one[0] = '\0'; 631 phrase_two[0] = '\0';632 dvd_last_resort[0] = '\0';633 601 634 602 /*@ end vars **************************************************** */ … … 642 610 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 643 611 strcpy(output, the_last_place_i_found_it); 644 log_msg(3, 645 "find_cdrom_device() --- returning last found location - '%s'", 646 output); 612 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output); 647 613 retval = 0; 648 614 goto end_of_find_cdrom_device; … … 671 637 } 672 638 673 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);639 mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 674 640 fin = popen(command, "r"); 675 641 if (!fin) { … … 677 643 log_OS_error("Cannot popen command"); 678 644 mr_free(cdr_exe); 645 mr_free(command); 679 646 return (1); 680 647 } 648 mr_free(command); 649 681 650 for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL); 682 651 tmp1 = fgets(tmp, MAX_STR_LEN, fin)) { … … 696 665 } 697 666 *q = '\0'; 698 strcpy(phrase_two, p);667 mr_asprintf(phrase_two, "%s", p); 699 668 } 700 669 } … … 705 674 706 675 #ifndef __FreeBSD__ 707 if ( strlen(phrase_two) == 0) {676 if (!phrase_two || strlen(phrase_two) == 0) { 708 677 log_msg(4, "Not running phase two. String is empty."); 709 678 } else { 710 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);679 mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 711 680 fin = popen(command, "r"); 681 mr_free(command); 682 712 683 if (!fin) { 713 684 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); … … 721 692 *p = '\0'; 722 693 if (strstr(tmp, "DVD")) { 723 sprintf(dvd_last_resort, "/dev/%s", tmp); 724 log_msg(4, 725 "Ignoring '%s' because it's a DVD drive", 726 tmp); 694 mr_free(dvd_last_resort); 695 mr_asprintf(dvd_last_resort, "/dev/%s", tmp); 696 log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp); 727 697 } else { 728 698 sprintf(output, "/dev/%s", tmp); … … 775 745 #else 776 746 if (!found_it && strlen(dvd_last_resort) > 0) { 777 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 778 dvd_last_resort); 747 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 779 748 strcpy(output, dvd_last_resort); 780 749 found_it = TRUE; 781 750 } 782 751 if (found_it) { 783 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 784 strrchr(output, '/') + 1); 752 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1); 785 753 if (system(tmp) == 0) { 786 log_msg(4, 787 "%s is not right. It's being SCSI-emulated. Continuing.", 788 output); 754 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); 789 755 found_it = FALSE; 790 756 output[0] = '\0'; … … 852 818 found_it = FALSE; 853 819 } else { 854 sprintf(command, "umount %s", output);820 mr_asprintf(command, "umount %s", output); 855 821 paranoid_system(command); 822 mr_free(command); 823 856 824 log_msg(4, "I'm confident the Mondo CD is in %s", output); 857 825 } … … 872 840 } 873 841 874 sprintf(command, 875 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 876 cdr_exe, g_cdrw_drive_is_here); 842 mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here); 843 877 844 log_msg(1, "command=%s", command); 878 845 mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command)); 846 mr_free(command); 847 879 848 if (strlen(tmp1) > 0) { 880 849 strcpy(output, tmp1); … … 888 857 889 858 end_of_find_cdrom_device: 859 mr_free(cdr_exe); 860 mr_free(phrase_two); 861 mr_free(dvd_last_resort); 862 890 863 paranoid_free(tmp); 891 mr_free(cdr_exe);892 864 paranoid_free(phrase_one); 893 paranoid_free(phrase_two);894 paranoid_free(command);895 paranoid_free(dvd_last_resort);896 865 paranoid_free(mountpoint); 897 866 return (retval); … … 899 868 900 869 901 902 903 904 870 int find_dvd_device(char *output, bool try_to_mount) 905 871 { 906 char *command;907 872 char *tmp; 908 873 int retval = 0, devno = -1; 909 910 malloc_string(command);911 malloc_string(tmp);912 874 913 875 if (g_dvd_drive_is_here[0]) { … … 917 879 } 918 880 919 sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 881 malloc_string(tmp); 882 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 920 883 log_msg(5, "tmp = '%s'", tmp); 921 if (!tmp[0]) 922 sprintf(tmp, "%s", call_program_and_get_last_line_of_output923 ("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")924 );884 if (!tmp[0]) { 885 mr_free(tmp); 886 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")); 887 } 925 888 if (tmp[0]) { 926 889 devno = atoi(tmp) - 1; 927 890 } 891 mr_free(tmp); 892 928 893 if (devno >= 0) { 929 894 retval = 0; … … 936 901 } 937 902 938 if (try_to_mount) {939 log_msg(1, "Ignoring the fact that try_to_mount==TRUE");940 }941 903 return (retval); 942 904 } … … 1053 1015 { 1054 1016 char *good_formats = NULL; 1055 char *command ;1056 char *format_sz ;1017 char *command = NULL; 1018 char *format_sz = NULL; 1057 1019 char *p; 1058 1020 … … 1060 1022 int retval; 1061 1023 malloc_string(good_formats); 1062 malloc_string(command);1063 malloc_string(format_sz);1064 1024 1065 1025 assert_string_is_neither_NULL_nor_zerolength(format); 1066 1026 1067 sprintf(format_sz, "%s ", format);1027 mr_asprintf(format_sz, "%s ", format); 1068 1028 1069 1029 #ifdef __FreeBSD__ 1070 sprintf(command, 1071 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1030 mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1072 1031 #else 1073 sprintf(command, 1074 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1032 mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1075 1033 #endif 1076 1034 1077 1035 pin = popen(command, "r"); 1036 mr_free(command); 1037 1078 1038 if (!pin) { 1079 1039 log_OS_error("Unable to read good formats"); … … 1094 1054 } 1095 1055 paranoid_free(good_formats); 1096 paranoid_free(command);1097 paranoid_free(format_sz); 1056 mr_free(format_sz); 1057 1098 1058 return (retval); 1099 1059 } … … 1114 1074 1115 1075 /*@ buffers ***************************************************** */ 1116 char *incoming ;1076 char *incoming = NULL; 1117 1077 char *device_with_tab = NULL; 1118 1078 char *device_with_space = NULL; … … 1128 1088 /*@ end vars **************************************************** */ 1129 1089 1130 malloc_string(incoming); 1131 assert(device_raw != NULL); 1132 // assert_string_is_neither_NULL_nor_zerolength(device_raw); 1090 if (device_raw == NULL) { 1091 return(FALSE); 1092 } 1093 1133 1094 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) { 1134 1095 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", … … 1153 1114 return(FALSE); 1154 1115 } 1155 for (tmp = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (tmp != NULL); 1156 tmp = fgets(incoming, MAX_STR_LEN - 1, fin)) { 1157 if (strstr(incoming, device_with_space) //> incoming 1158 || strstr(incoming, device_with_tab)) // > incoming) 1159 { 1116 1117 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 1118 if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) { 1160 1119 paranoid_pclose(fin); 1161 paranoid_free(incoming);1120 mr_free(incoming); 1162 1121 return(TRUE); 1163 1122 } 1164 } 1123 mr_free(incoming); 1124 } 1125 mr_free(incoming); 1165 1126 mr_free(device_with_tab); 1166 1127 paranoid_pclose(fin); … … 1172 1133 } 1173 1134 mr_free(tmp); 1174 paranoid_free(incoming);1175 1135 return(retval); 1176 1136 } … … 1189 1149 char command[MAX_STR_LEN]; 1190 1150 int vndev = 2; 1191 if (atoi 1192 (call_program_and_get_last_line_of_output 1193 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1151 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) { 1194 1152 do { 1195 1153 sprintf(mddevice, "vn%ic", vndev++); … … 1223 1181 int kick_vn(char *dname) 1224 1182 { 1225 char command[MAX_STR_LEN]; 1183 char *command = NULL; 1184 int res = 0; 1226 1185 1227 1186 if (strncmp(dname, "/dev/", 5) == 0) { … … 1229 1188 } 1230 1189 1231 if (atoi 1232 (call_program_and_get_last_line_of_output 1233 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1234 sprintf(command, "vnconfig -d %s", dname); 1235 return system(command); 1190 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) { 1191 mr_asprintf(command, "vnconfig -d %s", dname); 1236 1192 } else { 1237 sprintf(command, "mdconfig -d -u %s", dname); 1238 return system(command); 1239 } 1240 /*NOTREACHED*/ return 255; 1193 mr_asprintf(command, "mdconfig -d -u %s", dname); 1194 } 1195 res = system(command); 1196 mr_free(command); 1197 return(res); 1241 1198 } 1242 1199 #endif … … 1252 1209 { 1253 1210 /*@ buffer ****************************************************** */ 1254 char *command ;1211 char *command = NULL; 1255 1212 int retval; 1256 1213 1257 malloc_string(command);1258 1214 assert_string_is_neither_NULL_nor_zerolength(device); 1259 1215 assert_string_is_neither_NULL_nor_zerolength(mountpoint); … … 1263 1219 return(1); 1264 1220 } 1265 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, 1266 mountpoint); 1221 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint); 1267 1222 1268 1223 #ifdef __FreeBSD__ 1269 sprintf(command, "mount_vfat %s %s 2>> %s", 1270 device, mountpoint, MONDO_LOGFILE); 1224 mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1271 1225 1272 1226 #else 1273 sprintf(command, "mount %s -t vfat %s 2>> %s", 1274 device, mountpoint, MONDO_LOGFILE); 1227 mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE); 1275 1228 #endif 1276 1229 … … 1278 1231 retval = system(command); 1279 1232 log_msg(1, "system(%s) returned %d", command, retval); 1280 1281 paranoid_free(command); 1233 mr_free(command); 1234 1282 1235 return (retval); 1283 1236 } … … 1289 1242 * @return 0 for success, nonzero for failure. 1290 1243 */ 1291 int mount_CDROM_here(char *device, c har *mountpoint)1244 int mount_CDROM_here(char *device, const char *mountpoint) 1292 1245 { 1293 1246 /*@ buffer ****************************************************** */ … … 1327 1280 1328 1281 } 1329 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 1330 mountpoint); 1282 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint); 1331 1283 /*@ end vars *************************************************** */ 1332 1284 … … 1345 1297 retval = system(command); 1346 1298 log_msg(1, "system(%s) returned %d", command, retval); 1347 paranoid_free(command);1299 mr_free(command); 1348 1300 1349 1301 return (retval); … … 1362 1314 int mount_media() 1363 1315 { 1364 char *mount_cmd ;1316 char *mount_cmd = NULL; 1365 1317 char *mountdir = NULL; 1366 1318 int i, res; 1367 1319 #ifdef __FreeBSD__ 1368 char mdd[32]; 1369 char *mddev = mdd; 1370 #endif 1371 1372 malloc_string(mount_cmd); 1373 assert(bkpinfo != NULL); 1374 1375 if (bkpinfo->backup_media_type == tape 1376 || bkpinfo->backup_media_type == udev) { 1320 char mdd[32]; 1321 char *mddev = mdd; 1322 #endif 1323 1324 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 1377 1325 log_msg(8, "Tape/udev. Therefore, no need to mount a media."); 1378 paranoid_free(mount_cmd);1379 1326 return 0; 1380 1327 } … … 1382 1329 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 1383 1330 log_msg(2, "mount_media() - media already mounted. Fair enough."); 1384 paranoid_free(mount_cmd);1385 1331 return (0); 1386 1332 } … … 1389 1335 log_msg(2, "Mounting for Network thingy"); 1390 1336 log_msg(2, "isodir = %s", bkpinfo->isodir); 1391 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 1392 && am_I_in_disaster_recovery_mode()) { 1337 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) { 1393 1338 strcpy(bkpinfo->isodir, "/tmp/isodir"); 1394 1339 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 1395 1340 } 1396 1341 #ifdef __FreeBSD__ 1397 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,1342 mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 1398 1343 bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number); 1399 1344 mddev = make_vn(mount_cmd); 1400 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1345 mr_free(mount_cmd); 1346 1347 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 1401 1348 #else 1402 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 1403 bkpinfo->isodir, bkpinfo->netfs_remote_dir, 1404 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1349 mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1405 1350 #endif 1406 1351 … … 1412 1357 } 1413 1358 #ifdef __FreeBSD__ 1414 sprintf(mount_cmd, "%s/%s-%d.iso", mountdir, 1415 bkpinfo->prefix, g_current_media_number); 1359 mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number); 1416 1360 mddev = make_vn(mount_cmd); 1417 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1361 mr_free(mount_cmd); 1362 1363 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 1418 1364 #else 1419 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 1420 mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1365 mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 1421 1366 #endif 1422 1367 mr_free(mountdir); 1423 1368 } else if (bkpinfo->backup_media_type == usb) { 1424 sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);1369 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM); 1425 1370 } else if (strstr(bkpinfo->media_device, "/dev/")) { 1426 1371 #ifdef __FreeBSD__ 1427 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1428 MNT_CDROM); 1372 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1429 1373 #else 1430 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1431 bkpinfo->media_device, MNT_CDROM); 1374 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1432 1375 #endif 1433 1376 } else { … … 1441 1384 1442 1385 #ifdef __FreeBSD__ 1443 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 1444 MNT_CDROM); 1386 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 1445 1387 #else 1446 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 1447 bkpinfo->media_device, MNT_CDROM); 1388 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 1448 1389 #endif 1449 1390 } … … 1457 1398 log_msg(2, "Failed to mount device."); 1458 1399 sleep(5); 1459 run_program_and_log_output("sync", FALSE); 1460 } 1461 } 1400 sync(); 1401 } 1402 } 1403 mr_free(mount_cmd); 1462 1404 1463 1405 if (res) { … … 1466 1408 log_msg(2, "Mounted media drive OK"); 1467 1409 } 1468 paranoid_free(mount_cmd);1469 1410 return (res); 1470 1411 } … … 1496 1437 1497 1438 /*@ buffers ********************************************************* */ 1498 char *tmp ;1439 char *tmp = NULL; 1499 1440 char *mds = NULL; 1500 char *request ;1441 char *request = NULL; 1501 1442 1502 1443 assert(bkpinfo != NULL); … … 1510 1451 return; 1511 1452 } 1512 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1513 || bkpinfo->backup_media_type == netfs) { 1453 mr_asprintf(tmp, "mkdir -p " MNT_CDROM); 1454 run_program_and_log_output(tmp, 5); 1455 mr_free(tmp); 1456 1457 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) { 1514 1458 g_ISO_restore_mode = TRUE; 1515 1459 } 1516 malloc_string(tmp);1517 malloc_string(request);1518 sprintf(tmp, "mkdir -p " MNT_CDROM);1519 run_program_and_log_output(tmp, 5);1520 1460 if ((res = what_number_cd_is_this()) != cd_number_i_want) { 1521 log_msg(3, "Currently, we hold %d but we want %d", res, 1522 cd_number_i_want); 1461 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want); 1523 1462 1524 1463 /* Now we need to umount the current media to have the next mounted after */ … … 1529 1468 1530 1469 mds = media_descriptor_string(bkpinfo->backup_media_type); 1531 sprintf(tmp, "Insisting on %s #%d", mds, cd_number_i_want);1532 sprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);1470 log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want); 1471 mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want); 1533 1472 mr_free(mds); 1534 log_msg(3, tmp); 1473 1535 1474 while (what_number_cd_is_this() != cd_number_i_want) { 1536 paranoid_system("sync");1475 sync(); 1537 1476 if (is_this_device_mounted(MNT_CDROM)) { 1538 1477 res = … … 1556 1495 inject_device(bkpinfo->media_device); 1557 1496 } 1558 paranoid_system("sync"); 1559 } 1497 sync(); 1498 } 1499 mr_free(request); 1500 1560 1501 log_msg(1, "Thankyou. Proceeding..."); 1561 1502 g_current_media_number = cd_number_i_want; 1562 1503 } 1563 paranoid_free(tmp);1564 paranoid_free(request);1565 1504 } 1566 1505 … … 1676 1615 log_msg(5, "Running: %s", command); 1677 1616 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1678 paranoid_free(command);1617 mr_free(command); 1679 1618 1680 1619 mount_cnt = atoi(mounted_file_system); 1681 1620 log_msg (5, "mount_cnt: %d", mount_cnt); 1682 paranoid_free(mounted_file_system);1621 mr_free(mounted_file_system); 1683 1622 1684 1623 for (i=mount_cnt; i > 0; i--) { … … 1686 1625 log_msg(5, "Running: %s", command); 1687 1626 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 1688 paranoid_free(command);1627 mr_free(command); 1689 1628 1690 1629 log_msg (5, "mounted_file_system: %s", mounted_file_system); 1691 1630 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) { 1692 1631 log_msg (4, "Could not get the list of mounted file systems"); 1693 paranoid_free(mounted_file_system);1632 mr_free(mounted_file_system); 1694 1633 mr_free(token); 1695 1634 return (1); … … 1719 1658 mr_free(mounted_file_system); 1720 1659 } 1721 /********1722 * DSFptr = DSF_Head;1723 * while (DSFptr != NULL) {1724 * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);1725 * DSFptr = DSFptr->next;1726 * }1727 ********/1728 1660 return (0); 1729 1661 } … … 1773 1705 log_msg(5, " Executing: %s", command); 1774 1706 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1775 paranoid_free(command);1707 mr_free(command); 1776 1708 1777 1709 log_msg(5, " Return value: %s", tmp); 1778 1710 c = atoi(tmp); 1779 paranoid_free(tmp);1711 mr_free(tmp); 1780 1712 1781 1713 if (!c) { … … 1799 1731 log_msg(5, "Executing: %s", command); 1800 1732 mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command)); 1801 paranoid_free(command);1733 mr_free(command); 1802 1734 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 1803 1735 if (!strlen(partition_list)) { … … 1862 1794 log_msg(4, "Processing partition: %s", partitions[i]); 1863 1795 /* See if it's swap. If it is, ignore it. */ 1864 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", 1865 ndsf, partitions[i]); 1796 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]); 1866 1797 log_msg(5, " Running: %s", command); 1867 1798 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1868 paranoid_free(command); 1799 mr_free(command); 1800 1869 1801 log_msg(5, " Return value: %s", tmp); 1870 1802 c = strlen(tmp); 1871 paranoid_free(tmp); 1803 mr_free(tmp); 1804 1872 1805 if (c) { 1873 1806 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); 1874 1807 continue; 1875 1808 } 1809 1876 1810 /* It's not swap. See if we can find the mount point from the mount command. */ 1877 1811 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 1878 1812 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1879 paranoid_free(command); 1813 mr_free(command); 1814 1880 1815 if (strlen(tmp)) { 1881 1816 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 1882 1817 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 1883 1818 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 1884 paranoid_free(tmp);1819 mr_free(tmp); 1885 1820 return (1); 1886 1821 } 1887 1822 DSFptr->check = 1; 1888 paranoid_free(tmp);1823 mr_free(tmp); 1889 1824 continue; 1890 1825 } 1891 paranoid_free(tmp); 1826 mr_free(tmp); 1827 1892 1828 /* It's not swap and it's not mounted. See if it's LVM */ 1893 1829 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); 1830 1894 1831 /* Check for LVM */ 1895 1832 mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]); 1896 1833 log_msg(5, " Running: %s", command); 1897 1834 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1898 paranoid_free(command); 1835 mr_free(command); 1836 1899 1837 if (strlen(tmp)) { 1900 1838 log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]); … … 1903 1841 log_msg(5, " Running: %s", command); 1904 1842 strcpy(VG, call_program_and_get_last_line_of_output(command)); 1905 paranoid_free(command); 1843 mr_free(command); 1844 1906 1845 log_msg(4, " Volume Group: %s", VG); 1907 1846 if (strlen(VG)) { … … 1911 1850 log_msg(5, " Running: %s", command); 1912 1851 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1913 paranoid_free(command); 1852 mr_free(command); 1853 1914 1854 log_msg(4, " VG %s mount_list: %s", VG, mount_list); 1915 1855 lastpos = 0; … … 1918 1858 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 1919 1859 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 1920 paranoid_free(tmp);1860 mr_free(tmp); 1921 1861 mr_free(token); 1922 1862 return (1); … … 1929 1869 * any of the Logical Volumes on the Volume Group. 1930 1870 *******/ 1931 paranoid_free(mount_list);1871 mr_free(mount_list); 1932 1872 1933 1873 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1934 1874 log_msg (5, "Running: %s", command); 1935 1875 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1936 paranoid_free(command);1876 mr_free(command); 1937 1877 log_msg(4, " Software raid device list: %s", mount_list); 1938 1878 lastpos = 0; … … 1940 1880 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 1941 1881 log_msg (5, "Running: %s", command); 1942 paranoid_free(tmp);1882 mr_free(tmp); 1943 1883 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1944 paranoid_free(command);1884 mr_free(command); 1945 1885 log_msg(4, "Number of Software raid device: %s", tmp); 1946 1886 if (atoi(tmp)) { … … 1948 1888 if ((DSFptr = find_device_in_list(token)) == NULL) { 1949 1889 log_msg (4, "Can't find device %s in mounted file systems list", token); 1950 paranoid_free(tmp);1890 mr_free(tmp); 1951 1891 mr_free(token); 1952 1892 return (1); … … 1959 1899 } else { 1960 1900 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 1961 paranoid_free(tmp);1901 mr_free(tmp); 1962 1902 return (1); 1963 1903 } 1964 paranoid_free(tmp);1904 mr_free(tmp); 1965 1905 continue; 1966 1906 } else { 1967 1907 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 1968 1908 } 1969 paranoid_free(tmp); 1909 mr_free(tmp); 1910 1970 1911 /******** 1971 1912 * It's not swap, mounted, or LVM. See if it's used in a software raid device. … … 1975 1916 log_msg(4, " Running: %s", command); 1976 1917 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1977 paranoid_free(command); 1918 mr_free(command); 1919 1978 1920 if (!strlen(tmp)) { 1979 1921 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 1980 paranoid_free(tmp);1922 mr_free(tmp); 1981 1923 continue; 1982 1924 } 1983 1925 log_msg (5, " UUID: %s", tmp); 1926 1984 1927 /* Get the Software raid device list */ 1985 1928 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1986 1929 log_msg (5, " Running: %s", command); 1987 1930 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command)); 1988 paranoid_free(command); 1931 mr_free(command); 1932 1989 1933 log_msg(4, " Software raid device list: %s", mount_list); 1990 1934 /* Loop through the software raid device list to see if we can find the partition */ … … 1993 1937 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 1994 1938 log_msg(4, " Running: %s", command); 1995 paranoid_free(tmp);1939 mr_free(tmp); 1996 1940 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1997 paranoid_free(command); 1941 mr_free(command); 1942 1998 1943 if (!atoi(tmp)) { 1999 1944 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); … … 2001 1946 if ((DSFptr = find_device_in_list(token)) == NULL) { 2002 1947 log_msg (4, "Can't find device %s in mounted file systems list", token); 2003 paranoid_free(tmp);1948 mr_free(tmp); 2004 1949 mr_free(token); 2005 1950 return (1); … … 2010 1955 mr_free(token); 2011 1956 } 2012 paranoid_free(tmp);2013 paranoid_free(mount_list);1957 mr_free(tmp); 1958 mr_free(mount_list); 2014 1959 } 2015 1960 … … 2047 1992 return (0); 2048 1993 } 2049 2050 2051 2052 1994 2053 1995 … … 2099 2041 log_to_screen("Archiving only the following file systems on %s:", token); 2100 2042 log_to_screen("==> %s", mounted_on_dsf); 2101 strcpy(bkpinfo->include_paths, "/"); 2043 mr_free(bkpinfo->include_paths); 2044 mr_asprintf(bkpinfo->include_paths, "%s", "/"); 2102 2045 if (strlen(not_mounted_on_dsf)) { 2103 2046 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf); … … 2136 2079 mr_asprintf(tmp,"|%s|",bkpinfo->include_paths); 2137 2080 if (strstr(tmp,tmp2) == NULL) { 2138 strcat(bkpinfo->include_paths,tmp1);2081 mr_strcat(bkpinfo->include_paths, "%s", tmp1); 2139 2082 } 2140 2083 mr_free(tmp1); … … 2181 2124 char *q = NULL; 2182 2125 char p[16*MAX_STR_LEN]; 2183 char *sz_size ;2184 char *command ;2126 char *sz_size = NULL; 2127 char *command = NULL; 2185 2128 char *compression_type = NULL; 2186 char *comment; 2187 char *prompt; 2129 char *comment = NULL; 2188 2130 int i; 2189 2131 FILE *fin; 2190 2132 2191 malloc_string(sz_size);2192 malloc_string(command);2193 malloc_string(comment);2194 malloc_string(prompt);2195 2133 malloc_string(tmp1); 2196 2134 assert(bkpinfo != NULL); 2197 sz_size[0] = '\0';2198 2135 bkpinfo->nonbootable_backup = FALSE; 2199 2136 … … 2232 2169 setup_scratchdir(tmp); 2233 2170 } 2234 log_msg(3, "media type = %s", 2235 bkptype_to_string(bkpinfo->backup_media_type)); 2171 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2236 2172 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 2237 bkpinfo->compression_level = 2238 (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2239 bkpinfo->use_lzo = 2240 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2173 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 2174 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 2241 2175 mvaddstr_and_log_it(2, 0, " "); 2242 2176 … … 2253 2187 if (archiving_to_media) { 2254 2188 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) { 2255 if (ask_me_yes_or_no 2256 ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) 2257 { 2189 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) { 2258 2190 bkpinfo->manual_cd_tray = TRUE; 2259 2191 } … … 2263 2195 finish(1); 2264 2196 } 2265 if ((bkpinfo->compression_level = 2266 2197 2198 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2267 2199 log_to_screen("User has chosen not to backup the PC"); 2268 2200 finish(1); 2269 2201 } 2270 2202 mds = media_descriptor_string(bkpinfo->backup_media_type); 2271 sprintf(comment, "What speed is your %s (re)writer?", mds);2203 mr_asprintf(comment, "What speed is your %s (re)writer?", mds); 2272 2204 if (bkpinfo->backup_media_type == dvd) { 2273 2205 find_dvd_device(bkpinfo->media_device, FALSE); 2274 2206 strcpy(tmp1, "1"); 2275 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2207 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2276 2208 log_msg(1, "Setting to DVD defaults"); 2277 2209 } else { 2278 2210 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 2279 2211 strcpy(tmp1, "4"); 2280 strcpy(sz_size, "650");2212 mr_asprintf(sz_size, "%d", 650); 2281 2213 log_msg(1, "Setting to CD defaults"); 2282 2214 } … … 2284 2216 if (!popup_and_get_string("Speed", comment, tmp1, 4)) { 2285 2217 log_to_screen("User has chosen not to backup the PC"); 2218 mr_free(comment); 2286 2219 finish(1); 2287 2220 } 2288 2221 } 2222 mr_free(comment); 2289 2223 bkpinfo->cdrw_speed = atoi(tmp1); // if DVD then this shouldn't ever be used anyway :) 2290 2224 2291 s printf(comment,2292 2225 strcpy(tmp1, sz_size); 2226 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds); 2293 2227 mr_free(mds); 2294 if (!popup_and_get_string("Size", comment, sz_size, 5)) {2228 if (!popup_and_get_string("Size", comment, tmp1, 5)) { 2295 2229 log_to_screen("User has chosen not to backup the PC"); 2296 2230 finish(1); 2297 2231 } 2232 mr_asprintf(sz_size, "%s", tmp1); 2298 2233 bkpinfo->media_size = atoi(sz_size); 2234 2299 2235 if (bkpinfo->media_size <= 0) { 2300 2236 log_to_screen("User has chosen not to backup the PC"); … … 2308 2244 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) { 2309 2245 strcpy(bkpinfo->media_device, "/dev/cdrom"); 2310 log_msg(2, "CD-ROM device assumed to be at %s", 2311 bkpinfo->media_device); 2312 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) 2313 || bkpinfo->backup_media_type == dvd) { 2246 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device); 2247 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) { 2314 2248 if (!bkpinfo->media_device[0]) { 2315 2249 strcpy(bkpinfo->media_device, "/dev/cdrom"); 2316 2250 } // just for the heck of it :) 2317 log_msg(1, "bkpinfo->media_device = %s", 2318 bkpinfo->media_device); 2319 if (bkpinfo->backup_media_type == dvd 2320 || find_cdrom_device(bkpinfo->media_device, FALSE)) { 2321 log_msg(1, "bkpinfo->media_device = %s", 2322 bkpinfo->media_device); 2323 sprintf(comment, 2324 "Please specify your %s drive's /dev entry", mds); 2325 if (!popup_and_get_string 2326 ("Device?", comment, bkpinfo->media_device, 2327 MAX_STR_LEN / 4)) { 2251 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2252 if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) { 2253 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 2254 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds); 2255 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) { 2328 2256 log_to_screen("User has chosen not to backup the PC"); 2329 2257 finish(1); … … 2399 2327 } else { 2400 2328 if (does_file_exist("/tmp/mondo-restore.cfg")) { 2401 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 2402 bkpinfo->media_device); 2329 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device); 2403 2330 } 2404 2331 } … … 2455 2382 finish(1); 2456 2383 } 2457 if ((bkpinfo->compression_level = 2458 which_compression_level()) == -1) { 2384 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2459 2385 log_to_screen("User has chosen not to backup the PC"); 2460 2386 finish(1); … … 2468 2394 /* Never try to eject a NETFS device */ 2469 2395 bkpinfo->please_dont_eject = TRUE; 2396 /* Force NFS to be the protocol by default */ 2397 if (bkpinfo->netfs_proto == NULL) { 2398 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 2399 } 2470 2400 2471 2401 /* Initiate bkpinfo netfs_mount path from running environment if not already done */ 2472 if (!bkpinfo->netfs_mount[0]) { 2473 strcpy(bkpinfo->netfs_mount, 2474 call_program_and_get_last_line_of_output 2475 ("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 2402 if (!bkpinfo->netfs_mount == NULL) { 2403 mr_asprintf(bkpinfo->netfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 2476 2404 } 2477 2405 #ifdef __FreeBSD__ … … 2484 2412 ("Network shared dir.", 2485 2413 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", 2486 bkpinfo->netfs_mount, MAX_STR_LEN / 4)) {2414 p, MAX_STR_LEN / 4)) { 2487 2415 log_to_screen("User has chosen not to backup the PC"); 2488 2416 finish(1); 2489 2417 } 2418 mr_free(bkpinfo->netfs_mount); 2419 mr_asprintf(bkpinfo->netfs_mount, "%s", p; 2490 2420 if (!bkpinfo->restore_data) { 2491 2421 if ((compression_type = which_compression_type()) == NULL) { … … 2493 2423 finish(1); 2494 2424 } 2495 if ((bkpinfo->compression_level = 2496 2425 2426 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2497 2427 log_to_screen("User has chosen not to backup the PC"); 2498 2428 finish(1); … … 2501 2431 // check whether already mounted - we better remove 2502 2432 // surrounding spaces and trailing '/' for this 2503 strip_spaces(bkpinfo->netfs_mount);2433 mr_strip_spaces(bkpinfo->netfs_mount); 2504 2434 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/') 2505 2435 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0'; … … 2513 2443 strcpy(tmp1,bkpinfo->netfs_mount); 2514 2444 } 2515 sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);2445 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1); 2516 2446 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command)); 2447 mr_free(command); 2517 2448 2518 2449 if (!bkpinfo->restore_data) { 2519 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2520 sprintf(comment, 2521 "How much data (in Megabytes) will each media store?"); 2522 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 2450 mr_sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2451 mr_asprintf(comment, "How much data (in Megabytes) will each media store?"); 2452 strcpy(tmp1, sz_size); 2453 mr_free(sz_size); 2454 if (!popup_and_get_string("Size", comment, tmp1, 5)) { 2523 2455 log_to_screen("User has chosen not to backup the PC"); 2524 2456 finish(1); 2525 2457 } 2458 mr_free(comment); 2459 mr_asprintf(sz_size, "%s", tmp1); 2526 2460 } else { 2527 strcpy(sz_size, "0");2461 mr_asprintf(sz_size, "0"); 2528 2462 } 2529 2463 bkpinfo->media_size = atoi(sz_size); 2464 mr_free(sz_size); 2465 2530 2466 if (bkpinfo->media_size < 0) { 2531 2467 log_to_screen("User has chosen not to backup the PC"); … … 2533 2469 } 2534 2470 } 2535 /* Force NFS to be the protocol by default */2536 if (bkpinfo->netfs_proto == NULL) {2537 mr_asprintf(bkpinfo->netfs_proto, "nfs");2538 }2539 2471 if (bkpinfo->disaster_recovery) { 2540 sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);2472 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir); 2541 2473 paranoid_system(command); 2474 mr_free(command); 2475 2542 2476 } 2543 2477 strcpy(tmp1, bkpinfo->netfs_proto); 2544 if (!popup_and_get_string 2545 ("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?", 2546 tmp1, MAX_STR_LEN)) { 2478 if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) { 2547 2479 log_to_screen("User has chosen not to backup the PC"); 2548 2480 finish(1); … … 2550 2482 mr_free(bkpinfo->netfs_proto); 2551 2483 mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1); 2552 if (!popup_and_get_string 2553 ("Network share", "Which remote share should I mount?",2554 bkpinfo->netfs_mount, MAX_STR_LEN)) {2484 2485 strcpy(tmp1, bkpinfo->netfs_mount); 2486 if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) { 2555 2487 log_to_screen("User has chosen not to backup the PC"); 2556 2488 finish(1); 2557 2489 } 2490 mr_free(bkpinfo->netfs_mount); 2491 mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1); 2558 2492 2559 2493 if (bkpinfo->netfs_user) { … … 2562 2496 strcpy(tmp1, ""); 2563 2497 } 2564 if (!popup_and_get_string 2565 ("Network user", "Which user should I use if any ?", 2566 tmp1, MAX_STR_LEN)) { 2498 if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1)) { 2567 2499 log_to_screen("User has chosen not to backup the PC"); 2568 2500 finish(1); … … 2575 2507 /* Initiate bkpinfo isodir path from running environment if mount already done */ 2576 2508 if (is_this_device_mounted(bkpinfo->netfs_mount)) { 2577 strcpy(bkpinfo->isodir, 2578 call_program_and_get_last_line_of_output 2579 ("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2509 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1")); 2580 2510 } else { 2581 2511 sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir); 2582 sprintf(command, "mkdir -p %s", bkpinfo->isodir);2512 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir); 2583 2513 run_program_and_log_output(command, 5); 2514 mr_free(command); 2584 2515 2585 2516 if (bkpinfo->restore_data) { … … 2615 2546 } 2616 2547 if (!is_this_device_mounted(bkpinfo->netfs_mount)) { 2617 popup_and_OK 2618 ("Please mount that partition before you try to backup to or restore from it."); 2548 popup_and_OK("Please mount that partition before you try to backup to or restore from it."); 2619 2549 finish(1); 2620 2550 } … … 2640 2570 log_msg(3, "prefix set to %s", bkpinfo->prefix); 2641 2571 2642 log_msg(3, "Just set netfs_remote_dir to %s", 2643 bkpinfo->netfs_remote_dir); 2572 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir); 2644 2573 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2645 2574 break; … … 2659 2588 finish(1); 2660 2589 } 2661 if ((bkpinfo->compression_level = 2662 which_compression_level()) == -1) { 2590 if ((bkpinfo->compression_level = which_compression_level()) == -1) { 2663 2591 log_to_screen("User has chosen not to backup the PC"); 2664 2592 finish(1); 2665 2593 } 2666 sprintf( sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB2594 sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 2667 2595 if (!popup_and_get_string 2668 2596 ("ISO size.", 2669 2597 "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.", 2670 sz_size, 16)) {2598 tmp1, 16)) { 2671 2599 log_to_screen("User has chosen not to backup the PC"); 2672 2600 finish(1); 2673 2601 } 2674 bkpinfo->media_size = atoi( sz_size);2602 bkpinfo->media_size = atoi(tmp1); 2675 2603 } else { 2676 2604 bkpinfo->media_size = 650; … … 2723 2651 finish(1); 2724 2652 } 2725 if (does_string_exist_in_boot_block 2726 (bkpinfo->boot_device, "LILO")) { 2653 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { 2727 2654 i = 'L'; 2728 2655 } else 2729 if (does_string_exist_in_boot_block 2730 (bkpinfo->boot_device, "ELILO")) { 2656 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { 2731 2657 i = 'E'; 2732 2658 } else 2733 if (does_string_exist_in_boot_block 2734 (bkpinfo->boot_device, "GRUB")) { 2659 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { 2735 2660 i = 'G'; 2736 2661 } else { … … 2739 2664 #endif 2740 2665 if (i == 'U') { 2741 if (ask_me_yes_or_no 2742 ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) 2743 { 2666 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) { 2744 2667 i = 'R'; // raw 2745 2668 } else { 2746 log_to_screen 2747 ("I cannot find your boot loader. Please run mondoarchive with parameters."); 2669 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); 2748 2670 finish(1); 2749 2671 } … … 2751 2673 } 2752 2674 bkpinfo->boot_loader = i; 2753 strcpy(bkpinfo->include_paths, "/"); 2675 2676 mr_free(bkpinfo->include_paths); 2677 strcpy(tmp1, "/"); 2754 2678 if (!popup_and_get_string 2755 2679 ("Backup paths", 2756 2680 "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).", 2757 bkpinfo->include_paths, MAX_STR_LEN)) {2681 tmp1, MAX_STR_LEN)) { 2758 2682 log_to_screen("User has chosen not to backup the PC"); 2759 2683 finish(1); 2760 2684 } 2685 mr_asprintf(bkpinfo->include_paths, "%s", tmp1); 2686 2761 2687 tmp = list_of_NETFS_mounts_only(); 2762 2688 if (strlen(tmp) > 2) { … … 2815 2741 if (ask_me_yes_or_no("Do you want to backup extended attributes?")) { 2816 2742 if (find_home_of_exe("getfattr")) { 2743 mr_free(g_getfattr); 2817 2744 mr_asprintf(g_getfattr,"getfattr"); 2818 2745 } 2819 2746 if (find_home_of_exe("getfacl")) { 2747 mr_free(g_getfacl); 2820 2748 mr_asprintf(g_getfacl,"getfacl"); 2821 2749 } … … 2835 2763 strcpy(bkpinfo->zip_exe, "gzip"); 2836 2764 strcpy(bkpinfo->zip_suffix, "gz"); 2837 //} else if (strcmp(compression_type,"lzma") == 0) {2765 } else if (strcmp(compression_type,"lzma") == 0) { 2838 2766 //strcpy(bkpinfo->zip_exe, "xy"); 2839 2767 //strcpy(bkpinfo->zip_suffix, "xy"); … … 2849 2777 ("Will you want to verify your backups after Mondo has created them?"); 2850 2778 2851 #ifndef __FreeBSD__2852 if (!ask_me_yes_or_no2853 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))2854 #endif2855 {2856 strcpy(bkpinfo->kernel_path, "FAILSAFE");2857 }2858 2859 2779 if (!ask_me_yes_or_no 2860 2780 ("Are you sure you want to proceed? Hit 'no' to abort.")) { … … 2875 2795 #else 2876 2796 if (bkpinfo->backup_media_type == netfs) { 2877 log_msg(3, "I think the Remote mount is mounted at %s", 2878 bkpinfo->isodir); 2797 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir); 2879 2798 } 2880 2799 log_it("isodir = %s", bkpinfo->isodir); 2881 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2800 if (bkpinfo->netfs_mount) { 2801 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount); 2802 } 2803 if (bkpinfo->netfs_user) { 2804 log_it("netfs_user = '%s'", bkpinfo->netfs_user); 2805 } 2882 2806 if (bkpinfo->netfs_proto) { 2883 2807 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto); 2884 }2885 if (bkpinfo->netfs_user) {2886 log_it("netfs_user = '%s'", bkpinfo->netfs_user);2887 2808 } 2888 2809 #endif … … 2891 2812 log_it("media size = %ld", bkpinfo->media_size); 2892 2813 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2893 log_it("prefix = %s", bkpinfo->prefix); 2814 if (bkpinfo->prefix) { 2815 log_it("prefix = %s", bkpinfo->prefix); 2816 } 2894 2817 log_it("compression = %ld", bkpinfo->compression_level); 2895 2818 log_it("exclude_path = %s", bkpinfo->exclude_paths); … … 2897 2820 2898 2821 /* Handle devices passed in bkpinfo and print result */ 2899 /* the mr_make_devlist_from_pathlist function appends 2900 2822 /* the mr_make_devlist_from_pathlist function appends 2823 /* to the *_paths variables so copy before */ 2901 2824 mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E'); 2902 2825 mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I'); … … 2904 2827 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 2905 2828 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 2906 log_it("image_devs = '%s'", bkpinfo->image_devs); 2907 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, 2908 bkpinfo->boot_loader); 2829 if (bkpinfo->image_devs) { 2830 log_it("image_devs = '%s'", bkpinfo->image_devs); 2831 } 2832 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader); 2909 2833 if (bkpinfo->media_size < 0) { 2910 2834 if (archiving_to_media) { … … 2917 2841 paranoid_free(sz_size); 2918 2842 paranoid_free(tmp1); 2919 paranoid_free(command);2920 paranoid_free(comment);2921 paranoid_free(prompt);2922 2843 return (0); 2923 2844 } … … 3170 3091 3171 3092 malloc_string(current_drive); 3093 3094 /* UEFI is not supported here - but should be managed as a BIOS/UEFI option not a Boot Loader one per se */ 3172 3095 3173 3096 #ifdef __IA64__
Note:
See TracChangeset
for help on using the changeset viewer.