Changeset 688 in MondoRescue
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-archive.c
r687 r688 27 27 #include <sys/ipc.h> 28 28 #include <stdarg.h> 29 #include <unistd.h> 29 30 #define DVDRWFORMAT 1 30 31 … … 230 231 log_msg(5, "command='%s'", command); 231 232 res = system(command); 232 asprintf(&tmp, "%s",last_line_of_file(MONDO_LOGFILE));233 tmp = last_line_of_file(MONDO_LOGFILE)); 233 234 log_msg(1, "res=%d; tmp='%s'", res, tmp); 234 235 if (bkpinfo->use_star && (res == 254 || res == 65024) … … 296 297 297 298 /*@ buffers ******************************************************** */ 298 char *command ;299 char *command = NULL; 299 300 char *zipparams = NULL; 300 char *tmp, *tmp1; 301 char *tmp = NULL; 302 char *tmp1 = NULL; 301 303 302 304 assert(bkpinfo != NULL); … … 389 391 390 392 if (g_tmpfs_mountpt[0] != '\0') { 391 i = atoi(call_program_and_get_last_line_of_output 392 ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4")); 393 tmp = call_program_and_get_last_line_of_output 394 ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"); 395 i = atoi(tmp); 396 paranoid_free(tmp); 397 393 398 if (i > 0) { 394 399 if (free_ramdisk_space > i) { … … 466 471 copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo); // payload, too, if it exists 467 472 #if __FreeBSD__ == 5 468 strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");473 paranoid_alloc(bkpinfo->kernel_path, "/boot/kernel/kernel"); 469 474 #elif __FreeBSD__ == 4 470 strcpy(bkpinfo->kernel_path, "/kernel");475 paranoid_alloc(bkpinfo->kernel_path, "/kernel"); 471 476 #elif linux 472 477 if (figure_out_kernel_path_interactively_if_necessary … … 523 528 { 524 529 /*@ buffer ************************************************************ */ 525 char *tmp ;526 char *command ;527 char *use_lzo_sz ;528 char *use_comp_sz ;529 char *use_star_sz ;530 char *bootldr_str ;531 char *tape_device ;532 char *last_filelist_number ;533 char *broken_bios_sz ;534 char *cd_recovery_sz ;535 char *tape_size_sz ;536 char *devs_to_exclude ;537 char *use_lilo_sz ;538 char *value ;539 char *bootdev ;530 char *tmp = NULL; 531 char *command = NULL; 532 char *use_lzo_sz = NULL; 533 char *use_comp_sz = NULL; 534 char *use_star_sz = NULL; 535 char *bootldr_str = NULL; 536 char *tape_device = NULL; 537 char *last_filelist_number = NULL; 538 char *broken_bios_sz = NULL; 539 char *cd_recovery_sz = NULL; 540 char *tape_size_sz = NULL; 541 char *devs_to_exclude = NULL; 542 char *use_lilo_sz = NULL; 543 char *value = NULL; 544 char *bootdev = NULL; 540 545 541 546 … … 556 561 "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'", 557 562 bkpinfo->exclude_paths); 558 asprintf(&devs_to_exclude, 559 call_program_and_get_last_line_of_output(tmp)); 563 devs_to_exclude = call_program_and_get_last_line_of_output(tmp); 560 564 paranoid_free(tmp); 561 565 asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude); … … 576 580 paranoid_free(tmp); 577 581 asprintf(&tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir); 578 asprintf(&last_filelist_number, last_line_of_file(tmp));582 last_filelist_number = last_line_of_file(tmp); 579 583 paranoid_free(tmp); 580 584 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { … … 617 621 if (!bkpinfo->nonbootable_backup 618 622 && (bkpinfo->boot_loader == '\0' 619 || bkpinfo->boot_device [0] == '\0')) {623 || bkpinfo->boot_device == NULL)) { 620 624 621 625 #ifdef __FreeBSD__ 622 asprintf(&bootdev, call_program_and_get_last_line_of_output 623 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 624 if (!bootdev[0]) { 626 bootdev = call_program_and_get_last_line_of_output 627 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"); 628 if (!bootdev) { 629 bootdev = call_program_and_get_last_line_of_output 630 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"); 631 } 632 #else 633 bootdev = call_program_and_get_last_line_of_output 634 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"); 635 if (!bootdev) { 636 bootdev = call_program_and_get_last_line_of_output 637 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"); 638 } 639 if ((bootdev) && (strstr(bootdev, "/dev/cciss/"))) { 625 640 paranoid_free(bootdev); 626 asprintf(&bootdev, call_program_and_get_last_line_of_output 627 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 628 } 629 #else 630 asprintf(&bootdev, call_program_and_get_last_line_of_output 631 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 632 if (strstr(bootdev, "/dev/cciss/")) { 633 paranoid_free(bootdev); 634 asprintf(&bootdev, call_program_and_get_last_line_of_output 635 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1")); 636 } 637 if (!bootdev[0]) { 638 paranoid_free(bootdev); 639 asprintf(&bootdev, call_program_and_get_last_line_of_output 640 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 641 if (strstr(bootdev, "/dev/cciss/")) { 642 paranoid_free(bootdev); 643 asprintf(&bootdev, call_program_and_get_last_line_of_output 644 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1")); 645 } 641 bootdev = call_program_and_get_last_line_of_output 642 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"); 646 643 } 647 644 #endif 648 if (bootdev [0])645 if (bootdev) 649 646 ch = which_boot_loader(bootdev); 650 647 else … … 658 655 bkpinfo->boot_loader = ch; 659 656 } 660 if (bkpinfo->boot_device [0] != '\0') {657 if (bkpinfo->boot_device != NULL) { 661 658 asprintf(&tmp, "User specified boot device. It is '%s'.", 662 659 bkpinfo->boot_device); 663 660 log_msg(2, tmp); 664 661 paranoid_free(tmp); 662 paranoid_free(bootdev); 665 663 } else { 666 strcpy(bkpinfo->boot_device, bootdev); 667 } 668 } 669 paranoid_free(bootdev); 664 bkpinfo->boot_device = bootdev; 665 } 666 } 670 667 671 668 if ( … … 797 794 estimated_total_noof_slices = 798 795 size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1; 799 /* add nfs stuff here? */800 796 asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir); 801 797 if (system(command)) { … … 916 912 log_to_screen("Mindi failed to create your boot+data disks."); 917 913 asprintf(&command, "grep 'Fatal error' /var/log/mindi.log"); 918 asprintf(&tmp, call_program_and_get_last_line_of_output(command));914 tmp = call_program_and_get_last_line_of_output(command); 919 915 paranoid_free(command); 920 916 if (strlen(tmp) > 1) { … … 1176 1172 asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir); 1177 1173 1178 asprintf(&g_serial_string, 1179 call_program_and_get_last_line_of_output("dd \ 1174 g_serial_string = call_program_and_get_last_line_of_output("dd \ 1180 1175 if=/dev/urandom bs=16 count=1 2> /dev/null | \ 1181 1176 hexdump | tr -s ' ' '0' | head -n1")); 1182 strip_spaces(g_serial_string);1183 1177 asprintf(&tmp, "%s...word.", g_serial_string); 1184 1178 paranoid_free(g_serial_string); … … 1271 1265 } 1272 1266 /* if not Debian then go ahead & use fdformat */ 1273 asprintf(&tempfile, "%s", 1274 call_program_and_get_last_line_of_output 1275 ("mktemp -q /tmp/mondo.XXXXXXXX")); 1267 tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX")); 1276 1268 asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, 1277 1269 tempfile, tempfile); … … 1729 1721 ("Failed to write to disk. I shall blank it and then try again."); 1730 1722 sleep(5); 1731 sy stem("sync");1723 sync(); 1732 1724 pause_for_N_seconds(5, "Letting DVD drive settle"); 1733 1725 … … 1921 1913 char *tmp; 1922 1914 char *command; 1915 bool ret = TRUE; 1923 1916 asprintf(&command, 1924 1917 "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1", 1925 1918 bigfile_fname); 1926 1919 log_msg(1, "command = '%s'", command); 1927 asprintf(&tmp, "%s", 1928 call_program_and_get_last_line_of_output(command)); 1920 tmp = call_program_and_get_last_line_of_output(command)); 1929 1921 log_msg(1, "--> tmp = '%s'", tmp); 1930 1922 paranoid_free(command); 1931 1923 if (strstr(tmp, "NTFS")) { 1932 1924 iamhere("TRUE"); 1933 paranoid_free(tmp);1934 return (TRUE);1935 1925 } else { 1936 1926 iamhere("FALSE"); 1937 paranoid_free(tmp); 1938 return (FALSE); 1939 } 1927 ret = FALSE; 1928 } 1929 paranoid_free(tmp); 1930 return(ret); 1940 1931 } 1941 1932 … … 2870 2861 log_to_screen("%s found in drive. It's a Mondo disk.", 2871 2862 media_descriptor_string(g_backup_media_type)); 2872 cd_number = atoi(last_line_of_file(szcdno)); 2863 tmp1 = last_line_of_file(szcdno); 2864 cd_number = atoi(tmp1); 2865 paranoid_free(tmp1); 2873 2866 asprintf(&tmp1, "cat %s 2> /dev/null", szserfname); 2874 asprintf(&our_serial_str, "%s", 2875 call_program_and_get_last_line_of_output(tmp1)); 2867 our_serial_str = call_program_and_get_last_line_of_output(tmp1); 2876 2868 paranoid_free(tmp1); 2877 2869 // FIXME - should be able to use last_line_of_file(), surely? … … 2916 2908 } 2917 2909 paranoid_free(mtpt); 2918 2919 /*2920 if (g_current_media_number > ask_for_one_if_more_than_this)2921 {2922 ok_go_ahead_burn_it = FALSE;2923 log_it("paafcd: %d > %d, so I'll definitely pause.", g_current_media_number > ask_for_one_if_more_than_this);2924 }2925 */2926 2910 2927 2911 if (!ok_go_ahead_burn_it) { … … 3077 3061 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename); 3078 3062 log_it("command = %s", command); 3079 strcpy (tmp, call_program_and_get_last_line_of_output(command));3063 tmp = call_program_and_get_last_line_of_output(command); 3080 3064 log_it("res of it = %s", tmp); 3081 3065 totallength = (off_t)atoll(tmp); 3066 paranoid_free(tmp); 3082 3067 } else { 3083 3068 file_to_openin = biggie_filename; … … 3105 3090 paranoid_free(checksum_line); 3106 3091 3107 asprintf(&tmp, "%s", 3108 slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "")); 3092 tmp = slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""); 3109 3093 fout = fopen(tmp, "w"); 3110 3094 paranoid_free(tmp); … … 3124 3108 return (1); 3125 3109 } 3110 tmp = slice_fname(biggie_file_number, 0,bkpinfo->tmpdir, ""); 3126 3111 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3127 res = move_files_to_stream(bkpinfo, 3128 slice_fname(biggie_file_number, 0, 3129 bkpinfo->tmpdir, ""), NULL); 3112 res = move_files_to_stream(bkpinfo,tmp,NULL); 3130 3113 } else { 3131 res = 3132 move_files_to_cd(bkpinfo, mrconf, 3133 slice_fname(biggie_file_number, 0, 3134 bkpinfo->tmpdir, ""), NULL); 3135 } 3114 res = move_files_to_cd(bkpinfo, mrconf, tmp, NULL); 3115 } 3116 paranoid_free(tmp); 3136 3117 i = bkpinfo->optimal_set_size / 256; 3137 3118 for (slice_num = 1; !finished; slice_num++) { 3138 asprintf(&curr_slice_fname_uncompressed, "%s", 3139 slice_fname(biggie_file_number, slice_num, 3140 bkpinfo->tmpdir, "")); 3141 asprintf(&curr_slice_fname_compressed, "%s", 3142 slice_fname(biggie_file_number, slice_num, 3143 bkpinfo->tmpdir, suffix)); 3119 curr_slice_fname_uncompressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, ""); 3120 curr_slice_fname_compressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix)); 3144 3121 3145 3122 tmp = percent_media_full_comment(bkpinfo); … … 3573 3550 "Verifying archives against live filesystem"); 3574 3551 if (bkpinfo->backup_media_type == cdstream) { 3575 paranoid_alloc(bkpinfo->media_device, 3576 "/dev/cdrom"); 3552 paranoid_alloc(bkpinfo->media_device,"/dev/cdrom"); 3577 3553 } 3578 3554 verify_tape_backups(bkpinfo); … … 3588 3564 g_current_media_number = cdno; 3589 3565 if (bkpinfo->backup_media_type != iso) { 3590 paranoid_free(bkpinfo->media_device); 3591 bkpinfo->media_device = find_cdrom_device(FALSE); 3566 bkpinfo->media_device = find_cdrom_device(FALSE)); 3592 3567 } 3593 3568 chdir("/"); … … 3717 3692 } 3718 3693 if (((blockno + 1) % 128) == 0) { 3719 paranoid_system("sync"); /* fflush doesn't work; dunno why */3694 sync(); /* fflush doesn't work; dunno why */ 3720 3695 update_evalcall_form(percentage); 3721 3696 } -
trunk/mondo/mondo/common/libmondo-devices.c
r687 r688 1 /* $Id$ 1 /* 2 * $Id$ 2 3 * Subroutines for handling devices 3 4 */ … … 19 20 #include <sys/ioctl.h> 20 21 #include <sys/types.h> 22 #include <unistd.h> 21 23 #ifdef __FreeBSD__ 22 24 #define DKTYPENAMES … … 60 62 { 61 63 if (bkpinfo->media_device != NULL) { 62 paranoid_free(g_cdrom_drive_is_here); 63 asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 64 paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 64 65 } 65 66 if (bkpinfo->media_device != NULL) { 66 paranoid_free(g_dvd_drive_is_here); 67 asprintf(&g_dvd_drive_is_here, bkpinfo->media_device); // just in case 67 paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 68 68 } 69 69 } … … 320 320 char *incoming = NULL; 321 321 char *searchstr; 322 char *tmp; 322 323 323 324 /*@ ints ******************************************************* */ … … 332 333 assert_string_is_neither_NULL_nor_zerolength(drive); 333 334 assert(partno >= 0 && partno < 999); 334 335 malloc_string(searchstr);336 335 337 336 #ifdef __FreeBSD__ … … 353 352 paranoid_free(program); 354 353 355 (void) build_partition_name(searchstr, drive, partno); 356 strcat(searchstr, " "); 354 searchstr = build_partition_name(drive, partno); 355 asprintf(&tmp, "%s ", searchstr); 356 paranoid_free(searchstr); 357 357 358 for (res = 0; !res && getline(&incoming, &n, fin);) { 358 if (strstr(incoming, searchstr)) {359 if (strstr(incoming, tmp)) { 359 360 res = 1; 360 361 } … … 365 366 log_OS_error("Cannot pclose fin"); 366 367 } 367 paranoid_free( searchstr);368 paranoid_free(tmp); 368 369 return (res); 369 370 } … … 459 460 asprintf(&dev, g_cdrom_drive_is_here); 460 461 } else { 462 // find_cdrom_device allocates the string 461 463 dev = find_cdrom_device(FALSE); 462 464 } … … 468 470 469 471 if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) { 472 paranoid_free(dev); 470 473 if (!popup_and_get_string 471 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), 472 dev, MAX_STR_LEN / 4)) { 474 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) { 473 475 res = FALSE; 474 476 } else { … … 556 558 { 557 559 /*@ pointers **************************************************** */ 558 FILE *fin ;559 char *p ;560 char *q ;561 char *r ;560 FILE *fin = NULL; 561 char *p = NULL; 562 char *q = NULL; 563 char *r = NULL; 562 564 char *output = NULL; 563 565 size_t n = 0; … … 568 570 /*@ buffers ***************************************************** */ 569 571 char *tmp = NULL; 570 char *cdr_exe ;572 char *cdr_exe = NULL; 571 573 #ifndef __FreeBSD__ 572 574 char *phrase_two = NULL; 573 575 char *dvd_last_resort = NULL; 574 576 #endif 575 char *command ;576 char *mountpoint ;577 static char the_last_place_i_found_it[MAX_STR_LEN] = "";577 char *command = NULL; 578 char *mountpoint = NULL; 579 static char *the_last_place_i_found_it = NULL; 578 580 579 581 /*@ end vars **************************************************** */ … … 584 586 return(output); 585 587 } 586 if ( the_last_place_i_found_it[0] != '\0'&& !try_to_mount) {588 if ((the_last_place_i_found_it != NULL) && !try_to_mount) { 587 589 asprintf(&output, the_last_place_i_found_it); 588 590 log_msg(3, … … 834 836 } 835 837 log_msg(3, "(find_cdrom_device) --> '%s'", output); 836 strcpy(the_last_place_i_found_it, output);838 asprintf(&the_last_place_i_found_it, output); 837 839 paranoid_free(g_cdrom_drive_is_here); 838 840 asprintf(&g_cdrom_drive_is_here, output); … … 863 865 char *find_dvd_device() 864 866 { 865 char *tmp ;867 char *tmp = NULL; 866 868 int retval = 0, devno = -1; 867 869 char *output = NULL; … … 1008 1010 bool is_this_a_valid_disk_format(char *format) 1009 1011 { 1010 char *good_formats; 1011 char *command; 1012 char *format_sz; 1013 1014 FILE *pin; 1012 char *good_formats = NULL; 1013 char *command = NULL; 1014 char *tmp = NULL; 1015 char *format_sz = NULL; 1016 1017 FILE *pin = NULL; 1015 1018 bool retval; 1016 malloc_string(good_formats);1019 size_t n = 0; 1017 1020 assert_string_is_neither_NULL_nor_zerolength(format); 1018 1021 … … 1034 1037 retval = FALSE; 1035 1038 } else { 1036 strcpy(good_formats, " "); 1037 (void) fgets(good_formats + 1, MAX_STR_LEN, pin); 1039 getline(&good_formats, &n , pin); 1038 1040 if (pclose(pin)) { 1039 1041 log_OS_error("Cannot pclose good formats"); 1040 1042 } 1041 1043 strip_spaces(good_formats); 1042 strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1044 // " ntfs 7 " -- um, cheating much? :) 1045 asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats); 1046 paranoid_free(good_formats); 1047 good_formats = tmp; 1048 1043 1049 if (strstr(good_formats, format_sz)) { 1044 1050 retval = TRUE; … … 1046 1052 retval = FALSE; 1047 1053 } 1048 }1049 paranoid_free(good_formats);1054 paranoid_free(good_formats); 1055 } 1050 1056 paranoid_free(format_sz); 1051 1057 return (retval); … … 1141 1147 char *make_vn(char *fname) 1142 1148 { 1143 char *device ;1149 char *device = NULL; 1144 1150 char *mddevice = NULL; 1145 1151 char *command = NULL; … … 1224 1230 { 1225 1231 /*@ buffer ****************************************************** */ 1226 char *command ;1227 int retval ;1232 char *command = NULL; 1233 int retval = 0; 1228 1234 1229 1235 assert_string_is_neither_NULL_nor_zerolength(device); … … 1238 1244 1239 1245 #ifdef __FreeBSD__ 1240 char *dev ;1246 char *dev = NULL; 1241 1247 1242 1248 dev = make_vn(device)); … … 1361 1367 1362 1368 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) { 1363 paranoid_system("sync");1369 sync(); 1364 1370 if (is_this_device_mounted(MNT_CDROM)) { 1365 1371 res = … … 1383 1389 inject_device(bkpinfo->media_device); 1384 1390 } 1385 paranoid_system("sync");1391 sync(); 1386 1392 } 1387 1393 paranoid_free(request); … … 1410 1416 // archiving_to_media is FALSE if I'm being called by mondorestore 1411 1417 { 1412 char *tmp; 1418 char *tmp = NULL; 1419 char *tmp1 = NULL; 1420 char *tmp2 = NULL; 1413 1421 char *sz_size = NULL; 1414 char *command ;1415 char *comment ;1422 char *command = NULL; 1423 char *comment = NULL; 1416 1424 char *prompt = NULL; 1417 int i ;1418 FILE *fin ;1425 int i = 0; 1426 FILE *fin = NULL; 1419 1427 1420 1428 assert(bkpinfo != NULL); … … 1480 1488 media_descriptor_string(bkpinfo->backup_media_type)); 1481 1489 if (bkpinfo->backup_media_type == dvd) { 1482 paranoid_free(bkpinfo->media_device);1483 1490 bkpinfo->media_device = find_dvd_device(); 1484 1491 asprintf(&tmp, "1"); … … 1492 1499 } 1493 1500 if (bkpinfo->backup_media_type != dvd) { 1494 if (!popup_and_get_string(_("Speed"), comment, tmp , 4)) {1501 if (!popup_and_get_string(_("Speed"), comment, tmp)) { 1495 1502 log_to_screen(_("User has chosen not to backup the PC")); 1496 1503 finish(1); … … 1506 1513 media_descriptor_string(bkpinfo->backup_media_type)); 1507 1514 1508 if (!popup_and_get_string("Size", comment, sz_size , 5)) {1515 if (!popup_and_get_string("Size", comment, sz_size)) { 1509 1516 log_to_screen(_("User has chosen not to backup the PC")); 1510 1517 finish(1); … … 1515 1522 bkpinfo->media_size[i] = atoi(sz_size); 1516 1523 } 1524 paranoid_free(sz_size); 1525 1517 1526 if (bkpinfo->media_size[0] <= 0) { 1518 1527 log_to_screen(_("User has chosen not to backup the PC")); 1519 1528 finish(1); 1520 1529 } 1521 paranoid_free(sz_size);1522 1530 } 1523 1531 case cdstream: … … 1529 1537 || bkpinfo->backup_media_type == dvd) { 1530 1538 if (bkpinfo->media_device == NULL) { 1531 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");1539 asprintf(&bkpinfo->media_device, "/dev/cdrom"); 1532 1540 } // just for the heck of it :) 1533 1541 log_msg(1, "bkpinfo->media_device = %s", … … 1544 1552 backup_media_type)); 1545 1553 if (!popup_and_get_string 1546 (_("Device?"), comment, bkpinfo->media_device, 1547 MAX_STR_LEN / 4)) { 1554 (_("Device?"), comment, bkpinfo->media_device)) { 1548 1555 log_to_screen(_("User has chosen not to backup the PC")); 1549 1556 finish(1); … … 1555 1562 bkpinfo->media_device); 1556 1563 } else { 1557 paranoid_free(bkpinfo->media_device);1558 1564 bkpinfo->media_device = find_cdrw_device(); 1559 1565 if (bkpinfo->media_device != NULL) { … … 1571 1577 i = popup_and_get_string(_("Device node?"), 1572 1578 _("What is the SCSI node of your CD (re)writer, please?"), 1573 bkpinfo->media_device, 1574 MAX_STR_LEN / 4); 1579 bkpinfo->media_device); 1575 1580 } else { 1576 1581 i = popup_and_get_string(_("/dev entry?"), 1577 1582 _("What is the /dev entry of your CD (re)writer, please?"), 1578 bkpinfo->media_device, 1579 MAX_STR_LEN / 4); 1583 bkpinfo->media_device); 1580 1584 } 1581 1585 if (!i) { … … 1602 1606 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) { 1603 1607 log_msg(3, _("Ok, using vanilla scsi tape.")); 1604 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE );1608 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" ); 1605 1609 if ((fin = fopen(bkpinfo->media_device, "r"))) { 1606 1610 paranoid_fclose(fin); … … 1630 1634 (_("Device name?"), 1631 1635 _("What is the /dev entry of your tape streamer?"), 1632 bkpinfo->media_device , MAX_STR_LEN / 4)) {1636 bkpinfo->media_device)) { 1633 1637 log_to_screen(_("User has chosen not to backup the PC")); 1634 1638 finish(1); … … 1642 1646 paranoid_free(tmp); 1643 1647 log_msg(4, "sz_size = %s", sz_size); 1644 sz_size[0] = '\0';1648 paranoid_free(sz_size); 1645 1649 bkpinfo->media_size[0] = 0; 1646 1650 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); … … 1677 1681 (_("NFS dir."), 1678 1682 _("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.)"), 1679 bkpinfo->nfs_mount , MAX_STR_LEN / 4)) {1683 bkpinfo->nfs_mount)) { 1680 1684 log_to_screen(_("User has chosen not to backup the PC")); 1681 1685 finish(1); … … 1701 1705 asprintf(&comment, 1702 1706 _("How much data (in Megabytes) will each media store?")); 1703 if (!popup_and_get_string(_("Size"), comment, sz_size , 5)) {1707 if (!popup_and_get_string(_("Size"), comment, sz_size)) { 1704 1708 log_to_screen(_("User has chosen not to backup the PC")); 1705 1709 finish(1); … … 1718 1722 if (!popup_and_get_string 1719 1723 (_("NFS share"), _("Which remote NFS share should I mount?"), 1720 bkpinfo->nfs_mount , MAX_STR_LEN)) {1724 bkpinfo->nfs_mount)) { 1721 1725 log_to_screen(_("User has chosen not to backup the PC")); 1722 1726 finish(1); … … 1742 1746 finish(1); 1743 1747 } 1744 asprintf(&tmp, bkpinfo->nfs_remote_dir);1745 1748 if (!popup_and_get_string 1746 (_("Directory"), _("Which directory within that mountpoint?"), tmp, 1747 MAX_STR_LEN)) { 1749 (_("Directory"), _("Which directory within that mountpoint?"),bkpinfo->nfs_remote_dir)) { 1748 1750 log_to_screen(_("User has chosen not to backup the PC")); 1749 1751 finish(1); 1750 1752 } 1751 strcpy(bkpinfo->nfs_remote_dir, tmp); 1752 paranoid_free(tmp); 1753 1754 // check whether writable - we better remove surrounding spaces for this 1755 strip_spaces(bkpinfo->nfs_remote_dir); 1756 asprintf(&command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 1753 1754 asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir, 1757 1755 bkpinfo->nfs_remote_dir); 1758 1756 while (run_program_and_log_output(command, FALSE)) { 1759 paranoid_free(tmp);1760 paranoid_free(prompt);1761 asprintf(&tmp, bkpinfo->nfs_remote_dir);1762 1757 asprintf(&prompt, 1763 1758 _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."), 1764 1759 bkpinfo->nfs_remote_dir, bkpinfo->isodir); 1765 1760 if (!popup_and_get_string 1766 (_("Directory"), prompt, tmp, MAX_STR_LEN)) {1761 (_("Directory"), prompt, bkpinfo->nfs_remote_dir)) { 1767 1762 log_to_screen(_("User has chosen not to backup the PC")); 1768 1763 finish(1); 1769 1764 } 1770 strcpy(bkpinfo->nfs_remote_dir, tmp);1771 // check whether writable - we better remove surrounding spaces for this */ 1772 strip_spaces(bkpinfo->nfs_remote_dir);1765 paranoid_free(prompt); 1766 1767 paranoid_free(command); 1773 1768 asprintf(&command, "echo hi > %s/%s/.dummy.txt", 1774 1769 bkpinfo->isodir, bkpinfo->nfs_remote_dir); 1775 1770 } 1776 1771 paranoid_free(command); 1777 paranoid_free(tmp);1778 paranoid_free(prompt);1779 1772 1780 1773 if (!popup_and_get_string 1781 1774 (_("Prefix."), 1782 1775 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"), 1783 bkpinfo->prefix , MAX_STR_LEN / 4)) {1776 bkpinfo->prefix)) { 1784 1777 log_to_screen(_("User has chosen not to backup the PC")); 1785 1778 finish(1); … … 1800 1793 (_("Storage dir."), 1801 1794 _("Please enter the full path that contains your ISO images. Example: /mnt/raid0_0"), 1802 bkpinfo->isodir , MAX_STR_LEN / 4)) {1795 bkpinfo->isodir)) { 1803 1796 log_to_screen(_("User has chosen not to backup the PC")); 1804 1797 finish(1); … … 1812 1805 if (!popup_and_get_string 1813 1806 (_("ISO size."), 1814 _("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 or DVD's you plan to backup to."), 1815 sz_size, 16)) { 1807 _("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 or DVD's you plan to backup to."), sz_size)) { 1816 1808 log_to_screen(_("User has chosen not to backup the PC")); 1817 1809 finish(1); … … 1825 1817 (_("Prefix."), 1826 1818 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"), 1827 bkpinfo->prefix , MAX_STR_LEN / 4)) {1819 bkpinfo->prefix)) { 1828 1820 log_to_screen("User has chosen not to backup the PC"); 1829 1821 finish(1); … … 1844 1836 1845 1837 #ifdef __FreeBSD__ 1846 strcpy(bkpinfo->boot_device, 1847 call_program_and_get_last_line_of_output 1838 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1848 1839 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 1849 1840 #else 1850 strcpy(bkpinfo->boot_device, 1851 call_program_and_get_last_line_of_output 1841 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1852 1842 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 1853 1843 #endif … … 1860 1850 (_("Boot device"), 1861 1851 _("What is your boot device? (e.g. /dev/ad0)"), 1862 bkpinfo->boot_device , MAX_STR_LEN / 4)) {1852 bkpinfo->boot_device)) { 1863 1853 log_to_screen(_("User has chosen not to backup the PC")); 1864 1854 finish(1); … … 1869 1859 (_("Boot device"), 1870 1860 _("What is your boot device? (e.g. /dev/hda)"), 1871 bkpinfo->boot_device , MAX_STR_LEN / 4)) {1861 bkpinfo->boot_device)) { 1872 1862 log_to_screen(_("User has chosen not to backup the PC")); 1873 1863 finish(1); … … 1901 1891 } 1902 1892 bkpinfo->boot_loader = i; 1903 strcpy(bkpinfo->include_paths, "/");1893 asprintf(&bkpinfo->include_paths, "/"); 1904 1894 if (!popup_and_get_string 1905 1895 (_("Backup paths"), 1906 1896 _("Please enter paths which you want me to backup. The default is '/' (i.e. everything)."), 1907 bkpinfo->include_paths , MAX_STR_LEN)) {1897 bkpinfo->include_paths)) { 1908 1898 log_to_screen(_("User has chosen not to backup the PC")); 1909 1899 finish(1); 1910 1900 } 1901 1911 1902 tmp = list_of_NFS_mounts_only(); 1912 1903 if (strlen(tmp) > 2) { 1913 if (bkpinfo->exclude_paths[0]) { 1914 strcat(bkpinfo->exclude_paths, " "); 1915 } 1916 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 1904 if (bkpinfo->exclude_paths != NULL) { 1905 tmp1 = bkpinfo->exclude_paths; 1906 asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp); 1907 paranoid_free(tmp1); 1908 } else { 1909 bkpinfo->exclude_paths = tmp; 1910 } 1917 1911 } 1918 1912 paranoid_free(tmp); 1919 1913 // NTFS 1920 asprintf(&tmp, 1921 call_program_and_get_last_line_of_output 1922 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); 1914 tmp = call_program_and_get_last_line_of_output 1915 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"); 1923 1916 if (strlen(tmp) > 2) { 1924 1917 if (!popup_and_get_string 1925 1918 (_("NTFS partitions"), 1926 1919 _("Please enter/confirm the NTFS partitions you wish to backup as well."), 1927 tmp , MAX_STR_LEN / 4)) {1920 tmp1)) { 1928 1921 log_to_screen(_("User has chosen not to backup the PC")); 1929 1922 finish(1); 1930 1923 } 1931 strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4); 1924 if (bkpinfo->image_devs != NULL) { 1925 tmp2 = bkpinfo->image_devs; 1926 asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1); 1927 paranoid_free(tmp2); 1928 } else { 1929 bkpinfo->image_devs = tmp1; 1930 } 1931 paranoid_free(tmp1); 1932 1932 } 1933 1933 paranoid_free(tmp); … … 1936 1936 (_("Exclude paths"), 1937 1937 _("Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup."), 1938 bkpinfo->exclude_paths , MAX_STR_LEN)) {1938 bkpinfo->exclude_paths)) { 1939 1939 log_to_screen(_("User has chosen not to backup the PC")); 1940 1940 finish(1); … … 2005 2005 * Get a space-separated list of NFS mounts. 2006 2006 * @return The list created. 2007 * @note The return value points to static data that will be overwritten with each call.2007 * @note The return value should be freed by caller 2008 2008 * @bug Even though we only want the mounts, the devices are still checked. 2009 2009 */ 2010 2010 char *list_of_NFS_mounts_only(void) 2011 2011 { 2012 char *exclude_these_devices; 2013 char *exclude_these_directories; 2014 char *result_sz; 2015 2016 asprintf(&exclude_these_directories, 2017 call_program_and_get_last_line_of_output 2012 return(call_program_and_get_last_line_of_output 2018 2013 ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2014 /* BERLIOS : Useless 2019 2015 asprintf(&exclude_these_devices, 2020 2016 call_program_and_get_last_line_of_output 2021 2017 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2022 asprintf(&result_sz, "%s", exclude_these_directories); 2023 paranoid_free(exclude_these_devices); 2024 paranoid_free(exclude_these_directories); 2025 return (result_sz); 2018 */ 2026 2019 } 2027 2020 … … 2060 2053 void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo) 2061 2054 { 2062 char *tmp, *command, *sz; 2055 char *tmp = NULL; 2056 char *command = NULL; 2057 char *sz = NULL; 2058 int i = 0; 2063 2059 2064 2060 assert(bkpinfo != NULL); 2065 2061 2066 2062 #ifdef __FreeBSD__ 2067 asprintf(&tmp, 2068 call_program_and_get_last_line_of_output 2069 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2063 tmp = call_program_and_get_last_line_of_output 2064 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2070 2065 #else 2071 asprintf(&tmp, 2072 call_program_and_get_last_line_of_output 2073 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2066 tmp = call_program_and_get_last_line_of_output 2067 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2074 2068 #endif 2075 2069 … … 2082 2076 fatal_error("I couldn't figure out the tempdir!"); 2083 2077 } 2084 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,2085 (int) (random() % 32768));2078 i = (int) (random() % 32768); 2079 asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i); 2086 2080 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2087 2081 2088 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, 2089 (int) (random() % 32768)); 2082 asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i); 2090 2083 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2091 2084 2092 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,2085 asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 2093 2086 bkpinfo->scratchdir); 2094 2087 2095 asprintf(&command, "rm -Rf %s/ tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);2088 asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp); 2096 2089 paranoid_free(tmp); 2097 2090 … … 2152 2145 { 2153 2146 int cd_number = -1; 2154 char *mountdev; 2155 char *tmp; 2147 char *mountdev = NULL; 2148 char *tmp = NULL; 2149 char *tmp1 = NULL; 2156 2150 2157 2151 assert(bkpinfo != NULL); … … 2159 2153 asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2160 2154 2161 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));2155 tmp1 = call_program_and_get_last_line_of_output(tmp); 2162 2156 paranoid_free(tmp); 2163 2157 2164 cd_number = atoi(last_line_of_file(mountdev)); 2158 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1); 2159 paranoid_free(tmp1); 2160 2161 tmp = last_line_of_file(mountdev); 2162 cd_number = atoi(tmp); 2165 2163 paranoid_free(mountdev); 2164 paranoid_free(tmp); 2166 2165 2167 2166 return (cd_number); … … 2176 2175 (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM); 2177 2176 } 2178 cd_number = 2179 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2177 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"); 2178 cd_number = atoi(tmp); 2179 paranoid_free(tmp); 2180 2180 return (cd_number); 2181 2181 } … … 2191 2191 char *where_is_root_mounted() 2192 2192 { 2193 /*@ buffers **************** */2194 2193 char *tmp; 2195 2194 2196 2197 2195 #ifdef __FreeBSD__ 2198 asprintf(&tmp,call_program_and_get_last_line_of_output2199 ("mount | grep \" on / \" | cut -d' ' -f1") );2196 tmp = call_program_and_get_last_line_of_output 2197 ("mount | grep \" on / \" | cut -d' ' -f1"); 2200 2198 #else 2201 asprintf(&tmp,call_program_and_get_last_line_of_output2202 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//") );2199 tmp = call_program_and_get_last_line_of_output 2200 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"); 2203 2201 if (strstr(tmp, "/dev/cciss/")) { 2204 2202 paranoid_free(tmp); 2205 asprintf(&tmp,call_program_and_get_last_line_of_output2206 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1") );2203 tmp = call_program_and_get_last_line_of_output 2204 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"); 2207 2205 } 2208 2206 if (strstr(tmp, "/dev/md")) { 2209 2207 paranoid_free(tmp); 2210 asprintf(&tmp, 2211 call_program_and_get_last_line_of_output 2212 ("mount | grep \" on / \" | cut -d' ' -f1")); 2208 tmp = call_program_and_get_last_line_of_output 2209 ("mount | grep \" on / \" | cut -d' ' -f1"); 2213 2210 } 2214 2211 #endif … … 2373 2370 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2374 2371 { 2375 char *output ;2376 char *command ;2377 char *curr_fname ;2378 char *scratch ;2379 char *tmp ;2380 char *p ;2372 char *output = NULL; 2373 char *command = NULL; 2374 char *curr_fname = NULL; 2375 char *scratch = NULL; 2376 char *tmp = NULL; 2377 char *p = NULL; 2381 2378 2382 2379 struct stat statbuf; … … 2391 2388 log_msg(1, "curr_fname = %s", curr_fname); 2392 2389 asprintf(&command, "file %s", curr_fname); 2393 asprintf(&tmp, call_program_and_get_last_line_of_output(command));2390 tmp = call_program_and_get_last_line_of_output(command); 2394 2391 paranoid_free(command); 2395 2392 … … 2400 2397 for (p = scratch; *p != '\0' && *p != '\''; p++); 2401 2398 *p = '\0'; 2402 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, 2403 scratch); 2399 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 2404 2400 paranoid_free(tmp); 2405 2401 … … 2439 2435 char *which_partition_format(const char *drive) 2440 2436 { 2441 char *output ;2442 char *tmp ;2443 char *command ;2444 char *fdisk ;2437 char *output = NULL; 2438 char *tmp = NULL; 2439 char *command = NULL; 2440 char *fdisk = NULL; 2445 2441 2446 2442 log_msg(0, "Looking for partition table format type"); … … 2450 2446 paranoid_free(fdisk); 2451 2447 2452 asprintf(&tmp, call_program_and_get_last_line_of_output(command));2448 tmp = call_program_and_get_last_line_of_output(command); 2453 2449 paranoid_free(command); 2454 2450 -
trunk/mondo/mondo/common/libmondo-fifo.c
r687 r688 13 13 #endif 14 14 #include <fcntl.h> 15 #include <stdio.h>16 15 17 16 #include <errno.h> … … 85 84 wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32); 86 85 wise_lower_limit = 1; // wise_upper_limit/2 + 1; 87 paranoid_system("sync");86 sync(); 88 87 for (bufsize = wise_upper_limit, res = -1; 89 88 res != 0 && bufsize >= wise_lower_limit; bufsize--) { … … 96 95 if (!res) { 97 96 bufsize++; 98 asprintf(&tmp, _("Negotiated max buffer of %d MB " , bufsize));97 asprintf(&tmp, _("Negotiated max buffer of %d MB "), bufsize); 99 98 log_to_screen(tmp); 100 99 paranoid_free(tmp); … … 160 159 char *command; 161 160 162 paranoid_system("sync");161 sync(); 163 162 asprintf(&command, 164 163 "ps wwax | grep -F \"%s\" | grep -Fv grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'", … … 167 166 log_msg(2, "kill_buffer() --- command = %s", command); 168 167 169 asprintf(&tmp, "%s", 170 call_program_and_get_last_line_of_output(command)); 168 tmp = call_program_and_get_last_line_of_output(command); 171 169 paranoid_free(command); 172 170 … … 177 175 run_program_and_log_output(command, TRUE); 178 176 } 177 paranoid_free(tmp); 179 178 paranoid_free(command); 180 paranoid_free(tmp);181 179 } 182 180 -
trunk/mondo/mondo/common/libmondo-filelist.c
r687 r688 847 847 { 848 848 849 /*@ structures ************************************************* */ 850 struct s_node *filelist; 851 852 /*@ pointers *************************************************** */ 853 FILE *pin; 854 855 /*@ buffers **************************************************** */ 856 char *command_to_open_fname; 849 struct s_node *filelist = NULL; 850 FILE *pin = NULL; 851 char *command_to_open_fname = NULL; 857 852 char *fname = NULL; 858 char *tmp; 859 int pos_in_fname; 853 char *tmp = NULL; 854 char *tmp1 = NULL; 855 int pos_in_fname = 0; 860 856 size_t n = 0; 861 /*@ int ******************************************************** */ 862 int percentage; 863 864 /*@ long ******************************************************* */ 865 long lines_in_filelist; 866 long lino = 0; 867 /*@ end vars *************************************************** */ 857 int percentage = 0; 858 859 long lines_in_filelist = 0L; 860 long lino = 0L; 868 861 869 862 assert_string_is_neither_NULL_nor_zerolength(filelist_fname); … … 876 869 asprintf(&tmp, "zcat %s | wc -l", filelist_fname); 877 870 log_msg(6, "tmp = %s", tmp); 878 lines_in_filelist = 879 atol(call_program_and_get_last_line_of_output(tmp)); 871 tmp1 = call_program_and_get_last_line_of_output(tmp); 880 872 paranoid_free(tmp); 873 874 lines_in_filelist = atol(tmp1); 875 paranoid_free(tmp1); 881 876 882 877 if (lines_in_filelist < 3) { … … 1322 1317 char *skeleton_filelist) 1323 1318 { 1324 DIR *dip ;1325 struct dirent *dit ;1319 DIR *dip = NULL; 1320 struct dirent *dit = NULL; 1326 1321 struct stat statbuf; 1327 char *new; 1328 char *tmp; 1322 char *new = NULL; 1323 char *tmp = NULL; 1324 char *tmp1 = NULL; 1329 1325 static int percentage = 0; 1330 char *skip_these ;1331 char *new_with_spaces ;1332 static char *name_of_evalcall_form ;1333 int i ;1326 char *skip_these = NULL; 1327 char *new_with_spaces = NULL; 1328 static char *name_of_evalcall_form = NULL; 1329 int i = 0; 1334 1330 static int depth = 0; 1335 char *p ;1331 char *p = NULL; 1336 1332 static int counter = 0; 1337 1333 static int uberctr = 0; 1338 static char *find_skeleton_marker ;1334 static char *find_skeleton_marker = NULL; 1339 1335 static long skeleton_lino = 0; 1340 1336 static time_t last_time = 0; … … 1365 1361 1366 1362 asprintf(&tmp, "wc -l %s | awk '{print $1;}'", skeleton_filelist); 1367 g_skeleton_entries = 1368 1 + atol(call_program_and_get_last_line_of_output(tmp)); 1363 tmp1 = call_program_and_get_last_line_of_output(tmp); 1369 1364 paranoid_free(tmp); 1365 1366 g_skeleton_entries = 1 + atol(tmp1); 1367 paranoid_free(tmp1); 1370 1368 1371 1369 asprintf(&name_of_evalcall_form, "Making catalog of %s", dir); … … 1534 1532 { 1535 1533 char sz_datefile_wildcard[] = "/var/cache/mondo/difflevel.%d"; 1536 char *p, *q; 1534 char *p = NULL; 1535 char *q = NULL; 1536 char *tmp = NULL; 1537 char *tmp1 = NULL; 1538 char *tmp2 = NULL; 1537 1539 char *sz_datefile; 1538 char *sz_filelist, *exclude_paths; 1539 int i; 1540 FILE *fout; 1541 char *command; 1540 char *sz_filelist = NULL; 1541 char *exclude_paths = NULL; 1542 int i = 0; 1543 FILE *fout = NULL; 1544 char *command = NULL; 1542 1545 time_t time_of_last_full_backup = 0; 1543 1546 struct stat statbuf; 1544 char *skeleton_filelist; 1547 char *skeleton_filelist = NULL; 1548 1545 1549 // The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist(). 1546 1547 1550 asprintf(&sz_datefile, sz_datefile_wildcard, 0); 1548 1551 if (!include_paths && !userdef_filelist) { … … 1573 1576 } 1574 1577 make_hole_for_file(sz_datefile); 1575 write_one_liner_data_file(sz_datefile,1576 call_program_and_get_last_line_of_output1577 ("date +%s"));1578 tmp = call_program_and_get_last_line_of_output("date +%s"); 1579 write_one_liner_data_file(sz_datefile, tmp); 1580 paranoid_free(tmp); 1578 1581 } else if (lstat(sz_datefile, &statbuf)) { 1579 1582 log_msg(2, … … 1600 1603 log_msg(2, "include_paths = '%s'", include_paths); 1601 1604 log_msg(1, "Calculating filelist"); 1605 tmp = call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"); 1606 tmp1 = call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"); 1607 tmp2 = call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"); 1602 1608 asprintf(&exclude_paths, " %s %s %s %s %s %s . .. \ 1603 1609 " MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \ 1604 /proc /sys /tmp /var/cache/mondo /var/cache/mindi", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir); 1610 /proc /sys /tmp /var/cache/mondo /var/cache/mindi", excp, tmp, tmp1, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir); 1611 paranoid_free(tmp); 1612 paranoid_free(tmp1); 1613 paranoid_free(tmp2); 1605 1614 1606 1615 log_msg(2, "Excluding paths = '%s'", exclude_paths); -
trunk/mondo/mondo/common/libmondo-files.c
r687 r688 22 22 //static char cvsid[] = "$Id$"; 23 23 24 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];24 extern char **err_log_lines; 25 25 26 26 extern int g_currentY; … … 270 270 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 271 271 { 272 char *tmp; 273 char *command; 274 275 if (!kernel[0]) { 276 strcpy(kernel, 277 call_program_and_get_last_line_of_output 272 char *tmp = NULL; 273 char *command = NULL; 274 275 if (kernel == NULL) { 276 kernel = call_program_and_get_last_line_of_output 278 277 ("mindi --findkernel 2> /dev/null")); 279 278 } 280 279 // If we didn't get anything back, check whether mindi raised a fatal error 281 if ( !kernel[0]) {280 if (kernel == NULL) { 282 281 asprintf(&command, "grep 'Fatal error' /var/log/mindi.log"); 283 asprintf(&tmp, call_program_and_get_last_line_of_output(command));282 tmp = call_program_and_get_last_line_of_output(command); 284 283 if (strlen(tmp) > 1) { 285 284 popup_and_OK(tmp); … … 289 288 paranoid_free(tmp); 290 289 } 291 log_it("Calling Mindi with kernel path of '%s'", kernel); 292 while (!kernel[0]) { 290 291 if (kernel != NULL) { 292 log_it("Calling Mindi with kernel path of '%s'", kernel); 293 } else { 294 log_it("Calling Mindi without kernel, so asking one"); 295 } 296 297 while (kernel == NULL) { 293 298 if (!ask_me_yes_or_no 294 299 (_("Kernel not found or invalid. Choose another?"))) { … … 298 303 (_("Kernel path"), 299 304 _("What is the full path and filename of your kernel, please?"), 300 kernel , MAX_STR_LEN / 4)) {305 kernel)) { 301 306 fatal_error 302 307 ("Kernel not found. Please specify with the '-k' flag."); 303 308 } 304 asprintf(&tmp, "User says kernel is at %s", kernel); 305 log_it(tmp); 306 paranoid_free(tmp); 309 log_it("User says kernel is at %s", kernel); 307 310 } 308 311 return (0); … … 322 325 { 323 326 /*@ buffers ********************* */ 324 static char output[MAX_STR_LEN];325 char *incoming ;326 char *command ;327 char *output = NULL; 328 char *incoming = NULL; 329 char *command = NULL; 327 330 328 331 /*@******************************* */ 329 332 330 333 assert_string_is_neither_NULL_nor_zerolength(fname); 334 331 335 asprintf(&command, "which %s 2> /dev/null", fname); 332 asprintf(&incoming, call_program_and_get_last_line_of_output(command));333 paranoid_free(command); 334 335 if (incoming [0] == '\0') {336 incoming = call_program_and_get_last_line_of_output(command); 337 paranoid_free(command); 338 339 if (incoming == NULL) { 336 340 if (system("which file > /dev/null 2> /dev/null")) { 337 paranoid_free(incoming);338 341 return (NULL); // forget it :) 339 342 } … … 343 346 paranoid_free(incoming); 344 347 345 asprintf(&incoming, 346 call_program_and_get_last_line_of_output(command)); 348 incoming = call_program_and_get_last_line_of_output(command); 347 349 paranoid_free(command); 348 350 } 349 if (incoming [0] == '\0') // yes, it is == '\0' twice, not once :)351 if (incoming == NULL) // yes, it is == '\0' twice, not once :) 350 352 { 351 353 asprintf(&command, "dirname %s 2> /dev/null", incoming); 352 354 paranoid_free(incoming); 353 355 354 asprintf(&incoming, 355 call_program_and_get_last_line_of_output(command)); 356 incoming = call_program_and_get_last_line_of_output(command); 356 357 paranoid_free(command); 357 358 } 358 strcpy(output, incoming); 359 paranoid_free(incoming); 360 361 if (output[0] != '\0' && does_file_exist(output)) { 362 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 363 output); 359 output = incoming; 360 361 if (output != NULL && does_file_exist(output)) { 362 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output); 364 363 } else { 365 output[0] = '\0';364 paranoid_free(output); 366 365 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 367 366 } 368 if (!output[0]) { 369 return (NULL); 370 } else { 371 return (output); 372 } 367 return (output); 373 368 } 374 369 … … 421 416 { 422 417 423 /*@ buffers ***************************************************** */ 424 char *lastline; 425 char *command; 426 /*@ pointers **************************************************** */ 427 char *p; 428 429 /*@ int's ******************************************************* */ 418 char *lastline = NULL; 419 char *command = NULL; 420 char *p = NULL; 430 421 int i; 431 422 432 for (i = NOOF_ERR_LINES- 1;423 for (i = g_noof_log_lines - 1; 433 424 i >= 0 && !strstr(err_log_lines[i], "% Done") 434 425 && !strstr(err_log_lines[i], "% done"); i--); … … 437 428 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", 438 429 filename, '%'); 439 asprintf(&lastline, 440 call_program_and_get_last_line_of_output(command)); 430 lastline = call_program_and_get_last_line_of_output(command); 441 431 paranoid_free(command); 442 if (!lastline[0]) { 443 paranoid_free(lastline); 432 if (!lastline) { 444 433 return (0); 445 434 } … … 477 466 { 478 467 /*@ buffers ***************************************************** */ 479 static char output[MAX_STR_LEN];480 static char *command;481 static char *tmp;468 char *output = NULL; 469 char *command = NULL; 470 char *tmp = NULL; 482 471 483 472 /*@ pointers **************************************************** */ 484 473 FILE *fin; 474 size_t n = 0; 485 475 486 476 /*@ end vars **************************************************** */ … … 491 481 log_it(tmp); 492 482 paranoid_free(tmp); 493 494 output[0] = '\0'; 483 asprintf(&output, ""); 484 495 485 return (output); 496 486 } … … 499 489 paranoid_free(command); 500 490 501 (void) fgets(output, MAX_STR_LEN, fin);491 getline(&output, &n, fin); 502 492 paranoid_pclose(fin); 503 493 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { … … 693 683 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 694 684 { 695 char *command ;696 char *sz_res ;697 long file_len_K ;685 char *command = NULL; 686 char *sz_res = NULL; 687 long file_len_K = 0L; 698 688 699 689 asprintf(&command, … … 701 691 dev, tmpdir); 702 692 log_it(command); 703 asprintf(&sz_res, call_program_and_get_last_line_of_output(command));693 sz_res = call_program_and_get_last_line_of_output(command); 704 694 file_len_K = atol(sz_res); 705 695 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); … … 717 707 long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo) 718 708 { 719 /*@ buffers ***************************************************** */ 720 char *fname; 721 char *biggielist; 722 char *comment; 723 char *tmp; 724 char *command; 709 char *fname = NULL; 710 char *biggielist = NULL; 711 char *comment = NULL; 712 char *tmp = NULL; 713 char *command = NULL; 725 714 726 715 /*@ long ******************************************************** */ 727 long scratchL = 0 ;728 long file_len_K ;716 long scratchL = 0L; 717 long file_len_K = 0L; 729 718 730 719 /*@ pointers *************************************************** */ … … 734 723 /*@ end vars *************************************************** */ 735 724 736 malloc_string(tmp);737 malloc_string(command);738 725 log_it("Calculating size of all biggiefiles (in total)"); 739 726 asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); … … 754 741 fatal_error("ntfsresize not found"); 755 742 } 756 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);743 asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 757 744 log_it("command = %s", command); 758 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 745 tmp = call_program_and_get_last_line_of_output(command); 746 paranoid_free(command); 747 759 748 log_it("res of it = %s", tmp); 760 749 file_len_K = atoll(tmp) / 1024L; 750 paranoid_free(tmp); 761 751 } else { 762 752 file_len_K = get_phys_size_of_drive(fname) * 1024L; … … 787 777 paranoid_fclose(fin); 788 778 log_it("Finished calculating total size of all biggiefiles"); 789 paranoid_free(tmp);790 paranoid_free(command);791 779 return (scratchL); 792 780 } … … 803 791 /*@ buffer ****************************************************** */ 804 792 char *tmp = NULL; 805 char *command ;793 char *command = NULL; 806 794 long long llres; 807 795 size_t n = 0; 808 796 /*@ pointers **************************************************** */ 809 char *p ;810 FILE *fin ;797 char *p = NULL; 798 FILE *fin = NULL; 811 799 812 800 /*@ end vars *************************************************** */ … … 1025 1013 paranoid_free(command); 1026 1014 1027 asprintf(&tmp, 1028 call_program_and_get_last_line_of_output("which mondorestore")); 1029 if (!tmp[0]) { 1015 tmp = call_program_and_get_last_line_of_output("which mondorestore"); 1016 if (!tmp) { 1030 1017 fatal_error 1031 1018 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); … … 1068 1055 1069 1056 /*@ buffers ******** */ 1070 char *outfile ;1071 char *nfs_dev ;1072 char *nfs_mount ;1073 char *nfs_client_ipaddr ;1074 char *nfs_client_netmask ;1075 char *nfs_client_broadcast ;;1076 char *nfs_client_defgw ;1077 char *nfs_server_ipaddr ;1078 char *tmp ;1079 char *command ;1057 char *outfile = NULL; 1058 char *nfs_dev = NULL; 1059 char *nfs_mount = NULL; 1060 char *nfs_client_ipaddr = NULL; 1061 char *nfs_client_netmask = NULL; 1062 char *nfs_client_broadcast = NULL; 1063 char *nfs_client_defgw = NULL; 1064 char *nfs_server_ipaddr = NULL; 1065 char *tmp = NULL; 1066 char *command = NULL; 1080 1067 1081 1068 /*@ pointers ***** */ … … 1099 1086 asprintf(&command, 1100 1087 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1101 asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command));1088 nfs_dev = call_program_and_get_last_line_of_output(command); 1102 1089 paranoid_free(command); 1103 1090 1104 1091 asprintf(&command, 1105 1092 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1106 asprintf(&nfs_client_ipaddr, 1107 call_program_and_get_last_line_of_output(command)); 1093 nfs_client_ipaddr = call_program_and_get_last_line_of_output(command); 1108 1094 paranoid_free(command); 1109 1095 1110 1096 asprintf(&command, 1111 1097 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1112 asprintf(&nfs_client_netmask, 1113 call_program_and_get_last_line_of_output(command)); 1098 nfs_client_netmask = call_program_and_get_last_line_of_output(command); 1114 1099 paranoid_free(command); 1115 1100 1116 1101 asprintf(&command, 1117 1102 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1118 strcpy(nfs_client_broadcast, 1119 call_program_and_get_last_line_of_output(command)); 1120 sprintf(command, 1103 nfs_client_broadcast = call_program_and_get_last_line_of_output(command); 1104 paranoid_free(command); 1105 1106 asprintf(&command, 1121 1107 "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1122 asprintf(&nfs_client_defgw, 1123 call_program_and_get_last_line_of_output(command)); 1108 nfs_client_defgw = call_program_and_get_last_line_of_output(command); 1124 1109 paranoid_free(command); 1125 1110 … … 1317 1302 paranoid_free(tmp); 1318 1303 1319 asprintf(&do_not_compress_these, last_line_of_file(tmp));1304 do_not_compress_these = last_line_of_file(tmp); 1320 1305 for (p = do_not_compress_these; p != NULL; p++) { 1321 1306 asprintf(&tmp, p); -
trunk/mondo/mondo/common/libmondo-fork.c
r687 r688 1 /* libmondo-fork.c 2 $Id$ 3 4 - subroutines for handling forking/pthreads/etc. 5 6 7 01/20/2006 8 - replaced partimagehack with ntfsclone 9 10 06/20/2004 11 - create fifo /var/log/partimagehack-debug.log and empty it 12 to keep ramdisk from filling up 13 14 04/13/2004 15 - >= should be <= g_loglevel 16 17 11/15/2003 18 - changed a few []s to char*s 19 20 10/12 21 - rewrote partimagehack handling (multiple fifos, chunks, etc.) 22 23 10/11 24 - partimagehack now has debug level of N (set in my-stuff.h) 25 26 10/08 27 - call to partimagehack when restoring will now log errors to /var/log/....log 28 29 10/06 30 - cleaned up logging a bit 31 32 09/30 33 - line 735 - missing char* cmd in sprintf() 34 35 09/28 36 - added run_external_binary_with_percentage_indicator() 37 - rewritten eval_call_to_make_ISO() 38 39 09/18 40 - call mkstemp instead of mktemp 41 42 09/13 43 - major NTFS hackage 44 45 09/12 46 - paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack 47 48 09/11 49 - forward-ported unbroken feed_*_partimage() subroutines 50 from early August 2003 51 52 09/08 53 - detect & use partimagehack if it exists 54 55 09/05 56 - finally finished partimagehack hack :) 57 58 07/04 59 - added subroutines to wrap around partimagehack 60 61 04/27 62 - don't echo (...res=%d...) at end of log_it() 63 unnecessarily 64 - replace newtFinished() and newtInit() with 65 newtSuspend() and newtResume() 66 67 04/24 68 - added some assert()'s and log_OS_error()'s 69 70 04/09 71 - cleaned up run_program_and_log_output() 72 73 04/07 74 - cleaned up code a bit 75 - let run_program_and_log_output() accept -1 (only log if _no error_) 76 77 01/02/2003 78 - in eval_call_to_make_ISO(), append output to MONDO_LOGFILE 79 instead of a temporary stderr text file 80 81 12/10 82 - patch by Heiko Schlittermann to handle % chars in issue.net 83 84 11/18 85 - if mkisofs in eval_call_to_make_ISO() returns an error then return it, 86 whether ISO was created or not 87 88 10/30 89 - if mkisofs in eval_call_to_make_ISO() returns an error then find out if 90 the output (ISO) file has been created; if it has then return 0 anyway 91 92 08/01 - 09/30 93 - run_program_and_log_output() now takes boolean operator to specify 94 whether it will log its activities in the event of _success_ 95 - system() now includes 2>/dev/null 96 - enlarged some tmp[]'s 97 - added run_program_and_log_to_screen() and run_program_and_log_output() 98 99 07/24 100 - created 101 */ 102 1 /* libmondo-fork.c - subroutines for handling forking/pthreads/etc. 2 * $Id$ 3 */ 103 4 104 5 #include "my-stuff.h" … … 110 11 #include "libmondo-tools-EXT.h" 111 12 112 /*@unused@*/113 //static char cvsid[] = "$Id$";114 115 13 extern char *g_tmpfs_mountpt; 116 14 extern t_bkptype g_backup_media_type; … … 123 21 * @param call The program to run. 124 22 * @return The last line of its output. 125 * @note The returned value points to static storage that will be overwritten with each call.23 * @note The returned value should be freed by caller 126 24 */ 127 25 char *call_program_and_get_last_line_of_output(char *call) 128 26 { 129 /*@ buffers ***************************************************** */ 130 static char *result = NULL; 131 char *tmp = NULL; 132 133 /*@ pointers **************************************************** */ 134 FILE *fin; 135 27 char *result = NULL; 28 FILE *fin = NULL; 136 29 size_t n = 0; 137 30 138 /*@******************************************************************** */139 140 31 assert_string_is_neither_NULL_nor_zerolength(call); 32 141 33 if ((fin = popen(call, "r"))) { 142 for (getline(&tmp, &n, fin); !feof(fin); 143 getline(&tmp, &n, fin)) { 144 if (strlen(tmp) > 1) { 145 if (result != NULL) { 146 paranoid_free(result); 147 } 148 asprintf(&result, tmp); 149 } 150 } 34 for (getline(&result, &n, fin); !feof(fin); getline(&result, &n, fin)); 151 35 paranoid_pclose(fin); 152 36 } else { 153 37 log_OS_error("Unable to popen call"); 154 38 } 155 strip_spaces(result); 156 paranoid_free(tmp); 157 return (result); 39 return(result); 158 40 } 159 41 … … 425 307 if (!(fin = popen(command, "r"))) { 426 308 log_OS_error("Unable to popen-in command"); 427 asprintf(&tmp, _("Failed utterly to call '%s'" , command));309 asprintf(&tmp, _("Failed utterly to call '%s'"), command); 428 310 log_to_screen(tmp); 429 311 paranoid_free(tmp); … … 648 530 { 649 531 650 /*@ int *************************************************************** */651 532 int res = 0; 652 533 int percentage = 0; … … 655 536 int last_pcno = 0; 656 537 657 /*@ buffers *********************************************************** */ 658 char *command; 659 char *tempfile; 660 /*@ pointers ********************************************************** */ 661 FILE *pin; 538 char *command = NULL; 539 char *tempfile = NULL; 540 FILE *pin = NULL; 662 541 663 542 assert_string_is_neither_NULL_nor_zerolength(cmd); 664 543 665 asprintf(&tempfile, 666 call_program_and_get_last_line_of_output 667 ("mktemp -q /tmp/mondo.XXXXXXXX")); 544 tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX"); 668 545 asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile, 669 546 tempfile); -
trunk/mondo/mondo/common/libmondo-mountlist-EXT.h
r59 r688 1 1 /* libmondo-mountlist-EXT.h */ 2 2 3 extern int evaluate_drive_within_mountlist(struct mountlist_itself4 *mountlist, char *drive,5 char *flaws_str);6 3 extern int evaluate_mountlist(struct mountlist_itself *mountlist, 7 4 char *flaws_str_A, char *flaws_str_B, … … 11 8 extern int look_for_duplicate_mountpoints(struct mountlist_itself 12 9 *mountlist, char *flaws_str); 13 extern int look_for_weird_formats(struct mountlist_itself *mountlist,14 char *flaws_str);15 10 extern int make_list_of_drives_in_mountlist(struct mountlist_itself *, 16 11 struct list_of_disks *); -
trunk/mondo/mondo/common/libmondo-mountlist.c
r507 r688 60 60 61 61 /*@ buffers ******************************************************** */ 62 char *tmp; 63 char *device; 62 char *tmp = NULL; 63 char *tmp1 = NULL; 64 char *device = NULL; 64 65 // BERLIOS : useless ? char *mountpoint; 65 66 … … 69 70 70 71 /*@ pointers ******************************************************* */ 71 char *part_table_fmt ;72 char *part_table_fmt = NULL; 72 73 73 74 /*@ initialize ***************************************************** */ 74 flaws_str[0] = '\0';75 75 prev_part_no = 0; 76 76 // BERLIOS: tmp[0] = '\0'; … … 81 81 if (physical_drive_size < 0) { 82 82 asprintf(&tmp, " %s does not exist.", drive); 83 strcat(flaws_str, tmp);83 flaws_str = tmp; 84 84 } else { 85 85 asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); 86 flaws_str = NULL; 86 87 } 87 88 log_it(tmp); … … 108 109 asprintf(&tmp, " Can only have up to 'h' in disklabel."); 109 110 log_it(tmp); 110 strcat(flaws_str, tmp); 111 if (flaws_str) { 112 asprintf(&tmp1, "%s%s",flaws_str, tmp); 113 } else { 114 asprintf(&tmp1, "%s", tmp); 115 } 116 paranoid_free(flaws_str); 117 flaws_str = tmp1; 111 118 paranoid_free(tmp); 112 119 res++; … … 124 131 if (!strstr(flaws_str, tmp)) { 125 132 log_it(tmp); 126 strcat(flaws_str, tmp); 133 if (flaws_str) { 134 asprintf(&tmp1, "%s%s",flaws_str, tmp); 135 } else { 136 asprintf(&tmp1, "%s", tmp); 137 } 138 paranoid_free(flaws_str); 139 flaws_str = tmp1; 127 140 res++; 128 141 } … … 134 147 asprintf(&tmp, " %s is tiny!", device); 135 148 log_it(tmp); 136 strcat(flaws_str, tmp); 149 if (flaws_str) { 150 asprintf(&tmp1, "%s%s",flaws_str, tmp); 151 } else { 152 asprintf(&tmp1, "%s", tmp); 153 } 154 paranoid_free(flaws_str); 155 flaws_str = tmp1; 137 156 paranoid_free(tmp); 138 157 res++; … … 147 166 asprintf(&tmp, " %s has a weird mountpoint.", device); 148 167 log_it(tmp); 149 strcat(flaws_str, tmp); 168 if (flaws_str) { 169 asprintf(&tmp1, "%s%s",flaws_str, tmp); 170 } else { 171 asprintf(&tmp1, "%s", tmp); 172 } 173 paranoid_free(flaws_str); 174 flaws_str = tmp1; 150 175 paranoid_free(tmp); 151 176 res++; … … 155 180 asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 156 181 log_it(tmp); 157 strcat(flaws_str, tmp); 182 if (flaws_str) { 183 asprintf(&tmp1, "%s%s",flaws_str, tmp); 184 } else { 185 asprintf(&tmp1, "%s", tmp); 186 } 187 paranoid_free(flaws_str); 188 flaws_str = tmp1; 158 189 paranoid_free(tmp); 159 190 res++; … … 179 210 180 211 if (((pos >= 0) || npos) && foundsome) { 181 sprintf(flaws_str + strlen(flaws_str), 182 " %s has both DD and PC-style partitions.", drive); 212 asprintf(&tmp, " %s has both DD and PC-style partitions.", drive); 213 if (flaws_str) { 214 asprintf(&tmp1, "%s%s",flaws_str, tmp); 215 } else { 216 asprintf(&tmp1, "%s", tmp); 217 } 218 paranoid_free(flaws_str); 219 flaws_str = tmp1; 220 paranoid_free(tmp); 183 221 return ++res; // fatal error 184 222 } … … 191 229 asprintf(&tmp, " Gap prior to %s.", device); 192 230 log_it(tmp); 193 strcat(flaws_str, tmp); 231 if (flaws_str) { 232 asprintf(&tmp1, "%s%s",flaws_str, tmp); 233 } else { 234 asprintf(&tmp1, "%s", tmp); 235 } 236 paranoid_free(flaws_str); 237 flaws_str = tmp1; 194 238 paranoid_free(tmp); 195 239 res++; … … 199 243 prev_part_no, curr_part_no); 200 244 log_it(tmp); 201 strcat(flaws_str, tmp); 245 if (flaws_str) { 246 asprintf(&tmp1, "%s%s",flaws_str, tmp); 247 } else { 248 asprintf(&tmp1, "%s", tmp); 249 } 250 paranoid_free(flaws_str); 251 flaws_str = tmp1; 202 252 paranoid_free(tmp); 203 253 res++; … … 211 261 asprintf(&tmp, " Partition %ss4 is occupied.", drive); 212 262 log_it(tmp); 213 strcat(flaws_str, tmp); 263 if (flaws_str) { 264 asprintf(&tmp1, "%s%s",flaws_str, tmp); 265 } else { 266 asprintf(&tmp1, "%s", tmp); 267 } 268 paranoid_free(flaws_str); 269 flaws_str = tmp1; 214 270 paranoid_free(tmp); 215 271 res++; … … 227 283 if (!strstr(flaws_str, tmp)) { 228 284 log_it(tmp); 229 strcat(flaws_str, tmp); 285 if (flaws_str) { 286 asprintf(&tmp1, "%s%s",flaws_str, tmp); 287 } else { 288 asprintf(&tmp1, "%s", tmp); 289 } 290 paranoid_free(flaws_str); 291 flaws_str = tmp1; 230 292 res++; 231 293 } … … 237 299 asprintf(&tmp, " %s is tiny!", device); 238 300 log_it(tmp); 239 strcat(flaws_str, tmp); 301 if (flaws_str) { 302 asprintf(&tmp1, "%s%s",flaws_str, tmp); 303 } else { 304 asprintf(&tmp1, "%s", tmp); 305 } 306 paranoid_free(flaws_str); 307 flaws_str = tmp1; 240 308 paranoid_free(tmp); 241 309 res++; … … 250 318 asprintf(&tmp, " %s has a weird mountpoint.", device); 251 319 log_it(tmp); 252 strcat(flaws_str, tmp); 320 if (flaws_str) { 321 asprintf(&tmp1, "%s%s",flaws_str, tmp); 322 } else { 323 asprintf(&tmp1, "%s", tmp); 324 } 325 paranoid_free(flaws_str); 326 flaws_str = tmp1; 253 327 paranoid_free(tmp); 254 328 res++; … … 258 332 asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 259 333 log_it(tmp); 260 strcat(flaws_str, tmp); 334 if (flaws_str) { 335 asprintf(&tmp1, "%s%s",flaws_str, tmp); 336 } else { 337 asprintf(&tmp1, "%s", tmp); 338 } 339 paranoid_free(flaws_str); 340 flaws_str = tmp1; 261 341 paranoid_free(tmp); 262 342 res++; … … 278 358 " Can only have up to 'h' in disklabel."); 279 359 log_it(tmp); 280 strcat(flaws_str, tmp); 360 if (flaws_str) { 361 asprintf(&tmp1, "%s%s",flaws_str, tmp); 362 } else { 363 asprintf(&tmp1, "%s", tmp); 364 } 365 paranoid_free(flaws_str); 366 flaws_str = tmp1; 281 367 paranoid_free(tmp); 282 368 res++; … … 294 380 if (!strstr(flaws_str, tmp)) { 295 381 log_it(tmp); 296 strcat(flaws_str, tmp); 382 if (flaws_str) { 383 asprintf(&tmp1, "%s%s",flaws_str, tmp); 384 } else { 385 asprintf(&tmp1, "%s", tmp); 386 } 387 paranoid_free(flaws_str); 388 flaws_str = tmp1; 297 389 res++; 298 390 } … … 304 396 asprintf(&tmp, " %s is tiny!", device); 305 397 log_it(tmp); 306 strcat(flaws_str, tmp); 398 if (flaws_str) { 399 asprintf(&tmp1, "%s%s",flaws_str, tmp); 400 } else { 401 asprintf(&tmp1, "%s", tmp); 402 } 403 paranoid_free(flaws_str); 404 flaws_str = tmp1; 307 405 paranoid_free(tmp); 308 406 res++; … … 317 415 asprintf(&tmp, " %s has a weird mountpoint.", device); 318 416 log_it(tmp); 319 strcat(flaws_str, tmp); 417 if (flaws_str) { 418 asprintf(&tmp1, "%s%s",flaws_str, tmp); 419 } else { 420 asprintf(&tmp1, "%s", tmp); 421 } 422 paranoid_free(flaws_str); 423 flaws_str = tmp1; 320 424 paranoid_free(tmp); 321 425 res++; … … 326 430 asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 327 431 log_it(tmp); 328 strcat(flaws_str, tmp); 432 if (flaws_str) { 433 asprintf(&tmp1, "%s%s",flaws_str, tmp); 434 } else { 435 asprintf(&tmp1, "%s", tmp); 436 } 437 paranoid_free(flaws_str); 438 flaws_str = tmp1; 329 439 paranoid_free(tmp); 330 440 res++; … … 347 457 amount_allocated - physical_drive_size, drive); 348 458 log_it(tmp); 349 strcat(flaws_str, tmp); 459 if (flaws_str) { 460 asprintf(&tmp1, "%s%s",flaws_str, tmp); 461 } else { 462 asprintf(&tmp1, "%s", tmp); 463 } 464 paranoid_free(flaws_str); 465 flaws_str = tmp1; 350 466 paranoid_free(tmp); 351 467 res++; … … 354 470 physical_drive_size - amount_allocated, drive); 355 471 log_it(tmp); 356 strcat(flaws_str, tmp); 472 if (flaws_str) { 473 asprintf(&tmp1, "%s%s",flaws_str, tmp); 474 } else { 475 asprintf(&tmp1, "%s", tmp); 476 } 477 paranoid_free(flaws_str); 478 flaws_str = tmp1; 357 479 paranoid_free(tmp); 358 480 } … … 391 513 assert_string_is_neither_NULL_nor_zerolength(drive); 392 514 assert(mountlist != NULL); 393 assert(flaws_str != NULL); 394 395 flaws_str[0] = '\0'; 515 flaws_str = NULL; 516 396 517 prev_part_no = 0; 397 518 // BERLIOS : useless ? tmp[0] = '\0'; … … 402 523 if (physical_drive_size < 0) { 403 524 asprintf(&tmp, " %s does not exist.", drive); 404 strcat(flaws_str, tmp); 525 if (flaws_str) { 526 asprintf(&tmp1, "%s%s",flaws_str, tmp); 527 } else { 528 asprintf(&tmp1, "%s", tmp); 529 } 530 paranoid_free(flaws_str); 531 flaws_str = tmp1; 405 532 res++; 406 533 log_msg(1, tmp); … … 421 548 if (physical_drive_size < 0) { 422 549 asprintf(&tmp, " %s refers to non-existent hardware.", device); 423 strcat(flaws_str, tmp); 550 if (flaws_str) { 551 asprintf(&tmp1, "%s%s",flaws_str, tmp); 552 } else { 553 asprintf(&tmp1, "%s", tmp); 554 } 555 paranoid_free(flaws_str); 556 flaws_str = tmp1; 424 557 res++; 425 558 paranoid_free(tmp); … … 432 565 asprintf(&tmp, " Gap prior to %s.", device); 433 566 log_it(tmp); 434 strcat(flaws_str, tmp); 567 if (flaws_str) { 568 asprintf(&tmp1, "%s%s",flaws_str, tmp); 569 } else { 570 asprintf(&tmp1, "%s", tmp); 571 } 572 paranoid_free(flaws_str); 573 flaws_str = tmp1; 435 574 paranoid_free(tmp); 436 575 res++; … … 440 579 prev_part_no, curr_part_no); 441 580 log_it(tmp); 442 strcat(flaws_str, tmp); 581 if (flaws_str) { 582 asprintf(&tmp1, "%s%s",flaws_str, tmp); 583 } else { 584 asprintf(&tmp1, "%s", tmp); 585 } 586 paranoid_free(flaws_str); 587 flaws_str = tmp1; 443 588 paranoid_free(tmp); 444 589 res++; … … 452 597 asprintf(&tmp, " Partition %s4 is occupied.", drive); 453 598 log_it(tmp); 454 strcat(flaws_str, tmp); 599 if (flaws_str) { 600 asprintf(&tmp1, "%s%s",flaws_str, tmp); 601 } else { 602 asprintf(&tmp1, "%s", tmp); 603 } 604 paranoid_free(flaws_str); 605 flaws_str = tmp1; 455 606 paranoid_free(tmp); 456 607 res++; … … 470 621 if (!strstr(flaws_str, tmp)) { 471 622 log_it(tmp); 472 strcat(flaws_str, tmp); 623 if (flaws_str) { 624 asprintf(&tmp1, "%s%s",flaws_str, tmp); 625 } else { 626 asprintf(&tmp1, "%s", tmp); 627 } 628 paranoid_free(flaws_str); 629 flaws_str = tmp1; 473 630 res++; 474 631 } … … 480 637 asprintf(&tmp, " %s is tiny!", device); 481 638 log_it(tmp); 482 strcat(flaws_str, tmp); 639 if (flaws_str) { 640 asprintf(&tmp1, "%s%s",flaws_str, tmp); 641 } else { 642 asprintf(&tmp1, "%s", tmp); 643 } 644 paranoid_free(flaws_str); 645 flaws_str = tmp1; 483 646 paranoid_free(tmp); 484 647 res++; … … 492 655 asprintf(&tmp, " %s has a weird mountpoint.", device); 493 656 log_it(tmp); 494 strcat(flaws_str, tmp); 657 if (flaws_str) { 658 asprintf(&tmp1, "%s%s",flaws_str, tmp); 659 } else { 660 asprintf(&tmp1, "%s", tmp); 661 } 662 paranoid_free(flaws_str); 663 flaws_str = tmp1; 495 664 paranoid_free(tmp); 496 665 res++; … … 500 669 asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 501 670 log_it(tmp); 502 strcat(flaws_str, tmp); 671 if (flaws_str) { 672 asprintf(&tmp1, "%s%s",flaws_str, tmp); 673 } else { 674 asprintf(&tmp1, "%s", tmp); 675 } 676 paranoid_free(flaws_str); 677 flaws_str = tmp1; 503 678 paranoid_free(tmp); 504 679 res++; … … 515 690 amount_allocated - physical_drive_size, drive); 516 691 log_it(tmp); 517 strcat(flaws_str, tmp); 692 if (flaws_str) { 693 asprintf(&tmp1, "%s%s",flaws_str, tmp); 694 } else { 695 asprintf(&tmp1, "%s", tmp); 696 } 697 paranoid_free(flaws_str); 698 flaws_str = tmp1; 518 699 paranoid_free(tmp); 519 700 res++; … … 522 703 physical_drive_size - amount_allocated, drive); 523 704 log_it(tmp); 524 strcat(flaws_str, tmp); 705 if (flaws_str) { 706 asprintf(&tmp1, "%s%s",flaws_str, tmp); 707 } else { 708 asprintf(&tmp1, "%s", tmp); 709 } 710 paranoid_free(flaws_str); 711 flaws_str = tmp1; 525 712 paranoid_free(tmp); 526 713 } … … 582 769 log_it(tmp); 583 770 } else { 584 asprintf(&tmp, " "); 585 // BERLIOS : tmp was NOT initialized ??? 771 // This function allocates tmp 586 772 if (!evaluate_drive_within_mountlist 587 773 (mountlist, drivelist->el[i].device, tmp)) { … … 595 781 } 596 782 res += look_for_duplicate_mountpoints(mountlist, flaws_str); 597 /* res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see598 which formarts are actually _supported_ by the kernel */599 /* log_it(flaws_str); */600 783 return (spread_flaws_across_three_lines 601 784 (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res)); … … 650 833 651 834 /*@ buffetr ********************************************************* */ 652 char *curr_mountpoint; 653 char *tmp; 835 char *curr_mountpoint = NULL; 836 char *tmp = NULL; 837 char *tmp1 = NULL; 654 838 655 839 assert(mountlist != NULL); 656 840 assert(flaws_str != NULL); 841 657 842 for (currline = 0; currline < mountlist->entries; currline++) { 658 843 asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint); … … 670 855 asprintf(&tmp, " %s %s's.", number_to_text(copies), 671 856 curr_mountpoint); 672 strcat(flaws_str, tmp);673 857 log_it(tmp); 858 asprintf(&tmp1, "%s%s",flaws_str, tmp); 859 paranoid_free(flaws_str); 860 flaws_str = tmp1; 674 861 paranoid_free(tmp); 675 862 res++; 676 863 } 677 864 paranoid_free(curr_mountpoint); 678 }679 return (res);680 }681 682 683 /**684 * Look for strange formats. Does not respect /proc/filesystems.685 * @param mountlist The mountlist to check.686 * @param flaws_str The flaws string to append the results to.687 * @return The number of weird formats found, or 0 for success.688 * @bug Seems orphaned; please remove.689 */690 int691 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)692 {693 694 /*@ int ************************************************************* */695 int i = 0;696 int res = 0;697 698 /*@ buffers ********************************************************* */699 char *tmp;700 char *format_sz;701 702 assert(mountlist != NULL);703 assert(flaws_str != NULL);704 705 for (i = 0; i < mountlist->entries; i++) {706 asprintf(&format_sz, " %s ", mountlist->el[i].format);707 if (!strstr(SANE_FORMATS, format_sz)708 && strcmp(mountlist->el[i].mountpoint, "image") != 0) {709 asprintf(&tmp, " %s has unknown format.",710 mountlist->el[i].device);711 log_it(tmp);712 strcat(flaws_str, tmp);713 paranoid_free(tmp);714 res++;715 } else if ((!strcmp(mountlist->el[i].format, "swap")716 && strcmp(mountlist->el[i].mountpoint, "swap")717 && strcmp(mountlist->el[i].mountpoint, "none"))718 || (strcmp(mountlist->el[i].format, "swap")719 && !strcmp(mountlist->el[i].mountpoint, "swap")720 && !strcmp(mountlist->el[i].mountpoint, "none"))) {721 asprintf(&tmp, " %s is half-swap.", mountlist->el[i].device);722 log_it(tmp);723 strcat(flaws_str, tmp);724 paranoid_free(tmp);725 res++;726 }727 paranoid_free(format_sz);728 865 } 729 866 return (res); -
trunk/mondo/mondo/common/libmondo-mountlist.h
r59 r688 4 4 5 5 6 int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,7 char *drive, char *flaws_str);8 6 int evaluate_mountlist(struct mountlist_itself *mountlist, 9 7 char *flaws_str_A, char *flaws_str_B, … … 13 11 int look_for_duplicate_mountpoints(struct mountlist_itself *mountlist, 14 12 char *flaws_str); 15 int look_for_weird_formats(struct mountlist_itself *mountlist,16 char *flaws_str);17 13 int make_list_of_drives_in_mountlist(struct mountlist_itself *, 18 14 struct list_of_disks *); -
trunk/mondo/mondo/common/libmondo-raid.c
r672 r688 774 774 { 775 775 int cnt = 0; 776 staticchar *argv[64];776 char *argv[64]; 777 777 char **ap; 778 char *line = (char *) malloc(MAX_STR_LEN); 779 if (!line) 780 errx(1, 781 "unable to allocate %i bytes of memory for `char *line' at %s:%i", 782 MAX_STR_LEN, __FILE__, __LINE__); 783 (void) fgets(line, MAX_STR_LEN, f); 778 char *line = NULL; 779 size_t = 0; 780 int lastpos = 0; 781 782 getline(&line, &n, f); 784 783 if (feof(f)) { 785 784 log_it("[GNVCL] Uh... I reached the EOF."); 786 return 0;787 } 788 789 for (ap = argv; (*ap = strsep(&line, " \t")) != NULL;)785 return NULL; 786 } 787 788 for (ap = argv; (*ap = mr_strtok(line, " \t", &lastpos)) != NULL;) 790 789 if (**ap != '\0') { 791 790 if (++ap >= &argv[64]) -
trunk/mondo/mondo/common/libmondo-stream.c
r687 r688 9 9 * Functions for writing data to/reading data from streams (tape, CD stream, etc.) 10 10 */ 11 12 #include <unistd.h> 11 13 12 14 #include "my-stuff.h" … … 23 25 #define EXTRA_TAPE_CHECKSUMS 24 26 25 /*@unused@*/26 //static char cvsid[] = "$Id$";27 27 extern bool g_sigpipe; 28 28 extern int g_tape_buffer_size_MB; … … 119 119 } 120 120 sleep(1); 121 paranoid_system("sync");121 sync(); 122 122 sleep(1); 123 123 paranoid_pclose(g_tape_stream); … … 152 152 153 153 sleep(1); 154 paranoid_system("sync");154 sync(); 155 155 sleep(1); 156 156 log_it("closeout_tape() -- entering"); … … 213 213 int find_tape_device_and_size(char *dev, char *siz) 214 214 { 215 char *tmp; 216 char *command; 217 char *cdr_exe; 218 int res; 215 char *tmp = NULL; 216 char *tmp1 = NULL; 217 char *command = NULL; 218 char *cdr_exe = NULL; 219 int res = 0; 219 220 220 221 log_to_screen("I am looking for your tape streamer. Please wait."); 221 dev [0] = '\0';222 dev = NULL; 222 223 siz = NULL; 223 224 if (find_home_of_exe("cdrecord")) { … … 228 229 asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", 229 230 cdr_exe); 230 asprintf(&tmp, call_program_and_get_last_line_of_output(command));231 tmp = call_program_and_get_last_line_of_output(command); 231 232 paranoid_free(command); 232 233 … … 234 235 log_it 235 236 ("Either too few or too many tape streamers for me to detect..."); 236 strcpy(dev, VANILLA_SCSI_TAPE);237 asprintf(&dev, VANILLA_SCSI_TAPE"0"); 237 238 paranoid_free(tmp); 238 239 paranoid_free(cdr_exe); … … 244 245 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", 245 246 cdr_exe); 246 asprintf(&tmp, call_program_and_get_last_line_of_output(command));247 tmp = call_program_and_get_last_line_of_output(command); 247 248 paranoid_free(command); 248 249 if (strlen(tmp) < 2) { … … 259 260 paranoid_free(cdr_exe); 260 261 261 asprintf(&tmp, call_program_and_get_last_line_of_output(command));262 tmp = call_program_and_get_last_line_of_output(command); 262 263 paranoid_free(command); 263 strcpy(dev, VANILLA_SCSI_TAPE); 264 dev[strlen(dev) - 1] = '\0'; 265 strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN' 264 265 asprintf(&dev, VANILLA_SCSI_TAPE"%s", tmp); 266 266 paranoid_free(tmp); 267 267 268 res = 0;269 268 if (!mt_says_tape_exists(dev)) { 270 strcpy(dev, ALT_TAPE); 269 paranoid_free(dev); 270 271 asprintf(&dev, ALT_TAPE"%s", tmp); 271 272 if (!mt_says_tape_exists(dev)) { 272 273 log_it("Cannot openin %s", dev); 273 strcpy(dev, "/dev/st0"); 274 paranoid_free(dev); 275 276 asprintf(&dev, VANILLA_SCSI_TAPE"0"); 274 277 if (!mt_says_tape_exists(dev)) { 275 278 log_it("Cannot openin %s", dev); 276 strcpy(dev, "/dev/osst0"); 279 paranoid_free(dev); 280 281 asprintf(&dev, "/dev/osst0"); 277 282 if (!mt_says_tape_exists(dev)) { 278 283 res++; … … 286 291 log_it("At this point, dev = %s and res = %d", dev, res); 287 292 288 asprintf(&tmp,call_program_and_get_last_line_of_output("\293 tmp = call_program_and_get_last_line_of_output("\ 289 294 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \ 290 295 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \ 291 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'") );296 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"); 292 297 293 298 if (mt_says_tape_exists(dev)) { … … 296 301 log_it("Turning %s", dev); 297 302 paranoid_free(tmp); 298 asprintf(&tmp ,303 asprintf(&tmp1, 299 304 (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev); 300 sprintf(dev, "/dev/os%s", tmp); 305 paranoid_free(dev); 306 asprintf(&dev, "/dev/os%s", tmp1); 307 paranoid_free(tmp1); 308 301 309 log_it("...into %s", dev); 302 310 if (mt_says_tape_exists(dev)) { … … 1228 1236 1229 1237 paranoid_pclose(g_tape_stream); 1230 sy stem("sync");1231 sy stem("sync");1232 sy stem("sync");1238 sync(); 1239 sync(); 1240 sync(); 1233 1241 log_it("Next tape requested."); 1234 1242 insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too … … 1269 1277 1270 1278 paranoid_pclose(g_tape_stream); 1271 sy stem("sync");1272 sy stem("sync");1273 sy stem("sync");1279 sync(); 1280 sync(); 1281 sync(); 1274 1282 log_it("New tape requested."); 1275 1283 insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too -
trunk/mondo/mondo/common/libmondo-string.c
r672 r688 33 33 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno. 34 34 */ 35 char *build_partition_name(c har *partition, const char *drive, int partno)35 char *build_partition_name(const char *drive, int partno) 36 36 { 37 37 char *p, *c; 38 39 assert(partition != NULL); 38 char *partition; 39 40 40 assert_string_is_neither_NULL_nor_zerolength(drive); 41 41 assert(partno >= 0); … … 537 537 538 538 /*@ buffers **************************************************** */ 539 char *output ;540 char *suffix ;539 char *output = NULL; 540 char *suffix = NULL; 541 541 542 542 /*@ end vars *************************************************** */ 543 543 544 544 assert_string_is_neither_NULL_nor_zerolength(path); 545 if (s[0] != '\0') { 545 546 if (s != NULL) { 546 547 asprintf(&suffix, ".%s", s); 547 548 } else { 548 asprintf(&suffix, "%s", " 549 asprintf(&suffix, "%s", ""); 549 550 } 550 551 asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, -
trunk/mondo/mondo/common/libmondo-tools.c
r687 r688 218 218 d = 5.2; // :-) 219 219 #else 220 asprintf(&tmp, call_program_and_get_last_line_of_output("uname -r"));220 tmp = call_program_and_get_last_line_of_output("uname -r"); 221 221 p = strchr(tmp, '.'); 222 222 if (p) { … … 390 390 rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB; 391 391 #ifdef __FreeBSD__ 392 asprintf(&tmp, 393 call_program_and_get_last_line_of_output 394 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6")); 392 tmp = call_program_and_get_last_line_of_output 393 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"); 395 394 avm += atol(tmp); 396 395 paranoid_free(tmp); 397 asprintf(&tmp, 398 call_program_and_get_last_line_of_output 399 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc")); 396 tmp = call_program_and_get_last_line_of_output 397 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"); 400 398 avm += atol(tmp); 401 399 paranoid_free(tmp); … … 403 401 g_tmpfs_mountpt); 404 402 #else 405 asprintf(&tmp, 406 call_program_and_get_last_line_of_output 407 ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1")); 403 tmp = call_program_and_get_last_line_of_output 404 ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"); 408 405 avm += atol(tmp); 409 406 paranoid_free(tmp); … … 478 475 if (getenv ("SUDO_COMMAND")) { 479 476 asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 480 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 477 tmp = call_program_and_get_last_line_of_output(command); 478 if (!strcmp(tmp, "1")) { 481 479 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 482 480 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 483 481 } 482 paranoid_free(tmp); 484 483 paranoid_free(command); 485 484 } … … 574 573 bkpinfo->isodir); 575 574 log_it("command = %s", command); 576 asprintf(&tmp, call_program_and_get_last_line_of_output(command));575 tmp = call_program_and_get_last_line_of_output(command); 577 576 paranoid_free(command); 578 577 log_it("res of it = %s", tmp); … … 585 584 paranoid_free(tmp); 586 585 log_it("command = %s", command); 587 asprintf(&tmp, call_program_and_get_last_line_of_output(command));586 tmp = call_program_and_get_last_line_of_output(command); 588 587 paranoid_free(command); 589 588 log_it("res of it = %s", tmp); … … 704 703 } 705 704 g_current_media_number = 1; 706 bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0'; 705 bkpinfo->postnuke_tarball = NULL; 706 bkpinfo->nfs_mount = NULL; 707 707 return (res); 708 708 } … … 717 717 void reset_bkpinfo(struct s_bkpinfo *bkpinfo) 718 718 { 719 int i ;719 int i = 0; 720 720 721 721 log_msg(1, "Hi"); 722 722 723 assert(bkpinfo != NULL); 724 /* BERLIOS : Useless 723 725 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); 726 */ 727 724 728 bkpinfo->manual_cd_tray = FALSE; 725 729 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 726 paranoid_free(bkpinfo->media_device); 730 bkpinfo->boot_loader = '\0'; 731 727 732 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 728 733 bkpinfo->media_size[i] = -1; 729 734 } 730 bkpinfo->boot_loader = '\0'; 731 bkpinfo->boot_device[0] = '\0'; 732 bkpinfo->zip_exe[0] = '\0'; 733 bkpinfo->zip_suffix[0] = '\0'; 734 bkpinfo->restore_path[0] = '\0'; 735 736 paranoid_free(bkpinfo->media_device); 737 paranoid_free(bkpinfo->boot_device); 738 paranoid_free(bkpinfo->zip_exe); 739 paranoid_free(bkpinfo->zip_suffix); 740 paranoid_free(bkpinfo->restore_path); 735 741 bkpinfo->use_lzo = FALSE; 736 bkpinfo->do_not_compress_these[0] = '\0';742 paranoid_free(bkpinfo->do_not_compress_these); 737 743 bkpinfo->verify_data = FALSE; 738 744 bkpinfo->backup_data = FALSE; … … 741 747 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 742 748 if (bkpinfo->disaster_recovery) { 743 strcpy(bkpinfo->isodir, "/");749 paranoid_alloc(bkpinfo->isodir, "/"); 744 750 } else { 745 strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");746 } 747 strcpy(bkpinfo->prefix, STD_PREFIX);748 749 bkpinfo->scratchdir[0] = '\0';751 paranoid_alloc(bkpinfo->isodir, "/var/cache/mondo/iso"); 752 } 753 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 754 755 paranoid_free(bkpinfo->scratchdir); 750 756 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 751 sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore 757 paranoid_free(bkpinfo->tmpdir); 758 asprintf(&bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore 752 759 bkpinfo->optimal_set_size = 0; 753 760 bkpinfo->backup_media_type = none; 754 strcpy(bkpinfo->include_paths, "/");755 bkpinfo->exclude_paths[0] = '\0';756 bkpinfo->call_before_iso[0] = '\0';757 bkpinfo->call_make_iso[0] = '\0';758 bkpinfo->call_burn_iso[0] = '\0';759 bkpinfo->call_after_iso[0] = '\0';760 bkpinfo->image_devs[0] = '\0';761 bkpinfo->postnuke_tarball[0] = '\0';762 bkpinfo->kernel_path[0] = '\0';763 bkpinfo->nfs_mount[0] = '\0';764 bkpinfo->nfs_remote_dir[0] = '\0';761 paranoid_alloc(bkpinfo->include_paths, "/"); 762 paranoid_free(bkpinfo->exclude_paths); 763 paranoid_free(bkpinfo->call_before_iso); 764 paranoid_free(bkpinfo->call_make_iso); 765 paranoid_free(bkpinfo->call_burn_iso); 766 paranoid_free(bkpinfo->call_after_iso); 767 paranoid_free(bkpinfo->image_devs); 768 paranoid_free(bkpinfo->postnuke_tarball); 769 paranoid_free(bkpinfo->kernel_path); 770 paranoid_free(bkpinfo->nfs_mount); 771 paranoid_free(bkpinfo->nfs_remote_dir); 765 772 bkpinfo->wipe_media_first = FALSE; 766 773 bkpinfo->differential = FALSE; … … 773 780 774 781 775 776 777 782 /** 778 783 * Get the remaining free space (in MB) on @p partition. … … 782 787 long free_space_on_given_partition(char *partition) 783 788 { 784 char *command, *out_sz; 789 char *command = NULL; 790 char *out_sz = NULL; 785 791 long res; 786 792 … … 795 801 asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 796 802 partition); 797 asprintf(&out_sz, call_program_and_get_last_line_of_output(command));803 out_sz = call_program_and_get_last_line_of_output(command); 798 804 paranoid_free(command); 799 805 if (strlen(out_sz) == 0) { … … 840 846 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 841 847 } 842 asprintf(&tmp, 843 call_program_and_get_last_line_of_output 844 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 848 tmp = call_program_and_get_last_line_of_output 849 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"); 845 850 if (atol(tmp) < 35000) { 846 851 retval++; … … 928 933 run_program_and_log_output 929 934 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 930 asprintf(&tmp, 931 call_program_and_get_last_line_of_output 932 ("mount | grep -E \"cdr(om|w)\"")); 935 tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""); 933 936 if (strcmp("", tmp)) { 934 937 if (strstr(tmp, "autofs")) { … … 1021 1024 { 1022 1025 /*@ buffer ****************************************************** */ 1023 char *command ;1024 char *tmp ;1026 char *command = NULL; 1027 char *tmp = NULL; 1025 1028 1026 1029 /*@ end vars *************************************************** */ … … 1028 1031 assert_string_is_neither_NULL_nor_zerolength(config_file); 1029 1032 assert_string_is_neither_NULL_nor_zerolength(label); 1033 1030 1034 if (!does_file_exist(config_file)) { 1031 1035 asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", … … 1033 1037 log_to_screen(tmp); 1034 1038 paranoid_free(tmp); 1035 value [0] = '\0';1039 value = NULL; 1036 1040 return (1); 1037 1041 } else if (strstr(value, "/dev/") && strstr(value, "t0") … … 1043 1047 asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", 1044 1048 label, config_file); 1045 strcpy(value, call_program_and_get_last_line_of_output(command));1049 value = call_program_and_get_last_line_of_output(command); 1046 1050 paranoid_free(command); 1047 1051 if (strlen(value) == 0) { … … 1052 1056 } 1053 1057 } 1054 1055 1058 1056 1059 … … 1101 1104 "grep -v \":\" /etc/fstab | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1102 1105 log_msg(4, "Cool. Command = '%s'", command); 1103 asprintf(&tmp, call_program_and_get_last_line_of_output(command));1106 tmp = call_program_and_get_last_line_of_output(command); 1104 1107 paranoid_free(command); 1105 1108 1106 1109 log_msg(4, "tmp = '%s'", tmp); 1107 if (tmp [0]) {1110 if (tmp) { 1108 1111 log_it("/boot is at %s according to /etc/fstab", tmp); 1109 1112 if (strstr(tmp, "LABEL=")) { … … 1199 1202 return (1); 1200 1203 } 1201 asprintf(&tempfile, 1202 call_program_and_get_last_line_of_output 1203 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX")); 1204 tempfile = call_program_and_get_last_line_of_output 1205 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"); 1204 1206 if (does_file_exist(config_file)) { 1205 1207 asprintf(&command, "grep -vx '%s .*' %s > %s", … … 1228 1230 if (mal) { 1229 1231 iamhere("Malloc'ing globals"); 1230 malloc_string(g_erase_tmpdir_and_scratchdir);1232 g_erase_tmpdir_and_scratchdir = NULL; 1231 1233 malloc_string(g_serial_string); 1232 malloc_string(g_magicdev_command);1233 1234 } else { 1234 1235 iamhere("Freeing globals"); … … 1268 1269 void stop_magicdev_if_necessary() 1269 1270 { 1270 strcpy(g_magicdev_command, 1271 call_program_and_get_last_line_of_output 1272 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1273 if (g_magicdev_command[0]) { 1271 g_magicdev_command = call_program_and_get_last_line_of_output 1272 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"); 1273 if (g_magicdev_command) { 1274 1274 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command); 1275 1275 paranoid_system("killall magicdev"); … … 1283 1283 void restart_magicdev_if_necessary() 1284 1284 { 1285 char *tmp ;1286 1287 if ( g_magicdev_command && g_magicdev_command[0]) {1285 char *tmp = NULL; 1286 1287 if (!g_magicdev_command) { 1288 1288 asprintf(&tmp, "%s &", g_magicdev_command); 1289 1289 paranoid_system(tmp); -
trunk/mondo/mondo/common/libmondo-verify.c
r507 r688 5 5 * Functions for verifying backups (booted from hard drive, not CD). 6 6 */ 7 8 #include <unistd.h> 7 9 8 10 #include "my-stuff.h" … … 59 61 60 62 asprintf(&afio_found_changes, "%s.afio", ignorefiles_fname); 61 paranoid_system("sync");63 sync(); 62 64 63 65 /* sprintf (command, … … 193 195 { 194 196 195 /*@ buffer ********************************************************** */196 char *tmp ;197 char * mountpoint;198 // char ca, cb;199 char *command ;200 char *sz_exe ;197 char *tmp = NULL; 198 char *tmp1 = NULL; 199 char *tmp2 = NULL; 200 char *mountpoint = NULL; 201 char *command = NULL; 202 char *sz_exe = NULL; 201 203 static char *bufblkA = NULL; 202 204 static char *bufblkB = NULL; 203 205 const long maxbufsize = 65536L; 204 long currsizA = 0; 205 long currsizB = 0; 206 long j; 207 208 /*@ long ************************************************************ */ 209 long bigfile_num = 0; 206 long currsizA = 0L; 207 long currsizB = 0L; 208 long j = 0L; 209 long bigfile_num = 0L; 210 210 long slice_num = -1; 211 int res ;211 int res = 0; 212 212 213 213 static FILE *forig = NULL; … … 215 215 static long last_bigfile_num = -1; 216 216 static long last_slice_num = -1; 217 FILE *pin ;218 FILE *fin ;217 FILE *pin = NULL; 218 FILE *fin = NULL; 219 219 int retval = 0; 220 // long long outlen; 221 222 malloc_string(sz_exe); 220 223 221 if (!bufblkA) { 224 222 if (!(bufblkA = malloc(maxbufsize))) { … … 251 249 open_evalcall_form(tmp); 252 250 paranoid_free(tmp); 251 253 252 iamhere("after vsbf"); 254 253 asprintf(&mountpoint, "%s/archives", mtpt); … … 263 262 slice_num = last_slice_num + 1; 264 263 } 265 while (does_file_exist 266 (slice_fname 267 (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix)) 268 || 269 does_file_exist(slice_fname 270 (bigfile_num, slice_num, mountpoint, ""))) { 271 // handle slices until end of CD 264 265 tmp = slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix); 266 tmp1 = slice_fname(bigfile_num, slice_num, mountpoint, ""); 267 while (does_file_exist(tmp) || does_file_exist(tmp1)) { 268 // handle slices until end of CD 272 269 if (slice_num == 0) { 273 270 log_msg(2, "ISO=%d bigfile=%ld --START--", 274 271 g_current_media_number, bigfile_num); 275 if (! 276 (fin = 277 fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""), 278 "r"))) { 272 if (!(fin = fopen(tmp1,"r"))) { 279 273 log_msg(2, "Cannot open bigfile's info file"); 280 274 } else { … … 286 280 paranoid_fclose(fin); 287 281 } 288 asprintf(&tmp , "%s/%s", bkpinfo->restore_path,282 asprintf(&tmp2, "%s/%s", bkpinfo->restore_path, 289 283 biggiestruct.filename); 290 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp );291 if (!(forig = fopen(tmp , "r"))) {284 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp2); 285 if (!(forig = fopen(tmp2, "r"))) { 292 286 log_msg(2, "Failed to open bigfile. Darn."); 293 287 retval++; 294 288 } 295 paranoid_free(tmp );289 paranoid_free(tmp2); 296 290 297 291 slice_num++; 298 } else if (does_file_exist 299 (slice_fname(bigfile_num, slice_num, mountpoint, ""))) { 292 } else if (does_file_exist(tmp1)) { 300 293 log_msg(2, "ISO=%d bigfile=%ld ---END---", 301 294 g_current_media_number, bigfile_num); … … 307 300 g_current_media_number, bigfile_num, slice_num); 308 301 if (bkpinfo->compression_level > 0) { 309 asprintf(&command, "%s -dc %s 2>> %s", sz_exe, 310 slice_fname(bigfile_num, slice_num, mountpoint, 311 bkpinfo->zip_suffix), 312 MONDO_LOGFILE); 302 asprintf(&command, "%s -dc %s 2>> %s", sz_exe, tmp, MONDO_LOGFILE); 313 303 } else { 314 asprintf(&command, "cat %s", 315 slice_fname(bigfile_num, slice_num, mountpoint, 316 bkpinfo->zip_suffix)); 304 asprintf(&command, "cat %s", tmp); 317 305 } 318 306 if ((pin = popen(command, "r"))) { … … 356 344 } 357 345 } 346 paranoid_free(tmp); 347 paranoid_free(tmp1); 358 348 paranoid_free(mountpoint); 359 349 paranoid_free(sz_exe); … … 1072 1062 1073 1063 /* find the final blocks */ 1074 paranoid_system("sync");1064 sync(); 1075 1065 sleep(2); 1076 1066 closein_tape(bkpinfo); -
trunk/mondo/mondo/common/libmondo-verify.h
r687 r688 42 42 extern int openin_tape(struct s_bkpinfo *); 43 43 extern void popup_and_OK(char *); 44 extern bool popup_and_get_string(char *, char *, char * , int);44 extern bool popup_and_get_string(char *, char *, char *); 45 45 extern int read_file_from_tape_to_file(struct s_bkpinfo *, char *, 46 46 long long); … … 83 83 extern long g_start_time, g_minimum_progress, g_maximum_progress, 84 84 g_current_progress, g_currentY; 85 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];86 85 extern int g_current_media_number; 87 86 -
trunk/mondo/mondo/common/my-stuff.h
r687 r688 145 145 146 146 #define SCREEN_LENGTH 25 ///< The default size of the screen. 147 #define NOOF_ERR_LINES 6 ///< The number of lines of log output to keep at the bottom of the screen.148 147 #define ARBITRARY_MAXIMUM 2000 ///< The maximum number of items showing at once in the mountlist or filelist editor. 149 148 #define MAX_TAPECATALOG_ENTRIES 8192 ///< The maximum number of entries in the tape catalog. … … 335 334 336 335 /** @def VANILLA_SCSI_CDROM The first SCSI CD-ROM in the system (most likely to be the one to write to). */ 337 /** @def VANILLA_SCSI_TAPE The first SCSI tape in the system (most likely to be the one towrite to. */336 /** @def VANILLA_SCSI_TAPE The SCSI tape radical on the system (most likely to be the one towrite to. */ 338 337 /** @def DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE A string whose presence in a device name indicates the 339 338 * inability to check this device for errors in the mountlist. */ … … 345 344 #ifdef __FreeBSD__ 346 345 #define VANILLA_SCSI_CDROM "/dev/cd0" 347 #define VANILLA_SCSI_TAPE "/dev/sa 0"346 #define VANILLA_SCSI_TAPE "/dev/sa" 348 347 #define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE "/dev/vinum/" 349 348 #define RAID_DEVICE_STUB DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE 350 349 #define SANE_FORMATS "swap image msdosfs nfs ntfs raid lvm ffs ufs ext2fs" 351 #define ALT_TAPE "/dev/ast 0"350 #define ALT_TAPE "/dev/ast" 352 351 #define MKE2FS_OR_NEWFS "newfs" 353 352 #define CP_BIN "gcp" 354 353 #else 355 354 #define VANILLA_SCSI_CDROM "/dev/scd0" 356 #define VANILLA_SCSI_TAPE "/dev/st 0"355 #define VANILLA_SCSI_TAPE "/dev/st" 357 356 #define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE "/dev/md" 358 357 #define RAID_DEVICE_STUB DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE 359 358 #define SANE_FORMATS "swap image vfat ext2 ext3 xfs vfs jfs reiserfs dos minix coda nfs ntfs hpfs raid lvm cifs" 360 #define ALT_TAPE "/dev/ht 0"359 #define ALT_TAPE "/dev/ht" 361 360 #define MKE2FS_OR_NEWFS "mke2fs" 362 361 #define CP_BIN "cp" -
trunk/mondo/mondo/common/newt-specific-EXT.h
r59 r688 15 15 extern void log_to_screen(const char *fmt, ...); 16 16 extern void popup_and_OK(char *prompt); 17 extern bool popup_and_get_string(char *title, char *b, char *output, 18 int maxsize); 17 extern bool popup_and_get_string(char *title, char *b, char *output); 19 18 extern bool popup_with_buttons(char *p, char *button1, char *button2); 20 19 extern void refresh_log_screen(); -
trunk/mondo/mondo/common/newt-specific.c
r588 r688 13 13 #define MAX_NEWT_COMMENT_LEN 200 14 14 15 #if __cplusplus 16 extern "C" { 17 #endif 15 #include <unistd.h> 18 16 19 17 #include "my-stuff.h" … … 111 109 if (g_text_mode) { 112 110 while (1) { 113 sy stem("sync");111 sync(); 114 112 printf 115 113 ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ", … … 130 128 return (FALSE); 131 129 } else { 132 sy stem("sync");130 sync(); 133 131 printf 134 132 (_("Please enter either YES or NO (or yes or no, or y or n, or...)\n")); … … 156 154 assert_string_is_neither_NULL_nor_zerolength(prompt); 157 155 if (g_text_mode) { 158 sy stem("sync");156 sync(); 159 157 printf 160 158 ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ", … … 279 277 paranoid_system("killall mindi 2> /dev/null"); 280 278 kill_anything_like_this("/mondo/do-not"); 281 kill_anything_like_this(" tmp.mondo");279 kill_anything_like_this("mondo.tmp"); 282 280 kill_anything_like_this("ntfsclone"); 283 281 sync(); … … 291 289 paranoid_free(tmp); 292 290 293 if (g_erase_tmpdir_and_scratchdir [0]) {291 if (g_erase_tmpdir_and_scratchdir) { 294 292 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5); 295 293 } … … 339 337 void 340 338 finish(int signal) { 341 char *command; 342 malloc_string(command); 339 char *command = NULL; 343 340 344 341 /* if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */ … … 349 346 chdir("/"); 350 347 run_program_and_log_output("umount " MNT_CDROM, FALSE); 351 run_program_and_log_output("rm -Rf /mondo.scratch.* / tmp.mondo.*",348 run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*", 352 349 FALSE); 353 350 if (g_erase_tmpdir_and_scratchdir) { … … 394 391 395 392 /*@ buffers ********************************************************** */ 396 char *command ;397 char *tmp ;393 char *command = NULL; 394 char *tmp = NULL; 398 395 399 396 /*@ pointers ********************************************************* */ 400 FILE *fin ;397 FILE *fin = NULL; 401 398 402 399 /*@ int ************************************************************** */ 403 400 int i = 0; 401 size_t n = 0; 404 402 405 403 assert_string_is_neither_NULL_nor_zerolength(filename); … … 420 418 } else { 421 419 for (i = 0; i < g_noof_log_lines; i++) { 422 for (err_log_lines[i][0] = '\0'; 423 strlen(err_log_lines[i]) < 2 && !feof(fin);) { 424 (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN, 425 fin); 420 for (; 421 strlen(err_log_lines[i]) < 2 && !feof(fin);) { 422 getline(&(err_log_lines[i]), &n, fin); 426 423 strip_spaces(err_log_lines[i]); 427 424 if (!strncmp(err_log_lines[i], "root:", 5)) { 428 425 asprintf(&tmp, "%s", err_log_lines[i] + 6); 429 strcpy(err_log_lines[i], tmp);430 paranoid_free(tmp);426 paranoid_free(err_log_lines[i]); 427 err_log_lines[i] = tmp; 431 428 } 432 429 if (feof(fin)) { … … 456 453 457 454 /*@ buffers ********************************************************** */ 458 char *output ;455 char *output = NULL; 459 456 460 457 … … 472 469 473 470 if (err_log_lines) { 471 paranoid_free(&err_log_lines[0]); 474 472 for (i = 1; i < g_noof_log_lines; i++) { 475 strcpy(err_log_lines[i - 1], 476 " "); 477 strcpy(err_log_lines[i - 1], err_log_lines[i]); 473 err_log_lines[i - 1] = err_log_lines[i]; 478 474 } 479 475 } … … 487 483 } 488 484 if (err_log_lines) 489 strcpy(err_log_lines[g_noof_log_lines - 1], output);485 err_log_lines[g_noof_log_lines - 1] = output; 490 486 if (g_text_mode) { 491 487 printf("%s\n", output); … … 493 489 refresh_log_screen(); 494 490 } 495 paranoid_free(output); 496 } 497 498 491 } 499 492 500 493 … … 670 663 * @param b The blurb (e.g. what you want the user to enter). 671 664 * @param output The string to put the user's answer in. It has to be freed by the caller 672 * @param maxsize The size in bytes allocated to @p output.673 665 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. 674 666 */ 675 bool popup_and_get_string(char *title, char *b, char *output, 676 int maxsize) { 667 bool popup_and_get_string(char *title, char *b, char *output) { 677 668 678 669 /*@ newt ************************************************************ */ … … 685 676 686 677 /*@ pointers ********************************************************* */ 687 char *entry_value ;678 char *entry_value = NULL; 688 679 689 680 /*@ buffers ********************************************************** */ 690 char *blurb; 691 char *original_contents; 681 char *blurb = NULL; 692 682 size_t n = 0; 683 bool ret = TRUE; 693 684 694 685 assert_string_is_neither_NULL_nor_zerolength(title); … … 699 690 ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", 700 691 title, b); 692 paranoid_free(output); 701 693 (void) getline(&output, &n, stdin); 702 694 if (output[strlen(output) - 1] == '\n') 703 695 output[strlen(output) - 1] = '\0'; 704 return ( TRUE);696 return (ret); 705 697 } 706 698 asprintf(&blurb, b); 707 699 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 708 original_contents = output;709 700 710 701 type_here = 711 702 newtEntry(2, newtTextboxGetNumLines(text) + 2, 712 original_contents, 50, 713 #ifdef __cplusplus 714 0, NEWT_FLAG_RETURNEXIT 715 #else 716 (void *) &entry_value, NEWT_FLAG_RETURNEXIT 717 #endif 703 output, 50, 704 &entry_value, NEWT_FLAG_RETURNEXIT 718 705 ); 719 706 b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _(" OK ")); 720 707 b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel")); 721 // newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);722 708 newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title); 723 709 myForm = newtForm(NULL, NULL, 0); … … 727 713 newtPushHelpLine(blurb); 728 714 paranoid_free(blurb); 715 729 716 b_res = newtRunForm(myForm); 730 output = entry_value;731 717 newtPopHelpLine(); 718 if (b_res == b_2) { 719 ret = FALSE; 720 } else { 721 // Copy entry_value before destroying the form 722 // clearing potentially output before 723 paranoid_alloc(output,entry_value); 724 } 732 725 newtFormDestroy(myForm); 733 726 newtPopWindow(); 734 if (b_res == b_2) { 735 paranoid_free(output); 736 output = original_contents; 737 paranoid_free(original_contents); 738 return (FALSE); 739 } else { 740 paranoid_free(original_contents); 741 return (TRUE); 742 } 727 return(ret); 743 728 } 744 729 … … 846 831 newtRefresh(); 847 832 for (i = g_noof_log_lines - 1; i >= 0; i--) { 848 err_log_lines[i][79] = '\0';833 //BERLIOS : removed for now, Think it's useless : err_log_lines[i][79] = '\0'; 849 834 newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines, 850 835 err_log_lines[i]); … … 884 869 885 870 for (i = 0; i < g_noof_log_lines; i++) { 886 err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN); 887 if (!err_log_lines[i]) { 888 fatal_error("Out of memory"); 889 } 890 } 891 892 for (i = 0; i < g_noof_log_lines; i++) { 893 err_log_lines[i][0] = '\0'; 871 err_log_lines[i] = NULL; 894 872 } 895 873 } … … 1575 1553 1576 1554 1577 #if __cplusplus1578 } /* extern "C" */1579 #endif1580 1581 1582 1555 void wait_until_software_raids_are_prepped(char *mdstat_file, 1583 1556 int wait_for_percentage); -
trunk/mondo/mondo/common/newt-specific.h
r59 r688 21 21 long max_val); 22 22 void popup_and_OK(char *prompt); 23 bool popup_and_get_string(char *title, char *b, char *output , int maxsize);23 bool popup_and_get_string(char *title, char *b, char *output); 24 24 bool popup_with_buttons(char *p, char *button1, char *button2); 25 25 void refresh_log_screen(); -
trunk/mondo/mondo/mondoarchive/main.c
r539 r688 88 88 } 89 89 90 91 extern char *g_magicdev_command;92 90 93 91 /** … … 199 197 distro_specific_kludges_at_start_of_mondoarchive(); 200 198 // BERLIOS : too early, bkpinfo is not initialized ?? 201 //s printf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);199 //s-printf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 202 200 g_kernel_version = get_kernel_version(); 203 201 … … 396 394 paranoid_free(tmp); 397 395 398 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,396 asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 399 397 bkpinfo->scratchdir); 400 398 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE); … … 403 401 404 402 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 405 system("rm -Rf / tmp.mondo.* /mondo.scratch.*");403 system("rm -Rf /mondo.tmp* /mondo.scratch.*"); 406 404 if (retval == 0) { 407 405 printf(_("Mondoarchive ran OK.\n")); -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r687 r688 14 14 #include <pthread.h> 15 15 #endif 16 17 //static char cvsid[] = "$Id$";18 16 19 17 extern int g_loglevel; … … 119 117 } 120 118 // } 121 asprintf(&tmp, "rm -Rf %s/ tmp.mondo.*", bkpinfo->tmpdir);119 asprintf(&tmp, "rm -Rf %s/mondo.tmp.*", bkpinfo->tmpdir); 122 120 paranoid_system(tmp); 123 121 paranoid_free(tmp); … … 127 125 paranoid_free(tmp); 128 126 129 sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", 127 /* BERLIOS : Useless ??? 128 s-printf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/mondo.tmp.%ld", 130 129 random() % 32767); 131 s printf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),130 s-printf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), 132 131 "/mondo.scratch.%ld", random() % 32767); 132 */ 133 133 134 134 asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); … … 211 211 /*@ ints *** */ 212 212 int i = 0; 213 int j = 0; 213 214 int retval = 0; 214 215 int percent = 0; … … 216 217 /*@ buffers ** */ 217 218 char *tmp; 218 char *tmp2;219 219 char *tmp1; 220 220 char *psz; … … 495 495 asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 496 496 bkpinfo->nfs_mount); 497 asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp)); 498 bkpinfo->isodir = tmp2; 497 bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp); 499 498 paranoid_free(tmp); 500 499 … … 683 682 if (popup_and_get_string 684 683 (_("Device"), _("Please specify the device"), 685 bkpinfo->media_device , MAX_STR_LEN / 4)) {684 bkpinfo->media_device)) { 686 685 retval++; 687 686 log_to_screen(_("User opted to cancel.")); … … 711 710 } /* not '\0' but '0' */ 712 711 } 712 j = (int) random() % 32768; 713 713 if (flag_set['S']) { 714 asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'], 715 random() % 32768);714 asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'], j); 715 paranoid_free(bkpinfo->scratchdir); 716 716 bkpinfo->scratchdir = tmp; 717 717 } 718 718 if (flag_set['T']) { 719 asprintf(&tmp, "%s/ tmp.mondo.%ld", flag_val['T'],720 random() % 32768);719 asprintf(&tmp, "%s/mondo.tmp.%ld", flag_val['T'], j); 720 paranoid_free(bkpinfo->tmpdir); 721 721 bkpinfo->tmpdir = tmp; 722 722 asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']); … … 766 766 (BOOT_LOADER_CHARS, 767 767 (bkpinfo->boot_loader = flag_val['l'][0]))) { 768 log_msg(1, "%c? W TFis %c? I need G, L, E or R.",768 log_msg(1, "%c? What is %c? I need G, L, E or R.", 769 769 bkpinfo->boot_loader, bkpinfo->boot_loader); 770 770 fatal_error -
trunk/mondo/mondo/mondorestore/mondo-prep.c
r687 r688 1 1 /*************************************************************************** 2 mondo-prep.c - description 3 ----------------- 4 5 begin: Fri Apr 19 16:40:35 EDT 2002 6 copyright : (C) 2002 Mondo Hugo Rabson 7 email : Hugo Rabson <hugorabson@msn.com> 8 edited by : by Stan Benoit 4/2002 9 email : troff@nakedsoul.org 10 cvsid : $Id$ 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 22 /* mondo-prep.c Hugo Rabson 23 24 25 26 07/20 27 - when starting RAID, don't do it twice :) 28 - moved Joshua's new get_phys_size_of_drive() code 29 from resize_drive... into get_phys_size_of_drive() 30 31 06/29 32 - make sure software RAID devices are formatted IF user says they're to be 33 - drivelist is struct now, not char[][] 34 35 06/26 36 - drop make_relevant_partition_bootable(); do it yourself in C (mostly) 37 - offer to reboot if partition table is locked up by the kernel 38 39 06/22 40 - be sure not to resize non-NTFS images when restoring 41 - set non-NTFS images' partition types properly 42 43 06/19 44 - shut down all LVMs and VGs before prepping 45 46 05/07 47 - usage of parted2fdisk instead of fdisk alone (ia32/ia64 compatibility) 48 BCO 49 50 03/31 51 - rewrote partitioning and formatting code to call fdisk once per disk 52 53 10/21/2003 54 - suspend/resume Newt gui before/after calling do_my_funky_lvm_stuff() 55 56 10/20 57 - rewrote format_everything() - what a mess it was. 58 It now does things in three phases:- 59 - formats software RAID devices (/dev/md0, etc.) 60 - formats and configures LVM devices 61 - formats regular partitions (/dev/hda1, /dev/sdb2, etc.) 62 and any LVMs recently prepped 63 64 10/07 65 - use strstr(format, "raid") instead of strcmp(format,"raid") to determin 66 if partition is a RAID component 67 68 09/23 69 - better comments 70 71 09/18 72 - better logging of RAID activity 73 74 05/05 75 - added Joshua Oreman's FreeBSD patches 76 77 04/30 78 - added textonly mode 79 80 04/24 81 - added lots of assert()'s and log_OS_error()'s 82 83 04/21 84 - format_everything() --- don't let bar go too far 85 - mkfs -c to check for bad blocks when formatting 86 87 04/04 88 - misc clean-up (Tom Mortell) 89 90 01/15/2003 91 - added code for LVM and SW Raid (Brian Borgeson) 92 93 12/10/2002 94 - line 1238: friendlier output 95 96 11/20 97 - when wiping a given device in preparation for partitioning + formatting 98 it, don't wipe the MBR; just the partition table. That allows for 99 stupid-ass Compaq users who like to play with their MBR's. 100 - disable mountlist.txt-->mountlist.txt.pre-resize copying (superfluous) 101 102 09/09 103 - run_program_and_log_output() now takes boolean operator to specify 104 whether it will log its activities in the event of _success_ 105 106 07/01 - 07/31 107 - added hooks to libmondo 108 - RAID enhancements (Philippe de Muyter) 109 110 01/01 - 03/31 111 - partition_device() will refuse to partition /dev/mdX now (cos it's a 112 virtual drive); however, it will return 0 (i.e. not an error) 113 - make_list_of_drives() will exclude /dev/md* from list 114 - mkreiserfs -ff instead of -q (Andy Glass) 115 - don't resize drive if drive not found (or if its size cannot be det'd) 116 - when generating list of drives from mountlist, skip the 'p' at the end 117 of drive name if /dev/ida/ or /dev/cciss/; just do it (Michael Eisenberg) 118 - don't specify journal size when formatting ext3 119 (used to have -Jsize=10 in the call to mkfs) 120 - handles files >2GB in size 121 - format interactively, if Interactive Mode 122 - removed reference to g_tape_size 123 - when executing /tmp/i-want-my-lvm, only record the error# if the command 124 was _not_ an 'insmod' command 125 - pass partition size to fdisk in Kilobytes now, not Megabytes 126 - log fdisk's output to /tmp/mondo-restore.log if it fails 127 - don't try to format partitions of type 'image' 128 - don't type to set types of 'image' partitions 129 - if format code is 1 or 2 chars then assume it is a hex string 130 - took out all '/ /' comments 131 - don't extrapolate/add partition from RAID dev to mountlist if it's already 132 present in mountlist 133 - less repetitive logging in the event of vacuum-packing of last part'n 134 - no extrapolation at all: RAID partitions should be listed in mountlist 135 already, thanks to either Mindi v0.5x or the mountlist editor itself 136 - no longer say, 'and logging to...' when setting a partition's type 137 - don't run mkfs on RAID partitions (/dev/hd*, /dev/sd*); just set type 138 - the setting of a partition's type now takes place in a separate subroutine 139 from the subroutine that actually creates the partition 140 - no need to set type if 83: 83 is the default (under fdisk) 141 - turned on '-Wall'; cleaned up some cruft 142 - if vacuum-packing partition (i.e. size=0MB --> max) then say, "(maximum)" 143 not, "(0 MB)" 144 145 11/22/2001 146 - preliminary code review 147 - created on Nov 22nd, 2001 148 */ 2 * $Id 3 **/ 149 4 150 5 /** … … 159 14 #include "../common/libmondo.h" 160 15 #include "mondo-rstr-tools-EXT.h" 16 161 17 #include <sys/ioctl.h> 162 18 #include <linux/hdreg.h> 163 19 #include <math.h> 20 #include <unistd.h> 164 21 165 22 … … 185 42 extern char *g_mountlist_fname; 186 43 extern long g_current_progress, g_maximum_progress; 187 188 44 extern bool g_text_mode; 189 190 45 extern void pause_for_N_seconds(int, char *); 191 46 192 193 47 FILE *g_fprep = NULL; 194 195 196 197 48 int g_partition_table_locked_up = 0; 198 199 200 201 202 203 204 205 206 49 207 50 … … 209 52 { 210 53 char *command; 211 char *tmp;212 54 int lino; 213 55 int i; … … 218 60 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 219 61 // then zero & insist on reboot. 220 malloc_string(command);221 malloc_string(tmp);222 62 buf = malloc(blocksize); 223 63 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) … … 226 66 make_list_of_drives_in_mountlist(mountlist, drivelist); 227 67 for (lino = 0; lino < drivelist->entries; lino++) { 228 sprintf(command,229 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",230 drivelist->el[lino].device, MONDO_WAS_HERE);68 asprintf(&command, 69 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 70 drivelist->el[lino].device, MONDO_WAS_HERE); 231 71 if (!run_program_and_log_output(command, 1)) { 232 72 log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", 233 73 lino, drivelist->el[lino].device); 74 paranoid_free(command); 234 75 break; 235 76 } 77 paranoid_free(command); 236 78 } 237 79 … … 239 81 // zero & reboot 240 82 log_to_screen 241 (_("I am sorry for the inconvenience but I must ask you to reboot.")); 242 log_to_screen 243 (_("I need to reset the Master Boot Record; in order to be")); 244 log_to_screen 245 (_("sure the kernel notices, I must reboot after doing it.")); 83 (_ 84 ("I am sorry for the inconvenience but I must ask you to reboot.")); 85 log_to_screen(_ 86 ("I need to reset the Master Boot Record; in order to be")); 87 log_to_screen(_ 88 ("sure the kernel notices, I must reboot after doing it.")); 246 89 log_to_screen("Please hit 'Enter' to reboot."); 247 90 for (lino = 0; lino < drivelist->entries; lino++) { … … 265 108 } 266 109 } 267 sy stem("sync");268 sy stem("sync");269 sy stem("sync");110 sync(); 111 sync(); 112 sync(); 270 113 popup_and_OK 271 (_("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.")); 114 (_ 115 ("I must reboot now. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.")); 272 116 system("reboot"); 273 117 } 274 118 } 275 119 // Still here? Cool! 276 paranoid_free(command);277 paranoid_free(tmp);278 120 log_msg(1, "Cool. I didn't have to wipe anything."); 279 121 } 280 281 282 283 284 122 285 123 … … 311 149 return (i); 312 150 } 313 314 315 316 317 318 319 320 321 151 322 152 … … 330 160 * @return The number of errors encountered (0 for success). 331 161 */ 332 333 334 162 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, 335 163 bool vacuum_pack) 336 164 { 337 /** buffers **********************************************/338 char *tmp;339 char *incoming;340 char *command;341 char *lvscan_sz;342 char *lvremove_sz;343 char *pvscan_sz;344 char *vgscan_sz;345 char *vgcreate_sz;346 char *vgchange_sz;347 char *vgremove_sz;348 // char *do_this_last;349 350 165 /** char **************************************************/ 351 char *p; 352 char *q; 166 char *tmp = NULL; 167 char *tmp1 = NULL; 168 char *incoming = NULL; 169 char *command = NULL; 170 char *lvscan_sz = NULL; 171 char *lvremove_sz = NULL; 172 char *pvscan_sz = NULL; 173 char *vgscan_sz = NULL; 174 char *vgchange_sz = NULL; 175 char *vgremove_sz = NULL; 176 char *p = NULL; 177 char *q = NULL; 353 178 354 179 /** int ***************************************************/ 355 180 int retval = 0; 356 181 int res = 0; 357 int i ;182 int i = 0; 358 183 int lvmversion = 1; 359 184 long extents; 360 185 fpos_t orig_pos; 186 size_t n = 0; 187 size_t n1 = 0; 361 188 362 189 /** pointers **********************************************/ … … 374 201 } 375 202 376 malloc_string(tmp);377 malloc_string(incoming);378 malloc_string(lvscan_sz);379 malloc_string(lvremove_sz);380 malloc_string(vgscan_sz);381 malloc_string(pvscan_sz);382 malloc_string(vgcreate_sz);383 malloc_string(vgchange_sz);384 malloc_string(vgremove_sz);385 // malloc_string(do_this_last); // postpone lvcreate call if necessary386 command = malloc(512);387 388 // do_this_last[0] = '\0';389 203 iamhere("STARTING"); 390 204 log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes..."); 391 205 if (find_home_of_exe("lvm")) // found it :) cool 392 206 { 393 strcpy(lvscan_sz, "lvm lvscan"); 394 strcpy(lvremove_sz, "lvm lvremove"); 395 strcpy(vgscan_sz, "lvm vgscan"); 396 strcpy(pvscan_sz, "lvm pvscan"); 397 strcpy(vgcreate_sz, "lvm vgcreate"); 398 strcpy(vgchange_sz, "lvm vgchange"); 399 strcpy(vgremove_sz, "lvm vgremove"); 207 asprintf(&lvscan_sz, "lvm lvscan"); 208 asprintf(&lvremove_sz, "lvm lvremove"); 209 asprintf(&vgscan_sz, "lvm vgscan"); 210 asprintf(&pvscan_sz, "lvm pvscan"); 211 asprintf(&vgchange_sz, "lvm vgchange"); 212 asprintf(&vgremove_sz, "lvm vgremove"); 400 213 } else { 401 strcpy(lvscan_sz, "lvscan"); 402 strcpy(lvremove_sz, "lvremove"); 403 strcpy(vgscan_sz, "vgscan"); 404 strcpy(pvscan_sz, "pvscan"); 405 strcpy(vgcreate_sz, "vgcreate"); 406 strcpy(vgchange_sz, "vgchange"); 407 strcpy(vgremove_sz, "vgremove"); 408 } 409 sprintf(command, 214 asprintf(&lvscan_sz, "lvscan"); 215 asprintf(&lvremove_sz, "lvremove"); 216 asprintf(&vgscan_sz, "vgscan"); 217 asprintf(&pvscan_sz, "pvscan"); 218 asprintf(&vgchange_sz, "vgchange"); 219 asprintf(&vgremove_sz, "vgremove"); 220 } 221 asprintf(&command, 410 222 "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " 411 223 MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz); 224 paranoid_free(lvscan_sz); 225 paranoid_free(lvremove_sz); 226 412 227 run_program_and_log_output(command, 5); 228 paranoid_free(command); 229 413 230 sleep(1); 414 sprintf(command,231 asprintf(&command, 415 232 "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " 416 MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, 417 vgremove_sz, vgremove_sz); 233 MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz); 234 paranoid_free(vgchange_sz); 235 paranoid_free(vgremove_sz); 236 418 237 run_program_and_log_output(command, 5); 238 paranoid_free(command); 239 419 240 if (just_erase_existing_volumes) { 420 241 paranoid_fclose(fin); 421 242 log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs."); 422 retval = 0; 423 goto end_of_i_want_my_lvm; 243 sync(); 244 sync(); 245 sync(); 246 sleep(1); 247 iamhere("ENDING"); 248 log_msg(1, "Not many errors. Returning 0."); 249 return (0); 424 250 } 425 251 426 252 log_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff..."); 427 253 rewind(fin); 428 for ( fgets(incoming, 512, fin); !feof(fin); fgets(incoming, 512, fin)) {254 for (getline(&incoming, &n1, fin); !feof(fin); getline(&incoming, &n1, fin)) { 429 255 fgetpos(fin, &orig_pos); 256 /* BERLIOS : Strange no ? */ 430 257 if (incoming[0] != '#') { 431 258 continue; … … 433 260 if (res && strstr(command, "create") && vacuum_pack) { 434 261 sleep(2); 435 sy stem("sync");436 sy stem("sync");437 sy stem("sync");262 sync(); 263 sync(); 264 sync(); 438 265 } 439 266 if ((p = strstr(incoming, "vgcreate"))) { 440 267 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm) 441 for ( fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {268 for (getline(&tmp, &n, fin); !feof(fin); getline(&tmp, &n, fin)) { 442 269 if (tmp[0] == '#') { 443 270 fsetpos(fin, &orig_pos); … … 445 272 } else { 446 273 fgetpos(fin, &orig_pos); 447 strcat(incoming, tmp); 274 asprintf(&tmp1, "%s%s", incoming, tmp); 275 paranoid_free(incoming); 276 incoming = tmp1; 448 277 } 449 278 } 279 paranoid_free(tmp); 280 450 281 for (q = incoming; *q != '\0'; q++) { 451 282 if (*q < 32) { … … 453 284 } 454 285 } 455 strcpy(tmp, p + strlen("vgcreate") + 1); 456 for (q = tmp; *q > 32; q++); 286 malloc_string(tmp1); 287 strcpy(tmp1, p + strlen("vgcreate") + 1); 288 for (q = tmp1; *q > 32; q++); 457 289 *q = '\0'; 458 log_msg(1, "Deleting old entries at /dev/%s", tmp); 459 // sprintf(command, "%s -f %s", vgremove_sz, tmp); 460 // run_program_and_log_output(command, 1); 461 sprintf(command, "rm -Rf /dev/%s", tmp); 462 run_program_and_log_output(command, 1); 290 log_msg(1, "Deleting old entries at /dev/%s", tmp1); 291 asprintf(&tmp, "rm -Rf /dev/%s", tmp1); 292 paranoid_free(tmp1); 293 run_program_and_log_output(tmp, 1); 294 paranoid_free(tmp); 295 463 296 run_program_and_log_output(vgscan_sz, 1); 464 297 run_program_and_log_output(pvscan_sz, 1); … … 468 301 } 469 302 for (p = incoming + 1; *p == ' '; p++); 470 strcpy(command, p); 303 paranoid_free(command); 304 asprintf(&command, p); 471 305 for (p = command; *p != '\0'; p++); 472 306 for (; *(p - 1) < 32; p--); … … 485 319 if (strstr(command, "lvm lvcreate")) 486 320 lvmversion = 2; 321 /* BERLIOS : this tmp may be uninitialized ? 487 322 log_it("%s... so I'll get creative.", tmp); 323 */ 488 324 if (lvmversion == 2) { 489 strcpy(tmp, call_program_and_get_last_line_of_output 490 ("tail -n5 "MONDO_LOGFILE" | grep Insufficient | tail -n1")); 325 tmp = call_program_and_get_last_line_of_output 326 ("tail -n5 " MONDO_LOGFILE 327 " | grep Insufficient | tail -n1"); 491 328 } else { 492 strcpy(tmp, call_program_and_get_last_line_of_output 493 ("tail -n5 "MONDO_LOGFILE" | grep lvcreate | tail -n1")); 329 tmp = call_program_and_get_last_line_of_output 330 ("tail -n5 " MONDO_LOGFILE 331 " | grep lvcreate | tail -n1"); 494 332 } 495 333 for (p = tmp; *p != '\0' && !isdigit(*p); p++); 496 334 extents = atol(p); 497 335 log_msg(5, "p='%s' --> extents=%ld", p, extents); 336 paranoid_free(tmp); 498 337 p = strstr(command, "-L"); 499 338 if (!p) { … … 543 382 retval++; 544 383 } 545 sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);384 asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command); 546 385 system(tmp); 386 paranoid_free(tmp); 547 387 sleep(1); 548 388 } 549 389 paranoid_fclose(fin); 550 log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");551 end_of_i_want_my_lvm:552 paranoid_free(tmp);553 paranoid_free(incoming);554 paranoid_free(command);555 paranoid_free(lvscan_sz);556 paranoid_free(lvremove_sz);557 390 paranoid_free(vgscan_sz); 558 391 paranoid_free(pvscan_sz); 559 paranoid_free( vgcreate_sz);560 paranoid_free( vgchange_sz);561 paranoid_free(vgremove_sz); 562 // paranoid_free(do_this_last);563 sy stem("sync");564 sy stem("sync");565 sy stem("sync");392 paranoid_free(command); 393 paranoid_free(incoming); 394 395 log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff."); 396 sync(); 397 sync(); 398 sync(); 566 399 sleep(1); 567 400 iamhere("ENDING"); … … 589 422 *old_mountlist) 590 423 { 591 /** pointers *********************************************************/ 592 FILE *fin; 593 594 /** int **************************************************************/ 595 int lino; 596 int j; 597 598 /** buffers **********************************************************/ 599 char *incoming; 600 char *tmp; 601 602 /** pointers *********************************************************/ 603 char *p; 424 FILE *fin = NULL; 425 int lino = 0; 426 int j = 0; 427 char *incoming = NULL; 428 char *tmp = NULL; 429 char *p = NULL; 430 size_t n = 0; 604 431 605 432 /** init *************************************************************/ … … 608 435 /** end **************************************************************/ 609 436 610 malloc_string(incoming);611 malloc_string(tmp);612 437 assert(new_mountlist != NULL); 613 438 assert(old_mountlist != NULL); … … 615 440 #ifdef __FreeBSD__ 616 441 log_to_screen 617 (_("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.")); 442 (_ 443 ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.")); 618 444 return (1); 619 445 #endif … … 624 450 if (!does_file_exist("/etc/raidtab")) { 625 451 log_to_screen 626 (_("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries")); 452 (_ 453 ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries")); 627 454 finish(1); 628 455 } … … 631 458 finish(1); 632 459 } 633 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)460 for (getline(&incoming, &n, fin); !feof(fin) 634 461 && !strstr(incoming, old_mountlist->el[lino].device); 635 fgets(incoming, MAX_STR_LEN - 1, fin));462 getline(&incoming, &n, fin)); 636 463 if (!feof(fin)) { 637 sprintf(tmp, "Investigating %s",464 asprintf(&tmp, "Investigating %s", 638 465 old_mountlist->el[lino].device); 639 466 log_it(tmp); 640 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 467 paranoid_free(tmp); 468 469 for (getline(&incoming, &n, fin); !feof(fin) 641 470 && !strstr(incoming, "raiddev"); 642 fgets(incoming, MAX_STR_LEN - 1, fin)) {471 getline(&incoming, &n, fin)) { 643 472 if (strstr(incoming, OSSWAP("device", "drive")) 644 473 && !strchr(incoming, '#')) { … … 647 476 *p = '\0'; 648 477 for (p--; p > incoming && *(p - 1) > 32; p--); 649 sprintf(tmp, "Extrapolating %s", p);478 asprintf(&tmp, "Extrapolating %s", p); 650 479 log_it(tmp); 480 paranoid_free(tmp); 481 651 482 for (j = 0; 652 483 j < new_mountlist->entries … … 666 497 new_mountlist->entries++; 667 498 } else { 668 sprintf(tmp, 669 "Not adding %s to mountlist: it's already there", 670 p); 499 asprintf(&tmp, 500 "Not adding %s to mountlist: it's already there", p); 671 501 log_it(tmp); 502 paranoid_free(tmp); 672 503 } 673 504 } 674 505 } 675 506 } 507 paranoid_free(incoming); 676 508 paranoid_fclose(fin); 677 509 } else { … … 687 519 } 688 520 } 689 paranoid_free(incoming);690 paranoid_free(tmp);691 521 692 522 return (0); … … 702 532 * @return 0 for success, nonzero for failure. 703 533 */ 704 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device) 534 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, 535 char *device) 705 536 { 706 537 /** int **************************************************************/ 707 int i= 0;708 int j= 0;709 710 538 int i = 0; 539 int j = 0; 540 int res = 0; 541 711 542 /** buffers ***********************************************************/ 712 char *devices = NULL; 713 char *strtmp = NULL; 714 char *level = NULL; 715 char *program = NULL; 716 717 // leave straight away if raidlist is initial or has no entries 718 if (!raidlist || raidlist->entries == 0) { 719 log_msg(1, "No RAID arrays found."); 720 return 1; 721 } else { 722 log_msg(1, "%d RAID arrays found.", raidlist->entries); 723 } 724 // find raidlist entry for requested device 725 for (i = 0; i < raidlist->entries; i++) { 726 if (!strcmp(raidlist->el[i].raid_device, device)) break; 727 } 728 // check whether RAID device was found in raidlist 729 if (i == raidlist->entries) { 730 log_msg(1, "RAID device %s not found in list.", device); 731 return 1; 732 } 733 // create device list from normal disks followed by spare ones 734 asprintf(&devices, raidlist->el[i].data_disks.el[0].device); 735 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 736 asprintf(&strtmp, "%s", devices); 737 paranoid_free(devices); 738 asprintf(&devices, "%s %s", strtmp, 739 raidlist->el[i].data_disks.el[j].device); 740 paranoid_free(strtmp); 741 } 742 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 743 asprintf(&strtmp, "%s", devices); 744 paranoid_free(devices); 745 asprintf(&devices, "%s %s", strtmp, 746 raidlist->el[i].spare_disks.el[j].device); 747 paranoid_free(strtmp); 748 } 749 // translate RAID level 750 if (raidlist->el[i].raid_level == -2) { 751 asprintf(&level, "multipath"); 752 } else if (raidlist->el[i].raid_level == -1) { 753 asprintf(&level, "linear"); 754 } else { 755 asprintf(&level, "raid%d", raidlist->el[i].raid_level); 756 } 757 // create RAID device: 758 // - RAID device, number of devices and devices mandatory 759 // - parity algorithm, chunk size and spare devices optional 760 // - faulty devices ignored 761 // - persistent superblock always used as this is recommended 762 asprintf(&program, 763 "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", 764 raidlist->el[i].raid_device, level, 765 raidlist->el[i].data_disks.entries); 766 if (raidlist->el[i].parity != -1) { 767 asprintf(&strtmp, "%s", program); 768 paranoid_free(program); 769 switch(raidlist->el[i].parity) { 770 case 0: 771 asprintf(&program, "%s --parity=%s", strtmp, "la"); 772 break; 773 case 1: 774 asprintf(&program, "%s --parity=%s", strtmp, "ra"); 775 break; 776 case 2: 777 asprintf(&program, "%s --parity=%s", strtmp, "ls"); 778 break; 779 case 3: 780 asprintf(&program, "%s --parity=%s", strtmp, "rs"); 781 break; 782 default: 783 fatal_error("Unknown RAID parity algorithm."); 784 break; 785 } 786 paranoid_free(strtmp); 787 } 788 if (raidlist->el[i].chunk_size != -1) { 789 asprintf(&strtmp, "%s", program); 790 paranoid_free(program); 791 asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 792 paranoid_free(strtmp); 793 } 794 if (raidlist->el[i].spare_disks.entries > 0) { 795 asprintf(&strtmp, "%s", program); 796 paranoid_free(program); 797 asprintf(&program, "%s --spare-devices=%d", strtmp, 798 raidlist->el[i].spare_disks.entries); 799 paranoid_free(strtmp); 800 } 801 asprintf(&strtmp, "%s", program); 802 paranoid_free(program); 803 asprintf(&program, "%s %s", strtmp, devices); 804 paranoid_free(strtmp); 805 res = run_program_and_log_output(program, 1); 806 // free memory 807 paranoid_free(devices); 808 paranoid_free(level); 809 paranoid_free(program); 810 // return to calling instance 811 return res; 543 char *devices = NULL; 544 char *strtmp = NULL; 545 char *level = NULL; 546 char *program = NULL; 547 548 // leave straight away if raidlist is initial or has no entries 549 if (!raidlist || raidlist->entries == 0) { 550 log_msg(1, "No RAID arrays found."); 551 return 1; 552 } else { 553 log_msg(1, "%d RAID arrays found.", raidlist->entries); 554 } 555 // find raidlist entry for requested device 556 for (i = 0; i < raidlist->entries; i++) { 557 if (!strcmp(raidlist->el[i].raid_device, device)) 558 break; 559 } 560 // check whether RAID device was found in raidlist 561 if (i == raidlist->entries) { 562 log_msg(1, "RAID device %s not found in list.", device); 563 return 1; 564 } 565 // create device list from normal disks followed by spare ones 566 asprintf(&devices, raidlist->el[i].data_disks.el[0].device); 567 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 568 asprintf(&strtmp, "%s", devices); 569 paranoid_free(devices); 570 asprintf(&devices, "%s %s", strtmp, 571 raidlist->el[i].data_disks.el[j].device); 572 paranoid_free(strtmp); 573 } 574 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 575 asprintf(&strtmp, "%s", devices); 576 paranoid_free(devices); 577 asprintf(&devices, "%s %s", strtmp, 578 raidlist->el[i].spare_disks.el[j].device); 579 paranoid_free(strtmp); 580 } 581 // translate RAID level 582 if (raidlist->el[i].raid_level == -2) { 583 asprintf(&level, "multipath"); 584 } else if (raidlist->el[i].raid_level == -1) { 585 asprintf(&level, "linear"); 586 } else { 587 asprintf(&level, "raid%d", raidlist->el[i].raid_level); 588 } 589 // create RAID device: 590 // - RAID device, number of devices and devices mandatory 591 // - parity algorithm, chunk size and spare devices optional 592 // - faulty devices ignored 593 // - persistent superblock always used as this is recommended 594 asprintf(&program, 595 "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", 596 raidlist->el[i].raid_device, level, 597 raidlist->el[i].data_disks.entries); 598 if (raidlist->el[i].parity != -1) { 599 asprintf(&strtmp, "%s", program); 600 paranoid_free(program); 601 switch (raidlist->el[i].parity) { 602 case 0: 603 asprintf(&program, "%s --parity=%s", strtmp, "la"); 604 break; 605 case 1: 606 asprintf(&program, "%s --parity=%s", strtmp, "ra"); 607 break; 608 case 2: 609 asprintf(&program, "%s --parity=%s", strtmp, "ls"); 610 break; 611 case 3: 612 asprintf(&program, "%s --parity=%s", strtmp, "rs"); 613 break; 614 default: 615 fatal_error("Unknown RAID parity algorithm."); 616 break; 617 } 618 paranoid_free(strtmp); 619 } 620 if (raidlist->el[i].chunk_size != -1) { 621 asprintf(&strtmp, "%s", program); 622 paranoid_free(program); 623 asprintf(&program, "%s --chunk=%d", strtmp, 624 raidlist->el[i].chunk_size); 625 paranoid_free(strtmp); 626 } 627 if (raidlist->el[i].spare_disks.entries > 0) { 628 asprintf(&strtmp, "%s", program); 629 paranoid_free(program); 630 asprintf(&program, "%s --spare-devices=%d", strtmp, 631 raidlist->el[i].spare_disks.entries); 632 paranoid_free(strtmp); 633 } 634 asprintf(&strtmp, "%s", program); 635 paranoid_free(program); 636 asprintf(&program, "%s %s", strtmp, devices); 637 paranoid_free(strtmp); 638 res = run_program_and_log_output(program, 1); 639 // free memory 640 paranoid_free(devices); 641 paranoid_free(level); 642 paranoid_free(program); 643 // return to calling instance 644 return res; 812 645 } 813 646 … … 823 656 * @return 0 for success, nonzero for failure. 824 657 */ 825 int format_device(char *device, char *format, struct raidlist_itself *raidlist) 658 int format_device(char *device, char *format, 659 struct raidlist_itself *raidlist) 826 660 { 827 661 /** int **************************************************************/ 828 int res ;662 int res = 0; 829 663 int retval = 0; 830 664 #ifdef __FreeBSD__ … … 833 667 834 668 /** buffers ***********************************************************/ 835 char *program; 836 char *tmp; 669 char *program = NULL; 670 char *tmp = NULL; 671 char *tmp1 = NULL; 672 char *line = NULL; 673 char *status = NULL; 674 FILE *pin; 675 FILE *fin; 676 size_t n = 0; 677 size_t n1 = 0; 837 678 838 679 /** end ****************************************************************/ 839 680 840 malloc_string(program);841 malloc_string(tmp);842 681 assert_string_is_neither_NULL_nor_zerolength(device); 843 682 assert(format != NULL); 844 683 845 684 if (strstr(format, "raid")) { // do not form RAID disks; do it to /dev/md* instead 846 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);685 asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device); 847 686 log_it(tmp); 848 paranoid_free(program);849 687 paranoid_free(tmp); 850 688 return (0); … … 853 691 if (strcmp(format, "swap") == 0) { 854 692 log_it("Not formatting %s - it's swap", device); 855 paranoid_free(program);856 paranoid_free(tmp);857 693 return (0); 858 694 } 859 695 #endif 860 696 if (strlen(format) <= 2) { 861 sprintf(tmp,697 asprintf(&tmp, 862 698 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", 863 699 device, format); 864 700 log_it(tmp); 865 paranoid_free(program);866 701 paranoid_free(tmp); 867 702 return (0); 868 703 } 869 704 if (is_this_device_mounted(device)) { 870 sprintf(tmp, _("%s is mounted - cannot format it "), device);705 asprintf(&tmp, _("%s is mounted - cannot format it "), device); 871 706 log_to_screen(tmp); 872 paranoid_free(program);873 707 paranoid_free(tmp); 874 708 return (1); … … 880 714 if (!does_file_exist("/tmp/raidconf.txt")) { 881 715 log_to_screen 882 (_("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.")); 716 (_ 717 ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.")); 883 718 } else { 884 719 int res; … … 888 723 if (res) { 889 724 log_to_screen 890 (_("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.")); 725 (_ 726 ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.")); 891 727 finish(1); 892 728 } … … 896 732 897 733 if (vinum_started_yet) { 898 FILE *fin; 899 char line[MAX_STR_LEN]; 900 sprintf(tmp, 901 _("Initializing Vinum device %s (this may take a *long* time)"), 734 asprintf(&tmp, 735 _ 736 ("Initializing Vinum device %s (this may take a *long* time)"), 902 737 device); 903 738 log_to_screen(tmp); 739 paranoid_free(tmp); 740 904 741 /* format raid partition */ 905 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 906 sprintf(program, 742 asprintf(&program, 907 743 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", 908 744 basename(device)); 909 745 system(program); 746 910 747 if (g_fprep) { 911 748 fprintf(g_fprep, "%s\n", program); 912 749 } 750 paranoid_free(program); 751 913 752 fin = fopen("/tmp/plexes", "r"); 914 while ( fgets(line, MAX_STR_LEN - 1, fin)) {753 while (getline(&line, &n, fin)) { 915 754 if (strchr(line, '\n')) 916 755 *(strchr(line, '\n')) = '\0'; // get rid of the \n on the end 917 756 918 sprintf(tmp, "Initializing plex: %s", line);757 asprintf(&tmp, "Initializing plex: %s", line); 919 758 open_evalcall_form(tmp); 920 sprintf(tmp, "vinum init %s", line); 759 paranoid_free(tmp); 760 761 asprintf(&tmp, "vinum init %s", line); 921 762 system(tmp); 763 paranoid_free(tmp); 764 922 765 while (1) { 923 sprintf(tmp,766 asprintf(&tmp, 924 767 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 925 768 line); 926 FILE *pin = popen(tmp, "r"); 927 char status[MAX_STR_LEN / 4]; 928 fgets(status, MAX_STR_LEN / 4 - 1, pin); 769 pin = popen(tmp, "r"); 770 paranoid_free(tmp); 771 772 getline(&status, &n1, pin); 929 773 pclose(pin); 930 774 … … 934 778 update_evalcall_form(atoi(status)); 935 779 usleep(250000); 780 paranoid_free(status); 936 781 } 937 782 close_evalcall_form(); 938 783 } 784 paranoid_free(line); 939 785 fclose(fin); 940 786 unlink("/tmp/plexes"); … … 942 788 } 943 789 #else 944 sprintf(tmp, _("Initializing RAID device %s"), device);790 asprintf(&tmp, _("Initializing RAID device %s"), device); 945 791 log_to_screen(tmp); 792 paranoid_free(tmp); 946 793 947 794 // Shouldn't be necessary. 948 795 log_to_screen(_("Stopping %s"), device); 949 796 stop_raid_device(device); 950 sy stem("sync");797 sync(); 951 798 sleep(1); 799 /* BERLIOS: This code is wrong as program has not been initialized 952 800 if (g_fprep) { 953 801 fprintf(g_fprep, "%s\n", program); 954 802 } 803 */ 955 804 956 805 log_msg(1, "Making %s", device); 957 806 // use mkraid if it exists, otherwise use mdadm 958 if (run_program_and_log_output("which mkraid", FALSE)) { 959 res = create_raid_device_via_mdadm(raidlist, device); 960 log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res); 807 if (run_program_and_log_output("which mkraid", FALSE)) { 808 res = create_raid_device_via_mdadm(raidlist, device); 809 log_msg(1, "Creating RAID device %s via mdadm returned %d", 810 device, res); 961 811 } else { 962 sprintf(program, "mkraid --really-force %s", device);812 asprintf(&program, "mkraid --really-force %s", device); 963 813 res = run_program_and_log_output(program, 1); 964 814 log_msg(1, "%s returned %d", program, res); 965 sy stem("sync");815 sync(); 966 816 sleep(3); 967 817 start_raid_device(device); … … 969 819 fprintf(g_fprep, "%s\n", program); 970 820 } 971 } 972 system("sync"); 821 paranoid_free(program); 822 } 823 sync(); 973 824 sleep(2); 974 // log_to_screen("Starting %s", device); 975 // sprintf(program, "raidstart %s", device); 976 // res = run_program_and_log_output(program, 1); 977 // log_msg(1, "%s returned %d", program, res); 978 // system("sync"); sleep(1); 979 #endif 980 system("sync"); 825 #endif 826 sync(); 981 827 sleep(1); 982 828 newtResume(); … … 987 833 if (!strcmp(format, "lvm")) { 988 834 log_msg(1, "Don't format %s - it's part of an lvm volume", device); 989 paranoid_free(program);990 paranoid_free(tmp);991 835 return (0); 992 836 } 837 /* This function allocates program */ 993 838 res = which_format_command_do_i_need(format, program); 994 sprintf(tmp, "%s %s", program, device);995 839 if (strstr(program, "kludge")) { 996 strcat(tmp, " /"); 997 } 998 sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 999 sprintf(tmp, "Formatting %s as %s", device, format); 840 asprintf(&tmp, "%s %s /", program, device); 841 } else { 842 asprintf(&tmp, "%s %s", program, device); 843 } 844 paranoid_free(program); 845 846 asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 847 paranoid_free(tmp); 848 849 asprintf(&tmp, "Formatting %s as %s", device, format); 1000 850 update_progress_form(tmp); 851 1001 852 res = run_program_and_log_output(program, FALSE); 1002 853 if (res && strstr(program, "kludge")) { 1003 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",1004 format, device);1005 854 #ifdef __FreeBSD__ 1006 sprintf(program, "newfs_msdos -F 32 %s", device); 855 paranoid_free(program); 856 asprintf(&program, "newfs_msdos -F 32 %s", device); 1007 857 #else 1008 858 #ifdef __IA64__ 1009 859 /* For EFI partitions take fat16 1010 860 * as we want to make small ones */ 1011 sprintf(program, "mkfs -t %s -F 16 %s", format, device); 861 paranoid_free(program); 862 asprintf(&program, "mkfs -t %s -F 16 %s", format, device); 1012 863 #else 1013 sprintf(program, "mkfs -t %s -F 32 %s", format, device); 864 paranoid_free(program); 865 asprintf(&program, "mkfs -t %s -F 32 %s", format, device); 1014 866 #endif 1015 867 #endif … … 1019 871 } 1020 872 } 873 paranoid_free(program); 874 1021 875 retval += res; 1022 876 if (retval) { 1023 strcat(tmp, _("...failed"));877 asprintf(&tmp1, "%s%s",tmp, _("...failed")); 1024 878 } else { 1025 strcat(tmp, _("...OK")); 1026 } 1027 1028 log_to_screen(tmp); 1029 paranoid_free(program); 879 asprintf(&tmp1, "%s%s",tmp, _("...OK")); 880 } 1030 881 paranoid_free(tmp); 1031 system("sync"); 882 883 log_to_screen(tmp1); 884 paranoid_free(tmp1); 885 sync(); 1032 886 sleep(1); 1033 887 return (retval); 1034 888 } 1035 1036 1037 1038 889 1039 890 … … 1044 895 * @return The number of errors encountered (0 for success). 1045 896 */ 1046 int format_everything(struct mountlist_itself *mountlist, bool interactively,1047 897 int format_everything(struct mountlist_itself *mountlist, 898 bool interactively, struct raidlist_itself *raidlist) 1048 899 { 1049 900 /** int **************************************************************/ … … 1068 919 1069 920 assert(mountlist != NULL); 1070 malloc_string(tmp); 1071 sprintf(tmp, "format_everything (mountlist, interactively = %s", 921 asprintf(&tmp, "format_everything (mountlist, interactively = %s", 1072 922 (interactively) ? "true" : "false"); 1073 923 log_it(tmp); 924 paranoid_free(tmp); 925 1074 926 mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions ")); 1075 927 open_progress_form(_("Formatting partitions"), … … 1085 937 log_msg(1, "Stopping all RAID devices"); 1086 938 stop_all_raid_devices(mountlist); 1087 sy stem("sync");1088 sy stem("sync");1089 sy stem("sync");939 sync(); 940 sync(); 941 sync(); 1090 942 sleep(2); 1091 943 log_msg(1, "Prepare soft-RAIDs"); // prep and format too … … 1096 948 if (interactively) { 1097 949 // ask user if we should format the current device 1098 sprintf(tmp, "Shall I format %s (%s) ?", me->device,950 asprintf(&tmp, "Shall I format %s (%s) ?", me->device, 1099 951 me->mountpoint); 1100 952 do_it = ask_me_yes_or_no(tmp); 953 paranoid_free(tmp); 1101 954 } else { 1102 955 do_it = TRUE; … … 1109 962 } 1110 963 } 1111 sy stem("sync");1112 sy stem("sync");1113 sy stem("sync");964 sync(); 965 sync(); 966 sync(); 1114 967 sleep(2); 1115 968 // This last step is probably necessary … … 1126 979 newtSuspend(); 1127 980 } 1128 /*1129 for(i=0; i<3; i++)1130 {1131 res = do_my_funky_lvm_stuff(FALSE, FALSE);1132 if (!res) { break; }1133 sleep(3);1134 res = do_my_funky_lvm_stuff(TRUE, FALSE);1135 sleep(3);1136 }1137 if (res) {1138 log_msg(1, "Vacuum-packing...");1139 */1140 981 res = do_my_funky_lvm_stuff(FALSE, TRUE); 1141 /*1142 }1143 */1144 982 if (!g_text_mode) { 1145 983 newtResume(); … … 1150 988 log_to_screen("Failed to initialize LVM"); 1151 989 } 1152 // retval += res;1153 990 if (res) { 1154 991 retval++; … … 1162 999 me = &mountlist->el[lino]; // the current mountlist entry 1163 1000 if (!strcmp(me->mountpoint, "image")) { 1164 sprintf(tmp, "Not formatting %s - it's an image", me->device);1001 asprintf(&tmp, "Not formatting %s - it's an image", me->device); 1165 1002 log_it(tmp); 1003 paranoid_free(tmp); 1166 1004 } else if (!strcmp(me->format, "raid")) { 1167 sprintf(tmp, "Not formatting %s - it's a raid-let",1005 asprintf(&tmp, "Not formatting %s - it's a raid-let", 1168 1006 me->device); 1169 1007 log_it(tmp); 1008 paranoid_free(tmp); 1170 1009 continue; 1171 1010 } else if (!strcmp(me->format, "lvm")) { 1172 sprintf(tmp, "Not formatting %s - it's an LVM", me->device);1011 asprintf(&tmp, "Not formatting %s - it's an LVM", me->device); 1173 1012 log_it(tmp); 1013 paranoid_free(tmp); 1174 1014 continue; 1175 1015 } else if (!strncmp(me->device, "/dev/md", 7)) { 1176 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",1016 asprintf(&tmp, "Already formatted %s - it's a soft-RAID dev", 1177 1017 me->device); 1178 1018 log_it(tmp); 1019 paranoid_free(tmp); 1179 1020 continue; 1180 1021 } else if (!does_file_exist(me->device) 1181 1022 && strncmp(me->device, "/dev/hd", 7) 1182 1023 && strncmp(me->device, "/dev/sd", 7)) { 1183 sprintf(tmp,1024 asprintf(&tmp, 1184 1025 "Not formatting %s yet - doesn't exist - probably an LVM", 1185 1026 me->device); 1186 1027 log_it(tmp); 1028 paranoid_free(tmp); 1187 1029 continue; 1188 1030 } else { 1189 1031 if (interactively) { 1190 1032 // ask user if we should format the current device 1191 sprintf(tmp, "Shall I format %s (%s) ?", me->device,1033 asprintf(&tmp, "Shall I format %s (%s) ?", me->device, 1192 1034 me->mountpoint); 1193 1035 do_it = ask_me_yes_or_no(tmp); 1036 paranoid_free(tmp); 1194 1037 } else { 1195 1038 do_it = TRUE; … … 1215 1058 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1216 1059 log_to_screen 1217 (_("Errors occurred during the formatting of your hard drives.")); 1060 (_ 1061 ("Errors occurred during the formatting of your hard drives.")); 1218 1062 } else { 1219 1063 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1220 1064 } 1221 1065 1222 sprintf(tmp, "format_everything () - %s",1066 asprintf(&tmp, "format_everything () - %s", 1223 1067 (retval) ? "failed!" : "finished successfully"); 1224 1068 log_it(tmp); 1069 paranoid_free(tmp); 1225 1070 1226 1071 if (g_partition_table_locked_up > 0) { … … 1228 1073 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1229 1074 log_to_screen 1230 (_("Partition table locked up %d times. At least one 'mkfs' (format) command"), 1075 (_ 1076 ("Partition table locked up %d times. At least one 'mkfs' (format) command"), 1231 1077 g_partition_table_locked_up); 1232 log_to_screen 1233 (_("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"));1234 log_to_screen 1235 (_("to refresh its copy of the partition table causes the kernel to lock the "));1236 log_to_screen 1237 (_("partition table. I believe this has just happened."));1078 log_to_screen(_ 1079 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call")); 1080 log_to_screen(_ 1081 ("to refresh its copy of the partition table causes the kernel to lock the ")); 1082 log_to_screen(_ 1083 ("partition table. I believe this has just happened.")); 1238 1084 if (ask_me_yes_or_no 1239 (_("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))) 1085 (_ 1086 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))) 1240 1087 { 1241 sy stem("sync");1242 sy stem("sync");1243 sy stem("sync");1088 sync(); 1089 sync(); 1090 sync(); 1244 1091 system("reboot"); 1245 1092 } 1246 1093 } else { 1247 1094 log_to_screen 1248 (_("Partition table locked up %d time%c. However, disk formatting succeeded."), 1095 (_ 1096 ("Partition table locked up %d time%c. However, disk formatting succeeded."), 1249 1097 g_partition_table_locked_up, 1250 1098 (g_partition_table_locked_up == 1) ? '.' : 's'); … … 1254 1102 system("clear"); 1255 1103 newtResume(); 1256 paranoid_free(tmp);1257 1104 return (retval); 1258 1105 } … … 1281 1128 /** end **************************************************************/ 1282 1129 1283 malloc_string(tmp);1284 1130 assert_string_is_neither_NULL_nor_zerolength(drivename); 1285 1131 1286 1132 if (devno_we_must_allow_for >= 5) { 1287 sprintf(tmp, "Making dummy primary %s%d", drivename, 1);1133 asprintf(&tmp, "Making dummy primary %s%d", drivename, 1); 1288 1134 log_it(tmp); 1135 paranoid_free(tmp); 1136 1289 1137 g_maximum_progress++; 1290 1138 res = … … 1299 1147 } 1300 1148 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1301 sprintf(tmp, "Creating dummy partition %s%d", drivename,1149 asprintf(&tmp, "Creating dummy partition %s%d", drivename, 1302 1150 current_devno); 1303 1151 log_it(tmp); 1152 paranoid_free(tmp); 1153 1304 1154 g_maximum_progress++; 1305 1155 res = … … 1309 1159 previous_devno = current_devno; 1310 1160 } 1311 paranoid_free(tmp);1312 1161 return (previous_devno); 1313 1162 } … … 1340 1189 } 1341 1190 } 1191 1342 1192 1343 1193 /* The following 2 functions are stolen from /usr/src/sbin/disklabel/disklabel.c */ … … 1442 1292 static struct disklabel loclab; 1443 1293 struct partition *dp; 1444 char lnamebuf[BBSIZE];1294 char *lnamebuf; 1445 1295 int f; 1446 1296 u_int secsize, u; 1447 1297 off_t mediasize; 1448 1298 1449 (void) snprintf(lnamebuf, BBSIZE, "%s", dkname);1299 asprintf(&lnamebuf, "%s", dkname); 1450 1300 if ((f = open(lnamebuf, O_RDONLY)) == -1) { 1451 1301 warn("cannot open %s", lnamebuf); 1302 paranoid_free(lnamebuf); 1452 1303 return (NULL); 1453 1304 } 1305 paranoid_free(lnamebuf); 1454 1306 1455 1307 /* New world order */ … … 1522 1374 char *drivename, struct disklabel *ret) 1523 1375 { 1524 char subdev_str[MAX_STR_LEN];1525 char command[MAX_STR_LEN];1376 char *subdev_str; 1377 char *command; 1526 1378 struct disklabel *lp; 1527 1379 int i, lo = 0; … … 1533 1385 for (c = 'a'; c <= 'z'; ++c) { 1534 1386 int idx; 1535 sprintf(subdev_str, "%s%c", drivename, c);1387 asprintf(&subdev_str, "%s%c", drivename, c); 1536 1388 if ((idx = find_device_in_mountlist(mountlist, subdev_str)) < 0) { 1537 1389 lp->d_partitions[c - 'a'].p_size = 0; … … 1558 1410 lp->d_partitions[c - 'a'].p_fstype = FS_OTHER; 1559 1411 } 1412 paranoid_free(subdev_str); 1560 1413 } 1561 1414 … … 1588 1441 display_disklabel(ftmp, lp); 1589 1442 fclose(ftmp); 1590 sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));1443 asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename)); 1591 1444 retval += run_program_and_log_output(command, TRUE); 1592 sprintf(command, "disklabel -R %s /tmp/disklabel", 1445 paranoid_free(command); 1446 1447 asprintf(&command, "disklabel -R %s /tmp/disklabel", 1593 1448 canonical_name(drivename)); 1594 1449 retval += run_program_and_log_output(command, TRUE); 1450 paranoid_free(command); 1595 1451 if (ret) 1596 1452 *ret = *lp; … … 1609 1465 { 1610 1466 /** int *************************************************************/ 1611 int current_devno ;1467 int current_devno = 0; 1612 1468 int previous_devno = 0; 1613 int lino ;1469 int lino = 0; 1614 1470 int retval = 0; 1615 int i ;1471 int i = 0; 1616 1472 FILE *pout_to_fdisk = NULL; 1617 1473 1618 1474 #ifdef __FreeBSD__ 1619 1475 bool fbsd_part = FALSE; 1620 char subdev_str[MAX_STR_LEN];1476 char *subdev_str = NULL; 1621 1477 #endif 1622 1478 … … 1625 1481 1626 1482 /** buffers *********************************************************/ 1627 char *device_str; 1628 char *format; 1629 char *tmp; 1483 char *device_str = NULL; 1484 char *format = NULL; 1485 char *tmp = NULL; 1486 char *tmp1 = NULL; 1630 1487 1631 1488 /** end *************************************************************/ … … 1634 1491 assert_string_is_neither_NULL_nor_zerolength(drivename); 1635 1492 1636 malloc_string(device_str); 1637 malloc_string(format); 1638 malloc_string(tmp); 1639 1640 sprintf(tmp, "Partitioning drive %s", drivename); 1493 asprintf(&tmp, "Partitioning drive %s", drivename); 1641 1494 log_it(tmp); 1495 paranoid_free(tmp); 1642 1496 1643 1497 #if __FreeBSD__ … … 1646 1500 #else 1647 1501 make_hole_for_file(FDISK_LOG); 1648 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1502 asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, 1503 FDISK_LOG); 1649 1504 pout_to_fdisk = popen(tmp, "w"); 1505 paranoid_free(tmp); 1506 1650 1507 if (!pout_to_fdisk) { 1651 log_to_screen(_("Cannot call parted2fdisk to configure %s"), drivename); 1652 paranoid_free(device_str); 1653 paranoid_free(format); 1654 paranoid_free(tmp); 1508 log_to_screen(_("Cannot call parted2fdisk to configure %s"), 1509 drivename); 1655 1510 return (1); 1656 1511 } 1657 1512 #endif 1658 1513 for (current_devno = 1; current_devno < 99; current_devno++) { 1659 build_partition_name(device_str,drivename, current_devno);1514 device_str = build_partition_name(drivename, current_devno); 1660 1515 lino = find_device_in_mountlist(mountlist, device_str); 1661 1516 … … 1670 1525 // try DangerouslyDedicated mode 1671 1526 for (c = 'a'; c <= 'z'; c++) { 1672 sprintf(subdev_str, "%s%c", drivename, c); 1673 if (find_device_in_mountlist(mountlist, subdev_str) > 1674 0) { 1527 asprintf(&subdev_str, "%s%c", drivename, c); 1528 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1675 1529 fbsd_part = TRUE; 1676 1530 } 1531 paranoid_free(subdev_str); 1677 1532 } 1678 1533 if (fbsd_part) { … … 1685 1540 if (system(command)) { 1686 1541 log_to_screen 1687 (_("Warning! Unable to make the drive bootable.")); 1542 (_ 1543 ("Warning! Unable to make the drive bootable.")); 1688 1544 } 1689 1545 paranoid_free(device_str); 1690 paranoid_free(format); 1691 paranoid_free(tmp); 1546 1692 1547 return r; 1693 1548 } 1694 1549 } 1695 1550 for (c = 'a'; c <= 'z'; c++) { 1696 sprintf(subdev_str, "%s%c", device_str, c);1551 asprintf(&subdev_str, "%s%c", device_str, c); 1697 1552 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1698 1553 fbsd_part = TRUE; 1699 1554 } 1555 paranoid_free(subdev_str); 1700 1556 } 1701 1557 // Now we check the subpartitions of the current partition. … … 1703 1559 int i, line; 1704 1560 1705 strcpy(format, "ufs");1561 asprintf(&format, "ufs"); 1706 1562 partsize = 0; 1707 1563 for (i = 'a'; i < 'z'; ++i) { 1708 sprintf(subdev_str, "%s%c", device_str, i);1564 asprintf(&subdev_str, "%s%c", device_str, i); 1709 1565 line = find_device_in_mountlist(mountlist, subdev_str); 1566 paranoid_free(subdev_str); 1567 1710 1568 if (line > 0) { 1711 1569 // We found one! Add its size to the total size. … … 1730 1588 #if __FreeBSD__ 1731 1589 // FreeBSD doesn't let you write to blk devices in <512byte chunks. 1732 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);1733 // if (run_program_and_log_output(tmp, TRUE)) {1734 1590 file = open(drivename, O_WRONLY); 1735 1591 if (!file) { 1736 sprintf(tmp,1592 asprintf(&tmp, 1737 1593 _("Warning - unable to open %s for wiping it's partition table"), 1738 1594 drivename); 1739 1595 log_to_screen(tmp); 1596 paranoid_free(tmp); 1740 1597 } 1741 1598 1742 1599 for (i = 0; i < 512; i++) { 1743 1600 if (!write(file, "\0", 1)) { 1744 sprintf(tmp, _("Warning - unable to write to %s"),1601 asprintf(&tmp, _("Warning - unable to write to %s"), 1745 1602 drivename); 1746 1603 log_to_screen(tmp); 1604 paranoid_free(tmp); 1747 1605 } 1748 1606 } 1749 sy stem("sync");1607 sync(); 1750 1608 #else 1751 1609 iamhere("New, kernel-friendly partition remover"); … … 1754 1612 fflush(pout_to_fdisk); 1755 1613 } 1756 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);1757 // run_program_and_log_output(tmp, 1);1758 1614 #endif 1759 1615 if (current_devno > 1) { … … 1767 1623 #endif 1768 1624 1769 strcpy(format, mountlist->el[lino].format);1625 asprintf(&format, mountlist->el[lino].format); 1770 1626 partsize = mountlist->el[lino].size; 1771 1627 … … 1776 1632 if (current_devno == 5 && previous_devno == 4) { 1777 1633 log_to_screen 1778 (_("You must leave at least one partition spare as the Extended partition.")); 1634 (_ 1635 ("You must leave at least one partition spare as the Extended partition.")); 1779 1636 paranoid_free(device_str); 1780 1637 paranoid_free(format); 1781 paranoid_free(tmp); 1638 1782 1639 return (1); 1783 1640 } … … 1789 1646 #ifdef __FreeBSD__ 1790 1647 if ((current_devno <= 4) && fbsd_part) { 1791 sprintf(tmp, "disklabel -B %s", basename(device_str));1648 asprintf(&tmp, "disklabel -B %s", basename(device_str)); 1792 1649 retval += label_drive_or_slice(mountlist, device_str, 0); 1793 1650 if (system(tmp)) { … … 1795 1652 (_("Warning! Unable to make the slice bootable.")); 1796 1653 } 1654 paranoid_free(tmp); 1797 1655 } 1798 1656 #endif … … 1800 1658 previous_devno = current_devno; 1801 1659 } 1660 paranoid_free(device_str); 1661 paranoid_free(format); 1802 1662 1803 1663 if (pout_to_fdisk) { 1804 // mark relevant partition as bootable 1805 sprintf(tmp, "a\n%s\n", 1806 call_program_and_get_last_line_of_output 1807 ("make-me-bootable /tmp/mountlist.txt dummy")); 1664 // mark relevant partition as bootable 1665 tmp1 = call_program_and_get_last_line_of_output 1666 ("make-me-bootable /tmp/mountlist.txt dummy"); 1667 asprintf(&tmp, "a\n%s\n", tmp1); 1668 paranoid_free(tmp1); 1669 1808 1670 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1809 // close fdisk 1671 paranoid_free(tmp); 1672 1673 // close fdisk 1810 1674 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1811 sy stem("sync");1675 sync(); 1812 1676 paranoid_pclose(pout_to_fdisk); 1813 1677 log_msg(0, 1814 1678 "------------------- fdisk.log looks like this ------------------"); 1815 sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);1679 asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1816 1680 system(tmp); 1681 paranoid_free(tmp); 1682 1817 1683 log_msg(0, 1818 1684 "------------------- end of fdisk.log... word! ------------------"); 1819 sprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);1685 asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG); 1820 1686 if (!run_program_and_log_output(tmp, 5)) { 1821 1687 g_partition_table_locked_up++; 1822 1688 log_to_screen 1823 (_("A flaw in the Linux kernel has locked the partition table.")); 1824 } 1825 } 1826 paranoid_free(device_str); 1827 paranoid_free(format); 1828 paranoid_free(tmp); 1689 (_ 1690 ("A flaw in the Linux kernel has locked the partition table.")); 1691 } 1692 paranoid_free(tmp); 1693 } 1829 1694 return (retval); 1830 1695 } 1696 1831 1697 1832 1698 /** … … 1851 1717 char *partition_name; 1852 1718 char *tmp; 1853 char *logfile;1854 1719 char *output; 1855 1720 … … 1861 1726 /** end ***************************************************************/ 1862 1727 1863 malloc_string(program);1864 malloc_string(partition_name);1865 malloc_string(tmp);1866 malloc_string(logfile);1867 malloc_string(output);1868 1869 1728 assert_string_is_neither_NULL_nor_zerolength(drive); 1870 1729 assert(format != NULL); … … 1874 1733 1875 1734 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 1876 sprintf(tmp, "Not partitioning %s - it is a virtual drive", drive);1735 asprintf(&tmp, "Not partitioning %s - it is a virtual drive", drive); 1877 1736 log_it(tmp); 1878 paranoid_free(program);1879 paranoid_free(partition_name);1880 1737 paranoid_free(tmp); 1881 paranoid_free(logfile);1882 paranoid_free(output);1883 1738 return (0); 1884 1739 } 1885 build_partition_name(partition_name,drive, partno);1740 partition_name = build_partition_name(drive, partno); 1886 1741 if (partsize <= 0) { 1887 sprintf(tmp, "Partitioning device %s (max size)", partition_name);1742 asprintf(&tmp, "Partitioning device %s (max size)", partition_name); 1888 1743 } else { 1889 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,1744 asprintf(&tmp, "Partitioning device %s (%lld MB)", partition_name, 1890 1745 (long long) partsize / 1024); 1891 1746 } 1892 1747 update_progress_form(tmp); 1893 1748 log_it(tmp); 1749 paranoid_free(tmp); 1894 1750 1895 1751 if (is_this_device_mounted(partition_name)) { 1896 sprintf(tmp, _("%s is mounted, and should not be partitioned"),1752 asprintf(&tmp, _("%s is mounted, and should not be partitioned"), 1897 1753 partition_name); 1754 paranoid_free(partition_name); 1755 1898 1756 log_to_screen(tmp); 1899 paranoid_free(program);1900 paranoid_free(partition_name);1901 1757 paranoid_free(tmp); 1902 paranoid_free(logfile);1903 paranoid_free(output);1904 1758 return (1); 1905 /* 1906 } else if (does_partition_exist(drive, partno)) { 1907 sprintf(tmp, "%s already has a partition", partition_name); 1908 log_to_screen(tmp); 1909 return (1); 1910 */ 1911 } 1912 1913 1914 /* sprintf(tmp,"Partitioning %s ",partition_name); */ 1915 /* mvaddstr_and_log_it(g_currentY+1,30,tmp); */ 1759 } 1760 1916 1761 p = (char *) strrchr(partition_name, '/'); 1917 sprintf(logfile, "/tmp/fdisk.log.%s", ++p); 1918 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1762 asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1919 1763 MONDO_LOGFILE); 1920 1764 1921 /* BERLIOS: sho ould not be called each time */1765 /* BERLIOS: should not be called each time */ 1922 1766 part_table_fmt = which_partition_format(drive); 1923 output[0] = '\0';1924 1767 /* make it a primary/extended/logical */ 1925 1768 if (partno <= 4) { 1926 sprintf(output + strlen(output),"n\np\n%d\n", partno);1769 asprintf(&output,"n\np\n%d\n", partno); 1927 1770 } else { 1928 1771 /* MBR needs an extended partition if more than 4 partitions */ … … 1931 1774 if (prev_partno >= 4) { 1932 1775 log_to_screen 1933 (_("You need to leave at least one partition free, for 'extended/logical'")); 1776 (_ 1777 ("You need to leave at least one partition free, for 'extended/logical'")); 1778 paranoid_free(partition_name); 1934 1779 paranoid_free(program); 1935 paranoid_free(partition_name); 1936 paranoid_free(tmp); 1937 paranoid_free(logfile); 1780 1938 1781 paranoid_free(output); 1939 1782 return (1); 1940 1783 } else { 1941 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1942 prev_partno + 1); 1784 asprintf(&output,"n\ne\n%d\n\n\n",prev_partno + 1); 1943 1785 } 1944 1786 } 1945 strcat(output + strlen(output), "n\nl\n"); 1787 asprintf(&tmp,"%sn\nl\n",output); 1788 paranoid_free(output); 1789 output = tmp; 1946 1790 } else { 1947 1791 /* GPT allows more than 4 primary partitions */ 1948 sprintf(output + strlen(output), "n\np\n%d\n",partno);1792 asprintf(&output,"n\np\n%d\n",partno); 1949 1793 } 1950 1794 } 1951 1795 paranoid_free(part_table_fmt); 1952 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */ 1796 /*start block (ENTER for next free blk */ 1797 asprintf(&tmp,"%s\n",output); 1798 paranoid_free(output); 1799 output = tmp; 1800 1953 1801 if (partsize > 0) { 1954 1802 if (!strcmp(format, "7")) { … … 1956 1804 partsize += 512; 1957 1805 } 1958 sprintf(output + strlen(output), "+%lldK", (long long) (partsize)); 1959 } 1960 strcat(output + strlen(output), "\n"); 1806 asprintf(&tmp,"%s+%lldK", output, (long long) (partsize)); 1807 paranoid_free(output); 1808 output = tmp; 1809 } 1810 asprintf(&tmp,"%s\n",output); 1811 paranoid_free(output); 1812 output = tmp; 1961 1813 #if 0 1962 1814 /* 1963 1815 #endif 1964 sprintf(tmp,"PARTSIZE = +%ld",(long)partsize);1816 asprintf(&tmp,"PARTSIZE = +%ld",(long)partsize); 1965 1817 log_it(tmp); 1818 paranoid_free(tmp); 1819 1966 1820 log_it("---fdisk command---"); 1967 1821 log_it(output); … … 1977 1831 fput_string_one_char_at_a_time(pout_to_fdisk, output); 1978 1832 fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n"); 1979 strcpy(tmp, last_line_of_file(FDISK_LOG));1833 tmp = last_line_of_file(FDISK_LOG); 1980 1834 if (strstr(tmp, " (m ")) { 1981 1835 log_msg(1, "Successfully created %s%d", drive, partno); … … 1985 1839 partno); 1986 1840 } 1841 paranoid_free(tmp); 1842 1987 1843 if (!retval) { 1988 1844 log_msg(1, "Trying to set %s%d's partition type now", drive, … … 2002 1858 } 2003 1859 } else { 2004 strcat(output, "w\n\n"); 1860 asprintf(&tmp,"%sw\n\n",output); 1861 paranoid_free(output); 1862 output = tmp; 1863 2005 1864 if (g_fprep) { 2006 1865 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); … … 2020 1879 format, -1); 2021 1880 if (res) { 2022 sprintf(tmp, "Failed to vacuum-pack %s", partition_name);1881 asprintf(&tmp, "Failed to vacuum-pack %s", partition_name); 2023 1882 log_it(tmp); 1883 paranoid_free(tmp); 1884 2024 1885 retval++; 2025 1886 } else { … … 2032 1893 partsize); 2033 1894 if (retval) { 2034 sprintf(tmp, "Partitioned %s but failed to set its type",1895 asprintf(&tmp, "Partitioned %s but failed to set its type", 2035 1896 partition_name); 2036 1897 log_it(tmp); 1898 paranoid_free(tmp); 2037 1899 } else { 2038 1900 if (partsize > 0) { 2039 sprintf(tmp, "Partition %s created+configured OK",1901 asprintf(&tmp, "Partition %s created+configured OK", 2040 1902 partition_name); 2041 1903 log_to_screen(tmp); 1904 paranoid_free(tmp); 2042 1905 } else { 2043 1906 log_it("Returning from a successful vacuum-pack"); … … 2045 1908 } 2046 1909 } else { 2047 sprintf(tmp, "Failed to partition %s", partition_name);1910 asprintf(&tmp, "Failed to partition %s", partition_name); 2048 1911 if (partsize > 0) { 2049 1912 log_to_screen(tmp); … … 2051 1914 log_it(tmp); 2052 1915 } 1916 paranoid_free(tmp); 2053 1917 retval++; 2054 1918 } … … 2056 1920 g_current_progress++; 2057 1921 log_it("partition_device() --- leaving"); 1922 paranoid_free(partition_name); 2058 1923 paranoid_free(program); 2059 paranoid_free(partition_name);2060 paranoid_free(tmp);2061 paranoid_free(logfile);2062 1924 paranoid_free(output); 2063 1925 return (retval); 2064 1926 } 2065 2066 1927 2067 1928 … … 2124 1985 open_progress_form(_("Partitioning devices"), 2125 1986 _("I am now going to partition all your drives."), 2126 _("This should not take more than five minutes."), "",2127 mountlist->entries);1987 _("This should not take more than five minutes."), 1988 "", mountlist->entries); 2128 1989 2129 1990 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 2138 1999 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 2139 2000 log_to_screen 2140 (_("Errors occurred during the partitioning of your hard drives.")); 2001 (_ 2002 ("Errors occurred during the partitioning of your hard drives.")); 2141 2003 } else { 2142 2004 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); … … 2168 2030 { 2169 2031 /** buffers *********************************************************/ 2170 char *partition ;2171 char *command ;2172 char *output ;2173 char *tmp ;2174 char * partcode;2175 char * logfile;2032 char *partition = NULL; 2033 char *command = NULL; 2034 char *output = NULL; 2035 char *tmp = NULL; 2036 char *tmp1 = NULL; 2037 char *partcode = NULL; 2176 2038 2177 2039 /** pointers *********************************************************/ 2178 char *p ;2179 FILE *fout ;2040 char *p = NULL; 2041 FILE *fout = NULL; 2180 2042 2181 2043 /** int **************************************************************/ … … 2187 2049 assert(format != NULL); 2188 2050 2189 malloc_string(partition); 2190 malloc_string(command); 2191 malloc_string(output); 2192 malloc_string(tmp); 2193 malloc_string(partcode); 2194 malloc_string(logfile); 2195 2196 build_partition_name(partition, drive, partno); 2051 partition = build_partition_name(drive, partno); 2197 2052 p = (char *) strrchr(partition, '/'); 2198 sprintf(logfile, "/tmp/fdisk-set-type.%s.log", ++p);2199 2053 if (strcmp(format, "swap") == 0) { 2200 strcpy(partcode, "82");2054 asprintf(&partcode, "82"); 2201 2055 } else if (strcmp(format, "vfat") == 0) { 2202 2056 if (partsize / 1024 > 8192) { 2203 strcpy(partcode, "c");2057 asprintf(&partcode, "c"); 2204 2058 } else { 2205 strcpy(partcode, "b");2059 asprintf(&partcode, "b"); 2206 2060 } 2207 2061 } else if (strcmp(format, "ext2") == 0 … … 2209 2063 || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0 2210 2064 || strcmp(format, "jfs") == 0) { 2211 strcpy(partcode, "83");2065 asprintf(&partcode, "83"); 2212 2066 } else if (strcmp(format, "minix") == 0) { 2213 strcpy(partcode, "81");2067 asprintf(&partcode, "81"); 2214 2068 } else if (strcmp(format, "raid") == 0) { 2215 strcpy(partcode, "fd");2069 asprintf(&partcode, "fd"); 2216 2070 } else if ((strcmp(format, "ufs") == 0) 2217 2071 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */ 2218 strcpy(partcode, "a5");2072 asprintf(&partcode, "a5"); 2219 2073 } else if (strcmp(format, "lvm") == 0) { 2220 strcpy(partcode, "8e");2074 asprintf(&partcode, "8e"); 2221 2075 } else if (format[0] == '\0') { /* LVM physical partition */ 2222 partcode[0] = '\0';2076 asprintf(&partcode, ""); 2223 2077 } else if (strlen(format) >= 1 && strlen(format) <= 2) { 2224 strcpy(partcode, format);2078 asprintf(&partcode, format); 2225 2079 } else { 2226 2080 /* probably an image */ 2227 sprintf(tmp,2081 asprintf(&tmp, 2228 2082 "Unknown format ('%s') - using supplied string anyway", 2229 2083 format); 2230 2084 mvaddstr_and_log_it(g_currentY++, 0, tmp); 2085 paranoid_free(tmp); 2231 2086 #ifdef __FreeBSD__ 2232 strcpy(partcode, format); // was a52087 asprintf(&partcode, format); // was a5 2233 2088 #else 2234 strcpy(partcode, format); // was 832235 #endif 2236 } 2237 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,2089 asprintf(&partcode, format); // was 83 2090 #endif 2091 } 2092 asprintf(&tmp, "Setting %s's type to %s (%s)", partition, format, 2238 2093 partcode); 2094 paranoid_free(partition); 2095 2239 2096 log_msg(1, tmp); 2097 paranoid_free(tmp); 2240 2098 if (partcode[0] != '\0' && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */ 2241 2099 … … 2243 2101 res = 0; 2244 2102 fput_string_one_char_at_a_time(pout_to_fdisk, "t\n"); 2103 tmp1 = last_line_of_file(FDISK_LOG); 2245 2104 if (partno > 1 2246 || strstr( last_line_of_file(FDISK_LOG), " (1-4)")) {2105 || strstr(tmp1, " (1-4)")) { 2247 2106 log_msg(5, "Specifying partno (%d) - yay", partno); 2248 sprintf(tmp, "%d\n", partno);2107 asprintf(&tmp, "%d\n", partno); 2249 2108 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 2250 log_msg(5, "A - last line = '%s'", 2251 last_line_of_file(FDISK_LOG)); 2252 } 2253 2254 sprintf(tmp, "%s\n", partcode); 2109 paranoid_free(tmp); 2110 paranoid_free(tmp1); 2111 tmp1 = last_line_of_file(FDISK_LOG); 2112 log_msg(5, "A - last line = '%s'", tmp1); 2113 } 2114 paranoid_free(tmp1); 2115 2116 asprintf(&tmp, "%s\n", partcode); 2255 2117 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 2256 log_msg(5, "B - last line = '%s'", 2257 last_line_of_file(FDISK_LOG)); 2118 paranoid_free(tmp); 2119 tmp1 = last_line_of_file(FDISK_LOG); 2120 log_msg(5, "B - last line = '%s'",tmp1); 2121 paranoid_free(tmp1); 2122 2258 2123 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 2259 log_msg(5, "C - last line = '%s'", 2260 last_line_of_file(FDISK_LOG)); 2261 2262 strcpy(tmp, last_line_of_file(FDISK_LOG)); 2124 tmp1 = last_line_of_file(FDISK_LOG); 2125 log_msg(5, "C - last line = '%s'",tmp1); 2126 paranoid_free(tmp1); 2127 2128 tmp = last_line_of_file(FDISK_LOG); 2263 2129 if (!strstr(tmp, " (m ")) { 2264 2130 log_msg(1, "last line = '%s'; part type set failed", tmp); … … 2266 2132 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 2267 2133 } 2134 paranoid_free(tmp); 2268 2135 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2269 2136 } else { 2270 sprintf(output, "t\n%d\n%s\n", partno, partcode); 2271 strcat(output, "w\n"); 2272 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2137 asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode); 2138 asprintf(&command, "parted2fdisk %s >> %s 2>> %s", drive, 2273 2139 MONDO_LOGFILE, MONDO_LOGFILE); 2274 2140 log_msg(5, "output = '%s'", output); … … 2284 2150 paranoid_pclose(fout); 2285 2151 } 2286 } 2152 paranoid_free(command); 2153 paranoid_free(output); 2154 } 2155 /* BERLIOS: Useless as command not initialized in all cases 2287 2156 if (res) { 2288 2157 log_OS_error(command); 2289 2158 } 2290 } 2291 2292 paranoid_free(partition); 2293 paranoid_free(command); 2294 paranoid_free(output); 2295 paranoid_free(tmp); 2159 */ 2160 } 2296 2161 paranoid_free(partcode); 2297 paranoid_free(logfile); 2162 2298 2163 2299 2164 return (res); … … 2313 2178 2314 2179 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2315 malloc_string(program);2316 2180 2317 2181 #ifdef __FreeBSD__ … … 2320 2184 return 1; 2321 2185 } 2322 sprintf(program, "vinum start -f %s", raid_device);2186 asprintf(&program, "vinum start -f %s", raid_device); 2323 2187 #else 2324 sprintf(program, "raidstart %s", raid_device);2188 asprintf(&program, "raidstart %s", raid_device); 2325 2189 // sprintf (program, "raidstart " RAID_DEVICE_STUB "*"); 2326 2190 #endif … … 2330 2194 fprintf(g_fprep, "%s\n", program); 2331 2195 } 2196 paranoid_free(program); 2197 2332 2198 if (res) { 2333 2199 log_msg(1, "Warning - failed to start RAID device %s", … … 2338 2204 return (retval); 2339 2205 } 2340 2341 2206 2342 2207 … … 2358 2223 2359 2224 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2360 malloc_string(program);2361 2225 2362 2226 #ifdef __FreeBSD__ … … 2365 2229 return 1; 2366 2230 } 2367 sprintf(program, "vinum stop -f %s", raid_device);2231 asprintf(&program, "vinum stop -f %s", raid_device); 2368 2232 #else 2369 2370 2371 sprintf(program, "mdadm -S %s", raid_device);2233 // use raidstop if it exists, otherwise use mdadm 2234 if (run_program_and_log_output("which raidstop", FALSE)) { 2235 asprintf(&program, "mdadm -S %s", raid_device); 2372 2236 } else { 2373 sprintf(program, "raidstop %s", raid_device);2237 asprintf(&program, "raidstop %s", raid_device); 2374 2238 } 2375 2239 #endif … … 2379 2243 fprintf(g_fprep, "%s\n", program); 2380 2244 } 2245 paranoid_free(program); 2246 2381 2247 if (res) { 2382 2248 log_msg(1, "Warning - failed to stop RAID device %s", raid_device); … … 2409 2275 return (retval); 2410 2276 } 2277 2411 2278 2412 2279 /** … … 2421 2288 int retval = 0; 2422 2289 #ifndef __FreeBSD__ 2423 int res ;2290 int res = 0; 2424 2291 #endif 2425 2292 2426 2293 /** char ************************************************************/ 2427 char *incoming ;2294 char *incoming = NULL; 2428 2295 #ifndef __FreeBSD__ 2429 char *dev ;2296 char *dev = NULL; 2430 2297 #endif 2431 2298 /** pointers ********************************************************/ 2432 2299 #ifndef __FreeBSD__ 2433 char *p; 2434 #endif 2435 FILE *fin; 2436 int i; 2300 char *p = NULL; 2301 #endif 2302 FILE *fin = NULL; 2303 int i = 0; 2304 size_t n = 0; 2437 2305 2438 2306 /** end ****************************************************************/ 2439 2307 2440 malloc_string(dev);2441 malloc_string(incoming);2442 2308 assert(mountlist != NULL); 2443 2309 … … 2449 2315 "r"); 2450 2316 if (!fin) { 2451 paranoid_free(dev);2452 paranoid_free(incoming);2453 2317 return (1); 2454 2318 } 2455 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);2456 fgets(incoming, MAX_STR_LEN - 1, fin)) {2319 for (getline(&incoming, &n, fin); !feof(fin); 2320 getline(&incoming, &n, fin)) { 2457 2321 retval += stop_raid_device(incoming); 2458 2322 } … … 2461 2325 if (!fin) { 2462 2326 log_OS_error("/proc/mdstat"); 2463 paranoid_free(dev);2464 paranoid_free(incoming);2465 2327 return (1); 2466 2328 } 2467 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);2468 fgets(incoming, MAX_STR_LEN - 1, fin)) {2329 for (getline(&incoming, &n, fin); !feof(fin); 2330 getline(&incoming, &n, fin)) { 2469 2331 for (p = incoming; 2470 2332 *p != '\0' && (*p != 'm' || *(p + 1) != 'd' 2471 2333 || !isdigit(*(p + 2))); p++); 2472 2334 if (*p != '\0') { 2473 sprintf(dev, "/dev/%s", p); 2335 asprintf(&dev, "/dev/%s", p); 2336 /* BERLIOS : 32 Hard coded value */ 2474 2337 for (p = dev; *p > 32; p++); 2475 2338 *p = '\0'; 2476 2339 res = stop_raid_device(dev); 2477 } 2478 } 2479 #endif 2340 paranoid_free(dev); 2341 } 2342 } 2343 #endif 2344 paranoid_free(incoming); 2480 2345 } 2481 2346 paranoid_fclose(fin); … … 2483 2348 log_msg(1, "Warning - unable to stop some RAID devices"); 2484 2349 } 2485 paranoid_free(dev); 2486 paranoid_free(incoming); 2487 system("sync"); 2488 system("sync"); 2489 system("sync"); 2350 sync(); 2351 sync(); 2352 sync(); 2490 2353 sleep(1); 2491 2354 return (retval); 2492 2355 } 2493 2494 2356 2495 2357 … … 2510 2372 /** end ***************************************************************/ 2511 2373 2512 malloc_string(tmp);2513 2374 assert_string_is_neither_NULL_nor_zerolength(format); 2514 2375 assert(program != NULL); … … 2542 2403 sprintf(program, "mkfs -t %s -c", format); // -c checks for bad blocks 2543 2404 #endif 2544 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,2405 asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format, 2545 2406 program); 2546 2407 log_it(tmp); 2408 paranoid_free(tmp); 2547 2409 res = 0; 2548 2410 } 2549 paranoid_free(tmp);2550 2411 return (res); 2551 2412 } … … 2573 2434 /** end *************************************************************/ 2574 2435 2575 malloc_string(tmp);2576 2436 assert(mountlist != NULL); 2577 2437 assert_string_is_neither_NULL_nor_zerolength(drive_name); … … 2584 2444 original_size_of_drive += mountlist->el[partno].size; 2585 2445 } else { 2586 sprintf(tmp, "Skipping %s", mountlist->el[partno].device);2446 asprintf(&tmp, "Skipping %s", mountlist->el[partno].device); 2587 2447 // log_to_screen(tmp); 2448 paranoid_free(tmp); 2588 2449 } 2589 2450 } 2590 2451 original_size_of_drive = original_size_of_drive / 1024; 2591 paranoid_free(tmp);2592 2452 return (original_size_of_drive); 2593 2453 } … … 2632 2492 /** end **************************************************************/ 2633 2493 2634 malloc_string(tmp);2635 2494 assert(mountlist != NULL); 2636 2495 assert_string_is_neither_NULL_nor_zerolength(drive_name); … … 2639 2498 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2640 2499 == 0) { 2641 paranoid_free(tmp);2642 2500 return; 2643 2501 } … … 2653 2511 if (current_size_of_drive <= 0) { 2654 2512 log_it("Not resizing to match %s - can't find drive", drive_name); 2655 paranoid_free(tmp);2656 2513 return; 2657 2514 } 2658 sprintf(tmp, _("Expanding entries to suit drive %s (%ld MB)"), drive_name,2659 current_size_of_drive);2515 asprintf(&tmp, _("Expanding entries to suit drive %s (%ld MB)"), 2516 drive_name, current_size_of_drive); 2660 2517 log_to_screen(tmp); 2518 paranoid_free(tmp); 2661 2519 2662 2520 drivemntlist = malloc(sizeof(struct mountlist_reference)); … … 2675 2533 2676 2534 if (original_size_of_drive <= 0) { 2677 sprintf(tmp, _("Cannot resize %s's entries. Drive not found."),2535 asprintf(&tmp, _("Cannot resize %s's entries. Drive not found."), 2678 2536 drive_name); 2679 2537 log_to_screen(tmp); … … 2683 2541 factor = 2684 2542 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2685 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",2543 asprintf(&tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", 2686 2544 drive_name, original_size_of_drive, current_size_of_drive, 2687 2545 factor); 2688 2546 log_to_screen(tmp); 2547 paranoid_free(tmp); 2689 2548 2690 2549 lastpart = drivemntlist->entries - 1; … … 2705 2564 newsizL = (long) new_size; 2706 2565 } 2707 sprintf(tmp, _("Changing %s from %lld KB to %ld KB"),2566 asprintf(&tmp, _("Changing %s from %lld KB to %ld KB"), 2708 2567 drivemntlist->el[partno]->device, 2709 2568 drivemntlist->el[partno]->size, newsizL); 2710 2569 log_to_screen(tmp); 2570 paranoid_free(tmp); 2711 2571 drivemntlist->el[partno]->size = newsizL; 2712 2572 } 2713 2573 final_size = get_phys_size_of_drive(drive_name); 2714 sprintf(tmp, _("final_size = %ld MB"), final_size);2574 asprintf(&tmp, _("final_size = %ld MB"), final_size); 2715 2575 log_to_screen(tmp); 2716 2576 paranoid_free(tmp); … … 2778 2638 log_msg(1, "Creating list of partitions for drive %s", drive_name); 2779 2639 2780 tmp_drive_name = strdup(drive_name);2640 asprintf(&tmp_drive_name,drive_name); 2781 2641 if (!tmp_drive_name) 2782 2642 fatal_error("Out of memory"); … … 2798 2658 } 2799 2659 } 2800 if (tmp_drive_name) 2801 free(tmp_drive_name); 2660 paranoid_free(tmp_drive_name); 2802 2661 } 2803 2662 -
trunk/mondo/mondo/mondorestore/mondo-restore-EXT.h
r426 r688 1 /* mondo-restore-EXT.h */ 1 /* 2 * $Id$ 3 **/ 2 4 3 5 #ifdef __FreeBSD__ -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r687 r688 1 1 /*************************************************************************** 2 mondo-restore.c - restores mondoarchive data 3 ------------------- 4 begin : Fri May 19 2000 5 copyright : (C) 2000 by Hugo Rabson 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 /*************************************************************************** 20 * Change Log * 21 *************************************************************************** 22 . 23 24 25 07/26 26 - workaround - if not /dev then don't call partimagehack 27 28 07/21 29 - if switch to Interactive Mode during nuke then don't nuke twice :) just once 30 31 07/18 32 - better support of users who boot from LVM CD and nuke-restore non-LVM backups 33 34 07/10 35 - when using 'star', exclude all 'not removed.' messages from log (misleading, they are) 36 - try w/ ACLs, then w/o ACLs if star fails w/ ACLs 37 - added ACL, xattr support for afio 38 39 06/26 40 - remove make_relevant_partition_bootable(); roll into mondo-prep.c 41 - changed various newtDrawRootText() calls to use g_noof_rows instead of 42 integers 43 44 06/19 45 - don't try to access biggiestruct before it is populated w/ data relating 46 to biggiefile; instead, use control char to find out if biggiefile is 47 to be restored w/ partimagehack or not 48 - added AUX_VER 49 50 06/15 51 - read_cfg_file_into_bkpinfo() --- use user-supplied 'isodir' instead of 52 archive's 'isodir' if different 53 Conor Daly <conor.daly@met.ie> 54 55 06/17 56 - restore with partimagehack if NTFS device; dd, if non-NTFS device 57 58 06/14 59 - unmount all; remount, run grub-mr; unmount again 60 61 04/09 62 - fixed subset restoration bug introduced when I added 'star' support 63 64 04/04 65 - cleaned up restore_a_tarball_from_stream() 66 67 04/03 68 - added star support 69 - pause for 3s between partitioning and formatting (if in Nuke Mode) 70 71 03/28 72 - check that g_mountlist_fname was correcfly set; abort if it wasn't 73 74 03/25 75 - removed dev_null code 76 77 03/22/04 78 - added mode_of_file() 79 - added code to check for unauthorised modification of /dev/null 80 by afio (for instance) 81 82 12/27/03 83 - check /tmp/cmdline instead of /proc/cmdline if on FreeBSD 84 85 11/15 86 - added g_fprep 87 - "Switch to interactive mode?" msg is now more informative 88 89 11/05 90 - after 'Are you sure?' when user specifies / as restore path, set 91 restore_path[] to "" so that files are restored to [blank]/file/name :) 92 93 10/29 94 - moved "No restoring or comparing will take place today" block 95 up to before iso_fiddly_bits (if iso) is called - fix bug 96 if you're in ISO Mode and you say "exit to shell" 97 98 10/22 99 - swapped calls to chmod() and chown() after restoration 100 of big files (Jens) 101 102 10/21 103 - changed "/mnt/cdrom" to MNT_CDROM 104 105 10/19 106 - restore biggiefiles selectively from CD properly 107 - use find_my_editor() to find pico/vi/whatever 108 - better use of call_program_and_get_last_line_of_output() to 109 scan /proc/cmdline 110 111 10/18 112 - don't report 'missing compressor' if no compressor used at all 113 114 10/14 115 - log afio's error messages to /var/log/mondo-archive.log 116 when restoring :) 117 - call vi if pico is not available 118 119 10/09 120 - better logging if fatal error (cannot openout bigfile) 121 - better GUI feedback when restoring big files 122 - restore_everything() now uses s_node* instead of char* 123 - ditto restore_all_*_from_*() 124 125 10/02 126 - succinct msg instead of pop-ups, if used -H 127 128 09/27 129 - tweaked restore-time gui 130 131 09/26 132 - proper reporting of DVD/CDR/etc. type in displayed dialogs 133 134 09/23 135 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings() 136 and free_libmondo_global_strings() - which are in libmondo-tools.c 137 138 09/21 139 - trying to fix "mondorestore <no params>" segfault 140 141 09/18 142 - better remounting of / 143 - cleaned up run_grub() 144 - sensible command-line handling in Live Mode 145 146 09/17 147 - cleaned up GRUB installer script a bit 148 149 09/15 150 - remount / as r/w if in disaster recovery mode; 151 helps for b0rken distros 152 153 09/13 154 - major NTFS hackage 155 156 09/12 157 - changed some in-sub var decl'ns to malloc()'s 158 159 09/05 160 - don't let me run unless I'm root 161 - finished NTFS/partimagehack support (CD only); working on tape now 162 163 09/01 164 - fixed cosmetic bug in biggiefile restore window 165 166 06/01 - 08/31 167 - added code to main() to make sure NFS 168 (backup) share is mounted in Nuke and Compare Modes 169 - added code to run_grub() to mount /boot before running grub-install 170 - fixed some stray assert()'s in restore_a_biggiefile_from_stream() 171 - fixed bugs in extract_config_file_from_ramdisk() 172 and get_cfg_file_from_archive() which 173 stopped fape+floppy users from being able to 174 boot from floppy and leave floppy in drive :) 175 - added hooks to partimage for doing imagedevs 176 - fixed calls to popup_and_get_string() 177 178 05/01 - 05/31 179 - fixed biggiefile atime/utime dates restoration bug, I think 180 - added misc clean-up (Steve Hindle) 181 - fixed support for subdir-within-NFS-mount 182 - if nuke mode fails & user reverts to interactive mode _and succeeds_, 183 don't claim nuke mode aborted :) 184 - unmount_all_devices() uses mountlist->el[lino].mountpt 185 instead of mountlist->el[lino].device where possible 186 - added Joshua Oreman's FreeBSD patches 187 - copied missing paragraph from 1.6x's read_cfg_file_into_bkpinfo() 188 to 1.7x's; affected tape streamer users (badly!) 189 - cleaned up some paranoid assert()'s 190 - use which("post-nuke") instead of find_home_of_exe("post-nuke") 191 - fixed "Don't eject while restoring" mode 192 - get_cfg_file_from_archive() --- also recovers mountlist.txt now :) 193 - don't eject if 'donteject' is in kernel's command line 194 - added 'don't panic' msg to start of log 195 196 04/01 - 04/30 197 - added text mode (cat /proc/cmdline; if textonly then text mode is on) 198 - delete /var/lock/subsys/ * when nuking 199 - don't resize mountlist if "noresize" present in /proc/cmdline 200 - changed from chmod -R 1777 tmp to chmod 1777 tmp 201 - replace newtFinished() and newtInit() with 202 newtSuspend() and newtResume() 203 - get_cfg_file_from_archive() returns 1 instead of aborting now 204 - read_cfg_file_into_bkpinfo) --- if autorun CD but its config 205 file indicates a non-CD backup media then ask, just in case 206 - sped up restore_a_tarball_from_CD() a bit 207 - line 4469 --- if post-nuke not found then don't run it :) 208 - replaced "/mnt/RESTORING" with MNT_RESTORING (#define'd) 209 - moved compare_*() into mondorestore/mondo-rstr-compare.c 210 - moved some RAID subroutines into common/libmondo-raid.c 211 - fixed some iso live compare problems 212 - replaced FILELIST_FULL with g_filelist_full and FILELIST_FULL_STUB; 213 g_filelist_full being the full path of the filelist.full text file and 214 FILELIST_FULL_STUB being "tmp/filelist.full" (relative path); 215 - ditto BIGGIELIST_TXT, MONDO_CFG_FILE 216 - added lots of assert()'s and log_OS_error()'s 217 - in Nuke Mode, check mountlist's sanity before doing anything else; 218 if it fails sanity test, offer to revert to Interactive Mode (or abort) 219 - copy log to /mnt/RESTORING/root at end 220 - read_cfg_file_into_bkpinfo() --- read iso-dev and isodir if bkptype==iso 221 - line 1701 --- delete ramdisk file after extracting config info 222 - moved call to make_relevant_partitions_bootable() from 223 within run_boot_loader() to within interactive_mode() and 224 nuke_mode(), after unmounting disks 225 - if editing fstab or *.conf, try to use pico if available 226 - better calling of make-me-bootable 227 - don't sort mountlist anywhere anymore except _locally_ in 228 mount_all_devices() and unmount_all_devices() 229 - edit fstab, grub.conf _after_ stabgrub-me if it fails 230 - run_boot_loader() --- backup all crucial files to /etc/ *.pristine first 231 - added iso_fiddly_bits() 232 - fixed ISO mode support 233 - mount_cdrom() only searches for device if NOT in disaster recovery mode 234 - changed lost of system()'s into run_program_and_log_output()'s 235 - don't eject if bkpinfo->please_dont_eject_when_restoring 236 - cleaned up post-nuke handling code 237 - always eject CD at end, unless bkpinfo->please_dont_... 238 - misc clean-up (Tom Mortell) 239 - afio uses -c (1024L*1024L)/TAPE_BLOCK_SIZE now 240 instead of -c 1024 241 242 01/01 - 03/31/2003 243 - commented out sort_... line (BB) 244 - clean-up (Stan Benoit) 245 - added code for LVM and SW Raid (Brian Borgeson) 246 - line 814 - added -p to 'mkdir -p tmp' 247 - mount_cdrom() - calls find_cdrom_device() if 248 bkpinfo->media_device is blank (to fill it) 249 250 11/01 - 12/31/2002 251 - mount_cdrom() better at handling multiple CD drives 252 - minor clean-up in restore_a_tarball_from_CD() 253 - if --live-from-cd then assume restoring live from CD 254 - tweaked it to run better w/ ArkLinux 255 - create /mnt/RESTORING/mnt/.boot.d for Gentoo users 256 after restoring 257 - cleaned up iso_mode(); no longer asks for NFS info 3 times 258 - mount_cdrom() was trying to mount /mnt/isodir/%s/%d.iso; 259 is now just %s/%d.iso 260 - mount/unmount /boot if necessary (Gentoo) 261 - added RAW MBR support; added run_raw_mbr() for the purpose 262 - unmount & remount supermounts at start/end of live restore 263 - copy /tmp/mountlist.txt to /tmp/mountlist.txt.orig at start 264 - cleaned up string-handling in get_cfg_info_from_archives() 265 - fixed run_grub() to call new stabgrub-me script 266 - popup list of changed files after Compare Mode 267 - permit mondorestore --edit-mountlist even if live mode 268 - create a repaired copy of grub-install which is RAID-friendly; 269 use it when initializing boot sector with run_grub() 270 - use grub-MR instead of grub-install 271 - fixed read_cfg_file_into_bkpinfo() to ignore cfg file's backup_media_type 272 if user has already specified a backup media type interactively 273 274 10/01 - 10/31 275 - run_grub() will let you specify the boot device as well as edit the system 276 files, if grub-install fails 277 - fixed bug in fwrite() call in restore_biggiefile_from_CD() 278 - fixed bug affecting restoration of bigfiles from CD's w/0 compression 279 - run_grub() will run 'grub-install {boot device}' instead of 280 'grub-install (hd0)' 281 282 09/01 - 09/30 283 - use /tmp/tmpfs/mondo.tmp instead of /tmp/mondo.tmp 284 - initialize MOUNTLIST_FNAME at start of main() 285 - differential-related cleanup 286 - better handling of CD-ROM drives which aren't /dev/cdrom :) 287 - run_program_and_log_output() now takes boolean operator to specify 288 whether it will log its activities in the event of _success_ 289 - always load config file from archive before operating on it 290 - moved some subroutines around; now closer to alphabetical order 291 - changed mount.mindi to mount.bootisk 292 - mount disks readonly if in Compare Mode 293 - set /dev/null's permissions to 777, just in case it somehow gets mangled 294 ...which apparently happen with some devfs-based Linux distributions 295 - remove /var/run/ *.pid after restoring 296 - move spurious lockfiles from /home/ * to /home/ * /.disabled 297 - if Interactive Mode then ask user which media, etc. (i.e. catchall mode 298 is now same as Interactive Mode) 299 300 08/01 - 08/30 301 - use data structure to store the fname, checksum, mods & perms of each bigfile 302 ... biggiestruct :) 303 - if a filelist is tiny (2 bytes or less) then ignore it 304 - insist_on_this_cd_number() --- now takes 2 params, not 1 305 - re-enabled 'g_current_media_number = 1' in restore_everything() 306 - added same to compare_mode() 307 - replaced lots of global char[]'s with malloc()'s 308 - if differential backup then don't permit formatting or fdisking, 309 whether Interactive or Nuke mode 310 - added call to register_pid() at start of main() 311 - if Nuke Mode & it succeeds then ask user if they have contributed yet 312 - changed tape-size to media-size (config file) 313 - changed using_* to backup_media_type 314 - changed *_from_tape to *_from_stream 315 316 07/01 - 07/31 317 - added find_and_mount_actual_cdrom() 318 - temp dir is always random 319 - skip tarballs if they don't contain files we're looking for 320 (used to read the whole thing & _then_ skip) 321 - use media_size[1] instead of media_size[0] 322 - fixed serious bug in line 1546 - should have been !=, not ==; stopped 323 mondorestore from correctly restoring big files 324 - bigfile piping enhancements (Philippe de Muyter) 325 - unmount CD-ROM after restoring from live filesystem 326 - TAPE_BLOCK_SIZE treated as %ld, not %d 327 328 06/01 - 06/30 329 - added signal-trapping 330 - disabled 'nr-failed-disks' flag 331 - fixed problem w/selective restore 332 - don't change /tmp's permissions unless it doesn't exist & must be created 333 - fixed bug in --mbr 334 - is_file_in_list() enhanced to exclude /mnt/RESTORING or whatever 335 - added support for uncompressed archives 336 - --monitas-live now accepts path-to-restore_to_, not just path to restore 337 - added some debugging/tracking code to the NFS section 338 - various monitas-related enhancements 339 - added --isonuke and --mbr switches 340 - better logging in run_grub() 341 - improved --monitas-live 342 - mkdir -p /mnt/RESTORING/var/run/console just in case user excludes it 343 - afio now uses 16MB buffer instead of 8MB 344 - always use bkpinfo->media_size[0], now that -s has been expanded 345 - popup and ask where to restore data, if restoring selectively 346 347 05/01 - 05/31 348 - add '--monitas' flag 349 - don't run chmod -R 1777 /mnt/RESTORING/tmp before unmounting unless 350 restoring at the time... 351 352 04/01 - 04/30 353 - delete old /tmp/filelist.full,biggielist.txt if found when restoring to 354 live filesystem 355 - replace MONDO_VERSION #define with VERSION from ../config.h 356 - write fname of bigfile to screen when having trouble reading/comparing it 357 - if restoring to live filesystem then wipe /tmp/tmpfs/ * afterwards 358 - removed spurious finish(0) from main() 359 360 03/01 - 03/31/2002 361 - if /tmp/m*ndo-restore.cfg not found then assume live restore; restore 362 to / instead of /mnt/RESTORING 363 - clean up is_file_in_list() to deal with the /mnt/RESTORING/ prefix 364 - exclude leading '/' from filelist.restore-these 365 - if /tmp/fstab.new exists then use _it_ instead of /tmp/fstab to label 366 ext2 or ext3 partitions 367 - improved logging 368 369 [...] 370 371 07/10/2001 --- first incarnation 372 */ 373 2 * $Id$ 3 */ 374 4 375 5 /** … … 381 11 * #include statements * 382 12 **************************************************************************/ 13 #include <unistd.h> 14 383 15 #include "../common/my-stuff.h" 384 16 #include "../common/mondostructures.h" … … 443 75 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode. 444 76 */ 445 char *g_isodir_device ;77 char *g_isodir_device = NULL; 446 78 447 79 /** 448 80 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode. 449 81 */ 450 char *g_isodir_format ;82 char *g_isodir_format = NULL; 451 83 452 84 /** 453 85 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set. 454 86 */ 455 char *g_biggielist_txt ;87 char *g_biggielist_txt = NULL; 456 88 457 89 /** … … 459 91 * the current archive set. 460 92 */ 461 char *g_filelist_full ;93 char *g_filelist_full = NULL; 462 94 463 95 /** … … 465 97 * as images, not as individual files. 466 98 */ 467 char *g_filelist_imagedevs ;99 char *g_filelist_imagedevs = NULL; 468 100 469 101 /** … … 471 103 * @see g_filelist_imagedevs 472 104 */ 473 char *g_imagedevs_restthese ;105 char *g_imagedevs_restthese = NULL; 474 106 475 107 /** … … 477 109 * information for this backup. 478 110 */ 479 char *g_mondo_cfg_file ;111 char *g_mondo_cfg_file = NULL; 480 112 481 113 /** … … 483 115 * user's partitions and hard drives. 484 116 */ 485 char *g_mountlist_fname ;117 char *g_mountlist_fname = NULL; 486 118 487 119 /** … … 489 121 * to avoid link errors. 490 122 */ 491 char *g_mondo_home ;123 char *g_mondo_home = NULL; 492 124 493 125 /* @} - end of "Restore-Time Globals" in globalGroup */ 494 495 496 126 497 127 extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, 498 128 char direction); 499 500 501 129 502 130 /************************************************************************** … … 508 136 */ 509 137 #define COMPAQ_PROLIANTS_SUCK _("Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo CD/floppy in Interactive Mode.") 510 511 512 138 513 139 … … 561 187 562 188 563 564 565 566 189 /** 567 190 * Determine whether @p mountlist contains a Compaq diagnostic partition. … … 604 227 popup_and_OK(COMPAQ_PROLIANTS_SUCK); 605 228 if (ask_me_yes_or_no 606 (_("Would you like to reboot and use your Compaq CD to prep your hard drive?"))) 229 (_ 230 ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))) 607 231 { 608 fatal_error 609 (_("Aborting. Please reboot and prep your hard drive with your Compaq CD."));232 fatal_error(_ 233 ("Aborting. Please reboot and prep your hard drive with your Compaq CD.")); 610 234 } 611 235 } … … 614 238 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK * 615 239 **************************************************************************/ 616 617 240 618 241 … … 637 260 assert(mountlist != NULL); 638 261 assert(raidlist != NULL); 639 malloc_string(tmp);640 262 iamhere("pre wrm"); 641 263 c = which_restore_mode(); … … 644 266 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 645 267 } else { 646 popup_and_OK(_("No restoring or comparing will take place today.")); 268 popup_and_OK(_ 269 ("No restoring or comparing will take place today.")); 647 270 if (is_this_device_mounted("/mnt/cdrom")) { 648 271 run_program_and_log_output("umount /mnt/cdrom", FALSE); 649 272 } 650 273 if (g_ISO_restore_mode) { 651 sprintf(tmp, "umount %s", bkpinfo->isodir);274 asprintf(&tmp, "umount %s", bkpinfo->isodir); 652 275 run_program_and_log_output(tmp, FALSE); 276 paranoid_free(tmp); 653 277 } 654 278 paranoid_MR_finish(0); … … 677 301 retval += compare_mode(bkpinfo, mountlist, raidlist); 678 302 } 679 paranoid_free(tmp);680 303 return (retval); 681 304 } … … 726 349 727 350 728 729 730 351 /** 731 352 * @addtogroup restoreGroup … … 754 375 bool restore_all; 755 376 756 /** needs malloc **********/ 757 char *tmp ;758 char *fstab_fname ;759 char *old_restpath ;760 761 struct s_node *filelist ;377 char *tmp = NULL; 378 char *tmp1 = NULL; 379 char *fstab_fname = NULL; 380 char *old_restpath = NULL; 381 382 struct s_node *filelist = NULL; 762 383 763 384 /* try to partition and format */ … … 765 386 log_msg(2, "interactive_mode --- starting (great, assertions OK)"); 766 387 767 malloc_string(tmp);768 malloc_string(fstab_fname);769 malloc_string(old_restpath);770 388 assert(bkpinfo != NULL); 771 389 assert(mountlist != NULL); … … 776 394 if (g_text_mode) { 777 395 if (!ask_me_yes_or_no 778 (_("Interactive Mode + textonly = experimental! Proceed anyway?"))) 396 (_ 397 ("Interactive Mode + textonly = experimental! Proceed anyway?"))) 779 398 { 780 399 fatal_error("Wise move."); … … 787 406 iamhere("Done loading config file; resizing ML"); 788 407 #ifdef __FreeBSD__ 789 if (strstr 790 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 791 "noresize")) 408 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 792 409 #else 793 if (strstr 794 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 795 "noresize")) 410 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 796 411 #endif 797 {412 if (strstr(tmp,"noresize")) { 798 413 log_msg(1, "Not resizing mountlist."); 799 414 } else { … … 804 419 if (g_text_mode) { 805 420 save_mountlist_to_disk(mountlist, g_mountlist_fname); 806 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 421 tmp1 = find_my_editor(); 422 asprintf(&tmp, "%s %s", tmp1, g_mountlist_fname); 423 paranoid_free(tmp1); 424 807 425 res = system(tmp); 426 paranoid_free(tmp); 808 427 load_mountlist(mountlist, g_mountlist_fname); 809 428 } else { … … 819 438 mvaddstr_and_log_it(1, 30, _("Restoring Interactively")); 820 439 if (bkpinfo->differential) { 821 log_to_screen(_("Because this is a differential backup, disk")); 822 log_to_screen 823 (_(" partitioning and formatting will not take place.")); 440 log_to_screen(_ 441 ("Because this is a differential backup, disk")); 442 log_to_screen(_ 443 (" partitioning and formatting will not take place.")); 824 444 done = TRUE; 825 445 } else { 826 446 if (ask_me_yes_or_no 827 (_("Do you want to erase and partition your hard drives?"))) { 447 (_ 448 ("Do you want to erase and partition your hard drives?"))) 449 { 828 450 if (partition_table_contains_Compaq_diagnostic_partition 829 451 (mountlist)) { … … 836 458 if (ptn_errs) { 837 459 log_to_screen 838 (_("Warning. Errors occurred during disk partitioning.")); 460 (_ 461 ("Warning. Errors occurred during disk partitioning.")); 839 462 } 840 463 841 fmt_errs = format_everything(mountlist, FALSE, raidlist); 464 fmt_errs = 465 format_everything(mountlist, FALSE, raidlist); 842 466 if (!fmt_errs) { 843 467 log_to_screen 844 (_("Errors during disk partitioning were handled OK.")); 845 log_to_screen 846 (_("Partitions were formatted OK despite those errors.")); 468 (_ 469 ("Errors during disk partitioning were handled OK.")); 470 log_to_screen(_ 471 ("Partitions were formatted OK despite those errors.")); 847 472 ptn_errs = 0; 848 473 } … … 854 479 } else { 855 480 mvaddstr_and_log_it(g_currentY++, 0, 856 _("User opted not to partition the devices")); 481 _ 482 ("User opted not to partition the devices")); 857 483 if (ask_me_yes_or_no 858 484 (_("Do you want to format your hard drives?"))) { 859 fmt_errs = format_everything(mountlist, TRUE, raidlist); 485 fmt_errs = 486 format_everything(mountlist, TRUE, raidlist); 860 487 if (!fmt_errs) { 861 488 done = TRUE; … … 869 496 mvaddstr_and_log_it(g_currentY++, 870 497 0, 871 _("Errors occurred. Please repartition and format drives manually.")); 498 _ 499 ("Errors occurred. Please repartition and format drives manually.")); 872 500 done = FALSE; 873 501 } … … 875 503 mvaddstr_and_log_it(g_currentY++, 876 504 0, 877 _("Errors occurred during partitioning. Formatting, however, went OK.")); 505 _ 506 ("Errors occurred during partitioning. Formatting, however, went OK.")); 878 507 done = TRUE; 879 508 } … … 881 510 if (!ask_me_yes_or_no(_("Re-edit the mountlist?"))) { 882 511 retval++; 883 goto end_of_func; 512 iamhere("Leaving interactive_mode()"); 513 return (retval); 884 514 } 885 515 } … … 891 521 unmount_all_devices(mountlist); 892 522 retval++; 893 goto end_of_func; 523 iamhere("Leaving interactive_mode()"); 524 return (retval); 894 525 } 895 526 /* restore */ 896 527 if ((restore_all = 897 ask_me_yes_or_no(_("Do you want me to restore all of your data?")))) 528 ask_me_yes_or_no(_ 529 ("Do you want me to restore all of your data?")))) 898 530 { 899 531 log_msg(1, "Restoring all data"); 900 532 retval += restore_everything(bkpinfo, NULL); 901 } else 902 if ((restore_all = 533 } else if ((restore_all = 903 534 ask_me_yes_or_no 904 535 (_("Do you want me to restore _some_ of your data?")))) { 905 strcpy(old_restpath, bkpinfo->restore_path);536 old_restpath = bkpinfo->restore_path; 906 537 for (done = FALSE; !done;) { 907 538 unlink("/tmp/filelist.full"); … … 912 543 if (filelist) { 913 544 gotos_suck: 914 strcpy(tmp, old_restpath);915 545 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING); 916 546 if (popup_and_get_string 917 (_("Restore path"), _("Restore files to where?"), tmp, 918 MAX_STR_LEN / 4)) { 919 if (!strcmp(tmp, "/")) { 547 (_("Restore path"), _("Restore files to where?"), bkpinfo->restore_path)) { 548 if (!strcmp(bkpinfo->restore_path, "/")) { 920 549 if (!ask_me_yes_or_no(_("Are you sure?"))) { 550 paranoid_free(bkpinfo->restore_path); 551 bkpinfo->restore_path = old_restpath; 921 552 goto gotos_suck; 922 553 } 923 tmp[0] = '\0'; // so we restore to [blank]/file/name :)554 paranoid_alloc(bkpinfo->restore_path, ""); // so we restore to [blank]/file/name :) 924 555 } 925 strcpy(bkpinfo->restore_path, tmp);926 556 log_msg(1, "Restoring subset"); 927 557 retval += restore_everything(bkpinfo, filelist); 928 558 free_filelist(filelist); 929 559 } else { 930 strcpy(bkpinfo->restore_path, old_restpath);560 bkpinfo->restore_path = old_restpath; 931 561 free_filelist(filelist); 932 562 } … … 939 569 } 940 570 } 941 strcpy(old_restpath, bkpinfo->restore_path);942 571 } else { 943 572 mvaddstr_and_log_it(g_currentY++, 944 573 0, 945 _("User opted not to restore any data. ")); 574 _ 575 ("User opted not to restore any data. ")); 946 576 } 947 577 if (retval) { 948 578 mvaddstr_and_log_it(g_currentY++, 949 579 0, 950 _("Errors occurred during the restore phase. ")); 580 _ 581 ("Errors occurred during the restore phase. ")); 951 582 } 952 583 … … 956 587 mvaddstr_and_log_it(g_currentY++, 957 588 0, 958 _("User opted not to initialize the boot loader.")); 589 _ 590 ("User opted not to initialize the boot loader.")); 959 591 } 960 592 961 593 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 962 594 protect_against_braindead_sysadmins(); 963 // modify_rclocal_one_time( MNT_RESTORING "/etc" );964 595 retval += unmount_all_devices(mountlist); 965 596 /* if (restore_some || restore_all || */ … … 967 598 (_("Label your ext2 and ext3 partitions if necessary?"))) { 968 599 mvaddstr_and_log_it(g_currentY, 0, 969 _("Using e2label to label your ext2,3 partitions")); 600 _ 601 ("Using e2label to label your ext2,3 partitions")); 970 602 if (does_file_exist("/tmp/fstab.new")) { 971 strcpy(fstab_fname, "/tmp/fstab.new");603 asprintf(&fstab_fname, "/tmp/fstab.new"); 972 604 } else { 973 strcpy(fstab_fname, "/tmp/fstab");974 } 975 sprintf(tmp,605 asprintf(&fstab_fname, "/tmp/fstab"); 606 } 607 asprintf(&tmp, 976 608 "label-partitions-as-necessary %s < %s >> %s 2>> %s", 977 609 g_mountlist_fname, fstab_fname, MONDO_LOGFILE, 978 610 MONDO_LOGFILE); 611 paranoid_free(fstab_fname); 612 979 613 res = system(tmp); 614 paranoid_free(tmp); 980 615 if (res) { 981 616 log_to_screen … … 992 627 mvaddstr_and_log_it(g_currentY++, 993 628 0, 994 _("Warning - errors occurred during the restore phase.")); 995 } 996 end_of_func: 997 paranoid_free(tmp); 998 paranoid_free(fstab_fname); 999 paranoid_free(old_restpath); 1000 iamhere("Leaving interactive_mode()"); 1001 return (retval); 629 _ 630 ("Warning - errors occurred during the restore phase.")); 631 } 1002 632 } 1003 633 … … 1005 635 *END_INTERACTIVE_MODE * 1006 636 **************************************************************************/ 1007 1008 637 1009 638 … … 1054 683 if (system("umount /tmp/isodir 2> /dev/null")) { 1055 684 log_to_screen 1056 (_("WARNING - unable to unmount device where the ISO files are stored.")); 685 (_ 686 ("WARNING - unable to unmount device where the ISO files are stored.")); 1057 687 } 1058 688 // } … … 1065 695 1066 696 1067 /* MONDO - saving your a$$ since Feb 18th, 2000 */ 1068 1069 697 static void call_me_after_the_nuke(int retval) { 698 699 char *tmp = NULL; 700 char *tmp1 = NULL; 701 702 if (retval) { 703 log_to_screen(_("Errors occurred during the nuke phase.")); 704 log_to_screen(_("Please visit our website at http://www.mondorescue.org for more information.")); 705 } else { 706 #ifdef __FreeBSD__ 707 tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 708 #else 709 tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 710 #endif 711 if ((strstr(tmp1,"restore") == NULL) || 712 (strstr(tmp1,"RESTORE") == NULL)) { 713 /* -H option */ 714 asprintf(&tmp, 715 _ 716 (" Mondo has restored your system. Please remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.")); 717 popup_and_OK(tmp); 718 paranoid_free(tmp); 719 } 720 paranoid_free(tmp1); 721 722 log_to_screen(_ 723 ("Mondo has restored your system. Please remove the backup media and reboot.")); 724 log_to_screen(_ 725 ("Thank you for using Mondo Rescue.")); 726 log_to_screen(_ 727 ("Please visit our website at http://www.mondorescue.org for more information.")); 728 } 729 g_I_have_just_nuked = TRUE; 730 return; 731 } 1070 732 1071 733 … … 1087 749 int res = 0; 1088 750 bool boot_loader_installed = FALSE; 1089 /** malloc **/ 1090 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], 1091 tmpC[MAX_STR_LEN]; 751 char *tmp = NULL; 752 char tmpA[MAX_STR_LEN]; 753 char tmpB[MAX_STR_LEN]; 754 char tmpC[MAX_STR_LEN]; 1092 755 1093 756 assert(bkpinfo != NULL); … … 1100 763 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1101 764 #ifdef __FreeBSD__ 1102 if (strstr 1103 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 1104 "noresize")) 765 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 1105 766 #else 1106 if (strstr 1107 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 1108 "noresize")) 767 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 1109 768 #endif 1110 {769 if (strstr(tmp,"noresize")) { 1111 770 log_msg(2, "Not resizing mountlist."); 1112 771 } else { 1113 772 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 1114 773 } 774 paranoid_free(tmp); 775 1115 776 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) { 1116 sprintf(tmp, 1117 _("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"), 777 asprintf(&tmp, 778 _ 779 ("Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?"), 1118 780 tmpA, tmpB, tmpC); 1119 781 if (ask_me_yes_or_no(tmp)) { 782 paranoid_free(tmp); 1120 783 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1121 784 finish(retval); 1122 785 } else { 786 paranoid_free(tmp); 1123 787 fatal_error("Nuke Mode aborted. "); 1124 788 } … … 1128 792 if (bkpinfo->differential) { 1129 793 log_to_screen(_("Because this is a differential backup, disk")); 1130 log_to_screen(_("partitioning and formatting will not take place.")); 794 log_to_screen(_ 795 ("partitioning and formatting will not take place.")); 1131 796 res = 0; 1132 797 } else { … … 1138 803 g_fprep = fopen("/tmp/prep.sh", "w"); 1139 804 #ifdef __FreeBSD__ 1140 if (strstr 1141 (call_program_and_get_last_line_of_output 1142 ("cat /tmp/cmdline"), "nopart")) 805 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 1143 806 #else 1144 if (strstr 1145 (call_program_and_get_last_line_of_output 1146 ("cat /proc/cmdline"), "nopart")) 807 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 1147 808 #endif 1148 {809 if (strstr(tmp,,"nopart")) { 1149 810 log_msg(2, 1150 811 "Not partitioning drives due to 'nopart' option."); … … 1154 815 if (res) { 1155 816 log_to_screen 1156 (_("Warning. Errors occurred during partitioning.")); 817 (_ 818 ("Warning. Errors occurred during partitioning.")); 1157 819 res = 0; 1158 820 } 1159 821 } 822 paranoid_free(tmp); 823 1160 824 retval += res; 1161 825 if (!res) { 1162 826 log_to_screen(_("Preparing to format your disk(s)")); 1163 827 sleep(1); 1164 system("sync"); 1165 log_to_screen(_("Please wait. This may take a few minutes.")); 828 sync(); 829 log_to_screen(_ 830 ("Please wait. This may take a few minutes.")); 1166 831 res += format_everything(mountlist, FALSE, raidlist); 1167 832 } … … 1173 838 mvaddstr_and_log_it(g_currentY++, 1174 839 0, 1175 _("Failed to partition and/or format your hard drives.")); 840 _ 841 ("Failed to partition and/or format your hard drives.")); 1176 842 1177 843 if (ask_me_yes_or_no(_("Try in interactive mode instead?"))) { 1178 844 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1179 goto after_the_nuke;845 call_me_after_the_nuke(retval); 1180 846 } else 1181 847 if (!ask_me_yes_or_no 1182 848 (_("Would you like to try to proceed anyway?"))) { 1183 return (retval);1184 }849 } 850 return(retval); 1185 851 } 1186 852 retval = mount_all_devices(mountlist, TRUE); … … 1188 854 unmount_all_devices(mountlist); 1189 855 log_to_screen 1190 (_("Unable to mount all partitions. Sorry, I cannot proceed.")); 856 (_ 857 ("Unable to mount all partitions. Sorry, I cannot proceed.")); 1191 858 return (retval); 1192 859 } … … 1200 867 protect_against_braindead_sysadmins(); 1201 868 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1202 // modify_rclocal_one_time( MNT_RESTORING "/etc" );1203 869 retval += unmount_all_devices(mountlist); 1204 870 mvaddstr_and_log_it(g_currentY, 1205 871 0, 1206 _("Using e2label to label your ext2,3 partitions")); 1207 1208 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab", 872 _ 873 ("Using e2label to label your ext2,3 partitions")); 874 875 asprintf(&tmp, "label-partitions-as-necessary %s < /tmp/fstab", 1209 876 g_mountlist_fname); 1210 877 res = run_program_and_log_output(tmp, TRUE); 878 paranoid_free(tmp); 879 1211 880 if (res) { 1212 log_to_screen(_("label-partitions-as-necessary returned an error")); 881 log_to_screen(_ 882 ("label-partitions-as-necessary returned an error")); 1213 883 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1214 884 } else { … … 1216 886 } 1217 887 retval += res; 1218 1219 after_the_nuke: 1220 if (retval) { 1221 log_to_screen(_("Errors occurred during the nuke phase.")); 1222 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1223 { 1224 log_to_screen 1225 (_("PC was restored successfully. Thank you for using Mondo Rescue.")); 1226 log_to_screen 1227 (_("Please visit our website at http://www.mondorescue.org for more information.")); 1228 } else { 1229 strcpy(tmp,_(" Mondo has restored your system. Please remove the backup media and reboot.\n\nPlease visit our website at http://www.mondorescue.org for more information.")); 1230 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) { 1231 popup_and_OK(tmp); 1232 } 1233 log_to_screen 1234 (_("Mondo has restored your system. Please remove the backup media and reboot.")); 1235 log_to_screen 1236 (_("Please visit our website at http://www.mondorescue.org for more information.")); 1237 } 1238 g_I_have_just_nuked = TRUE; 1239 /* 1240 if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE)) 1241 { 1242 log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR"); 1243 write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr"); 1244 } 1245 */ 1246 return (retval); 888 call_me_after_the_nuke(retval); 889 return(retval); 1247 890 } 1248 1249 891 /************************************************************************** 1250 892 *END_NUKE_MODE * 1251 893 **************************************************************************/ 1252 1253 894 1254 895 … … 1263 904 int retval = 0; 1264 905 1265 /** malloc **/ 1266 char *old_restpath; 1267 1268 struct mountlist_itself *mountlist; 1269 // static 1270 struct raidlist_itself *raidlist; 1271 struct s_node *filelist; 906 char *old_restpath = NULL; 907 908 struct mountlist_itself *mountlist = NULL; 909 struct raidlist_itself *raidlist = NULL; 910 struct s_node *filelist = NULL; 1272 911 1273 912 log_msg(1, "restore_to_live_filesystem() - starting"); 1274 913 assert(bkpinfo != NULL); 1275 malloc_string(old_restpath); 914 1276 915 mountlist = malloc(sizeof(struct mountlist_itself)); 1277 916 raidlist = malloc(sizeof(struct raidlist_itself)); 917 1278 918 if (!mountlist || !raidlist) { 1279 919 fatal_error("Cannot malloc() mountlist and/or raidlist"); 1280 920 } 1281 921 1282 strcpy(bkpinfo->restore_path, "/");922 paranoid_alloc(bkpinfo->restore_path, "/"); 1283 923 if (!g_restoring_live_from_cd) { 1284 924 popup_and_OK 1285 (_("Please insert tape/CD/boot floppy, then hit 'OK' to continue.")); 925 (_ 926 ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.")); 1286 927 sleep(1); 1287 928 } … … 1308 949 if (filelist) { 1309 950 save_filelist(filelist, "/tmp/selected-files.txt"); 1310 strcpy(old_restpath, bkpinfo->restore_path);951 old_restpath = bkpinfo->restore_path; 1311 952 if (popup_and_get_string(_("Restore path"), 1312 953 _("Restore files to where? )"), 1313 bkpinfo->restore_path , MAX_STR_LEN / 4)) {954 bkpinfo->restore_path)) { 1314 955 iamhere("Restoring everything"); 1315 956 retval += restore_everything(bkpinfo, filelist); 1316 free_filelist(filelist); 1317 strcpy(bkpinfo->restore_path, old_restpath); 1318 } else { 1319 free_filelist(filelist); 1320 } 1321 strcpy(bkpinfo->restore_path, old_restpath); 957 } 958 free_filelist(filelist); 959 bkpinfo->restore_path = old_restpath; 1322 960 } 1323 961 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { … … 1329 967 eject_device(bkpinfo->media_device); 1330 968 } 1331 paranoid_free(old_restpath);1332 969 free(mountlist); 1333 970 free(raidlist); … … 1358 995 * @return 0 for success (or skip), nonzero for failure. 1359 996 */ 1360 int 997 char * 1361 998 restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo, 1362 999 long bigfileno, 1363 struct s_node *filelist, 1364 char *pathname_of_last_file_restored) 1000 struct s_node *filelist) 1365 1001 { 1366 FILE *fin; 1367 FILE *fout; 1368 FILE *fbzip2; 1369 1370 /** malloc ***/ 1371 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1372 *ntfsprog_command, *suffix, *sz_devfile; 1373 char *bigblk; 1374 char *p; 1002 FILE *fin = NULL; 1003 FILE *fout = NULL; 1004 FILE *fbzip2 = NULL; 1005 char *checksum = NULL; 1006 char *outfile_fname = NULL; 1007 char *tmp = NULL; 1008 char *tmp1 = NULL; 1009 char *tmp2 = NULL; 1010 char *tmp3 = NULL; 1011 char *bzip2_command = NULL; 1012 char *bigblk = NULL; 1013 char *pathname_of_last_file_restored = NULL; 1375 1014 int retval = 0; 1376 1015 int finished = FALSE; 1377 1016 long sliceno; 1378 1017 long siz; 1379 char ntfsprog_fifo[MAX_STR_LEN]; 1018 long siz1; 1019 char *ntfsprog_fifo = NULL; 1380 1020 char *file_to_openout = NULL; 1381 1021 struct s_filename_and_lstat_info biggiestruct; 1382 struct utimbuf the_utime_buf, *ubuf ;1022 struct utimbuf the_utime_buf, *ubuf = NULL; 1383 1023 bool use_ntfsprog_hack = FALSE; 1384 1024 pid_t pid; 1385 1025 int res = 0; 1386 1026 int old_loglevel; 1387 char sz_msg[MAX_STR_LEN];1388 struct s_node *node ;1027 char *sz_msg; 1028 struct s_node *node = NULL; 1389 1029 1390 1030 old_loglevel = g_loglevel; … … 1392 1032 assert(bkpinfo != NULL); 1393 1033 1394 malloc_string(checksum);1395 malloc_string(outfile_fname);1396 malloc_string(tmp);1397 malloc_string(bzip2_command);1398 malloc_string(ntfsprog_command);1399 malloc_string(suffix);1400 malloc_string(sz_devfile);1401 1402 pathname_of_last_file_restored[0] = '\0';1403 1034 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) { 1404 1035 fatal_error("Cannot malloc bigblk"); 1405 1036 } 1406 1037 1407 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 1038 tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, ""); 1039 if (!(fin = fopen(tmp,"r"))) { 1408 1040 log_to_screen(_("Cannot even open bigfile's info file")); 1409 return (1); 1410 } 1041 paranoid_free(tmp); 1042 return (pathname_of_last_file_restored); 1043 } 1044 paranoid_free(tmp); 1411 1045 1412 1046 memset((void *) &biggiestruct, 0, sizeof(biggiestruct)); … … 1418 1052 paranoid_fclose(fin); 1419 1053 1420 strcpy(checksum, biggiestruct.checksum);1054 asprintf(&checksum, biggiestruct.checksum); 1421 1055 1422 1056 if (!checksum[0]) { 1423 sprintf(tmp, "Warning - bigfile %ld does not have a checksum",1057 asprintf(&tmp, "Warning - bigfile %ld does not have a checksum", 1424 1058 bigfileno + 1); 1425 1059 log_msg(3, tmp); 1060 paranoid_free(tmp); 1061 /* BERLIOS : Useless ??? 1426 1062 p = checksum; 1427 } 1063 */ 1064 } 1065 paranoid_free(checksum); 1428 1066 1429 1067 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :) 1430 1068 { 1431 strcpy(outfile_fname, biggiestruct.filename);1069 asprintf(&outfile_fname, biggiestruct.filename); 1432 1070 } else { 1433 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,1071 asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path, 1434 1072 biggiestruct.filename); 1435 1073 } … … 1441 1079 log_msg(0, "Skipping %s (name isn't in filelist)", 1442 1080 biggiestruct.filename); 1443 pathname_of_last_file_restored[0] = '\0'; 1444 return (0); 1081 return (pathname_of_last_file_restored); 1445 1082 } else if (!(node->selected)) { 1446 1083 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1447 1084 biggiestruct.filename); 1448 pathname_of_last_file_restored[0] = '\0'; 1449 return (0); 1085 return (pathname_of_last_file_restored); 1450 1086 } 1451 1087 } … … 1470 1106 "Calling ntfsclone in background because %s is an NTFS /dev entry", 1471 1107 outfile_fname); 1472 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),1108 asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768), 1473 1109 (int) (random() % 32768)); 1474 mkfifo( sz_devfile, 0x770);1475 strcpy(ntfsprog_fifo, sz_devfile); 1110 mkfifo(ntfsprog_fifo, 0x770); 1111 1476 1112 file_to_openout = ntfsprog_fifo; 1477 1113 switch (pid = fork()) { … … 1484 1120 res = 1485 1121 feed_outfrom_ntfsprog(biggiestruct.filename, 1486 1122 ntfsprog_fifo); 1487 1123 // log_msg(3, "CHILD - fip - exiting"); 1488 1124 exit(res); … … 1493 1129 (long int) (pid)); 1494 1130 } 1131 // BERLIOS: Is it the right place ?? 1132 paranoid_free(ntfsprog_fifo); 1495 1133 } else { 1496 1134 use_ntfsprog_hack = FALSE; 1497 ntfsprog_fifo[0] = '\0';1498 1135 file_to_openout = outfile_fname; 1499 1136 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1503 1140 } 1504 1141 1505 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,1142 asprintf(&tmp, "Reassembling big file %ld (%s)", bigfileno + 1, 1506 1143 outfile_fname); 1507 1144 log_msg(2, tmp); 1145 paranoid_free(tmp); 1508 1146 1509 1147 /* … … 1513 1151 */ 1514 1152 1515 strncpy(pathname_of_last_file_restored, biggiestruct.filename, 1516 MAX_STR_LEN - 1); 1517 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1153 asprintf(&pathname_of_last_file_restored, biggiestruct.filename); 1518 1154 1519 1155 log_msg(3, "file_to_openout = %s", file_to_openout); 1520 1156 if (!(fout = fopen(file_to_openout, "w"))) { 1521 1157 log_to_screen(_("Cannot openout outfile_fname - hard disk full?")); 1522 return ( 1);1158 return (pathname_of_last_file_restored); 1523 1159 } 1524 1160 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> ntfsclone --> hard disk itself 1525 1161 1526 1162 for (sliceno = 1, finished = FALSE; !finished;) { 1527 if (!does_file_exist 1528 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) 1529 && 1530 !does_file_exist(slice_fname 1531 (bigfileno, sliceno, ARCHIVES_PATH, "lzo")) 1532 && 1533 !does_file_exist(slice_fname 1534 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1163 tmp = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""); 1164 tmp1 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"); 1165 tmp2 = slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"); 1166 if (!does_file_exist(tmp) && !does_file_exist(tmp1) && 1167 !does_file_exist(tmp2)) { 1535 1168 log_msg(3, 1536 1169 "Cannot find a data slice or terminator slice on CD %d", 1537 1170 g_current_media_number); 1538 1171 g_current_media_number++; 1539 sprintf(tmp,1172 asprintf(&tmp3, 1540 1173 "Asking for %s #%d so that I may read slice #%ld\n", 1541 1174 media_descriptor_string(bkpinfo->backup_media_type), 1542 1175 g_current_media_number, sliceno); 1543 log_msg(2, tmp); 1544 sprintf(tmp, _("Restoring from %s #%d"), 1176 log_msg(2, tmp3); 1177 paranoid_free(tmp3); 1178 1179 asprintf(&tmp3, _("Restoring from %s #%d"), 1545 1180 media_descriptor_string(bkpinfo->backup_media_type), 1546 1181 g_current_media_number); 1547 log_to_screen(tmp); 1182 log_to_screen(tmp3); 1183 paranoid_free(tmp3); 1184 1548 1185 insist_on_this_cd_number(bkpinfo, g_current_media_number); 1549 1186 log_to_screen(_("Continuing to restore.")); 1550 1187 } else { 1551 strcpy(tmp,1552 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));1553 1188 if (does_file_exist(tmp) && length_of_file(tmp) == 0) { 1554 1189 log_msg(2, … … 1558 1193 continue; 1559 1194 } else { 1560 if (does_file_exist 1561 (slice_fname 1562 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1563 strcpy(bzip2_command, "lzop"); 1564 strcpy(suffix, "lzo"); 1565 } else 1566 if (does_file_exist 1567 (slice_fname 1568 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1569 strcpy(bzip2_command, "bzip2"); 1570 strcpy(suffix, "bz2"); 1571 } else 1572 if (does_file_exist 1573 (slice_fname 1574 (bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1575 strcpy(bzip2_command, ""); 1576 strcpy(suffix, ""); 1195 if (does_file_exist(tmp1)) { 1196 asprintf(&bzip2_command, "lzop -dc %s 2>> %s",tmp1, MONDO_LOGFILE); 1197 } else if (does_file_exist(tmp2)) { 1198 asprintf(&bzip2_command, "bzip2 -dc %s 2>> %s",tmp2, MONDO_LOGFILE); 1199 } else if (does_file_exist(tmp)) { 1200 asprintf(&bzip2_command, ""); 1577 1201 } else { 1578 1202 log_to_screen(_("OK, that's pretty fsck0red...")); 1579 return ( 1);1203 return (pathname_of_last_file_restored); 1580 1204 } 1581 1205 } 1582 if (bzip2_command[0] != '\0') { 1583 sprintf(bzip2_command + strlen(bzip2_command), 1584 " -dc %s 2>> %s", 1585 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1586 suffix), MONDO_LOGFILE); 1587 } else { 1588 sprintf(bzip2_command, "cat %s 2>> %s", 1589 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1590 suffix), MONDO_LOGFILE); 1591 } 1592 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", 1206 1207 if (bzip2_command == NULL) { 1208 asprintf(&bzip2_command, "cat %s 2>> %s", tmp, MONDO_LOGFILE); 1209 } 1210 asprintf(&tmp3, "Working on %s #%d, file #%ld, slice #%ld ", 1593 1211 media_descriptor_string(bkpinfo->backup_media_type), 1594 1212 g_current_media_number, bigfileno + 1, sliceno); 1595 log_msg(2, tmp); 1596 1213 log_msg(2, tmp3); 1597 1214 if (!g_text_mode) { 1598 newtDrawRootText(0, g_noof_rows - 2, tmp );1215 newtDrawRootText(0, g_noof_rows - 2, tmp3); 1599 1216 newtRefresh(); 1600 strip_spaces(tmp); 1601 update_progress_form(tmp); 1602 } 1217 update_progress_form(tmp3); 1218 } 1219 paranoid_free(tmp3); 1220 1603 1221 if (!(fbzip2 = popen(bzip2_command, "r"))) { 1604 1222 fatal_error("Can't run popen command"); 1605 1223 } 1224 paranoid_free(bzip2_command); 1225 1606 1226 while (!feof(fbzip2)) { 1607 1227 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2); 1608 1228 if (siz > 0) { 1609 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1610 siz = fwrite(bigblk, 1, siz, fout); 1611 sprintf(sz_msg + strlen(sz_msg), 1612 "; written %ld to fout", siz); 1613 // log_msg(2. sz_msg); 1229 siz1 = fwrite(bigblk, 1, siz, fout); 1230 asprintf(&sz_msg, "Read %ld from fbzip2; written %ld to fout", siz, siz1); 1231 log_it(sz_msg); 1232 paranoid_free(sz_msg); 1614 1233 } 1615 1234 } … … 1620 1239 g_current_progress++; 1621 1240 } 1622 } 1623 /* 1624 memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy... 1625 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1626 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1627 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1628 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1629 */ 1241 paranoid_free(tmp); 1242 paranoid_free(tmp1); 1243 paranoid_free(tmp2); 1244 } 1630 1245 paranoid_fclose(fout); 1631 1246 g_loglevel = old_loglevel; … … 1633 1248 if (use_ntfsprog_hack) { 1634 1249 log_msg(3, "Waiting for ntfsclone to finish"); 1635 sprintf(tmp,1250 asprintf(&tmp, 1636 1251 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1637 1252 while (system(tmp) == 0) { 1638 1253 sleep(1); 1639 1254 } 1255 paranoid_free(tmp); 1640 1256 log_it("OK, ntfsclone has really finished"); 1641 1257 } … … 1649 1265 utime(outfile_fname, ubuf); 1650 1266 } 1267 paranoid_free(outfile_fname); 1651 1268 paranoid_free(bigblk); 1652 paranoid_free(checksum); 1653 paranoid_free(outfile_fname); 1654 paranoid_free(tmp); 1655 paranoid_free(bzip2_command); 1656 paranoid_free(ntfsprog_command); 1657 paranoid_free(suffix); 1658 paranoid_free(sz_devfile); 1659 1660 return (retval); 1269 1270 return (pathname_of_last_file_restored); 1661 1271 } 1272 1662 1273 1663 1274 /************************************************************************** 1664 1275 *END_ RESTORE_A_BIGGIEFILE_FROM_CD * 1665 1276 **************************************************************************/ 1666 1667 1277 1668 1278 … … 1674 1284 * @param orig_bf_fname The original filename of the biggiefile. 1675 1285 * @param biggiefile_number The number of the biggiefile (starting from 0). 1676 * @param orig_checksum Unused.1677 * @param biggiefile_size Unused.1678 1286 * @param filelist The node structure containing the list of files to be restored. 1679 1287 * If @p orig_bf_fname is not in the list, it will be ignored. 1680 1288 * @return 0 for success (or skip), nonzero for failure. 1681 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL). 1682 */ 1683 int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED 1684 long long biggiefile_size, //UNUSED 1289 */ 1290 char *restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, 1685 1291 struct s_node *filelist, 1686 int use_ntfsprog, 1687 char *pathname_of_last_file_restored) 1292 int use_ntfsprog) 1688 1293 { 1689 1294 FILE *pout; … … 1691 1296 1692 1297 /** mallocs ********/ 1693 char *tmp ;1694 char * command;1695 char * outfile_fname;1696 char * ntfsprog_command;1697 char * sz_devfile;1698 char *ntfsprog_fifo ;1298 char *tmp = NULL; 1299 char *tmp1 = NULL; 1300 char *command = NULL; 1301 char *outfile_fname = NULL; 1302 char *ntfsprog_command = NULL; 1303 char *ntfsprog_fifo = NULL; 1699 1304 char *file_to_openout = NULL; 1305 char *pathname_of_last_file_restored = NULL; 1700 1306 1701 1307 struct s_node *node; … … 1714 1320 ubuf = &the_utime_buf; 1715 1321 1716 malloc_string(tmp);1717 malloc_string(ntfsprog_fifo);1718 malloc_string(outfile_fname);1719 malloc_string(command);1720 malloc_string(sz_devfile);1721 malloc_string(ntfsprog_command);1722 1322 old_loglevel = g_loglevel; 1723 1323 assert(bkpinfo != NULL); 1724 1324 assert(orig_bf_fname != NULL); 1725 assert(orig_checksum != NULL); 1726 1727 pathname_of_last_file_restored[0] = '\0'; 1325 1728 1326 if (use_ntfsprog == BLK_START_A_PIHBIGGIE) { 1729 1327 use_ntfsprog = 1; … … 1737 1335 } 1738 1336 1739 strncpy(pathname_of_last_file_restored, orig_bf_fname, 1740 MAX_STR_LEN - 1); 1741 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1337 asprintf(&pathname_of_last_file_restored, orig_bf_fname); 1742 1338 1743 1339 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ … … 1750 1346 "Skipping big file %ld (%s) - not in biggielist subset", 1751 1347 biggiefile_number + 1, orig_bf_fname); 1752 pathname_of_last_file_restored [0] = '\0';1348 pathname_of_last_file_restored = NULL; 1753 1349 } else if (!(node->selected)) { 1754 1350 dummy_restore = TRUE; 1755 1351 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1756 1352 orig_bf_fname); 1757 pathname_of_last_file_restored [0] = '\0';1353 pathname_of_last_file_restored = NULL; 1758 1354 } 1759 1355 } … … 1761 1357 if (use_ntfsprog) { 1762 1358 if (strncmp(orig_bf_fname, "/dev/", 5)) { 1763 log_msg(1, 1764 "I was in error when I set use_ntfsprog to TRUE."); 1359 log_msg(1, "I was in error when I set use_ntfsprog to TRUE."); 1765 1360 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1766 1361 use_ntfsprog = FALSE; … … 1770 1365 if (use_ntfsprog) { 1771 1366 g_loglevel = 4; 1772 strcpy(outfile_fname, orig_bf_fname);1367 asprintf(&outfile_fname, orig_bf_fname); 1773 1368 use_ntfsprog_hack = TRUE; 1774 1369 log_msg(2, 1775 1370 "Calling ntfsclone in background because %s is a /dev entry", 1776 1371 outfile_fname); 1777 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),1372 asprintf(&ntfsprog_fifo, "/tmp/%d.%d.000", (int) (random() % 32768), 1778 1373 (int) (random() % 32768)); 1779 mkfifo( sz_devfile, 0x770);1780 strcpy(ntfsprog_fifo, sz_devfile); 1374 mkfifo(ntfsprog_fifo, 0x770); 1375 1781 1376 file_to_openout = ntfsprog_fifo; 1782 1377 switch (pid = fork()) { … … 1787 1382 "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", 1788 1383 outfile_fname, ntfsprog_fifo); 1789 res = 1790 feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo); 1384 res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo); 1791 1385 // log_msg(3, "CHILD - fip - exiting"); 1792 1386 exit(res); … … 1797 1391 (long int) (pid)); 1798 1392 } 1393 paranoid_free(ntfsprog_fifo); 1799 1394 } else { 1800 1395 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1801 1396 { 1802 strcpy(outfile_fname, orig_bf_fname);1397 asprintf(&outfile_fname, orig_bf_fname); 1803 1398 } else // biggiefile 1804 1399 { 1805 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,1400 asprintf(&outfile_fname, "%s/%s", bkpinfo->restore_path, 1806 1401 orig_bf_fname); 1807 1402 } 1808 1403 use_ntfsprog_hack = FALSE; 1809 ntfsprog_fifo[0] = '\0';1810 1404 file_to_openout = outfile_fname; 1811 1405 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way … … 1813 1407 make_hole_for_file(outfile_fname); 1814 1408 } 1815 sprintf(tmp, "Reassembling big file %ld (%s)",1409 asprintf(&tmp1, "Reassembling big file %ld (%s)", 1816 1410 biggiefile_number + 1, orig_bf_fname); 1817 log_msg(2, tmp); 1411 log_msg(2, tmp1); 1412 paranoid_free(tmp1); 1818 1413 } 1819 1414 1820 1415 if (dummy_restore) { 1821 sprintf(outfile_fname, "/dev/null"); 1416 paranoid_free(outfile_fname); 1417 asprintf(&outfile_fname, "/dev/null"); 1822 1418 } 1823 1419 1824 1420 if (!bkpinfo->zip_exe[0]) { 1825 sprintf(command, "cat > \"%s\"", file_to_openout);1421 asprintf(&command, "cat > \"%s\"", file_to_openout); 1826 1422 } else { 1827 sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,1423 asprintf(&command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, 1828 1424 file_to_openout, MONDO_LOGFILE); 1829 1425 } 1830 sprintf(tmp, "Pipe command = '%s'", command); 1831 log_msg(3, tmp); 1426 asprintf(&tmp1, "Pipe command = '%s'", command); 1427 log_msg(3, tmp1); 1428 paranoid_free(tmp1); 1832 1429 1833 1430 /* restore biggiefile, one slice at a time */ … … 1835 1432 fatal_error("Cannot pipe out"); 1836 1433 } 1434 paranoid_free(command); 1435 1837 1436 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1838 1437 ctrl_chr != BLK_STOP_A_BIGGIE; … … 1841 1440 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1842 1441 } 1843 sprintf(tmp, "Working on file #%ld, slice #%ld ",1442 asprintf(&tmp1, "Working on file #%ld, slice #%ld ", 1844 1443 biggiefile_number + 1, current_slice_number); 1845 log_msg(2, tmp); 1444 log_msg(2, tmp1); 1445 1846 1446 if (!g_text_mode) { 1847 newtDrawRootText(0, g_noof_rows - 2, tmp );1447 newtDrawRootText(0, g_noof_rows - 2, tmp1); 1848 1448 newtRefresh(); 1849 1449 } 1850 strip_spaces(tmp); 1851 update_progress_form(tmp); 1450 strip_spaces(tmp1); 1451 update_progress_form(tmp1); 1452 paranoid_free(tmp1); 1453 1852 1454 if (current_slice_number == 0) { 1853 1455 res = … … 1879 1481 g_current_progress++; 1880 1482 } 1483 paranoid_free(tmp); 1881 1484 paranoid_pclose(pout); 1882 1485 … … 1886 1489 if (use_ntfsprog_hack) { 1887 1490 log_msg(3, "Waiting for ntfsclone to finish"); 1888 sprintf(tmp,1491 asprintf(&tmp, 1889 1492 " ps | grep \" ntfsclone \" | grep -v grep > /dev/null 2> /dev/null"); 1890 1493 while (system(tmp) == 0) { 1891 1494 sleep(1); 1892 } 1495 } 1496 paranoid_free(tmp); 1893 1497 log_msg(3, "OK, ntfsclone has really finished"); 1894 1498 } … … 1905 1509 } 1906 1510 1907 paranoid_free(tmp);1908 1511 paranoid_free(outfile_fname); 1909 paranoid_free(command);1910 paranoid_free(ntfsprog_command);1911 paranoid_free(sz_devfile);1912 paranoid_free(ntfsprog_fifo);1913 1512 g_loglevel = old_loglevel; 1914 return ( retval);1513 return (pathname_of_last_file_restored); 1915 1514 } 1916 1515 … … 1918 1517 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM * 1919 1518 **************************************************************************/ 1920 1921 1519 1922 1520 … … 1943 1541 /** malloc **/ 1944 1542 char *command; 1945 char *tmp ;1543 char *tmp = NULL; 1946 1544 char *filelist_name; 1947 char *filelist_subset_fname; 1948 char *executable; 1949 char *temp_log; 1950 char screen_message[100]; 1545 char *filelist_subset_fname = NULL; 1546 char *executable = NULL; 1547 char *temp_log = NULL; 1951 1548 long matches = 0; 1952 1549 bool use_star; 1953 char *xattr_fname; 1954 char *acl_fname; 1955 // char files_to_restore_this_time_fname[MAX_STR_LEN]; 1550 char *xattr_fname = NULL; 1551 char *acl_fname = NULL; 1956 1552 1957 1553 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1958 malloc_string(command);1959 malloc_string(tmp);1960 malloc_string(filelist_name);1961 malloc_string(filelist_subset_fname);1962 malloc_string(executable);1963 malloc_string(temp_log);1964 malloc_string(xattr_fname);1965 malloc_string(acl_fname);1966 1554 1967 1555 log_msg(5, "Entering"); 1968 filelist_subset_fname[0] = '\0';1969 1556 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1970 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random()); 1971 sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING); 1557 asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING); 1972 1558 run_program_and_log_output(command, 9); 1973 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1974 (int) (random() % 32768)); 1975 1976 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", 1559 paranoid_free(command); 1560 1561 asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%ld", 1977 1562 current_tarball_number); 1978 1563 if (length_of_file(filelist_name) <= 2) { … … 1984 1569 "but it's non-critical. It's cosmetic. Don't worry about it."); 1985 1570 retval = 0; 1986 goto leave_sub; 1571 log_msg(5, "Leaving"); 1572 return (retval); 1987 1573 } 1988 1574 if (count_lines_in_file(filelist_name) <= 0 … … 1990 1576 log_msg(3, "length_of_file(%s) = %llu", tarball_fname, 1991 1577 length_of_file(tarball_fname)); 1992 sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",1578 asprintf(&tmp, "Unable to restore fileset #%ld (CD I/O error)", 1993 1579 current_tarball_number); 1994 1580 log_to_screen(tmp); 1581 paranoid_free(tmp); 1995 1582 retval = 1; 1996 goto leave_sub; 1583 log_msg(5, "Leaving"); 1584 return (retval); 1997 1585 } 1998 1586 1999 1587 if (filelist) { 2000 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",1588 asprintf(&filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", 2001 1589 current_tarball_number); 2002 1590 if ((matches = … … 2005 1593 use_star)) 2006 1594 <= 0) { 2007 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);1595 asprintf(&tmp, "Skipping fileset %ld", current_tarball_number); 2008 1596 log_msg(1, tmp); 1597 paranoid_free(tmp); 2009 1598 } else { 2010 1599 log_msg(3, "Saved fileset %ld's subset to %s", 2011 1600 current_tarball_number, filelist_subset_fname); 2012 1601 } 2013 sprintf(screen_message, "Tarball #%ld --- %ld matches",1602 asprintf(&tmp, "Tarball #%ld --- %ld matches", 2014 1603 current_tarball_number, matches); 2015 log_to_screen(screen_message); 1604 log_to_screen(tmp); 1605 paranoid_free(tmp); 2016 1606 } else { 2017 filelist_subset_fname[0] = '\0'; 2018 } 1607 filelist_subset_fname = NULL; 1608 } 1609 paranoid_free(filelist_name); 2019 1610 2020 1611 if (filelist == NULL || matches > 0) { 2021 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,1612 asprintf(&xattr_fname, XATTR_LIST_FNAME_RAW_SZ, 2022 1613 MNT_CDROM "/archives", current_tarball_number); 2023 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",1614 asprintf(&acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", 2024 1615 current_tarball_number); 2025 1616 if (strstr(tarball_fname, ".bz2")) { 2026 strcpy(executable, "bzip2");1617 asprintf(&executable, "bzip2"); 2027 1618 } else if (strstr(tarball_fname, ".lzo")) { 2028 strcpy(executable, "lzop");1619 asprintf(&executable, "lzop"); 2029 1620 } else { 2030 executable[0] = '\0'; 2031 } 2032 if (executable[0]) { 2033 sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable); 1621 executable = NULL; 1622 } 1623 1624 if (executable == NULL) { 1625 asprintf(&tmp, "which %s > /dev/null 2> /dev/null", executable); 2034 1626 if (run_program_and_log_output(tmp, FALSE)) { 2035 1627 log_to_screen 2036 (_("(compare_a_tarball) Compression program not found - oh no!")); 1628 (_ 1629 ("(compare_a_tarball) Compression program not found - oh no!")); 2037 1630 paranoid_MR_finish(1); 2038 1631 } 2039 strcpy(tmp, executable); 2040 sprintf(executable, "-P %s -Z", tmp); 1632 paranoid_free(tmp); 1633 1634 asprintf(&tmp, executable); 1635 asprintf(&executable, "-P %s -Z", tmp); 1636 paranoid_free(tmp); 2041 1637 } 2042 1638 #ifdef __FreeBSD__ … … 2046 1642 #endif 2047 1643 2048 // if (strstr(tarball_fname, ".star.")) 1644 asprintf(&temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1645 (int) (random() % 32768)); 1646 2049 1647 if (use_star) { 2050 sprintf(command, 1648 if (strstr(tarball_fname, ".bz2")) { 1649 asprintf(&tmp, " -bz"); 1650 } else { 1651 asprintf(&tmp, ""); 1652 } 1653 asprintf(&command, 2051 1654 "star -x -force-remove -U " STAR_ACL_SZ 2052 " errctl= file=%s", tarball_fname); 2053 if (strstr(tarball_fname, ".bz2")) { 2054 strcat(command, " -bz"); 2055 } 1655 " errctl= file=%s %s 2>> %s >> %s", tarball_fname, tmp, temp_log, temp_log); 1656 paranoid_free(tmp); 2056 1657 } else { 2057 if (filelist_subset_fname [0] != '\0') {2058 sprintf(command,2059 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s ",1658 if (filelist_subset_fname != NULL) { 1659 asprintf(&command, 1660 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s 2>> %s >> %s", 2060 1661 TAPE_BLOCK_SIZE, 2061 1662 BUFSIZE, executable, filelist_subset_fname, 2062 1663 // files_to_restore_this_time_fname, 2063 tarball_fname );1664 tarball_fname, temp_log, temp_log); 2064 1665 } else { 2065 sprintf(command,2066 "afio -i -b %ld -c %ld -M 8m %s %s ",1666 asprintf(&command, 1667 "afio -i -b %ld -c %ld -M 8m %s %s 2>> %s >> %s", 2067 1668 TAPE_BLOCK_SIZE, 2068 BUFSIZE, executable, tarball_fname); 2069 } 2070 } 1669 BUFSIZE, executable, tarball_fname, temp_log, temp_log); 1670 } 1671 } 1672 paranoid_free(executable); 1673 2071 1674 #undef BUFSIZE 2072 sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,2073 temp_log);2074 1675 log_msg(1, "command = '%s'", command); 2075 1676 unlink(temp_log); … … 2083 1684 } 2084 1685 } 1686 paranoid_free(command); 1687 2085 1688 if (res && length_of_file(temp_log) < 5) { 2086 1689 res = 0; … … 2092 1695 if (res) { 2093 1696 log_to_screen 2094 (_("Errors occurred while setting extended attributes")); 1697 (_ 1698 ("Errors occurred while setting extended attributes")); 2095 1699 } else { 2096 1700 log_msg(1, "I set xattr OK"); … … 2103 1707 if (res) { 2104 1708 log_to_screen 2105 (_("Errors occurred while setting access control lists")); 1709 (_ 1710 ("Errors occurred while setting access control lists")); 2106 1711 } else { 2107 1712 log_msg(1, "I set ACL OK"); … … 2110 1715 } 2111 1716 if (retval) { 2112 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);1717 asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2113 1718 system(command); 1719 paranoid_free(command); 2114 1720 log_msg(2, "Errors occurred while processing fileset #%d", 2115 1721 current_tarball_number); … … 2117 1723 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2118 1724 } 1725 unlink(xattr_fname); 1726 paranoid_free(xattr_fname); 2119 1727 } 2120 1728 if (does_file_exist("/PAUSE")) { 2121 1729 popup_and_OK 2122 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 1730 (_ 1731 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 2123 1732 } 2124 1733 unlink(filelist_subset_fname); 2125 unlink(xattr_fname);2126 1734 unlink(acl_fname); 2127 1735 unlink(temp_log); 2128 1736 2129 leave_sub:2130 paranoid_free(command);2131 paranoid_free(tmp);2132 paranoid_free(filelist_name);2133 1737 paranoid_free(filelist_subset_fname); 2134 paranoid_free( executable);1738 paranoid_free(acl_fname); 2135 1739 paranoid_free(temp_log); 2136 paranoid_free(xattr_fname); 2137 paranoid_free(acl_fname); 1740 2138 1741 log_msg(5, "Leaving"); 2139 1742 return (retval); … … 2172 1775 2173 1776 /** malloc add ***/ 2174 char *tmp ;2175 char *command ;2176 char *afio_fname ;2177 char *filelist_fname ;2178 char *filelist_subset_fname ;2179 char *executable ;1777 char *tmp = NULL; 1778 char *command = NULL; 1779 char *afio_fname = NULL; 1780 char *filelist_fname = NULL; 1781 char *filelist_subset_fname = NULL; 1782 char *executable = NULL; 2180 1783 long matches = 0; 2181 1784 bool restore_this_fileset = FALSE; … … 2184 1787 assert(bkpinfo != NULL); 2185 1788 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 2186 malloc_string(filelist_subset_fname);2187 malloc_string(filelist_fname);2188 malloc_string(afio_fname);2189 malloc_string(executable);2190 malloc_string(command);2191 malloc_string(tmp);2192 filelist_subset_fname[0] = '\0';2193 1789 /* to do it with a file... */ 2194 1790 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 2195 sprintf(tmp,1791 asprintf(&tmp, 2196 1792 "Restoring from fileset #%ld (%ld KB) on %s #%d", 2197 1793 current_tarball_number, (long) size >> 10, … … 2199 1795 g_current_media_number); 2200 1796 log_msg(2, tmp); 1797 paranoid_free(tmp); 2201 1798 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE); 2202 1799 … … 2206 1803 * in afio or someting; oh darn.. OK, use tmpfs :-) * 2207 1804 ****************************************************************************/ 2208 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2209 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 1805 asprintf(&afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 2210 1806 current_tarball_number); 2211 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,1807 asprintf(&filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, 2212 1808 current_tarball_number); 2213 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",1809 asprintf(&filelist_subset_fname, "%s/filelist-subset-%ld.tmp", 2214 1810 bkpinfo->tmpdir, current_tarball_number); 2215 // sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);2216 1811 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size); 2217 1812 if (strstr(tarball_fname, ".star")) { … … 2221 1816 log_msg(1, "Warning - error reading afioball from tape"); 2222 1817 } 2223 if (bkpinfo->compression_level == 0) { 2224 executable[0] = '\0'; 2225 } else { 1818 if (bkpinfo->compression_level != 0) { 2226 1819 if (bkpinfo->use_star) { 2227 strcpy(executable, " -bz");1820 asprintf(&executable, " -bz"); 2228 1821 } else { 2229 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);1822 asprintf(&executable, "-P %s -Z", bkpinfo->zip_exe); 2230 1823 } 2231 1824 } … … 2238 1831 if (strstr(tarball_fname, ".star.")) { 2239 1832 use_star = TRUE; 2240 sprintf(command, "star -t file=%s %s", afio_fname, executable);1833 asprintf(&command, "star -t file=%s %s > %s 2>> %s", afio_fname, executable, filelist_fname, MONDO_LOGFILE); 2241 1834 } else { 2242 1835 use_star = FALSE; 2243 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2244 executable, afio_fname); 2245 } 2246 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname, 2247 MONDO_LOGFILE); 1836 asprintf(&command, "afio -t -M 8m -b %ld %s %s > %s 2>> %s", TAPE_BLOCK_SIZE, 1837 executable, afio_fname, filelist_fname, MONDO_LOGFILE); 1838 } 2248 1839 log_msg(1, "command = %s", command); 2249 1840 if (system(command)) { 2250 1841 log_msg(4, "Warning - error occurred while retrieving TOC"); 2251 1842 } 1843 paranoid_free(command); 2252 1844 if ((matches = 2253 1845 save_filelist_entries_in_common(filelist_fname, filelist, … … 2259 1851 current_tarball_number); 2260 1852 } 2261 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);1853 asprintf(&tmp, "Skipping fileset %ld", current_tarball_number); 2262 1854 log_msg(2, tmp); 1855 paranoid_free(tmp); 2263 1856 restore_this_fileset = FALSE; 2264 1857 } else { … … 2269 1862 } 2270 1863 } 1864 unlink(filelist_fname); 1865 paranoid_free(filelist_fname); 2271 1866 2272 1867 // Concoct the call to star/afio to restore files 2273 if (strstr(tarball_fname, ".star.")) // star 2274 { 2275 sprintf(command, "star -x file=%s %s", afio_fname, executable); 1868 if (strstr(tarball_fname, ".star.")) { 1869 // star 2276 1870 if (filelist) { 2277 sprintf(command + strlen(command), " list=%s",2278 filelist_subset_fname );2279 } 2280 } else // afio2281 {2282 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,2283 executable);1871 asprintf(&command, "star -x file=%s %s list=%s 2>> %s", afio_fname, executable 1872 filelist_subset_fname,MONDO_LOGFILE); 1873 } else { 1874 asprintf(&command,"star -x file=%s %s 2>> %s", afio_fname, executable,MONDO_LOGFILE); 1875 } 1876 } else { 1877 // afio 2284 1878 if (filelist) { 2285 sprintf(command + strlen(command), " -w %s",2286 filelist_subset_fname);2287 }2288 sprintf(command + strlen(command), " %s", afio_fname);2289 } 2290 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);2291 2292 // Call if IF there are files to restore (selectively/unconditionally)1879 asprintf(&command, "afio -i -M 8m -b %ld %s -w %s %s 2>> %s", TAPE_BLOCK_SIZE, executable, filelist_subset_fname,afio_fname,MONDO_LOGFILE); 1880 } else { 1881 asprintf(&command, "afio -i -M 8m -b %ld %s %s 2>> %s", TAPE_BLOCK_SIZE, executable,afio_fname,MONDO_LOGFILE); 1882 } 1883 } 1884 paranoid_free(executable); 1885 1886 // Call if IF there are files to restore (selectively/unconditionally) 2293 1887 if (restore_this_fileset) { 2294 1888 log_msg(1, "Calling command='%s'", command); … … 2315 1909 log_msg(1, "NOT CALLING '%s'", command); 2316 1910 } 1911 paranoid_free(command); 2317 1912 2318 1913 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) { … … 2322 1917 2323 1918 unlink(filelist_subset_fname); 2324 unlink(filelist_fname);2325 1919 unlink(afio_fname); 2326 1920 2327 1921 paranoid_free(filelist_subset_fname); 2328 paranoid_free(filelist_fname);2329 1922 paranoid_free(afio_fname); 2330 paranoid_free(command);2331 paranoid_free(tmp);2332 1923 return (retval); 2333 1924 } … … 2336 1927 *END_RESTORE_A_TARBALL_FROM_STREAM * 2337 1928 **************************************************************************/ 2338 2339 2340 1929 2341 1930 … … 2354 1943 { 2355 1944 int retval = 0; 2356 int res; 2357 long noof_biggiefiles, bigfileno = 0, total_slices; 2358 /** malloc **/ 2359 char *tmp; 2360 bool just_changed_cds = FALSE, finished; 2361 char *xattr_fname; 2362 char *acl_fname; 2363 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2364 char *pathname_of_last_biggie_restored; 1945 int res = 0; 1946 long noof_biggiefiles = 0L, bigfileno = 0L, total_slices = 0L; 1947 char *tmp = NULL; 1948 bool just_changed_cds = FALSE, finished = FALSE; 1949 char *xattr_fname = NULL; 1950 char *acl_fname = NULL; 1951 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes 1952 char *pathname_of_last_biggie_restored = NULL; 2365 1953 FILE *fbw = NULL; 2366 1954 2367 malloc_string(xattr_fname);2368 malloc_string(acl_fname);2369 malloc_string(tmp);2370 malloc_string(biggies_whose_EXATs_we_should_set);2371 malloc_string(pathname_of_last_biggie_restored);2372 1955 assert(bkpinfo != NULL); 2373 1956 2374 sprintf(biggies_whose_EXATs_we_should_set,1957 asprintf(&biggies_whose_EXATs_we_should_set, 2375 1958 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2376 1959 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { … … 2381 1964 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2382 1965 total_slices = atol(tmp); 2383 sprintf(tmp, _("Reassembling large files ")); 1966 paranoid_free(tmp); 1967 1968 asprintf(&tmp, _("Reassembling large files ")); 2384 1969 mvaddstr_and_log_it(g_currentY, 0, tmp); 1970 paranoid_free(tmp); 1971 2385 1972 if (length_of_file(BIGGIELIST) < 6) { 2386 1973 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); … … 2393 1980 return (0); 2394 1981 } 2395 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",1982 asprintf(&tmp, "OK, there are %ld biggiefiles in the archives", 2396 1983 noof_biggiefiles); 2397 1984 log_msg(2, tmp); 1985 paranoid_free(tmp); 2398 1986 2399 1987 open_progress_form(_("Reassembling large files"), … … 2403 1991 for (bigfileno = 0, finished = FALSE; !finished;) { 2404 1992 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1); 2405 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 1993 tmp = slice_fname(bigfileno, 0, ARCHIVES_PATH, ""); 1994 if (!does_file_exist(tmp)) { 2406 1995 log_msg(3, 2407 1996 "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); … … 2410 1999 media_descriptor_string(bkpinfo->backup_media_type), 2411 2000 g_current_media_number); 2412 log_msg(3, "Slicename would have been %s", 2413 slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "")); 2001 tmp1 = slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""); 2002 log_msg(3, "Slicename would have been %s", tmp1); 2003 paranoid_free(tmp1); 2004 2414 2005 // I'm not positive 'just_changed_cds' is even necessary... 2415 2006 if (just_changed_cds) { … … 2420 2011 insist_on_this_cd_number(bkpinfo, 2421 2012 ++g_current_media_number); 2422 sprintf(tmp, _("Restoring from %s #%d"),2013 asprintf(&tmp, _("Restoring from %s #%d"), 2423 2014 media_descriptor_string(bkpinfo-> 2424 2015 backup_media_type), 2425 2016 g_current_media_number); 2426 2017 log_to_screen(tmp); 2018 paranoid_free(tmp); 2019 2427 2020 just_changed_cds = TRUE; 2428 2021 } else { … … 2434 2027 } else { 2435 2028 just_changed_cds = FALSE; 2436 sprintf(tmp, _("Restoring big file %ld"), bigfileno + 1);2029 asprintf(&tmp, _("Restoring big file %ld"), bigfileno + 1); 2437 2030 update_progress_form(tmp); 2438 res = 2439 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, 2440 pathname_of_last_biggie_restored); 2031 paranoid_free(tmp); 2032 2033 pathname_of_last_biggie_restored = 2034 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist); 2441 2035 iamhere(pathname_of_last_biggie_restored); 2442 2036 if (fbw && pathname_of_last_biggie_restored[0]) { 2443 2037 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2444 2038 } 2039 paranoid_free(pathname_of_last_biggie_restored); 2445 2040 retval += res; 2446 2041 bigfileno++; 2447 2042 2448 2043 } 2044 paranoid_free(tmp); 2449 2045 } 2450 2046 2451 2047 if (fbw) { 2452 2048 fclose(fbw); 2453 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);2454 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);2049 asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2050 asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2455 2051 if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) { 2456 2052 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); … … 2460 2056 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2461 2057 } 2462 } 2058 paranoid_free(acl_fname); 2059 paranoid_free(xattr_fname); 2060 } 2061 paranoid_free(biggies_whose_EXATs_we_should_set); 2062 2463 2063 if (does_file_exist("/PAUSE")) { 2464 2064 popup_and_OK 2465 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 2065 (_ 2066 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 2466 2067 } 2467 2068 close_progress_form(); … … 2471 2072 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 2472 2073 } 2473 paranoid_free(xattr_fname);2474 paranoid_free(acl_fname);2475 paranoid_free(tmp);2476 paranoid_free(biggies_whose_EXATs_we_should_set);2477 paranoid_free(pathname_of_last_biggie_restored);2478 2074 return (retval); 2479 2075 } 2480 2481 2076 /************************************************************************** 2482 2077 *END_RESTORE_ALL_BIGGIFILES_FROM_CD * 2483 2078 **************************************************************************/ 2484 2485 2079 2486 2080 … … 2506 2100 /**malloc ***/ 2507 2101 char *tmp; 2102 char *tmp1; 2508 2103 char *tarball_fname; 2509 2104 char *progress_str; 2510 2105 char *comment; 2511 2512 malloc_string(tmp);2513 malloc_string(tarball_fname);2514 malloc_string(progress_str);2515 malloc_string(comment);2516 2106 2517 2107 assert(bkpinfo != NULL); … … 2527 2117 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2528 2118 max_val = atol(tmp) + 1; 2529 sprintf(progress_str, _("Restoring from %s #%d"), 2119 paranoid_free(tmp); 2120 2121 asprintf(&progress_str, _("Restoring from %s #%d"), 2530 2122 media_descriptor_string(bkpinfo->backup_media_type), 2531 2123 g_current_media_number); … … 2538 2130 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2539 2131 update_progress_form(progress_str); 2540 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2132 2133 asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2541 2134 current_tarball_number); 2542 2135 if (!does_file_exist(tarball_fname)) { 2543 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", 2136 paranoid_free(tarball_fname); 2137 asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", 2544 2138 current_tarball_number); 2545 2139 } 2546 2140 if (!does_file_exist(tarball_fname)) { 2547 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", 2141 paranoid_free(tarball_fname); 2142 asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.afio.", 2548 2143 current_tarball_number); 2549 2144 } 2550 2145 if (!does_file_exist(tarball_fname)) { 2551 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", 2146 paranoid_free(tarball_fname); 2147 asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", 2552 2148 current_tarball_number); 2553 2149 } 2554 2150 if (!does_file_exist(tarball_fname)) { 2555 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", 2151 paranoid_free(tarball_fname); 2152 asprintf(&tarball_fname, MNT_CDROM "/archives/%ld.star.", 2556 2153 current_tarball_number); 2557 2154 } 2558 2155 if (!does_file_exist(tarball_fname)) { 2156 paranoid_free(tarball_fname); 2559 2157 if (current_tarball_number == 0) { 2560 2158 log_to_screen 2561 (_("No tarballs. Strange. Maybe you only backed up freakin' big files?")); 2159 (_ 2160 ("No tarballs. Strange. Maybe you only backed up freakin' big files?")); 2562 2161 return (0); 2563 2162 } … … 2569 2168 } 2570 2169 g_current_media_number++; 2571 sprintf(progress_str, _("Restoring from %s #%d"), 2170 paranoid_free(progress_str); 2171 asprintf(&progress_str, _("Restoring from %s #%d"), 2572 2172 media_descriptor_string(bkpinfo->backup_media_type), 2573 2173 g_current_media_number); 2574 2174 log_to_screen(progress_str); 2575 2175 } else { 2576 sprintf(progress_str, _("Restoring from fileset #%ld on %s #%d"), 2176 paranoid_free(progress_str); 2177 asprintf(&progress_str, 2178 _("Restoring from fileset #%ld on %s #%d"), 2577 2179 current_tarball_number, 2578 2180 media_descriptor_string(bkpinfo->backup_media_type), … … 2586 2188 filelist); 2587 2189 } 2588 sprintf(tmp, _("%s #%d, fileset #%ld - restore "), 2190 if (res) { 2191 asprintf(&tmp1, _("reported errors")); 2192 } else { 2193 asprintf(&tmp1, _("succeeded")); 2194 } 2195 asprintf(&tmp, _("%s #%d, fileset #%ld - restore %s"), 2589 2196 media_descriptor_string(bkpinfo->backup_media_type), 2590 g_current_media_number, current_tarball_number); 2591 if (res) { 2592 strcat(tmp, _("reported errors")); 2593 } else if (attempts > 1) { 2594 strcat(tmp, _("succeeded")); 2595 } else { 2596 strcat(tmp, _("succeeded")); 2597 } 2197 g_current_media_number, current_tarball_number,tmp1); 2198 paranoid_free(tmp1); 2199 2598 2200 if (attempts > 1) { 2599 sprintf(tmp + strlen(tmp), _(" (%d attempts) - review logs"), 2600 attempts); 2601 } 2602 strcpy(comment, tmp); 2201 asprintf(&tmp1, _(" (%d attempts) - review logs"), attempts); 2202 } 2203 asprintf(&comment, "%s%s", tmp, tmp1); 2204 paranoid_free(tmp); 2205 paranoid_free(tmp1); 2603 2206 if (attempts > 1) { 2604 2207 log_to_screen(comment); 2605 2208 } 2209 paranoid_free(comment); 2606 2210 2607 2211 retval += res; … … 2609 2213 g_current_progress++; 2610 2214 } 2611 } 2215 paranoid_free(tarball_fname); 2216 } 2217 paranoid_free(progress_str); 2612 2218 close_progress_form(); 2219 2613 2220 if (retval) { 2614 2221 mvaddstr_and_log_it(g_currentY++, 74, _("Errors.")); … … 2616 2223 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 2617 2224 } 2618 paranoid_free(tmp);2619 paranoid_free(tarball_fname);2620 paranoid_free(progress_str);2621 paranoid_free(comment);2622 2225 2623 2226 return (retval); … … 2627 2230 *END_RESTORE_ALL_TARBALLS_FROM_CD * 2628 2231 **************************************************************************/ 2629 2630 2232 2631 2233 … … 2650 2252 2651 2253 /** malloc add ****/ 2652 char *tmp; 2653 char *biggie_fname; 2654 char *biggie_cksum; 2655 char *xattr_fname; 2656 char *acl_fname; 2657 char *p; 2658 char *pathname_of_last_biggie_restored; 2659 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2660 long long biggie_size; 2254 char *tmp = NULL; 2255 char *biggie_fname = NULL; 2256 char *xattr_fname = NULL; 2257 char *acl_fname = NULL; 2258 char *p = NULL; 2259 char *pathname_of_last_biggie_restored = NULL; 2260 char *biggies_whose_EXATs_we_should_set = NULL; // EXtended ATtributes 2261 long long biggie_size = NULL; 2661 2262 FILE *fbw = NULL; 2662 2263 2663 malloc_string(tmp);2664 malloc_string(biggie_fname);2665 malloc_string(biggie_cksum);2666 malloc_string(xattr_fname);2667 malloc_string(acl_fname);2668 malloc_string(biggies_whose_EXATs_we_should_set);2669 malloc_string(pathname_of_last_biggie_restored);2670 2264 assert(bkpinfo != NULL); 2671 2265 2672 2266 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2673 2674 2267 total_slices = atol(tmp); 2675 sprintf(tmp, "Reassembling large files "); 2676 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2677 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2268 paranoid_free(tmp); 2269 2270 asprintf(&tmp, "Reassembling large files "); 2271 asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2272 asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2678 2273 mvaddstr_and_log_it(g_currentY, 0, tmp); 2679 sprintf(biggies_whose_EXATs_we_should_set, 2274 paranoid_free(tmp); 2275 2276 asprintf(&biggies_whose_EXATs_we_should_set, 2680 2277 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2681 2278 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { … … 2694 2291 2695 2292 noof_biggiefiles = atol(biggie_fname); 2696 sprintf(tmp, "OK, there are %ld biggiefiles in the archives",2293 asprintf(&tmp, "OK, there are %ld biggiefiles in the archives", 2697 2294 noof_biggiefiles); 2698 2295 log_msg(2, tmp); 2296 paranoid_free(tmp); 2297 2699 2298 open_progress_form(_("Reassembling large files"), 2700 2299 _("I am now reassembling all the large files."), … … 2713 2312 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 2714 2313 } 2314 /* BERLIOS: useless 2715 2315 p = strrchr(biggie_fname, '/'); 2716 2316 if (!p) { … … 2719 2319 p++; 2720 2320 } 2721 sprintf(tmp, _("Restoring big file %ld (%lld K)"), 2321 */ 2322 asprintf(&tmp, _("Restoring big file %ld (%lld K)"), 2722 2323 current_bigfile_number + 1, biggie_size / 1024); 2723 2324 update_progress_form(tmp); 2724 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname, 2325 paranoid_free(tmp); 2326 2327 pathname_of_last_biggie_restored = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname, 2725 2328 current_bigfile_number, 2726 biggie_cksum, 2727 biggie_size, 2728 filelist, ctrl_chr, 2729 pathname_of_last_biggie_restored); 2329 filelist, ctrl_chr); 2730 2330 log_msg(1, "I believe I have restored %s", 2731 2331 pathname_of_last_biggie_restored); … … 2733 2333 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2734 2334 } 2335 paranoid_free(pathname_of_last_biggie_restored); 2336 2735 2337 retval += res; 2736 2338 current_bigfile_number++; … … 2739 2341 if (current_bigfile_number != noof_biggiefiles 2740 2342 && noof_biggiefiles != 0) { 2741 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",2343 asprintf(&tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", 2742 2344 current_bigfile_number, noof_biggiefiles); 2743 2345 } else { 2744 sprintf(tmp,2346 asprintf(&tmp, 2745 2347 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2746 2348 noof_biggiefiles, current_bigfile_number); 2747 2349 } 2748 2350 log_msg(1, tmp); 2351 paranoid_free(tmp); 2749 2352 2750 2353 if (fbw) { … … 2768 2371 } 2769 2372 } 2373 paranoid_free(xattr_fname); 2374 paranoid_free(acl_fname); 2375 paranoid_free(biggies_whose_EXATs_we_should_set); 2376 2770 2377 if (does_file_exist("/PAUSE")) { 2771 2378 popup_and_OK 2772 (_("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 2379 (_ 2380 ("Press ENTER to go on. Delete /PAUSE to stop these pauses.")); 2773 2381 } 2774 2382 … … 2779 2387 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 2780 2388 } 2781 paranoid_free(biggies_whose_EXATs_we_should_set);2782 paranoid_free(pathname_of_last_biggie_restored);2783 2389 paranoid_free(biggie_fname); 2784 paranoid_free(biggie_cksum);2785 paranoid_free(xattr_fname);2786 paranoid_free(acl_fname);2787 paranoid_free(tmp);2788 2390 return (retval); 2789 2391 } … … 2792 2394 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM * 2793 2395 **************************************************************************/ 2794 2795 2796 2797 2798 2396 2799 2397 … … 2819 2417 2820 2418 /** malloc **/ 2821 char *tmp ;2822 char *progress_str ;2823 char *tmp_fname ;2824 char *xattr_fname ;2825 char *acl_fname ;2419 char *tmp = NULL; 2420 char *progress_str = NULL; 2421 char *tmp_fname = NULL; 2422 char *xattr_fname = NULL; 2423 char *acl_fname = NULL; 2826 2424 2827 2425 long long tmp_size; 2828 2426 2829 malloc_string(tmp);2830 malloc_string(progress_str);2831 malloc_string(tmp_fname);2832 2427 assert(bkpinfo != NULL); 2833 malloc_string(xattr_fname);2834 malloc_string(acl_fname);2835 2428 mvaddstr_and_log_it(g_currentY, 0, _("Restoring from archives")); 2836 2429 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2837 2430 max_val = atol(tmp) + 1; 2431 paranoid_free(tmp); 2838 2432 2839 2433 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ … … 2841 2435 run_program_and_log_output("pwd", 5); 2842 2436 2843 sprintf(progress_str, _("Restoring from media #%d"),2437 asprintf(&progress_str, _("Restoring from media #%d"), 2844 2438 g_current_media_number); 2845 2439 log_to_screen(progress_str); … … 2863 2457 while (ctrl_chr != BLK_STOP_AFIOBALLS) { 2864 2458 update_progress_form(progress_str); 2865 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,2459 asprintf(&xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, 2866 2460 current_afioball_number); 2867 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,2461 asprintf(&acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, 2868 2462 current_afioball_number); 2869 2463 unlink(xattr_fname); … … 2879 2473 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 2880 2474 } 2881 sprintf(tmp, 2475 /* BERLIOS: useless ? 2476 asprintf(&tmp, 2882 2477 _("Restoring from fileset #%ld (name=%s, size=%ld K)"), 2883 2478 current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2479 */ 2884 2480 res = 2885 2481 restore_a_tarball_from_stream(bkpinfo, tmp_fname, … … 2889 2485 retval += res; 2890 2486 if (res) { 2891 sprintf(tmp, _("Fileset %ld - errors occurred"),2487 asprintf(&tmp, _("Fileset %ld - errors occurred"), 2892 2488 current_afioball_number); 2893 2489 log_to_screen(tmp); 2490 paranoid_free(tmp); 2894 2491 } 2895 2492 res = … … 2901 2498 current_afioball_number++; 2902 2499 g_current_progress++; 2903 sprintf(progress_str, _("Restoring from fileset #%ld on %s #%d"), 2500 2501 paranoid_free(progress_str); 2502 asprintf(&progress_str, _("Restoring from fileset #%ld on %s #%d"), 2904 2503 current_afioball_number, 2905 2504 media_descriptor_string(bkpinfo->backup_media_type), … … 2909 2508 unlink(xattr_fname); 2910 2509 unlink(acl_fname); 2510 paranoid_free(xattr_fname); 2511 paranoid_free(acl_fname); 2911 2512 } // next 2513 paranoid_free(progress_str); 2514 paranoid_free(tmp_fname); 2515 2912 2516 log_msg(1, "All done with afioballs"); 2913 2517 close_progress_form(); … … 2917 2521 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 2918 2522 } 2919 paranoid_free(tmp);2920 paranoid_free(progress_str);2921 paranoid_free(tmp_fname);2922 paranoid_free(xattr_fname);2923 paranoid_free(acl_fname);2924 2523 return (retval); 2925 2524 } … … 2946 2545 2947 2546 /** mallco ***/ 2948 char *cwd ;2949 char *newpath ;2950 char *tmp ;2547 char *cwd = NULL; 2548 char *newpath = NULL; 2549 char *tmp = NULL; 2951 2550 assert(bkpinfo != NULL); 2952 2551 2953 2552 malloc_string(cwd); 2954 2553 malloc_string(newpath); 2955 malloc_string(tmp);2956 2554 log_msg(2, "restore_everything() --- starting"); 2957 2555 g_current_media_number = 1; 2556 /* BERLIOS: should test return value, or better change the function */ 2958 2557 getcwd(cwd, MAX_STR_LEN - 1); 2959 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);2558 asprintf(&tmp, "mkdir -p %s", bkpinfo->restore_path); 2960 2559 run_program_and_log_output(tmp, FALSE); 2560 paranoid_free(tmp); 2561 2961 2562 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2962 2563 chdir(bkpinfo->restore_path); 2564 /* BERLIOS: should test return value, or better change the function */ 2963 2565 getcwd(newpath, MAX_STR_LEN - 1); 2964 2566 log_msg(1, "path is now %s", newpath); … … 2966 2568 if (!find_home_of_exe("petris") && !g_text_mode) { 2967 2569 newtDrawRootText(0, g_noof_rows - 2, 2968 _("Press ALT-<left cursor> twice to play Petris :-) ")); 2570 _ 2571 ("Press ALT-<left cursor> twice to play Petris :-) ")); 2969 2572 newtRefresh(); 2970 2573 } 2971 mvaddstr_and_log_it(g_currentY, 0, _("Preparing to read your archives")); 2574 mvaddstr_and_log_it(g_currentY, 0, 2575 _("Preparing to read your archives")); 2972 2576 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2973 2577 mount_cdrom(bkpinfo); 2974 2578 mvaddstr_and_log_it(g_currentY++, 0, 2975 _("Restoring OS and data from streaming media")); 2579 _ 2580 ("Restoring OS and data from streaming media")); 2976 2581 if (bkpinfo->backup_media_type == cdstream) { 2977 2582 openin_cdstream(bkpinfo); … … 3008 2613 paranoid_free(cwd); 3009 2614 paranoid_free(newpath); 3010 paranoid_free(tmp);3011 2615 return (resA + resB); 3012 2616 } … … 3017 2621 3018 2622 3019 3020 /**3021 * @brief Haha. You wish! (This function is not implemented :-)3022 */3023 int3024 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,3025 char *monitas_device,3026 char *restore_this_directory,3027 char *restore_here)3028 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */3029 {3030 FILE *fout;3031 int retval = 0;3032 int i;3033 int j;3034 struct mountlist_itself the_mountlist;3035 static struct raidlist_itself the_raidlist;3036 /** malloc **/3037 char tmp[MAX_STR_LEN + 1];3038 char command[MAX_STR_LEN + 1];3039 char datablock[256 * 1024];3040 char datadisks_fname[MAX_STR_LEN + 1];3041 long k;3042 long length;3043 long long llt;3044 struct s_node *filelist = NULL;3045 assert(bkpinfo != NULL);3046 assert_string_is_neither_NULL_nor_zerolength(monitas_device);3047 assert(restore_this_directory != NULL);3048 assert(restore_here != NULL);3049 3050 sprintf(tmp, "restore_here = '%s'", restore_here);3051 3052 log_msg(2, tmp);3053 3054 log_msg(2, "restore_live_from_monitas_server() - starting");3055 unlink("/tmp/mountlist.txt");3056 unlink("/tmp/filelist.full");3057 unlink("/tmp/biggielist.txt");3058 if (restore_here[0] == '\0') {3059 strcpy(bkpinfo->restore_path, MNT_RESTORING);3060 } else {3061 strcpy(bkpinfo->restore_path, restore_here);3062 }3063 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");3064 sprintf(tmp, "FYI - data will be restored to %s",3065 bkpinfo->restore_path);3066 log_msg(3, tmp);3067 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");3068 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",3069 (int) (random() % 32768));3070 chdir(bkpinfo->tmpdir);3071 3072 sprintf(command, "cat %s", monitas_device);3073 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape()3074 if (!(fout = fopen(datadisks_fname, "w"))) {3075 log_OS_error(datadisks_fname);3076 return (1);3077 }3078 for (i = 0; i < 32; i++) {3079 for (j = 0; j < 4; j++) {3080 for (length = k = 0; length < 256 * 1024; length += k) {3081 k = fread(datablock + length, 1, 256 * 1024 - length,3082 g_tape_stream);3083 }3084 fwrite(datablock, 1, length, fout);3085 g_tape_posK += length;3086 }3087 }3088 paranoid_fclose(fout);3089 sprintf(command,3090 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",3091 datadisks_fname);3092 run_program_and_log_output(command, 4);3093 read_header_block_from_stream(&llt, tmp, &i);3094 read_header_block_from_stream(&llt, tmp, &i);3095 3096 unlink(datadisks_fname);3097 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);3098 retval = load_mountlist(&the_mountlist, g_mountlist_fname);3099 3100 3101 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);3102 iamhere("FIXME");3103 fatal_error("This will fail");3104 sprintf(command,3105 "grep -x \"%s.*\" %s > %s",3106 restore_this_directory, g_filelist_full, g_filelist_full);3107 if (system(command)) {3108 retval++;3109 log_to_screen3110 (_("Error(s) occurred while processing filelist and wildcard"));3111 }3112 iamhere("FIXME");3113 fatal_error("This will fail");3114 sprintf(command,3115 "grep -x \"%s.*\" %s > %s",3116 restore_this_directory, g_biggielist_txt, g_biggielist_txt);3117 if (system(command)) {3118 log_msg(1,3119 "Error(s) occurred while processing biggielist and wildcard");3120 }3121 sprintf(command, "touch %s", g_biggielist_txt);3122 run_program_and_log_output(command, FALSE);3123 // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles3124 retval += restore_everything(bkpinfo, filelist);3125 free_filelist(filelist);3126 log_msg(2, "--------End of restore_live_from_monitas_server--------");3127 return (retval);3128 }3129 3130 /**************************************************************************3131 *END_RESTORE_LIVE_FROM_MONITAS_SERVER *3132 **************************************************************************/3133 3134 3135 3136 3137 2623 extern void wait_until_software_raids_are_prepped(char *, int); 3138 3139 2624 3140 2625 char which_restore_mode(void); … … 3146 2631 void welcome_to_mondorestore() 3147 2632 { 3148 log_msg(0, "-------------- Mondo Restore v%s -------------", PACKAGE_VERSION); 2633 log_msg(0, "-------------- Mondo Restore v%s -------------", 2634 PACKAGE_VERSION); 3149 2635 log_msg(0, 3150 2636 "DON'T PANIC! Mondorestore logs almost everything, so please "); … … 3170 2656 "stopped for some reason, chances are it's detailed here. "); 3171 2657 log_msg(0, 3172 "More than likely there's a message at the very end of this");2658 "More than likely there's a message near the end of this "); 3173 2659 log_msg(0, 3174 2660 "log that will tell you what is wrong. Please read it! "); … … 3178 2664 3179 2665 3180 3181 2666 /** 3182 2667 * Restore the user's data. … … 3185 2670 int main(int argc, char *argv[]) 3186 2671 { 3187 FILE *fin ;3188 FILE *fout ;2672 FILE *fin = NULL; 2673 FILE *fout = NULL; 3189 2674 int retval = 0; 3190 int res; 3191 // int c; 3192 char *tmp; 3193 3194 struct mountlist_itself *mountlist; 3195 struct raidlist_itself *raidlist; 3196 struct s_bkpinfo *bkpinfo; 3197 struct s_node *filelist; 3198 char *a, *b; 2675 int res = 0; 2676 char *tmp = NULL; 2677 2678 struct mountlist_itself *mountlist = NULL; 2679 struct raidlist_itself *raidlist = NULL; 2680 struct s_bkpinfo *bkpinfo = NULL; 2681 struct s_node *filelist = NULL; 2682 char *a = NULL, *b = NULL; 3199 2683 3200 2684 /************************************************************************** … … 3215 2699 3216 2700 g_loglevel = DEFAULT_MR_LOGLEVEL; 3217 malloc_string(tmp);3218 2701 3219 2702 /* Configure global variables */ 3220 2703 #ifdef __FreeBSD__ 3221 if (strstr 3222 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 3223 "textonly")) 2704 tmp = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 3224 2705 #else 3225 if (strstr 3226 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 3227 "textonly")) 2706 tmp = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 3228 2707 #endif 3229 {2708 if (strstr(tmp,"textonly")) { 3230 2709 g_text_mode = TRUE; 3231 2710 log_msg(1, "TEXTONLY MODE"); … … 3233 2712 g_text_mode = FALSE; 3234 2713 } // newt :-) 2714 paranoid_free(tmp); 2715 3235 2716 if (! 3236 2717 (bkpinfo = g_bkpinfo_DONTUSETHIS = … … 3247 2728 malloc_libmondo_global_strings(); 3248 2729 3249 asprintf(&g_mondo_home, 3250 call_program_and_get_last_line_of_output 3251 ("which mondorestore")); 2730 g_mondo_home = call_program_and_get_last_line_of_output("which mondorestore")); 3252 2731 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3253 2732 make_hole_for_dir(g_tmpfs_mountpt); … … 3257 2736 run_program_and_log_output("mkdir -p /mnt/floppy", FALSE); 3258 2737 3259 malloc_string(tmp);3260 malloc_string(a);3261 malloc_string(b);3262 2738 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc. 3263 2739 reset_bkpinfo(bkpinfo); … … 3281 2757 3282 2758 /* Backup original mountlist.txt */ 3283 sprintf(tmp, "%s.orig", g_mountlist_fname);2759 asprintf(&tmp, "%s.orig", g_mountlist_fname); 3284 2760 if (!does_file_exist(g_mountlist_fname)) { 3285 2761 log_msg(2, … … 3287 2763 __LINE__, g_mountlist_fname); 3288 2764 } else if (!does_file_exist(tmp)) { 3289 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, 2765 paranoid_free(tmp); 2766 asprintf(&tmp, "cp -f %s %s.orig", g_mountlist_fname, 3290 2767 g_mountlist_fname); 3291 2768 run_program_and_log_output(tmp, FALSE); 3292 2769 } 2770 paranoid_free(tmp); 3293 2771 3294 2772 /* Init directories */ 3295 2773 make_hole_for_dir(bkpinfo->tmpdir); 3296 sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);2774 asprintf(&tmp, "mkdir -p %s", bkpinfo->tmpdir); 3297 2775 run_program_and_log_output(tmp, FALSE); 2776 paranoid_free(tmp); 2777 3298 2778 make_hole_for_dir("/var/log"); 3299 2779 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */ 3300 2780 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3301 2781 run_program_and_log_output 3302 ("ln -sf "MONDO_LOGFILE" /tmp/mondo-restore.log", 3303 FALSE); 2782 ("ln -sf " MONDO_LOGFILE " /tmp/mondo-restore.log", FALSE); 3304 2783 3305 2784 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); … … 3361 2840 system("rm -Rf /tmp/*pih*"); 3362 2841 3363 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);2842 (void)restore_a_biggiefile_from_CD(bkpinfo, 42, NULL); 3364 2843 } 3365 2844 … … 3378 2857 // finish(0); 3379 2858 // toggle_path_selection (filelist, "/root/stuff", TRUE); 3380 strcpy(a, argv[3]);3381 strcpy(b, argv[4]);2859 asprintf(&a, argv[3]); 2860 asprintf(&b, argv[4]); 3382 2861 3383 2862 res = save_filelist_entries_in_common(a, filelist, b, FALSE); 3384 2863 free_filelist(filelist); 2864 paranoid_free(a); 2865 paranoid_free(b); 3385 2866 printf("res = %d", res); 3386 2867 finish(0); … … 3444 2925 if (argc != 1) { 3445 2926 popup_and_OK 3446 (_("Live mode doesn't support command-line parameters yet.")); 2927 (_ 2928 ("Live mode doesn't support command-line parameters yet.")); 3447 2929 paranoid_MR_finish(1); 3448 2930 // return(1); … … 3454 2936 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) { 3455 2937 g_restoring_live_from_cd = TRUE; 3456 }3457 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {3458 retval =3459 restore_live_from_monitas_server(bkpinfo,3460 argv[2],3461 argv[3], argv[4]);3462 2938 } else { 3463 2939 log_msg(2, "Calling restore_to_live_filesystem()"); … … 3466 2942 log_msg(2, "Still here. Yay."); 3467 2943 if (strlen(bkpinfo->tmpdir) > 0) { 3468 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);2944 asprintf(&tmp, "rm -Rf %s/*", bkpinfo->tmpdir); 3469 2945 run_program_and_log_output(tmp, FALSE); 2946 paranoid_free(tmp); 3470 2947 } 3471 2948 unmount_boot_if_necessary(); /* for Gentoo users */ … … 3496 2973 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3497 2974 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3498 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",2975 asprintf(&tmp, "mount %s -t nfs -o nolock /tmp/isodir", 3499 2976 bkpinfo->nfs_mount); 3500 2977 run_program_and_log_output(tmp, 1); 2978 paranoid_free(tmp); 3501 2979 } 3502 2980 } … … 3505 2983 if (retval) { 3506 2984 log_to_screen 3507 (_("Warning - load_raidtab_into_raidlist returned an error")); 2985 (_ 2986 ("Warning - load_raidtab_into_raidlist returned an error")); 3508 2987 } 3509 2988 … … 3577 3056 if (does_file_exist("/tmp/changed.files")) { 3578 3057 log_to_screen 3579 (_("See /tmp/changed.files for list of files that have changed.")); 3058 (_ 3059 ("See /tmp/changed.files for list of files that have changed.")); 3580 3060 } 3581 3061 mvaddstr_and_log_it(g_currentY++, 3582 3062 0, 3583 _("Run complete. Errors were reported. Please review the logfile.")); 3063 _ 3064 ("Run complete. Errors were reported. Please review the logfile.")); 3584 3065 } else { 3585 3066 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3586 3067 mvaddstr_and_log_it(g_currentY++, 3587 3068 0, 3588 _("Run complete. Please remove floppy/CD/media and reboot.")); 3069 _ 3070 ("Run complete. Please remove floppy/CD/media and reboot.")); 3589 3071 } else { 3590 3072 run_program_and_log_output("sync", FALSE); … … 3607 3089 mvaddstr_and_log_it(g_currentY++, 3608 3090 0, 3609 _("Run complete. Please remove media and reboot.")); 3091 _ 3092 ("Run complete. Please remove media and reboot.")); 3610 3093 } 3611 3094 } … … 3617 3100 if (mount_all_devices(mountlist, TRUE)) { 3618 3101 log_to_screen 3619 (_("Unable to re-mount partitions for post-nuke stuff")); 3102 (_ 3103 ("Unable to re-mount partitions for post-nuke stuff")); 3620 3104 } else { 3621 3105 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3622 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,3106 asprintf(&tmp, "post-nuke %s %d", bkpinfo->restore_path, 3623 3107 retval); 3624 3108 if (!g_text_mode) { … … 3629 3113 log_OS_error(tmp); 3630 3114 } 3115 paranoid_free(tmp); 3631 3116 if (!g_text_mode) { 3632 3117 newtResume(); … … 3647 3132 unlink("/tmp/mondo-run-prog.tmp"); 3648 3133 set_signals(FALSE); 3649 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);3134 asprintf(&tmp, "rm -Rf %s", bkpinfo->tmpdir); 3650 3135 run_program_and_log_output(tmp, FALSE); 3136 paranoid_free(tmp); 3137 3651 3138 log_to_screen 3652 (_("Restore log copied to /tmp/mondo-restore.log on your hard disk")); 3653 sprintf(tmp, 3654 _("Mondo-restore is exiting (retval=%d) "), 3139 (_ 3140 ("Restore log copied to /tmp/mondo-restore.log on your hard disk")); 3141 asprintf(&tmp, 3142 _ 3143 ("Mondo-restore is exiting (retval=%d) "), 3655 3144 retval); 3656 3145 log_to_screen(tmp); 3657 sprintf(tmp, "umount %s", bkpinfo->isodir); 3146 paranoid_free(tmp); 3147 3148 asprintf(&tmp, "umount %s", bkpinfo->isodir); 3658 3149 run_program_and_log_output(tmp, 5); 3150 paranoid_free(tmp); 3151 3659 3152 paranoid_free(mountlist); 3660 3153 paranoid_free(raidlist); … … 3664 3157 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo 3665 3158 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3666 paranoid_free(a);3667 paranoid_free(b);3668 paranoid_free(tmp);3669 3159 3670 3160 unlink("/tmp/filelist.full"); … … 3679 3169 3680 3170 3681 3682 3683 3684 3171 /************************************************************************** 3685 3172 *END_MONDO-RESTORE.C * -
trunk/mondo/mondo/mondorestore/mondo-restore.h
r59 r688 1 /* mondo-restore.h1 /* 2 2 * $Id$ 3 3 **/ 4 4 5 5 /************************************************************************** … … 22 22 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, 23 23 struct raidlist_itself *); 24 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *,25 char *);26 24 int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long, 27 25 char *, long long, struct s_node *, -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h
r59 r688 1 /* mondo-rstr-compare-EXT.h */ 1 /* 2 * $Id$ 3 **/ 2 4 3 5 -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
r524 r688 1 1 /*************************************************************************** 2 mondo-compare.c - compares mondoarchive data 3 ------------------- 4 begin : Fri Apr 25 2003 5 copyright : (C) 2000 by Hugo Rabson 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 /*************************************************************************** 20 * Change Log * 21 *************************************************************************** 22 . 23 24 25 26 10/21/2003 27 - changed "/mnt/cdrom" to MNT_CDROM 28 29 10/18 30 - don't say unknown compressor if no compressor at all 31 32 09/17 33 - cleaned up logging & conversion-to-changed.txt 34 - cleaned up compare_mode() 35 36 09/16 37 - fixed bad malloc(),free() pairs in compare_a_biggiefile() 38 39 09/14 40 - compare_mode() --- a couple of strings were the wrong way round, 41 e.g. changed.txt and changed.files 42 43 05/05 44 - exclude /dev/ * from list of changed files 45 46 04/30 47 - added textonly mode 48 49 04/27 50 - improved compare_mode() to allow for ISO/cd/crazy people 51 52 04/25 53 - first incarnation 54 */ 2 * $Id$ - compares mondoarchive data 3 **/ 55 4 56 5 … … 58 7 #include "../common/mondostructures.h" 59 8 #include "../common/libmondo.h" 60 //#include "../../config.h"61 9 #include "mr-externs.h" 62 10 #include "mondo-rstr-compare.h" … … 67 15 #endif 68 16 69 //static char cvsid[] = "$Id$";70 71 17 void popup_changelist_from_file(char *); 72 18 … … 89 35 90 36 /** needs malloc *******/ 91 char *checksum _ptr;92 char *original_cksum _ptr;93 char *bigfile_fname _ptr;94 char *tmp _ptr;95 char * command_ptr;96 97 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 98 99 char *p;100 int i;37 char *checksum = NULL; 38 char *original_cksum = NULL; 39 char *bigfile_fname = NULL; 40 char *tmp = NULL; 41 char *tmp1 = NULL; 42 char *command = NULL; 43 44 char *p = NULL; 45 int i = 0; 46 int n = 0; 101 47 int retval = 0; 102 48 103 49 struct s_filename_and_lstat_info biggiestruct; 104 50 105 malloc_string(checksum);106 malloc_string(original_cksum);107 malloc_string(bigfile_fname);108 malloc_string(tmp);109 malloc_string(command);110 malloc_string(checksum_ptr);111 malloc_string(original_cksum_ptr);112 malloc_string(bigfile_fname_ptr);113 malloc_string(command_ptr);114 malloc_string(tmp_ptr);115 116 /*********************************************************************117 * allocate memory clear test sab 16 feb 2003 *118 *********************************************************************/119 51 assert(bkpinfo != NULL); 120 memset(checksum_ptr, '\0', sizeof(checksum)); 121 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 122 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 123 memset(tmp_ptr, '\0', sizeof(tmp)); 124 memset(command_ptr, '\0', sizeof(command)); 125 /** end **/ 126 127 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 52 53 tmp1 = slice_fname(bigfileno, 0, ARCHIVES_PATH, ""); 54 if (!does_file_exist(tmp1)) { 128 55 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 129 56 insist_on_this_cd_number(bkpinfo, (++g_current_media_number)); 130 57 } else { 131 sprintf(tmp_ptr, 132 "No CD's left. No biggiefiles left. No prob, Bob."); 133 log_msg(2, tmp_ptr); 58 log_msg(2, "No CD's left. No biggiefiles left. No problem."); 134 59 return (0); 135 60 } 136 61 } 137 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 138 sprintf(tmp_ptr, 139 _("Cannot open bigfile %ld (%s)'s info file"), 140 bigfileno + 1, bigfile_fname_ptr); 141 log_to_screen(tmp_ptr); 62 if (!(fin = fopen(tmp1, "r"))) { 63 asprintf(&tmp, _("Cannot open bigfile %ld (%s)'s info file"), 64 bigfileno + 1, tmp); 65 log_to_screen(tmp); 66 paranoid_free(tmp); 67 paranoid_free(tmp1); 142 68 return (1); 143 69 } … … 145 71 paranoid_fclose(fin); 146 72 147 strcpy(checksum_ptr, biggiestruct.checksum); 148 strcpy(bigfile_fname_ptr, biggiestruct.filename); 149 150 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 151 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 152 153 sprintf(tmp_ptr, _("Comparing %s"), bigfile_fname_ptr); 73 asprintf(&checksum, biggiestruct.checksum); 74 asprintf(&bigfile_fname, biggiestruct.filename); 75 76 log_msg(2, "biggiestruct.filename = %s", bigfile_fname); 77 log_msg(2, "biggiestruct.checksum = %s", checksum); 154 78 155 79 if (!g_text_mode) { 156 newtDrawRootText(0, 22, tmp_ptr); 80 asprintf(&tmp, _("Comparing %s"), bigfile_fname); 81 newtDrawRootText(0, 22, tmp); 157 82 newtRefresh(); 158 } 83 paranoid_free(tmp); 84 } 85 /* BERLIOS: Useless ? 159 86 if (!checksum[0]) { 160 87 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 161 } 162 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 163 strcpy(original_cksum_ptr, "IGNORE"); 164 } else { 165 sprintf(command_ptr, 88 } */ 89 if (!strncmp(bigfile_fname, "/dev/", 5)) { 90 log_msg(2, _("Ignoring device %s"), bigfile_fname); 91 return(0); 92 } else { 93 asprintf(&command, 166 94 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 167 MNT_RESTORING, bigfile_fname_ptr); 168 } 169 log_msg(2, command_ptr); 170 paranoid_system 171 ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null"); 172 if (system(command_ptr)) { 95 MNT_RESTORING, bigfile_fname); 96 } 97 log_msg(2, command); 98 paranoid_system("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null"); 99 if (system(command)) { 173 100 log_OS_error("Warning - command failed"); 174 original_cksum[0] = '\0'; 101 paranoid_free(command); 102 paranoid_free(bigfile_fname); 175 103 return (1); 176 104 } else { 105 paranoid_free(command); 177 106 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 178 log_msg(2, 179 "Unable to open /tmp/md5sum.txt; can't get live checksum"); 180 original_cksum[0] = '\0'; 107 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum"); 108 paranoid_free(bigfile_fname); 181 109 return (1); 182 110 } else { 183 fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);111 getline(&original_cksum, &n, fin); 184 112 paranoid_fclose(fin); 185 for (i = strlen(original_cksum _ptr);113 for (i = strlen(original_cksum); 186 114 i > 0 && original_cksum[i - 1] < 32; i--); 187 115 original_cksum[i] = '\0'; 188 p = (char *) strchr(original_cksum _ptr, ' ');116 p = (char *) strchr(original_cksum, ' '); 189 117 if (p) { 190 118 *p = '\0'; … … 192 120 } 193 121 } 194 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, 195 bigfile_fname_ptr); 196 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) { 197 strcat(tmp_ptr, " ... OK"); 198 } else { 199 strcat(tmp_ptr, "... changed"); 122 if (!strcmp(checksum, original_cksum) != 0) { 123 log_msg(1, "bigfile #%ld ('%s') ... OK", bigfileno + 1, bigfile_fname); 124 } else { 125 log_msg(1, "bigfile #%ld ('%s') ... changed", bigfileno + 1, bigfile_fname); 200 126 retval++; 201 127 } 202 log_msg(1, tmp_ptr); 128 paranoid_free(original_cksum); 129 paranoid_free(checksum); 130 203 131 if (retval) { 204 132 if (!(fout = fopen("/tmp/changed.txt", "a"))) { 205 133 fatal_error("Cannot openout changed.txt"); 206 134 } 207 fprintf(fout, "%s\n", bigfile_fname _ptr);135 fprintf(fout, "%s\n", bigfile_fname); 208 136 paranoid_fclose(fout); 209 137 } 210 211 paranoid_free(original_cksum_ptr);212 paranoid_free(original_cksum);213 paranoid_free(bigfile_fname_ptr);214 138 paranoid_free(bigfile_fname); 215 paranoid_free(checksum_ptr);216 paranoid_free(checksum);217 paranoid_free(command_ptr);218 paranoid_free(command);219 paranoid_free(tmp_ptr);220 paranoid_free(tmp);221 139 222 140 return (retval); … … 238 156 int res; 239 157 long noof_biggiefiles, bigfileno = 0; 240 char tmp[MAX_STR_LEN];158 char *tmp; 241 159 242 160 assert(bkpinfo != NULL); … … 254 172 } 255 173 mvaddstr_and_log_it(g_currentY, 0, 256 _("Comparing large files ")); 174 _ 175 ("Comparing large files ")); 257 176 open_progress_form(_("Comparing large files"), 258 177 _("I am now comparing the large files"), … … 260 179 noof_biggiefiles); 261 180 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 262 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);181 asprintf(&tmp, "Comparing big file #%ld", bigfileno + 1); 263 182 log_msg(1, tmp); 264 183 update_progress_form(tmp); 184 paranoid_free(tmp); 265 185 res = compare_a_biggiefile(bkpinfo, bigfileno); 266 186 retval += res; … … 268 188 } 269 189 close_progress_form(); 190 /* BERLIOS: useless ? 270 191 return (0); 192 */ 271 193 if (retval) { 272 194 mvaddstr_and_log_it(g_currentY++, 74, _("Errors.")); … … 299 221 300 222 /*** needs malloc *********/ 301 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, 302 *compressor_exe; 303 304 malloc_string(command); 305 malloc_string(tmp); 306 malloc_string(filelist_name); 307 malloc_string(logfile); 308 malloc_string(archiver_exe); 309 malloc_string(compressor_exe); 223 char *command = NULL; 224 char *tmp = NULL; 225 char *filelist_name = NULL; 226 char *logfile = NULL; 227 char *archiver_exe = NULL; 228 char *compressor_exe = NULL; 310 229 311 230 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 312 231 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 313 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 314 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 232 asprintf(&filelist_name, MNT_CDROM "/archives/filelist.%d", 315 233 current_tarball_number); 316 234 317 235 noof_lines = count_lines_in_file(filelist_name); 236 paranoid_free(filelist_name); 318 237 319 238 if (strstr(tarball_fname, ".bz2")) { 320 strcpy(compressor_exe, "bzip2");239 asprintf(&compressor_exe, "bzip2"); 321 240 } else if (strstr(tarball_fname, ".lzo")) { 322 strcpy(compressor_exe, "lzop");323 } else { 324 compressor_exe [0] = '\0';241 asprintf(&compressor_exe, "lzop"); 242 } else { 243 compressor_exe = NULL; 325 244 } 326 245 327 246 if (use_star) { 328 strcpy(archiver_exe, "star"); 329 } else { 330 strcpy(archiver_exe, "afio"); 331 } 332 333 if (compressor_exe[0]) { 334 strcpy(tmp, compressor_exe); 335 if (!find_home_of_exe(tmp)) { 247 asprintf(&archiver_exe, "star -bz"); 248 } else { 249 asprintf(&archiver_exe, "afio"); 250 } 251 252 if (compressor_exe != NULL) { 253 if (!find_home_of_exe(compressor_exe)) { 336 254 fatal_error("(compare_a_tarball) Compression program missing"); 337 255 } 338 if (use_star) // star 339 { 340 if (!strcmp(compressor_exe, "bzip2")) { 341 strcat(archiver_exe, " -bz"); 342 } else { 256 if (use_star) { 257 if (strcmp(compressor_exe, "bzip2")) { 343 258 fatal_error 344 259 ("(compare_a_tarball) Please use only bzip2 with star"); 345 260 } 346 } else // afio347 {261 } else { 262 asprintf(&tmp, compressor_exe); 348 263 sprintf(compressor_exe, "-P %s -Z", tmp); 264 paranoid_free(tmp); 349 265 } 350 266 } … … 356 272 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 357 273 #endif 274 275 asprintf(&logfile, "/tmp/afio.log.%d", current_tarball_number); 358 276 if (use_star) // doesn't use compressor_exe 359 277 { 360 sprintf(command,278 asprintf(&command, 361 279 "%s -diff H=star file=%s >> %s 2>> %s", 362 280 archiver_exe, tarball_fname, logfile, logfile); 363 281 } else { 364 sprintf(command,282 asprintf(&command, 365 283 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 366 284 archiver_exe, … … 369 287 } 370 288 #undef BUFSIZE 289 paranoid_free(archiver_exe); 290 paranoid_free(compressor_exe); 371 291 372 292 res = system(command); … … 374 294 if (res) { 375 295 log_OS_error(command); 376 sprintf(tmp, "Warning - afio returned error = %d", res);377 296 } 378 297 if (length_of_file(logfile) > 5) { … … 385 304 archiver_errors = 0; 386 305 } 387 sprintf(tmp, "%ld difference%c in fileset #%d ", 388 archiver_errors, (archiver_errors != 1) ? 's' : ' ', 389 current_tarball_number); 306 paranoid_free(command); 307 390 308 if (archiver_errors) { 391 sprintf(tmp,309 asprintf(&tmp, 392 310 "Differences found while processing fileset #%d ", 393 311 current_tarball_number); 394 312 log_msg(1, tmp); 313 paranoid_free(tmp); 395 314 } 396 315 unlink(logfile); 397 paranoid_free(command);398 paranoid_free(tmp);399 paranoid_free(filelist_name);400 316 paranoid_free(logfile); 401 malloc_string(archiver_exe);402 malloc_string(compressor_exe);403 317 return (retval); 404 318 } … … 422 336 /** needs malloc **********/ 423 337 424 char *tarball_fname, *progress_str, *tmp; 338 char *tarball_fname = NULL; 339 char *progress_str = NULL; 340 char *tmp = NULL; 425 341 long max_val; 426 427 malloc_string(tarball_fname);428 malloc_string(progress_str);429 malloc_string(tmp);430 342 431 343 assert(bkpinfo != NULL); … … 434 346 435 347 max_val = atol(tmp); 436 sprintf(progress_str, _("Comparing with %s #%d "), 348 paranoid_free(tmp); 349 350 asprintf(&progress_str, _("Comparing with %s #%d "), 437 351 media_descriptor_string(bkpinfo->backup_media_type), 438 352 g_current_media_number); … … 448 362 insist_on_this_cd_number(bkpinfo, g_current_media_number); 449 363 update_progress_form(progress_str); 450 sprintf(tarball_fname,364 asprintf(&tarball_fname, 451 365 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 452 366 453 367 if (!does_file_exist(tarball_fname)) { 454 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", 368 paranoid_free(tarball_fname); 369 asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", 455 370 current_tarball_number); 456 371 } 457 372 if (!does_file_exist(tarball_fname)) { 458 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", 373 paranoid_free(tarball_fname); 374 asprintf(&tarball_fname, MNT_CDROM "/archives/%d.afio.", 459 375 current_tarball_number); 460 376 } 461 377 if (!does_file_exist(tarball_fname)) { 462 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", 378 paranoid_free(tarball_fname); 379 asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.bz2", 463 380 current_tarball_number); 464 381 } 465 382 if (!does_file_exist(tarball_fname)) { 466 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 383 paranoid_free(tarball_fname); 384 asprintf(&tarball_fname, MNT_CDROM "/archives/%d.star.", 467 385 current_tarball_number); 468 386 } … … 473 391 == 0) { 474 392 log_msg(2, "OK, I think I'm done with tarballs..."); 393 paranoid_free(tarball_fname); 475 394 break; 476 395 } 477 396 log_msg(2, "OK, I think it's time for another CD..."); 478 397 g_current_media_number++; 479 sprintf(progress_str, _("Comparing with %s #%d "), 398 paranoid_free(progress_str); 399 asprintf(&progress_str, _("Comparing with %s #%d "), 480 400 media_descriptor_string(bkpinfo->backup_media_type), 481 401 g_current_media_number); … … 483 403 } else { 484 404 res = compare_a_tarball(tarball_fname, current_tarball_number); 405 paranoid_free(tarball_fname); 485 406 486 407 g_current_progress++; … … 488 409 } 489 410 } 411 paranoid_free(progress_str); 490 412 close_progress_form(); 413 491 414 if (retval) { 492 415 mvaddstr_and_log_it(g_currentY++, 74, _("Errors.")); … … 494 417 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 495 418 } 496 paranoid_free(tarball_fname);497 paranoid_free(progress_str);498 paranoid_free(tmp);499 419 return (retval); 500 420 } … … 519 439 { 520 440 /** needs malloc *********/ 521 char *tmp, *cwd, *new, *command; 441 char *tmp = NULL; 442 char *cwd = NULL; 443 char *new = NULL; 444 char *command = NULL; 522 445 int resA = 0; 523 446 int resB = 0; 524 447 long noof_changed_files; 525 448 526 malloc_string(tmp);527 449 malloc_string(cwd); 528 450 malloc_string(new); 529 malloc_string(command);530 451 531 452 assert(bkpinfo != NULL); … … 534 455 chdir(bkpinfo->restore_path); 535 456 getcwd(new, MAX_STR_LEN - 1); 536 sprintf(tmp, "new path is %s", new);537 457 insist_on_this_cd_number(bkpinfo, g_current_media_number); 538 458 unlink("/tmp/changed.txt"); … … 543 463 noof_changed_files = count_lines_in_file("/tmp/changed.txt"); 544 464 if (noof_changed_files) { 545 sprintf(tmp, _("%ld files do not match the backup "),465 asprintf(&tmp, _("%ld files do not match the backup "), 546 466 noof_changed_files); 547 467 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 548 468 log_to_screen(tmp); 549 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE); 469 paranoid_free(tmp); 470 471 asprintf(&command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE); 550 472 paranoid_system(command); 551 } else { 552 sprintf(tmp, _("All files match the backup ")); 473 paranoid_free(command); 474 } else { 475 asprintf(&tmp, _("All files match the backup ")); 553 476 mvaddstr_and_log_it(g_currentY++, 0, tmp); 554 477 log_to_screen(tmp); 555 }556 557 paranoid_free(tmp); 478 paranoid_free(tmp); 479 } 480 558 481 paranoid_free(cwd); 559 482 paranoid_free(new); 560 paranoid_free(command);561 483 562 484 return (resA + resB); … … 566 488 *END_COMPARE_TO_CD * 567 489 **************************************************************************/ 568 569 570 490 571 491 … … 588 508 char *tmp; 589 509 590 malloc_string(tmp);591 592 510 /************************************************************************** 593 511 * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to * … … 600 518 while (get_cfg_file_from_archive(bkpinfo)) { 601 519 if (!ask_me_yes_or_no 602 (_("Failed to find config file/archives. Choose another source?"))) 520 (_ 521 ("Failed to find config file/archives. Choose another source?"))) 603 522 { 604 523 fatal_error("Unable to find config file/archives. Aborting."); … … 628 547 mvaddstr_and_log_it(g_currentY++, 629 548 0, 630 _("Warning - differences found during the compare phase")); 549 _ 550 ("Warning - differences found during the compare phase")); 631 551 } 632 552 … … 635 555 if (count_lines_in_file("/tmp/changed.txt") > 0) { 636 556 mvaddstr_and_log_it(g_currentY++, 0, 637 _("Differences found while files were being compared.")); 557 _ 558 ("Differences found while files were being compared.")); 638 559 streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt"); 639 560 if (count_lines_in_file("/tmp/changed.files") <= 0) { 640 561 mvaddstr_and_log_it(g_currentY++, 0, 641 _("...but they were logfiles and temporary files. Your archives are fine.")); 642 log_to_screen 643 (_("The differences were logfiles and temporary files. Your archives are fine.")); 562 _ 563 ("...but they were logfiles and temporary files. Your archives are fine.")); 564 log_to_screen(_ 565 ("The differences were logfiles and temporary files. Your archives are fine.")); 644 566 } else { 645 567 q = count_lines_in_file("/tmp/changed.files"); 646 sprintf(tmp, _("%ld significant difference%s found."), q,568 asprintf(&tmp, _("%ld significant difference%s found."), q, 647 569 (q != 1) ? "s" : ""); 648 570 mvaddstr_and_log_it(g_currentY++, 0, tmp); 649 571 log_to_screen(tmp); 650 651 strcpy(tmp, 572 paranoid_free(tmp); 573 574 asprintf(&tmp, 652 575 _("Type 'less /tmp/changed.files' for a list of non-matching files")); 653 576 mvaddstr_and_log_it(g_currentY++, 0, tmp); 654 577 log_to_screen(tmp); 578 paranoid_free(tmp); 655 579 656 580 log_msg(2, "calling popup_changelist_from_file()"); … … 660 584 } else { 661 585 log_to_screen 662 (_("No significant differences were found. Your backup is perfect.")); 586 (_ 587 ("No significant differences were found. Your backup is perfect.")); 663 588 } 664 589 kill_petris(); 665 paranoid_free(tmp);666 590 return (retval); 667 591 } … … 670 594 *END_COMPARE_MODE * 671 595 **************************************************************************/ 596 672 597 673 598 /** … … 683 608 int res; 684 609 610 char *dir = NULL; 611 char *command = NULL; 612 613 assert(bkpinfo != NULL); 685 614 /** needs malloc **/ 686 char *dir, *command, *tmp;687 688 assert(bkpinfo != NULL);689 615 malloc_string(dir); 690 malloc_string(command);691 616 getcwd(dir, MAX_STR_LEN); 692 617 chdir(bkpinfo->restore_path); 693 618 694 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",619 asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 695 620 bkpinfo->restore_path); 696 621 run_program_and_log_output(command, FALSE); 622 paranoid_free(command); 697 623 mvaddstr_and_log_it(g_currentY, 698 624 0, _("Verifying archives against filesystem")); … … 700 626 if (bkpinfo->disaster_recovery 701 627 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 702 asprintf(&tmp,703 last_line_of_file("/tmp/CDROM-LIVES-HERE"));704 628 paranoid_free(bkpinfo->media_device); 705 bkpinfo->media_device = tmp; 629 // last_line_of_file allocates the string 630 bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE"); 706 631 } else { 707 632 paranoid_free(bkpinfo->media_device); 633 // find_cdrom_device allocates the string 708 634 bkpinfo->media_device = find_cdrom_device(FALSE); 709 635 } … … 721 647 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 722 648 paranoid_free(dir); 723 paranoid_free(command);724 649 return (res); 725 650 } … … 744 669 { 745 670 int res; 746 char *dir, *command; 671 char *dir = NULL; 672 char *command = NULL; 747 673 748 674 assert(bkpinfo != NULL); 749 675 malloc_string(dir); 750 malloc_string(command);751 676 752 677 getcwd(dir, MAX_STR_LEN); 753 678 chdir(bkpinfo->restore_path); 754 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp",679 asprintf(&command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 755 680 bkpinfo->restore_path); 756 681 run_program_and_log_output(command, FALSE); 682 paranoid_free(command); 683 757 684 mvaddstr_and_log_it(g_currentY, 758 685 0, _("Verifying archives against filesystem")); … … 765 692 } 766 693 paranoid_free(dir); 767 paranoid_free(command);768 694 return (res); 769 695 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.h
r59 r688 1 /* mondo-rstr-compare.h1 /* 2 2 * $Id$ 3 3 **/ 4 4 5 5 -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c
r539 r688 1 1 /*************************************************************************** 2 2 * $Id$ 3 * /3 **/ 4 4 5 5 … … 11 11 #ifdef __FreeBSD__ 12 12 #define OSSWAP(linux,fbsd) fbsd 13 //#include <libgen.h>14 13 #else 15 14 #define OSSWAP(linux,fbsd) linux … … 17 16 18 17 #include "mondo-rstr-newt.h" 19 20 //static char cvsid[] = "$Id$";21 22 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];23 24 18 25 19 /** … … 57 51 { 58 52 /** buffers ***********************************************************/ 59 char *tmp ;53 char *tmp = NULL; 60 54 61 55 /** newt **************************************************************/ … … 82 76 83 77 newtPushHelpLine 84 (_(" Add one of the following unallocated RAID partitions to this RAID device.")); 78 (_ 79 (" Add one of the following unallocated RAID partitions to this RAID device.")); 85 80 asprintf(&tmp, "%-26s %s", _("Device"), _("Size")); 86 81 headerMsg = newtLabel(1, 1, tmp); … … 157 152 newtComponent formatComp; 158 153 159 /** buffers **********************************************************/ 160 char *drive_to_add; 161 char *mountpoint_str; 154 char *drive_to_add = NULL; 155 char *mountpoint_str = NULL; 162 156 char *size_str = NULL; 163 char *device_str; 164 char *format_str; 165 166 /** pointers *********************************************************/ 167 char *mountpoint_here; 168 char *size_here; 169 char *device_here; 170 char *format_here; 157 char *device_str = NULL; 158 char *format_str = NULL; 159 char *mountpoint_here = NULL; 160 char *size_here = NULL; 161 char *device_here = NULL; 162 char *format_here = NULL; 171 163 172 164 assert(mountlist != NULL); … … 198 190 bCancel = newtButton(17, 6, _("Cancel")); 199 191 newtPushHelpLine 200 (_("To add an entry to the mountlist, please fill in these fields and then hit 'OK'")); 192 (_ 193 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'")); 201 194 myForm = newtForm(NULL, NULL, 0); 202 195 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, … … 229 222 if (size_of_specific_device_in_mountlist(mountlist, device_str) 230 223 >= 0) { 231 popup_and_OK(_("Can't add this - you've got one already!")); 224 popup_and_OK(_ 225 ("Can't add this - you've got one already!")); 232 226 b_res = NULL; 233 227 } … … 286 280 287 281 if (popup_and_get_string 288 ("Add variable", _("Enter the name of the variable to add"), sz_out, 289 MAX_STR_LEN)) { 290 strip_spaces(sz_out); 282 ("Add variable", _("Enter the name of the variable to add"), 283 sz_out)) { 291 284 items = raidrec->additional_vars.entries; 292 285 for (i = 0; … … 295 288 if (i < items) { 296 289 popup_and_OK 297 (_("No need to add that variable. It is already listed here.")); 290 (_ 291 ("No need to add that variable. It is already listed here.")); 298 292 } else { 299 293 strcpy(raidrec->additional_vars.el[items].label, sz_out); … … 302 296 } 303 297 } 298 paranoid_free(sz_out); 304 299 } 305 300 #endif … … 322 317 323 318 /** structures ********************************************************/ 324 struct vinum_volume *raidrec; 325 326 /** int ***************************************************************/ 319 struct vinum_volume *raidrec = NULL; 320 327 321 int i = 0, j = 0; 328 322 int noof_partitions = 0; 329 323 330 /** long **************************************************************/331 324 long total_size = 0; 332 325 long plex_size = 0; … … 335 328 long sp = 0; 336 329 337 /** buffers ***********************************************************/ 338 char *tmp; 339 char *devname; 340 341 342 330 char *tmp = NULL; 331 char *devname = NULL; 343 332 344 333 for (i = 0; … … 347 336 if (i == raidlist->entries) { 348 337 asprintf(&tmp, 349 "Cannot calc size of raid device %s - cannot find it in raidlist",350 raid_device);338 "Cannot calc size of raid device %s - cannot find it in raidlist", 339 raid_device); 351 340 log_it(tmp); 352 341 paranoid_free(tmp); … … 411 400 } 412 401 413 asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device,414 (long) smallest_plex);402 asprintf(&tmp, "I have calculated %s's real size to be %ld", 403 raid_device, (long) smallest_plex); 415 404 log_it(tmp); 416 405 paranoid_free(tmp); … … 420 409 421 410 /** structures ********************************************************/ 422 struct raid_device_record *raidrec ;411 struct raid_device_record *raidrec = NULL; 423 412 424 413 /** int ***************************************************************/ … … 432 421 433 422 /** buffers ***********************************************************/ 434 char *tmp ;423 char *tmp = NULL; 435 424 436 425 assert(mountlist != NULL); … … 443 432 if (i == raidlist->entries) { 444 433 asprintf(&tmp, 445 "Cannot calc size of raid device %s - cannot find it in raidlist",446 raid_device);434 "Cannot calc size of raid device %s - cannot find it in raidlist", 435 raid_device); 447 436 log_it(tmp); 448 437 paranoid_free(tmp); … … 469 458 total_size = smallest_partition * (noof_partitions - 1); 470 459 } 471 asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device,472 (long) total_size);460 asprintf(&tmp, "I have calculated %s's real size to be %ld", 461 raid_device, (long) total_size); 473 462 log_it(tmp); 474 463 paranoid_free(tmp); … … 478 467 479 468 480 481 469 /** 482 470 * Choose the RAID level for the RAID device record in @p raidrec. … … 495 483 496 484 /** buffers ***********************************************************/ 497 char *tmp ;498 char *prompt ;499 char *sz ;485 char *tmp = NULL; 486 char *prompt = NULL; 487 char *sz = NULL; 500 488 501 489 asprintf(&prompt, 502 _("Please enter the RAID level you want. (concat, striped, raid5)")); 490 _ 491 ("Please enter the RAID level you want. (concat, striped, raid5)")); 503 492 if (raidrec->raidlevel == -1) { 504 493 asprintf(&tmp, "concat"); … … 509 498 } 510 499 for (out = 999; out == 999;) { 511 res = popup_and_get_string("Specify RAID level", prompt, tmp , 10);500 res = popup_and_get_string("Specify RAID level", prompt, tmp); 512 501 if (!res) { 513 502 return; 514 503 } 515 strip_spaces(tmp);504 /* BERLIOS: Useless ??? 516 505 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 517 506 asprintf(&sz, tmp); … … 520 509 paranoid_free(sz); 521 510 } 511 */ 522 512 if (!strcmp(tmp, "concat")) { 523 513 out = -1; … … 544 534 #else 545 535 /** buffers ***********************************************************/ 546 char *tmp ;547 char personalities[MAX_STR_LEN];548 char *prompt ;549 char *sz ;536 char *tmp = NULL; 537 char *personalities = NULL; 538 char *prompt = NULL; 539 char *sz = NULL; 550 540 int out = 0, res = 0; 551 541 … … 554 544 system 555 545 ("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null"); 556 strcpy(personalities, 557 last_line_of_file("/tmp/raid-personalities.txt")); 546 personalities = last_line_of_file("/tmp/raid-personalities.txt")); 558 547 asprintf(&prompt, _("Please enter the RAID level you want. %s"), 559 personalities); 548 personalities); 549 paranoid_free(personalities); 550 560 551 if (raidrec->raid_level == -1) { 561 552 asprintf(&tmp, "linear"); … … 566 557 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 567 558 && out != 10;) { 568 res = popup_and_get_string(_("Specify RAID level"), prompt, tmp, 10); 559 res = 560 popup_and_get_string(_("Specify RAID level"), prompt, tmp); 569 561 if (!res) { 570 562 return; 571 563 } 572 strip_spaces(tmp);564 /* BERLIOS: Useless ??? 573 565 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 574 566 asprintf(&sz, tmp); 575 strncpy(tmp, sz + 1, strlen(sz) - 2); 567 paranoid_free(tmp); 568 569 asprintf(&tmp, sz + 1); 576 570 tmp[strlen(sz) - 2] = '\0'; 577 571 paranoid_free(sz); 578 572 } 573 */ 579 574 if (!strcmp(tmp, "linear")) { 580 575 out = -1; … … 585 580 } 586 581 log_it(tmp); 587 paranoid_free(tmp);588 582 if (is_this_raid_personality_registered(out)) { 589 583 log_it … … 591 585 } else { 592 586 if (ask_me_yes_or_no 593 (_("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))) 587 (_ 588 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?"))) 594 589 { 595 590 out = 999; … … 597 592 } 598 593 } 594 paranoid_free(tmp); 599 595 paranoid_free(prompt); 600 596 raidrec->raid_level = out; … … 622 618 623 619 /** buffers ***********************************************************/ 624 char *tmp ;620 char *tmp = NULL; 625 621 626 622 assert(mountlist != NULL); … … 634 630 pos++); 635 631 if (pos < mountlist->entries) { 636 asprintf(&tmp, 637 "Deleting partition %s cos it was part of a now-defunct RAID", 638 mountlist->el[pos].device); 639 log_it(tmp); 640 paranoid_free(tmp); 632 log_it("Deleting partition %s cos it was part of a now-defunct RAID", 633 mountlist->el[pos].device); 641 634 memcpy((void *) &mountlist->el[pos], 642 635 (void *) &mountlist->el[mountlist->entries - 1], … … 665 658 666 659 /** buffers ***********************************************************/ 667 char *tmp ;660 char *tmp = NULL; 668 661 669 662 assert(disklist != NULL); … … 671 664 672 665 asprintf(&tmp, _("Delete %s from RAID device %s - are you sure?"), 673 disklist->el[currline].device, raid_device);666 disklist->el[currline].device, raid_device); 674 667 if (!ask_me_yes_or_no(tmp)) { 675 668 paranoid_free(tmp); … … 705 698 706 699 /** buffers ***********************************************************/ 707 char *tmp ;708 char *device ;700 char *tmp = NULL; 701 char *device = NULL; 709 702 710 703 assert(mountlist != NULL); … … 718 711 device); 719 712 if (pos >= 0) { 720 asprintf(&tmp, _("Cannot delete %s: it is in use by RAID device %s"), 721 mountlist->el[currline].device, 722 raidlist->el[pos].OSSWAP(raid_device, volname)); 713 asprintf(&tmp, 714 _("Cannot delete %s: it is in use by RAID device %s"), 715 mountlist->el[currline].device, 716 raidlist->el[pos].OSSWAP(raid_device, volname)); 723 717 popup_and_OK(tmp); 724 718 paranoid_free(tmp); … … 726 720 } 727 721 asprintf(&tmp, _("Delete %s - are you sure?"), 728 mountlist->el[currline].device);722 mountlist->el[currline].device); 729 723 if (!ask_me_yes_or_no(tmp)) { 730 724 paranoid_free(tmp); … … 740 734 && strcmp(mountlist->el[currline].device, device); 741 735 currline++); 742 if (currline == mountlist->entries) {743 log_it("Dev is gone. I can't delete it. Ho-hum");744 paranoid_free(device);745 return;746 }736 if (currline == mountlist->entries) { 737 log_it("Dev is gone. I can't delete it. Ho-hum"); 738 paranoid_free(device); 739 return; 740 } 747 741 paranoid_free(device); 748 742 } … … 775 769 776 770 /** buffers ***********************************************************/ 777 char *tmp ;771 char *tmp = NULL; 778 772 779 773 assert(mountlist != NULL); … … 785 779 return; 786 780 } 787 asprintf(&tmp, _("Do you want me to delete %s's partitions, too?", device)); 781 asprintf(&tmp, 782 _("Do you want me to delete %s's partitions, too?"), device); 788 783 delete_partitions_too = ask_me_yes_or_no(tmp); 789 784 if (delete_partitions_too) { … … 846 841 847 842 /** buffers ************************************************************/ 848 char *tmp ;843 char *tmp = NULL; 849 844 850 845 /** structures *********************************************************/ 851 struct additional_raid_variables *av ;846 struct additional_raid_variables *av = NULL; 852 847 853 848 assert(raidrec != NULL); 854 849 855 850 av = &raidrec->additional_vars; 856 asprintf(&tmp, _("Delete %s - are you sure?" , av->el[lino].label));851 asprintf(&tmp, _("Delete %s - are you sure?"), av->el[lino].label); 857 852 if (ask_me_yes_or_no(tmp)) { 858 853 if (!strcmp(av->el[lino].label, "persistent-superblock") … … 860 855 paranoid_free(tmp); 861 856 asprintf(&tmp, _("%s must not be deleted. It would be bad."), 862 av->el[lino].label);857 av->el[lino].label); 863 858 popup_and_OK(tmp); 864 859 } else { … … 891 886 892 887 /** structures *******************************************************/ 893 struct s_node *node ;888 struct s_node *node = NULL; 894 889 895 890 /** buffers **********************************************************/ 896 static char *current_filename ;897 char *tmp ;891 static char *current_filename = NULL; 892 char *tmp = NULL; 898 893 899 894 /** bool *************************************************************/ … … 905 900 assert(keylist != NULL); 906 901 assert(listbox != NULL); 907 908 902 909 903 if (depth == 0) { … … 927 921 warned_already = TRUE; 928 922 asprintf(&tmp, 929 _("Too many lines. Displaying first %d entries only. Close a directory to see more."), 930 ARBITRARY_MAXIMUM); 923 _ 924 ("Too many lines. Displaying first %d entries only. Close a directory to see more."), 925 ARBITRARY_MAXIMUM); 931 926 popup_and_OK(tmp); 932 927 paranoid_free(tmp); … … 964 959 newtListboxClear(listbox); 965 960 for (i = 0; i < lines_in_flist_window; i++) { 966 asprintf(&tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '), 967 (g_is_path_expanded[i] ? '+' : '-'), 968 strip_path(g_strings_of_flist_window[i])); 969 // BERLIOS: this is dangerous now 961 asprintf(&tmp, "%c%c %-80s", 962 (g_is_path_selected[i] ? '*' : ' '), 963 (g_is_path_expanded[i] ? '+' : '-'), 964 strip_path(g_strings_of_flist_window[i])); 965 // BERLIOS: this is dangerous now => Memory leak 970 966 if (strlen(tmp) > 71) { 971 967 tmp[70] = '\0'; … … 1011 1007 slashcount--; /* Keep one slash 'cos Hugh does... */ 1012 1008 1009 /* BERLIOS: tmpnopath and prev not defined !! How can this compile ?? */ 1013 1010 for (i = 0; i < slashcount; i++) { /* Replace each dir with a space char */ 1014 1011 tmpnopath[i] = ' '; … … 1062 1059 void *keylist[ARBITRARY_MAXIMUM]; 1063 1060 1064 /** buffers ***********************************************************/1065 char tmp[MAX_STR_LEN];1066 1067 1061 /** bool **************************************************************/ 1068 1062 bool dummybool; … … 1074 1068 log_to_screen(_("Editing filelist")); 1075 1069 newtPushHelpLine 1076 (_(" Please edit the filelist to your satisfaction, then click OK or Cancel.")); 1070 (_ 1071 (" Please edit the filelist to your satisfaction, then click OK or Cancel.")); 1077 1072 j = 4; 1078 1073 bLess = newtCompactButton(j, 17, _(" Less ")); … … 1111 1106 indexno = 0; 1112 1107 } 1113 sprintf(tmp,"You selected '%s'",1108 log_it("You selected '%s'", 1114 1109 g_strings_of_flist_window[indexno]); 1115 log_it(tmp);1116 1110 if (b_res == bMore) { 1117 1111 g_is_path_expanded[indexno] = TRUE; … … 1204 1198 newtComponent b_raid = NULL; 1205 1199 1206 /** buffers ***********************************************************/ 1207 char device_str[MAX_STR_LEN]; 1208 char mountpoint_str[MAX_STR_LEN]; 1209 char size_str[MAX_STR_LEN]; 1210 char format_str[MAX_STR_LEN]; 1211 char tmp[MAX_STR_LEN]; 1212 char device_used_to_be[MAX_STR_LEN]; 1213 char mountpt_used_to_be[MAX_STR_LEN]; 1214 1215 /** pointers **********************************************************/ 1216 char *device_here; 1217 char *mountpoint_here; 1218 char *size_here; 1219 char *format_here; 1220 1221 /** int ***************************************************************/ 1200 char *device_str = NULL; 1201 char *mountpoint_str = NULL; 1202 char *size_str = NULL; 1203 char *format_str = NULL; 1204 char *tmp = NULL; 1205 char *device_used_to_be = NULL; 1206 char *mountpt_used_to_be = NULL; 1207 char *device_here = NULL; 1208 char *mountpoint_here = NULL; 1209 char *size_here = NULL; 1210 char *format_here = NULL; 1211 1222 1212 int j = 0; 1223 1213 … … 1229 1219 memcpy((void *) &bkp_raidlist, (void *) raidlist, 1230 1220 sizeof(struct raidlist_itself)); 1231 strcpy(device_str, mountlist->el[currline].device); 1232 strcpy(device_used_to_be, mountlist->el[currline].device); 1233 strcpy(mountpoint_str, mountlist->el[currline].mountpoint); 1234 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint); 1235 strcpy(format_str, mountlist->el[currline].format); 1236 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024); 1221 asprintf(&device_str, mountlist->el[currline].device); 1222 asprintf(&device_used_to_be, mountlist->el[currline].device); 1223 asprintf(&mountpoint_str, mountlist->el[currline].mountpoint); 1224 asprintf(&mountpt_used_to_be, mountlist->el[currline].mountpoint); 1225 asprintf(&format_str, mountlist->el[currline].format); 1226 asprintf(&size_str, "%lld", mountlist->el[currline].size / 1024); 1227 1237 1228 newtOpenWindow(20, 5, 48, 10, "Edit entry"); 1238 1229 label0 = newtLabel(2, 1, _("Device:")); … … 1242 1233 deviceComp = 1243 1234 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1235 paranoid_free(device_str); 1236 1244 1237 mountpointComp = 1245 1238 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1239 paranoid_free(mountpoint_str); 1240 1246 1241 formatComp = 1247 1242 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1243 paranoid_free(format_str); 1244 1248 1245 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1249 1246 || !strcmp(mountlist->el[currline].mountpoint, "image")) { … … 1252 1249 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 1253 1250 } 1251 paranoid_free(size_str); 1252 1254 1253 bOK = newtButton(2, 6, _(" OK ")); 1255 1254 bCancel = newtButton(14, 6, _("Cancel")); … … 1258 1257 } 1259 1258 newtPushHelpLine 1260 (_(" Edit this partition's mountpoint, size and format; then click 'OK'.")); 1259 (_ 1260 (" Edit this partition's mountpoint, size and format; then click 'OK'.")); 1261 1261 myForm = newtForm(NULL, NULL, 0); 1262 1262 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, … … 1265 1265 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 1266 1266 b_res = newtRunForm(myForm); 1267 strcpy(device_str, device_here); 1267 1268 paranoid_free(device_str); 1269 asprintf(&device_str, device_here); 1268 1270 strip_spaces(device_str); 1269 strcpy(mountpoint_str, mountpoint_here); 1271 1272 paranoid_free(mountpoint_str); 1273 asprintf(&mountpoint_str, mountpoint_here); 1270 1274 strip_spaces(mountpoint_str); 1271 strcpy(format_str, format_here); 1275 1276 paranoid_free(format_str); 1277 asprintf(&format_str, format_here); 1278 paranoid_free(format_here); 1272 1279 strip_spaces(format_str); 1273 1280 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) … … 1279 1286 } else if (b_res == bOK && !strcmp(mountpoint_str, "image") 1280 1287 && strcmp(mountpt_used_to_be, "image")) { 1281 popup_and_OK(_("You can't change a regular device to an image.")); 1288 popup_and_OK(_ 1289 ("You can't change a regular device to an image.")); 1282 1290 b_res = NULL; 1283 1291 continue; 1284 1292 } 1293 paranoid_free(mountpt_used_to_be); 1294 1285 1295 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1286 1296 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1287 strcpy(size_str, size_here);1297 asprintf(&size_str, size_here); 1288 1298 strip_spaces(size_str); 1289 1299 } else { 1290 sprintf(size_str, "%ld",1300 asprintf(&size_str, "%ld", 1291 1301 calculate_raid_device_size(mountlist, raidlist, 1292 1302 mountlist->el[currline]. … … 1294 1304 newtLabelSetText(sizeComp, size_str); 1295 1305 } 1306 paranoid_free(size_here); 1307 1296 1308 /* do not let user click RAID button if user has changed device_str */ 1297 1309 if (b_res == b_raid) { … … 1302 1314 */ 1303 1315 popup_and_OK 1304 (_("You cannot edit the RAID settings until you have OK'd your change to the device node.")); 1316 (_ 1317 ("You cannot edit the RAID settings until you have OK'd your change to the device node.")); 1305 1318 } else { 1306 1319 j = find_raid_device_in_raidlist(raidlist, … … 1309 1322 if (j < 0) { 1310 1323 sprintf(tmp, 1311 _("/etc/raidtab does not have an entry for %s; please delete it and add it again"), 1324 _ 1325 ("/etc/raidtab does not have an entry for %s; please delete it and add it again"), 1312 1326 mountlist->el[currline].device); 1313 1327 popup_and_OK(tmp); … … 1320 1334 } 1321 1335 } 1336 paranoid_free(device_here); 1337 paranoid_free(mountpoint_here); 1338 1322 1339 newtFormDestroy(myForm); 1323 1340 newtPopHelpLine(); … … 1330 1347 strcpy(mountlist->el[currline].device, device_str); 1331 1348 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 1349 paranoid_free(mountpoint_str); 1350 1332 1351 strcpy(mountlist->el[currline].format, format_str); 1352 paranoid_free(format_str); 1353 1333 1354 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1334 1355 || !strcmp(mountlist->el[currline].mountpoint, "image")) { … … 1339 1360 mountlist->el[currline].size = atol(size_str) * 1024; 1340 1361 } 1362 paranoid_free(size_str); 1363 1341 1364 newtListboxSetEntry(listbox, (int) keylist[currline], 1342 1365 mountlist_entry_to_string(mountlist, currline)); … … 1363 1386 else if (strcmp(device_used_to_be, device_str)) { 1364 1387 popup_and_OK 1365 (_("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.")); 1388 (_ 1389 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.")); 1366 1390 } 1367 1391 #endif 1368 1392 redraw_mountlist(mountlist, keylist, listbox); 1393 paranoid_free(device_str); 1394 paranoid_free(device_used_to_be); 1369 1395 } 1370 1396 … … 1425 1451 } 1426 1452 1453 1427 1454 void 1428 1455 edit_raidlist_plex(struct mountlist_itself *mountlist, … … 1455 1482 1456 1483 /** buffers ***********************************************************/ 1457 char title_of_editraidForm_window[MAX_STR_LEN];1484 char *title_of_editraidForm_window; 1458 1485 1459 1486 /** newt **************************************************************/ … … 1472 1499 1473 1500 int currline2 = 0; 1501 char *pname = NULL; 1502 char *raidlevel = NULL; 1503 char *chunksize = NULL; 1504 char *entry = NULL; 1505 char *msg = NULL; 1506 int i = 0; 1507 char *headerstr = NULL; 1474 1508 1475 1509 log_it(_("Started edit_raidlist_entry")); 1476 1510 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1477 1511 sizeof(struct vinum_volume)); 1478 sprintf(title_of_editraidForm_window, _("Plexes on %s"),1512 asprintf(&title_of_editraidForm_window, _("Plexes on %s"), 1479 1513 raidrec->volname); 1480 1514 newtPushHelpLine(_(" Please select a plex to edit")); 1481 1515 newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window); 1516 paranoid_free(title_of_editraidForm_window); 1517 1482 1518 for (;;) { 1483 int i; 1484 char headerstr[MAX_STR_LEN]; 1485 snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s", 1486 _("Plex"), _("Level",) _("Stripe Size"), _("Subdisks")); 1519 asprintf(&headerstr, "%-14s %-8s %11s %8s", _("Plex"), _("Level",) _("Stripe Size"), _("Subdisks")); 1487 1520 1488 1521 bOK = newtCompactButton(2, 13, _(" OK ")); … … 1495 1528 newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1496 1529 plexesHeader = newtLabel(2, 2, headerstr); 1530 paranoid_free(headerstr); 1531 1497 1532 editraidForm = newtForm(NULL, NULL, 0); 1498 1533 … … 1501 1536 keylist[i] = (void *) i; 1502 1537 if (i < raidrec->plexes) { 1503 char pname[64], entry[MAX_STR_LEN], raidlevel[64],1504 chunksize[64];1505 1538 switch (raidrec->plex[i].raidlevel) { 1506 1539 case -1: 1507 strcpy(raidlevel, "concat");1540 asprintf(&raidlevel, "concat"); 1508 1541 break; 1509 1542 case 0: 1510 strcpy(raidlevel, "striped");1543 asprintf(&raidlevel, "striped"); 1511 1544 break; 1512 1545 case 5: 1513 strcpy(raidlevel, "raid5");1546 asprintf(&raidlevel, "raid5"); 1514 1547 break; 1515 1548 default: 1516 sprintf(raidlevel, "raid%i",1549 asprintf(&raidlevel, "raid%i", 1517 1550 raidrec->plex[i].raidlevel); 1518 1551 break; … … 1520 1553 1521 1554 if (raidrec->plex[i].raidlevel == -1) { 1522 strcpy(chunksize, "N/A");1555 asprintf(&chunksize, "N/A"); 1523 1556 } else { 1524 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);1557 asprintf(&chunksize, "%dk", raidrec->plex[i].stripesize); 1525 1558 } 1526 snprintf(pname, 64, "%s.p%i", raidrec->volname, i);1527 snprintf(entry, MAX_STR_LEN, "%-14s %-8s %11s %8d",1559 asprintf(&pname, "%s.p%i", raidrec->volname, i); 1560 asprintf(&entry, "%-14s %-8s %11s %8d", 1528 1561 pname, raidlevel, chunksize, 1529 1562 raidrec->plex[i].subdisks); 1563 paranoid_free(pname); 1564 paranoid_free(chunksize); 1565 paranoid_free(raidlevel); 1530 1566 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1567 paranoid_free(entry); 1531 1568 } 1532 1569 } … … 1549 1586 1550 1587 if (b_res == bDelete) { 1551 char msg[MAX_STR_LEN]; 1552 sprintf(msg, _("Are you sure you want to delete %s.p%i?"), 1588 asprintf(&msg, _("Are you sure you want to delete %s.p%i?"), 1553 1589 raidrec->volname, currline2); 1554 1590 if (ask_me_yes_or_no(msg)) { … … 1559 1595 raidrec->plexes--; 1560 1596 } 1597 paranoid_free(msg); 1561 1598 continue; 1562 1599 } … … 1581 1618 #else 1582 1619 /** structures ********************************************************/ 1583 struct raid_device_record *bkp_raidrec ;1620 struct raid_device_record *bkp_raidrec = NULL; 1584 1621 1585 1622 1586 1623 /** buffers ***********************************************************/ 1587 char *title_of_editraidForm_window ;1588 char *sz_raid_level ;1589 char *sz_data_disks ;1590 char *sz_spare_disks ;1591 char *sz_parity_disks ;1592 char *sz_failed_disks ;1624 char *title_of_editraidForm_window = NULL; 1625 char *sz_raid_level = NULL; 1626 char *sz_data_disks = NULL; 1627 char *sz_spare_disks = NULL; 1628 char *sz_parity_disks = NULL; 1629 char *sz_failed_disks = NULL; 1593 1630 1594 1631 /** newt **************************************************************/ … … 1608 1645 assert(raidrec != NULL); 1609 1646 1610 malloc_string(title_of_editraidForm_window);1611 malloc_string(sz_raid_level);1612 malloc_string(sz_data_disks);1613 malloc_string(sz_spare_disks);1614 malloc_string(sz_parity_disks);1615 malloc_string(sz_failed_disks);1616 1647 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 1617 1648 fatal_error("Cannot malloc space for raidrec"); … … 1622 1653 memcpy((void *) bkp_raidrec, (void *) raidrec, 1623 1654 sizeof(struct raid_device_record)); 1624 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);1655 asprintf(&title_of_editraidForm_window, _("Edit %s"), raidrec->raid_device); 1625 1656 log_msg(2, "Opening newt window"); 1626 1657 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window); 1658 paranoid_free(title_of_editraidForm_window); 1659 1627 1660 for (;;) { 1628 1661 log_msg(2, "Main loop"); 1629 sprintf(title_of_editraidForm_window, _("Edit %s"), 1630 raidrec->raid_device); 1631 strcpy(sz_raid_level, 1662 asprintf(&sz_raid_level, 1632 1663 turn_raid_level_number_to_string(raidrec->raid_level)); 1633 strcpy(sz_data_disks,1664 asprintf(&sz_data_disks, 1634 1665 number_of_disks_as_string(raidrec->data_disks.entries, 1635 1666 _("data"))); 1636 strcpy(sz_spare_disks,1667 asprintf(&sz_spare_disks, 1637 1668 number_of_disks_as_string(raidrec->spare_disks.entries, 1638 1669 _("spare"))); 1639 strcpy(sz_parity_disks,1670 asprintf(&sz_parity_disks, 1640 1671 number_of_disks_as_string(raidrec->parity_disks.entries, 1641 1672 _("parity"))); 1642 strcpy(sz_failed_disks,1673 asprintf(&sz_failed_disks, 1643 1674 number_of_disks_as_string(raidrec->failed_disks.entries, 1644 1675 _("failed"))); … … 1648 1679 bSelectFailed = newtButton(20, 5, sz_failed_disks); 1649 1680 bChangeRaid = newtButton(1, 9, sz_raid_level); 1681 paranoid_free(sz_raid_level); 1682 paranoid_free(sz_data_disks); 1683 paranoid_free(sz_spare_disks); 1684 paranoid_free(sz_parity_disks); 1685 paranoid_free(sz_failed_disks); 1686 1650 1687 bOK = newtButton(16 + (raidrec->raid_level == -1), 9, _(" OK ")); 1651 1688 bCancel = newtButton(28, 9, _("Cancel")); … … 1654 1691 _("Additional settings and information")); 1655 1692 newtPushHelpLine 1656 (_(" Edit the RAID device's settings to your heart's content, then hit OK/Cancel.")); 1693 (_ 1694 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel.")); 1657 1695 editraidForm = newtForm(NULL, NULL, 0); 1658 1696 newtFormAddComponents(editraidForm, bSelectData, bSelectParity, … … 1691 1729 calculate_raid_device_size(mountlist, raidlist, 1692 1730 raidrec->raid_device); 1693 paranoid_free(title_of_editraidForm_window);1694 paranoid_free(sz_raid_level);1695 paranoid_free(sz_data_disks);1696 paranoid_free(sz_spare_disks);1697 paranoid_free(sz_parity_disks);1698 paranoid_free(sz_failed_disks);1699 1731 paranoid_free(bkp_raidrec); 1700 1732 #endif 1701 1733 } 1702 1703 1734 #ifdef __FreeBSD__ 1735 1704 1736 1705 1737 /** … … 1724 1756 1725 1757 /** buffers ***********************************************************/ 1726 char title_of_editraidForm_window[MAX_STR_LEN]; 1758 char *title_of_editraidForm_window = NULL; 1759 char *tmp = NULL; 1760 char *entry = NULL; 1727 1761 1728 1762 /** newt **************************************************************/ … … 1742 1776 void *curr_choice_a, *curr_choice_u; 1743 1777 int currline_a, currline_u; 1744 1745 struct mountlist_itself *unallocparts; 1746 1778 int i; 1779 1780 struct mountlist_itself *unallocparts = NULL; 1781 1782 /* BERLIOS: Check return value */ 1747 1783 unallocparts = malloc(sizeof(struct mountlist_itself)); 1748 1784 … … 1750 1786 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1751 1787 sizeof(struct vinum_plex)); 1752 sprintf(title_of_editraidForm_window, "%s.p%i",1788 asprintf(&title_of_editraidForm_window, "%s.p%i", 1753 1789 raidlist->el[currline].volname, currline2); 1754 1790 newtPushHelpLine 1755 (_(" Please select a subdisk to edit, or edit this plex's parameters")); 1791 (_ 1792 (" Please select a subdisk to edit, or edit this plex's parameters")); 1756 1793 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1794 paranoid_free(title_of_editraidForm_window); 1795 1757 1796 for (;;) { 1758 int i;1759 char headerstr[MAX_STR_LEN];1760 char tmp[64];1761 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", _("Subdisk"), _("Device"));1762 1763 1764 1797 switch (raidrec->raidlevel) { 1765 1798 case -1: 1766 strcpy(tmp, "concat");1799 asprintf(&tmp, "concat"); 1767 1800 break; 1768 1801 case 0: 1769 strcpy(tmp, "striped");1802 asprintf(&tmp, "striped"); 1770 1803 break; 1771 1804 case 5: 1772 strcpy(tmp, "raid5");1805 asprintf(&tmp, "raid5"); 1773 1806 break; 1774 1807 default: 1775 sprintf(tmp, _("unknown (%i)"), raidrec->raidlevel);1808 asprintf(&tmp, _("unknown (%i)"), raidrec->raidlevel); 1776 1809 break; 1777 1810 } 1778 1811 bLevel = newtCompactButton(2, 2, _(" RAID level ")); 1779 1812 sLevel = newtLabel(19, 2, tmp); 1813 paranoid_free(tmp); 1780 1814 1781 1815 if (raidrec->raidlevel >= 0) { 1782 sprintf(tmp, "%ik", raidrec->stripesize);1816 asprintf(&tmp, "%ik", raidrec->stripesize); 1783 1817 bStripeSize = newtCompactButton(2, 4, _(" Stripe size ")); 1784 1818 } else { 1785 strcpy(tmp, "N/A");1819 asprintf(&tmp, "N/A"); 1786 1820 bStripeSize = newtLabel(2, 4, _("Stripe size:")); 1787 1821 } 1788 1822 sStripeSize = newtLabel(19, 4, tmp); 1823 paranoid_free(tmp); 1789 1824 1790 1825 bOK = newtCompactButton(2, 16, _(" OK ")); … … 1796 1831 1797 1832 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1798 // plexesHeader = newtLabel (2, 6, headerstr);1799 1833 unallocListbox = 1800 1834 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); … … 1812 1846 raidlist); 1813 1847 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1814 char entry[MAX_STR_LEN];1815 1848 keylist[i] = (void *) i; 1816 1849 if (i < raidrec->subdisks) { 1817 snprintf(entry, MAX_STR_LEN, "%-17s",1850 asprintf(&entry, "%-17s", 1818 1851 find_dev_entry_for_raid_device_name(raidlist, 1819 1852 raidrec-> … … 1821 1854 which_device)); 1822 1855 newtListboxAppendEntry(allocListbox, entry, keylist[i]); 1856 paranoid_free(entry); 1823 1857 } 1824 1858 if (i < unallocparts->entries) { 1825 snprintf(entry, MAX_STR_LEN, "%-17s", 1826 unallocparts->el[i].device); 1859 asprintf(&entry, "%-17s", unallocparts->el[i].device); 1827 1860 newtListboxAppendEntry(unallocListbox, entry, keylist[i]); 1861 paranoid_free(entry); 1828 1862 } 1829 1863 } … … 1875 1909 choose_raid_level(raidrec); 1876 1910 } else if (b_res == bStripeSize) { 1877 char tmp[64]; 1878 sprintf(tmp, "%i", raidrec->stripesize); 1911 asprintf(&tmp, "%i", raidrec->stripesize); 1879 1912 if (popup_and_get_string 1880 1913 (_("Stripe size"), 1881 _("Please enter the stripe size in kilobytes."), tmp , 20)) {1914 _("Please enter the stripe size in kilobytes."), tmp)) { 1882 1915 raidrec->stripesize = atoi(tmp); 1883 1916 } 1917 paranoid_free(tmp); 1884 1918 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 1885 1919 if (currline_u <= unallocparts->entries) … … 1922 1956 1923 1957 /** buffers ***********************************************************/ 1924 char header[MAX_STR_LEN];1925 char comment[MAX_STR_LEN];1926 char sz_out[MAX_STR_LEN];1958 char *header = NULL; 1959 char *comment = NULL; 1960 char *sz_out = NULL; 1927 1961 1928 1962 assert(raidrec != 0); 1929 1963 assert(lino >= 0); 1930 1964 1931 strcpy(sz_out, raidrec->additional_vars.el[lino].value);1932 sprintf(header, _("Edit %s"), raidrec->additional_vars.el[lino].label);1933 sprintf(comment, _("Please set %s's value (currently '%s')"),1965 asprintf(&sz_out, raidrec->additional_vars.el[lino].value); 1966 asprintf(&header, _("Edit %s"), raidrec->additional_vars.el[lino].label); 1967 asprintf(&comment, _("Please set %s's value (currently '%s')"), 1934 1968 raidrec->additional_vars.el[lino].label, sz_out); 1935 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1936 strip_spaces(sz_out); 1969 if (popup_and_get_string(header, comment, sz_out)) { 1937 1970 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1938 1971 } 1939 } 1940 1941 1942 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain. - Hugo, 09/01/2001 */ 1943 1972 paranoid_free(header); 1973 paranoid_free(comment); 1974 paranoid_free(sz_out); 1975 } 1944 1976 #endif 1977 1945 1978 1946 1979 /** … … 1972 2005 1973 2006 /** ???? *************************************************************/ 1974 void *curr_choice ;2007 void *curr_choice = NULL; 1975 2008 void *keylist[ARBITRARY_MAXIMUM]; 1976 2009 … … 1981 2014 1982 2015 /** buffers **********************************************************/ 1983 char tmp[MAX_STR_LEN];1984 char flaws_str_A[MAX_STR_LEN];1985 char flaws_str_B[MAX_STR_LEN];1986 char flaws_str_C[MAX_STR_LEN];2016 char *tmp = NULL; 2017 char *flaws_str_A = NULL; 2018 char *flaws_str_B = NULL; 2019 char *flaws_str_C = NULL; 1987 2020 1988 2021 assert(mountlist != NULL); 1989 2022 assert(raidlist != NULL); 1990 2023 1991 strcpy(flaws_str_A, "xxxxxxxxx");1992 strcpy(flaws_str_B, "xxxxxxxxx");1993 strcpy(flaws_str_C, "xxxxxxxxx");2024 asprintf(&flaws_str_A, "xxxxxxxxx"); 2025 asprintf(&flaws_str_B, "xxxxxxxxx"); 2026 asprintf(&flaws_str_C, "xxxxxxxxx"); 1994 2027 if (mountlist->entries > ARBITRARY_MAXIMUM) { 1995 2028 log_to_screen(_("Arbitrary limits suck, man!")); … … 1997 2030 } 1998 2031 newtPushHelpLine 1999 (_(" Please edit the mountlist to your satisfaction, then click OK or Cancel.")); 2032 (_ 2033 (" Please edit the mountlist to your satisfaction, then click OK or Cancel.")); 2000 2034 i = 4; 2001 2035 bAdd = newtCompactButton(i, 17, _(" Add ")); … … 2005 2039 bCancel = newtCompactButton(i += 12, 17, _("Cancel")); 2006 2040 bOK = newtCompactButton(i += 12, 17, _(" OK ")); 2007 sprintf(tmp, "%-24s %-24s %-8s %s", _("Device"), _("Mountpoint"), _("Format"),2008 _(" Size (MB)"));2041 asprintf(&tmp, "%-24s %-24s %-8s %s", _("Device"), _("Mountpoint"), 2042 _("Format"), _("Size (MB)")); 2009 2043 headerMsg = newtLabel(2, 1, tmp); 2010 2044 flawsLabelA = newtLabel(2, 13, flaws_str_A); … … 2026 2060 newtLabelSetText(flawsLabelC, flaws_str_C); 2027 2061 b_res = newtRunForm(myForm); 2062 /* BERLIOS: This needs to be re-written */ 2028 2063 if (b_res == bOK) { 2029 2064 if (!evaluate_mountlist … … 2035 2070 finished = 2036 2071 ask_me_yes_or_no 2037 (_("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)")); 2072 (_ 2073 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)")); 2038 2074 } 2039 2075 } else if (b_res == bCancel) { … … 2041 2077 } else if (b_res == bReload) { 2042 2078 if (ask_me_yes_or_no(_("Reload original mountlist?"))) { 2043 /*2044 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/242045 if (!RAIDTAB_FNAME[0])2046 {2047 strcpy(RAIDTAB_FNAME, "/etc/raidtab");2048 log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);2049 }2050 */2051 2079 load_mountlist(mountlist, mountlist_fname); 2052 2080 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); … … 2076 2104 } else { 2077 2105 popup_and_OK 2078 (_("Please add an entry. Then press ENTER to edit it.")); 2106 (_ 2107 ("Please add an entry. Then press ENTER to edit it.")); 2079 2108 } 2080 2109 } 2081 2110 } 2082 2111 } 2112 paranoid_free(flaws_str_A); 2113 paranoid_free(flaws_str_B); 2114 paranoid_free(flaws_str_C); 2083 2115 } 2084 2116 newtFormDestroy(myForm); … … 2095 2127 2096 2128 2097 2098 2129 /** 2099 2130 * Edit the mountlist. … … 2107 2138 { 2108 2139 int res = 0; 2109 // char tmp[MAX_STR_LEN];2110 2140 2111 2141 iamhere("entering eml"); … … 2121 2151 return (res); 2122 2152 } 2123 2124 2125 2153 2126 2154 … … 2149 2177 2150 2178 /** ?? ***************************************************************/ 2151 void *keylist[ARBITRARY_MAXIMUM], *curr_choice ;2179 void *keylist[ARBITRARY_MAXIMUM], *curr_choice = NULL; 2152 2180 2153 2181 /** buffers **********************************************************/ 2154 char title_of_window[MAX_STR_LEN];2182 char *title_of_window = NULL; 2155 2183 2156 2184 /** int **************************************************************/ … … 2163 2191 memcpy((void *) &bkp_raidrec, (void *) raidrec, 2164 2192 sizeof(struct raid_device_record)); 2165 sprintf(title_of_window, "Additional variables");2193 asprintf(&title_of_window, "Additional variables"); 2166 2194 newtPushHelpLine 2167 (_(" Edit the additional fields to your heart's content, then click OK or Cancel.")); 2168 headerMsg = newtLabel(1, 1, _("Label Value")); 2195 (_ 2196 (" Edit the additional fields to your heart's content, then click OK or Cancel.")); 2197 headerMsg = 2198 newtLabel(1, 1, _("Label Value")); 2169 2199 varsListbox = 2170 2200 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); … … 2176 2206 bCancel = newtCompactButton(i += 9, 9, _("Cancel")); 2177 2207 newtOpenWindow(17, 7, 46, 10, title_of_window); 2208 paranoid_free(title_of_window); 2209 2178 2210 myForm = newtForm(NULL, NULL, 0); 2179 2211 newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit, … … 2247 2279 2248 2280 2249 2250 2281 /** 2251 2282 * Locate @p device in @p raidlist. … … 2259 2290 char *device) 2260 2291 { 2261 2262 2292 /** int ***************************************************************/ 2263 2293 int i = 0; 2264 2294 #ifdef __FreeBSD__ 2265 char vdev[64]; 2266 #else 2267 // Linux 2295 char *vdev = NULL; 2268 2296 #endif 2269 2297 … … 2273 2301 #ifdef __FreeBSD__ 2274 2302 for (i = 0; i < raidlist->entries; i++) { 2275 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2276 if (!strcmp(device, vdev)) 2303 asprintf(&vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2304 if (!strcmp(device, vdev)) { 2305 paranoid_free(vdev); 2277 2306 break; 2307 } 2308 paranoid_free(vdev); 2278 2309 } 2279 2310 #else … … 2305 2336 /** initialize ********************************************************/ 2306 2337 2307 assert(isodir_device != NULL); 2308 assert(isodir_format != NULL); 2309 assert(isodir_path != NULL); 2310 2311 log_it("%d - AAA - isodir_path = %s", isodir_path); 2312 isodir_format[0] = '\0'; 2313 if (isodir_device[0] == '\0') { 2314 strcpy(isodir_device, "/dev/"); 2315 } 2316 if (isodir_path[0] == '\0') { 2317 strcpy(isodir_path, "/"); 2338 // %d no var ??? 2339 // log_it("%d - AAA - isodir_path = %s", isodir_path); 2340 if (isodir_device == NULL) { 2341 asprintf(&isodir_device, "/dev/"); 2342 } 2343 if (isodir_path == NULL) { 2344 asprintf(&isodir_path, "/"); 2318 2345 } 2319 2346 if (does_file_exist("/tmp/NFS-SERVER-PATH")) { 2320 strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT")); 2321 strcpy(isodir_format, "nfs"); 2322 strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH")); 2347 paranoid_free(isodir_device); 2348 isodir_device = last_line_of_file("/tmp/NFS-SERVER-MOUNT"); 2349 asprintf(&isodir_format, "nfs"); 2350 paranoid_free(isodir_path); 2351 isodir_path = last_line_of_file("/tmp/NFS-SERVER-PATH"); 2323 2352 } 2324 2353 if (nuke_me_please) { … … 2327 2356 2328 2357 if (popup_and_get_string 2329 (_("ISO Mode - device"), _("On what device do the ISO files live?"),2330 isodir_device, MAX_STR_LEN / 4)) {2358 (_("ISO Mode - device"), 2359 _("On what device do the ISO files live?"), isodir_device)) { 2331 2360 if (popup_and_get_string 2332 2361 (_("ISO Mode - format"), 2333 _("What is the disk format of the device? (Hit ENTER if you don't know.)"), 2334 isodir_format, 16)) { 2362 _ 2363 ("What is the disk format of the device? (Hit ENTER if you don't know.)"), 2364 isodir_format)) { 2335 2365 if (popup_and_get_string 2336 2366 (_("ISO Mode - path"), 2337 _("At what path on this device can the ISO files be found?"), 2338 isodir_path, MAX_STR_LEN / 4)) { 2339 strip_spaces(isodir_device); 2340 strip_spaces(isodir_format); 2341 strip_spaces(isodir_path); 2342 log_it("%d - BBB - isodir_path = %s", isodir_path); 2367 _ 2368 ("At what path on this device can the ISO files be found?"), 2369 isodir_path)) { 2370 // Same pb: 2371 // log_it("%d - BBB - isodir_path = %s", isodir_path); 2343 2372 return (TRUE); 2344 2373 } … … 2362 2391 int currline, char *device) 2363 2392 { 2364 2365 2393 /** structure *********************************************************/ 2366 2394 struct OSSWAP (raid_device_record, vinum_volume) * raidrec; … … 2415 2443 raidrec->additional_vars.entries = items; 2416 2444 } 2417 2418 2445 #endif 2446 2419 2447 2420 2448 /** … … 2433 2461 2434 2462 newtPushHelpLine 2435 (_("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!")); 2463 (_ 2464 ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!")); 2436 2465 newtOpenWindow(24, 3, 32, 13, _("Nuking")); 2437 2466 b1 = newtButton(7, 1, _("Slowly")); … … 2447 2476 2448 2477 2449 2450 2478 /** 2451 2479 * Redraw the disklist. … … 2512 2540 2513 2541 2514 2515 2516 2542 /** 2517 2543 * Redraw the list of unallocated RAID partitions. … … 2531 2557 2532 2558 /** buffers **********************************************************/ 2533 char tmp[MAX_STR_LEN];2559 char *tmp = NULL; 2534 2560 2535 2561 assert(unallocated_raid_partitions != NULL); … … 2542 2568 } 2543 2569 for (i = 0; i < unallocated_raid_partitions->entries; i++) { 2544 sprintf(tmp, "%-22s %8lld",2570 asprintf(&tmp, "%-22s %8lld", 2545 2571 unallocated_raid_partitions->el[i].device, 2546 2572 unallocated_raid_partitions->el[i].size / 1024); 2547 2573 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2548 } 2549 } 2574 paranoid_free(tmp); 2575 } 2576 } 2577 2550 2578 2551 2579 #ifndef __FreeBSD__ … … 2565 2593 2566 2594 /** buffers *********************************************************/ 2567 char tmp[MAX_STR_LEN];2595 char *tmp; 2568 2596 2569 2597 assert(additional_vars != NULL); … … 2577 2605 } 2578 2606 for (i = 0; i < additional_vars->entries; i++) { 2579 sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label,2607 asprintf(&tmp, "%-32s %-8s", additional_vars->el[i].label, 2580 2608 additional_vars->el[i].value); 2581 2609 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2610 paranoid_free(tmp); 2582 2611 } 2583 2612 } … … 2622 2651 #endif 2623 2652 2653 2624 2654 /** 2625 2655 * Change all RAID devices to use @p new_dev instead of @p old_dev. … … 2635 2665 { 2636 2666 /** buffers ********************************************************/ 2637 char tmp[MAX_STR_LEN];2667 char *tmp; 2638 2668 2639 2669 /** int ************************************************************/ … … 2647 2677 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2648 2678 if (pos < 0) { 2649 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",2679 asprintf(&tmp, "No need to rejig %s in raidlist: it's not listed.", 2650 2680 old_dev); 2651 2681 log_it(tmp); 2682 paranoid_free(tmp); 2652 2683 } else { 2653 2684 if ((j = … … 2681 2712 #endif 2682 2713 else { 2683 sprintf(tmp,2714 asprintf(&tmp, 2684 2715 "%s is supposed to be listed in this raid dev but it's not...", 2685 2716 old_dev); 2686 2717 log_it(tmp); 2718 paranoid_free(tmp); 2687 2719 } 2688 2720 } … … 2717 2749 res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size"); 2718 2750 } 2751 2719 2752 2720 2753 /** … … 2734 2767 struct list_of_disks *disklist) 2735 2768 { 2736 void *curr_choice; 2737 2738 /** ??? ***************************************************************/ 2769 void *curr_choice = NULL; 2739 2770 2740 2771 /** structures ********************************************************/ 2741 struct raidlist_itself *bkp_raidlist ;2742 struct raid_device_record *bkp_raidrec ;2743 struct list_of_disks *bkp_disklist ;2744 struct mountlist_itself *unallocated_raid_partitions ;2772 struct raidlist_itself *bkp_raidlist = NULL; 2773 struct raid_device_record *bkp_raidrec = NULL; 2774 struct list_of_disks *bkp_disklist = NULL; 2775 struct mountlist_itself *unallocated_raid_partitions = NULL; 2745 2776 2746 2777 /** newt **************************************************************/ … … 2756 2787 /** buffers **********************************************************/ 2757 2788 void *keylist[ARBITRARY_MAXIMUM]; 2758 char *tmp ;2759 char *help_text ;2760 char *title_of_window ;2761 char *sz_res ;2762 char *header_text ;2789 char *tmp = NULL; 2790 char *help_text = NULL; 2791 char *title_of_window = NULL; 2792 char *sz_res = NULL; 2793 char *header_text = NULL; 2763 2794 2764 2795 /** int **************************************************************/ … … 2773 2804 2774 2805 iamhere("malloc'ing"); 2775 malloc_string(tmp);2776 malloc_string(help_text);2777 malloc_string(title_of_window);2778 malloc_string(sz_res);2779 malloc_string(header_text);2780 2806 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2781 2807 fatal_error("Cannot malloc space for raidrec"); … … 2801 2827 2802 2828 iamhere("Post-malloc"); 2803 strcpy(help_text, 2804 _(" Edit this RAID device's list of partitions. Choose OK or Cancel when done.")); 2805 sprintf(header_text, "%-24s %s", _("Device"), _("Index")); 2806 sprintf(title_of_window, _("%s contains..."), raidrec->raid_device); 2829 asprintf(&help_text, 2830 _ 2831 (" Edit this RAID device's list of partitions. Choose OK or Cancel when done.")); 2832 asprintf(&header_text, "%-24s %s", _("Device"), _("Index")); 2833 asprintf(&title_of_window, _("%s contains..."), raidrec->raid_device); 2807 2834 newtPushHelpLine(help_text); 2835 paranoid_free(help_text); 2808 2836 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { 2809 2837 headerMsg = newtLabel(1, 1, header_text); … … 2844 2872 if (unallocated_raid_partitions->entries <= 0) { 2845 2873 popup_and_OK 2846 (_("There are no unallocated partitions marked for RAID.")); 2874 (_ 2875 ("There are no unallocated partitions marked for RAID.")); 2847 2876 } else { 2848 2877 log_it 2849 (_("Done. The user may add one or more of the above to RAID device")); 2878 (_ 2879 ("Done. The user may add one or more of the above to RAID device")); 2850 2880 add_disklist_entry(disklist, raidrec->raid_device, 2851 2881 unallocated_raid_partitions); 2852 log_it(_("I have finished adding a disklist entry.")); 2882 log_it(_ 2883 ("I have finished adding a disklist entry.")); 2853 2884 redraw_disklist(disklist, keylist, 2854 2885 partitionsListbox); … … 2859 2890 redraw_disklist(disklist, keylist, partitionsListbox); 2860 2891 } else { 2861 sprintf(tmp, _("%s's index is %d. What should it be?"),2892 asprintf(&tmp, _("%s's index is %d. What should it be?"), 2862 2893 raidrec->raid_device, 2863 2894 disklist->el[currline].index); 2864 sprintf(sz_res, "%d", disklist->el[currline].index); 2865 if (popup_and_get_string(_("Set index"), tmp, sz_res, 10)) { 2895 asprintf(&sz_res, "%d", disklist->el[currline].index); 2896 if (popup_and_get_string 2897 (_("Set index"), tmp, sz_res)) { 2866 2898 disklist->el[currline].index = atoi(sz_res); 2867 2899 } 2900 paranoid_free(tmp); 2901 paranoid_free(sz_res); 2868 2902 redraw_disklist(disklist, keylist, partitionsListbox); 2869 2903 } … … 2873 2907 newtPopWindow(); 2874 2908 } 2909 paranoid_free(title_of_window); 2910 paranoid_free(header_text); 2911 2875 2912 newtPopHelpLine(); 2876 2913 if (b_res == bCancel) { … … 2882 2919 sizeof(struct list_of_disks)); 2883 2920 } 2884 paranoid_free(tmp);2885 paranoid_free(help_text);2886 paranoid_free(title_of_window);2887 paranoid_free(sz_res);2888 paranoid_free(header_text);2889 2921 paranoid_free(bkp_raidrec); 2890 2922 paranoid_free(bkp_disklist); … … 2895 2927 2896 2928 2897 2898 2929 /** 2899 2930 * Ask the user which restore mode (nuke, interactive, or compare) we should use. … … 2906 2937 /** char *************************************************************/ 2907 2938 char output = '\0'; 2908 char tmp[MAX_STR_LEN]; 2939 char *tmp = NULL; 2940 size_t n = 0; 2909 2941 2910 2942 /** newt *************************************************************/ … … 2920 2952 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) { 2921 2953 printf 2922 (_("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ")); 2923 fgets(tmp, MAX_STR_LEN - 1, stdin); 2924 } 2954 (_ 2955 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> ")); 2956 getline(&tmp, &n, stdin); 2957 } 2958 paranoid_free(tmp); 2925 2959 return (output); 2926 2960 } 2927 2961 2928 2962 newtPushHelpLine 2929 (_(" Do you want to 'nuke' your system, restore interactively, or just compare?")); 2963 (_ 2964 (" Do you want to 'nuke' your system, restore interactively, or just compare?")); 2930 2965 newtOpenWindow(24, 3, 32, 17, _("How should I restore?")); 2931 2966 b1 = newtButton(7, 1, _("Automatically")); -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.h
r507 r688 1 /*************************************************************************** 2 mondo-rstr-newt.h - description 3 ------------------- 4 begin : Sat Apr 20 2002 5 copyright : (C) 2002 by Stan Benoit 6 email : troff@nakedsoul.org 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 1 /* 2 * $Id$ 3 **/ 19 4 20 5 #include "../common/my-stuff.h" … … 72 57 extern bool g_ISO_restore_mode; 73 58 74 75 /* my global variables */76 77 //extern newtComponent g_progressForm, g_blurb1, g_blurb2, g_blurb3, g_label,78 // g_timeline, g_percentline, g_scale;79 //extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN], g_blurb_str_1[MAX_STR_LEN] =80 // "", g_blurb_str_2[MAX_STR_LEN] = "", g_blurb_str_3[MAX_STR_LEN] = "";81 //newtComponent g_isoform_main =82 // NULL, g_isoform_header, g_isoform_scale, g_isoform_timeline,83 // g_isoform_pcline;84 //long g_isoform_starttime;85 //int g_isoform_old_progress = -1;86 //char g_isoform_header_str[MAX_STR_LEN];87 //int g_mysterious_dot_counter;88 89 90 91 92 93 59 /* my subroutines */ 94 60 … … 137 103 struct raidlist_itself *); 138 104 void edit_raidrec_additional_vars(struct raid_device_record *); 139 int evaluate_drive_within_mountlist(struct mountlist_itself *, char *,140 char *);141 105 int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *); 142 106 int find_device_in_mountlist(struct mountlist_itself *, char *); … … 151 115 void log_to_screen(const char *fmt, ...); 152 116 int look_for_duplicate_mountpoints(struct mountlist_itself *, char *); 153 int look_for_weird_formats(struct mountlist_itself *, char *);154 117 void make_list_of_unallocated_raid_partitions(struct mountlist_itself *, 155 118 struct mountlist_itself *, … … 162 125 void open_progress_form(char *, char *, char *, char *, long); 163 126 void popup_and_OK(char *); 164 bool popup_and_get_string(char *, char *, char * , int);127 bool popup_and_get_string(char *, char *, char *); 165 128 bool popup_with_buttons(char *, char *, char *); 166 129 void redraw_disklist(struct list_of_disks *, void *keylist[], … … 194 157 char *strip_path(char *); 195 158 196 197 198 199 159 /* -------------------------------------------------------------------- */ 200 160 201 202 203 204 char tmpnopath[MAX_STR_LEN + 2];205 char tmpprevpath[MAX_STR_LEN + 2];206 161 207 162 #ifdef __FreeBSD__ -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h
r59 r688 1 /* mondo-rstr-tools-EXT.h1 /* 2 2 * $Id: mondo-rstr-tools-EXT.h 3 3 **/ 4 4 5 5 extern void free_MR_global_filenames(); … … 8 8 extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 extern void kill_petris(void); 10 extern int modify_rclocal_one_time(char *path);11 10 extern int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 11 extern int mount_device(char *, char *, char *, bool); … … 27 26 extern void set_signals(int on); 28 27 extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo); 29 //extern void setup_signals(int);30 28 extern void terminate_daemon(int); 31 29 extern void termination_in_progress(int); -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r687 r688 1 1 /* 2 2 * $Id$ 3 */ 4 3 **/ 4 5 #include <unistd.h> 5 6 6 7 #include "../common/my-stuff.h" … … 8 9 #include "../common/libmondo.h" 9 10 #include "mr-externs.h" 10 //#include "mondo-restore.h"11 //#include "mondo-rstr-compare-EXT.h"12 11 #include "mondo-rstr-tools.h" 13 12 #ifndef S_SPLINT_S … … 55 54 paranoid_free(g_filelist_full); 56 55 paranoid_free(g_filelist_imagedevs); 57 // paranoid_free (g_imagedevs_pot );58 56 paranoid_free(g_imagedevs_restthese); 59 57 paranoid_free(g_mondo_cfg_file); … … 67 65 68 66 69 70 67 /** 71 68 * Ask the user which imagedevs from the list contained in @p infname should … … 77 74 void ask_about_these_imagedevs(char *infname, char *outfname) 78 75 { 79 FILE *fin ;80 FILE *fout ;76 FILE *fin = NULL; 77 FILE *fout = NULL; 81 78 /************************************************************************ 82 79 * allocate memory regions. test and set -sab 16 feb 2003 * 83 80 ************************************************************************/ 84 char *incoming ;85 char *question ;81 char *incoming = NULL; 82 char *question = NULL; 86 83 87 84 size_t n = 0; … … 105 102 106 103 asprintf(&question, 107 _("Should I restore the image of %s ?", incoming));104 _("Should I restore the image of %s ?"), incoming); 108 105 109 106 if (ask_me_yes_or_no(question)) { 110 107 fprintf(fout, "%s\n", incoming); 111 108 } 109 paranoid_free(question); 112 110 } 113 111 114 112 /*** free memory ***********/ 115 113 paranoid_free(incoming); 116 paranoid_free(question);117 118 114 119 115 paranoid_fclose(fout); … … 124 120 *ASK_ABOUT_THESE_IMAGEDEVS * 125 121 **************************************************************************/ 126 127 128 129 130 131 132 122 133 123 … … 147 137 char *output_mountlist_file) 148 138 { 149 char *mountpt ;150 char *command ;151 char *orig_fname ;139 char *mountpt = NULL; 140 char *command = NULL; 141 char *orig_fname = NULL; 152 142 int retval = 0; 153 143 154 144 assert(bkpinfo != NULL); 155 malloc_string(mountpt);156 malloc_string(command);157 malloc_string(orig_fname);158 145 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 159 146 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 160 147 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 161 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);162 sprintf(command, "mkdir -p %s", mountpt);148 asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 149 asprintf(&command, "mkdir -p %s", mountpt); 163 150 run_program_and_log_output(command, FALSE); 164 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 151 paranoid_free(command); 152 153 asprintf(&command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 165 154 ramdisk_fname, bkpinfo->tmpdir); 166 167 155 run_program_and_log_output(command, FALSE); 168 sprintf(command, "umount %s", mountpt); 169 156 paranoid_free(command); 157 158 asprintf(&command, "umount %s", mountpt); 170 159 run_program_and_log_output(command, FALSE); 171 172 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s", 160 paranoid_free(command); 161 162 asprintf(&command, "mount -o loop %s/mindi.rd -t ext2 %s", 173 163 bkpinfo->tmpdir, mountpt); 174 175 164 run_program_and_log_output(command, FALSE); 176 177 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 178 165 paranoid_free(command); 166 167 asprintf(&command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 179 168 run_program_and_log_output(command, FALSE); 180 181 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 169 paranoid_free(command); 170 171 asprintf(&command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 182 172 mountpt, g_mondo_cfg_file, output_cfg_file); 183 173 run_program_and_log_output(command, FALSE); 184 185 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname); 174 paranoid_free(command); 175 176 asprintf(&orig_fname, "%s/%s", mountpt, g_mountlist_fname); 186 177 if (does_file_exist(orig_fname)) { 187 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);178 asprintf(&command, "cp -f %s %s", orig_fname, output_mountlist_file); 188 179 run_program_and_log_output(command, FALSE); 189 } 190 sprintf(command, "umount %s", mountpt); 180 paranoid_free(command); 181 } 182 asprintf(&command, "umount %s", mountpt); 183 paranoid_free(mountpt); 184 191 185 run_program_and_log_output(command, FALSE); 186 paranoid_free(command); 187 192 188 if (!does_file_exist(output_cfg_file) 193 189 || (!does_file_exist(output_mountlist_file) … … 199 195 retval = 0; 200 196 } 201 paranoid_free(mountpt);202 paranoid_free(command);203 197 paranoid_free(orig_fname); 204 198 return (retval); 205 206 } 207 208 199 } 209 200 210 201 … … 217 208 while (get_cfg_file_from_archive(bkpinfo)) { 218 209 if (!ask_me_yes_or_no 219 (_("Failed to find config file/archives. Choose another source?"))) 210 (_ 211 ("Failed to find config file/archives. Choose another source?"))) 220 212 { 221 213 fatal_error("Could not find config file/archives. Aborting."); … … 237 229 238 230 /** needs malloc **/ 239 char *command; 240 char *file; 241 char *tmp; 242 int res; 243 244 malloc_string(command); 245 malloc_string(file); 246 malloc_string(tmp); 231 char *command = NULL; 232 char *file = NULL; 233 char *tmp = NULL; 234 int res = 0; 235 247 236 assert_string_is_neither_NULL_nor_zerolength(f); 248 237 assert_string_is_neither_NULL_nor_zerolength(list_fname); … … 250 239 251 240 if (strncmp(preamble, f, strlen(preamble)) == 0) { 252 strcpy(file, f + strlen(preamble));253 } else { 254 strcpy(file, f);241 asprintf(&file, f + strlen(preamble)); 242 } else { 243 asprintf(&file, f); 255 244 } 256 245 if (file[0] == '/' && file[1] == '/') { 257 strcpy(tmp, file); 258 strcpy(file, tmp + 1); 259 } 260 sprintf(tmp, 246 asprintf(&tmp, file); 247 paranoid_free(file); 248 asprintf(&file, tmp + 1); 249 paranoid_free(tmp); 250 } 251 asprintf(&tmp, 261 252 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 262 253 f, file); 263 254 log_msg(2, tmp); 264 sprintf(command, "grep -x \"%s\" %s", file, list_fname); 255 paranoid_free(tmp); 256 257 asprintf(&command, "grep -x \"%s\" %s", file, list_fname); 258 paranoid_free(file); 259 265 260 res = run_program_and_log_output(command, FALSE); 266 261 paranoid_free(command); 267 paranoid_free(file);268 paranoid_free(tmp);269 262 if (res) { 270 263 return (FALSE); … … 273 266 } 274 267 } 275 276 268 /************************************************************************** 277 269 *END_IS_FILE_IN_LIST * 278 270 **************************************************************************/ 279 280 271 281 272 … … 291 282 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please) 292 283 { 293 char *mount_isodir_command, *tmp, *command; 294 int retval = 0, i; 284 char *mount_isodir_command = NULL; 285 char *tmp = NULL; 286 char *command = NULL; 287 int retval = 0, i = 0; 295 288 bool already_mounted = FALSE; 296 289 297 290 assert(bkpinfo != NULL); 298 malloc_string(mount_isodir_command);299 malloc_string(tmp);300 malloc_string(command);301 291 g_ISO_restore_mode = TRUE; 302 292 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); … … 308 298 } 309 299 /* End patch */ 310 sprintf(command, "mkdir -p %s", bkpinfo->isodir);300 asprintf(&command, "mkdir -p %s", bkpinfo->isodir); 311 301 run_program_and_log_output(command, 5); 302 paranoid_free(command); 312 303 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 313 304 } … … 324 315 already_mounted = TRUE; 325 316 } else { 326 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 327 if (strlen(g_isodir_format) > 1) { 328 sprintf(mount_isodir_command + strlen(mount_isodir_command), 329 " -t %s", g_isodir_format); 330 } 331 strcat(mount_isodir_command, " -o ro "); 332 strcat(mount_isodir_command, bkpinfo->isodir); 317 if (g_isodir_format != NULL) { 318 asprintf(&mount_isodir_command, "mount %s -t %s -o ro %s", g_isodir_device, g_isodir_format, bkpinfo->isodir); 319 } else { 320 asprintf(&mount_isodir_command, "mount %s -o ro %s", g_isodir_device, bkpinfo->isodir); 321 } 333 322 run_program_and_log_output("df -P -m", FALSE); 334 sprintf(tmp,323 asprintf(&tmp, 335 324 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 336 325 mount_isodir_command); 337 326 log_msg(1, tmp); 327 paranoid_free(tmp); 328 338 329 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 339 330 popup_and_OK 340 (_("Cannot mount the device where the ISO files are stored.")); 331 (_ 332 ("Cannot mount the device where the ISO files are stored.")); 333 paranoid_free(mount_isodir_command); 341 334 return (1); 342 335 } 336 paranoid_free(mount_isodir_command); 343 337 log_to_screen 344 (_("I have mounted the device where the ISO files are stored.")); 338 (_ 339 ("I have mounted the device where the ISO files are stored.")); 345 340 } 346 341 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { … … 348 343 } 349 344 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 350 sprintf(tmp, "%s #%d has been mounted via loopback mount",345 asprintf(&tmp, "%s #%d has been mounted via loopback mount", 351 346 media_descriptor_string(bkpinfo->backup_media_type), i); 352 347 log_msg(1, tmp); 348 paranoid_free(tmp); 349 353 350 if (i < 0) { 354 351 popup_and_OK … … 358 355 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 359 356 bkpinfo->isodir); 360 paranoid_free(mount_isodir_command);361 paranoid_free(tmp);362 paranoid_free(command);363 357 return (retval); 364 358 } 365 359 366 360 367 368 369 361 /** 370 362 * Kill all Petris processes. … … 373 365 { 374 366 char *command; 375 malloc_string(command); 376 sprintf(command, 367 asprintf(&command, 377 368 "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 378 369 paranoid_system(command); … … 383 374 *END_KILL_PETRIS * 384 375 **************************************************************************/ 385 386 387 /**388 * (Disabled) Modify rc.local to fix some things on first boot.389 * This function currently doesn't do anything except make sure /tmp has the390 * right permissions.391 * @param path The path to /etc on the user's filesystem.392 * @return 0 for success, nonzero for failure.393 */394 int modify_rclocal_one_time(char *path)395 {396 /** malloc **/397 char *rclocal_fname;398 char *newfile_fname;399 char *tmp;400 401 malloc_string(rclocal_fname);402 malloc_string(newfile_fname);403 malloc_string(tmp);404 assert_string_is_neither_NULL_nor_zerolength(path);405 406 sprintf(rclocal_fname, "%s/rc.local", path);407 408 // sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);409 // run_program_and_log_output( tmp, FALSE );410 return (0); /* remove this line to open the floodgates... */411 412 if (!does_file_exist(rclocal_fname)) {413 sprintf(rclocal_fname, "%s/rc.d/rc.local", path);414 }415 if (!does_file_exist(rclocal_fname)) {416 paranoid_free(rclocal_fname);417 paranoid_free(newfile_fname);418 paranoid_free(tmp);419 return (1);420 }421 sprintf(newfile_fname, "%s/rc.local.mondorescue", path);422 sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null",423 rclocal_fname);424 if (system(tmp)) {425 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",426 newfile_fname, newfile_fname, rclocal_fname);427 428 paranoid_system(tmp);429 }430 sprintf(tmp, "echo -en \"#!/bin/sh\431 \\n\432 \\n\433 grep -v mondorescue %s > %s\\n\434 rm -f /var/lock/subsys/*xfs*\\n\435 rm -f /var/run/xfs.*\\n\436 killall xfs\\n\437 service xfs start\\n\438 yes | rm -f %s\\n\439 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);440 sprintf(tmp, "chmod +x \"%s\"", newfile_fname);441 run_program_and_log_output(tmp, FALSE);442 paranoid_free(rclocal_fname);443 paranoid_free(newfile_fname);444 paranoid_free(tmp);445 return (0);446 }447 448 /**************************************************************************449 *END_ MODIFY_RCLOCAL_ONE_TIME *450 **************************************************************************/451 452 453 454 376 455 377 … … 463 385 *p_external_copy_of_mountlist, bool writeable) 464 386 { 465 int retval = 0, lino, res; 466 char *tmp, *these_failed, *format; 467 struct mountlist_itself *mountlist; 468 469 malloc_string(tmp); 470 malloc_string(format); 471 malloc_string(these_failed); 387 int retval = 0; 388 int lino = 0; 389 int res = 0; 390 char *tmp = NULL; 391 char *these_failed = NULL; 392 char *format = NULL; 393 struct mountlist_itself *mountlist = NULL; 394 472 395 assert(p_external_copy_of_mountlist != NULL); 473 396 mountlist = malloc(sizeof(struct mountlist_itself)); … … 476 399 sort_mountlist_by_mountpoint(mountlist, 0); 477 400 478 /** menset **/479 these_failed[0] = '\0';480 481 401 mvaddstr_and_log_it(g_currentY, 0, _("Mounting devices ")); 482 402 open_progress_form(_("Mounting devices"), … … 490 410 "Again with the /proc - why is this in your mountlist?"); 491 411 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 492 sprintf(tmp, _("%s is already mounted"),412 asprintf(&tmp, _("%s is already mounted"), 493 413 mountlist->el[lino].device); 494 414 log_to_screen(tmp); 415 paranoid_free(tmp); 495 416 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 496 417 && strcmp(mountlist->el[lino].mountpoint, "lvm") 497 418 && strcmp(mountlist->el[lino].mountpoint, "raid") 498 419 && strcmp(mountlist->el[lino].mountpoint, "image")) { 499 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);420 asprintf(&tmp, "Mounting %s", mountlist->el[lino].device); 500 421 update_progress_form(tmp); 501 strcpy(format, mountlist->el[lino].format); 422 paranoid_free(tmp); 423 424 asprintf(&format, mountlist->el[lino].format); 502 425 if (!strcmp(format, "ext3")) { 503 strcpy(format, "ext2"); 426 paranoid_free(format); 427 asprintf(&format, "ext2"); 504 428 } 505 429 res = mount_device(mountlist->el[lino].device, … … 508 432 retval += res; 509 433 if (res) { 510 strcat(these_failed, mountlist->el[lino].device); 511 strcat(these_failed, " "); 512 } 434 if (these_failed != NULL) { /* not the first time */ 435 asprintf(&tmp, "%s %s", these_failed, mountlist->el[lino].device); 436 paranoid_free(these_failed); 437 these_failed = tmp; 438 } else { /* The first time */ 439 asprintf(&these_failed, "%s ", mountlist->el[lino].device); 440 } 441 } 442 paranoid_free(format); 513 443 } 514 444 g_current_progress++; … … 519 449 if (g_partition_table_locked_up > 0) { 520 450 log_to_screen 521 (_("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to")); 522 log_to_screen 523 (_("lock up the partition table. You might have to reboot and use Interactive Mode to")); 524 log_to_screen 525 (_("format and restore *without* partitioning first. Sorry for the inconvenience.")); 526 } 527 sprintf(tmp, _("Could not mount devices %s- shall I abort?"), 451 (_ 452 ("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to")); 453 log_to_screen(_ 454 ("lock up the partition table. You might have to reboot and use Interactive Mode to")); 455 log_to_screen(_ 456 ("format and restore *without* partitioning first. Sorry for the inconvenience.")); 457 } 458 asprintf(&tmp, _("Could not mount devices %s- shall I abort?"), 528 459 these_failed); 460 paranoid_free(these_failed); 461 529 462 if (!ask_me_yes_or_no(tmp)) { 530 463 retval = 0; 531 464 log_to_screen 532 (_("Continuing, although some devices failed to be mounted")); 465 (_ 466 ("Continuing, although some devices failed to be mounted")); 533 467 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 534 468 } else { … … 537 471 (_("Unable to mount some or all of your partitions.")); 538 472 } 473 paranoid_free(tmp); 539 474 } else { 540 475 log_to_screen(_("All partitions were mounted OK.")); … … 543 478 run_program_and_log_output("df -P -m", 3); 544 479 paranoid_free(mountlist); 545 paranoid_free(tmp);546 paranoid_free(format);547 paranoid_free(these_failed);548 480 return (retval); 549 481 } 550 551 482 /************************************************************************** 552 483 *END_MOUNT_ALL_DEVICES * … … 565 496 int mount_cdrom(struct s_bkpinfo *bkpinfo) 566 497 { 567 char *mount_cmd, *tmp; 498 char *mount_cmd = NULL; 499 char *tmp = NULL; 568 500 int i, res; 569 501 #ifdef __FreeBSD__ 570 char mdd[32]; 571 char *mddev = mdd; 502 char *mddev = NULL; 572 503 #endif 573 504 574 malloc_string(mount_cmd);575 505 assert(bkpinfo != NULL); 576 506 … … 578 508 || bkpinfo->backup_media_type == udev) { 579 509 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 580 paranoid_free(mount_cmd);581 510 return 0; 582 511 } … … 584 513 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 585 514 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 586 paranoid_free(mount_cmd);587 515 return (0); 588 516 } … … 597 525 } 598 526 #ifdef __FreeBSD__ 599 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 600 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number); 527 asprintf(&mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 528 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 529 g_current_media_number); 601 530 mddev = make_vn(mount_cmd); 602 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 531 paranoid_free(mount_cmd); 532 533 asprintf(&mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 534 paranoid_free(mddev); 603 535 #else 604 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 605 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 606 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 536 asprintf(&mount_cmd, 537 "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 538 bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, 539 g_current_media_number, MNT_CDROM); 607 540 #endif 608 541 609 542 } else if (bkpinfo->backup_media_type == iso) { 610 543 #ifdef __FreeBSD__ 611 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,544 asprintf(&mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir, 612 545 bkpinfo->prefix, g_current_media_number); 613 546 mddev = make_vn(mount_cmd); 614 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 547 paranoid_free(mount_cmd); 548 549 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 550 paranoid_free(mddev); 615 551 #else 616 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 617 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 552 asprintf(&mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 553 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, 554 MNT_CDROM); 618 555 #endif 619 556 } else if (strstr(bkpinfo->media_device, "/dev/")) 620 557 #ifdef __FreeBSD__ 621 558 { 622 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,559 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 623 560 MNT_CDROM); 624 561 } 625 562 #else 626 563 { 627 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",564 asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s", 628 565 bkpinfo->media_device, MNT_CDROM); 629 566 } … … 634 571 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 635 572 paranoid_free(bkpinfo->media_device); 636 asprintf(&tmp, 637 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 638 bkpinfo->media_device = tmp; 573 bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE"); 639 574 } else { 640 575 paranoid_free(bkpinfo->media_device); … … 643 578 644 579 #ifdef __FreeBSD__ 645 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,580 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 646 581 MNT_CDROM); 647 582 #else 648 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",583 asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s", 649 584 bkpinfo->media_device, MNT_CDROM); 650 585 #endif … … 662 597 } 663 598 } 599 paranoid_free(mount_cmd); 600 664 601 if (res) { 665 602 log_msg(2, "Failed, despite %d attempts", i); … … 667 604 log_msg(2, "Mounted CD-ROM drive OK"); 668 605 } 669 paranoid_free(mount_cmd);670 606 return (res); 671 607 } 672 673 674 675 676 677 608 /************************************************************************** 678 609 *END_MOUNT_CDROM * … … 692 623 int res = 0; 693 624 694 /** malloc **/ 695 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 625 char *tmp = NULL; 626 char *command = NULL; 627 char *mountdir = NULL; 628 char *mountpoint = NULL; 629 char *additional_parameters = NULL; 630 char *p1 = NULL; 631 char *p2 = NULL; 632 char *p3 = NULL; 696 633 697 634 assert_string_is_neither_NULL_nor_zerolength(device); 698 635 assert_string_is_neither_NULL_nor_zerolength(mpt); 699 636 assert(format != NULL); 700 malloc_string(tmp);701 malloc_string(command);702 malloc_string(mountdir);703 malloc_string(mountpoint);704 malloc_string(additional_parameters);705 637 706 638 if (!strcmp(mpt, "/1")) { 707 strcpy(mountpoint, "/");639 asprintf(&mountpoint, "/"); 708 640 log_msg(3, "Mommm! SME is being a dildo!"); 709 641 } else { 710 strcpy(mountpoint, mpt);642 asprintf(&mountpoint, mpt); 711 643 } 712 644 713 645 if (!strcmp(mountpoint, "lvm")) { 646 paranoid_free(mountpoint); 714 647 return (0); 715 648 } 716 649 if (!strcmp(mountpoint, "image")) { 650 paranoid_free(mountpoint); 717 651 return (0); 718 652 } 719 sprintf(tmp, "Mounting device %s ", device);653 asprintf(&tmp, "Mounting device %s ", device); 720 654 log_msg(1, tmp); 655 721 656 if (writeable) { 722 strcpy(additional_parameters, "-o rw");723 } else { 724 strcpy(additional_parameters, "-o ro");657 asprintf(&p1, "-o rw"); 658 } else { 659 asprintf(&p1, "-o ro"); 725 660 } 726 661 if (find_home_of_exe("setfattr")) { 727 strcat(additional_parameters, ",user_xattr"); 662 asprintf(&p2, ",user_xattr"); 663 } else { 664 asprintf(&p2, ""); 728 665 } 729 666 if (find_home_of_exe("setfacl")) { 730 strcat(additional_parameters, ",acl"); 731 } 667 asprintf(&p3, ",acl"); 668 } else { 669 asprintf(&p3, ""); 670 } 671 asprintf(&additional_parameters, "%s%s%s", p1, p2, p3); 672 paranoid_free(p1); 673 paranoid_free(p2); 674 paranoid_free(p3); 732 675 733 676 if (!strcmp(mountpoint, "swap")) { 734 sprintf(command, "swapon %s", device);677 asprintf(&command, "swapon %s", device); 735 678 } else { 736 679 if (!strcmp(mountpoint, "/")) { 737 strcpy(mountdir, MNT_RESTORING);680 asprintf(&mountdir, MNT_RESTORING); 738 681 } else { 739 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);740 } 741 sprintf(command, "mkdir -p %s", mountdir);682 asprintf(&mountdir, "%s%s", MNT_RESTORING, mountpoint); 683 } 684 asprintf(&command, "mkdir -p %s", mountdir); 742 685 run_program_and_log_output(command, FALSE); 743 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 686 paranoid_free(command); 687 688 asprintf(&command, "mount -t %s %s %s %s 2>> %s", format, device, 744 689 additional_parameters, mountdir, MONDO_LOGFILE); 745 690 log_msg(2, "command='%s'", command); 746 691 } 692 paranoid_free(additional_parameters); 693 747 694 res = run_program_and_log_output(command, TRUE); 748 695 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 749 696 log_msg(1, "Re-trying without the fancy extra parameters"); 750 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 697 paranoid_free(command); 698 699 asprintf(&command, "mount -t %s %s %s 2>> %s", format, device, 751 700 mountdir, MONDO_LOGFILE); 752 701 res = run_program_and_log_output(command, TRUE); … … 760 709 } else { 761 710 log_msg(2, "Retrying w/o the '-t' switch"); 762 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 711 paranoid_free(command); 712 713 asprintf(&command, "mount %s %s 2>> %s", device, mountdir, 763 714 MONDO_LOGFILE); 764 715 log_msg(2, "2nd command = '%s'", command); … … 772 723 } 773 724 } 725 paranoid_free(tmp); 726 paranoid_free(command); 727 paranoid_free(mountdir); 728 774 729 if (res && !strcmp(mountpoint, "swap")) { 775 730 log_msg(2, "That's ok. It's just a swap partition."); … … 777 732 res = 0; 778 733 } 779 780 paranoid_free(tmp);781 paranoid_free(command);782 paranoid_free(mountdir);783 734 paranoid_free(mountpoint); 784 paranoid_free(additional_parameters);785 735 786 736 return (res); 787 737 } 788 789 738 /************************************************************************** 790 739 *END_MOUNT_DEVICE * 791 740 **************************************************************************/ 792 793 741 794 742 … … 819 767 TRUE); 820 768 } 821 822 769 /************************************************************************** 823 770 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * 824 771 **************************************************************************/ 825 826 827 772 828 773 … … 836 781 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 837 782 { 838 /** add mallocs **/ 839 char *value; 840 char *tmp; 841 char *command; 842 char *iso_mnt; 843 char *iso_path; 844 char *old_isodir; 845 char cfg_file[100]; 783 char *value = NULL; 784 char *tmp = NULL; 785 char *command = NULL; 786 char *iso_mnt = NULL; 787 char *iso_path = NULL; 788 char *old_isodir = NULL; 789 char *cfg_file = NULL; 846 790 t_bkptype media_specified_by_user; 847 791 848 malloc_string(command);849 malloc_string(iso_mnt);850 malloc_string(iso_path);851 malloc_string(old_isodir);852 malloc_string(value);853 malloc_string(tmp);854 // assert_string_is_neither_NULL_nor_zerolength(cfg_file);855 792 assert(bkpinfo != NULL); 856 793 857 794 if (!cfgf) { 858 strcpy(cfg_file, g_mondo_cfg_file);859 } else { 860 strcpy(cfg_file, cfgf);795 cfg_file = g_mondo_cfg_file; 796 } else { 797 cfg_file = cfgf; 861 798 } 862 799 … … 873 810 bkpinfo->backup_media_type = dvd; 874 811 } else if (!strcmp(value, "iso")) { 875 /* 876 if (am_I_in_disaster_recovery_mode() 877 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1) 878 && does_file_exist(MNT_CDROM"/archives/filelist.0")) 879 */ 880 881 // Patch by Conor Daly - 2004/07/12 812 // Patch by Conor Daly - 2004/07/12 882 813 bkpinfo->backup_media_type = iso; 883 814 if (am_I_in_disaster_recovery_mode()) { … … 896 827 } 897 828 } 829 paranoid_free(value); 830 898 831 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 899 strcpy(bkpinfo->prefix,value); 832 paranoid_free(bkpinfo->prefix); 833 bkpinfo->prefix = value; 900 834 } else { 901 strcpy(bkpinfo->prefix,STD_PREFIX);835 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 902 836 } 903 837 } else if (!strcmp(value, "nfs")) { 904 838 bkpinfo->backup_media_type = nfs; 839 paranoid_free(value); 905 840 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 906 strcpy(bkpinfo->prefix,value); 841 paranoid_free(bkpinfo->prefix); 842 bkpinfo->prefix = value; 907 843 } else { 908 strcpy(bkpinfo->prefix,STD_PREFIX);844 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 909 845 } 910 846 } else if (!strcmp(value, "tape")) { … … 918 854 fatal_error("backup-media-type not specified!"); 919 855 } 856 paranoid_free(value); 857 920 858 if (bkpinfo->disaster_recovery) { 921 859 if (bkpinfo->backup_media_type == cdstream) { … … 930 868 read_cfg_var(cfg_file, "media-size", value); 931 869 bkpinfo->media_size[1] = atol(value); 932 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 870 paranoid_free(value); 871 872 asprintf(&tmp, "Backup medium is TAPE --- dev=%s", 933 873 bkpinfo->media_device); 934 874 log_msg(2, tmp); 875 paranoid_free(tmp); 935 876 } else { 936 877 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); … … 949 890 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 950 891 } 892 paranoid_free(value); 951 893 952 894 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { … … 960 902 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 961 903 } 904 paranoid_free(value); 962 905 963 906 read_cfg_var(cfg_file, "use-lzo", value); 964 907 if (strstr(value, "yes")) { 965 908 bkpinfo->use_lzo = TRUE; 966 strcpy(bkpinfo->zip_exe, "lzop"); 967 strcpy(bkpinfo->zip_suffix, "lzo"); 968 } else { 909 paranoid_alloc(bkpinfo->zip_exe, "lzop"); 910 paranoid_alloc(bkpinfo->zip_suffix, "lzo"); 911 } else { 912 paranoid_free(value); 969 913 read_cfg_var(cfg_file, "use-comp", value); 970 914 if (strstr(value, "yes")) { 971 915 bkpinfo->use_lzo = FALSE; 972 strcpy(bkpinfo->zip_exe, "bzip2");973 strcpy(bkpinfo->zip_suffix, "bz2");916 paranoid_alloc(bkpinfo->zip_exe, "bzip2"); 917 paranoid_alloc(bkpinfo->zip_suffix, "bz2"); 974 918 } else { 975 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 976 } 977 } 978 979 value[0] = '\0'; 919 // Just to be sure 920 bkpinfo->zip_exe = NULL; 921 bkpinfo->zip_suffix = NULL; 922 } 923 } 924 paranoid_free(value); 925 980 926 read_cfg_var(cfg_file, "differential", value); 981 927 if (!strcmp(value, "yes") || !strcmp(value, "1")) { … … 983 929 } 984 930 log_msg(2, "differential var = '%s'", value); 931 paranoid_free(value); 932 985 933 if (bkpinfo->differential) { 986 934 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); … … 990 938 991 939 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp); 992 if (tmp[0] 993 || 994 strstr(call_program_and_get_last_line_of_output 995 ("cat /proc/cmdline"), "donteject")) { 940 #ifdef __FreeBSD__ 941 tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 942 #else 943 tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 944 #endif 945 if ((tmp != NULL) || strstr(tmp1,"donteject")) { 996 946 bkpinfo->please_dont_eject = TRUE; 997 947 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); 998 948 } 949 paranoid_free(tmp); 950 paranoid_free(tmp1); 999 951 1000 952 if (bkpinfo->backup_media_type == nfs) { … … 1018 970 * isodir in disaster recovery mode 1019 971 */ 1020 strcpy(old_isodir, bkpinfo->isodir);972 old_isodir = bkpinfo->isodir; 1021 973 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1022 974 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1023 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1024 if (!bkpinfo->isodir[0]) { 1025 strcpy(bkpinfo->isodir, old_isodir); 1026 } 975 if (iso_mnt && iso_path) { 976 asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 977 } else { 978 bkpinfo->isodir = old_isodir; 979 } 980 paranoid_free(iso_mnt); 981 paranoid_free(iso_path); 982 1027 983 if (!bkpinfo->disaster_recovery) { 1028 984 if (strcmp(old_isodir, bkpinfo->isodir)) { … … 1030 986 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n", 1031 987 old_isodir, bkpinfo->isodir); 1032 strcpy(bkpinfo->isodir, old_isodir); 1033 } 1034 } 988 if (bkpinfo->isodir != old_isodir) { 989 paranoid_free(old_isodir); 990 } 991 } else { 992 paranoid_free(old_isodir); 993 } 994 } 995 1035 996 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1036 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, 1037 g_isodir_device); 997 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 1038 998 if (bkpinfo->disaster_recovery) { 1039 999 if (is_this_device_mounted(g_isodir_device)) { 1040 1000 log_msg(2, "NB: isodir is already mounted"); 1041 1001 /* Find out where it's mounted */ 1042 sprintf(command,1002 asprintf(&command, 1043 1003 "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 1044 1004 g_isodir_device); 1045 1005 log_it("command = %s", command); 1046 log_it("res of it = %s",1047 call_program_and_get_last_line_of_output(command));1048 sprintf(iso_mnt, "%s",1049 call_program_and_get_last_line_of_output(command));1006 tmp = call_program_and_get_last_line_of_output(command); 1007 log_it("res of it = %s", tmp); 1008 iso_mnt = tmp; 1009 paranoid_free(command); 1050 1010 } else { 1051 sprintf(iso_mnt, "/tmp/isodir");1052 sprintf(tmp, "mkdir -p %s", iso_mnt);1011 asprintf(&iso_mnt, "/tmp/isodir"); 1012 asprintf(&tmp, "mkdir -p %s", iso_mnt); 1053 1013 run_program_and_log_output(tmp, 5); 1054 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1014 paranoid_free(tmp); 1015 1016 asprintf(&tmp, "mount %s %s", g_isodir_device, iso_mnt); 1055 1017 if (run_program_and_log_output(tmp, 3)) { 1056 1018 log_msg(1, … … 1058 1020 bkpinfo->backup_media_type = cdr; 1059 1021 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1060 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1022 paranoid_free(bkpinfo->isodir); 1023 paranoid_free(iso_mnt); 1024 paranoid_free(iso_path); 1025 asprintf(&iso_mnt, ""); 1026 asprintf(&iso_path, ""); 1027 1061 1028 if (mount_cdrom(bkpinfo)) { 1062 1029 fatal_error … … 1067 1034 } 1068 1035 } 1036 paranoid_free(tmp); 1069 1037 } 1070 1038 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */ 1071 1039 if (bkpinfo->backup_media_type == iso) { 1072 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1073 } 1040 paranoid_free(bkpinfo->isodir); 1041 asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1042 } 1043 paranoid_free(iso_mnt); 1044 paranoid_free(iso_path); 1074 1045 } 1075 1046 } … … 1080 1051 log_msg(2, 1081 1052 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1082 interactively_obtain_media_parameters_from_user(bkpinfo, 1083 FALSE); 1053 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1084 1054 media_specified_by_user = bkpinfo->backup_media_type; 1085 1055 get_cfg_file_from_archive(bkpinfo); … … 1093 1063 } 1094 1064 g_backup_media_type = bkpinfo->backup_media_type; 1095 paranoid_free(value);1096 paranoid_free(tmp);1097 paranoid_free(command);1098 paranoid_free(iso_mnt);1099 paranoid_free(iso_path);1100 paranoid_free(old_isodir);1101 1065 return (0); 1102 1103 } 1104 1066 } 1105 1067 /************************************************************************** 1106 1068 *END_READ_CFG_FILE_INTO_BKPINFO * 1107 1069 **************************************************************************/ 1108 1109 1110 1070 1111 1071 … … 1125 1085 struct s_node *filelist; 1126 1086 1127 /** add mallocs**/ 1128 char *command; 1129 char *tmp; 1087 char *command = NULL; 1088 char *tmp = NULL; 1130 1089 int res = 0; 1090 size_t n = 0; 1131 1091 pid_t pid; 1132 1092 1133 1093 assert(bkpinfo != NULL); 1134 malloc_string(command);1135 1094 malloc_string(tmp); 1136 1095 … … 1150 1109 unlink("/tmp/i-want-my-lvm"); 1151 1110 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1152 sprintf(command,1111 asprintf(&command, 1153 1112 "tar -zxf %s %s %s %s %s %s", 1154 1113 bkpinfo->media_device, … … 1159 1118 log_msg(1, "tarcommand = %s", command); 1160 1119 run_program_and_log_output(command, 1); 1120 paranoid_free(command); 1161 1121 } else { 1162 1122 log_msg(2, … … 1166 1126 log_msg(2, "Back from iotcn"); 1167 1127 run_program_and_log_output("mount", 1); 1168 sprintf(command,1128 asprintf(&command, 1169 1129 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1170 1130 MNT_CDROM, … … 1176 1136 log_msg(1, "tarcommand = %s", command); 1177 1137 run_program_and_log_output(command, 1); 1178 // popup_and_OK("Press ENTER to continue"); 1138 paranoid_free(command); 1139 1179 1140 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1180 1141 fatal_error … … 1186 1147 } 1187 1148 } 1188 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,1149 asprintf(&command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1189 1150 g_mondo_cfg_file); 1190 1151 run_program_and_log_output(command, FALSE); 1191 1192 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1152 paranoid_free(command); 1153 1154 asprintf(&command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1193 1155 BIGGIELIST_TXT_STUB, g_biggielist_txt); 1194 1156 log_msg(1, "command = %s", command); 1195 1157 paranoid_system(command); 1196 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1158 paranoid_free(command); 1159 1160 asprintf(&command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1197 1161 FILELIST_FULL_STUB, g_filelist_full); 1198 1162 log_msg(1, "command = %s", command); 1199 1163 paranoid_system(command); 1164 paranoid_free(command); 1200 1165 } 1201 1166 1202 1167 if (am_I_in_disaster_recovery_mode() 1203 1168 && 1204 ask_me_yes_or_no(_("Do you want to retrieve the mountlist as well?"))) 1169 ask_me_yes_or_no(_ 1170 ("Do you want to retrieve the mountlist as well?"))) 1205 1171 { 1206 // sprintf(command, "cp -f tmp/mountlist.txt /tmp"); 1207 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1172 asprintf(&command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1208 1173 bkpinfo->tmpdir); 1209 1174 paranoid_system(command); 1175 paranoid_free(command); 1210 1176 } 1211 1177 1212 1178 chdir(tmp); 1179 paranoid_free(tmp); 1213 1180 1214 1181 if (!does_file_exist(g_biggielist_txt)) { … … 1230 1197 log_to_screen(("Pre-processing filelist")); 1231 1198 if (!does_file_exist(g_biggielist_txt)) { 1232 sprintf(command, "> %s", g_biggielist_txt);1199 asprintf(&command, "> %s", g_biggielist_txt); 1233 1200 paranoid_system(command); 1234 } 1235 sprintf(command, "grep -x \"/dev/.*\" %s > %s", 1201 paranoid_free(command); 1202 } 1203 asprintf(&command, "grep -x \"/dev/.*\" %s > %s", 1236 1204 g_biggielist_txt, g_filelist_imagedevs); 1237 1205 paranoid_system(command); 1206 paranoid_free(command); 1238 1207 exit(0); 1239 1208 break; … … 1254 1223 if (g_text_mode) { 1255 1224 printf(_("Restore which directory? --> ")); 1256 fgets(tmp, sizeof(tmp), stdin);1225 getline(&tmp, &n, stdin); 1257 1226 toggle_path_selection(filelist, tmp, TRUE); 1258 1227 if (strlen(tmp) == 0) { … … 1261 1230 res = 0; 1262 1231 } 1232 paranoid_free(tmp); 1263 1233 } else { 1264 1234 res = edit_filelist(filelist); … … 1282 1252 TRUE); 1283 1253 } 1284 1285 paranoid_free(command);1286 paranoid_free(tmp);1287 1254 return (filelist); 1288 1255 } 1289 1290 1256 /************************************************************************** 1291 1257 *END_ PROCESS_FILELIST_AND_BIGGIELIST * 1292 1258 **************************************************************************/ 1293 1294 1295 1259 1296 1260 … … 1304 1268 int backup_crucial_file(char *path_root, char *filename) 1305 1269 { 1306 char *tmp; 1307 char *command; 1308 int res; 1309 1310 malloc_string(tmp); 1311 malloc_string(command); 1270 char *command = NULL; 1271 int res = 0; 1272 1312 1273 assert(path_root != NULL); 1313 1274 assert_string_is_neither_NULL_nor_zerolength(filename); 1314 1275 1315 sprintf(tmp, "%s/%s", path_root, filename); 1316 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1317 1276 asprintf(&command, "cp -f %s/%s %s/%s.pristine", path_root, filename,path_root, filename); 1318 1277 res = run_program_and_log_output(command, 5); 1319 paranoid_free(tmp);1320 1278 paranoid_free(command); 1321 1279 return (res); … … 1334 1292 int retval = 0; 1335 1293 1336 /** malloc *******/ 1337 char *device; 1338 char *tmp; 1339 char *name; 1340 1341 malloc_string(device); 1342 malloc_string(tmp); 1343 malloc_string(name); 1294 char *device = NULL; 1295 char *tmp = NULL; 1296 char *name = NULL; 1297 1344 1298 backup_crucial_file(MNT_RESTORING, "/etc/fstab"); 1345 1299 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf"); … … 1348 1302 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1349 1303 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1350 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);1304 asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1351 1305 log_msg(2, tmp); 1352 system("sync"); 1306 paranoid_free(tmp); 1307 1308 sync(); 1353 1309 if (!strcmp(name, "LILO")) { 1354 1310 res = run_lilo(offer_to_hack_scripts); … … 1371 1327 #ifdef __FreeBSD__ 1372 1328 else if (!strcmp(name, "BOOT0")) { 1373 sprintf(tmp, "boot0cfg -B %s", device);1329 asprintf(&tmp, "boot0cfg -B %s", device); 1374 1330 res = run_program_and_log_output(tmp, FALSE); 1375 } else { 1376 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1331 paranoid_free(tmp); 1332 } else { 1333 asprintf(&tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1377 1334 if (!system(tmp)) { 1378 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1335 paranoid_free(tmp); 1336 asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1379 1337 res = run_program_and_log_output(tmp, 3); 1380 1338 } else { … … 1382 1340 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1383 1341 } 1342 paranoid_free(tmp); 1384 1343 } 1385 1344 #else 1386 1345 else { 1387 1346 log_to_screen 1388 (_("Unable to determine type of boot loader. Defaulting to LILO.")); 1347 (_ 1348 ("Unable to determine type of boot loader. Defaulting to LILO.")); 1389 1349 res = run_lilo(offer_to_hack_scripts); 1390 1350 } 1391 1351 #endif 1352 paranoid_free(device); 1353 paranoid_free(name); 1354 1392 1355 retval += res; 1393 1356 if (res) { … … 1396 1359 log_to_screen(_("Your boot loader ran OK")); 1397 1360 } 1398 paranoid_free(device);1399 paranoid_free(tmp);1400 paranoid_free(name);1401 1361 return (retval); 1402 1362 } 1403 1404 1363 /************************************************************************** 1405 1364 *END_ RUN_BOOT_LOADER * … … 1407 1366 1408 1367 1409 1410 1368 /** 1411 1369 * Attempt to find the user's editor. 1412 1370 * @return The editor found ("vi" if none could be found). 1413 * @note The returned string points to static storage that will be overwritten with each call.1371 * @note The returned string points to malloced storage that needs to be freed by caller 1414 1372 */ 1415 1373 char *find_my_editor(void) 1416 1374 { 1417 static char output[MAX_STR_LEN]; 1375 char *output = NULL; 1376 1377 /* BERLIOS: This should use $EDITOR + conf file rather first */ 1418 1378 if (find_home_of_exe("pico")) { 1419 strcpy(output, "pico");1379 asprintf(&output, "pico"); 1420 1380 } else if (find_home_of_exe("nano")) { 1421 strcpy(output, "nano");1381 asprintf(&output, "nano"); 1422 1382 } else if (find_home_of_exe("e3em")) { 1423 strcpy(output, "e3em");1383 asprintf(&output, "e3em"); 1424 1384 } else if (find_home_of_exe("e3vi")) { 1425 strcpy(output, "e3vi");1426 } else { 1427 strcpy(output, "vi");1385 asprintf(&output, "e3vi"); 1386 } else { 1387 asprintf(&output, "vi"); 1428 1388 } 1429 1389 if (!find_home_of_exe(output)) { … … 1442 1402 int run_grub(bool offer_to_run_stabgrub, char *bd) 1443 1403 { 1444 /** malloc **/ 1445 char *command; 1446 char *boot_device; 1447 char *rootdev; 1448 char *rootdrive; 1449 char *conffile; 1450 char *tmp; 1451 char *editor; 1452 1453 int res; 1454 int done; 1455 1456 malloc_string(command); 1457 malloc_string(boot_device); 1458 malloc_string(tmp); 1459 malloc_string(editor); 1460 malloc_string(rootdev); 1461 malloc_string(rootdrive); 1462 malloc_string(conffile); 1404 char *command = NULL; 1405 char *tmp = NULL; 1406 char *editor = NULL; 1407 1408 int res = 0; 1409 int done = 0; 1410 1463 1411 assert_string_is_neither_NULL_nor_zerolength(bd); 1464 strcpy(editor, "vi"); // find_my_editor() ); 1465 strcpy(boot_device, bd); 1466 1467 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1468 log_msg(1, "Yay! grub-MR found..."); 1469 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1470 log_msg(1, "command = %s", command); 1471 } else { 1472 sprintf(command, "chroot " MNT_RESTORING " grub-install %s", 1473 boot_device); 1474 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1475 } 1412 1476 1413 if (offer_to_run_stabgrub 1477 1414 && ask_me_yes_or_no(_("Did you change the mountlist?"))) … … 1480 1417 mvaddstr_and_log_it(g_currentY, 1481 1418 0, 1482 _("Modifying fstab and grub.conf, and running GRUB... ")); 1419 _ 1420 ("Modifying fstab and grub.conf, and running GRUB... ")); 1483 1421 for (done = FALSE; !done;) { 1484 1422 popup_and_get_string(_("Boot device"), 1485 _("Please confirm/enter the boot device. If in doubt, try /dev/hda"), 1486 boot_device, MAX_STR_LEN / 4); 1487 sprintf(command, "stabgrub-me %s", boot_device); 1423 _("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd); 1424 asprintf(&command, "stabgrub-me %s", bd); 1488 1425 res = run_program_and_log_output(command, 1); 1426 paranoid_free(command); 1427 1489 1428 if (res) { 1490 1429 popup_and_OK 1491 (_("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.")); 1430 (_ 1431 ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.")); 1492 1432 newtSuspend(); 1493 1433 system("chroot " MNT_RESTORING); … … 1501 1441 newtSuspend(); 1502 1442 } 1503 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1443 editor = find_my_editor(); 1444 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1504 1445 paranoid_system(tmp); 1505 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1446 paranoid_free(tmp); 1447 1448 asprintf(&tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1449 paranoid_free(editor); 1450 1506 1451 paranoid_system(tmp); 1452 paranoid_free(tmp); 1453 1507 1454 if (!g_text_mode) { 1508 1455 newtResume(); 1509 1456 } 1510 1457 } 1511 } else 1458 } else { 1512 1459 /* nuke mode */ 1513 { 1460 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1461 log_msg(1, "Yay! grub-MR found..."); 1462 asprintf(&command, "grub-MR %s /tmp/mountlist.txt", bd); 1463 log_msg(1, "command = %s", command); 1464 } else { 1465 asprintf(&command, "chroot " MNT_RESTORING " grub-install %s", bd); 1466 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1467 } 1514 1468 mvaddstr_and_log_it(g_currentY, 1515 1469 0, 1516 _("Running GRUB... ")); 1470 _ 1471 ("Running GRUB... ")); 1517 1472 iamhere(command); 1518 1473 res = run_program_and_log_output(command, 1); 1474 paranoid_free(command); 1475 1519 1476 if (res) { 1520 1477 popup_and_OK 1521 (_("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.")); 1478 (_ 1479 ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.")); 1522 1480 newtSuspend(); 1523 1481 system("chroot " MNT_RESTORING); … … 1529 1487 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1530 1488 log_to_screen 1531 (_("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.")); 1489 (_ 1490 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.")); 1532 1491 log_msg(1, "Type:-"); 1533 1492 log_msg(1, " mount-me"); … … 1542 1501 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1543 1502 } 1544 paranoid_free(rootdev);1545 paranoid_free(rootdrive);1546 paranoid_free(conffile);1547 paranoid_free(command);1548 paranoid_free(boot_device);1549 paranoid_free(tmp);1550 paranoid_free(editor);1551 1552 1503 return (res); 1553 1504 } 1554 1555 1505 /************************************************************************** 1556 1506 *END_RUN_GRUB * … … 1565 1515 int run_elilo(bool offer_to_run_stabelilo) 1566 1516 { 1567 /** malloc **/ 1568 char *command; 1569 char *tmp; 1570 char *editor; 1571 1572 int res; 1573 int done; 1574 1575 malloc_string(command); 1576 malloc_string(tmp); 1577 malloc_string(editor); 1578 strcpy(editor, find_my_editor()); 1517 char *command = NULL; 1518 char *tmp = NULL; 1519 char *editor = NULL; 1520 1521 int res = 0; 1522 int done = 0; 1523 1579 1524 if (offer_to_run_stabelilo 1580 1525 && ask_me_yes_or_no(_("Did you change the mountlist?"))) … … 1584 1529 mvaddstr_and_log_it(g_currentY, 1585 1530 0, 1586 _("Modifying fstab and elilo.conf... ")); 1587 sprintf(command, "stabelilo-me"); 1531 _ 1532 ("Modifying fstab and elilo.conf... ")); 1533 asprintf(&command, "stabelilo-me"); 1588 1534 res = run_program_and_log_output(command, 3); 1535 paranoid_free(command); 1536 1589 1537 if (res) { 1590 1538 popup_and_OK 1591 (_("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.")); 1539 (_ 1540 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.")); 1592 1541 for (done = FALSE; !done;) { 1593 1542 if (!g_text_mode) { 1594 1543 newtSuspend(); 1595 1544 } 1596 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1545 editor = find_my_editor(); 1546 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1597 1547 paranoid_system(tmp); 1598 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", 1599 editor); 1548 paranoid_free(tmp); 1549 1550 asprintf(&tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor); 1551 paranoid_free(editor); 1552 1600 1553 paranoid_system(tmp); 1554 paranoid_free(tmp); 1555 1601 1556 if (!g_text_mode) { 1602 1557 newtResume(); … … 1616 1571 res = TRUE; 1617 1572 } 1618 paranoid_free(command);1619 paranoid_free(tmp);1620 paranoid_free(editor);1621 1573 return (res); 1622 1574 } 1623 1624 1575 /************************************************************************** 1625 1576 *END_RUN_ELILO * … … 1635 1586 { 1636 1587 /** malloc **/ 1637 char *command ;1638 char *tmp ;1639 char *editor ;1640 1641 int res ;1642 int done ;1588 char *command = NULL; 1589 char *tmp = NULL; 1590 char *editor = NULL; 1591 1592 int res = 0; 1593 int done = 0; 1643 1594 bool run_lilo_M = FALSE; 1644 malloc_string(command);1645 malloc_string(tmp);1646 malloc_string(editor);1647 1595 1648 1596 if (!run_program_and_log_output … … 1651 1599 } 1652 1600 1653 strcpy(editor, find_my_editor());1654 1601 if (offer_to_run_stablilo 1655 && ask_me_yes_or_no(_("Did you change the mountlist?"))) 1656 1602 && ask_me_yes_or_no(_("Did you change the mountlist?"))) { 1657 1603 /* interactive mode */ 1658 {1659 1604 mvaddstr_and_log_it(g_currentY, 1660 1605 0, 1661 _("Modifying fstab and lilo.conf, and running LILO... ")); 1662 sprintf(command, "stablilo-me"); 1606 _ 1607 ("Modifying fstab and lilo.conf, and running LILO... ")); 1608 asprintf(&command, "stablilo-me"); 1663 1609 res = run_program_and_log_output(command, 3); 1610 paranoid_free(command); 1611 1664 1612 if (res) { 1665 1613 popup_and_OK 1666 (_("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.")); 1614 (_ 1615 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.")); 1667 1616 for (done = FALSE; !done;) { 1668 1617 if (!g_text_mode) { 1669 1618 newtSuspend(); 1670 1619 } 1671 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1620 editor = find_my_editor(); 1621 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1672 1622 paranoid_system(tmp); 1673 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1623 paranoid_free(tmp); 1624 1625 asprintf(&tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1626 paranoid_free(editor); 1627 1674 1628 paranoid_system(tmp); 1629 paranoid_free(tmp); 1630 1675 1631 if (!g_text_mode) { 1676 1632 newtResume(); … … 1699 1655 log_to_screen(_("lilo.conf and fstab were modified OK")); 1700 1656 } 1701 } else 1657 } else { 1702 1658 /* nuke mode */ 1703 {1704 1659 mvaddstr_and_log_it(g_currentY, 1705 1660 0, 1706 _("Running LILO... ")); 1661 _ 1662 ("Running LILO... ")); 1707 1663 res = 1708 1664 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", … … 1716 1672 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1717 1673 log_to_screen 1718 (_("Failed to re-jig fstab and/or lilo. Edit/run manually, please.")); 1674 (_ 1675 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.")); 1719 1676 } else { 1720 1677 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); … … 1727 1684 " lilo -M /dev/sda", 3); 1728 1685 } 1729 paranoid_free(command);1730 paranoid_free(tmp);1731 paranoid_free(editor);1732 1686 return (res); 1733 1687 } … … 1746 1700 int run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1747 1701 { 1748 /** malloc **/ 1749 char *command; 1750 char *boot_device; 1751 char *tmp; 1752 char *editor; 1753 int res; 1754 int done; 1755 1756 malloc_string(command); 1757 malloc_string(boot_device); 1758 malloc_string(tmp); 1759 malloc_string(editor); 1702 char *command = NULL; 1703 char *tmp = NULL; 1704 char *editor = NULL; 1705 int res = 0; 1706 int done = 0; 1707 1760 1708 assert_string_is_neither_NULL_nor_zerolength(bd); 1761 1709 1762 strcpy(editor, find_my_editor());1763 strcpy(boot_device, bd);1764 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);1765 log_msg(2, "run_raw_mbr() --- command='%s'", command);1766 1767 1710 if (offer_to_hack_scripts 1768 && ask_me_yes_or_no(_("Did you change the mountlist?"))) 1711 && ask_me_yes_or_no(_("Did you change the mountlist?"))) { 1769 1712 /* interactive mode */ 1770 {1771 1713 mvaddstr_and_log_it(g_currentY, 0, 1772 _("Modifying fstab and restoring MBR... ")); 1714 _ 1715 ("Modifying fstab and restoring MBR... ")); 1773 1716 for (done = FALSE; !done;) { 1774 1717 if (!run_program_and_log_output("which vi", FALSE)) { … … 1777 1720 newtSuspend(); 1778 1721 } 1779 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1722 editor = find_my_editor(); 1723 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1724 paranoid_free(editor); 1725 1780 1726 paranoid_system(tmp); 1727 paranoid_free(tmp); 1728 1781 1729 if (!g_text_mode) { 1782 1730 newtResume(); … … 1785 1733 } 1786 1734 popup_and_get_string(_("Boot device"), 1787 _ ("Please confirm/enter the boot device. If in doubt, try /dev/hda"),1788 boot_device, MAX_STR_LEN / 4);1789 sprintf(command, "stabraw-me %s", boot_device);1735 _ 1736 ("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd); 1737 asprintf(&command, "stabraw-me %s", bd); 1790 1738 res = run_program_and_log_output(command, 3); 1739 paranoid_free(command); 1740 1791 1741 if (res) { 1792 done = ask_me_yes_or_no(_("Modifications failed. Re-try?")); 1742 done = 1743 ask_me_yes_or_no(_("Modifications failed. Re-try?")); 1793 1744 } else { 1794 1745 done = TRUE; 1795 1746 } 1796 1747 } 1797 } else 1748 } else { 1798 1749 /* nuke mode */ 1799 {1800 1750 mvaddstr_and_log_it(g_currentY, 0, 1801 _("Restoring MBR... ")); 1751 _ 1752 ("Restoring MBR... ")); 1753 asprintf(&command, "raw-MR %s /tmp/mountlist.txt", bd); 1754 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1802 1755 res = run_program_and_log_output(command, 3); 1756 paranoid_free(command); 1803 1757 } 1804 1758 if (res) { 1805 1759 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1806 1760 log_to_screen 1807 (_("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.")); 1761 (_ 1762 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.")); 1808 1763 } else { 1809 1764 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1810 1765 } 1811 paranoid_free(command);1812 paranoid_free(boot_device);1813 paranoid_free(tmp);1814 paranoid_free(editor);1815 1766 return (res); 1816 1767 } 1817 1818 1768 /************************************************************************** 1819 1769 *END_RUN_RAW_MBR * 1820 1770 **************************************************************************/ 1821 1822 1823 1824 1771 1825 1772 … … 1858 1805 void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 1859 1806 { 1860 char *temppath;1861 1862 1807 assert(bkpinfo != NULL); 1863 1808 1864 malloc_string(g_biggielist_txt);1865 malloc_string(g_filelist_full);1866 malloc_string(g_filelist_imagedevs);1867 malloc_string(g_imagedevs_restthese);1868 malloc_string(g_mondo_cfg_file);1869 malloc_string(g_mountlist_fname);1870 1809 malloc_string(g_tmpfs_mountpt); 1871 malloc_string(g_isodir_device); 1872 malloc_string(g_isodir_format); 1873 1874 temppath = bkpinfo->tmpdir; 1875 1876 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 1877 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 1878 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 1879 // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath); 1880 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 1881 temppath); 1810 1811 asprintf(&g_biggielist_txt, "%s/%s",bkpinfo->tmpdir , BIGGIELIST_TXT_STUB); 1812 asprintf(&g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB); 1813 asprintf(&g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir); 1814 asprintf(&g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 1815 bkpinfo->tmpdir); 1882 1816 if (bkpinfo->disaster_recovery) { 1883 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 1884 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 1885 } else { 1886 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB); 1887 sprintf(g_mountlist_fname, "%s/%s", temppath, 1888 MOUNTLIST_FNAME_STUB); 1889 } 1890 } 1891 1817 asprintf(&g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 1818 asprintf(&g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 1819 } else { 1820 asprintf(&g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 1821 asprintf(&g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 1822 } 1823 } 1892 1824 /************************************************************************** 1893 1825 *END_SET_GLOBAL_FILENAME * … … 1905 1837 FILE *fin; 1906 1838 FILE *fout; 1907 /** malloc **/ 1908 char *incoming;1839 char *incoming = NULL; 1840 size_t n = 0; 1909 1841 1910 1842 assert_string_is_neither_NULL_nor_zerolength(output_file); 1911 1843 assert_string_is_neither_NULL_nor_zerolength(input_file); 1912 malloc_string(incoming);1913 1844 1914 1845 if (!(fin = fopen(input_file, "r"))) { … … 1919 1850 fatal_error("cannot open output_file"); 1920 1851 } 1921 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);1922 fgets(incoming, MAX_STR_LEN - 1, fin)) {1852 for (getline(&incoming, &n, fin); !feof(fin); 1853 getline(&incoming, &n, fin)) { 1923 1854 if (strncmp(incoming, "etc/adjtime", 11) 1924 1855 && strncmp(incoming, "etc/mtab", 8) … … 1930 1861 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 1931 1862 } 1863 paranoid_free(incoming); 1932 1864 paranoid_fclose(fout); 1933 1865 paranoid_fclose(fin); 1934 paranoid_free(incoming); 1935 } 1936 1866 } 1937 1867 /************************************************************************** 1938 1868 *END_STREAMLINE_CHANGES_FILE * … … 1947 1877 { 1948 1878 log_to_screen 1949 (_("Mondorestore is terminating in response to a signal from the OS")); 1879 (_ 1880 ("Mondorestore is terminating in response to a signal from the OS")); 1950 1881 paranoid_MR_finish(254); 1951 1882 } 1952 1953 1883 /************************************************************************** 1954 1884 *END_TERMINATE_DAEMON * … … 1962 1892 { 1963 1893 int i; 1964 /* MALLOC * */ 1965 char *tmp; 1966 1967 malloc_string(tmp); 1894 char *tmp = NULL; 1895 1968 1896 if (does_file_exist("/tmp/NOPAUSE")) { 1969 1897 return; 1970 1898 } 1971 1899 open_progress_form(_("CAUTION"), 1972 _("Be advised: I am about to ERASE your hard disk(s)!"), 1900 _ 1901 ("Be advised: I am about to ERASE your hard disk(s)!"), 1973 1902 _("You may press Ctrl+Alt+Del to abort safely."), 1974 1903 "", 20); 1975 1904 for (i = 0; i < 20; i++) { 1976 1905 g_current_progress = i; 1977 sprintf(tmp, _("You have %d seconds left to abort."), 20 - i);1906 asprintf(&tmp, _("You have %d seconds left to abort."), 20 - i); 1978 1907 update_progress_form(tmp); 1908 paranoid_free(tmp); 1979 1909 sleep(1); 1980 1910 } 1981 1911 close_progress_form(); 1982 paranoid_free(tmp); 1983 } 1984 1912 } 1985 1913 /************************************************************************** 1986 1914 *END_TWENTY_SECONDS_TIL_YIKES * … … 1988 1916 1989 1917 1990 1991 1992 1993 1918 /** 1994 1919 * Exit due to a signal (no cleanup). … … 2001 1926 pthread_exit(0); 2002 1927 } 2003 2004 1928 /************************************************************************** 2005 1929 *END_TERMINATION_IN_PROGRESS * … … 2007 1931 2008 1932 2009 2010 1933 /** 2011 1934 * Unmount all devices in @p p_external_copy_of_mountlist. … … 2017 1940 { 2018 1941 struct mountlist_itself *mountlist; 2019 int retval = 0, lino, res = 0, i; 2020 char *command; 2021 char *tmp; 2022 2023 malloc_string(command); 2024 malloc_string(tmp); 1942 int retval = 0; 1943 int lino = 0; 1944 int res = 0; 1945 int i = 0; 1946 char *command = NULL; 1947 char *tmp = NULL; 1948 char *tmp1 = NULL; 1949 2025 1950 assert(p_external_copy_of_mountlist != NULL); 2026 1951 … … 2034 1959 open_progress_form(_("Unmounting devices"), 2035 1960 _("Unmounting all devices that were mounted,"), 2036 _("in preparation for the post-restoration reboot."), 1961 _ 1962 ("in preparation for the post-restoration reboot."), 2037 1963 "", mountlist->entries); 2038 1964 chdir("/"); … … 2047 1973 } 2048 1974 2049 paranoid_system("sync");1975 sync(); 2050 1976 2051 1977 if (run_program_and_log_output … … 2067 1993 continue; 2068 1994 } 2069 sprintf(tmp, _("Unmounting device %s "), mountlist->el[lino].device); 1995 asprintf(&tmp, _("Unmounting device %s "), 1996 mountlist->el[lino].device); 2070 1997 2071 1998 update_progress_form(tmp); 1999 2072 2000 if (is_this_device_mounted(mountlist->el[lino].device)) { 2073 2001 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { 2074 sprintf(command, "swapoff %s", mountlist->el[lino].device);2002 asprintf(&command, "swapoff %s", mountlist->el[lino].device); 2075 2003 } else { 2076 2004 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) { 2077 sprintf(command, "umount %s/", MNT_RESTORING);2005 asprintf(&command, "umount %s/", MNT_RESTORING); 2078 2006 log_msg(3, 2079 2007 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2080 2008 } else { 2081 sprintf(command, "umount " MNT_RESTORING "%s",2009 asprintf(&command, "umount " MNT_RESTORING "%s", 2082 2010 mountlist->el[lino].mountpoint); 2083 2011 } … … 2085 2013 log_msg(10, "The 'umount' command is '%s'", command); 2086 2014 res = run_program_and_log_output(command, 3); 2015 paranoid_free(command); 2087 2016 } else { 2088 strcat(tmp, _("...not mounted anyway :-) OK")); 2017 asprintf(&tmp1, "%s%s", tmp, _("...not mounted anyway :-) OK")); 2018 paranoid_free(tmp); 2019 tmp = tmp1; 2089 2020 res = 0; 2090 2021 } 2091 2022 g_current_progress++; 2092 2023 if (res) { 2093 strcat(tmp, _("...Failed")); 2024 asprintf(&tmp1, "%s%s", tmp, _("...Failed")); 2025 paranoid_free(tmp); 2026 tmp = tmp1; 2094 2027 retval++; 2095 2028 log_to_screen(tmp); … … 2097 2030 log_msg(2, tmp); 2098 2031 } 2032 paranoid_free(tmp); 2099 2033 } 2100 2034 close_progress_form(); … … 2110 2044 } 2111 2045 free(mountlist); 2112 paranoid_free(command);2113 paranoid_free(tmp);2114 2046 return (retval); 2115 2047 } 2116 2117 2048 /************************************************************************** 2118 2049 *END_UNMOUNT_ALL_DEVICES * 2119 2050 **************************************************************************/ 2120 2121 2051 2122 2052 … … 2129 2059 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 2130 2060 { 2131 char *command ;2061 char *command = NULL; 2132 2062 int res = 0; 2133 // B CO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.02063 // BERLIOS: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2134 2064 long tape_block_size = 32768; 2135 2065 2136 malloc_string(command);2137 2138 2066 // tar -zxvf- 2139 sprintf(command,2067 asprintf(&command, 2140 2068 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2141 2069 dev, … … 2146 2074 log_msg(2, "command = '%s'", command); 2147 2075 res = run_program_and_log_output(command, -1); 2076 paranoid_free(command); 2077 2148 2078 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) { 2149 2079 res = 0; 2150 2080 } 2151 paranoid_free(command);2152 2081 return (res); 2153 2082 } 2154 2155 2083 2156 2084 … … 2166 2094 { 2167 2095 int retval = 0; 2168 2169 /** malloc *****/ 2170 char *device; 2171 char *command; 2172 char *cfg_file; 2173 char *mounted_cfgf_path; 2174 char *tmp; 2175 char *sav; 2176 char *mountpt; 2177 char *ramdisk_fname; 2178 char *mountlist_file; 2179 int res; 2096 char *device = NULL; 2097 char *command = NULL; 2098 char *cfg_file = NULL; 2099 char *mounted_cfgf_path = NULL; 2100 char *tmp = NULL; 2101 char *tmp1 = NULL; 2102 char *sav = NULL; 2103 char *mountpt = NULL; 2104 char *ramdisk_fname = NULL; 2105 char *mountlist_file = NULL; 2106 int res = 0; 2180 2107 2181 2108 bool try_plan_B; 2182 2109 2183 2110 assert(bkpinfo != NULL); 2184 malloc_string(cfg_file);2185 malloc_string(mounted_cfgf_path);2186 malloc_string(mountpt);2187 malloc_string(ramdisk_fname);2188 malloc_string(mountlist_file);2189 malloc_string(device);2190 malloc_string(command);2191 malloc_string(tmp);2192 2111 log_msg(2, "gcffa --- starting"); 2193 2112 log_to_screen(_("I'm thinking...")); 2194 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2195 device[0] = '\0'; 2113 asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2196 2114 chdir(bkpinfo->tmpdir); 2197 strcpy(cfg_file, MONDO_CFG_FILE_STUB); 2198 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent 2115 // MONDO_CFG_FILE_STUB is missing the '/' at the start, FYI, by intent 2116 unlink(MONDO_CFG_FILE_STUB); 2117 2199 2118 unlink(FILELIST_FULL_STUB); 2200 2119 unlink(BIGGIELIST_TXT_STUB); 2201 2120 unlink("tmp/i-want-my-lvm"); 2202 sprintf(command, "mkdir -p %s", mountpt);2121 asprintf(&command, "mkdir -p %s", mountpt); 2203 2122 run_program_and_log_output(command, FALSE); 2204 2205 // unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely? 2206 2207 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2208 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, 2123 paranoid_free(command); 2124 2125 asprintf(&cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2126 asprintf(&mountlist_file, "%s/%s", bkpinfo->tmpdir, 2209 2127 MOUNTLIST_FNAME_STUB); 2210 // make_hole_for_file( cfg_file );2211 // make_hole_for_file( mountlist_file);2212 2128 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file); 2213 2129 2214 2130 /* Floppy? */ 2215 sprintf(tmp, "mkdir -p %s", mountpt);2131 asprintf(&tmp, "mkdir -p %s", mountpt); 2216 2132 run_program_and_log_output(tmp, FALSE); 2217 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2133 paranoid_free(tmp); 2134 2135 asprintf(&tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2218 2136 run_program_and_log_output(tmp, FALSE); 2219 2220 sprintf(command, "mount /dev/fd0u1722 %s", mountpt); 2221 sprintf(tmp, 2137 paranoid_free(tmp); 2138 2139 asprintf(&command, "mount /dev/fd0u1722 %s", mountpt); 2140 asprintf(&tmp, 2222 2141 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", 2223 2142 command); 2224 2143 log_msg(1, "tmp = '%s'", tmp); 2225 2144 system(tmp); 2145 paranoid_free(tmp); 2146 2226 2147 res = run_program_and_log_output(command, FALSE); 2148 paranoid_free(command); 2149 2227 2150 if (res) { 2228 sprintf(command, "mount /dev/fd0H1440 %s", mountpt);2151 asprintf(&command, "mount /dev/fd0H1440 %s", mountpt); 2229 2152 res = run_program_and_log_output(command, FALSE); 2153 paranoid_free(command); 2230 2154 } 2231 2155 if (res) { … … 2237 2161 // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK. 2238 2162 log_msg(2, "Processing floppy (plan A?)"); 2239 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);2163 asprintf(&ramdisk_fname, "%s/mindi.rdz", mountpt); 2240 2164 if (!does_file_exist(ramdisk_fname)) { 2241 sprintf(ramdisk_fname, "%s/initrd.img", mountpt); 2165 paranoid_free(ramdisk_fname); 2166 asprintf(&ramdisk_fname, "%s/initrd.img", mountpt); 2242 2167 } 2243 2168 if (!does_file_exist(ramdisk_fname)) { … … 2250 2175 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled."); 2251 2176 } 2252 sprintf(command, "umount %s", mountpt);2177 asprintf(&command, "umount %s", mountpt); 2253 2178 run_program_and_log_output(command, 5); 2179 paranoid_free(command); 2180 2254 2181 unlink(ramdisk_fname); 2182 paranoid_free(ramdisk_fname); 2255 2183 } 2256 2184 if (!does_file_exist(cfg_file)) { … … 2277 2205 run_program_and_log_output("mkdir -p tmp", FALSE); 2278 2206 2279 if (strlen(bkpinfo->media_device) == 0) { 2280 paranoid_alloc(bkpinfo->media_device, "/dev/st0"); 2281 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device); 2282 } 2283 asprintf(&sav,bkpinfo->media_device); 2207 if (bkpinfo->media_device == NULL) { 2208 asprintf(&bkpinfo->media_device, "/dev/st0"); 2209 log_msg(2, "media_device is blank; assuming %s", 2210 bkpinfo->media_device); 2211 } 2212 asprintf(&sav, bkpinfo->media_device); 2284 2213 if (extract_cfg_file_and_mountlist_from_tape_dev 2285 2214 (bkpinfo->media_device)) { … … 2303 2232 2304 2233 if (!does_file_exist("tmp/mondo-restore.cfg")) { 2305 log_to_screen(_("Cannot find config info on tape/CD/floppy")); 2234 log_to_screen(_ 2235 ("Cannot find config info on tape/CD/floppy")); 2306 2236 return (1); 2307 2237 } … … 2309 2239 log_msg(2, 2310 2240 "gcffa --- looking at mounted CD for mindi-boot.2880.img"); 2311 sprintf(command, 2241 /* BERLIOS : Useless ? 2242 asprintf(&command, 2312 2243 "mount " MNT_CDROM 2313 2244 "/images/mindi-boot.2880.img -o loop %s", mountpt); 2314 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2245 */ 2246 asprintf(&mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2315 2247 if (!does_file_exist(mounted_cfgf_path)) { 2316 2248 log_msg(2, 2317 2249 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz"); 2318 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2250 asprintf(&command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2319 2251 run_program_and_log_output(command, TRUE); 2252 paranoid_free(command); 2253 2320 2254 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2321 2255 fatal_error … … 2323 2257 } 2324 2258 } 2325 } 2326 } 2259 paranoid_free(mounted_cfgf_path); 2260 } 2261 } 2262 paranoid_free(mountpt); 2263 2327 2264 if (does_file_exist(MONDO_CFG_FILE_STUB)) { 2328 2265 log_msg(1, "gcffa --- great! We've got the config file"); 2329 sprintf(tmp, "%s/%s", 2330 call_program_and_get_last_line_of_output("pwd"), 2331 MONDO_CFG_FILE_STUB); 2332 sprintf(command, "cp -f %s %s", tmp, cfg_file); 2266 tmp1 = call_program_and_get_last_line_of_output("pwd"); 2267 asprintf(&tmp, "%s/%s", tmp1,MONDO_CFG_FILE_STUB); 2268 asprintf(&command, "cp -f %s %s", tmp, cfg_file); 2333 2269 iamhere(command); 2270 2334 2271 if (strcmp(tmp, cfg_file) 2335 2272 && run_program_and_log_output(command, 1)) { … … 2340 2277 log_msg(1, "... and I moved it successfully to %s", cfg_file); 2341 2278 } 2342 sprintf(command, "cp -f %s/%s %s", 2343 call_program_and_get_last_line_of_output("pwd"), 2279 paranoid_free(command); 2280 2281 asprintf(&command, "cp -f %s/%s %s",tmp1, 2344 2282 MOUNTLIST_FNAME_STUB, mountlist_file); 2283 paranoid_free(tmp1); 2284 2345 2285 iamhere(command); 2346 2286 if (strcmp(tmp, cfg_file) … … 2349 2289 } else { 2350 2290 log_msg(1, "Got mountlist too"); 2351 sprintf(command, "cp -f %s %s", mountlist_file, 2291 paranoid_free(command); 2292 asprintf(&command, "cp -f %s %s", mountlist_file, 2352 2293 g_mountlist_fname); 2353 2294 if (run_program_and_log_output(command, 1)) { … … 2355 2296 } else { 2356 2297 log_msg(1, "Copied mountlist to /tmp as well OK"); 2357 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2298 paranoid_free(command); 2299 asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/"); 2358 2300 run_program_and_log_output(command, 1); 2359 /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname); 2360 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm")) 2361 { 2362 log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME."); 2363 } 2364 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm")) 2365 { 2366 log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool."); 2367 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :) 2368 stop_raid_device("/dev/md0"); 2369 stop_raid_device("/dev/md1"); 2370 stop_raid_device("/dev/md2"); 2371 unlink("/tmp/i-want-my-lvm"); 2372 } 2373 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm")) 2374 { 2375 log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME."); 2376 } 2377 */ 2378 } 2379 } 2301 } 2302 } 2303 paranoid_free(command); 2304 paranoid_free(tmp); 2380 2305 } 2381 2306 run_program_and_log_output("umount " MNT_CDROM, FALSE); … … 2384 2309 log_msg(1, "%s not found", cfg_file); 2385 2310 log_to_screen 2386 (_("Oh dear. Unable to recover configuration file from boot disk")); 2311 (_ 2312 ("Oh dear. Unable to recover configuration file from boot disk")); 2387 2313 return (1); 2388 2314 } … … 2394 2320 /* start SAH */ 2395 2321 else { 2396 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,2322 asprintf(&command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, 2397 2323 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2398 2324 run_program_and_log_output(command, FALSE); 2399 } 2400 /*--commented out by SAH 2401 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); 2402 run_program_and_log_output( command, FALSE ); 2403 sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB ); 2404 run_program_and_log_output( command, FALSE ); 2405 */ 2325 paranoid_free(command); 2326 } 2406 2327 /* end SAH */ 2407 2328 2408 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2329 asprintf(&command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2330 paranoid_free(cfg_file); 2331 2409 2332 run_program_and_log_output(command, FALSE); 2410 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2333 paranoid_free(command); 2334 2335 asprintf(&command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2336 paranoid_free(mountlist_file); 2337 2411 2338 run_program_and_log_output(command, FALSE); 2412 sprintf(command, "cp -f etc/raidtab /etc/"); 2339 paranoid_free(command); 2340 2341 asprintf(&command, "cp -f etc/raidtab /etc/"); 2413 2342 run_program_and_log_output(command, FALSE); 2414 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2343 paranoid_free(command); 2344 2345 asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/"); 2415 2346 run_program_and_log_output(command, FALSE); 2347 paranoid_free(command); 2348 2416 2349 g_backup_media_type = bkpinfo->backup_media_type; 2417 paranoid_free(device);2418 paranoid_free(command);2419 paranoid_free(tmp);2420 paranoid_free(cfg_file);2421 paranoid_free(mounted_cfgf_path);2422 paranoid_free(mountpt);2423 paranoid_free(ramdisk_fname);2424 paranoid_free(mountlist_file);2425 2350 return (retval); 2426 2351 } 2427 2428 2352 /************************************************************************** 2429 2353 *END_GET_CFG_FILE_FROM_ARCHIVE * 2430 2354 **************************************************************************/ 2431 2432 2355 /* @} - end restoreUtilityGroup */ 2433 2434 2435 /***************************************************************************2436 * F@ *2437 * () -- Hugo Rabson *2438 * *2439 * Purpose: *2440 * *2441 * Called by: *2442 * Params: - - *2443 * Returns: 0=success; nonzero=failure *2444 ***************************************************************************/2445 2446 2356 2447 2357 … … 2449 2359 int wait_for_percentage) 2450 2360 { 2451 struct raidlist_itself *raidlist; 2452 int unfinished_mdstat_devices = 9999, i; 2453 char *screen_message; 2454 2455 malloc_string(screen_message); 2361 struct raidlist_itself *raidlist = NULL; 2362 int unfinished_mdstat_devices = 9999, i = 0; 2363 char *screen_message = NULL; 2364 2456 2365 raidlist = malloc(sizeof(struct raidlist_itself)); 2457 2366 … … 2461 2370 if (parse_mdstat(raidlist, "/dev/")) { 2462 2371 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE); 2463 log_msg(1, "Sorry, cannot read %s", MDSTAT_FILE);2372 log_msg(1, "Sorry, cannot read %s", MDSTAT_FILE); 2464 2373 return; 2465 2374 } 2466 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) { 2375 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; 2376 i++) { 2467 2377 if (raidlist->el[i].progress < wait_for_percentage) { 2468 2378 unfinished_mdstat_devices++; 2469 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i); 2470 sprintf(screen_message, "Sync'ing %s", 2379 log_msg(1, "Sync'ing %s (i=%d)", 2380 raidlist->el[i].raid_device, i); 2381 asprintf(&screen_message, "Sync'ing %s", 2471 2382 raidlist->el[i].raid_device); 2472 2383 open_evalcall_form(screen_message); 2384 paranoid_free(screen_message); 2385 2473 2386 if (raidlist->el[i].progress == -1) // delayed while another partition inits 2474 2387 { … … 2476 2389 } 2477 2390 while (raidlist->el[i].progress < wait_for_percentage) { 2478 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress); 2391 log_msg(1, "Percentage sync'ed: %d", 2392 raidlist->el[i].progress); 2479 2393 update_evalcall_form(raidlist->el[i].progress); 2480 2394 sleep(2); … … 2488 2402 } 2489 2403 } 2490 paranoid_free(screen_message);2491 2404 paranoid_free(raidlist); 2492 2405 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.h
r426 r688 1 /* mondo-rstr-tools.h1 /* 2 2 * $Id: mondo-rstr-tools.h 3 3 **/ 4 4 5 5 void free_global_filenames(); … … 8 8 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 void kill_petris(void); 10 int modify_rclocal_one_time(char *path);11 10 int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 11 int mount_device(char *, char *, char *, bool); … … 26 25 void set_signals(int on); 27 26 void setup_global_filenames(struct s_bkpinfo *bkpinfo); 28 //void setup_signals(int);29 27 void twenty_seconds_til_yikes(void); 30 28 int run_raw_mbr(bool offer_to_hack_scripts, char *bd); -
trunk/mondo/mondo/mondorestore/mondoprep.h
r687 r688 1 /*************************************************************************** 2 mondoprep.h - description 3 ------------------- 4 begin : Sat Apr 20 2002 5 copyright : (C) 2002 by Stan Benoit 6 email : troff@nakedsoul.org 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 1 /* 2 * $Id$ 3 **/ 18 4 19 5 … … 28 14 extern bool ask_me_yes_or_no(char *); 29 15 extern long get_phys_size_of_drive(char *); 30 //extern void log_to_screen (char *);31 16 extern void update_progress_form(char *); 32 17 extern void open_progress_form(char *, char *, char *, char *, long); 33 18 extern void close_progress_form(void); 34 19 extern void popup_and_OK(char *); 35 extern bool popup_and_get_string(char *, char *, char * , int);20 extern bool popup_and_get_string(char *, char *, char *); 36 21 extern long get_time(void); 37 22 extern bool is_this_device_mounted(char *); … … 41 26 extern off_t length_of_file(char *); 42 27 extern long noof_lines_that_match_wildcard(char *, char *); 43 //extern char *slice_fname (long, long, bool, char *);44 28 extern char *last_line_of_file(char *); 45 29 extern void log_file_end_to_screen(char *, char *); … … 58 42 int start_all_raid_devices(struct mountlist_itself *); 59 43 int stop_all_raid_devices(struct mountlist_itself *); 60 int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *); 44 int format_everything(struct mountlist_itself *, bool, 45 struct raidlist_itself *); 61 46 int partition_device(FILE *, const char *, int, int, const char *, 62 47 long long); -
trunk/mondo/mondo/mondorestore/mr-externs.h
r687 r688 27 27 extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 28 28 struct raidlist_itself *); 29 extern int format_everything(struct mountlist_itself *, bool, struct raidlist_itself *); 29 extern int format_everything(struct mountlist_itself *, bool, 30 struct raidlist_itself *); 30 31 extern int format_device(char *, char *, struct raidlist_itself *); 31 32 extern void finish(int); … … 59 60 extern int partition_everything(struct mountlist_itself *); 60 61 extern void popup_and_OK(char *); 61 extern bool popup_and_get_string(char *, char *, char * , int);62 extern bool popup_and_get_string(char *, char *, char *); 62 63 extern void setup_newt_stuff(void); 63 64 extern void reset_bkpinfo(struct s_bkpinfo *); -
trunk/tools/quality
r146 r688 28 28 29 29 # How many sprintf/strcat/strcpy vs asprintf are they 30 for s in asprintf sprintf strcat strcpy fgets malloc_string MAX_STR_LENgoto; do30 for s in asprintf sprintf strcat strcpy strncpy fgets malloc malloc_string MAX_STR_LEN getcwd goto; do 31 31 echo "monodrescue $s usage : " 32 for i in `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r -c -w $s | egrep -v ":0$"`; do 32 tot=0 33 for i in `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn|/\*|monitas' | xargs grep -r -c -w $s | egrep -v ":0$"`; do 33 34 echo " === $i" 35 ((tot=$tot+`echo $i | cut -d: -f2`)) 34 36 done 37 echo "total $s usage : $tot" 35 38 done 36 39
Note:
See TracChangeset
for help on using the changeset viewer.