Changeset 2272 in MondoRescue
- Timestamp:
- Jul 12, 2009, 2:05:33 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-files.c
r2242 r2272 47 47 /*@ buffers ***************************************************** */ 48 48 static char output[MAX_STR_LEN]; 49 char command[MAX_STR_LEN * 2];50 char tmp[MAX_STR_LEN];49 char *command = NULL; 50 char *tmp = NULL; 51 51 52 52 /*@ pointers **************************************************** */ … … 62 62 assert_string_is_neither_NULL_nor_zerolength(filename); 63 63 if (does_file_exist(filename)) { 64 sprintf(command, "md5sum \"%s\"", filename);64 mr_asprintf(&command, "md5sum \"%s\"", filename); 65 65 fin = popen(command, "r"); 66 66 if (fin) { … … 69 69 paranoid_pclose(fin); 70 70 } 71 mr_free(command); 71 72 } else { 72 sprintf(tmp, "File '%s' not found; cannot calc checksum",73 mr_asprintf(&tmp, "File '%s' not found; cannot calc checksum", 73 74 filename); 74 75 log_it(tmp); 76 mr_free(tmp); 75 77 } 76 78 if (p) { … … 126 128 127 129 /*@ buffers ***************************************************** */ 128 char command[MAX_STR_LEN * 2];130 char *command = NULL; 129 131 char incoming[MAX_STR_LEN]; 130 char tmp[MAX_STR_LEN];132 char *tmp = NULL; 131 133 132 134 /*@ long ******************************************************** */ … … 141 143 assert_string_is_neither_NULL_nor_zerolength(filename); 142 144 if (!does_file_exist(filename)) { 143 sprintf(tmp,145 mr_asprintf(&tmp, 144 146 "%s does not exist, so I cannot found the number of lines in it", 145 147 filename); 146 148 log_it(tmp); 149 mr_free(tmp); 147 150 return (0); 148 151 } 149 sprintf(command, "cat %s | wc -l", filename);152 mr_asprintf(&command, "cat %s | wc -l", filename); 150 153 if (!does_file_exist(filename)) { 154 mr_free(command); 151 155 return (-1); 152 156 } 153 157 fin = popen(command, "r"); 158 mr_free(command); 154 159 if (fin) { 155 160 if (feof(fin)) { … … 207 212 void exclude_nonexistent_files(char *inout) 208 213 { 209 char infname[MAX_STR_LEN];210 char outfname[MAX_STR_LEN];211 char tmp[MAX_STR_LEN];214 char *infname = NULL; 215 char *outfname = NULL; 216 char *tmp NULL; 212 217 char incoming[MAX_STR_LEN]; 213 218 … … 222 227 223 228 assert_string_is_neither_NULL_nor_zerolength(inout); 224 sprintf(infname, "%s.in", inout);225 sprintf(outfname, "%s", inout);226 sprintf(tmp, "cp -f %s %s", inout, infname);229 mr_asprintf(&infname, "%s.in", inout); 230 mr_asprintf(&outfname, "%s", inout); 231 mr_asprintf(&tmp, "cp -f %s %s", inout, infname); 227 232 run_program_and_log_output(tmp, FALSE); 233 mr_free(tmp); 234 228 235 if (!(fin = fopen(infname, "r"))) { 229 236 log_OS_error("Unable to openin infname"); 237 mr_free(infname); 230 238 return; 231 239 } 232 240 if (!(fout = fopen(outfname, "w"))) { 233 241 log_OS_error("Unable to openout outfname"); 242 mr_free(outfname); 234 243 return; 235 244 } 245 mr_free(outfname); 246 236 247 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); 237 248 fgets(incoming, MAX_STR_LEN, fin)) { … … 243 254 fprintf(fout, "%s\n", incoming); 244 255 } else { 245 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);256 mr_asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming); 246 257 log_it(tmp); 258 mr_free(tmp); 247 259 } 248 260 } … … 250 262 paranoid_fclose(fin); 251 263 unlink(infname); 264 mr_free(infname); 252 265 } 253 266 … … 269 282 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 270 283 { 271 char tmp[MAX_STR_LEN];272 char *command ;284 char *tmp = NULL; 285 char *command = NULL;; 273 286 274 287 if (!kernel[0]) { … … 279 292 // If we didn't get anything back, check whether mindi raised a fatal error 280 293 if (!kernel[0]) { 281 malloc_string(command); 282 strcpy(command, "grep 'Fatal error' /var/log/mindi.log"); 283 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 294 mr_asprintf(&command, "%s", "grep 'Fatal error' /var/log/mindi.log"); 295 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 284 296 if (strlen(tmp) > 1) { 285 297 popup_and_OK(tmp); 298 mr_free(tmp); 299 mr_free(command); 286 300 fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'."); 287 301 } 288 paranoid_free(command); 302 mr_free(tmp); 303 mr_free(command); 289 304 } 290 305 log_it("Calling Mindi with kernel path of '%s'", kernel); … … 301 316 ("Kernel not found. Please specify with the '-k' flag."); 302 317 } 303 sprintf(tmp, "User says kernel is at %s", kernel);318 mr_asprintf(&tmp, "User says kernel is at %s", kernel); 304 319 log_it(tmp); 320 mr_free(tmp); 305 321 } 306 322 return (0); … … 326 342 static char output[MAX_STR_LEN]; 327 343 char *incoming; 328 char *command ;344 char *command = NULL; 329 345 330 346 malloc_string(incoming); 331 malloc_string(command);332 347 incoming[0] = '\0'; 333 348 /*@******************************* */ 334 349 335 350 assert_string_is_neither_NULL_nor_zerolength(fname); 336 sprintf(command, "which %s 2> /dev/null", fname);351 mr_asprintf(&command, "which %s 2> /dev/null", fname); 337 352 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 353 mr_free(command); 338 354 if (incoming[0] == '\0') { 339 355 if (system("which file > /dev/null 2> /dev/null")) { 340 356 paranoid_free(incoming); 341 paranoid_free(command);342 357 output[0] = '\0'; 343 358 return (NULL); // forget it :) 344 359 } 345 sprintf(command,360 mr_asprintf(&command, 346 361 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", 347 362 incoming); 348 363 strcpy(incoming, 349 364 call_program_and_get_last_line_of_output(command)); 365 mr_free(command); 350 366 } 351 367 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 352 368 { 353 sprintf(command, "dirname %s 2> /dev/null", incoming);369 mr_asprintf(&command, "dirname %s 2> /dev/null", incoming); 354 370 strcpy(incoming, 355 371 call_program_and_get_last_line_of_output(command)); 372 mr_free(command); 356 373 } 357 374 strcpy(output, incoming); … … 364 381 } 365 382 paranoid_free(incoming); 366 paranoid_free(command);367 383 if (!output[0]) { 368 384 return (NULL); … … 412 428 for (; len > 0 && isdigit(datablock[len - 1]); len--); 413 429 trackno = atoi(datablock + len); 414 /*415 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);416 log_it(tmp);417 */418 430 return (trackno); 419 431 } … … 435 447 436 448 /*@ buffers ***************************************************** */ 437 char tmp[MAX_STR_LEN];438 449 char lastline[MAX_STR_LEN]; 439 char command[MAX_STR_LEN];450 char *command = NULL; 440 451 /*@ pointers **************************************************** */ 441 452 char *p; … … 448 459 && !strstr(err_log_lines[i], "% done"); i--); 449 460 if (i < 0) { 450 sprintf(command,461 mr_asprintf(&command, 451 462 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", 452 463 filename, '%'); 453 464 strcpy(lastline, 454 465 call_program_and_get_last_line_of_output(command)); 466 mr_free(command); 455 467 if (!lastline[0]) { 456 468 return (0); … … 464 476 *p = '\0'; 465 477 } 466 // log_msg(2, "lastline='%s', ", p, lastline);467 478 if (!p) { 468 479 return (0); … … 475 486 i = atoi(p); 476 487 477 sprintf(tmp, "'%s' --> %d", p, i);478 // log_to_screen(tmp);479 480 488 return (i); 481 489 } … … 495 503 /*@ buffers ***************************************************** */ 496 504 static char output[MAX_STR_LEN]; 497 static char command[MAX_STR_LEN * 2];498 static char tmp[MAX_STR_LEN];505 char *command = NULL 506 char *tmp = NULL; 499 507 500 508 /*@ pointers **************************************************** */ … … 504 512 505 513 if (!does_file_exist(filename)) { 506 sprintf(tmp, "Tring to get last line of nonexistent file (%s)",514 mr_asprintf(&tmp, "Tring to get last line of nonexistent file (%s)", 507 515 filename); 508 516 log_it(tmp); 517 mr_free(tmp); 509 518 output[0] = '\0'; 510 519 return (output); 511 520 } 512 sprintf(command, "tail -n1 %s", filename);521 mr_asprintf(&command, "tail -n1 %s", filename); 513 522 fin = popen(command, "r"); 523 mr_free(command); 524 514 525 (void) fgets(output, MAX_STR_LEN, fin); 515 526 paranoid_pclose(fin); … … 567 578 char curr_fname[1000]; 568 579 char curr_cksum[1000]; 569 char tmp[1000];580 char *tmp = NULL; 570 581 571 582 /*@ long [long] ************************************************* */ … … 581 592 start_time = get_time(); 582 593 filelist_length = length_of_file(filelist); 583 sprintf(tmp,"filelist = %s; cksumlist = %s", filelist, cksumlist);584 log_it(tmp); 594 log_it("filelist = %s; cksumlist = %s", filelist, cksumlist); 595 585 596 fin = fopen(filelist, "r"); 586 597 if (fin == NULL) { … … 601 612 stub_fname[i] = '\0'; 602 613 } 603 sprintf(tmp, "%s%s", comppath, stub_fname);614 mr_asprintf(&tmp, "%s%s", comppath, stub_fname); 604 615 strcpy(curr_fname, tmp + 1); 616 mr_free(tmp); 617 605 618 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname)); 606 619 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum); … … 617 630 time_remaining = 618 631 time_taken * 100 / (long) (percentage) - time_taken; 619 sprintf(tmp,632 mr_asprintf(&tmp, 620 633 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", 621 634 percentage, (int) (time_taken / 60), … … 624 637 (int) (time_remaining % 60), curr_fname); 625 638 log_to_screen(tmp); 639 mr_free(tmp); 626 640 } 627 641 sync(); … … 642 656 int make_hole_for_dir(char *outdir_fname) 643 657 { 644 char tmp[MAX_STR_LEN * 2];658 char *tmp = NULL; 645 659 int res = 0; 646 660 647 661 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 648 sprintf(tmp, "mkdir -p %s", outdir_fname);662 mr_asprintf(&tmp, "mkdir -p %s", outdir_fname); 649 663 res = system(tmp); 664 mr_free(tmp); 650 665 return (res); 651 666 } … … 661 676 { 662 677 /*@ buffer ****************************************************** */ 663 char command[MAX_STR_LEN * 2];678 char *command = NULL; 664 679 665 680 /*@ int ******************************************************** */ … … 671 686 assert(!strstr(outfile_fname, MNT_CDROM)); 672 687 assert(!strstr(outfile_fname, "/dev/cdrom")); 673 sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);688 mr_asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 674 689 res += system(command); 675 sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 690 mr_free(command); 691 692 mr_asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 676 693 res += system(command); 677 sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 694 mr_free(command); 695 696 mr_asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 678 697 res += system(command); 698 mr_free(command); 699 679 700 unlink(outfile_fname); 680 701 return (0); … … 731 752 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 732 753 { 733 char command[MAX_STR_LEN];734 char mountlist[MAX_STR_LEN];754 char *command = NULL; 755 char *mountlist = NULL; 735 756 char sz_res[MAX_STR_LEN]; 736 757 long file_len_K; 737 758 738 sprintf(mountlist, "%s/mountlist.txt", tmpdir);739 sprintf(command,759 mr_asprintf(&mountlist, "%s/mountlist.txt", tmpdir); 760 mr_asprintf(&command, 740 761 "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", 741 762 dev, tmpdir); 763 mr_free(mountlist); 764 742 765 log_it(command); 743 766 strcpy(sz_res, call_program_and_get_last_line_of_output(command)); 744 767 file_len_K = atol(sz_res); 745 768 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 769 mr_free(command); 770 746 771 return (file_len_K); 747 772 } … … 756 781 /*@ buffers ***************************************************** */ 757 782 char *fname; 758 char *biggielist ;759 char *comment ;760 char *tmp ;761 char *command ;783 char *biggielist = NULL; 784 char *comment = NULL; 785 char *tmp = NULL; 786 char *command = NULL; 762 787 763 788 /*@ long ******************************************************** */ … … 765 790 long file_len_K; 766 791 792 int res = 0; 793 767 794 /*@ pointers *************************************************** */ 768 795 FILE *fin = NULL; … … 771 798 772 799 malloc_string(fname); 773 malloc_string(biggielist);774 malloc_string(comment);775 malloc_string(tmp);776 malloc_string(command);777 800 log_it("Calculating size of all biggiefiles (in total)"); 778 sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);801 mr_asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 779 802 log_it("biggielist = %s", biggielist); 780 if (!(fin = fopen(biggielist, "r"))) { 781 log_OS_error 782 ("Cannot open biggielist. OK, so estimate is based on filesets only."); 803 fin = fopen(biggielist, "r"); 804 mr_free(biggielist); 805 806 if (!(fin)) { 807 log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only."); 783 808 } else { 784 809 log_msg(4, "Reading it..."); … … 793 818 fatal_error("ntfsresize not found"); 794 819 } 795 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);820 mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 796 821 log_it("command = %s", command); 797 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 822 mr_asorintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 823 mr_free(command); 824 798 825 log_it("res of it = %s", tmp); 799 826 file_len_K = atoll(tmp) / 1024L; 827 mr_free(tmp); 800 828 } else { 801 829 file_len_K = get_phys_size_of_drive(fname) * 1024L; … … 809 837 log_msg(4, "%s --> %ld K", fname, file_len_K); 810 838 } 811 sprintf(comment,839 mr_asprintf(&comment, 812 840 "After adding %s, scratchL+%ld now equals %ld", fname, 813 841 file_len_K, scratchL); 814 842 log_msg(4, comment); 843 mr_free(comment); 815 844 if (feof(fin)) { 816 845 break; … … 822 851 log_it("Finished calculating total size of all biggiefiles"); 823 852 paranoid_free(fname); 824 paranoid_free(biggielist);825 paranoid_free(comment);826 paranoid_free(tmp);827 paranoid_free(command);828 853 return (scratchL); 829 854 } … … 839 864 /*@ buffer ****************************************************** */ 840 865 char tmp[MAX_STR_LEN]; 841 char command[MAX_STR_LEN * 2];866 char *command = NULL; 842 867 long long llres; 843 868 /*@ pointers **************************************************** */ … … 847 872 /*@ end vars *************************************************** */ 848 873 849 sprintf(command, "du -sk %s", mountpt);874 mr_asprintf(&command, "du -sk %s", mountpt); 850 875 errno = 0; 851 876 fin = popen(command, "r"); … … 865 890 } 866 891 } 892 mr_free(command); 867 893 868 894 return (llres); … … 912 938 { 913 939 /*@ buffers *** */ 914 char command[MAX_STR_LEN * 2]; 915 char errorstr[MAX_STR_LEN]; 916 917 918 sprintf(command, "which %s > /dev/null 2> /dev/null", fname); 919 sprintf(errorstr, 920 "Please install '%s'. I cannot find it on your system.", 921 fname); 922 if (system(command)) { 940 char *command = NULL; 941 char *errorstr = NULL; 942 int res = 0; 943 944 mr_asprintf(&command, "which %s > /dev/null 2> /dev/null", fname); 945 res = system(command); 946 mr_free(command); 947 948 if (res) { 949 mr_asprintf(&errorstr, "Please install '%s'. I cannot find it on your system.", fname); 923 950 log_to_screen(errorstr); 924 log_to_screen925 951 mr_free(errorstr); 952 log_to_screen("There may be hyperlink at http://www.mondorescue.com which"); 926 953 log_to_screen("will take you to the relevant (missing) package."); 927 954 return (1); … … 1021 1048 { 1022 1049 /*@ Char buffers ** */ 1023 char command[MAX_STR_LEN * 2];1050 char *command = NULL; 1024 1051 char tmp[MAX_STR_LEN]; 1025 1052 char old_pwd[MAX_STR_LEN]; 1053 int res = 0; 1026 1054 1027 1055 mvaddstr_and_log_it(g_currentY, 0, … … 1032 1060 find_and_store_mondoarchives_home(g_mondo_home); 1033 1061 } 1034 sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,1062 mr_asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1035 1063 bkpinfo->scratchdir); 1036 1064 1037 1065 log_msg(4, "command = %s", command); 1038 if (run_program_and_log_output(command, 1)) { 1066 res = run_program_and_log_output(command, 1); 1067 mr_free(command); 1068 1069 if (res) { 1039 1070 fatal_error("Failed to copy Mondo's stuff to scratchdir"); 1040 1071 } … … 1046 1077 (void) getcwd(old_pwd, MAX_STR_LEN - 1); 1047 1078 chdir(bkpinfo->scratchdir); 1048 sprintf(command, "tar -zxvf %s", tmp); 1049 if (run_program_and_log_output(command, FALSE)) { 1079 mr_asprintf(&command, "tar -zxvf %s", tmp); 1080 res = run_program_and_log_output(command, FALSE); 1081 mr_free(command); 1082 1083 if (res) { 1050 1084 fatal_error("Failed to untar payload"); 1051 1085 } … … 1053 1087 } 1054 1088 1055 sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,1089 mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1056 1090 bkpinfo->scratchdir); 1057 1058 if (run_program_and_log_output(command, FALSE)) { 1091 res = run_program_and_log_output(command, FALSE); 1092 mr_free(command); 1093 1094 if (res) { 1059 1095 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1060 1096 } … … 1066 1102 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1067 1103 } 1068 sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1069 if (run_program_and_log_output(command, FALSE)) { 1104 mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1105 res = run_program_and_log_output(command, FALSE); 1106 mr_free(command); 1107 1108 if (res) { 1070 1109 fatal_error("Failed to copy mondorestore to tmpdir"); 1071 1110 } 1072 1111 1073 sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);1112 mr_asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1074 1113 paranoid_system(command); 1114 mr_free(command); 1075 1115 1076 1116 if (bkpinfo->postnuke_tarball[0]) { 1077 sprintf(command, "cp -f %s %s/post-nuke.tgz",1117 mr_asprintf(&command, "cp -f %s %s/post-nuke.tgz", 1078 1118 bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1079 if (run_program_and_log_output(command, FALSE)) { 1119 res = run_program_and_log_output(command, FALSE); 1120 mr_free(command); 1121 1122 if (res) { 1080 1123 fatal_error("Unable to copy post-nuke tarball to tmpdir"); 1081 1124 } 1082 1125 } 1083 1084 1126 1085 1127 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1102 1144 1103 1145 /*@ buffers ******** */ 1104 char nfs_dev[MAX_STR_LEN];1105 char mac_addr[MAX_STR_LEN];1106 char nfs_mount[MAX_STR_LEN];1107 char nfs_client_ipaddr[MAX_STR_LEN];1108 char nfs_client_netmask[MAX_STR_LEN];1109 char nfs_client_broadcast[MAX_STR_LEN];1110 char nfs_client_defgw[MAX_STR_LEN];1111 char nfs_server_ipaddr[MAX_STR_LEN];1112 char tmp[MAX_STR_LEN];1113 char command[MAX_STR_LEN * 2];1146 char *nfs_dev = NULL; 1147 char *mac_addr = NULL; 1148 char *nfs_mount = NULL; 1149 char *nfs_client_ipaddr = NULL; 1150 char *nfs_client_netmask = NULL; 1151 char *nfs_client_broadcast = NULL; 1152 char *nfs_client_defgw = NULL; 1153 char *nfs_server_ipaddr = NULL; 1154 char *tmp = NULL; 1155 char *command = NULL 1114 1156 1115 1157 /*@ pointers ***** */ … … 1117 1159 1118 1160 log_it("Storing NFS configuration"); 1119 strcpy(tmp, bkpinfo->nfs_mount);1161 mr_asprintf(&tmp, "%s", bkpinfo->nfs_mount); 1120 1162 p = strchr(tmp, ':'); 1121 1163 if (!p) { … … 1124 1166 } 1125 1167 *(p++) = '\0'; 1126 strcpy(nfs_server_ipaddr, tmp); 1127 strcpy(nfs_mount, p); 1168 mr_asprintf(&nfs_server_ipaddr, tmp); 1169 mr_asprintf(&nfs_mount, p); 1170 mr_free(tmp); 1128 1171 1129 1172 /* BERLIOS : there is a bug #67 here as it only considers the first NIC */ 1130 sprintf(command,1173 mr_asprintf(&command, 1131 1174 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1132 strcpy(nfs_dev, call_program_and_get_last_line_of_output(command)); 1133 sprintf(command, 1134 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1135 strcpy(nfs_client_ipaddr, 1136 call_program_and_get_last_line_of_output(command)); 1137 sprintf(command, 1138 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1139 strcpy(nfs_client_netmask, 1140 call_program_and_get_last_line_of_output(command)); 1141 sprintf(command, 1142 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1143 strcpy(nfs_client_broadcast, 1144 call_program_and_get_last_line_of_output(command)); 1145 sprintf(command, 1146 "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1147 strcpy(nfs_client_defgw, 1148 call_program_and_get_last_line_of_output(command)); 1149 sprintf(tmp, 1150 "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s", 1151 nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount); 1175 mr_asprintf(&nfs_dev, "%s", call_program_and_get_last_line_of_output(command)); 1176 mr-free(command); 1177 1178 mr_asprintf(&command, 1179 "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1180 mr_asprintf(&nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command)); 1181 mr-free(command); 1182 1183 mr_asprintf(&command, 1184 "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1185 mr_asprintf(&nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command)); 1186 mr-free(command); 1187 1188 mr_asprintf(&command, 1189 "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1190 mr_asprintf(&nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command)); 1191 mr-free(command); 1192 1193 mr_asprintf(&command, 1194 "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1195 mr_asprintf(&nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command)); 1196 mr-free(command); 1197 1152 1198 if (strlen(nfs_dev) < 2) { 1153 1199 fatal_error … … 1165 1211 if (!strncmp(nfs_dev, "bond", 4) || !strncmp(nfs_dev, "alb", 3) || !strncmp(nfs_dev, "aft", 3)) { 1166 1212 log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev); 1167 sprintf(command, 1168 "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev); 1169 strcpy(mac_addr, call_program_and_get_last_line_of_output(command)); 1170 sprintf(command, 1171 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev); 1172 strcpy(nfs_dev, call_program_and_get_last_line_of_output(command)); 1213 mr_asprintf(&command, 1214 "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev); 1215 mr_asprintf(&mac_addr, "%s", call_program_and_get_last_line_of_output(command)); 1216 mr-free(command); 1217 1218 mr_asprintf(&command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev); 1219 mr_free(mac_addr); 1220 mr_free(nfs_dev); 1221 1222 mr_asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command)); 1223 mr-free(command); 1224 1173 1225 log_to_screen("Replacing it with %s\n", nfs_dev); 1174 1226 } 1175 1227 1176 sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);1228 mr_asprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir); 1177 1229 write_one_liner_data_file(tmp, nfs_dev); 1178 1179 sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1230 mr_free(nfs_dev); 1231 mr_free(tmp); 1232 1233 mr_asprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1180 1234 write_one_liner_data_file(tmp, nfs_client_ipaddr); 1181 sprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1235 mr_free(nfs_client_ipaddr); 1236 mr_free(tmp); 1237 1238 mr_asprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir); 1182 1239 write_one_liner_data_file(tmp, nfs_client_netmask); 1183 sprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1240 mr_free(nfs_client_netmask); 1241 mr_free(tmp); 1242 1243 mr_asprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir); 1184 1244 write_one_liner_data_file(tmp, nfs_client_broadcast); 1185 sprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1245 mr_free(nfs_client_broadcast); 1246 mr_free(tmp); 1247 1248 mr_asprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir); 1186 1249 write_one_liner_data_file(tmp, nfs_client_defgw); 1187 sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1250 mr_free(nfs_client_defgw); 1251 mr_free(tmp); 1252 1253 mr_asprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1188 1254 write_one_liner_data_file(tmp, nfs_server_ipaddr); 1189 sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1255 mr_free(tmp); 1256 mr_free(nfs_server_ipaddr); 1257 1258 mr_asprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1190 1259 write_one_liner_data_file(tmp, bkpinfo->nfs_mount); 1191 sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1260 mr_free(tmp); 1261 mr_free(nfs_mount); 1262 1263 mr_asprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1192 1264 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir); 1193 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1265 mr_free(tmp); 1266 1267 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 1194 1268 write_one_liner_data_file(tmp, bkpinfo->prefix); 1269 mr_free(tmp); 1270 1195 1271 log_it("Finished storing NFS configuration"); 1196 1272 } … … 1221 1297 { 1222 1298 /*@ buffers *************** */ 1223 char tmp[MAX_STR_LEN];1299 char *tmp = NULL; 1224 1300 char *mds = NULL; 1225 1301 … … 1250 1326 if (scratchLL <= 1) { 1251 1327 mds = media_descriptor_string(bkpinfo->backup_media_type); 1252 sprintf(tmp, 1253 "Your backup will probably occupy a single %s. Maybe two.", mds); 1328 mr_asprintf(&tmp, "Your backup will probably occupy a single %s. Maybe two.", mds); 1254 1329 mr_free(mds); 1255 1330 } else if (scratchLL > 4) { 1256 sprintf(tmp,1331 mr_asprintf(&tmp, 1257 1332 "Your backup will occupy one meeeeellion media! (maybe %s)", 1258 1333 number_to_text((int) (scratchLL + 1))); 1259 1334 } else { 1260 sprintf(tmp, "Your backup will occupy approximately %s media.",1335 mr_asprintf(&tmp, "Your backup will occupy approximately %s media.", 1261 1336 number_to_text((int) (scratchLL + 1))); 1262 1337 } … … 1264 1339 log_to_screen(tmp); 1265 1340 } 1341 mr_free(tmp); 1266 1342 } 1267 1343 … … 1298 1374 { 1299 1375 char do_not_compress_these[MAX_STR_LEN]; 1300 char tmp[MAX_STR_LEN];1376 char *tmp = NULL; 1301 1377 char *p; 1302 1378 char *q = NULL; … … 1307 1383 } 1308 1384 1309 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);1385 mr_asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home); 1310 1386 if (!does_file_exist(tmp)) { 1387 mr_free(tmp); 1311 1388 return (FALSE); 1312 1389 } 1313 1390 /* BERLIOS: This is just plain WRONG !! */ 1314 1391 strcpy(do_not_compress_these,last_line_of_file(tmp)); 1392 mr_free(tmp); 1315 1393 1316 1394 for (p = do_not_compress_these; p != NULL; p++) { 1317 strcpy(tmp, p);1395 mr_asprintf(&tmp, "%s", p); 1318 1396 if (strchr(tmp, ' ')) { 1319 1397 *(strchr(tmp, ' ')) = '\0'; 1320 1398 } 1321 1399 if (!strcmp(q, tmp)) { 1400 mr_free(tmp); 1322 1401 return (TRUE); 1323 1402 } … … 1325 1404 break; 1326 1405 } 1406 mr_free(tmp); 1327 1407 } 1328 1408 return (FALSE); 1329 1409 } 1330 1331 1410 1332 1411 … … 1354 1433 { 1355 1434 FILE *fout; 1356 char *tmp ;1435 char *tmp = NULL; 1357 1436 int retval = 0; 1358 1437 1359 malloc_string(tmp);1360 1438 if ((fout = fopen(outfile, "w"))) { 1361 1439 fprintf(fout, … … 1363 1441 paranoid_fclose(fout); 1364 1442 log_msg(2, "Created %s", outfile); 1365 sprintf(tmp, "chmod +x %s", outfile);1443 mr_asprintf(&tmp, "chmod +x %s", outfile); 1366 1444 paranoid_system(tmp); 1445 mr_free(tmp); 1367 1446 retval = 0; 1368 1447 } else { 1369 1448 retval = 1; 1370 1449 } 1371 paranoid_free(tmp);1372 1450 return (retval); 1373 1451 }
Note:
See TracChangeset
for help on using the changeset viewer.