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