Changeset 171 in MondoRescue for trunk/mondo/mondo/common
- Timestamp:
- Dec 8, 2005, 5:20:29 PM (19 years ago)
- Location:
- trunk/mondo/mondo/common
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-archive.c
r168 r171 298 298 /*@ buffers ******************************************************** */ 299 299 char *command; 300 char *zipparams ;300 char *zipparams = NULL; 301 301 char *tmp, *tmp1; 302 302 … … 325 325 326 326 327 327 if (bkpinfo->compression_level > 0) { 328 328 asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home); 329 329 // -b %ld, TAPE_BLOCK_SIZE … … 333 333 asprintf(&tmp1, "%s -E %s", zipparams, tmp); 334 334 paranoid_free(zipparams) 335 335 zipparams = tmp1; 336 336 } else { 337 asprintf(&zipparams, " ");337 asprintf(&zipparams, " "); 338 338 log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp); 339 339 } 340 340 paranoid_free(tmp) 341 341 } else { 342 asprintf(&zipparams, " ");342 asprintf(&zipparams, " "); 343 343 } 344 344 … … 582 582 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 583 583 asprintf(&tape_size_sz, "%ld", bkpinfo->media_size[1]); 584 asprintf(&tape_device, "%s",bkpinfo->media_device);584 asprintf(&tape_device, bkpinfo->media_device); 585 585 } else { 586 asprintf(&tape_size_sz, " ");587 asprintf(&tape_device, " ");586 asprintf(&tape_size_sz, " "); 587 asprintf(&tape_device, " "); 588 588 } 589 589 if (bkpinfo->use_lzo) { … … 825 825 asprintf(&tmp, " NONBOOTABLE"); 826 826 } else { 827 asprintf(&tmp, " ");827 asprintf(&tmp, " "); 828 828 } 829 829 … … 2007 2007 "Please wait. This may take some time.", "", 2008 2008 estimated_total_noof_slices); 2009 paranoid_free(tmp); 2010 2009 2011 if (!(fin = fopen(biggielist_fname, "r"))) { 2010 2012 log_OS_error("Unable to openin biggielist"); … … 2078 2080 noof_biggie_files, use_partimagehack); 2079 2081 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2080 write_header_block_to_stream(0, 2081 calc_checksum_of_file 2082 (bigfile_fname), 2083 BLK_STOP_A_BIGGIE); 2082 tmp = calc_checksum_of_file(bigfile_fname); 2083 write_header_block_to_stream(0, tmp, BLK_STOP_A_BIGGIE); 2084 paranoid_free(tmp); 2084 2085 } 2085 2086 retval += res; … … 2090 2091 p = bigfile_fname; 2091 2092 } 2092 paranoid_free(tmp);2093 2093 if (res) { 2094 2094 asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname); … … 2772 2772 /** 2773 2773 * Make sure the user has a valid CD-R(W) in the CD drive. 2774 * @param cdrw_dev Set to the CD-R(W) device checked.2774 * @param cdrw_device Set to the CD-R(W) device checked. 2775 2775 * @param keep_looping If TRUE, keep pestering user until they insist 2776 2776 * or insert a correct CD; if FALSE, only check once. 2777 2777 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't). 2778 2778 */ 2779 int 2780 interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev, bool keep_looping) 2779 char *interrogate_disk_currently_in_cdrw_drive() 2781 2780 { 2782 int res = 0;2783 char *bkp;2784 2781 char *cdrecord; 2785 2786 asprintf(&bkp, "%s", cdrw_dev); 2787 if (find_cdrw_device(cdrw_dev)) { 2788 strcpy(cdrw_dev, bkp); 2789 } else { 2782 char *cdrw_device; 2783 2784 if ((cdrw_device = find_cdrw_device()) != NULL) { 2790 2785 if (!system("which cdrecord > /dev/null 2> /dev/null")) { 2791 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev );2786 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device); 2792 2787 } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) { 2793 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev );2788 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device); 2794 2789 } else { 2795 asprintf(&cdrecord, " %s", "");2796 log_msg(2, " Oh well. I guess I'll just pray then.");2790 asprintf(&cdrecord, " "); 2791 log_msg(2, "Found no cdrecord nor dvdrecord in path."); 2797 2792 } 2798 2793 if (cdrecord[0]) { 2799 if (!keep_looping) {2800 2794 retract_CD_tray_and_defeat_autorun(); 2801 res = run_program_and_log_output(cdrecord, 5); 2802 } else { 2803 while ((res = run_program_and_log_output(cdrecord, 5))) { 2804 retract_CD_tray_and_defeat_autorun(); 2805 if (ask_me_yes_or_no 2806 ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?")) 2807 { 2808 log_msg(1, "Well, he insisted..."); 2809 break; 2810 } 2811 } 2812 } 2795 run_program_and_log_output(cdrecord, 5); 2813 2796 } 2814 2797 paranoid_free(cdrecord); 2815 2798 } 2816 paranoid_free(bkp); 2817 // retract_CD_tray_and_defeat_autorun(); 2818 return (res); 2799 return(cdrw_device); 2819 2800 } 2820 2801 … … 2834 2815 char *szmsg; 2835 2816 char *cdrom_dev; 2836 char *cdrw_dev ;2817 char *cdrw_device = NULL; 2837 2818 char *our_serial_str; 2838 2819 bool ok_go_ahead_burn_it; … … 2844 2825 char *szunmount; 2845 2826 2846 malloc_string(cdrom_dev);2847 malloc_string(cdrw_dev);2848 2849 2827 asprintf(&szmsg, "I am about to burn %s #%d", 2850 2828 media_descriptor_string(g_backup_media_type), … … 2862 2840 gotos_make_me_puke: 2863 2841 ok_go_ahead_burn_it = TRUE; 2864 if (!find_cdrom_device(cdrom_dev, FALSE)) { 2842 cdrom_dev = find_cdrom_device(FALSE); 2843 if (cdrom_dev != NULL) { 2865 2844 /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird 2866 2845 log_msg(2, "paafcd: Retracting CD-ROM drive if possible" ); … … 2880 2859 log_to_screen("If there's a CD/DVD in the drive, it's blank."); 2881 2860 asprintf(&our_serial_str, "%s", ""); 2882 /*2883 if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))2884 {2885 ok_go_ahead_burn_it = FALSE;2886 log_to_screen("There isn't a writable CD/DVD in the drive.");2887 }2888 else2889 {2890 log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");2891 }2892 */2893 2861 } else if (!does_file_exist(szcdno) 2894 2862 || !does_file_exist(szserfname)) { … … 2938 2906 "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?", 2939 2907 media_descriptor_string(g_backup_media_type)); 2940 if ( interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {2908 if ((cdrw_device = interrogate_disk_currently_in_cdrw_drive(cdrw_device)) != NULL) { 2941 2909 ok_go_ahead_burn_it = FALSE; 2942 2910 log_to_screen("There isn't a writable %s in the drive.", 2943 2911 media_descriptor_string(g_backup_media_type)); 2944 2912 } 2913 paranoid_free(cdrw_device); 2945 2914 } 2946 2915 paranoid_free(mtpt); … … 2967 2936 log_msg(2, "paafcd: OK, going ahead and burning it."); 2968 2937 } 2938 paranoid_free(cdrom_dev); 2969 2939 2970 2940 log_msg(2, … … 2974 2944 log_to_screen("Proceeding w/ %s in drive.", 2975 2945 media_descriptor_string(g_backup_media_type)); 2976 paranoid_free(cdrom_dev);2977 paranoid_free(cdrw_dev);2978 2946 if (pmountable) { 2979 2947 if (attempt_to_mount_returned_this) { … … 3497 3465 && (bkpinfo->backup_media_type == cdr 3498 3466 || bkpinfo->backup_media_type == cdrw)) { 3499 if ( find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc3467 if ((tmp = find_cdrom_device(FALSE)) == NULL) // make sure find_cdrom_device() finds, records CD-R's loc 3500 3468 { 3501 3469 log_msg(3, "*Sigh* Mike, I hate your computer."); … … 3504 3472 else { 3505 3473 log_msg(3, "Great. Found Mike's CD-ROM drive."); 3474 paranoid_free(tmp); 3506 3475 } 3507 3476 } … … 3594 3563 "Verifying archives against live filesystem"); 3595 3564 if (bkpinfo->backup_media_type == cdstream) { 3596 strcpy(bkpinfo->media_device, "/dev/cdrom"); 3565 paranoid_alloc(bkpinfo->media_device, 3566 "/dev/cdrom"); 3597 3567 } 3598 3568 verify_tape_backups(bkpinfo); … … 3608 3578 g_current_media_number = cdno; 3609 3579 if (bkpinfo->backup_media_type != iso) { 3610 find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom 3580 paranoid_free(bkpinfo->media_device); 3581 bkpinfo->media_device = find_cdrom_device(FALSE); 3611 3582 } 3612 3583 chdir("/"); … … 3647 3618 3648 3619 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3649 // if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)3650 //{3651 3620 eject_device(bkpinfo->media_device); 3652 //}3653 3621 } 3654 3622 diffs = count_lines_in_file("/tmp/changed.files"); -
trunk/mondo/mondo/common/libmondo-devices-EXT.h
r146 r171 9 9 extern int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, 10 10 char *mountpoint); 11 extern int find_cdrom_device(char *output,bool try_to_mount);12 extern int find_dvd_device(char *output, bool try_to_mount);11 extern char *find_cdrom_device(bool try_to_mount); 12 extern char *find_dvd_device(void); 13 13 extern long get_phys_size_of_drive(char *drive); 14 14 extern bool is_this_a_valid_disk_format(char *format); … … 16 16 extern int find_device_in_mountlist(struct mountlist_itself *mountlist, 17 17 char *device); 18 extern int mount_CDROM_here(char *device, char *mountpoint);19 18 extern long long size_of_specific_device_in_mountlist(struct 20 19 mountlist_itself … … 28 27 29 28 30 extern int find_cdrw_device(char *cdrw_device);29 extern char *find_cdrw_device(void); 31 30 32 31 -
trunk/mondo/mondo/common/libmondo-devices.c
r162 r171 1 /* libmondo-devices.c Subroutines for handling devices 2 $Id$ 3 */ 4 1 /* $Id$ 2 * Subroutines for handling devices 3 */ 5 4 /** 6 5 * @file … … 43 42 extern char *g_selfmounted_isodir; 44 43 45 static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";46 static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";47 static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";44 static char *g_cdrw_drive_is_here = NULL; 45 static char *g_cdrom_drive_is_here = NULL; 46 static char *g_dvd_drive_is_here = NULL; 48 47 49 48 … … 61 60 void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo) 62 61 { 63 strcpy(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 64 strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 62 if (bkpinfo->media_device != NULL) { 63 paranoid_free(g_cdrom_drive_is_here); 64 asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 65 } 66 if (bkpinfo->media_device != NULL) { 67 paranoid_free(g_dvd_drive_is_here); 68 asprintf(&g_dvd_drive_is_here, bkpinfo->media_device); // just in case 69 } 65 70 } 66 71 … … 152 157 * @ingroup stringGroup 153 158 */ 154 staticchar *bkptype_to_string(t_bkptype bt)155 { 156 staticchar *output = NULL;159 char *bkptype_to_string(t_bkptype bt) 160 { 161 char *output = NULL; 157 162 158 163 paranoid_free(output); … … 319 324 /*@ ints ******************************************************* */ 320 325 int res = 0; 321 int n = 0;326 size_t n = 0; 322 327 323 328 /*@ pointers *************************************************** */ … … 432 437 * @see mount_CDROM_here 433 438 */ 434 intfind_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)439 bool find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint) 435 440 { 436 441 /*@ buffers ***************************************************** */ 437 442 438 443 /*@ int's ****************************************************** */ 439 int res;440 char *dev ;444 bool res = TRUE; 445 char *dev = NULL; 441 446 442 447 /*@ end vars **************************************************** */ 443 448 444 malloc_string(dev);445 449 assert(bkpinfo != NULL); 446 450 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 447 451 448 452 if (g_backup_media_type == dvd) { 449 strcpy(dev, g_dvd_drive_is_here); 450 if (!dev[0]) { 451 find_dvd_device(dev, FALSE); 452 } 453 } else { 454 strcpy(dev, g_cdrom_drive_is_here); 455 if (!dev[0]) { 456 find_cdrom_device(dev, FALSE); 453 if (g_dvd_drive_is_here != NULL) { 454 asprintf(&dev, g_dvd_drive_is_here); 455 } else { 456 dev = find_dvd_device(); 457 } 458 } else { 459 if (g_cdrom_drive_is_here != NULL) { 460 asprintf(&dev, g_cdrom_drive_is_here); 461 } else { 462 dev = find_cdrom_device(FALSE); 457 463 } 458 464 } … … 462 468 } 463 469 464 if ( !dev[0] || (res =mount_CDROM_here(dev, mountpoint))) {470 if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) { 465 471 if (!popup_and_get_string 466 472 ("CD-ROM device", "Please enter your CD-ROM's /dev device", 467 473 dev, MAX_STR_LEN / 4)) { 468 res = 1;474 res = FALSE; 469 475 } else { 470 476 res = mount_CDROM_here(dev, mountpoint); … … 477 483 } 478 484 paranoid_free(dev); 479 return 485 return(res); 480 486 } 481 487 … … 483 489 /** 484 490 * Locate a CD-R/W writer's SCSI node. 485 * @param cdrw_device SCSI node will be placed here. 486 * @return 0 for success, nonzero for failure.487 */ 488 int find_cdrw_device(char *cdrw_device)491 * @param cdrw_device SCSI node will be placed here. Caller needs to free it. 492 * @return the cdrw device or NULL if not found 493 */ 494 char *find_cdrw_device(void) 489 495 { 490 496 /*@ buffers ************************ */ … … 493 499 char *cdr_exe; 494 500 char *command; 495 496 if (g_cdrw_drive_is_here[0]) { 497 strcpy(cdrw_device, g_cdrw_drive_is_here); 501 char *cdrw_device; 502 503 if (g_cdrw_drive_is_here != NULL) { 504 asprintf(&cdrw_device, g_cdrw_drive_is_here); 498 505 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 499 return (0);506 return(cdrw_device); 500 507 } 501 508 if (g_backup_media_type == dvd) { 502 509 log_msg(1, 503 510 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 504 return (1);511 return(NULL); 505 512 } 506 513 run_program_and_log_output("insmod ide-scsi", -1); … … 517 524 paranoid_free(command); 518 525 } else { 519 asprintf(&tmp, " ");526 asprintf(&tmp, " "); 520 527 } 521 528 paranoid_free(cdr_exe); … … 523 530 if (strlen(tmp) < 2) { 524 531 paranoid_free(tmp); 525 return 1; 526 } else { 527 strcpy(cdrw_device, tmp); 528 paranoid_free(tmp); 532 return(NULL); 533 } else { 534 cdrw_device = tmp; 529 535 530 536 asprintf(&comment, "Found CDRW device - %s", cdrw_device); … … 532 538 paranoid_free(comment); 533 539 534 strcpy(g_cdrw_drive_is_here, cdrw_device); 535 return (0); 540 paranoid_free(g_cdrw_drive_is_here); 541 asprintf(&g_cdrw_drive_is_here, cdrw_device); 542 return(cdrw_device); 536 543 } 537 544 } … … 542 549 * Several different methods may be used to find the device, including 543 550 * calling @c cdrecord, searching @c dmesg, and trial-and-error. 544 * @param output Where to put the located /dev entry. 551 * @param output Where to put the located /dev entry. Needs to be freed by the caller. 545 552 * @param try_to_mount Whether to mount the CD as part of the test; if mount 546 553 * fails then return failure. 547 * @return 0 for success, nonzero for failure.548 */ 549 int find_cdrom_device(char *output,bool try_to_mount)554 * @return output if success or NULL otherwise. 555 */ 556 char *find_cdrom_device(bool try_to_mount) 550 557 { 551 558 /*@ pointers **************************************************** */ … … 554 561 char *q; 555 562 char *r; 556 int n = 0;557 int retval= 0;563 char *output = NULL; 564 size_t n = 0; 558 565 559 566 /*@ bool's ****************************************************** */ … … 571 578 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 572 579 573 /*@ intialize *************************************************** */574 575 output[0] = '\0';576 577 580 /*@ end vars **************************************************** */ 578 581 579 if ( g_cdrom_drive_is_here[0]&& !isdigit(g_cdrom_drive_is_here[0])) {580 strcpy(output, g_cdrom_drive_is_here);582 if ((g_cdrom_drive_is_here != NULL) && !isdigit(g_cdrom_drive_is_here[0])) { 583 asprintf(&output, g_cdrom_drive_is_here); 581 584 log_msg(3, "Been there, done that. Returning %s", output); 582 return( 0);585 return(output); 583 586 } 584 587 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 585 strcpy(output, the_last_place_i_found_it);588 asprintf(&output, the_last_place_i_found_it); 586 589 log_msg(3, 587 590 "find_cdrom_device() --- returning last found location - '%s'", 588 591 output); 589 return( 0);592 return(output); 590 593 } 591 594 … … 596 599 } 597 600 if (!find_home_of_exe(cdr_exe)) { 598 strcpy(output, "/dev/cdrom");601 asprintf(&output, "/dev/cdrom"); 599 602 log_msg(4, "Can't find cdrecord; assuming %s", output); 600 603 if (!does_device_exist(output)) { 601 604 log_msg(4, "That didn't work. Sorry."); 602 605 paranoid_free(cdr_exe); 603 return(1); 606 paranoid_free(output); 607 return(NULL); 604 608 } else { 605 609 paranoid_free(cdr_exe); 606 return( 0);610 return(output); 607 611 } 608 612 } … … 615 619 paranoid_free(cdr_exe); 616 620 paranoid_free(command); 617 return ( 1);621 return (NULL); 618 622 } 619 623 paranoid_free(command); … … 672 676 tmp); 673 677 } else { 674 sprintf(output, "/dev/%s", tmp);678 asprintf(&output, "/dev/%s", tmp); 675 679 found_it = TRUE; 676 680 } … … 713 717 { 714 718 paranoid_free(cdr_exe); 715 return( 1);719 return(NULL); 716 720 } 717 721 } … … 727 731 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 728 732 dvd_last_resort); 729 strcpy(output, dvd_last_resort); 733 paranoid_free(output); 734 asprintf(&output, dvd_last_resort); 730 735 found_it = TRUE; 731 736 } … … 741 746 output); 742 747 found_it = FALSE; 743 output[0] = '\0';748 paranoid_free(output); 744 749 } 745 750 paranoid_free(tmp); … … 749 754 log_msg(4, "(find_cdrom_device) --> '%s'", output); 750 755 if (!does_device_exist(output)) { 756 log_msg(4, "OK, I was wrong, I haven't found it... yet."); 751 757 found_it = FALSE; 752 log_msg(4, "OK, I was wrong, I haven't found it... yet.");758 paranoid_free(output); 753 759 } 754 760 } … … 784 790 { 785 791 paranoid_free(cdr_exe); 786 return( 1);792 return(NULL); 787 793 } 788 794 } … … 800 806 801 807 if (found_it && try_to_mount) { 802 if ( mount_CDROM_here(output, mountpoint)) {808 if (! mount_CDROM_here(output, mountpoint)) { 803 809 log_msg(4, "[Cardigans] I've changed my mind"); 804 810 found_it = FALSE; 811 paranoid_free(output); 805 812 } else { 806 813 asprintf(&tmp, "%s/archives", mountpoint); … … 808 815 log_msg(4, "[Cardigans] I'll take it back"); 809 816 found_it = FALSE; 817 paranoid_free(output); 810 818 } else { 811 819 asprintf(&command, "umount %s", output); … … 823 831 if (!does_file_exist(output)) { 824 832 log_msg(3, "I still haven't found it."); 825 return (1); 833 paranoid_free(output); 834 return(NULL); 826 835 } 827 836 log_msg(3, "(find_cdrom_device) --> '%s'", output); 828 837 strcpy(the_last_place_i_found_it, output); 829 strcpy(g_cdrom_drive_is_here, output); 830 return(0); 838 paranoid_free(g_cdrom_drive_is_here); 839 asprintf(&g_cdrom_drive_is_here, output); 840 return(output); 831 841 } 832 842 … … 834 844 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 835 845 cdr_exe, g_cdrw_drive_is_here); 846 paranoid_free(cdr_exe); 847 836 848 log_msg(1, "command=%s", command); 837 849 asprintf(&tmp, call_program_and_get_last_line_of_output(command)); … … 839 851 840 852 if (tmp[0]) { 841 strcpy(output, tmp);853 output = tmp; 842 854 log_msg(4, "Finally found it at %s", output); 843 retval = 0; 844 } else { 855 } else { 856 paranoid_free(tmp); 857 paranoid_free(output); 845 858 log_msg(4, "Still couldn't find it."); 846 retval = 1; 847 } 848 paranoid_free(tmp); 849 paranoid_free(cdr_exe); 850 return (retval); 851 } 852 853 854 int find_dvd_device(char *output, bool try_to_mount) 859 } 860 return(output); 861 } 862 863 864 char *find_dvd_device() 855 865 { 856 866 char *tmp; 857 867 int retval = 0, devno = -1; 858 859 if (g_dvd_drive_is_here[0]) { 860 strcpy(output, g_dvd_drive_is_here); 868 char *output = NULL; 869 870 if (g_dvd_drive_is_here != NULL) { 871 asprintf(&output, g_dvd_drive_is_here); 861 872 log_msg(3, "Been there, done that. Returning %s", output); 862 return ( 0);873 return (output); 863 874 } 864 875 … … 880 891 if (devno >= 0) { 881 892 retval = 0; 882 sprintf(output, "/dev/scd%d", devno); 883 strcpy(g_dvd_drive_is_here, output); 893 asprintf(&output, "/dev/scd%d", devno); 894 paranoid_free(g_dvd_drive_is_here); 895 asprintf(&g_dvd_drive_is_here, output); 884 896 log_msg(2, "I think DVD is at %s", output); 885 897 } else { 886 898 log_msg(2, "I cannot find DVD"); 887 retval = 1; 888 } 889 890 if (try_to_mount) { 891 log_msg(1, "Ignoring the fact that try_to_mount==TRUE"); 892 } 893 return (retval); 899 } 900 901 return(output); 894 902 } 895 903 … … 1064 1072 char *device_with_space; 1065 1073 char *tmp; 1066 int n = 0;1074 size_t n = 0; 1067 1075 1068 1076 #ifdef __FreeBSD__ … … 1212 1220 * @param device The device (or file if g_ISO_restore_mode) to mount. 1213 1221 * @param mountpoint The place to mount it. 1214 * @return 0 for success, nonzerofor failure.1215 */ 1216 intmount_CDROM_here(char *device, char *mountpoint)1222 * @return TRUE for success, FALSE for failure. 1223 */ 1224 bool mount_CDROM_here(char *device, char *mountpoint) 1217 1225 { 1218 1226 /*@ buffer ****************************************************** */ … … 1225 1233 make_hole_for_dir(mountpoint); 1226 1234 if (isdigit(device[0])) { 1227 find_cdrom_device(device, FALSE); 1235 paranoid_free(device); 1236 device = find_cdrom_device(FALSE); 1228 1237 } 1229 1238 if (g_ISO_restore_mode) { … … 1238 1247 fatal_error(command); 1239 1248 } 1240 strcpy(device, dev);1241 paranoid_free(dev);1249 paranoid_free(device); 1250 device = dev; 1242 1251 #endif 1243 1252 } … … 1263 1272 paranoid_free(command); 1264 1273 1265 return (retval); 1274 if (retval == 0) { 1275 return(TRUE); 1276 } else { 1277 return(FALSE); 1278 } 1266 1279 } 1267 1280 … … 1331 1344 } 1332 1345 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM); 1333 if ( mount_CDROM_here(tmp, MNT_CDROM)) {1346 if (! mount_CDROM_here(tmp, MNT_CDROM)) { 1334 1347 fatal_error("Mommy!"); 1335 1348 } … … 1466 1479 media_descriptor_string(bkpinfo->backup_media_type)); 1467 1480 if (bkpinfo->backup_media_type == dvd) { 1468 find_dvd_device(bkpinfo->media_device, FALSE); 1481 paranoid_free(bkpinfo->media_device); 1482 bkpinfo->media_device = find_dvd_device(); 1469 1483 asprintf(&tmp, "1"); 1470 1484 asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 1471 1485 log_msg(1, "Setting to DVD defaults"); 1472 1486 } else { 1473 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);1487 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_CDROM ); 1474 1488 asprintf(&tmp, "4"); 1475 1489 asprintf(&sz_size, "650"); … … 1508 1522 case cdstream: 1509 1523 if (bkpinfo->disaster_recovery) { 1510 strcpy(bkpinfo->media_device, "/dev/cdrom");1524 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1511 1525 log_msg(2, "CD-ROM device assumed to be at %s", 1512 1526 bkpinfo->media_device); 1513 1527 } else if (bkpinfo->restore_data 1514 1528 || bkpinfo->backup_media_type == dvd) { 1515 if ( !bkpinfo->media_device[0]) {1516 strcpy(bkpinfo->media_device, "/dev/cdrom");1529 if (bkpinfo->media_device == NULL) { 1530 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1517 1531 } // just for the heck of it :) 1518 1532 log_msg(1, "bkpinfo->media_device = %s", 1519 1533 bkpinfo->media_device); 1520 if (bkpinfo->backup_media_type == dvd 1521 || find_cdrom_device(bkpinfo->media_device, FALSE)) { 1534 if ((bkpinfo->backup_media_type == dvd) 1535 || ((tmp = find_cdrom_device(FALSE)) != NULL)) { 1536 paranoid_free(bkpinfo->media_device); 1537 bkpinfo->media_device = tmp; 1522 1538 log_msg(1, "bkpinfo->media_device = %s", 1523 1539 bkpinfo->media_device); … … 1538 1554 bkpinfo->media_device); 1539 1555 } else { 1540 if (find_cdrw_device(bkpinfo->media_device)) { 1541 bkpinfo->media_device[0] = '\0'; 1542 } 1543 if (bkpinfo->media_device[0]) { 1556 paranoid_free(bkpinfo->media_device); 1557 bkpinfo->media_device = find_cdrw_device(); 1558 if (bkpinfo->media_device != NULL) { 1544 1559 asprintf(&tmp, 1545 1560 "I think I've found your %s burner at SCSI node %s; am I right on the money?", … … 1548 1563 bkpinfo->media_device); 1549 1564 if (!ask_me_yes_or_no(tmp)) { 1550 bkpinfo->media_device[0] = '\0';1565 paranoid_free(bkpinfo->media_device); 1551 1566 } 1552 1567 paranoid_free(tmp); 1553 } 1554 if (!bkpinfo->media_device[0]) { 1568 } else { 1555 1569 if (g_kernel_version < 2.6) { 1556 1570 i = popup_and_get_string("Device node?", … … 1584 1598 case tape: 1585 1599 1600 paranoid_free(bkpinfo->media_device); 1586 1601 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) { 1587 1602 log_msg(3, "Ok, using vanilla scsi tape."); 1588 strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);1603 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE ); 1589 1604 if ((fin = fopen(bkpinfo->media_device, "r"))) { 1590 1605 paranoid_fclose(fin); 1591 1606 } else { 1592 strcpy(bkpinfo->media_device,"/dev/osst0");1593 } 1594 } 1595 if (bkpinfo->media_device [0]) {1607 paranoid_alloc(bkpinfo->media_device,"/dev/osst0"); 1608 } 1609 } 1610 if (bkpinfo->media_device != NULL) { 1596 1611 if ((fin = fopen(bkpinfo->media_device, "r"))) { 1597 1612 paranoid_fclose(fin); … … 1606 1621 bkpinfo->media_device); 1607 1622 if (!ask_me_yes_or_no(tmp)) { 1608 bkpinfo->media_device[0] = '\0';1623 paranoid_free(bkpinfo->media_device); 1609 1624 } 1610 1625 paranoid_free(tmp); 1611 1626 } 1612 if ( !bkpinfo->media_device[0]) {1627 if (bkpinfo->media_device == NULL) { 1613 1628 if (!popup_and_get_string 1614 1629 ("Device name?", … … 1907 1922 #ifndef __FreeBSD__ 1908 1923 if (!ask_me_yes_or_no 1909 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) 1910 #endif 1911 { 1912 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 1913 } 1924 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) { 1925 paranoid_alloc(bkpinfo->kernel_path, "FAILSAFE"); 1926 } 1927 #endif 1914 1928 1915 1929 if (!ask_me_yes_or_no … … 2068 2082 * If @p dev cannot be read, set @p output to "". 2069 2083 * @param dev The device to check for. 2070 * @param output Set to @p dev if @p dev exists, "" otherwise.2084 * @param output Set to @p dev if @p dev exists, NULL otherwise. Needs to be freed by caller 2071 2085 * @return TRUE if @p dev exists, FALSE if it doesn't. 2072 2086 */ … … 2075 2089 char *command; 2076 2090 2091 paranoid_free(output); 2077 2092 if (!dev || dev[0] == '\0') { 2078 output[0] = '\0';2079 2093 return (FALSE); 2080 2094 } … … 2089 2103 if (!run_program_and_log_output(command, FALSE) 2090 2104 && !run_program_and_log_output(command, FALSE)) { 2091 strcpy(output, dev);2105 asprintf(&output, dev); 2092 2106 log_msg(4, "Found it - %s", dev); 2093 2107 paranoid_free(command); 2094 2108 return (TRUE); 2095 2109 } else { 2096 output[0] = '\0';2097 2110 log_msg(4, "It's not %s", dev); 2098 2111 paranoid_free(command); … … 2128 2141 } 2129 2142 2130 asprintf(&mountdev, bkpinfo->media_device); 2131 if (!mountdev[0]) { 2143 if (bkpinfo->media_device == NULL) { 2132 2144 log_it 2133 2145 ("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 2134 find_cdrom_device(bkpinfo->media_device,FALSE);2146 bkpinfo->media_device = find_cdrom_device(FALSE); 2135 2147 } 2136 2148 if (!is_this_device_mounted(MNT_CDROM)) { 2137 mount_CDROM_here(mountdev, MNT_CDROM);2149 (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM); 2138 2150 } 2139 2151 cd_number = 2140 2152 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2141 paranoid_free(mountdev);2142 2153 return (cd_number); 2143 2154 } … … 2243 2254 int count_lilos = 0; 2244 2255 int count_grubs = 0; 2245 int n = 0;2256 size_t n = 0; 2246 2257 2247 2258 /*@ end vars *************************************************** */ -
trunk/mondo/mondo/common/libmondo-devices.h
r146 r171 8 8 bool does_string_exist_in_boot_block(char *dev, char *str); 9 9 int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint); 10 int find_cdrom_device(char *output,bool try_to_mount);11 int find_dvd_device(char *output, bool try_to_mount);10 char *find_cdrom_device(bool try_to_mount); 11 char *find_dvd_device(void); 12 12 long get_phys_size_of_drive(char *drive); 13 13 bool is_this_a_valid_disk_format(char *format); 14 int mount_CDROM_here(char *device, char *mountpoint);15 14 int find_device_in_mountlist(struct mountlist_itself *mountlist, 16 15 char *device); … … 23 22 24 23 25 int find_cdrw_device(char *cdrw_device);24 char *find_cdrw_device(void); 26 25 27 26 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, -
trunk/mondo/mondo/common/libmondo-filelist.c
r147 r171 214 214 /*@ int **************************************** */ 215 215 int i; 216 int n = 0;216 size_t n = 0; 217 217 long curr_set_no; 218 218 … … 412 412 FILE *pattr; 413 413 char *tmp = NULL; 414 int n = 0;414 size_t n = 0; 415 415 416 416 pattr = popen(syscall, "r"); … … 443 443 char *file_to_analyze = NULL; 444 444 int i; 445 int n = 0;445 size_t n = 0; 446 446 447 447 if (!(fin = fopen(filelist, "r"))) { … … 550 550 int retval = 0; 551 551 int i; 552 int n = 0;552 size_t n = 0; 553 553 char *p, *q; 554 554 FILE *pin, *pout, *faclin; … … 859 859 char *tmp; 860 860 int pos_in_fname; 861 int n = 0;861 size_t n = 0; 862 862 /*@ int ******************************************************** */ 863 863 int percentage; … … 1769 1769 } 1770 1770 1771 /*1772 if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }1773 if (strlen(fname)==0) { continue; }1774 sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);1775 system(temporary_string);1776 */1777 1778 1771 log_msg(5, "Looking for '%s'", fname); 1779 1772 found_node = find_string_at_node(filelist, fname); … … 1788 1781 turn_wildcard_chars_into_literal_chars(tmp, fname); 1789 1782 fprintf(fout, "%s\n", tmp); 1783 paranoid_free(tmp); 1790 1784 retval++; 1791 1785 } … … 1812 1806 FILE *fin; 1813 1807 char *tmp = NULL; 1814 int n = 0;1808 size_t n = 0; 1815 1809 struct s_node *nod; 1816 1810 -
trunk/mondo/mondo/common/libmondo-files-EXT.h
r59 r171 17 17 extern char *last_line_of_file(char *filename); 18 18 extern long long length_of_file(char *filename); 19 extern int make_checksum_list_file(char *filelist, char *cksumlist,20 char *comppath);21 19 extern int make_hole_for_file(char *outfile_fname); 22 20 extern void make_list_of_files_to_ignore(char *ignorefiles_fname, … … 51 49 extern int read_one_liner_data_file(char *fname, char *contents); 52 50 extern int mode_of_file(char *fname); 51 extern void paranoid_alloc(char *alloc, char *orig); -
trunk/mondo/mondo/common/libmondo-files.c
r149 r171 1 /* libmondo-files.c file manipulation 2 $Id$ 3 . 4 5 6 04/16/04 7 - find_home_of_exe() really does return NULL now if file not found 8 9 03/22/04 10 - added mode_of_file() 11 12 10/02/03 13 - cleaned up grab_percentage_from_last_line_of_file() 14 15 09/18 16 - added int make_grub_install_scriptlet() 17 18 09/16 19 - cleaned up mkisofs feedback window 20 21 09/12 22 - fixed Teuton-hostile bug in size_of_all_biggiefiles_K() 23 24 09/05 25 - added size_of_partition_in_mountlist_K() 26 - size_of_all_biggiefiles_K() now calls get_phys_size_of_drive(fname) 27 28 07/02 29 - fixed calls to popup_and_get_string() 30 31 05/19 32 - added CP_BIN 33 34 05/05 35 - added Joshua Oreman's FreeBSD patches 36 37 05/04 38 - find_home_of_exe() now returns NULL if file not found 39 40 04/26 41 - if >4 media est'd, say one meeeellion 42 43 04/25 44 - fixed minor bug in find_home_of_exe() 45 46 04/24 47 - added lots of assert()'s and log_OS_error()'s 48 49 04/07 50 - fix find_home_of_exe() 51 - cleaned up code a bit 52 53 03/27 54 - copy_mondo_and_mindi_stuff --- if _homedir_/payload.tgz exists then untar it to CD 55 56 01/14/2003 57 - if backup media type == nfs then don't estimate no. of media reqd 58 59 11/25/2002 60 - don't log/echo estimated # of media required if >=50 61 62 10/01 - 11/09 63 - chmod uses 0x, not decimal :) 64 - added is_this_file_compressed() 65 - replace convoluted grep with wc (KP) 66 67 09/01 - 09/30 68 - only show "number of media" estimate if no -x 69 - run_program_and_log_output() now takes boolean operator to specify 70 whether it will log its activities in the event of _success_ 71 72 08/01 - 08/31 73 - handle unknown media sizes 74 - cleaned up some log_it() calls 75 76 07/24 77 - created 1 /* $Id$ 2 * file manipulation 78 3 */ 79 4 … … 117 42 { 118 43 /*@ buffers ***************************************************** */ 119 static char output[MAX_STR_LEN]; 120 char command[MAX_STR_LEN * 2]; 121 char tmp[MAX_STR_LEN]; 44 static char *output = NULL; 45 char *command; 46 char *tmp; 47 size_t n = 0; 122 48 123 49 /*@ pointers **************************************************** */ … … 132 58 133 59 assert_string_is_neither_NULL_nor_zerolength(filename); 60 134 61 if (does_file_exist(filename)) { 135 sprintf(command, "md5sum \"%s\"", filename);62 asprintf(&command, "md5sum \"%s\"", filename); 136 63 fin = popen(command, "r"); 64 paranoid_free(command); 65 137 66 if (fin) { 138 (void) fgets(output, MAX_STR_LEN, fin);67 (void) getline(&output, &n, fin); 139 68 p = strchr(output, ' '); 140 69 paranoid_pclose(fin); 141 70 } 142 71 } else { 143 sprintf(tmp, "File '%s' not found; cannot calc checksum",72 asprintf(&tmp, "File '%s' not found; cannot calc checksum", 144 73 filename); 145 74 log_it(tmp); 75 paranoid_free(tmp); 146 76 } 147 77 if (p) { … … 163 93 164 94 /*@ buffers ***************************************************** */ 165 static char curr_cksum[1000];95 char *curr_cksum; 166 96 167 97 /*@ pointers **************************************************** */ … … 170 100 struct stat buf; 171 101 172 /*@ initialize data *************************************************** */173 curr_cksum[0] = '\0';174 175 102 /*@************************************************************** */ 176 103 177 104 assert_string_is_neither_NULL_nor_zerolength(curr_fname); 178 105 if (lstat(curr_fname, &buf)) { 179 return (curr_cksum); // empty 180 } 181 182 sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size), 106 asprintf(&curr_cksum, ""); 107 } else { 108 asprintf(&curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size), 183 109 (long) (buf.st_mtime), (long) (buf.st_ctime)); 110 } 184 111 return (curr_cksum); 185 112 } 186 187 113 188 114 … … 197 123 198 124 /*@ buffers ***************************************************** */ 199 char command[MAX_STR_LEN * 2];200 char incoming[MAX_STR_LEN];201 char tmp[MAX_STR_LEN];125 char *command; 126 char *incoming = NULL; 127 char *tmp; 202 128 203 129 /*@ long ******************************************************** */ 204 130 long noof_lines = -1L; 205 131 132 /*@ int ******************************************************** */ 133 size_t n = 0; 134 206 135 /*@ pointers **************************************************** */ 207 136 FILE *fin; 208 137 209 /*@ initialize [0] to null ******************************************** */210 incoming[0] = '\0';211 212 138 assert_string_is_neither_NULL_nor_zerolength(filename); 213 139 if (!does_file_exist(filename)) { 214 sprintf(tmp,140 asprintf(&tmp, 215 141 "%s does not exist, so I cannot found the number of lines in it", 216 142 filename); 217 143 log_it(tmp); 144 paranoid_free(tmp); 218 145 return (0); 219 146 } 220 sprintf(command, "cat %s | wc -l", filename);147 asprintf(&command, "cat %s | wc -l", filename); 221 148 if (!does_file_exist(filename)) { 222 149 return (-1); 223 150 } 224 151 fin = popen(command, "r"); 152 paranoid_free(command); 153 225 154 if (fin) { 226 155 if (feof(fin)) { 227 156 noof_lines = 0; 228 157 } else { 229 (void) fgets(incoming, MAX_STR_LEN - 1, fin);158 (void) getline(&incoming, &n, fin); 230 159 while (strlen(incoming) > 0 231 160 && incoming[strlen(incoming) - 1] < 32) { … … 233 162 } 234 163 noof_lines = atol(incoming); 164 paranoid_free(incoming); 235 165 } 236 166 paranoid_pclose(fin); … … 254 184 255 185 assert(filename != NULL); 256 // assert_string_is_neither_NULL_nor_zerolength(filename); 186 257 187 if (lstat(filename, &buf)) { 258 188 log_msg(20, "%s does not exist", filename); … … 265 195 266 196 267 268 269 270 271 197 /** 272 198 * Modify @p inout (a file containing a list of files) to only contain files … … 278 204 void exclude_nonexistent_files(char *inout) 279 205 { 280 char infname[MAX_STR_LEN];281 char outfname[MAX_STR_LEN];282 char tmp[MAX_STR_LEN];283 char incoming[MAX_STR_LEN];206 char *infname; 207 char *outfname; 208 char *tmp; 209 char *incoming = NULL; 284 210 285 211 /*@ int ********************************************************* */ 286 212 int i; 213 size_t n = 0; 287 214 288 215 /*@ pointers **************************************************** */ … … 293 220 294 221 assert_string_is_neither_NULL_nor_zerolength(inout); 295 sprintf(infname, "%s.in", inout); 296 sprintf(outfname, "%s", inout); 297 sprintf(tmp, "cp -f %s %s", inout, infname); 222 223 asprintf(&infname, "%s.in", inout); 224 225 asprintf(&tmp, "cp -f %s %s", inout, infname); 298 226 run_program_and_log_output(tmp, FALSE); 227 paranoid_free(tmp); 228 299 229 if (!(fin = fopen(infname, "r"))) { 300 230 log_OS_error("Unable to openin infname"); 231 paranoid_free(infname); 301 232 return; 302 233 } 234 235 asprintf(&outfname, "%s", inout); 303 236 if (!(fout = fopen(outfname, "w"))) { 304 237 log_OS_error("Unable to openout outfname"); 238 paranoid_free(outfname); 305 239 return; 306 240 } 307 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); 308 fgets(incoming, MAX_STR_LEN, fin)) { 241 paranoid_free(outfname); 242 243 for (getline(&incoming, &n, fin); !feof(fin); 244 getline(&incoming, &n, fin)) { 309 245 i = strlen(incoming) - 1; 310 246 if (i >= 0 && incoming[i] < 32) { … … 314 250 fprintf(fout, "%s\n", incoming); 315 251 } else { 316 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);252 asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming); 317 253 log_it(tmp); 318 } 319 } 254 paranoid_free(tmp); 255 } 256 } 257 paranoid_free(incoming); 320 258 paranoid_fclose(fout); 321 259 paranoid_fclose(fin); 322 260 unlink(infname); 323 } 324 325 326 327 328 329 330 261 paranoid_free(infname); 262 } 331 263 332 264 … … 340 272 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 341 273 { 342 char tmp[MAX_STR_LEN];274 char *tmp; 343 275 344 276 if (!kernel[0]) { … … 360 292 ("Kernel not found. Please specify with the '-k' flag."); 361 293 } 362 sprintf(tmp, "User says kernel is at %s", kernel);294 asprintf(&tmp, "User says kernel is at %s", kernel); 363 295 log_it(tmp); 296 paranoid_free(tmp); 364 297 } 365 298 return (0); 366 299 } 367 368 369 370 371 300 372 301 … … 387 316 char *command; 388 317 389 malloc_string(incoming);390 malloc_string(command);391 incoming[0] = '\0';392 318 /*@******************************* */ 393 319 394 320 assert_string_is_neither_NULL_nor_zerolength(fname); 395 sprintf(command, "which %s 2> /dev/null", fname); 396 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 321 asprintf(&command, "which %s 2> /dev/null", fname); 322 asprintf(&incoming, call_program_and_get_last_line_of_output(command)); 323 paranoid_free(command); 324 397 325 if (incoming[0] == '\0') { 398 326 if (system("which file > /dev/null 2> /dev/null")) { 399 327 paranoid_free(incoming); 400 paranoid_free(command);401 output[0] = '\0';402 328 return (NULL); // forget it :) 403 329 } 404 sprintf(command,330 asprintf(&command, 405 331 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", 406 332 incoming); 407 strcpy(incoming, 333 paranoid_free(incoming); 334 335 asprintf(&incoming, 408 336 call_program_and_get_last_line_of_output(command)); 337 paranoid_free(command); 409 338 } 410 339 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 411 340 { 412 sprintf(command, "dirname %s 2> /dev/null", incoming); 413 strcpy(incoming, 341 asprintf(&command, "dirname %s 2> /dev/null", incoming); 342 paranoid_free(incoming); 343 344 asprintf(&incoming, 414 345 call_program_and_get_last_line_of_output(command)); 346 paranoid_free(command); 415 347 } 416 348 strcpy(output, incoming); 349 paranoid_free(incoming); 350 417 351 if (output[0] != '\0' && does_file_exist(output)) { 418 352 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 419 incoming);353 output); 420 354 } else { 421 355 output[0] = '\0'; 422 356 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 423 357 } 424 paranoid_free(incoming);425 paranoid_free(command);426 358 if (!output[0]) { 427 359 return (NULL); … … 432 364 433 365 434 435 436 437 438 439 440 366 /** 441 367 * Get the last sequence of digits surrounded by non-digits in the first 32k of … … 458 384 459 385 assert_string_is_neither_NULL_nor_zerolength(logfile); 386 460 387 if (!(fin = fopen(logfile, "r"))) { 461 388 log_OS_error("Unable to open logfile"); … … 471 398 for (; len > 0 && isdigit(datablock[len - 1]); len--); 472 399 trackno = atoi(datablock + len); 473 /*474 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);475 log_it(tmp);476 */477 400 return (trackno); 478 401 } 479 480 481 482 483 484 402 485 403 … … 494 412 495 413 /*@ buffers ***************************************************** */ 496 char tmp[MAX_STR_LEN]; 497 char lastline[MAX_STR_LEN]; 498 char command[MAX_STR_LEN]; 414 char *lastline; 415 char *command; 499 416 /*@ pointers **************************************************** */ 500 417 char *p; … … 507 424 && !strstr(err_log_lines[i], "% done"); i--); 508 425 if (i < 0) { 509 sprintf(command,426 asprintf(&command, 510 427 "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'", 511 428 filename, '%'); 512 strcpy(lastline,429 asprintf(&lastline, 513 430 call_program_and_get_last_line_of_output(command)); 431 paranoid_free(command); 514 432 if (!lastline[0]) { 433 paranoid_free(lastline); 515 434 return (0); 516 435 } 517 436 } else { 518 strcpy(lastline, err_log_lines[i]);437 asprintf(&lastline, err_log_lines[i]); 519 438 } 520 439 … … 523 442 *p = '\0'; 524 443 } 525 // log_msg(2, "lastline='%s', ", p, lastline);526 444 if (!p) { 445 paranoid_free(lastline); 527 446 return (0); 528 447 } … … 533 452 } 534 453 i = atoi(p); 535 536 sprintf(tmp, "'%s' --> %d", p, i); 537 // log_to_screen(tmp); 454 paranoid_free(lastline); 538 455 539 456 return (i); 540 457 } 541 542 543 544 458 545 459 … … 554 468 /*@ buffers ***************************************************** */ 555 469 static char output[MAX_STR_LEN]; 556 static char command[MAX_STR_LEN * 2];557 static char tmp[MAX_STR_LEN];470 static char *command; 471 static char *tmp; 558 472 559 473 /*@ pointers **************************************************** */ … … 563 477 564 478 if (!does_file_exist(filename)) { 565 sprintf(tmp, "Tring to get last line of nonexistent file (%s)",479 asprintf(&tmp, "Tring to get last line of nonexistent file (%s)", 566 480 filename); 567 481 log_it(tmp); 482 paranoid_free(tmp); 483 568 484 output[0] = '\0'; 569 485 return (output); 570 486 } 571 sprintf(command, "tail -n1 %s", filename);487 asprintf(&command, "tail -n1 %s", filename); 572 488 fin = popen(command, "r"); 489 paranoid_free(command); 490 573 491 (void) fgets(output, MAX_STR_LEN, fin); 574 492 paranoid_pclose(fin); … … 578 496 return (output); 579 497 } 498 580 499 581 500 /** … … 605 524 606 525 607 608 /**609 * ?????610 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.611 */612 int613 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)614 {615 /*@ pointers **************************************************** */616 FILE *fin;617 FILE *fout;618 619 /*@ int ******************************************************* */620 int percentage;621 int i;622 int counter = 0;623 624 /*@ buffer ****************************************************** */625 char stub_fname[1000];626 char curr_fname[1000];627 char curr_cksum[1000];628 char tmp[1000];629 630 /*@ long [long] ************************************************* */631 long long filelist_length;632 long curr_pos;633 long start_time;634 long current_time;635 long time_taken;636 long time_remaining;637 638 /*@ end vars *************************************************** */639 640 start_time = get_time();641 filelist_length = length_of_file(filelist);642 sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);643 log_it(tmp);644 fin = fopen(filelist, "r");645 if (fin == NULL) {646 log_OS_error("Unable to fopen-in filelist");647 log_to_screen("Can't open filelist");648 return (1);649 }650 fout = fopen(cksumlist, "w");651 if (fout == NULL) {652 log_OS_error("Unable to openout cksumlist");653 paranoid_fclose(fin);654 log_to_screen("Can't open checksum list");655 return (1);656 }657 for (fgets(stub_fname, 999, fin); !feof(fin);658 fgets(stub_fname, 999, fin)) {659 if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {660 stub_fname[i] = '\0';661 }662 sprintf(tmp, "%s%s", comppath, stub_fname);663 strcpy(curr_fname, tmp + 1);664 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));665 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);666 if (counter++ > 12) {667 current_time = get_time();668 counter = 0;669 curr_fname[37] = '\0';670 curr_pos = ftell(fin) / 1024;671 percentage = (int) (curr_pos * 100 / filelist_length);672 time_taken = current_time - start_time;673 if (percentage == 0) {674 /* printf("%0d%% done \r",percentage); */675 } else {676 time_remaining =677 time_taken * 100 / (long) (percentage) - time_taken;678 sprintf(tmp,679 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r",680 percentage, (int) (time_taken / 60),681 (int) (time_taken % 60),682 (int) (time_remaining / 60),683 (int) (time_remaining % 60), curr_fname);684 log_to_screen(tmp);685 }686 sync();687 }688 }689 paranoid_fclose(fout);690 paranoid_fclose(fin);691 log_it("Done.");692 return (0);693 }694 695 696 526 /** 697 527 * Create the directory @p outdir_fname and all parent directories. Equivalent to <tt>mkdir -p</tt>. … … 702 532 int make_hole_for_dir(char *outdir_fname) 703 533 { 704 char tmp[MAX_STR_LEN * 2];534 char *tmp; 705 535 int res = 0; 706 536 707 537 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 708 sprintf(tmp, "mkdir -p %s", outdir_fname);538 asprintf(&tmp, "mkdir -p %s", outdir_fname); 709 539 res = system(tmp); 540 paranoid_free(tmp); 710 541 return (res); 711 542 } … … 722 553 { 723 554 /*@ buffer ****************************************************** */ 724 char command[MAX_STR_LEN * 2];555 char *command; 725 556 726 557 /*@ int ******************************************************** */ … … 732 563 assert(!strstr(outfile_fname, MNT_CDROM)); 733 564 assert(!strstr(outfile_fname, "/dev/cdrom")); 734 sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 565 566 asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 735 567 res += system(command); 736 sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 568 paranoid_free(command); 569 570 asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 737 571 res += system(command); 738 sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 572 paranoid_free(command); 573 574 asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 739 575 res += system(command); 576 paranoid_free(command); 740 577 unlink(outfile_fname); 741 578 return (0); 742 579 } 743 744 745 580 746 581 … … 760 595 761 596 /*@ buffers **************************************************** */ 762 char incoming[MAX_STR_LEN]; 763 597 char *incoming = NULL; 598 599 size_t n = 0; 764 600 /*@ end vars *************************************************** */ 765 601 … … 771 607 return (0); 772 608 } 773 (void) fgets(incoming, MAX_STR_LEN - 1, fin);609 (void) getline(&incoming, &n, fin); 774 610 while (!feof(fin)) { 775 611 if (strstr(incoming, wildcard)) { 776 612 matches++; 777 613 } 778 (void) fgets(incoming, MAX_STR_LEN - 1, fin);614 (void) getline(&incoming, &n, fin); 779 615 } 780 616 paranoid_fclose(fin); 617 paranoid_free(incoming); 781 618 return (matches); 782 619 } 783 784 785 620 786 621 … … 794 629 void register_pid(pid_t pid, char *name_str) 795 630 { 796 char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1]; 631 char *tmp; 632 char *lockfile_fname; 797 633 int res; 634 size_t n = 0; 798 635 FILE *fin; 799 636 800 sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str);637 asprintf(&lockfile_fname, "/var/run/monitas-%s.pid", name_str); 801 638 if (!pid) { 802 639 log_it("Unregistering PID"); … … 804 641 log_it("Error unregistering PID"); 805 642 } 643 paranoid_free(lockfile_fname); 806 644 return; 807 645 } 808 646 if (does_file_exist(lockfile_fname)) { 809 tmp[0] = '\0';810 647 if ((fin = fopen(lockfile_fname, "r"))) { 811 (void) fgets(tmp, MAX_STR_LEN, fin);648 (void) getline(&tmp, &n, fin); 812 649 paranoid_fclose(fin); 813 650 } else { … … 815 652 } 816 653 pid = (pid_t) atol(tmp); 817 sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid); 654 paranoid_free(tmp); 655 656 asprintf(&tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid); 818 657 res = system(tmp); 658 paranoid_free(tmp); 819 659 if (!res) { 820 660 log_it … … 823 663 } 824 664 } 825 sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(),665 asprintf(&tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(), 826 666 lockfile_fname); 667 paranoid_free(lockfile_fname); 668 827 669 if (system(tmp)) { 828 670 fatal_error("Cannot register PID"); 829 671 } 830 } 831 672 paranoid_free(tmp); 673 return; 674 } 832 675 833 676 … … 840 683 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 841 684 { 842 char command[MAX_STR_LEN]; 843 char mountlist[MAX_STR_LEN]; 844 char sz_res[MAX_STR_LEN]; 685 char *command; 686 char *sz_res; 845 687 long file_len_K; 846 688 847 sprintf(mountlist, "%s/mountlist.txt", tmpdir); 848 sprintf(command, 849 "cat %s/mountlist.txt | grep \"%s \" | head -n1 | awk '{print $4;}'", 850 tmpdir, dev); 689 asprintf(&command, 690 "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'", 691 dev, tmpdir); 851 692 log_it(command); 852 strcpy(sz_res, call_program_and_get_last_line_of_output(command));693 asprintf(&sz_res, call_program_and_get_last_line_of_output(command)); 853 694 file_len_K = atol(sz_res); 854 695 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 696 paranoid_free(command); 697 paranoid_free(sz_res); 855 698 return (file_len_K); 856 699 } 700 857 701 858 702 /** … … 874 718 /*@ pointers *************************************************** */ 875 719 FILE *fin = NULL; 720 size_t n = 0; 876 721 877 722 /*@ end vars *************************************************** */ 878 723 879 malloc_string(fname);880 malloc_string(biggielist);881 malloc_string(comment);882 724 log_it("Calculating size of all biggiefiles (in total)"); 883 sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);725 asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 884 726 log_it("biggielist = %s", biggielist); 885 727 if (!(fin = fopen(biggielist, "r"))) { … … 888 730 } else { 889 731 log_msg(4, "Reading it..."); 890 for ( fgets(fname, MAX_STR_LEN, fin); !feof(fin);891 fgets(fname, MAX_STR_LEN, fin)) {732 for (getline(&fname, &n, fin); !feof(fin); 733 getline(&fname, &n, fin)) { 892 734 if (fname[strlen(fname) - 1] <= 32) { 893 735 fname[strlen(fname) - 1] = '\0'; … … 902 744 log_msg(4, "%s --> %ld K", fname, file_len_K); 903 745 } 904 sprintf(comment,746 asprintf(&comment, 905 747 "After adding %s, scratchL+%ld now equals %ld", fname, 906 748 file_len_K, scratchL); 907 749 log_msg(4, comment); 750 paranoid_free(comment); 751 908 752 if (feof(fin)) { 909 753 break; 910 754 } 911 755 } 912 } 756 paranoid_free(fname); 757 } 758 paranoid_free(biggielist); 759 913 760 log_it("Closing..."); 914 761 paranoid_fclose(fin); 915 762 log_it("Finished calculating total size of all biggiefiles"); 916 paranoid_free(fname);917 paranoid_free(biggielist);918 paranoid_free(comment);919 763 return (scratchL); 920 764 } 765 921 766 922 767 /** … … 929 774 { 930 775 /*@ buffer ****************************************************** */ 931 char tmp[MAX_STR_LEN];932 char command[MAX_STR_LEN * 2];776 char *tmp = NULL; 777 char *command; 933 778 long long llres; 779 size_t n = 0; 934 780 /*@ pointers **************************************************** */ 935 781 char *p; … … 938 784 /*@ end vars *************************************************** */ 939 785 940 sprintf(command, "du -sk %s", mountpt);786 asprintf(&command, "du -sk %s", mountpt); 941 787 fin = popen(command, "r"); 942 (void) fgets(tmp, MAX_STR_LEN, fin); 788 paranoid_free(command); 789 790 (void) getline(&tmp, &n, fin); 943 791 paranoid_pclose(fin); 944 792 p = strchr(tmp, '\t'); … … 950 798 llres += (int) (*p - '0'); 951 799 } 800 paranoid_free(tmp); 952 801 return (llres); 953 802 } … … 969 818 } 970 819 820 971 821 /** 972 822 * Update a reverse CRC checksum to include another character. … … 985 835 986 836 987 988 989 837 /** 990 838 * Check for an executable on the user's system; write a message to the … … 996 844 { 997 845 /*@ buffers *** */ 998 char command[MAX_STR_LEN * 2]; 999 char errorstr[MAX_STR_LEN]; 1000 1001 1002 sprintf(command, "which %s > /dev/null 2> /dev/null", fname); 1003 sprintf(errorstr, 846 char *command; 847 char *errorstr; 848 int res = 0; 849 850 851 asprintf(&command, "which %s > /dev/null 2> /dev/null", fname); 852 res = system(command); 853 paranoid_free(command); 854 855 if (res) { 856 asprintf(&errorstr, 1004 857 "Please install '%s'. I cannot find it on your system.", 1005 858 fname); 1006 if (system(command)) {1007 859 log_to_screen(errorstr); 860 paranoid_free(errorstr); 1008 861 log_to_screen 1009 ("There may be hyperlink at http://www.mondorescue.comwhich");862 ("There may be an hyperlink at http://www.mondorescue.org which"); 1010 863 log_to_screen("will take you to the relevant (missing) package."); 1011 864 return (1); … … 1014 867 } 1015 868 } 1016 1017 1018 1019 1020 869 1021 870 … … 1050 899 1051 900 1052 1053 901 /** 1054 902 * Read @p fname into @p contents. … … 1083 931 return (res); 1084 932 } 1085 1086 1087 1088 1089 1090 1091 1092 933 1093 934 … … 1105 946 { 1106 947 /*@ Char buffers ** */ 1107 char command[MAX_STR_LEN * 2];1108 char tmp[MAX_STR_LEN];948 char *command; 949 char *tmp; 1109 950 char old_pwd[MAX_STR_LEN]; 1110 951 … … 1118 959 g_mondo_home = find_and_store_mondoarchives_home(); 1119 960 } 1120 sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,961 asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1121 962 bkpinfo->scratchdir); 1122 963 … … 1125 966 fatal_error("Failed to copy Mondo's stuff to scratchdir"); 1126 967 } 1127 1128 sprintf(tmp, "%s/payload.tgz", g_mondo_home); 968 paranoid_free(command); 969 970 asprintf(&tmp, "%s/payload.tgz", g_mondo_home); 1129 971 if (does_file_exist(tmp)) { 1130 972 log_it("Untarring payload %s to scratchdir %s", tmp, … … 1132 974 (void) getcwd(old_pwd, MAX_STR_LEN - 1); 1133 975 chdir(bkpinfo->scratchdir); 1134 sprintf(command, "tar -zxvf %s", tmp);976 asprintf(&command, "tar -zxvf %s", tmp); 1135 977 if (run_program_and_log_output(command, FALSE)) { 1136 978 fatal_error("Failed to untar payload"); 1137 979 } 980 paranoid_free(command); 1138 981 chdir(old_pwd); 1139 982 } 1140 1141 sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 983 paranoid_free(tmp); 984 985 asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1142 986 bkpinfo->scratchdir); 1143 1144 987 if (run_program_and_log_output(command, FALSE)) { 1145 988 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1146 989 } 1147 1148 strcpy(tmp, 990 paranoid_free(command); 991 992 asprintf(&tmp, 1149 993 call_program_and_get_last_line_of_output("which mondorestore")); 1150 994 if (!tmp[0]) { … … 1152 996 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1153 997 } 1154 sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 998 asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 999 paranoid_free(tmp); 1000 1155 1001 if (run_program_and_log_output(command, FALSE)) { 1156 1002 fatal_error("Failed to copy mondorestore to tmpdir"); 1157 1003 } 1158 1159 sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1004 paranoid_free(command); 1005 1006 asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1160 1007 paranoid_system(command); 1008 paranoid_free(command); 1161 1009 1162 1010 if (bkpinfo->postnuke_tarball[0]) { 1163 sprintf(command, "cp -f %s %s/post-nuke.tgz",1011 asprintf(&command, "cp -f %s %s/post-nuke.tgz", 1164 1012 bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1165 1013 if (run_program_and_log_output(command, FALSE)) { 1166 1014 fatal_error("Unable to copy post-nuke tarball to tmpdir"); 1167 1015 } 1168 }1169 1016 paranoid_free(command); 1017 } 1170 1018 1171 1019 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1172 1020 } 1173 1174 1175 1176 1021 1177 1022 … … 1188 1033 1189 1034 /*@ buffers ******** */ 1190 char outfile[MAX_STR_LEN];1191 char nfs_dev[MAX_STR_LEN];1192 char nfs_mount[MAX_STR_LEN];1193 char nfs_client_ipaddr[MAX_STR_LEN];1194 char nfs_client_netmask[MAX_STR_LEN];1195 char nfs_client_defgw[MAX_STR_LEN];1196 char nfs_server_ipaddr[MAX_STR_LEN];1197 char tmp[MAX_STR_LEN];1198 char command[MAX_STR_LEN * 2];1035 char *outfile; 1036 char *nfs_dev; 1037 char *nfs_mount; 1038 char *nfs_client_ipaddr; 1039 char *nfs_client_netmask; 1040 char *nfs_client_defgw; 1041 char *nfs_server_ipaddr; 1042 char *tmp; 1043 char *command; 1199 1044 1200 1045 /*@ pointers ***** */ … … 1205 1050 1206 1051 log_it("Storing NFS configuration"); 1207 strcpy(tmp, bkpinfo->nfs_mount);1052 asprintf(&tmp, bkpinfo->nfs_mount); 1208 1053 p = strchr(tmp, ':'); 1209 1054 if (!p) { … … 1212 1057 } 1213 1058 *(p++) = '\0'; 1214 strcpy(nfs_server_ipaddr, tmp); 1215 strcpy(nfs_mount, p); 1216 sprintf(command, 1059 asprintf(&nfs_server_ipaddr, tmp); 1060 paranoid_free(tmp); 1061 1062 asprintf(&nfs_mount, p); 1063 asprintf(&command, 1217 1064 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1218 strcpy(nfs_dev, call_program_and_get_last_line_of_output(command)); 1219 sprintf(command, 1065 asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command)); 1066 paranoid_free(command); 1067 1068 asprintf(&command, 1220 1069 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1221 strcpy(nfs_client_ipaddr,1070 asprintf(&nfs_client_ipaddr, 1222 1071 call_program_and_get_last_line_of_output(command)); 1223 sprintf(command, 1072 paranoid_free(command); 1073 1074 asprintf(&command, 1224 1075 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1225 strcpy(nfs_client_netmask,1076 asprintf(&nfs_client_netmask, 1226 1077 call_program_and_get_last_line_of_output(command)); 1227 sprintf(command, 1078 paranoid_free(command); 1079 1080 asprintf(&command, 1228 1081 "route | egrep '^default' | awk '{printf $2}'"); 1229 strcpy(nfs_client_defgw,1082 asprintf(&nfs_client_defgw, 1230 1083 call_program_and_get_last_line_of_output(command)); 1231 sprintf(tmp, 1232 "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s", 1233 nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount); 1084 paranoid_free(command); 1085 1086 asprintf(&tmp, 1087 "nfs_client_ipaddr=%s; nfs_client_netmask=%s; nfs_server_ipaddr=%s; nfs_mount=%s; nfs_client_defgw=%s; ", 1088 nfs_client_ipaddr, nfs_client_netmask, nfs_server_ipaddr, nfs_mount, nfs_client_defgw); 1089 paranoid_free(nfs_mount); 1090 log_it(tmp); 1091 paranoid_free(tmp); 1092 1234 1093 if (strlen(nfs_dev) < 2) { 1235 1094 fatal_error 1236 1095 ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified."); 1237 1096 } 1238 sprintf(outfile, "%s/start-nfs", bkpinfo->tmpdir);1239 sprintf(tmp, "outfile = %s", outfile);1097 asprintf(&outfile, "%s/start-nfs", bkpinfo->tmpdir); 1098 asprintf(&tmp, "outfile = %s", outfile); 1240 1099 log_it(tmp); 1100 paranoid_free(tmp); 1101 1241 1102 if (!(fout = fopen(outfile, "w"))) { 1242 1103 fatal_error("Cannot store NFS config"); … … 1256 1117 // paranoid_system ("mkdir -p /var/cache/mondo-archive 2> /dev/null"); 1257 1118 1258 sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile); 1119 asprintf(&tmp, "cp -f %s /var/cache/mondo-archive", outfile); 1120 paranoid_free(outfile); 1121 1259 1122 run_program_and_log_output(tmp, FALSE); 1260 1261 sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir); 1123 paranoid_free(tmp); 1124 1125 asprintf(&tmp, "%s/NFS-DEV", bkpinfo->tmpdir); 1262 1126 write_one_liner_data_file(tmp, nfs_dev); 1263 1264 sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1127 paranoid_free(nfs_dev); 1128 paranoid_free(tmp); 1129 1130 asprintf(&tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1265 1131 write_one_liner_data_file(tmp, nfs_client_ipaddr); 1266 sprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1132 paranoid_free(nfs_client_ipaddr); 1133 paranoid_free(tmp); 1134 1135 asprintf(&tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1267 1136 write_one_liner_data_file(tmp, nfs_client_netmask); 1268 sprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1137 paranoid_free(nfs_client_netmask); 1138 paranoid_free(tmp); 1139 1140 asprintf(&tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1269 1141 write_one_liner_data_file(tmp, nfs_client_defgw); 1270 sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1142 paranoid_free(nfs_client_defgw); 1143 paranoid_free(tmp); 1144 1145 asprintf(&tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1271 1146 write_one_liner_data_file(tmp, nfs_server_ipaddr); 1272 sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1147 paranoid_free(nfs_server_ipaddr); 1148 paranoid_free(tmp); 1149 1150 asprintf(&tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1273 1151 write_one_liner_data_file(tmp, bkpinfo->nfs_mount); 1274 sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1152 paranoid_free(tmp); 1153 1154 asprintf(&tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1275 1155 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir); 1276 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1156 paranoid_free(tmp); 1157 1158 asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1277 1159 write_one_liner_data_file(tmp, bkpinfo->prefix); 1160 paranoid_free(tmp); 1161 1278 1162 log_it("Finished storing NFS configuration"); 1279 1163 } 1280 1281 1282 1283 1284 1164 1285 1165 … … 1304 1184 { 1305 1185 /*@ buffers *************** */ 1306 char tmp[MAX_STR_LEN];1186 char *tmp; 1307 1187 1308 1188 /*@ long long ************* */ … … 1329 1209 } 1330 1210 if (scratchLL <= 1) { 1331 sprintf(tmp,1211 asprintf(&tmp, 1332 1212 "Your backup will probably occupy a single %s. Maybe two.", 1333 1213 media_descriptor_string(bkpinfo->backup_media_type)); 1334 1214 } else { 1335 sprintf(tmp, "Your backup will occupy approximately %s media.",1215 asprintf(&tmp, "Your backup will occupy approximately %s media.", 1336 1216 number_to_text((int) (scratchLL + 1))); 1337 1217 } … … 1339 1219 log_to_screen(tmp); 1340 1220 } 1341 } 1342 1343 1344 /** 1345 * Get the last suffix of @p instr. 1346 * If @p instr was "httpd.log.gz", we would return "gz". 1347 * @param instr The filename to get the suffix of. 1348 * @return The suffix (without a dot), or "" if none. 1349 * @note The returned string points to static storage that will be overwritten with each call. 1350 */ 1351 char *sz_last_suffix(char *instr) 1352 { 1353 static char outstr[MAX_STR_LEN]; 1354 char *p; 1355 1356 p = strrchr(instr, '.'); 1357 if (!p) { 1358 outstr[0] = '\0'; 1359 } else { 1360 strcpy(outstr, p); 1361 } 1362 return (outstr); 1221 paranoid_free(tmp); 1222 return; 1363 1223 } 1364 1224 … … 1372 1232 bool is_this_file_compressed(char *filename) 1373 1233 { 1374 char do_not_compress_these[MAX_STR_LEN];1375 char tmp[MAX_STR_LEN];1234 char *do_not_compress_these; 1235 char *tmp; 1376 1236 char *p; 1377 1237 1378 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);1238 asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home); 1379 1239 if (!does_file_exist(tmp)) { 1240 paranoid_free(tmp); 1380 1241 return (FALSE); 1381 1242 } 1382 strcpy(do_not_compress_these, last_line_of_file(tmp)); 1243 paranoid_free(tmp); 1244 1245 asprintf(&do_not_compress_these, last_line_of_file(tmp)); 1383 1246 for (p = do_not_compress_these; p != NULL; p++) { 1384 strcpy(tmp, p);1247 asprintf(&tmp, p); 1385 1248 if (strchr(tmp, ' ')) { 1386 1249 *(strchr(tmp, ' ')) = '\0'; 1387 1250 } 1388 if (!strcmp(sz_last_suffix(filename), tmp)) { /*printf("MATCH\n"); */ 1251 if (!strcmp(strrchr(filename, '.'), tmp)) { 1252 paranoid_free(do_not_compress_these); 1253 paranoid_free(tmp); 1389 1254 return (TRUE); 1390 1255 } 1256 paranoid_free(tmp); 1257 1391 1258 if (!(p = strchr(p, ' '))) { 1392 1259 break; 1393 1260 } 1394 1261 } 1262 paranoid_free(do_not_compress_these); 1395 1263 return (FALSE); 1396 1264 } 1397 1398 1265 1399 1266 … … 1411 1278 1412 1279 1413 1414 1415 1280 /** 1416 1281 * Create a small script that mounts /boot, calls @c grub-install, and syncs the disks. … … 1424 1289 int retval = 0; 1425 1290 1426 malloc_string(tmp);1427 1291 if ((fout = fopen(outfile, "w"))) { 1428 1292 fprintf(fout, … … 1430 1294 paranoid_fclose(fout); 1431 1295 log_msg(2, "Created %s", outfile); 1432 sprintf(tmp, "chmod +x %s", outfile);1296 asprintf(&tmp, "chmod +x %s", outfile); 1433 1297 paranoid_system(tmp); 1298 paranoid_free(tmp); 1299 1434 1300 retval = 0; 1435 1301 } else { 1436 1302 retval = 1; 1437 1303 } 1438 paranoid_free(tmp);1439 1304 return (retval); 1440 1305 } 1441 1306 1442 1307 /* @} - end fileGroup */ 1308 1309 void paranoid_alloc(char *alloc, char *orig) 1310 { 1311 paranoid_free(alloc); 1312 asprintf(&alloc, orig); 1313 } 1314 -
trunk/mondo/mondo/common/libmondo-files.h
r59 r171 20 20 char *last_line_of_file(char *filename); 21 21 long long length_of_file(char *filename); 22 int make_checksum_list_file(char *filelist, char *cksumlist,23 char *comppath);24 22 int make_hole_for_file(char *outfile_fname); 25 23 void make_list_of_files_to_ignore(char *ignorefiles_fname, … … 51 49 int read_one_liner_data_file(char *fname, char *contents); 52 50 int mode_of_file(char *fname); 51 void paranoid_alloc(char *alloc, char *orig); -
trunk/mondo/mondo/common/libmondo-fork.c
r147 r171 37 37 FILE *fin; 38 38 39 int n = 0;39 size_t n = 0; 40 40 41 41 /*@******************************************************************** */ … … 192 192 int res; 193 193 int i; 194 int n = 0;194 size_t n = 0; 195 195 int len; 196 196 bool log_if_failure = FALSE; -
trunk/mondo/mondo/common/libmondo-mountlist.c
r146 r171 569 569 assert(flaws_str_C != NULL); 570 570 571 asprintf(&flaws_str, " ");571 asprintf(&flaws_str, " "); 572 572 573 573 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 583 583 log_it(tmp); 584 584 } else { 585 asprintf(&tmp, " ");585 asprintf(&tmp, " "); 586 586 // BERLIOS : tmp was NOT initialized ??? 587 587 if (!evaluate_drive_within_mountlist -
trunk/mondo/mondo/common/libmondo-stream.c
r147 r171 607 607 bkpinfo->internal_tape_block_size); 608 608 609 // start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);610 609 log_it("Opening IN tape"); 611 610 if (! -
trunk/mondo/mondo/common/libmondo-string.c
r122 r171 106 106 } 107 107 108 /* sout is allocated here and must be freed by the caller */ 108 109 109 110 inline void turn_wildcard_chars_into_literal_chars(char *sout, char *sin) 110 111 { 111 char *p, *q; 112 113 for (p = sin, q = sout; *p != '\0'; *(q++) = *(p++)) { 112 char *p; 113 char *q = NULL; 114 char *sav; 115 char r; 116 bool end = FALSE; 117 118 asprintf(&sav, sin); 119 p = sav; 120 while ((*p != '\0') && (! end)) { 114 121 if (strchr("[]*?", *p)) { 115 *(q++) = '\\'; 122 r = *p; // keep the wildcard char 123 *p = '\0'; // trunc the final string 124 p++; // continue on sav 125 // build the new string by recursion 126 turn_wildcard_chars_into_literal_chars(q,p); 127 asprintf(&sout, "%s\\%c%s", sav, r, q); 128 paranoid_free(q); 129 paranoid_free(sav); 130 end = TRUE; 116 131 } 117 } 118 *q = *p; // for the final '\0' 132 p++; 133 } 134 if (!end) { 135 sout = sav; 136 } 119 137 } 120 138 … … 345 363 break; 346 364 default: 347 asprintf(&outstr, "%s ", "BLK_UNKNOWN (%d)", marker);365 asprintf(&outstr, "%s (%d)", "BLK_UNKNOWN", marker); 348 366 break; 349 367 } … … 530 548 asprintf(&suffix, ".%s", s); 531 549 } else { 532 asprintf(&suffix, "%s", " ");550 asprintf(&suffix, "%s", " "); 533 551 } 534 552 asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, -
trunk/mondo/mondo/common/libmondo-tools-EXT.h
r94 r171 37 37 extern void mount_boot_if_necessary(void); 38 38 extern void unmount_boot_if_necessary(void); 39 extern void restart_autofs_if_necessary(void);40 39 extern void malloc_libmondo_global_strings(void); 41 40 extern void free_libmondo_global_strings(void); … … 49 48 extern void stop_magicdev_if_necessary(void); 50 49 extern void restart_magicdev_if_necessary(void); 51 extern void stop_autofs_if_necessary(void);52 extern void restart_autofs_if_necessary(void); -
trunk/mondo/mondo/common/libmondo-tools.c
r166 r171 605 605 log_it("isomnt: %s, %d", tmp, strlen(tmp)); 606 606 if (strlen(bkpinfo->isodir) < strlen(tmp)) { 607 asprintf(&iso_path, " ");607 asprintf(&iso_path, " "); 608 608 } else { 609 609 asprintf(&iso_path, "%s", bkpinfo->isodir + strlen(tmp)); … … 734 734 bkpinfo->manual_cd_tray = FALSE; 735 735 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 736 bkpinfo->media_device[0] = '\0';736 paranoid_free(bkpinfo->media_device); 737 737 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 738 738 bkpinfo->media_size[i] = -1; … … 1098 1098 1099 1099 /** 1100 * Whether we had to stop autofs (if so, restart it at end).1101 */1102 bool g_autofs_stopped = FALSE;1103 1104 /**1105 * Path to the autofs initscript ("" if none exists).1106 */1107 char g_autofs_exe[MAX_STR_LEN];1108 1109 /**1110 * Autofs initscript in Xandros Linux distribution.1111 */1112 #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"1113 1114 /**1115 * Autofs initscript in most Linux distributions.1116 */1117 #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"1118 1119 /**1120 * If autofs is mounted, stop it (restart at end).1121 */1122 void stop_autofs_if_necessary()1123 {1124 char *tmp;1125 1126 g_autofs_exe[0] = '\0';1127 if (does_file_exist(XANDROS_AUTOFS_FNAME)) {1128 strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);1129 } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {1130 strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);1131 }1132 1133 if (!g_autofs_exe[0]) {1134 log_msg(3, "No autofs detected.");1135 } else {1136 log_msg(3, "%s --- autofs detected", g_autofs_exe);1137 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);1138 asprintf(&tmp, "%s stop", g_autofs_exe);1139 if (run_program_and_log_output(tmp, 2)) {1140 log_it("Failed to stop autofs - I assume it wasn't running");1141 } else {1142 g_autofs_stopped = TRUE;1143 log_it("Stopped autofs OK");1144 }1145 paranoid_free(tmp);1146 }1147 }1148 1149 /**1150 * If autofs was stopped earlier, restart it.1151 */1152 void restart_autofs_if_necessary()1153 {1154 char *tmp;1155 1156 if (!g_autofs_stopped || !g_autofs_exe[0]) {1157 log_msg(3, "No autofs detected.");1158 return;1159 }1160 asprintf(&tmp, "%s start", g_autofs_exe);1161 if (run_program_and_log_output(tmp, 2)) {1162 log_it("Failed to start autofs");1163 } else {1164 g_autofs_stopped = FALSE;1165 log_it("Started autofs OK");1166 }1167 paranoid_free(tmp);1168 }1169 1170 1171 /**1172 1100 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1173 1101 */ … … 1214 1142 if (run_program_and_log_output(tmp1, 5)) { 1215 1143 paranoid_free(g_boot_mountpt); 1216 asprintf(&g_boot_mountpt, " ");1144 asprintf(&g_boot_mountpt, " "); 1217 1145 log_msg(1, "Plan B"); 1218 1146 if (!run_program_and_log_output("mount /boot", 5)) { -
trunk/mondo/mondo/common/libmondo-tools.h
r94 r171 42 42 void unmount_boot_if_necessary(void); 43 43 44 void restart_autofs_if_necessary(void);45 44 void malloc_libmondo_global_strings(void); 46 45 void free_libmondo_global_strings(void); … … 51 50 void stop_magicdev_if_necessary(void); 52 51 void restart_magicdev_if_necessary(void); 53 void stop_autofs_if_necessary(void);54 void restart_autofs_if_necessary(void); -
trunk/mondo/mondo/common/libmondo-verify.c
r127 r171 243 243 } 244 244 } else { 245 asprintf(&sz_exe, " ");245 asprintf(&sz_exe, " "); 246 246 } 247 247 … … 662 662 663 663 if (biggie_cksum[0] != '\0') { 664 asprintf(&orig_cksum, calc_checksum_of_file(biggie_fname));664 orig_cksum = calc_checksum_of_file(biggie_fname); 665 665 if (strcmp(biggie_cksum, orig_cksum)) { 666 666 asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, -
trunk/mondo/mondo/common/libmondo-verify.h
r59 r171 28 28 extern void fatal_error(char *); 29 29 extern int find_and_mount_actual_cd(struct s_bkpinfo *, char *); 30 extern int find_cdrom_device(char *,bool);30 extern char *find_cdrom_device(bool); 31 31 extern void finish(int); 32 32 extern int get_last_filelist_number(struct s_bkpinfo *); -
trunk/mondo/mondo/common/mondostructures.h
r122 r171 1 1 /*************************************************************************** 2 mondostructures.h - description 3 ------------------- 4 begin : Fri Apr 19 2002 5 copyright : (C) 2002 by Stan Benoit 6 email : troff@nakedsoul.org 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 11 * * 12 * This program is free software; you can redistribute it and/or modify * 13 * it under the terms of the GNU General Public License as published by * 14 * the Free Software Foundation; either version 2 of the License, or * 15 * (at your option) any later version. * 16 * * 17 ***************************************************************************/ 18 19 20 /* 2 * $Id$ 3 * 21 4 * @file 22 5 * The header file defining all of Mondo's structures. … … 310 293 * If backup_media_type is anything else, this should be blank. 311 294 */ 312 char media_device[MAX_STR_LEN / 4];295 char *media_device; 313 296 314 297 /** … … 340 323 * to take truncate_to_drive_name() of where_is_root_mounted(). 341 324 */ 342 char boot_device[MAX_STR_LEN / 4];325 char *boot_device; 343 326 344 327 /** … … 368 351 * This is a useful feature, but use at your own risk. 369 352 */ 370 char image_devs[MAX_STR_LEN / 4];353 char *image_devs; 371 354 372 355 /** … … 428 411 * If backup_media_type is anything else, this is ignored. 429 412 */ 430 char isodir[MAX_STR_LEN / 4];413 char *isodir; 431 414 432 415 /** … … 435 418 * If backup_media_type is anything else, this is ignored. 436 419 */ 437 char prefix[MAX_STR_LEN / 4];420 char *prefix; 438 421 439 422 /** … … 442 425 * As such, it needs to be at least as large as the largest CD/DVD/ISO. 443 426 */ 444 char scratchdir[MAX_STR_LEN / 4];427 char *scratchdir; 445 428 446 429 /** … … 450 433 * of space here. 451 434 */ 452 char tmpdir[MAX_STR_LEN / 4];435 char *tmpdir; 453 436 454 437 /** … … 496 479 * A command to call BEFORE making an ISO image. 497 480 */ 498 char call_before_iso[MAX_STR_LEN];481 char *call_before_iso; 499 482 500 483 /** … … 511 494 * A command to call AFTER making an ISO image. 512 495 */ 513 char call_after_iso[MAX_STR_LEN];496 char *call_after_iso; 514 497 515 498 /** … … 517 500 * included with Mindi. 518 501 */ 519 char kernel_path[MAX_STR_LEN];502 char *kernel_path; 520 503 521 504 /** … … 525 508 * address form. (Domain names will be resolved in post_param_configuration().) 526 509 */ 527 char nfs_mount[MAX_STR_LEN];510 char *nfs_mount; 528 511 529 512 /** … … 531 514 * the backups in. 532 515 */ 533 char nfs_remote_dir[MAX_STR_LEN];516 char *nfs_remote_dir; 534 517 535 518 /** … … 537 520 * after nuking the system. If "", do not use a post-nuke tarball. 538 521 */ 539 char postnuke_tarball[MAX_STR_LEN];522 char *postnuke_tarball; 540 523 541 524 /** -
trunk/mondo/mondo/common/my-stuff.h
r160 r171 1 1 /* $Id$ */ 2 2 3 #define AUX_VER "2. 05_berlios"3 #define AUX_VER "2.11" 4 4 #define HAVE_MALLOC 1 5 5 … … 19 19 /* Required for the use of getline, ... */ 20 20 #define __USE_GNU 21 #define _GNU_SOURCE 21 22 22 23 #include <stdio.h> … … 289 290 * Free @p x and set it to NULL. 290 291 */ 291 #define paranoid_free(x) {if ( x != NULL) free(x); x=NULL;}292 #define paranoid_free(x) {if ((x) != NULL) free(x); (x)=NULL;} 292 293 293 294 /** -
trunk/mondo/mondo/common/newt-specific.c
r146 r171 707 707 char *blurb; 708 708 char *original_contents; 709 int n = 0;709 size_t n = 0; 710 710 711 711 assert_string_is_neither_NULL_nor_zerolength(title); … … 791 791 printf("%s (%s or %s) --> ", p, button1, button2); 792 792 } 793 for (asprintf(&tmp, " ");793 for (asprintf(&tmp, " "); 794 794 strcmp(tmp, button1) && (strlen(button2) == 0 795 795 || strcmp(tmp, button2));) {
Note:
See TracChangeset
for help on using the changeset viewer.