- Timestamp:
- Dec 1, 2005, 10:00:14 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-devices-EXT.h
r59 r146 47 47 extern int eject_device(char *); 48 48 49 extern char *list_of_NFS_devices_and_mounts();50 49 extern char *list_of_NFS_mounts_only(void); 51 50 -
trunk/mondo/mondo/common/libmondo-devices.c
r133 r146 19 19 #include "libmondo-stream-EXT.h" 20 20 21 #include <sys/ioctl.h> 21 22 #include <sys/types.h> 22 23 #ifdef __FreeBSD__ … … 104 105 bool is_this_a_ramdisk = FALSE; 105 106 106 malloc_string(tmp); 107 malloc_string(comment); 108 strcpy(tmp, where_is_root_mounted()); 109 sprintf(comment, "root is mounted at %s\n", tmp); 107 asprintf(&tmp, where_is_root_mounted()); 108 asprintf(&comment, "root is mounted at %s\n", tmp); 110 109 log_msg(0, comment); 110 paranoid_free(comment); 111 111 112 log_msg(0, 112 113 "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", … … 127 128 } 128 129 #endif 130 paranoid_free(tmp); 129 131 130 132 if (is_this_a_ramdisk) { … … 139 141 is_this_a_ramdisk = TRUE; 140 142 } 141 paranoid_free(tmp);142 paranoid_free(comment);143 143 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); 144 144 return (is_this_a_ramdisk); 145 145 } 146 147 148 149 146 150 147 … … 157 154 static char *bkptype_to_string(t_bkptype bt) 158 155 { 159 static char output[MAX_STR_LEN / 4]; 156 static char *output = NULL; 157 158 paranoid_free(output); 159 160 160 switch (bt) { 161 161 case none: 162 strcpy(output, "none");162 asprintf(&output, "none"); 163 163 break; 164 164 case iso: 165 strcpy(output, "iso");165 asprintf(&output, "iso"); 166 166 break; 167 167 case cdr: 168 strcpy(output, "cdr");168 asprintf(&output, "cdr"); 169 169 break; 170 170 case cdrw: 171 strcpy(output, "cdrw");171 asprintf(&output, "cdrw"); 172 172 break; 173 173 case cdstream: 174 strcpy(output, "cdstream");174 asprintf(&output, "cdstream"); 175 175 break; 176 176 case nfs: 177 strcpy(output, "nfs");177 asprintf(&output, "nfs"); 178 178 break; 179 179 case tape: 180 strcpy(output, "tape");180 asprintf(&output, "tape"); 181 181 break; 182 182 case udev: 183 strcpy(output, "udev");183 asprintf(&output, "udev"); 184 184 break; 185 185 default: 186 strcpy(output, "default"); 187 } 188 return (output); 189 } 190 186 asprintf(&output, "default"); 187 } 188 return (&output); 189 } 191 190 192 191 … … 205 204 int res1 = 0, res2 = 0; 206 205 207 malloc_string(command);208 209 206 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 210 207 && g_backup_media_type != udev) { 211 sprintf(command, "mt -f %s offline", dev);208 asprintf(&command, "mt -f %s offline", dev); 212 209 res1 = run_program_and_log_output(command, 1); 210 paranoid_free(command); 213 211 } else { 214 212 res1 = 0; … … 217 215 #ifdef __FreeBSD__ 218 216 if (strstr(dev, "acd")) { 219 sprintf(command, "cdcontrol -f %s eject", dev);220 } else { 221 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",217 asprintf(&command, "cdcontrol -f %s eject", dev); 218 } else { 219 asprintf(&command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 222 220 dev); 223 221 } 224 222 #else 225 sprintf(command, "eject %s", dev);223 asprintf(&command, "eject %s", dev); 226 224 #endif 227 225 … … 236 234 } 237 235 236 238 237 /** 239 238 * Load (inject) the tray of the specified CD device. … … 246 245 int i; 247 246 248 malloc_string(command);249 250 251 247 #ifdef __FreeBSD__ 252 248 if (strstr(dev, "acd")) { 253 sprintf(command, "cdcontrol -f %s close", dev);254 } else { 255 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",249 asprintf(&command, "cdcontrol -f %s close", dev); 250 } else { 251 asprintf(&command, "camcontrol load `echo %s | sed 's|/dev/||'`", 256 252 dev); 257 253 } 258 254 #else 259 sprintf(command, "eject -t %s", dev);255 asprintf(&command, "eject -t %s", dev); 260 256 #endif 261 257 i = run_program_and_log_output(command, FALSE); … … 275 271 /*@ buffers *********************************************************** */ 276 272 char *tmp; 277 278 malloc_string(tmp); 273 bool ret; 274 279 275 assert_string_is_neither_NULL_nor_zerolength(device); 280 276 281 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device); 282 277 asprintf(&tmp, "ls %s > /dev/null 2> /dev/null", device); 278 279 if (system(tmp)) { 280 ret = FALSE; 281 } else { 282 ret = TRUE; 283 } 283 284 paranoid_free(tmp); 284 if (system(tmp)) { 285 return (FALSE); 286 } else { 287 return (TRUE); 288 } 285 return(ret); 289 286 } 290 287 … … 317 314 /*@ buffers **************************************************** */ 318 315 char *program; 319 char *incoming ;316 char *incoming = NULL; 320 317 char *searchstr; 321 char *tmp;322 318 323 319 /*@ ints ******************************************************* */ 324 320 int res = 0; 321 int n = 0; 325 322 326 323 /*@ pointers *************************************************** */ … … 332 329 assert(partno >= 0 && partno < 999); 333 330 334 malloc_string(program);335 malloc_string(incoming);336 331 malloc_string(searchstr); 337 malloc_string(tmp);338 332 339 333 #ifdef __FreeBSD__ 340 334 // We assume here that this is running from mondorestore. (It is.) 341 sprintf(program, "ls %s >/dev/null 2>&1", drive, 342 build_partition_name(tmp, drive, partno)); 343 return system(program); 344 #else 345 tmp[0] = '\0'; 346 #endif 347 348 sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 335 asprintf(&program, "ls %s >/dev/null 2>&1", drive); 336 res = system(program); 337 paranoid_free(program); 338 return(res); 339 #endif 340 341 asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive); 349 342 fin = popen(program, "r"); 350 343 if (!fin) { 351 344 log_it("program=%s", program); 352 345 log_OS_error("Cannot popen-in program"); 346 paranoid_free(program); 353 347 return (0); 354 348 } 349 paranoid_free(program); 350 355 351 (void) build_partition_name(searchstr, drive, partno); 356 352 strcat(searchstr, " "); 357 for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) {353 for (res = 0; !res && getline(&incoming, &n, fin);) { 358 354 if (strstr(incoming, searchstr)) { 359 355 res = 1; 360 356 } 361 357 } 358 paranoid_free(incoming); 359 362 360 if (pclose(fin)) { 363 361 log_OS_error("Cannot pclose fin"); 364 362 } 365 paranoid_free(program);366 paranoid_free(incoming);367 363 paranoid_free(searchstr); 368 paranoid_free(tmp);369 364 return (res); 370 365 } 371 372 373 374 366 375 367 … … 386 378 387 379 /*@ end vars *************************************************** */ 388 int i;380 int ret; 389 381 390 382 assert_string_is_neither_NULL_nor_zerolength(dev); 391 383 assert_string_is_neither_NULL_nor_zerolength(str); 392 384 393 malloc_string(command); 394 sprintf(command, 385 asprintf(&command, 395 386 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 396 387 dev, str); 397 i= system(command);388 ret = system(command); 398 389 paranoid_free(command); 399 if ( i) {390 if (ret) { 400 391 return (FALSE); 401 392 } else { … … 403 394 } 404 395 } 396 405 397 406 398 /** … … 416 408 char *command; 417 409 /*@ end vars *************************************************** */ 418 int i; 419 420 malloc_string(command); 421 sprintf(command, 410 int ret; 411 412 asprintf(&command, 422 413 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 423 414 dev, n, str); 424 i= system(command);415 ret = system(command); 425 416 paranoid_free(command); 426 if (i) { 417 418 if (ret) { 427 419 return (FALSE); 428 420 } else { … … 430 422 } 431 423 } 432 433 424 434 425 … … 490 481 491 482 492 493 494 495 /**496 * Locate a CD-R/W writer's SCSI node.497 * @param cdrw_device SCSI node will be placed here.498 * @return 0 for success, nonzero for failure.499 */500 501 502 483 /** 503 484 * Locate a CD-R/W writer's SCSI node. … … 513 494 char *command; 514 495 515 malloc_string(comment);516 malloc_string(tmp);517 malloc_string(cdr_exe);518 malloc_string(command);519 496 if (g_cdrw_drive_is_here[0]) { 520 497 strcpy(cdrw_device, g_cdrw_drive_is_here); 521 498 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 522 paranoid_free(comment);523 paranoid_free(tmp);524 paranoid_free(cdr_exe);525 paranoid_free(command);526 499 return (0); 527 500 } … … 529 502 log_msg(1, 530 503 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 531 paranoid_free(comment);532 paranoid_free(tmp);533 paranoid_free(cdr_exe);534 paranoid_free(command);535 504 return (1); 536 505 } 537 506 run_program_and_log_output("insmod ide-scsi", -1); 538 507 if (find_home_of_exe("cdrecord")) { 539 strcpy(cdr_exe, "cdrecord"); 540 } else { 541 strcpy(cdr_exe, "dvdrecord"); 542 } 543 tmp[0] = '\0'; 508 asprintf(&cdr_exe, "cdrecord"); 509 } else { 510 asprintf(&cdr_exe, "dvdrecord"); 511 } 544 512 if (find_home_of_exe(cdr_exe)) { 545 sprintf(command,513 asprintf(&command, 546 514 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", 547 515 cdr_exe); 548 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 549 } 516 asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 517 paranoid_free(command); 518 } else { 519 asprintf(&tmp, ""); 520 } 521 paranoid_free(cdr_exe); 522 550 523 if (strlen(tmp) < 2) { 524 paranoid_free(tmp); 525 return 1; 526 } else { 527 strcpy(cdrw_device, tmp); 528 paranoid_free(tmp); 529 530 asprintf(&comment, "Found CDRW device - %s", cdrw_device); 531 log_it(comment); 551 532 paranoid_free(comment); 552 paranoid_free(tmp); 553 paranoid_free(cdr_exe); 554 paranoid_free(command); 555 return 1; 556 } else { 557 strcpy(cdrw_device, tmp); 558 sprintf(comment, "Found CDRW device - %s", cdrw_device); 559 log_it(comment); 533 560 534 strcpy(g_cdrw_drive_is_here, cdrw_device); 561 paranoid_free(comment);562 paranoid_free(tmp);563 paranoid_free(cdr_exe);564 paranoid_free(command);565 535 return (0); 566 536 } 567 537 } 568 569 570 538 571 539 … … 586 554 char *q; 587 555 char *r; 556 int n = 0; 588 557 int retval = 0; 589 558 … … 592 561 593 562 /*@ buffers ***************************************************** */ 594 char *tmp ;563 char *tmp = NULL; 595 564 char *cdr_exe; 596 char *phrase_one; 597 char *phrase_two; 565 #ifndef __FreeBSD__ 566 char *phrase_two = NULL; 567 char *dvd_last_resort = NULL; 568 #endif 598 569 char *command; 599 char *dvd_last_resort;600 570 char *mountpoint; 601 571 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 602 572 603 573 /*@ intialize *************************************************** */ 604 malloc_string(tmp);605 malloc_string(cdr_exe);606 malloc_string(phrase_one);607 malloc_string(phrase_two);608 malloc_string(command);609 malloc_string(dvd_last_resort);610 malloc_string(mountpoint);611 574 612 575 output[0] = '\0'; 613 phrase_one[0] = '\0';614 phrase_two[0] = '\0';615 dvd_last_resort[0] = '\0';616 576 617 577 /*@ end vars **************************************************** */ … … 620 580 strcpy(output, g_cdrom_drive_is_here); 621 581 log_msg(3, "Been there, done that. Returning %s", output); 622 retval = 0; 623 goto end_of_find_cdrom_device; 582 return(0); 624 583 } 625 584 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { … … 628 587 "find_cdrom_device() --- returning last found location - '%s'", 629 588 output); 630 retval = 0; 631 goto end_of_find_cdrom_device; 632 } 633 634 sprintf(mountpoint, "/tmp/cd.%d", (int) (random() % 32767)); 635 make_hole_for_dir(mountpoint); 589 return(0); 590 } 636 591 637 592 if (find_home_of_exe("cdrecord")) { 638 strcpy(cdr_exe, "cdrecord"); 639 } else { 640 strcpy(cdr_exe, "dvdrecord"); 641 } 642 tmp[0] = '\0'; 593 asprintf(&cdr_exe, "cdrecord"); 594 } else { 595 asprintf(&cdr_exe, "dvdrecord"); 596 } 643 597 if (!find_home_of_exe(cdr_exe)) { 644 598 strcpy(output, "/dev/cdrom"); … … 646 600 if (!does_device_exist(output)) { 647 601 log_msg(4, "That didn't work. Sorry."); 648 retval = 1;649 goto end_of_find_cdrom_device;602 paranoid_free(cdr_exe); 603 return(1); 650 604 } else { 651 retval = 0;652 goto end_of_find_cdrom_device;653 } 654 } 655 656 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);605 paranoid_free(cdr_exe); 606 return(0); 607 } 608 } 609 610 asprintf(&command, "%s -scanbus 2> /dev/null", cdr_exe); 657 611 fin = popen(command, "r"); 658 612 if (!fin) { 659 613 log_msg(4, "command=%s", command); 660 614 log_OS_error("Cannot popen command"); 615 paranoid_free(cdr_exe); 616 paranoid_free(command); 661 617 return (1); 662 618 } 663 for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin); 664 fgets(tmp, MAX_STR_LEN, fin)) { 619 paranoid_free(command); 620 621 for (getline(&tmp, &n, fin); !feof(fin); 622 getline(&tmp, &n, fin)) { 665 623 p = strchr(tmp, '\''); 666 624 if (p) { … … 669 627 for (r = q; *(r - 1) == ' '; r--); 670 628 *r = '\0'; 671 strcpy(phrase_one, p);672 629 p = strchr(++q, '\''); 673 630 if (p) { … … 678 635 } 679 636 *q = '\0'; 680 strcpy(phrase_two, p); 637 #ifndef __FreeBSD__ 638 paranoid_free(phrase_two); 639 asprintf(&phrase_two, p); 640 #endif 681 641 } 682 642 } … … 685 645 } 686 646 paranoid_pclose(fin); 647 paranoid_free(tmp); 648 tmp = NULL; 649 n = 0; 687 650 688 651 #ifndef __FreeBSD__ … … 690 653 log_msg(4, "Not running phase two. String is empty."); 691 654 } else { 692 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);655 asprintf(&command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 693 656 fin = popen(command, "r"); 694 657 if (!fin) { 695 658 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); 696 659 } else { 697 for ( fgets(tmp, MAX_STR_LEN, fin); !feof(fin);698 fgets(tmp, MAX_STR_LEN, fin)) {660 for (getline(&tmp, &n, fin); !feof(fin); 661 getline(&tmp, &n, fin)) { 699 662 log_msg(5, "--> '%s'", tmp); 700 663 if (tmp[0] != ' ' && tmp[1] != ' ') { … … 703 666 *p = '\0'; 704 667 if (strstr(tmp, "DVD")) { 705 sprintf(dvd_last_resort, "/dev/%s", tmp); 668 paranoid_free(dvd_last_resort); 669 asprintf(&dvd_last_resort, "/dev/%s", tmp); 706 670 log_msg(4, 707 671 "Ignoring '%s' because it's a DVD drive", … … 714 678 } 715 679 } 680 paranoid_free(tmp); 716 681 paranoid_pclose(fin); 717 682 } 718 } 683 paranoid_free(command); 684 } 685 paranoid_free(phrase_two); 719 686 720 687 #endif … … 745 712 "/dev/cd1"))) 746 713 { 747 retval = 1;748 goto end_of_find_cdrom_device;714 paranoid_free(cdr_exe); 715 return(1); 749 716 } 750 717 } … … 756 723 } 757 724 #else 758 if (!found_it && strlen(dvd_last_resort) > 0) { 759 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 760 dvd_last_resort); 761 strcpy(output, dvd_last_resort); 762 found_it = TRUE; 763 } 725 if (dvd_last_resort != NULL) { 726 if (!found_it && strlen(dvd_last_resort) > 0) { 727 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 728 dvd_last_resort); 729 strcpy(output, dvd_last_resort); 730 found_it = TRUE; 731 } 732 } 733 paranoid_free(dvd_last_resort); 734 764 735 if (found_it) { 765 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",736 asprintf(&tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 766 737 strrchr(output, '/') + 1); 767 738 if (system(tmp) == 0) { … … 772 743 output[0] = '\0'; 773 744 } 745 paranoid_free(tmp); 774 746 } 775 747 … … 811 783 g_cdrw_drive_is_here))) 812 784 { 813 retval = 1;814 goto end_of_find_cdrom_device;785 paranoid_free(cdr_exe); 786 return(1); 815 787 } 816 788 } … … 824 796 #endif 825 797 798 asprintf(&mountpoint, "/tmp/cd.%d", (int) (random() % 32767)); 799 make_hole_for_dir(mountpoint); 800 826 801 if (found_it && try_to_mount) { 827 802 if (mount_CDROM_here(output, mountpoint)) { … … 829 804 found_it = FALSE; 830 805 } else { 831 sprintf(tmp, "%s/archives", mountpoint);806 asprintf(&tmp, "%s/archives", mountpoint); 832 807 if (!does_file_exist(tmp)) { 833 808 log_msg(4, "[Cardigans] I'll take it back"); 834 809 found_it = FALSE; 835 810 } else { 836 sprintf(command, "umount %s", output);811 asprintf(&command, "umount %s", output); 837 812 paranoid_system(command); 813 paranoid_free(command); 838 814 log_msg(4, "I'm confident the Mondo CD is in %s", output); 839 815 } 816 paranoid_free(tmp); 840 817 } 841 818 } 842 819 unlink(mountpoint); 820 paranoid_free(mountpoint); 843 821 844 822 if (found_it) { … … 850 828 strcpy(the_last_place_i_found_it, output); 851 829 strcpy(g_cdrom_drive_is_here, output); 852 retval = 0; 853 goto end_of_find_cdrom_device; 854 } 855 856 sprintf(command, 830 return(0); 831 } 832 833 asprintf(&command, 857 834 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 858 835 cdr_exe, g_cdrw_drive_is_here); 859 836 log_msg(1, "command=%s", command); 860 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 837 asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 838 paranoid_free(command); 839 861 840 if (tmp[0]) { 862 841 strcpy(output, tmp); 863 842 log_msg(4, "Finally found it at %s", output); 864 843 retval = 0; 865 goto end_of_find_cdrom_device;866 844 } else { 867 845 log_msg(4, "Still couldn't find it."); 868 846 retval = 1; 869 goto end_of_find_cdrom_device; 870 } 871 end_of_find_cdrom_device: 847 } 872 848 paranoid_free(tmp); 873 849 paranoid_free(cdr_exe); 874 paranoid_free(phrase_one);875 paranoid_free(phrase_two);876 paranoid_free(command);877 paranoid_free(dvd_last_resort);878 paranoid_free(mountpoint);879 850 return (retval); 880 851 } 881 852 882 853 883 884 885 886 854 int find_dvd_device(char *output, bool try_to_mount) 887 855 { 888 char *command;889 856 char *tmp; 890 857 int retval = 0, devno = -1; 891 892 malloc_string(command);893 malloc_string(tmp);894 858 895 859 if (g_dvd_drive_is_here[0]) { … … 899 863 } 900 864 901 sprintf(tmp, call_program_and_get_last_line_of_output865 asprintf(&tmp, call_program_and_get_last_line_of_output 902 866 ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 903 867 ); 904 868 log_msg(5, "tmp = '%s'", tmp); 905 if (!tmp[0]) 906 sprintf(tmp, call_program_and_get_last_line_of_output 869 if (!tmp[0]) { 870 paranoid_free(tmp); 871 asprintf(&tmp, call_program_and_get_last_line_of_output 907 872 ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 908 873 ); 874 } 909 875 if (tmp[0]) { 910 876 devno = atoi(tmp) - 1; 911 877 } 878 paranoid_free(tmp); 879 912 880 if (devno >= 0) { 913 881 retval = 0; … … 926 894 } 927 895 928 929 930 931 932 #include <sys/ioctl.h>933 896 934 897 /** … … 1015 978 log_msg(1, "Failed to get harddisk geometry, using old mode"); 1016 979 } 1017 /*1018 if ((fd = open (drive, O_RDONLY)) != -1) {1019 if (ioctl (fd, HDIO_GETGEO, &hdgeo) != -1) {1020 close (fd);1021 log_msg (2, "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB", drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors, (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));1022 if ( hdgeo.cylinders && hdgeo.heads && hdgeo.sectors ) {1023 outvalB = ((long) (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024));1024 }1025 }1026 close (fd);1027 */1028 980 #endif 1029 981 … … 1041 993 } 1042 994 1043 /* The old version */1044 #if 01045 long get_phys_size_of_drive(char *drive)1046 {1047 /*@ pointers **************************************************** */1048 #if linux1049 FILE *fin;1050 char *p;1051 char *q;1052 char *r;1053 /*@ buffers ***************************************************** */1054 char *tmp;1055 char *command;1056 1057 /*@ long ******************************************************** */1058 long outL;1059 long tempLa;1060 long tempLb;1061 long tempLc;1062 1063 #endif1064 1065 struct hd_geometry hdgeo;1066 int fd;1067 1068 #ifdef __FreeBSD__1069 off_t o;1070 1071 if ((fd = open(drive, O_RDONLY)) != -1) {1072 if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {1073 close(fd);1074 return (long) (o / (off_t) (1024 * 1024));1075 }1076 close(fd);1077 }1078 log_msg(4, "drive = %s, error = %s", drive, strerror(errno));1079 fatal_error("GPSOD: Unable to get size of drive");1080 #else1081 1082 malloc_string(tmp);1083 malloc_string(command);1084 1085 if ((fd = open(drive, O_RDONLY)) != -1) {1086 if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) {1087 close(fd);1088 log_msg(2,1089 "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB",1090 drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors,1091 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 /1092 1024));1093 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {1094 return ((long)1095 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors /1096 2 / 1024));1097 }1098 }1099 close(fd);1100 }1101 1102 assert_string_is_neither_NULL_nor_zerolength(drive);1103 1104 sprintf(command,1105 "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16",1106 drive);1107 strcpy(tmp, call_program_and_get_last_line_of_output(command));1108 if (tmp[0]) {1109 p = tmp;1110 q = strchr(p, ' ');1111 if (q) {1112 *(q++) = '\0';1113 r = strchr(q, ' ');1114 if (r) {1115 *(r++) = '\0';1116 tempLa = atol(p);1117 tempLb = atol(q);1118 tempLc = atol(r);1119 outL = tempLa * tempLb / 1024 * tempLc / 1024;1120 if (outL > 100) {1121 paranoid_free(tmp);1122 paranoid_free(command);1123 return (outL);1124 }1125 }1126 }1127 }1128 1129 /* try to grep for 'Drive xxxx: yyy MB' */1130 sprintf(command,1131 "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3",1132 drive);1133 strcpy(tmp, call_program_and_get_last_line_of_output(command));1134 if (atol(tmp) > 0) {1135 paranoid_free(tmp);1136 paranoid_free(command);1137 return (atol(tmp));1138 }1139 1140 /* else, do it the old-fashioned way */1141 p = strrchr(drive, (int) '/');1142 if (p) {1143 strcpy(tmp, p + 1);1144 } else {1145 paranoid_free(tmp);1146 paranoid_free(command);1147 return (-1);1148 }1149 sprintf(command, "dmesg | grep %s 2> /dev/null", tmp);1150 if (!(fin = popen(command, "r"))) {1151 log_OS_error("Cannot popen dmesg command");1152 } else {1153 fgets(tmp, MAX_STR_LEN - 1, fin);1154 while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) {1155 fgets(tmp, MAX_STR_LEN - 1, fin);1156 }1157 if (pclose(fin)) {1158 log_OS_error("Cannot pclose dmesg fin");1159 }1160 }1161 if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) {1162 log_msg(3, "Cannot find %s's size: dmesg isn't helping either.",1163 drive);1164 paranoid_free(tmp);1165 paranoid_free(command);1166 return (-1);1167 }1168 for (; !isdigit(*(p - 1)); p--);1169 *p = '\0';1170 for (p--; isdigit(*(p - 1)); p--);1171 outL = atol(p);1172 if (outL <= 0) {1173 paranoid_free(tmp);1174 paranoid_free(command);1175 return (-1);1176 }1177 if (strstr(tmp, "GB")) {1178 outL = outL * 1024;1179 }1180 paranoid_free(tmp);1181 paranoid_free(command);1182 return (outL * 19 / 20);1183 #endif1184 }1185 #endif /* 0 */1186 1187 1188 1189 1190 995 1191 996 /** … … 1202 1007 1203 1008 FILE *pin; 1204 intretval;1009 bool retval; 1205 1010 malloc_string(good_formats); 1206 malloc_string(command);1207 malloc_string(format_sz);1208 1209 1011 assert_string_is_neither_NULL_nor_zerolength(format); 1210 1012 1211 sprintf(format_sz, "%s ", format);1013 asprintf(&format_sz, "%s ", format); 1212 1014 1213 1015 #ifdef __FreeBSD__ 1214 sprintf(command,1016 asprintf(&command, 1215 1017 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1216 1018 #else 1217 sprintf(command,1019 asprintf(&command, 1218 1020 "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1219 1021 #endif 1220 1022 1221 1023 pin = popen(command, "r"); 1024 paranoid_free(command); 1025 1222 1026 if (!pin) { 1223 1027 log_OS_error("Unable to read good formats"); 1224 retval = 0;1028 retval = FALSE; 1225 1029 } else { 1226 1030 strcpy(good_formats, " "); … … 1232 1036 strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1233 1037 if (strstr(good_formats, format_sz)) { 1234 retval = 1;1038 retval = TRUE; 1235 1039 } else { 1236 retval = 0;1040 retval = FALSE; 1237 1041 } 1238 1042 } 1239 1043 paranoid_free(good_formats); 1240 paranoid_free(command);1241 1044 paranoid_free(format_sz); 1242 1045 return (retval); … … 1258 1061 1259 1062 /*@ buffers ***************************************************** */ 1260 char *incoming ;1063 char *incoming = NULL; 1261 1064 char *device_with_tab; 1262 1065 char *device_with_space; 1263 1066 char *tmp; 1264 int retval= 0;1067 int n = 0; 1265 1068 1266 1069 #ifdef __FreeBSD__ … … 1272 1075 /*@ end vars **************************************************** */ 1273 1076 1274 malloc_string(incoming);1275 malloc_string(device_with_tab);1276 malloc_string(device_with_space);1277 malloc_string(tmp);1278 1077 assert(device_raw != NULL); 1279 1078 // assert_string_is_neither_NULL_nor_zerolength(device_raw); … … 1281 1080 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", 1282 1081 device_raw); 1283 sprintf(tmp, "/%s", device_raw);1284 } else { 1285 strcpy(tmp, device_raw);1082 asprintf(&tmp, "/%s", device_raw); 1083 } else { 1084 asprintf(&tmp, device_raw); 1286 1085 } 1287 1086 log_msg(1, "Is %s mounted?", tmp); … … 1289 1088 log_msg(1, 1290 1089 "I don't know how the heck /proc made it into the mountlist. I'll ignore it."); 1291 return (0); 1292 } 1293 sprintf(device_with_tab, "%s\t", tmp); 1294 sprintf(device_with_space, "%s ", tmp); 1090 return (FALSE); 1091 } 1092 asprintf(&device_with_tab, "%s\t", tmp); 1093 asprintf(&device_with_space, "%s ", tmp); 1094 paranoid_free(tmp); 1295 1095 1296 1096 if (!(fin = popen("mount", "r"))) { … … 1298 1098 return (FALSE); 1299 1099 } 1300 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);1301 fgets(incoming, MAX_STR_LEN - 1, fin)) {1100 for (getline(&incoming, &n, fin); !feof(fin); 1101 getline(&incoming, &n, fin)) { 1302 1102 if (strstr(incoming, device_with_space) //> incoming 1303 1103 || strstr(incoming, device_with_tab)) // > incoming) 1304 1104 { 1305 1105 paranoid_pclose(fin); 1306 retval = 1; 1307 goto end_of_func; 1308 } 1309 } 1106 return(TRUE); 1107 } 1108 } 1109 paranoid_free(incoming); 1110 paranoid_free(device_with_tab); 1310 1111 paranoid_pclose(fin); 1311 sprintf(tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null", 1112 1113 asprintf(&tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null", 1312 1114 SWAPLIST_COMMAND, device_with_space); 1115 paranoid_free(device_with_space); 1116 1313 1117 log_msg(4, "tmp (command) = '%s'", tmp); 1314 1118 if (!system(tmp)) { 1315 retval = 1; 1316 goto end_of_func; 1317 } 1318 end_of_func: 1319 paranoid_free(incoming); 1320 paranoid_free(device_with_tab); 1321 paranoid_free(device_with_space); 1119 paranoid_free(tmp); 1120 return(TRUE); 1121 } 1322 1122 paranoid_free(tmp); 1323 return (retval); 1324 } 1123 return (FALSE); 1124 } 1125 1325 1126 1326 1127 #ifdef __FreeBSD__ … … 1329 1130 * Create a loopback device for specified @p fname. 1330 1131 * @param fname The file to associate with a device. 1331 * @return /dev entry for the device, or NULL if it couldn't be allocated. 1132 * @return /dev entry for the device (to be freed by the caller), 1133 * or NULL if it couldn't be allocated. 1332 1134 */ 1333 1135 char *make_vn(char *fname) 1334 1136 { 1335 char *device = (char *) malloc(MAX_STR_LEN);1336 char *mddevice = (char *) malloc(32);1337 char command[MAX_STR_LEN];1137 char *device; 1138 char *mddevice = NULL; 1139 char *command = NULL; 1338 1140 int vndev = 2; 1141 1339 1142 if (atoi 1340 1143 (call_program_and_get_last_line_of_output 1341 1144 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1342 1145 do { 1343 sprintf(mddevice, "vn%ic", vndev++); 1344 sprintf(command, "vnconfig %s %s", mddevice, fname); 1146 paranoid_free(mddevice); 1147 asprintf(&mddevice, "vn%ic", vndev++); 1148 1149 paranoid_free(command); 1150 asprintf(&command, "vnconfig %s %s", mddevice, fname); 1151 1345 1152 if (vndev > 10) { 1153 paranoid_free(command); 1154 paranoid_free(mddevice); 1346 1155 return NULL; 1347 1156 } 1348 1157 } 1349 1158 while (system(command)); 1350 } else { 1351 sprintf(command, "mdconfig -a -t vnode -f %s", fname); 1352 mddevice = call_program_and_get_last_line_of_output(command); 1159 paranoid_free(command); 1160 } else { 1161 asprintf(&command, "mdconfig -a -t vnode -f %s", fname); 1162 asprintf(&mddevice, call_program_and_get_last_line_of_output(command)); 1163 paranoid_free(command); 1164 1353 1165 if (!strstr(mddevice, "md")) { 1166 paranoid_free(mddevice); 1354 1167 return NULL; 1355 1168 } 1356 1169 } 1357 sprintf(device, "/dev/%s", mddevice);1358 return device;1359 } 1360 1170 asprintf(&device, "/dev/%s", mddevice); 1171 paranoid_free(mddevice); 1172 return(device); 1173 } 1361 1174 1362 1175 … … 1371 1184 int kick_vn(char *dname) 1372 1185 { 1373 char command[MAX_STR_LEN]; 1186 char *command; 1187 int ret = 0; 1374 1188 1375 1189 if (strncmp(dname, "/dev/", 5) == 0) { … … 1380 1194 (call_program_and_get_last_line_of_output 1381 1195 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1382 sprintf(command, "vnconfig -d %s", dname); 1383 return system(command); 1384 } else { 1385 sprintf(command, "mdconfig -d -u %s", dname); 1386 return system(command); 1196 asprintf(&command, "vnconfig -d %s", dname); 1197 ret = system(command); 1198 paranoid_free(command); 1199 return(ret); 1200 } else { 1201 asprintf(&command, "mdconfig -d -u %s", dname); 1202 ret = system(command); 1203 paranoid_free(command); 1204 return(ret); 1387 1205 } 1388 1206 /*NOTREACHED*/ return 255; … … 1401 1219 /*@ buffer ****************************************************** */ 1402 1220 char *command; 1403 char *dev;1404 char *options;1405 1221 int retval; 1406 1222 1407 malloc_string(command);1408 malloc_string(dev);1409 malloc_string(options);1410 1223 assert_string_is_neither_NULL_nor_zerolength(device); 1411 1224 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 1412 1225 1413 1226 make_hole_for_dir(mountpoint); 1414 strcpy(options, "ro");1415 1227 if (isdigit(device[0])) { 1416 1228 find_cdrom_device(device, FALSE); 1417 } else {1418 strcpy(dev, device);1419 1229 } 1420 1230 if (g_ISO_restore_mode) { 1421 1231 1422 1232 #ifdef __FreeBSD__ 1423 strcpy(dev, make_vn(device)); 1233 char *dev; 1234 1235 dev = make_vn(device)); 1424 1236 if (!dev) { 1425 sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",1237 asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)", 1426 1238 device); 1427 1239 fatal_error(command); 1428 1240 } 1429 1241 strcpy(device, dev); 1430 #else 1431 strcat(options, ",loop"); 1432 #endif 1433 1434 } 1242 paranoid_free(dev); 1243 #endif 1244 } 1245 1435 1246 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 1436 1247 mountpoint); … … 1438 1249 1439 1250 #ifdef __FreeBSD__ 1440 sprintf(command, "mount_cd9660 -r %s %s 2>> %s",1251 asprintf(&command, "mount_cd9660 -r %s %s 2>> %s", 1441 1252 device, mountpoint, MONDO_LOGFILE); 1442 1443 1253 #else 1444 sprintf(command, "mount %s -o %s-t iso9660 %s 2>> %s",1445 device, options,mountpoint, MONDO_LOGFILE);1254 asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s", 1255 device, mountpoint, MONDO_LOGFILE); 1446 1256 #endif 1447 1257 … … 1452 1262 retval = system(command); 1453 1263 log_msg(1, "system(%s) returned %d", command, retval); 1454 1455 1264 paranoid_free(command); 1456 paranoid_free(dev); 1457 paranoid_free(options); 1265 1458 1266 return (retval); 1459 1267 } 1460 1461 1462 1463 1464 1268 1465 1269 … … 1497 1301 return; 1498 1302 } 1499 malloc_string(tmp); 1500 malloc_string(request); 1501 sprintf(tmp, "mkdir -p " MNT_CDROM); 1303 1304 asprintf(&tmp, "mkdir -p " MNT_CDROM); 1502 1305 run_program_and_log_output(tmp, 5); 1306 paranoid_free(tmp); 1307 1503 1308 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1504 1309 || bkpinfo->backup_media_type == nfs) { … … 1511 1316 } 1512 1317 system("mkdir -p /tmp/isodir &> /dev/null"); 1513 sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,1318 asprintf(&tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, 1514 1319 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1515 1320 cd_number_i_want); 1516 1321 if (!does_file_exist(tmp)) { 1517 sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso", 1322 paranoid_free(tmp); 1323 asprintf(&tmp, "/tmp/isodir/%s/%s-%d.iso", 1518 1324 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1519 1325 cd_number_i_want); … … 1529 1335 fatal_error("Mommy!"); 1530 1336 } 1531 // g_current_media_number = cd_number_i_want; 1532 // return; 1337 paranoid_free(tmp); 1533 1338 } 1534 1339 if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) { 1535 1340 log_msg(3, "Currently, we hold %d but we want %d", res, 1536 1341 cd_number_i_want); 1537 sprintf(tmp, "Insisting on %s #%d",1342 asprintf(&tmp, "Insisting on %s #%d", 1538 1343 media_descriptor_string(bkpinfo->backup_media_type), 1539 1344 cd_number_i_want); 1540 sprintf(request, "Please insert %s #%d and press Enter.",1345 asprintf(&request, "Please insert %s #%d and press Enter.", 1541 1346 media_descriptor_string(bkpinfo->backup_media_type), 1542 1347 cd_number_i_want); 1543 1348 log_msg(3, tmp); 1349 paranoid_free(tmp); 1350 1544 1351 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) { 1545 1352 paranoid_system("sync"); … … 1567 1374 paranoid_system("sync"); 1568 1375 } 1376 paranoid_free(request); 1377 1569 1378 log_msg(1, "Thankyou. Proceeding..."); 1570 1379 g_current_media_number = cd_number_i_want; 1571 1380 } 1572 paranoid_free(tmp); 1573 paranoid_free(request); 1574 } 1575 1381 } 1576 1382 /* @} - end of deviceGroup */ 1577 1578 1579 1580 1581 1383 1582 1384 … … 1598 1400 { 1599 1401 char *tmp; 1600 char *sz_size ;1402 char *sz_size = NULL; 1601 1403 char *command; 1602 1404 char *comment; 1603 char *prompt ;1405 char *prompt = NULL; 1604 1406 int i; 1605 1407 FILE *fin; 1606 1408 1607 malloc_string(tmp);1608 malloc_string(sz_size);1609 malloc_string(command);1610 malloc_string(comment);1611 1409 assert(bkpinfo != NULL); 1612 sz_size[0] = '\0';1613 1410 bkpinfo->nonbootable_backup = FALSE; 1614 1411 … … 1667 1464 finish(1); 1668 1465 } 1669 sprintf(comment, "What speed is your %s (re)writer?",1466 asprintf(&comment, "What speed is your %s (re)writer?", 1670 1467 media_descriptor_string(bkpinfo->backup_media_type)); 1671 1468 if (bkpinfo->backup_media_type == dvd) { 1672 1469 find_dvd_device(bkpinfo->media_device, FALSE); 1673 strcpy(tmp, "1");1674 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB1470 asprintf(&tmp, "1"); 1471 asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 1675 1472 log_msg(1, "Setting to DVD defaults"); 1676 1473 } else { 1677 1474 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 1678 strcpy(tmp, "4");1679 strcpy(sz_size, "650");1475 asprintf(&tmp, "4"); 1476 asprintf(&sz_size, "650"); 1680 1477 log_msg(1, "Setting to CD defaults"); 1681 1478 } … … 1686 1483 } 1687 1484 } 1485 paranoid_free(comment); 1486 1688 1487 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1689 sprintf(comment, 1488 paranoid_free(tmp); 1489 1490 asprintf(&comment, 1690 1491 "How much data (in Megabytes) will each %s store?", 1691 1492 media_descriptor_string(bkpinfo->backup_media_type)); 1493 1692 1494 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 1693 1495 log_to_screen("User has chosen not to backup the PC"); 1694 1496 finish(1); 1695 1497 } 1498 paranoid_free(comment); 1499 1696 1500 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1697 1501 bkpinfo->media_size[i] = atoi(sz_size); … … 1701 1505 finish(1); 1702 1506 } 1507 paranoid_free(sz_size); 1703 1508 } 1704 1509 case cdstream: … … 1718 1523 log_msg(1, "bkpinfo->media_device = %s", 1719 1524 bkpinfo->media_device); 1720 sprintf(comment,1525 asprintf(&comment, 1721 1526 "Please specify your %s drive's /dev entry", 1722 1527 media_descriptor_string(bkpinfo-> … … 1728 1533 finish(1); 1729 1534 } 1535 paranoid_free(comment); 1730 1536 } 1731 1537 log_msg(2, "%s device found at %s", … … 1737 1543 } 1738 1544 if (bkpinfo->media_device[0]) { 1739 sprintf(tmp,1545 asprintf(&tmp, 1740 1546 "I think I've found your %s burner at SCSI node %s; am I right on the money?", 1741 1547 media_descriptor_string(bkpinfo-> … … 1745 1551 bkpinfo->media_device[0] = '\0'; 1746 1552 } 1553 paranoid_free(tmp); 1747 1554 } 1748 1555 if (!bkpinfo->media_device[0]) { … … 1796 1603 } 1797 1604 } 1798 sprintf(tmp, 1799 "I think I've found your tape streamer at %s; am I right on the money?", 1800 bkpinfo->media_device); 1801 } 1802 if (bkpinfo->media_device[0]) { 1803 sprintf(tmp, 1605 asprintf(&tmp, 1804 1606 "I think I've found your tape streamer at %s; am I right on the money?", 1805 1607 bkpinfo->media_device); … … 1807 1609 bkpinfo->media_device[0] = '\0'; 1808 1610 } 1611 paranoid_free(tmp); 1809 1612 } 1810 1613 if (!bkpinfo->media_device[0]) { … … 1817 1620 } 1818 1621 } 1819 sprintf(tmp, "ls -l %s", bkpinfo->media_device);1622 asprintf(&tmp, "ls -l %s", bkpinfo->media_device); 1820 1623 if (run_program_and_log_output(tmp, FALSE)) { 1821 1624 log_to_screen("User has not specified a valid /dev entry"); 1822 1625 finish(1); 1823 1626 } 1627 paranoid_free(tmp); 1824 1628 log_msg(4, "sz_size = %s", sz_size); 1825 1629 sz_size[0] = '\0'; 1826 /* 1827 if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media) 1828 { 1829 if (!popup_and_get_string("Tape size", "How much COMPRESSED data will one of your tape cartridges hold? (e.g. 4GB for 4 gigabytes)", size_sz, 16)) 1830 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1831 } 1832 */ 1833 if (sz_size[0] == '\0') { 1834 bkpinfo->media_size[0] = 0; 1835 } else { 1836 bkpinfo->media_size[0] = 1837 friendly_sizestr_to_sizelong(sz_size) / 2 - 50; 1838 } 1630 bkpinfo->media_size[0] = 0; 1839 1631 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); 1840 1632 if (bkpinfo->media_size[0] <= 0) { … … 1886 1678 if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/') 1887 1679 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0'; 1888 sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3",1680 asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3", 1889 1681 bkpinfo->nfs_mount); 1890 1682 strcpy(bkpinfo->isodir, 1891 1683 call_program_and_get_last_line_of_output(command)); 1684 paranoid_free(command); 1892 1685 } 1893 1686 if (bkpinfo->disaster_recovery) { … … 1903 1696 sprintf(bkpinfo->isodir, "/tmp/isodir.mondo.%d", 1904 1697 (int) (random() % 32768)); 1905 sprintf(command, "mkdir -p %s", bkpinfo->isodir);1698 asprintf(&command, "mkdir -p %s", bkpinfo->isodir); 1906 1699 run_program_and_log_output(command, 5); 1907 sprintf(tmp, "mount %s -t nfs %s", bkpinfo->nfs_mount, 1700 paranoid_free(command); 1701 1702 asprintf(&tmp, "mount %s -t nfs %s", bkpinfo->nfs_mount, 1908 1703 bkpinfo->isodir); 1909 1704 run_program_and_log_output(tmp, 5); 1705 paranoid_free(tmp); 1910 1706 malloc_string(g_selfmounted_isodir); 1911 1707 strcpy(g_selfmounted_isodir, bkpinfo->isodir); … … 1916 1712 finish(1); 1917 1713 } 1918 strcpy(tmp, bkpinfo->nfs_remote_dir);1714 asprintf(&tmp, bkpinfo->nfs_remote_dir); 1919 1715 if (!popup_and_get_string 1920 1716 ("Directory", "Which directory within that mountpoint?", tmp, … … 1924 1720 } 1925 1721 strcpy(bkpinfo->nfs_remote_dir, tmp); 1722 paranoid_free(tmp); 1723 1926 1724 // check whether writable - we better remove surrounding spaces for this 1927 1725 strip_spaces(bkpinfo->nfs_remote_dir); 1928 sprintf(command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,1726 asprintf(&command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 1929 1727 bkpinfo->nfs_remote_dir); 1930 1728 while (run_program_and_log_output(command, FALSE)) { 1931 strcpy(tmp, bkpinfo->nfs_remote_dir); 1729 paranoid_free(tmp); 1730 paranoid_free(prompt); 1731 asprintf(&tmp, bkpinfo->nfs_remote_dir); 1932 1732 asprintf(&prompt, 1933 1733 "Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup.", … … 1944 1744 bkpinfo->isodir, bkpinfo->nfs_remote_dir); 1945 1745 } 1746 paranoid_free(command); 1747 paranoid_free(tmp); 1748 paranoid_free(prompt); 1749 1946 1750 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1947 1751 bkpinfo->media_size[i] = 650; … … 1977 1781 bkpinfo->media_size[i] = atoi(sz_size); 1978 1782 } 1783 paranoid_free(sz_size); 1784 1979 1785 if (!popup_and_get_string 1980 1786 ("Prefix.", … … 2063 1869 finish(1); 2064 1870 } 2065 strcpy(tmp, list_of_NFS_mounts_only());1871 tmp = list_of_NFS_mounts_only(); 2066 1872 if (strlen(tmp) > 2) { 2067 1873 if (bkpinfo->exclude_paths[0]) { … … 2070 1876 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 2071 1877 } 1878 paranoid_free(tmp); 2072 1879 // NTFS 2073 strcpy(tmp,1880 asprintf(&tmp, 2074 1881 call_program_and_get_last_line_of_output 2075 1882 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); … … 2084 1891 strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4); 2085 1892 } 2086 1893 paranoid_free(tmp); 2087 1894 2088 1895 if (!popup_and_get_string … … 2124 1931 #else 2125 1932 if (bkpinfo->backup_media_type == nfs) { 2126 sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",2127 bkpinfo->nfs_mount);2128 // strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp));2129 1933 log_msg(3, "I think the NFS mount is mounted at %s", 2130 1934 bkpinfo->isodir); … … 2154 1958 } 2155 1959 } 2156 paranoid_free(tmp);2157 paranoid_free(sz_size);2158 paranoid_free(command);2159 paranoid_free(comment);2160 paranoid_free(prompt);2161 1960 return (0); 2162 1961 } 2163 2164 2165 2166 2167 /**2168 * @addtogroup utilityGroup2169 * @{2170 */2171 /**2172 * Get a space-separated list of NFS devices and mounts.2173 * @return The list created.2174 * @note The return value points to static data that will be overwritten with each call.2175 */2176 char *list_of_NFS_devices_and_mounts(void)2177 {2178 char *exclude_these_devices;2179 char *exclude_these_directories;2180 static char result_sz[512];2181 2182 malloc_string(exclude_these_devices);2183 malloc_string(exclude_these_directories);2184 strcpy(exclude_these_directories,2185 call_program_and_get_last_line_of_output2186 ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));2187 strcpy(exclude_these_devices,2188 call_program_and_get_last_line_of_output2189 ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));2190 sprintf(result_sz, "%s %s", exclude_these_directories,2191 exclude_these_devices);2192 paranoid_free(exclude_these_devices);2193 paranoid_free(exclude_these_directories);2194 return (result_sz);2195 }2196 2197 2198 1962 2199 1963 … … 2208 1972 char *exclude_these_devices; 2209 1973 char *exclude_these_directories; 2210 static char result_sz[512]; 2211 2212 malloc_string(exclude_these_devices); 2213 malloc_string(exclude_these_directories); 2214 strcpy(exclude_these_directories, 1974 char *result_sz; 1975 1976 asprintf(&exclude_these_directories, 2215 1977 call_program_and_get_last_line_of_output 2216 1978 ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2217 strcpy(exclude_these_devices,1979 asprintf(&exclude_these_devices, 2218 1980 call_program_and_get_last_line_of_output 2219 1981 ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2220 sprintf(result_sz, "%s", exclude_these_directories);1982 asprintf(&result_sz, "%s", exclude_these_directories); 2221 1983 paranoid_free(exclude_these_devices); 2222 1984 paranoid_free(exclude_these_directories); … … 2224 1986 } 2225 1987 1988 2226 1989 /* @} - end of utilityGroup */ 2227 2228 2229 2230 2231 1990 2232 1991 /** … … 2241 2000 char *tmp; 2242 2001 2243 malloc_string(tmp);2244 2002 assert_string_is_neither_NULL_nor_zerolength(stub); 2245 2003 … … 2248 2006 make_hole_for_file(store_name_here); 2249 2007 mkfifo(store_name_here, S_IRWXU | S_IRWXG); 2250 sprintf(tmp, "chmod 770 %s", store_name_here);2008 asprintf(&tmp, "chmod 770 %s", store_name_here); 2251 2009 paranoid_system(tmp); 2252 2010 paranoid_free(tmp); 2253 2011 } 2254 2255 2256 2257 2258 2012 2259 2013 … … 2268 2022 char *tmp, *command, *sz; 2269 2023 2270 malloc_string(tmp);2271 malloc_string(command);2272 malloc_string(sz);2273 2024 assert(bkpinfo != NULL); 2274 2025 2275 2026 #ifdef __FreeBSD__ 2276 strcpy(tmp,2027 asprintf(&tmp, 2277 2028 call_program_and_get_last_line_of_output 2278 2029 ("df -m -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2279 2030 #else 2280 strcpy(tmp,2031 asprintf(&tmp, 2281 2032 call_program_and_get_last_line_of_output 2282 2033 ("df -m -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | grep -v /dev/shm | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); … … 2284 2035 2285 2036 if (tmp[0] != '/') { 2286 strcpy(sz, tmp);2287 strcpy(tmp, "/");2288 strcat(tmp, sz);2037 asprintf(&sz, "/%s", tmp); 2038 paranoid_free(tmp); 2039 tmp = sz; 2289 2040 } 2290 2041 if (!tmp[0]) { … … 2302 2053 bkpinfo->scratchdir); 2303 2054 2304 sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2055 asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2056 paranoid_free(tmp); 2057 2305 2058 paranoid_system(command); 2306 paranoid_free(tmp);2307 2059 paranoid_free(command); 2308 paranoid_free(sz); 2309 } 2310 2311 2312 2313 2060 } 2314 2061 2315 2062 … … 2329 2076 char *command; 2330 2077 2331 malloc_string(command);2332 2078 if (!dev || dev[0] == '\0') { 2333 2079 output[0] = '\0'; 2334 2080 return (FALSE); 2335 2081 } 2336 // assert_string_is_neither_NULL_nor_zerolength(dev);2337 2082 log_msg(10, "Injecting %s", dev); 2338 2083 inject_device(dev); … … 2341 2086 return (FALSE); 2342 2087 } 2343 sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",2088 asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 2344 2089 512L, dev); 2345 2090 if (!run_program_and_log_output(command, FALSE) … … 2347 2092 strcpy(output, dev); 2348 2093 log_msg(4, "Found it - %s", dev); 2094 paranoid_free(command); 2349 2095 return (TRUE); 2350 2096 } else { 2351 2097 output[0] = '\0'; 2352 2098 log_msg(4, "It's not %s", dev); 2099 paranoid_free(command); 2353 2100 return (FALSE); 2354 2101 } 2355 2102 } 2356 2357 2358 2359 2103 2360 2104 … … 2372 2116 char *tmp; 2373 2117 2374 malloc_string(mountdev);2375 malloc_string(tmp);2376 2118 assert(bkpinfo != NULL); 2377 // log_it("Asking what_number_cd_is_this");2378 2119 if (g_ISO_restore_mode) { 2379 sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2380 // log_it("tmp = %s", tmp); 2381 2382 strcpy(mountdev, call_program_and_get_last_line_of_output(tmp)); 2383 strcat(mountdev, "/archives/THIS-CD-NUMBER"); 2384 // log_it("mountdev = %s", mountdev); 2120 asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2121 2122 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp)); 2123 paranoid_free(tmp); 2124 2385 2125 cd_number = atoi(last_line_of_file(mountdev)); 2386 // log_it("cd_number = %d", cd_number);2387 2126 paranoid_free(mountdev); 2388 paranoid_free(tmp); 2127 2389 2128 return (cd_number); 2390 2129 } 2391 2130 2392 strcpy(mountdev, bkpinfo->media_device);2131 asprintf(&mountdev, bkpinfo->media_device); 2393 2132 if (!mountdev[0]) { 2394 2133 log_it … … 2401 2140 cd_number = 2402 2141 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2403 // log_it("cd_number..later.. = %d", cd_number);2404 2142 paranoid_free(mountdev); 2405 paranoid_free(tmp);2406 2143 return (cd_number); 2407 2144 } 2408 2409 2410 2411 2412 2413 2145 2414 2146 … … 2423 2155 { 2424 2156 /*@ buffers **************** */ 2425 static char tmp[MAX_STR_LEN];2157 char *tmp; 2426 2158 2427 2159 2428 2160 #ifdef __FreeBSD__ 2429 strcpy(tmp, call_program_and_get_last_line_of_output2161 asprintf(&tmp, call_program_and_get_last_line_of_output 2430 2162 ("mount | grep \" on / \" | cut -d' ' -f1")); 2431 2163 #else 2432 strcpy(tmp, call_program_and_get_last_line_of_output2164 asprintf(&tmp, call_program_and_get_last_line_of_output 2433 2165 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//")); 2434 2166 if (strstr(tmp, "/dev/cciss/")) { 2435 strcpy(tmp, call_program_and_get_last_line_of_output 2167 paranoid_free(tmp); 2168 asprintf(&tmp, call_program_and_get_last_line_of_output 2436 2169 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1")); 2437 2170 } 2438 2171 if (strstr(tmp, "/dev/md")) { 2439 strcpy(tmp, 2172 paranoid_free(tmp); 2173 asprintf(&tmp, 2440 2174 call_program_and_get_last_line_of_output 2441 2175 ("mount | grep \" on / \" | cut -d' ' -f1")); … … 2502 2236 /*@ buffer ***************************************************** */ 2503 2237 char *list_drives_cmd; 2504 char *current_drive ;2238 char *current_drive = NULL; 2505 2239 2506 2240 /*@ pointers *************************************************** */ … … 2510 2244 int count_lilos = 0; 2511 2245 int count_grubs = 0; 2246 int n = 0; 2512 2247 2513 2248 /*@ end vars *************************************************** */ 2514 2515 malloc_string(list_drives_cmd);2516 malloc_string(current_drive);2517 2249 2518 2250 #ifdef __IA64__ … … 2521 2253 #endif 2522 2254 assert(which_device != NULL); 2523 // sprintf (list_drives_cmd, 2524 // "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2"); 2525 2526 sprintf(list_drives_cmd, 2255 asprintf(&list_drives_cmd, 2527 2256 // "parted2fdisk 2528 2257 "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", … … 2533 2262 log_OS_error("Unable to open list of drives"); 2534 2263 paranoid_free(list_drives_cmd); 2535 paranoid_free(current_drive);2536 2264 return ('\0'); 2537 2265 } 2538 for (fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives); 2539 fgets(current_drive, MAX_STR_LEN, pdrives)) { 2266 paranoid_free(list_drives_cmd); 2267 2268 for (getline(¤t_drive, &n, pdrives); !feof(pdrives); 2269 getline(¤t_drive, &n, pdrives)) { 2540 2270 strip_spaces(current_drive); 2541 2271 log_it("looking at drive %s's MBR", current_drive); … … 2551 2281 } 2552 2282 } 2283 paranoid_free(current_drive); 2284 2553 2285 if (pclose(pdrives)) { 2554 2286 log_OS_error("Cannot pclose pdrives"); 2555 2287 } 2556 2288 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 2557 paranoid_free(list_drives_cmd);2558 paranoid_free(current_drive);2559 2289 if (count_grubs && !count_lilos) { 2560 2290 return ('G'); … … 2572 2302 2573 2303 2574 2575 2576 2304 /** 2577 2305 * Write zeroes over the first 16K of @p device. … … 2599 2327 } 2600 2328 2329 2601 2330 /** 2602 2331 * Return the device pointed to by @p incoming. 2603 2332 * @param incoming The device to resolve symlinks for. 2604 2333 * @return The path to the real device file. 2605 * @note The returned string points to static storage that will be overwritten with each call.2334 * @note The returned string points to a storage that need to be freed by the caller 2606 2335 * @bug Won't work with file v4.0; needs to be written in C. 2607 2336 */ 2608 2337 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2609 2338 { 2610 static char output[MAX_STR_LEN];2339 char *output; 2611 2340 char *command; 2612 2341 char *curr_fname; … … 2616 2345 2617 2346 struct stat statbuf; 2618 command = malloc(1000);2619 malloc_string(tmp);2620 malloc_string(scratch);2621 malloc_string(curr_fname);2622 2347 if (!does_file_exist(incoming)) { 2623 2348 log_it 2624 2349 ("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2625 strcpy(output, incoming);2626 } else { 2627 strcpy(curr_fname, incoming);2350 asprintf(&output, incoming); 2351 } else { 2352 asprintf(&curr_fname, incoming); 2628 2353 lstat(curr_fname, &statbuf); 2629 2354 while (S_ISLNK(statbuf.st_mode)) { 2630 2355 log_msg(1, "curr_fname = %s", curr_fname); 2631 sprintf(command, "file %s", curr_fname); 2632 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 2356 asprintf(&command, "file %s", curr_fname); 2357 asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2358 paranoid_free(command); 2359 2633 2360 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2634 2361 p--); 2635 2362 p++; 2636 strcpy(scratch, p);2363 asprintf(&scratch, p); 2637 2364 for (p = scratch; *p != '\0' && *p != '\''; p++); 2638 2365 *p = '\0'; 2639 2366 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, 2640 2367 scratch); 2368 paranoid_free(tmp); 2369 2641 2370 if (scratch[0] == '/') { 2642 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink 2371 paranoid_free(curr_fname); 2372 asprintf(&curr_fname, scratch); // copy whole thing because it's an absolute softlink 2643 2373 } else { // copy over the basename cos it's a relative softlink 2644 2374 p = curr_fname + strlen(curr_fname); … … 2649 2379 p++; 2650 2380 } 2651 strcpy(p, scratch); 2652 } 2381 *p = '\0'; 2382 asprintf(&tmp, "%s%s", curr_fname, scratch); 2383 paranoid_free(curr_fname); 2384 curr_fname = tmp; 2385 } 2386 paranoid_free(scratch); 2653 2387 lstat(curr_fname, &statbuf); 2654 2388 } 2655 strcpy(output, curr_fname);2389 asprintf(&output, curr_fname); 2656 2390 log_it("resolved %s to %s", incoming, output); 2657 } 2658 paranoid_free(command); 2659 paranoid_free(curr_fname); 2660 paranoid_free(tmp); 2391 paranoid_free(curr_fname); 2392 } 2661 2393 return (output); 2662 2394 } … … 2667 2399 /** 2668 2400 * Return the type of partition format (GPT or MBR) 2401 * Caller needs to free the return value 2669 2402 */ 2670 2403 char *which_partition_format(const char *drive) 2671 2404 { 2672 static char output[4];2405 char *output; 2673 2406 char *tmp; 2674 2407 char *command; 2675 2408 char *fdisk; 2676 2409 2677 malloc_string(tmp);2678 malloc_string(command);2679 malloc_string(fdisk);2680 2410 log_msg(0, "Looking for partition table format type"); 2681 2411 // BERLIOS: Do that temporarily: we need to put back parted2fdisk everywhere … … 2683 2413 struct stat buf; 2684 2414 2685 sprintf(fdisk, "/usr/local/bin/fdisk");2415 asprintf(&fdisk, "/usr/local/bin/fdisk"); 2686 2416 if (stat(fdisk, &buf) != 0) { 2687 #endif 2688 sprintf(fdisk, "/sbin/fdisk"); 2417 paranoid_free(fdisk); 2418 #endif 2419 asprintf(&fdisk, "/sbin/fdisk"); 2689 2420 #ifdef __IA64__ 2690 2421 } 2691 2422 #endif 2692 2423 log_msg(1, "Using %s", fdisk); 2693 sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2694 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 2424 asprintf(&command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2425 paranoid_free(fdisk); 2426 2427 asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2428 paranoid_free(command); 2429 2695 2430 if (strstr(tmp, "GPT") == NULL) { 2696 strcpy(output, "MBR"); 2697 } else { 2698 strcpy(output, "GPT"); 2699 } 2431 asprintf(&output, "MBR"); 2432 } else { 2433 asprintf(&output, "GPT"); 2434 } 2435 paranoid_free(tmp); 2700 2436 log_msg(0, "Found %s partition table format type", output); 2701 paranoid_free(command);2702 paranoid_free(tmp);2703 paranoid_free(fdisk);2704 2437 return (output); 2705 2438 } -
trunk/mondo/mondo/common/libmondo-devices.h
r59 r146 39 39 int eject_device(char *); 40 40 41 char *list_of_NFS_devices_and_mounts();42 41 char *list_of_NFS_mounts_only(); 43 42 -
trunk/mondo/mondo/common/libmondo-mountlist.c
r87 r146 457 457 res++; 458 458 } 459 paranoid_free(part_table_fmt); 460 459 461 /* does partition /dev/hdNX exist more than once in the mountlist? */ 460 462 for (i = 0, mountpoint_copies = 0, device_copies = 0; -
trunk/mondo/mondo/common/libmondo-stream-EXT.h
r59 r146 23 23 extern int read_header_block_from_stream(long long *plen, char *filename, 24 24 int *pcontrol_char); 25 #ifndef S_SPLINT_S 25 26 extern int register_in_tape_catalog(t_archtype type, int number, long aux, 26 27 char *fn); 28 #endif 27 29 extern bool should_we_write_to_next_tape(long mediasize, 28 30 long long -
trunk/mondo/mondo/common/libmondo-stream.c
r127 r146 209 209 * this platform, then the IDE tape, then "/dev/st0", then "/dev/osst0". 210 210 * @param dev Where to put the found tape device. 211 * @param siz Where to put the tape size (a string like "4GB") 211 * @param siz Where to put the tape size (a string like "4GB"). Should be freed by caller 212 212 * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined). 213 213 */ … … 220 220 221 221 log_to_screen("I am looking for your tape streamer. Please wait."); 222 dev[0] = siz[0] = '\0'; 222 dev[0] = '\0'; 223 siz = NULL; 223 224 if (find_home_of_exe("cdrecord")) { 224 225 asprintf(&cdr_exe, "cdrecord"); … … 235 236 ("Either too few or too many tape streamers for me to detect..."); 236 237 strcpy(dev, VANILLA_SCSI_TAPE); 238 paranoid_free(tmp); 239 paranoid_free(cdr_exe); 237 240 return 1; 238 241 } … … 246 249 if (strlen(tmp) < 2) { 247 250 log_it("Could not find tape device"); 251 paranoid_free(tmp); 252 paranoid_free(cdr_exe); 248 253 return 1; 249 254 } … … 303 308 } 304 309 305 siz[0] = '\0';306 310 log_it("res=%d; dev=%s", res, dev); 307 311 308 312 if (res) { 313 paranoid_free(tmp); 309 314 return (res); 310 315 } 311 316 312 317 if (strlen(tmp) < 2) { 313 siz[0] = '\0';314 318 log_it("Warning - size of tape unknown"); 319 paranoid_free(tmp); 315 320 return (0); 316 321 } else { 317 s trcpy(siz, tmp);322 siz = tmp; 318 323 return (0); 319 324 } 320 paranoid_free(tmp);321 325 } 322 326 -
trunk/mondo/mondo/common/libmondo-tools.c
r127 r146 19 19 #include <netdb.h> 20 20 #include <netinet/in.h> 21 #ifndef S_SPLINT_S 21 22 #include <arpa/inet.h> 23 #endif 22 24 23 25 /*@unused@*/ -
trunk/mondo/mondo/common/my-stuff.h
r142 r146 115 115 */ 116 116 #ifdef NDEBUG 117 # define assert(exp) ((void)0)117 # define assert(exp) ((void)0) 118 118 #else 119 #define assert(exp) ((exp)?((void)0):_mondo_assert_fail(__FILE__, __FUNCTION__, __LINE__, #exp)) 119 # ifndef S_SPLINT_S 120 # define assert(exp) ((exp)?((void)0):_mondo_assert_fail(__FILE__, __FUNCTION__, __LINE__, #exp)) 121 # else 122 # define assert(exp) ((void)0) 123 # endif 120 124 #endif 121 125 … … 240 244 */ 241 245 #define MAX_TAPECAT_FNAME_LEN 32 242 243 //#define strcpy(y,x) strncpy(y, x, sizeof(y)-1)244 245 246 246 247 /** -
trunk/mondo/mondo/common/newt-specific.c
r127 r146 313 313 314 314 system 315 ("gzip -9c /var/log/mondo-archive.log> /tmp/MA.log.gz 2> /dev/null");315 ("gzip -9c "MONDO_LOGFILE" > /tmp/MA.log.gz 2> /dev/null"); 316 316 if (!strstr(g_version, "cvs") && !strstr(g_version, "svn")) { 317 317 printf("Please try the latest SVN version "); … … 686 686 * @param title The title of the dialog box. 687 687 * @param b The blurb (e.g. what you want the user to enter). 688 * @param output The string to put the user's answer in. 688 * @param output The string to put the user's answer in. It has to be freed by the caller 689 689 * @param maxsize The size in bytes allocated to @p output. 690 690 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel. … … 707 707 char *blurb; 708 708 char *original_contents; 709 int n = 0; 709 710 710 711 assert_string_is_neither_NULL_nor_zerolength(title); 711 712 assert(b != NULL); 712 assert(output != NULL);713 713 714 714 if (g_text_mode) { … … 716 716 ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n--> ", 717 717 title, b); 718 (void) fgets(output, maxsize, stdin);718 (void) getline(&output, &n, stdin); 719 719 if (output[strlen(output) - 1] == '\n') 720 720 output[strlen(output) - 1] = '\0'; … … 723 723 asprintf(&blurb, b); 724 724 text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0); 725 asprintf(&original_contents, output);726 output[0] = '\0'; 725 original_contents = output; 726 727 727 type_here = 728 728 newtEntry(2, newtTextboxGetNumLines(text) + 2, … … 745 745 paranoid_free(blurb); 746 746 b_res = newtRunForm(myForm); 747 strcpy(output, entry_value);747 output = entry_value; 748 748 newtPopHelpLine(); 749 749 newtFormDestroy(myForm); 750 750 newtPopWindow(); 751 751 if (b_res == b_2) { 752 strcpy(output, original_contents); 752 paranoid_free(output); 753 output = original_contents; 753 754 paranoid_free(original_contents); 754 755 return (FALSE); -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r142 r146 367 367 368 368 long itbs; 369 370 malloc_string(tmp);371 malloc_string(psz);372 369 373 370 assert(bkpinfo != NULL); … … 532 529 } 533 530 flag_set['d'] = TRUE; 534 sprintf(tmp, 531 paranoid_free(tmp); // allocation from find_tape_device_and_size 532 533 asprintf(&tmp, 535 534 "You didn't specify a tape streamer device. I'm assuming %s", 536 535 flag_val['d']); 537 536 log_to_screen(tmp); 537 paranoid_free(tmp); 538 538 percent = 0; 539 539 } … … 616 616 strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); 617 617 } 618 sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",618 asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 619 619 bkpinfo->nfs_mount); 620 620 strncpy(bkpinfo->isodir, 621 621 call_program_and_get_last_line_of_output(tmp), 622 622 MAX_STR_LEN / 4); 623 paranoid_free(tmp); 624 623 625 if (strlen(bkpinfo->isodir) < 3) { 624 626 retval++; … … 670 672 if (flag_set['N']) // exclude NFS mounts & devices 671 673 { 672 // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN); 673 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 674 psz = list_of_NFS_mounts_only(); 674 675 if (bkpinfo->exclude_paths[0]) { 675 676 strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); 676 677 } 677 678 strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); 679 paranoid_free(psz); 680 678 681 log_msg(3, "-N means we're now excluding %s", 679 682 bkpinfo->exclude_paths); … … 684 687 } 685 688 if (flag_set['b']) { 686 strcpy(psz, flag_val['b']);689 asprintf(&psz, flag_val['b']); 687 690 log_msg(1, "psz = '%s'", psz); 688 691 if (psz[strlen(psz) - 1] == 'k') { … … 692 695 itbs = atol(psz); 693 696 } 697 paranoid_free(psz); 698 694 699 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs); 695 700 log_msg(1, "Internal tape block size is now %ld bytes", itbs); … … 725 730 && !does_file_exist(bkpinfo->kernel_path)) { 726 731 retval++; 727 sprintf(tmp,732 asprintf(&tmp, 728 733 "You specified kernel '%s', which does not exist\n", 729 734 bkpinfo->kernel_path); 730 735 log_to_screen(tmp); 736 paranoid_free(tmp); 731 737 } 732 738 } … … 739 745 if (flag_set['i']) { 740 746 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); 741 sprintf(tmp, "ls -l %s", bkpinfo->isodir);747 asprintf(&tmp, "ls -l %s", bkpinfo->isodir); 742 748 if (run_program_and_log_output(tmp, FALSE)) { 743 749 fatal_error 744 750 ("output folder does not exist - please create it"); 745 751 } 752 paranoid_free(tmp); 746 753 } else if (flag_set['n']) { 747 754 strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); … … 753 760 754 761 if (flag_set['n']) { 755 sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,762 asprintf(&tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 756 763 bkpinfo->nfs_remote_dir); 757 764 if (run_program_and_log_output(tmp, FALSE)) { 758 765 retval++; 759 sprintf(tmp, 766 paranoid_free(tmp); 767 asprintf(&tmp, 760 768 "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", 761 769 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); 762 770 log_to_screen(tmp); 763 771 } 772 paranoid_free(tmp); 764 773 } 765 774 … … 802 811 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], 803 812 random() % 32768); 804 sprintf(tmp, "touch %s/.foo.dat", flag_val['T']);813 asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']); 805 814 if (run_program_and_log_output(tmp, 1)) { 806 815 retval++; … … 809 818 fatal_error("I cannot write to the tempdir you specified."); 810 819 } 811 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], 820 paranoid_free(tmp); 821 822 asprintf(&tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], 812 823 flag_val['T']); 813 824 if (run_program_and_log_output(tmp, 1)) { … … 817 828 fatal_error("I cannot write to the tempdir you specified."); 818 829 } 830 paranoid_free(tmp); 819 831 } 820 832 if (flag_set['A']) { … … 851 863 } 852 864 if (flag_set['f']) { 853 strncpy(bkpinfo->boot_device, 854 resolve_softlinks_to_get_to_actual_device_file(flag_val 855 ['f']), 865 tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']); 866 strncpy(bkpinfo->boot_device, tmp, 856 867 MAX_STR_LEN / 4); 857 868 } 858 if (flag_set['P']) {859 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);860 }861 869 if (flag_set['Q']) { 870 if (tmp == NULL) { 871 printf("-f option required when using -Q\n"); 872 finish(-1); 873 } 862 874 i = which_boot_loader(tmp); 863 875 log_msg(3, "boot loader is %c, residing at %s", i, tmp); 864 876 printf("boot loader is %c, residing at %s\n", i, tmp); 865 877 finish(0); 878 } 879 paranoid_free(tmp); 880 881 if (flag_set['P']) { 882 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 866 883 } 867 884 if (flag_set['L']) { … … 928 945 /* and finally... */ 929 946 930 paranoid_free(tmp);931 paranoid_free(psz);932 947 return (retval); 933 948 } -
trunk/mondo/mondo/mondorestore/mondo-prep.c
r127 r146 488 488 if (lvmversion == 2) { 489 489 strcpy(tmp, call_program_and_get_last_line_of_output 490 ("tail -n5 /var/log/mondo-archive.log| grep Insufficient | tail -n1"));490 ("tail -n5 "MONDO_LOGFILE" | grep Insufficient | tail -n1")); 491 491 } else { 492 492 strcpy(tmp, call_program_and_get_last_line_of_output 493 ("tail -n5 /var/log/mondo-archive.log| grep lvcreate | tail -n1"));493 ("tail -n5 "MONDO_LOGFILE" | grep lvcreate | tail -n1")); 494 494 } 495 495 for (p = tmp; *p != '\0' && !isdigit(*p); p++); … … 1833 1833 } 1834 1834 } 1835 paranoid_free(part_table_fmt); 1835 1836 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */ 1836 1837 if (partsize > 0) { -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r142 r146 3302 3302 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3303 3303 run_program_and_log_output 3304 ("ln -sf /var/log/mondo-archive.log/tmp/mondo-restore.log",3304 ("ln -sf "MONDO_LOGFILE" /tmp/mondo-restore.log", 3305 3305 FALSE); 3306 3306 -
trunk/tools/mkrpm
r63 r146 6 6 # 7 7 8 umask 022 8 9 dname=`dirname $0` 9 10 prem=`echo $dname |cut -c1` -
trunk/tools/quality
r142 r146 46 46 echo " " 47 47 echo "Splint: " 48 find . -name '*.c' -o -name '*.h' | xargs splint + gnuextensions +posixlib -Dlinux48 find . -name '*.c' -o -name '*.h' | xargs splint +posixlib -Dlinux 49 49 50 50 rm -f /tmp/mondo.quality
Note:
See TracChangeset
for help on using the changeset viewer.