Changeset 688 in MondoRescue
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (18 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 &n