- Timestamp:
- Dec 8, 2005, 5:20:29 PM (19 years ago)
- Location:
- trunk/mondo/mondo
- Files:
-
- 27 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));) { -
trunk/mondo/mondo/mondoarchive/main.c
r170 r171 1 /*************************************************************************** 2 main.c - description 3 ------------------- 4 begin : Fri Apr 19 16:40:35 EDT 2002 5 copyright : (C) 2002 by Stan Benoit 6 email : troff@nakedsoul.org 7 cvsid : $Id$ 8 ***************************************************************************/ 9 10 /*************************************************************************** 1 /* 2 * $Id$ 11 3 * * 12 4 * This program is free software; you can redistribute it and/or modify * … … 15 7 * (at your option) any later version. * 16 8 * * 17 ***************************************************************************/ 18 19 /** change log ****** MONDO-DEVEL 20 21 22 12/10 23 - disable stopping/starting of autofs 24 25 10/01 26 - update g_erase_tmpdir_and_scratchdir to delete user-specified tmpdir, scratchdir 27 28 06/19 29 - added AUX_VER 30 31 06/14/2004 32 - use mondorescue.iso, not mindi.iso 33 34 02/10/2004 35 - tell users where BusyBox's sources are 36 37 11/14/2003 38 - cleaned up logging at end# 39 40 10/23 41 - don't try to test-read tape ... That's already 42 handled by post_param_configuration() 43 44 10/19 45 - if your PATH var is too long, abort 46 47 09/23 48 - added some comments 49 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings() 50 and free_libmondo_global_strings() - which are in libmondo-tools.c 51 - better magicdev support 52 53 54 09/16 55 - delete /var/log/partimagehack-debug.log at start of main() 56 57 09/15 58 - added askbootloader 59 60 09/09 61 - if your tape is weird, I'll pause between backup and verify 62 - fixed silly bug in main() - re: say_at_end 63 64 01/01 - 08/31 65 - call 'dmesg -n1' at start, to shut the kernel logger up 66 - moved g_erase_tmpdir_and_scratchdir to common/newt-specific.c 67 - added 'don't panic' msg to start of logfile 68 - added 'nice(20)' to main() 69 - added lots of assert()'s and log_OS_error()'s 70 - clean-up (Hugo) 71 - make post_param_configuration() setup g_erase_tmpdir_and_scratchdir 72 - if --version then print & exit quickly 73 - re-run g_erase_tmpdir_and_scratchdir via system() at very end 74 75 Year: 2002 76 - if user goes root with 'su' instead of 'su -' then 77 workaround it by setting PATH correctly 78 - wipe mondoarchive.log at very beginning 79 - cleaned up code 80 - if changed.files.N exists then copy to changes.files for display 81 - run_program_and_log_output() now takes boolean operator to specify 82 whether it will log its activities in the event of _success_ 83 - added popup list of changed files 84 - removed 'beta-quality' warnings 85 - if kernel not found and mondo in graphics mode then popup and ask 86 for kernel path+filename 87 - fixed tmp[] 'too small' bug 88 - unmount and eject CD at end of verify cycle 89 - moved interactively_obtain...() to libmondo-stream.c 90 - wrote stuff to autodetect tape+cdrw+etc. 91 - renamed from main.c to mondo-archive.c 92 - fore+after warnings that this code is beta-quality 93 - abort if running from ramdisk 94 - remount floppy at end & unmount at start if Mandrake 95 - took out #debug stuff 96 - add 2> /dev/null to 'find' command 97 - add support for bkpinfo->nonbootable_backup 98 - add main function begin comment and debug conditional 99 compilation - Stan Benoit 100 - add debug statements to build a run tree. Stan Benoit 101 **** end change log **********/ 102 103 104 /** 105 * @file 9 *************************************************************************** 106 10 * The main file for mondoarchive. 107 11 */ … … 111 15 #include <pthread.h> 112 16 #endif 113 //#include <config.h>114 //#include "../../config.h"115 17 #include <stdio.h> 116 18 #include <stdlib.h> … … 141 43 extern char *g_tmpfs_mountpt; 142 44 extern char *g_erase_tmpdir_and_scratchdir; 143 extern char *g_cdrw_drive_is_here;144 static char *g_cdrom_drive_is_here = NULL;145 static char *g_dvd_drive_is_here = NULL;146 45 extern double g_kernel_version; 147 46 … … 211 110 ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2); 212 111 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted 213 // stop_autofs_if_necessary(); // for Xandros users214 112 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions 215 113 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way 216 114 } 217 218 115 219 116 … … 223 120 void distro_specific_kludges_at_end_of_mondoarchive() 224 121 { 225 // char tmp[500];226 122 log_msg(2, "Restarting magicdev if necessary"); 227 123 sync(); 228 124 restart_magicdev_if_necessary(); // for RH+Gnome users 229 125 230 log_msg(2, "Restarting autofs if necessary");231 sync();232 // restart_autofs_if_necessary(); // for Xandros users233 234 126 log_msg(2, "Restarting supermounts if necessary"); 235 127 sync(); … … 239 131 sync(); 240 132 unmount_boot_if_necessary(); // for Gentoo users 241 242 // log_msg( 2, "Cleaning up KDE desktop");243 // clean_up_KDE_desktop_if_necessary();244 133 } 245 246 247 /*-----------------------------------------------------------*/248 249 134 250 135 … … 257 142 struct s_bkpinfo *bkpinfo; 258 143 char *tmp; 259 int res, retval; 260 char *say_at_end; 144 int res = 0; 145 int retval = 0; 146 char *say_at_end = NULL; 261 147 262 148 /* Make sure I'm root; abort if not */ … … 277 163 278 164 malloc_libmondo_global_strings(); 279 malloc_string(tmp); 280 malloc_string(say_at_end); 281 282 res = 0; 283 retval = 0; 165 284 166 diffs = 0; 285 say_at_end[0] = '\0';286 167 unlink("/var/log/partimagehack-debug.log"); 287 168 printf("Initializing...\n"); … … 292 173 293 174 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */ 294 strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1); 295 tmp[MAX_STR_LEN - 1] = '\0'; 296 if (strlen(tmp) >= MAX_STR_LEN - 33) { 297 fatal_error 298 ("Your PATH environmental variable is too long. Please shorten it."); 299 } 300 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin"); 175 asprintf(&tmp, "/sbin:/usr/sbin:%s:/usr/local/sbin", getenv("PATH")); 301 176 setenv("PATH", tmp, 1); 177 paranoid_free(tmp); 302 178 303 179 /* Add the ARCH environment variable for ia64 purposes */ 304 strncpy(tmp, get_architecture(), MAX_STR_LEN - 1); 305 tmp[MAX_STR_LEN - 1] = '\0'; 306 setenv("ARCH", tmp, 1); 180 setenv("ARCH", get_architecture(), 1); 307 181 308 182 unlink(MONDO_LOGFILE); … … 339 213 if (argc == 4 && !strcmp(argv[1], "setfattr")) { 340 214 g_loglevel = 10; 341 // chdir("/tmp");342 215 g_text_mode = TRUE; 343 216 setup_newt_stuff(); … … 351 224 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 352 225 printf("in=%s; out=%s\n", argv[2], tmp); 226 paranoid_free(tmp); 353 227 finish(1); 354 228 } … … 368 242 if (argc == 4 && !strcmp(argv[1], "setfacl")) { 369 243 g_loglevel = 10; 370 // chdir("/tmp");371 244 g_text_mode = TRUE; 372 245 setup_newt_stuff(); … … 378 251 g_text_mode = TRUE; 379 252 setup_newt_stuff(); 380 if ( find_cdrw_device(tmp)) {253 if ((tmp = find_cdrw_device()) == NULL) { 381 254 printf("Failed to find CDR-RW drive\n"); 382 255 } else { 383 256 printf("CD-RW is at %s\n", tmp); 384 257 } 385 tmp[0] = '\0'; 386 if (find_cdrom_device(tmp, atoi(argv[2]))) { 258 paranoid_free(tmp); 259 260 if ((tmp = find_cdrom_device(FALSE)) == NULL) { 387 261 printf("Failed to find CD-ROM drive\n"); 388 262 } else { 389 263 printf("CD-ROM is at %s\n", tmp); 390 264 } 265 paranoid_free(tmp); 391 266 finish(0); 392 267 } … … 396 271 g_text_mode = TRUE; 397 272 setup_newt_stuff(); 398 if ( find_dvd_device(tmp, atoi(argv[2]))) {273 if ((tmp = find_dvd_device()) == NULL) { 399 274 printf("Failed to find DVD drive\n"); 400 275 } else { 401 276 printf("DVD is at %s\n", tmp); 402 277 } 278 paranoid_free(tmp); 403 279 finish(0); 404 280 } … … 451 327 log_to_screen 452 328 ("BusyBox's sources are available from http://www.busybox.net"); 453 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,454 bkpinfo->scratchdir);455 329 456 330 /* If we're meant to backup then backup */ 457 331 if (bkpinfo->backup_data) { 458 /*459 log_to_screen("INFERNAL PORPOISES");460 res = archive_this_fileset_with_star(bkpinfo, "/tmp/filelist.0", "/tmp/0.star.bz2", 0);461 log_to_screen("atfws returned %d", res);462 finish(0);463 */464 332 res = backup_data(bkpinfo); 465 333 retval += res; 466 334 if (res) { 467 strcat(say_at_end,335 asprintf(&say_at_end, 468 336 "Data archived. Please check the logs, just as a precaution. "); 469 337 } else { 470 strcat(say_at_end, "Data archived OK. ");338 asprintf(&say_at_end, "Data archived OK. "); 471 339 } 472 340 } … … 476 344 res = verify_data(bkpinfo); 477 345 if (res < 0) { 478 sprintf(tmp, "%d difference%c found.", -res,346 asprintf(&say_at_end, "%d difference%c found.", -res, 479 347 (-res != 1) ? 's' : ' '); 480 strcat(say_at_end, tmp);481 log_to_screen(tmp);482 348 res = 0; 483 349 } … … 485 351 } 486 352 487 /* Offer to write floppy disk images to physical disks */353 /* Offer to write floppy disk images to physical disks */ 488 354 if (bkpinfo->backup_data && !g_skip_floppies) { 489 355 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 490 356 retval += res; 491 // res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo); 492 // retval += res; 493 } 494 495 /* Report result of entire operation (success? errors?) */ 496 if (!retval) { 357 } 358 359 /* Report result of entire operation (success? errors?) */ 360 if (retval == 0) { 497 361 mvaddstr_and_log_it(g_currentY++, 0, 498 362 "Backup and/or verify ran to completion. Everything appears to be fine."); … … 523 387 } 524 388 log_to_screen(say_at_end); 525 sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 389 paranoid_free(say_at_end); 390 391 asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 526 392 run_program_and_log_output(tmp, TRUE); 393 paranoid_free(tmp); 394 395 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 396 bkpinfo->scratchdir); 527 397 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE); 528 398 … … 531 401 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 532 402 system("rm -Rf /tmp.mondo.* /mondo.scratch.*"); 533 if ( !retval) {403 if (retval == 0) { 534 404 printf("Mondoarchive ran OK.\n"); 535 405 } else { … … 542 412 system(g_erase_tmpdir_and_scratchdir); 543 413 free_libmondo_global_strings(); 544 paranoid_free(say_at_end);545 paranoid_free(tmp);546 414 paranoid_free(bkpinfo); 547 415 548 416 unlink("/tmp/filelist.full"); 549 417 unlink("/tmp/filelist.full.gz"); 550 551 if (!g_cdrom_drive_is_here) {552 log_msg(10, "FYI, g_cdrom_drive_is_here was never used");553 }554 if (!g_dvd_drive_is_here) {555 log_msg(10, "FYI, g_dvd_drive_is_here was never used");556 }557 418 558 419 run_program_and_log_output("date", 1); -
trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h
r59 r171 5 5 extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 6 6 extern int process_switches(struct s_bkpinfo *bkpinfo, 7 char flag_val[128][MAX_STR_LEN],7 char *flag_val[128], 8 8 bool flag_set[128]); 9 9 extern int retrieve_switches_from_command_line(int argc, char *argv[], 10 10 char 11 flag_val[128][MAX_STR_LEN],11 *flag_val[128], 12 12 bool flag_set[128]); 13 13 extern void help_screen(); -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r146 r171 1 1 /*************************************************************************** 2 mondo-cli.c 3 ------------------- 4 begin : Fri Apr 19 16:40:35 EDT 2002 5 copyright : (C) 2002 Mondo Hugo Rabson 6 email : Hugo Rabson <hugorabson@msn.com> 7 edited by : by Stan Benoit 4/2002 8 email : troff@nakedsoul.org 9 cvsid : $Id$ 10 ***************************************************************************/ 11 12 /*************************************************************************** 13 * * 14 * This program is free software; you can redistribute it and/or modify * 15 * it under the terms of the GNU General Public License as published by * 16 * the Free Software Foundation; either version 2 of the License, or * 17 * (at your option) any later version. * 18 * * 19 ***************************************************************************/ 20 21 /*************************************************************************** 22 UPDATE LOG 23 24 25 08/04 26 - if user specifies a dumb -T value, abort 27 28 07/22 29 - handle -Q sensibly (don't abort if only -Q supplied) 30 31 07/17 32 - better checking of NFS dir's validity 33 34 06/19 35 - added AUX_VER 36 37 04/17 38 - added '-b' support 39 04/03 40 - added star support 41 42 02/06 43 - fixed "Please give /dev entry" error msg 44 45 01/20/2004 46 - added 2.6.x-kernel "device = /dev/...." support to param reader 47 - better handling of SCSI and /dev entries 48 - touch /boot/boot.b if necessary 49 50 09/26/2003 51 - typo in command-line handling of 'r' 52 53 09/25 54 - added DVD write support 55 56 09/24 57 - if tape backup (-t) but user doesn't specify tape drive then 58 make an educated guess using find_tape_device_and_size() 59 60 09/18 61 - insist on partimagehack being present if -x found 62 63 09/16 64 - added support for multiple -I's and -E's in call to mondoarchive 65 - the '-D' flag doesn't take a value now 66 67 07/14 68 - fatal error if -E too short 69 70 05/14 71 - if 'n' and user doesn't have rights to write to output dir 72 then error out 73 74 05/05 75 - added Joshua Oreman's FreeBSD patches 76 77 05/04 78 - added Herman Kuster's multi-level bkp patch 79 80 05/02 81 - write errors to screen, not just to log 82 83 04/25 84 - added lots of assert()'s and log_OS_error()'s 85 86 04/21 87 - line 570 --- resolve boot device if softlink 88 89 04/08 90 - changed a bunch of fprintf(stderr,...)'s to log_it()'s 91 - fixed final / removal in retrieve_switches_from_command_line() 92 93 04/04 94 - added -e 95 96 03/15 97 - reject relative paths if -d flag (Alessandro Polverini) 98 99 01/02/2003 100 - added -J flag (to let user specify incoming filelist) 101 102 12/13/2002 103 - various strcpy() calls replaced with strncpy() calls 104 105 12/10 106 - added g_loglevel 107 108 11/25 109 - line 614 --- if commmand-line param ends in '/' then drop that '/' 110 111 11/19 112 - rewrote finish() to kill processes more softly 113 - if user calls with '-l RAW' then 114 115 09/01 - 09/30 116 - added -N to let user exclude all NFS-related mounts and devices 117 - run_program_and_log_output() now takes boolean operator to specify 118 whether it will log its activities in the event of _success_ 119 120 08/01 - 08/31 121 - if no device specified when backing up to tape streamer then assume /dev/st0 122 - abort if tape user specifies tape size (just for testing porpoises) 123 - tape users no longer need to specify tape size 124 - added some comments 125 - added bkpinfo->backup_media_type 126 - renamed from mondo-archive.c to mondo-cli.c 127 128 07/01 - 07/31 129 - better check for mkfs.vfat 130 - more sanity-checking for -d flag 131 - if isodir does not exist then abort 132 - removed "the rest are..." comment from log 133 - do not permit '-H' and '-t' in the same command line 134 - if not '-o' then insist on vfat-friendly kernel 135 136 06/01 - 06/30 137 - added signal-trapping 138 - added '-W' (won't make bootable CD or floppies) flag 139 - added missing 'j++' to -s switch's code 140 - expanded -s switch 141 - added -u switch 142 - if dvdrecord exists and cdrecord doesn't then use 143 dvdrecord instead of cdrecord 144 145 04/01 - 04/30 146 - if CD-ROM is supermounted then unmount, run, and remount 147 - replace MONDO_VERSION #define with VERSION from ../config.h 148 - if CD-ROM is mounted at start then abort 149 - improved homedir-locating code 150 - improved "backup will occupy N CD's" calculation a bit 151 - added -m (manual CD tray) flag 152 153 154 *******************************************************************/ 155 156 /** 157 * @file 2 * $Id$ 3 * 158 4 * Functions for handling command-line arguments passed to mondoarchive. 159 5 */ … … 180 26 extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks 181 27 extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ????? 182 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];183 28 extern char g_tmpfs_mountpt[MAX_STR_LEN]; 184 29 extern bool g_sigpipe; … … 245 90 /*@ buffers *************** */ 246 91 char *tmp; 247 char flag_val[128][MAX_STR_LEN];92 char *flag_val[128]; 248 93 bool flag_set[128]; 249 94 250 malloc_string(tmp);251 95 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 96 252 97 for (i = 0; i < 128; i++) { 253 flag_val[i] [0] = '\0';98 flag_val[i] = NULL; 254 99 flag_set[i] = FALSE; 255 100 } 256 // strcpy (bkpinfo->tmpdir, "/root/images/mondo");257 // strcpy (bkpinfo->scratchdir, "/home");258 101 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 259 102 bkpinfo->media_size[j] = 650; … … 275 118 for (i = 0; i < 128; i++) { 276 119 if (flag_set[i]) { 277 sprintf(tmp, "-%c %s", i, flag_val[i]);120 asprintf(&tmp, "-%c %s", i, flag_val[i]); 278 121 log_msg(3, tmp); 122 paranoid_free(tmp); 279 123 } 280 124 } 281 125 // } 282 sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);126 asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 283 127 paranoid_system(tmp); 284 sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 128 paranoid_free(tmp); 129 130 asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 285 131 paranoid_system(tmp); 132 paranoid_free(tmp); 133 286 134 sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", 287 135 random() % 32767); 288 136 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), 289 137 "/mondo.scratch.%ld", random() % 32767); 290 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 138 139 asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 291 140 paranoid_system(tmp); 292 sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir); 141 paranoid_free(tmp); 142 143 asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir); 293 144 paranoid_system(tmp); 145 paranoid_free(tmp); 146 294 147 if (bkpinfo->nfs_mount[0] != '\0') { 295 148 store_nfs_config(bkpinfo); 296 149 } 297 paranoid_free(tmp);298 150 return (retval); 299 151 } 300 301 302 152 303 153 … … 312 162 { 313 163 int j; 314 char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN]; 164 char *tmp; 165 char *p; 166 char *q; 167 char *comment; 315 168 316 169 assert(bkpinfo != NULL); … … 320 173 for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ','); 321 174 j++, p = strchr(p, ',') + 1) { 322 strncpy(tmp, p, MAX_STR_LEN); 323 *(strchr(tmp, ',')) = '\0'; 175 asprintf(&tmp, p); 176 q = strchr(tmp, ','); 177 if (q != NULL) { 178 *q = '\0'; 179 } 324 180 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp); 325 sprintf(comment, "media_size[%d] = %ld", j, 181 paranoid_free(tmp); 182 183 asprintf(&comment, "media_size[%d] = %ld", j, 326 184 bkpinfo->media_size[j]); 327 185 log_msg(3, comment); 186 paranoid_free(comment); 328 187 } 329 188 for (; j <= MAX_NOOF_MEDIA; j++) { 330 189 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p); 331 190 } 332 // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];333 191 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 334 192 if (bkpinfo->media_size[j] <= 0) { … … 339 197 return (0); 340 198 } 341 342 199 343 200 … … 354 211 int 355 212 process_switches(struct s_bkpinfo *bkpinfo, 356 char flag_val[128][MAX_STR_LEN], bool flag_set[128])213 char *flag_val[128], bool flag_set[128]) 357 214 { 358 215 … … 364 221 /*@ buffers ** */ 365 222 char *tmp; 223 char *tmp2; 366 224 char *psz; 367 225 … … 374 232 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 375 233 376 /* compulsory */234 /* compulsory */ 377 235 i = flag_set['c'] + flag_set['i'] + flag_set['n'] + 378 236 flag_set['t'] + flag_set['u'] + flag_set['r'] + … … 502 360 ("You must use -L with -C. Therefore I am setting it for you."); 503 361 flag_set['L'] = 1; 504 flag_val['L'] [0] = '\0';362 flag_val['L'] = NULL; 505 363 } 506 364 } else { 507 365 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 508 366 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 509 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );510 367 if (flag_set['c']) { 511 368 bkpinfo->cdrw_speed = atoi(flag_val['c']); … … 546 403 } 547 404 if (!flag_set['d']) { 548 if ( !find_dvd_device(flag_val['d'], FALSE)) {405 if ((flag_val['d'] = find_dvd_device()) != NULL) { 549 406 flag_set['d'] = TRUE; 550 407 log_to_screen("I guess DVD drive is at %s", flag_val['d']); … … 564 421 } 565 422 if (!flag_set['s']) { 566 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 567 strcat(flag_val['s'], "m"); 423 asprintf(&flag_val['s'], "%dm", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 568 424 log_to_screen 569 425 ("You did not specify a size (-s) for DVD. I'm guessing %s.", … … 571 427 flag_set['s'] = 1; 572 428 } 573 /*574 if (flag_set['Z']) {575 bkpinfo->blank_dvd_first = TRUE;576 }577 */578 429 } 579 430 … … 612 463 } 613 464 if (flag_set['n']) { 614 strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN); 465 asprintf(&tmp, flag_val['n']); 466 bkpinfo->nfs_mount = tmp; 615 467 if (!flag_set['d']) { 616 strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); 468 asprintf(&tmp, "/"); 469 bkpinfo->nfs_remote_dir = tmp; 617 470 } 618 471 asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 619 472 bkpinfo->nfs_mount); 620 strncpy(bkpinfo->isodir, 621 call_program_and_get_last_line_of_output(tmp), 622 MAX_STR_LEN / 4); 473 asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp)); 474 bkpinfo->isodir = tmp2; 623 475 paranoid_free(tmp); 624 476 … … 714 566 } 715 567 if (flag_set['x']) { 716 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4); 568 asprintf(&tmp, flag_val['x']); 569 bkpinfo->image_devs = tmp; 717 570 if (run_program_and_log_output("which partimagehack", 2)) { 718 571 fatal_error("Please install partimagehack RPM/tarball."); … … 723 576 } 724 577 if (flag_set['k']) { 725 strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 726 if (!strcmp(bkpinfo->kernel_path, "failsafe")) { 727 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 728 } 729 if (strcmp(bkpinfo->kernel_path, "FAILSAFE") 730 && !does_file_exist(bkpinfo->kernel_path)) { 731 retval++; 732 asprintf(&tmp, 578 if (strcasecmp(flag_val['k'], "FAILSAFE")) { 579 asprintf(&tmp, "FAILSAFE"); 580 bkpinfo->kernel_path = tmp; 581 582 if (!does_file_exist(bkpinfo->kernel_path)) { 583 retval++; 584 asprintf(&tmp, 733 585 "You specified kernel '%s', which does not exist\n", 734 586 bkpinfo->kernel_path); 735 log_to_screen(tmp); 736 paranoid_free(tmp); 587 log_to_screen(tmp); 588 paranoid_free(tmp); 589 } 590 } else { 591 asprintf(&tmp, flag_val['k']); 592 bkpinfo->kernel_path = tmp; 737 593 } 738 594 } 739 595 if (flag_set['p']) { 740 strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4); 596 asprintf(&tmp, bkpinfo->prefix); 597 bkpinfo->prefix = tmp; 741 598 } 742 599 … … 744 601 if (flag_set['d']) { /* backup directory (if ISO/NFS) */ 745 602 if (flag_set['i']) { 746 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); 603 asprintf(&tmp, flag_val['d']); 604 bkpinfo->isodir = tmp; 747 605 asprintf(&tmp, "ls -l %s", bkpinfo->isodir); 748 606 if (run_program_and_log_output(tmp, FALSE)) { … … 752 610 paranoid_free(tmp); 753 611 } else if (flag_set['n']) { 754 strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 612 asprintf(&tmp, flag_val['d']); 613 bkpinfo->nfs_remote_dir = tmp; 755 614 } else { /* backup device (if tape/CD-R/CD-RW) */ 756 615 757 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);616 paranoid_alloc(bkpinfo->media_device, flag_val['d']); 758 617 } 759 618 } … … 782 641 log_to_screen("User opted to cancel."); 783 642 } 784 } else if (find_cdrw_device(bkpinfo->media_device)) { 643 } else if ((tmp = find_cdrw_device()) == NULL) { 644 paranoid_free(bkpinfo->media_device); 645 bkpinfo->media_device = tmp; 785 646 retval++; 786 647 log_to_screen … … 788 649 } else { 789 650 flag_set['d'] = TRUE; 790 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);651 asprintf(&flag_val['d'], bkpinfo->media_device); 791 652 } 792 653 } … … 805 666 } 806 667 if (flag_set['S']) { 807 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],668 asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'], 808 669 random() % 32768); 670 bkpinfo->scratchdir = tmp; 809 671 } 810 672 if (flag_set['T']) { 811 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],673 asprintf(&tmp, "%s/tmp.mondo.%ld", flag_val['T'], 812 674 random() % 32768); 675 bkpinfo->tmpdir = tmp; 813 676 asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']); 814 677 if (run_program_and_log_output(tmp, 1)) { … … 831 694 } 832 695 if (flag_set['A']) { 833 strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 696 asprintf(&tmp, flag_val['A']); 697 bkpinfo->call_after_iso = tmp; 834 698 } 835 699 if (flag_set['B']) { 836 strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 700 asprintf(&tmp, flag_val['B']); 701 bkpinfo->call_before_iso = tmp; 837 702 } 838 703 if (flag_set['F']) { … … 864 729 if (flag_set['f']) { 865 730 tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']); 866 strncpy(bkpinfo->boot_device, tmp, 867 MAX_STR_LEN / 4); 731 bkpinfo->boot_device = tmp; 868 732 } 869 733 if (flag_set['Q']) { … … 880 744 881 745 if (flag_set['P']) { 882 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 746 asprintf(&tmp, flag_val['P']); 747 bkpinfo->postnuke_tarball = tmp; 883 748 } 884 749 if (flag_set['L']) { … … 894 759 && 895 760 !run_program_and_log_output 896 (" cat /etc/issue.net | grep -i suse| grep 64", TRUE)) {761 ("grep -i suse /etc/issue.net | grep 64", TRUE)) { 897 762 bkpinfo->make_cd_use_lilo = TRUE; 898 763 log_to_screen … … 963 828 int 964 829 retrieve_switches_from_command_line(int argc, char *argv[], 965 char flag_val[128][MAX_STR_LEN],830 char *flag_val[128], 966 831 bool flag_set[128]) 967 832 { 968 833 /*@ ints ** */ 969 834 int opt = 0; 970 char tmp[MAX_STR_LEN];835 char *tmp; 971 836 int i = 0; 972 837 int len; … … 979 844 980 845 for (i = 0; i < 128; i++) { 981 flag_val[i] [0] = '\0';846 flag_val[i] = NULL; 982 847 flag_set[i] = FALSE; 983 848 } … … 992 857 if (flag_set[optopt]) { 993 858 bad_switches = TRUE; 994 sprintf(tmp, "Switch -%c previously defined as %s\n", opt,859 asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, 995 860 flag_val[i]); 996 861 log_to_screen(tmp); 862 paranoid_free(tmp); 997 863 } else { 998 864 flag_set[opt] = TRUE; … … 1008 874 if (strchr(flag_val[opt], '/') 1009 875 && flag_val[opt][0] != '/') { 1010 sprintf(tmp,876 asprintf(&tmp, 1011 877 "-%c flag --- must be absolute path --- '%s' isn't absolute", 1012 878 opt, flag_val[opt]); 1013 879 log_to_screen(tmp); 880 paranoid_free(tmp); 1014 881 bad_switches = TRUE; 1015 882 } 1016 883 } 1017 strcpy(flag_val[opt], optarg);884 asprintf(&flag_val[opt], optarg); 1018 885 } 1019 886 } … … 1022 889 for (i = optind; i < argc; i++) { 1023 890 bad_switches = TRUE; 1024 sprintf(tmp, "Invalid arg -- %s\n", argv[i]);891 asprintf(&tmp, "Invalid arg -- %s\n", argv[i]); 1025 892 log_to_screen(tmp); 893 paranoid_free(tmp); 1026 894 } 1027 895 return (bad_switches); … … 1047 915 void terminate_daemon(int sig) 1048 916 { 1049 char tmp[64]; 1050 char tmp2[MAX_STR_LEN]; 1051 // char command[512]; 1052 // pid_t pid; 917 char *tmp; 918 char *tmp2; 1053 919 1054 920 switch (sig) { 1055 921 case SIGINT: 1056 sprintf(tmp, "SIGINT");1057 strcpy(tmp2, "You interrupted me :-)");922 asprintf(&tmp, "SIGINT signal received from OS"); 923 asprintf(&tmp2, "You interrupted me :-)"); 1058 924 break; 1059 925 case SIGKILL: 1060 sprintf(tmp, "SIGKILL");1061 strcpy(tmp2,926 asprintf(&tmp, "SIGKILL signal received from OS"); 927 asprintf(&tmp2, 1062 928 "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1063 929 break; 1064 930 case SIGTERM: 1065 sprintf(tmp, "SIGTERM");1066 strcpy(tmp2, "Got terminate signal");931 asprintf(&tmp, "SIGTERM signal received from OS"); 932 asprintf(&tmp2, "Got terminate signal"); 1067 933 break; 1068 934 case SIGHUP: 1069 sprintf(tmp, "SIGHUP");1070 strcpy(tmp2, "Hangup on line");935 asprintf(&tmp, "SIGHUP signal received from OS"); 936 asprintf(&tmp2, "Hangup on line"); 1071 937 break; 1072 938 case SIGSEGV: 1073 sprintf(tmp, "SIGSEGV");1074 strcpy(tmp2,939 asprintf(&tmp, "SIGSEGV signal received from OS"); 940 asprintf(&tmp2, 1075 941 "Internal programming error. Please send a backtrace as well as your log."); 1076 942 break; 1077 943 case SIGPIPE: 1078 sprintf(tmp, "SIGPIPE");1079 strcpy(tmp2, "Pipe was broken");944 asprintf(&tmp, "SIGPIPE signal received from OS"); 945 asprintf(&tmp2, "Pipe was broken"); 1080 946 break; 1081 947 case SIGABRT: 1082 sprintf(tmp, "SIGABRT");1083 sprintf(tmp2,948 asprintf(&tmp, "SIGABRT signal received from OS"); 949 asprintf(&tmp2, 1084 950 "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1085 951 break; 1086 952 default: 1087 sprintf(tmp, "(Unknown)");1088 }1089 1090 strcat(tmp, " signal received from OS"); 953 asprintf(&tmp, "(Unknown)"); 954 asprintf(&tmp2, "(Unknown)"); 955 } 956 1091 957 log_to_screen(tmp); 1092 958 log_to_screen(tmp2); 959 paranoid_free(tmp); 960 paranoid_free(tmp2); 1093 961 if (sig == SIGABRT) { 1094 962 sleep(10); … … 1099 967 finish(254); // just in case 1100 968 } 1101 1102 1103 969 1104 970 … … 1122 988 } 1123 989 } 1124 1125 1126 990 1127 991 -
trunk/mondo/mondo/mondoarchive/mondo-cli.h
r59 r171 7 7 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 8 8 int process_switches(struct s_bkpinfo *bkpinfo, 9 char flag_val[128][MAX_STR_LEN], bool flag_set[128]);9 char *flag_val[128], bool flag_set[128]); 10 10 int retrieve_switches_from_command_line(int argc, char *argv[], 11 char flag_val[128][MAX_STR_LEN],11 char *flag_val[128], 12 12 bool flag_set[128]); 13 13 void help_screen(); -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r146 r171 1292 1292 } 1293 1293 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1294 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device); 1295 if (!bkpinfo->media_device[0]) { 1294 if (bkpinfo->media_device == NULL) { 1296 1295 log_msg(2, "Warning - failed to find media dev"); 1296 } else { 1297 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device); 1297 1298 } 1298 1299 … … 1330 1331 } 1331 1332 run_program_and_log_output("umount " MNT_CDROM, FALSE); 1332 if ( !bkpinfo->please_dont_eject) {1333 if ((!bkpinfo->please_dont_eject) && (bkpinfo->media_device != NULL)) { 1333 1334 eject_device(bkpinfo->media_device); 1334 1335 } … … 3100 3101 unlink(datadisks_fname); 3101 3102 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3102 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device);3103 retval = load_mountlist(&the_mountlist, g_mountlist_fname); 3103 3104 3104 3105 -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
r142 r171 684 684 685 685 /** needs malloc **/ 686 char *dir, *command ;686 char *dir, *command, *tmp; 687 687 688 688 assert(bkpinfo != NULL); … … 700 700 if (bkpinfo->disaster_recovery 701 701 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 702 strcpy(bkpinfo->media_device,702 asprintf(&tmp, 703 703 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 704 } else { 705 find_cdrom_device(bkpinfo->media_device, FALSE); 704 paranoid_free(bkpinfo->media_device); 705 bkpinfo->media_device = tmp; 706 } else { 707 paranoid_free(bkpinfo->media_device); 708 bkpinfo->media_device = find_cdrom_device(FALSE); 706 709 } 707 710 res = verify_tape_backups(bkpinfo); -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r149 r171 202 202 * allocate memory regions. test and set -sab 16 feb 2003 * 203 203 ************************************************************************/ 204 char *incoming_ptr; 205 char *question_ptr; 206 207 char incoming[MAX_STR_LEN]; 208 char question[MAX_STR_LEN]; 204 char *incoming; 205 char *question; 206 207 size_t n = 0; 209 208 210 209 assert_string_is_neither_NULL_nor_zerolength(infname); 211 210 assert_string_is_neither_NULL_nor_zerolength(outfname); 212 211 213 incoming_ptr = malloc(sizeof(incoming));214 if (incoming_ptr == NULL) {215 fprintf(stderr, "Out of Memory\n");216 exit(EXIT_FAILURE);217 }218 219 question_ptr = malloc(sizeof(question));220 if (question_ptr == NULL) {221 fprintf(stderr, "Out of Memory\n");222 exit(EXIT_FAILURE);223 }224 225 memset(incoming_ptr, '\0', sizeof(incoming));226 memset(question_ptr, '\0', sizeof(question));227 228 229 230 212 if (!(fin = fopen(infname, "r"))) { 231 213 fatal_error("Cannot openin infname"); … … 234 216 fatal_error("Cannot openin outfname"); 235 217 } 236 for ( fgets(incoming_ptr, MAX_STR_LEN, fin);237 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {238 strip_spaces(incoming _ptr);218 for (getline(&incoming, &n, fin); 219 !feof(fin); getline(&incoming, &n, fin)) { 220 strip_spaces(incoming); 239 221 240 222 if (incoming[0] == '\0') { … … 242 224 } 243 225 244 sprintf(question_ptr,245 "Should I restore the image of %s ?", incoming _ptr);246 247 if (ask_me_yes_or_no(question _ptr)) {248 fprintf(fout, "%s\n", incoming _ptr);226 asprintf(&question, 227 "Should I restore the image of %s ?", incoming); 228 229 if (ask_me_yes_or_no(question)) { 230 fprintf(fout, "%s\n", incoming); 249 231 } 250 232 } 251 233 252 234 /*** free memory ***********/ 253 paranoid_free(incoming_ptr); 254 incoming_ptr = NULL; 255 paranoid_free(question_ptr); 256 question_ptr = NULL; 235 paranoid_free(incoming); 236 paranoid_free(question); 257 237 258 238 … … 705 685 int mount_cdrom(struct s_bkpinfo *bkpinfo) 706 686 { 707 char *mount_cmd ;687 char *mount_cmd, *tmp; 708 688 int i, res; 709 689 #ifdef __FreeBSD__ … … 773 753 if (bkpinfo->disaster_recovery 774 754 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 775 strcpy(bkpinfo->media_device, 755 paranoid_free(bkpinfo->media_device); 756 asprintf(&tmp, 776 757 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 758 bkpinfo->media_device = tmp; 777 759 } else { 778 find_cdrom_device(bkpinfo->media_device, TRUE); 760 paranoid_free(bkpinfo->media_device); 761 bkpinfo->media_device = find_cdrom_device(TRUE); 779 762 } 780 763 … … 1061 1044 if (bkpinfo->disaster_recovery) { 1062 1045 if (bkpinfo->backup_media_type == cdstream) { 1063 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1064 // bkpinfo->media_size[0] = -1; 1046 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1065 1047 bkpinfo->media_size[0] = 1999 * 1024; 1066 1048 bkpinfo->media_size[1] = 650; /* good guess */ 1067 1049 } else if (bkpinfo->backup_media_type == tape 1068 1050 || bkpinfo->backup_media_type == udev) { 1069 if (read_cfg_var(cfg_file, "media-dev", value)) {1051 if (read_cfg_var(cfg_file, "media-dev", bkpinfo->media_device)) { 1070 1052 fatal_error("Cannot get tape device name from cfg file"); 1071 1053 } 1072 strcpy(bkpinfo->media_device, value);1073 1054 read_cfg_var(cfg_file, "media-size", value); 1074 1055 bkpinfo->media_size[1] = atol(value); … … 1077 1058 log_msg(2, tmp); 1078 1059 } else { 1079 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */1060 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1080 1061 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1081 1062 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ … … 1200 1181 "Unable to mount isodir. Perhaps this is really a CD backup?"); 1201 1182 bkpinfo->backup_media_type = cdr; 1202 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */1183 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1203 1184 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1204 1185 if (mount_cdrom(bkpinfo)) { … … 2387 2368 char *mounted_cfgf_path; 2388 2369 char *tmp; 2370 char *sav; 2389 2371 char *mountpt; 2390 2372 char *ramdisk_fname; … … 2491 2473 2492 2474 if (strlen(bkpinfo->media_device) == 0) { 2493 strcpy(bkpinfo->media_device, "/dev/st0");2494 log_msg(2, "media_device is blank; assuming %s" );2495 } 2496 strcpy(tmp,bkpinfo->media_device);2475 paranoid_alloc(bkpinfo->media_device, "/dev/st0"); 2476 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device); 2477 } 2478 asprintf(&sav,bkpinfo->media_device); 2497 2479 if (extract_cfg_file_and_mountlist_from_tape_dev 2498 2480 (bkpinfo->media_device)) { 2499 strcpy(bkpinfo->media_device, "/dev/st0");2481 paranoid_alloc(bkpinfo->media_device, "/dev/st0"); 2500 2482 if (extract_cfg_file_and_mountlist_from_tape_dev 2501 2483 (bkpinfo->media_device)) { 2502 strcpy(bkpinfo->media_device, "/dev/osst0");2484 paranoid_alloc(bkpinfo->media_device, "/dev/osst0"); 2503 2485 if (extract_cfg_file_and_mountlist_from_tape_dev 2504 2486 (bkpinfo->media_device)) { 2505 strcpy(bkpinfo->media_device, "/dev/ht0");2487 paranoid_alloc(bkpinfo->media_device, "/dev/ht0"); 2506 2488 if (extract_cfg_file_and_mountlist_from_tape_dev 2507 2489 (bkpinfo->media_device)) { 2508 2490 log_msg(3, 2509 2491 "I tried lots of devices but none worked."); 2510 strcpy(bkpinfo->media_device, tmp);2492 paranoid_alloc(bkpinfo->media_device, sav); 2511 2493 } 2512 2494 } 2513 2495 } 2514 2496 } 2497 paranoid_free(sav); 2515 2498 2516 2499 if (!does_file_exist("tmp/mondo-restore.cfg")) {
Note:
See TracChangeset
for help on using the changeset viewer.