Changeset 120 in MondoRescue
- Timestamp:
- Nov 9, 2005, 2:44:43 AM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/AUTHORS
r30 r120 1 Hugo Rabson <hugorabson@msn.com> 1 mondorescue is copyrighted under the GPL by the following authors: 2 3 Hugo Rabson <hugo.rabson@mondorescue.org> 2 4 Jesse Keating <hosting@j2solutions.net> 3 5 Stan Benoit <troff@nakedsoul.org> 4 6 Mikael Hultgren <mikael.hultgren@gmx.net> 7 Bruno Cornec <bcornec@users.berlios.de> 8 Andree Leidenfrost <andree@users.berlios.de> -
trunk/mondo/mondo/common/libmondo-filelist-EXT.h
r59 r120 5 5 extern void free_filelist(struct s_node *filelist); 6 6 extern int get_last_filelist_number(struct s_bkpinfo *bkpinfo); 7 /* BERLIOS: Useless ? 7 8 extern int add_string_at_node(struct s_node *startnode, 8 9 char *string_to_add); 10 */ 9 11 extern struct s_node *load_filelist(char *filelist_fname); 10 12 extern void reload_filelist(struct s_node *filelist); -
trunk/mondo/mondo/common/libmondo-filelist.c
r87 r120 2 2 3 3 for subroutines which manipulate the filelist 4 5 4 */ 6 5 … … 64 63 65 64 66 67 68 69 65 /** 70 66 * @addtogroup filelistGroup … … 86 82 char *filelist; 87 83 char *tempfile; 88 char *cksumlist;89 char *tmp;90 84 long noof_sets; 91 85 … … 97 91 int i, retval = 0; 98 92 99 malloc_string(dev);100 malloc_string(filelist);101 malloc_string(tempfile);102 malloc_string(cksumlist);103 malloc_string(tmp);104 93 mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets"); 105 94 … … 114 103 { i=0; log_to_screen ("This will take more time. Please be patient."); } 115 104 */ 116 sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 117 sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir); 105 asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 118 106 if (!does_file_exist(filelist)) { 119 107 log_it("filelist %s not found", filelist); … … 124 112 chop_filelist(filelist, bkpinfo->tmpdir, 125 113 bkpinfo->optimal_set_size); 114 paranoid_free(filelist); 115 126 116 estimate_noof_media_required(bkpinfo, noof_sets); // for cosmetic purposes 127 117 128 sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);118 asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir); 129 119 if (!(fout = fopen(tempfile, "a"))) { 130 120 log_OS_error("Cannot append to biggielist"); 131 121 retval++; 132 goto end_of_func;133 }122 } 123 paranoid_free(tempfile); 134 124 log_it(bkpinfo->image_devs); 135 125 … … 137 127 138 128 while (ptr && *ptr) { 139 strcpy(dev, ptr);129 asprintf(&dev, ptr); 140 130 log_it("Examining imagedev %s", dev); 141 131 for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++); … … 146 136 fprintf(fout, "%s\n", dev); 147 137 log_it("Adding '%s' to biggielist", dev); 138 paranoid_free(dev); 139 148 140 if ((ptr = strchr(ptr, ' '))) { 149 141 ptr++; … … 153 145 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 154 146 155 end_of_func:156 paranoid_free(filelist);157 paranoid_free(tempfile);158 paranoid_free(cksumlist);159 paranoid_free(dev);160 paranoid_free(tmp);161 147 return (retval); 162 148 } … … 171 157 172 158 log_msg(1, "Sorting file %s", orig_fname); 173 malloc_string(tmp_fname); 174 malloc_string(command); 175 sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768), 159 asprintf(&tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768), 176 160 (int) (random() % 32768), (int) (random() % 32768)); 177 161 … … 180 164 } // no sense in trying to sort an empty file 181 165 182 sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,166 asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, 183 167 MONDO_LOGFILE); 184 168 retval = system(command); 169 paranoid_free(command); 170 185 171 if (retval) { 186 172 log_msg(2, "Failed to sort %s - oh dear", orig_fname); … … 188 174 log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now", 189 175 orig_fname, tmp_fname, orig_fname); 190 sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);176 asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname); 191 177 retval += run_program_and_log_output(command, 2); 178 paranoid_free(command); 179 192 180 if (retval) { 193 181 log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, … … 198 186 } 199 187 paranoid_free(tmp_fname); 200 paranoid_free(command);201 188 log_msg(1, "Finished sorting file %s", orig_fname); 202 189 return (retval); 203 190 } 204 205 191 206 192 … … 228 214 /*@ int **************************************** */ 229 215 int i; 216 int n = 0; 230 217 long curr_set_no; 231 218 … … 233 220 char *outfname; 234 221 char *biggie_fname; 235 char *incoming ;222 char *incoming = NULL; 236 223 char *tmp; 237 char *acl_fname;238 char *xattr_fname;239 224 240 225 /*@ pointers *********************************** */ … … 245 230 /*@ structures ********************************* */ 246 231 struct stat buf; 247 int err = 0;248 249 malloc_string(outfname);250 malloc_string(biggie_fname);251 incoming = malloc(MAX_STR_LEN * 2);252 malloc_string(tmp);253 malloc_string(acl_fname);254 malloc_string(xattr_fname);255 232 256 233 assert_string_is_neither_NULL_nor_zerolength(filelist); … … 272 249 curr_set_no = 0; 273 250 curr_set_size = 0; 274 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);275 sprintf(biggie_fname, "%s/biggielist.txt", outdir);251 asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 252 asprintf(&biggie_fname, "%s/biggielist.txt", outdir); 276 253 log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname); 277 254 if (!(fbig = fopen(biggie_fname, "w"))) { 278 255 log_OS_error("Cannot openout biggie_fname"); 279 err++; 280 goto end_of_func; 256 return(0); 281 257 } 282 258 if (!(fout = fopen(outfname, "w"))) { 283 259 log_OS_error("Cannot openout outfname"); 284 err++; 285 goto end_of_func; 286 } 287 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin); 260 return(0); 261 } 262 (void) fgets(&incoming, &n, fin); 288 263 while (!feof(fin)) { 289 264 lino++; … … 292 267 i = 0; 293 268 } 269 /* BERLIOS: Useless with getline 294 270 if (i > MAX_STR_LEN - 1) { 295 271 incoming[MAX_STR_LEN - 30] = '\0'; … … 297 273 err++; 298 274 } 275 */ 299 276 if (incoming[i] < 32) { 300 277 incoming[i] = '\0'; … … 317 294 paranoid_fclose(fout); 318 295 sort_file(outfname); 296 paranoid_free(outfname); 297 319 298 curr_set_no++; 320 299 curr_set_size = 0; 321 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);300 asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 322 301 if (!(fout = fopen(outfname, "w"))) { 323 302 log_OS_error("Unable to openout outfname"); 324 err++; 325 goto end_of_func; 303 return(0); 326 304 } 327 sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);328 305 update_evalcall_form((int) (lino * 100 / noof_lines)); 329 /* if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */330 306 } 331 307 } 332 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);308 (void) getline(&incoming, &n, fin); 333 309 } 334 310 paranoid_fclose(fin); … … 343 319 sort_file(outfname); 344 320 sort_file(biggie_fname); 345 sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir); 346 sprintf(tmp, "%ld", curr_set_no); 321 paranoid_free(biggie_fname); 322 paranoid_free(outfname); 323 324 asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir); 325 asprintf(&tmp, "%ld", curr_set_no); 347 326 if (write_one_liner_data_file(outfname, tmp)) { 348 327 log_OS_error 349 328 ("Unable to echo write one-liner to LAST-FILELIST-NUMBER"); 350 err = 1; 351 } 329 return(0); 330 } 331 paranoid_free(outfname); 332 paranoid_free(tmp); 333 352 334 if (curr_set_no == 0) { 353 sprintf(tmp, "Only one fileset. Fine.");335 asprintf(&tmp, "Only one fileset. Fine."); 354 336 } else { 355 sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);337 asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1); 356 338 } 357 339 log_msg(1, tmp); 340 paranoid_free(tmp); 358 341 close_evalcall_form(); 359 342 /* This is to work around an obscure bug in Newt; open a form, close it, … … 369 352 } 370 353 #endif 371 end_of_func: 372 paranoid_free(outfname); 373 paranoid_free(biggie_fname); 374 paranoid_free(incoming); 375 paranoid_free(tmp); 376 paranoid_free(acl_fname); 377 paranoid_free(xattr_fname); 378 return (err ? 0 : curr_set_no + 1); 379 } 380 381 382 354 return (curr_set_no + 1); 355 } 383 356 384 357 … … 437 410 { 438 411 FILE *pattr; 439 char *tmp; 412 char *tmp = NULL; 413 int n = 0; 414 440 415 pattr = popen(syscall, "r"); 441 416 if (!pattr) { … … 448 423 return (2); 449 424 } 450 malloc_string(tmp); 451 for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr); 452 fgets(tmp, MAX_STR_LEN, pattr)) { 425 for (getline(&tmp, &n, pattr); !feof(pattr); 426 getline(&tmp, &n, pattr)) { 453 427 fputs(tmp, pout); 454 428 } … … 457 431 return (0); 458 432 } 459 460 433 461 434 … … 467 440 char *pout_command; 468 441 char *syscall; 469 char *file_to_analyze; 442 char *tmp; 443 char *file_to_analyze = NULL; 470 444 int i; 445 int n = 0; 471 446 472 447 if (!(fin = fopen(filelist, "r"))) { … … 474 449 return (1); 475 450 } 476 malloc_string(pout_command); 477 sprintf(pout_command, "gzip -c1 > %s", auxlist_fname); 451 asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname); 478 452 if (!(pout = popen(pout_command, "w"))) { 479 453 log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname); … … 482 456 return (4); 483 457 } 484 malloc_string(syscall);485 malloc_string(file_to_analyze); 486 for ( fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);487 fgets(file_to_analyze, MAX_STR_LEN, fin)) {458 paranoid_free(pout_command); 459 460 for (getline(&file_to_analyze, &n, fin); !feof(fin); 461 getline(&file_to_analyze, &n, fin)) { 488 462 i = strlen(file_to_analyze); 489 463 if (i > 0 && file_to_analyze[i - 1] < 32) { … … 491 465 } 492 466 log_msg(8, "Analyzing %s", file_to_analyze); 493 sprintf(syscall, syscall_sprintf, file_to_analyze); 494 strcat(syscall, " 2>> /dev/null"); // " MONDO_LOGFILE); 467 asprintf(&tmp, "%s 2>> /dev/null", syscall_sprintf); 468 asprintf(&syscall, tmp, file_to_analyze); 469 paranoid_free(tmp); 495 470 call_exe_and_pipe_output_to_fd(syscall, pout); 471 paranoid_free(syscall); 496 472 } 497 473 paranoid_fclose(fin); 498 474 paranoid_pclose(pout); 499 475 paranoid_free(file_to_analyze); 500 paranoid_free(syscall);501 paranoid_free(pout_command);502 476 return (0); 503 477 } … … 509 483 int retval = 0; 510 484 511 malloc_string(command); 512 sprintf(command, "touch %s", facl_fname); 485 asprintf(&command, "touch %s", facl_fname); 513 486 run_program_and_log_output(command, 8); 487 paranoid_free(command); 488 514 489 if (find_home_of_exe("getfacl")) { 515 490 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 516 sprintf(command,491 asprintf(&command, 517 492 "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s", 518 493 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE); 519 494 iamhere(command); 520 495 retval = system(command); 521 }522 paranoid_free(command);496 paranoid_free(command); 497 } 523 498 return (retval); 524 499 } … … 530 505 int retval = 0; 531 506 532 malloc_string(command); 533 sprintf(command, "touch %s", fattr_fname); 507 asprintf(&command, "touch %s", fattr_fname); 534 508 run_program_and_log_output(command, 8); 509 paranoid_free(command); 510 535 511 if (find_home_of_exe("getfattr")) { 536 512 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary … … 539 515 fattr_fname); 540 516 } 541 paranoid_free(command);542 517 return (retval); 543 518 } … … 565 540 566 541 567 568 542 int set_EXAT_list(char *orig_msklist, char *original_exat_fname, 569 543 char *executable) 570 544 { 571 545 const int my_depth = 8; 572 char *command, *syscall_pin, *syscall_pout, *incoming; 573 char *current_subset_file, *current_master_file, *masklist; 546 char *command, *syscall_pin, *syscall_pout; 547 char *incoming = NULL; 548 char *current_subset_file = NULL; 549 char *current_master_file, *masklist; 574 550 int retval = 0; 575 551 int i; 552 int n = 0; 576 553 char *p, *q; 577 554 FILE *pin, *pout, *faclin; 578 555 579 malloc_string(command);580 556 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 581 557 original_exat_fname, executable); … … 584 560 log_msg(1, 585 561 "No masklist provided. I shall therefore set ALL attributes."); 586 sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s",562 asprintf(&command, "cat %s | gzip -dc | %s --restore - 2>> %s", 587 563 original_exat_fname, executable, MONDO_LOGFILE); 588 564 log_msg(1, "command = %s", command); … … 596 572 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 597 573 original_exat_fname); 598 paranoid_free(command);599 574 return (0); 600 575 } 601 malloc_string(incoming); 602 malloc_string(masklist); 603 malloc_string(current_subset_file); 604 malloc_string(current_master_file); 605 malloc_string(syscall_pin); 606 malloc_string(syscall_pout); 607 sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768), 576 asprintf(&masklist, "/tmp/%d.%d.mask", (int) (random() % 32768), 608 577 (int) (random() % 32768)); 609 sprintf(command, "cp -f %s %s", orig_msklist, masklist);578 asprintf(&command, "cp -f %s %s", orig_msklist, masklist); 610 579 run_program_and_log_output(command, 1); 580 paranoid_free(command); 581 611 582 sort_file(masklist); 612 current_subset_file[0] = current_master_file[0] = '\0'; 613 sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname); 614 sprintf(syscall_pout, "%s --restore - 2>> %s", executable, 583 asprintf(&syscall_pin, "cat %s | gzip -dc", original_exat_fname); 584 asprintf(&syscall_pout, "%s --restore - 2>> %s", executable, 615 585 MONDO_LOGFILE); 616 586 … … 622 592 return (1); 623 593 } 594 paranoid_free(syscall_pout); 595 624 596 pin = popen(syscall_pin, "r"); 625 597 if (!pin) { … … 628 600 return (1); 629 601 } 602 paranoid_free(syscall_pin); 603 630 604 faclin = fopen(masklist, "r"); 631 605 if (!faclin) { … … 637 611 // printf("Hi there. Starting the loop\n"); 638 612 639 fgets(current_subset_file, MAX_STR_LEN, faclin);640 fgets(incoming, MAX_STR_LEN, pin);613 getline(¤t_subset_file, &n, faclin); 614 getline(&incoming, &n, pin); 641 615 while (!feof(pin) && !feof(faclin)) { 642 616 // printf("incoming = %s", incoming); 643 617 644 strcpy(current_master_file, incoming + 8);618 asprintf(¤t_master_file, incoming + 8); 645 619 646 620 p = current_subset_file; … … 670 644 if (i < 0) { // read another subset file in. 671 645 log_msg(my_depth, "Reading next subset line in\n\n"); 672 fgets(current_subset_file, MAX_STR_LEN, faclin);646 getline(¤t_subset_file, &n, faclin); 673 647 continue; 674 648 } … … 677 651 fputs(incoming, pout); 678 652 } 679 fgets(incoming, MAX_STR_LEN, pin);653 getline(&incoming, &n, pin); 680 654 if (!i) { 681 655 log_msg(my_depth, "Copying master %s", q); … … 690 664 fputs(incoming, pout); 691 665 } 692 fgets(incoming, MAX_STR_LEN, pin);666 getline(&incoming, &n, pin); 693 667 } 694 668 if (!i) { 695 fgets(current_subset_file, MAX_STR_LEN, faclin); 696 } 697 } 669 getline(¤t_subset_file, &n, faclin); 670 } 671 paranoid_free(current_master_file); 672 } 673 paranoid_free(current_subset_file); 674 698 675 while (!feof(pin)) { 699 fgets(incoming, MAX_STR_LEN, pin); 700 } 676 getline(&incoming, &n, pin); 677 } 678 paranoid_free(incoming); 701 679 fclose(faclin); 702 680 pclose(pin); … … 706 684 707 685 unlink(masklist); 708 paranoid_free(current_subset_file);709 paranoid_free(current_master_file);710 paranoid_free(syscall_pout);711 paranoid_free(syscall_pin);712 686 paranoid_free(masklist); 713 paranoid_free(incoming); 714 paranoid_free(command); 687 715 688 return (retval); 716 689 } … … 728 701 return (set_EXAT_list(masklist, acl_fname, "setfacl")); 729 702 } 730 731 /*732 if (find_home_of_exe("setfattr"))733 {734 sprintf(command, "cat %s | gzip -dc | setfattr --restore - 2>> %s", acl_fname, MONDO_LOGFILE);735 log_msg(1, "command = %s", command);736 retval = system(command);737 }738 paranoid_free(acl_subset_fname);739 paranoid_free(syscall_pin);740 paranoid_free(command);741 return(retval);742 */743 744 745 746 747 703 748 704 … … 757 713 /*@ buffers ***************************************************** */ 758 714 char val_sz[MAX_STR_LEN]; 759 char cfg_fname[MAX_STR_LEN]; 760 /* char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */ 715 char *cfg_fname; 761 716 762 717 /*@ long ******************************************************** */ … … 767 722 assert(bkpinfo != NULL); 768 723 769 sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);724 asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir); 770 725 read_cfg_var(cfg_fname, "last-filelist-number", val_sz); 771 726 val_i = atoi(val_sz); … … 773 728 val_i = 500; 774 729 } 730 paranoid_free(cfg_fname); 775 731 return (val_i); 776 732 } … … 784 740 * @bug I don't understand this function. Would someone care to explain it? 785 741 */ 742 786 743 int add_string_at_node(struct s_node *startnode, char *string_to_add) 787 744 { 788 745 789 790 /*@ int ******************************************************** */791 746 int noof_chars; 792 747 int i; 793 748 int res; 794 749 795 /*@ sturctures ************************************************* */796 750 struct s_node *node, *newnode; 797 751 798 /*@ char ****************************************************** */799 752 char char_to_add; 800 801 /*@ bools ****************************************************** */802 753 803 754 const bool sosodef = FALSE; … … 813 764 } 814 765 815 noof_chars = strlen(string_to_add) + 1; / * we include the '\0' */816 817 /* walk across tree if necessary */ 766 noof_chars = strlen(string_to_add) + 1; // we include the '\0' 767 768 // walk across tree if necessary 818 769 node = startnode; 819 770 char_to_add = string_to_add[0]; … … 824 775 } 825 776 826 /* walk down tree if appropriate */ 777 // walk down tree if appropriate 827 778 if (node->down != NULL && node->ch == char_to_add) { 828 779 log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add); … … 838 789 } 839 790 840 /* add here */ 791 // add here 841 792 if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) { 842 793 log_to_screen("failed to malloc"); … … 866 817 return (0); 867 818 } 868 // add the rest819 // add the rest 869 820 log_msg(6, "Adding remaining chars ('%s')", string_to_add + 1); 870 821 for (i = 1; i < noof_chars; i++) { … … 890 841 891 842 892 893 894 843 /** 895 844 * Load a filelist into a <tt>struct s_node</tt>. … … 908 857 909 858 /*@ buffers **************************************************** */ 910 char command_to_open_fname[MAX_STR_LEN];911 char fname[MAX_STR_LEN];912 char tmp[MAX_STR_LEN];859 char *command_to_open_fname; 860 char *fname = NULL; 861 char *tmp; 913 862 int pos_in_fname; 863 int n = 0; 914 864 /*@ int ******************************************************** */ 915 865 int percentage; … … 926 876 } 927 877 log_to_screen("Loading filelist"); 928 sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);929 sprintf(tmp, "zcat %s | wc -l", filelist_fname);878 asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname); 879 asprintf(&tmp, "zcat %s | wc -l", filelist_fname); 930 880 log_msg(6, "tmp = %s", tmp); 931 881 lines_in_filelist = 932 882 atol(call_program_and_get_last_line_of_output(tmp)); 883 paranoid_free(tmp); 884 933 885 if (lines_in_filelist < 3) { 934 886 log_to_screen("Warning - surprisingly short filelist."); … … 949 901 return (NULL); 950 902 } 903 paranoid_free(command_to_open_fname); 904 951 905 open_evalcall_form("Loading filelist from disk"); 952 for ( fgets(fname, MAX_STR_LEN, pin); !feof(pin);953 fgets(fname, MAX_STR_LEN, pin)) {906 for (getline(&fname, &n, pin); !feof(pin); 907 getline(&fname, &n, pin)) { 954 908 if ((fname[strlen(fname) - 1] == 13 955 909 || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) { 956 910 fname[strlen(fname) - 1] = '\0'; 957 911 } 958 // strip_spaces (fname);959 912 if (!strlen(fname)) { 960 913 continue; … … 964 917 continue; 965 918 } 966 strcpy(tmp, fname);919 asprintf(&tmp, fname); 967 920 tmp[pos_in_fname] = '\0'; 968 921 if (strlen(tmp)) { 969 922 add_string_at_node(filelist, tmp); 970 923 } 924 paranoid_free(tmp); 971 925 } 972 926 add_string_at_node(filelist, fname); … … 976 930 } 977 931 } 932 paranoid_free(fname); 978 933 paranoid_pclose(pin); 979 934 close_evalcall_form(); … … 1020 975 1021 976 1022 1023 1024 977 /** 1025 978 * Reset the filelist to the state it was when it was loaded. This does not … … 1034 987 toggle_all_root_dirs_on(filelist); 1035 988 } 1036 1037 989 1038 990 … … 1100 1052 1101 1053 1102 1103 1054 /** 1104 1055 * Toggle all root dirs on. … … 1168 1119 /*@ buffers **************************************************** */ 1169 1120 static char current_filename[MAX_STR_LEN]; 1170 1171 /* char tmp[MAX_STR_LEN+2]; */1172 1121 1173 1122 /*@ end vars *************************************************** */ … … 1223 1172 } 1224 1173 1174 1225 1175 /** 1226 1176 * Toggle whether a path is selected. … … 1243 1193 /*@ buffers ***************************************************** */ 1244 1194 static char current_filename[MAX_STR_LEN]; 1245 char tmp[MAX_STR_LEN + 2];1246 1195 1247 1196 /*@ end vars *************************************************** */ … … 1266 1215 || current_filename[j] == '\0') { 1267 1216 node->selected = on_or_off; 1268 sprintf(tmp, "%s is now %s\n", current_filename,1269 (on_or_off ? "ON" : "OFF"));1270 1217 } 1271 1218 } … … 1305 1252 1306 1253 1307 1308 1309 1310 1311 1312 /**1313 * The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().1314 */1315 char *g_skeleton_filelist = NULL;1316 1317 1254 /** 1318 1255 * Number of entries in the skeleton filelist. 1319 1256 */ 1320 1257 long g_skeleton_entries = 0; 1258 1321 1259 1322 1260 /** … … 1388 1326 */ 1389 1327 int open_and_list_dir(char *dir, char *sth, FILE * fout, 1390 time_t time_of_last_full_backup )1328 time_t time_of_last_full_backup, char *skeleton_filelist) 1391 1329 { 1392 1330 DIR *dip; 1393 1331 struct dirent *dit; 1394 1332 struct stat statbuf; 1395 char new[MAX_STR_LEN];1333 char *new; 1396 1334 char *tmp; 1397 char *sth_B;1398 1335 static int percentage = 0; 1399 char *ith_B;1400 1336 char *skip_these; 1401 1337 char *new_with_spaces; … … 1411 1347 time_t this_time; 1412 1348 1413 malloc_string(tmp);1414 malloc_string(sth_B);1415 malloc_string(ith_B);1416 malloc_string(new_with_spaces);1417 1349 p = strrchr(dir, '/'); 1418 1350 if (p) { … … 1423 1355 1424 1356 if (!depth) { 1425 malloc_string(name_of_evalcall_form);1426 1357 malloc_string(find_skeleton_marker); 1427 1358 #if linux 1428 1359 // 2.6 has /sys as a proc-type thing -- must be excluded 1429 sprintf(tmp,1360 asprintf(&tmp, 1430 1361 "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null", 1431 dir, MAX_SKEL_DEPTH, g_skeleton_filelist);1362 dir, MAX_SKEL_DEPTH, skeleton_filelist); 1432 1363 #else 1433 1364 // On BSD, for example, /sys is the kernel sources -- don't exclude 1434 sprintf(tmp,1365 asprintf(&tmp, 1435 1366 "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null", 1436 dir, MAX_SKEL_DEPTH, g_skeleton_filelist);1367 dir, MAX_SKEL_DEPTH, skeleton_filelist); 1437 1368 #endif 1438 1369 system(tmp); 1439 sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist); 1370 paranoid_free(tmp); 1371 1372 asprintf(&tmp, "wc -l %s | awk '{print $1;}'", skeleton_filelist); 1440 1373 g_skeleton_entries = 1441 1374 1 + atol(call_program_and_get_last_line_of_output(tmp)); 1442 sprintf(name_of_evalcall_form, "Making catalog of %s", dir); 1375 paranoid_free(tmp); 1376 1377 asprintf(&name_of_evalcall_form, "Making catalog of %s", dir); 1443 1378 open_evalcall_form(name_of_evalcall_form); 1444 1379 find_skeleton_marker[0] = '\0'; … … 1450 1385 sprintf(find_skeleton_marker, 1451 1386 "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir, 1452 g_skeleton_filelist, g_skeleton_filelist);1387 skeleton_filelist, skeleton_filelist); 1453 1388 // log_msg(0, "fsm = %s", find_skeleton_marker); 1454 1389 if (!system(find_skeleton_marker)) { … … 1458 1393 // log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage); 1459 1394 sprintf(find_skeleton_marker, "mv -f %s.new %s", 1460 g_skeleton_filelist, g_skeleton_filelist);1395 skeleton_filelist, skeleton_filelist); 1461 1396 // log_msg(6, "fsm = %s", find_skeleton_marker); 1462 1397 run_program_and_log_output(find_skeleton_marker, 8); … … 1466 1401 #ifndef _XWIN 1467 1402 if (!g_text_mode) { 1468 sprintf(tmp, "Reading %-68s", dir);1403 asprintf(&tmp, "Reading %-68s", dir); 1469 1404 newtDrawRootText(0, g_noof_rows - 3, tmp); 1405 paranoid_free(tmp); 1470 1406 } 1471 1407 #endif … … 1479 1415 // log_msg(0, "Cataloguing %s", dir); 1480 1416 if (sth[0] == ' ') { 1481 skip_these = sth;1417 asprintf(&skip_these, "%s", sth); 1482 1418 } else { 1483 skip_these = sth_B; 1484 sprintf(skip_these, " %s ", sth); 1485 } 1486 sprintf(new_with_spaces, " %s ", dir); 1419 asprintf(&skip_these, " %s ", sth); 1420 } 1421 asprintf(&new_with_spaces, " %s ", dir); 1487 1422 if ((dip = opendir(dir)) == NULL) { 1488 1423 log_OS_error("opendir"); … … 1493 1428 while ((dit = readdir(dip)) != NULL) { 1494 1429 i++; 1495 strcpy(new, dir);1496 1430 if (strcmp(dir, "/")) { 1497 strcat(new, "/"); 1431 asprintf(&new, "%s/%s", dir, dit->d_name); 1432 } else { 1433 asprintf(&new, "%s%s", dir, dit->d_name); 1498 1434 } 1499 strcat(new, dit->d_name); 1435 paranoid_free(new_with_spaces); 1436 asprintf(&new_with_spaces, " %s ", new); 1437 /* BERLIOS: Old code 1500 1438 new_with_spaces[0] = ' '; 1501 1439 strcpy(new_with_spaces + 1, new); 1502 1440 strcat(new_with_spaces, " "); 1441 */ 1503 1442 if (strstr(skip_these, new_with_spaces)) { 1504 1443 fprintf(fout, "%s\n", new); … … 1508 1447 && S_ISDIR(statbuf.st_mode)) { 1509 1448 open_and_list_dir(new, skip_these, fout, 1510 time_of_last_full_backup );1449 time_of_last_full_backup, skeleton_filelist); 1511 1450 } else { 1512 1451 if (time_of_last_full_backup == 0 … … 1517 1456 counter = 0; 1518 1457 uberctr++; 1519 sprintf(tmp, " %c ",1458 asprintf(&tmp, " %c ", 1520 1459 special_dot_char(uberctr)); 1521 1460 #ifndef _XWIN … … 1525 1464 newtRefresh(); 1526 1465 } 1466 paranoid_free(tmp); 1527 1467 #endif 1528 1468 } … … 1531 1471 } 1532 1472 } 1533 } 1534 } 1473 paranoid_free(new); 1474 } 1475 } 1476 paranoid_free(new_with_spaces); 1477 paranoid_free(skip_these); 1478 1535 1479 if (dip) { 1536 1480 if (closedir(dip) == -1) { … … 1543 1487 paranoid_free(name_of_evalcall_form); 1544 1488 paranoid_free(find_skeleton_marker); 1545 unlink( g_skeleton_filelist);1489 unlink(skeleton_filelist); 1546 1490 log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries); 1547 1491 } 1548 paranoid_free(tmp);1549 paranoid_free(sth_B);1550 paranoid_free(ith_B);1551 paranoid_free(new_with_spaces);1552 1492 return (0); 1553 1493 } 1554 1555 1494 1556 1495 … … 1580 1519 return (sz_res); 1581 1520 } 1582 1583 1521 1584 1522 … … 1602 1540 char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d"; 1603 1541 char *p, *q; 1604 char sz_datefile[80];1605 char *sz_filelist, *exclude_paths , *tmp;1542 char *sz_datefile; 1543 char *sz_filelist, *exclude_paths; 1606 1544 int i; 1607 1545 FILE *fout; … … 1609 1547 time_t time_of_last_full_backup = 0; 1610 1548 struct stat statbuf; 1611 1612 malloc_string(command); 1613 malloc_string(tmp); 1614 malloc_string(sz_filelist); 1615 malloc_string(g_skeleton_filelist); 1616 if (!(exclude_paths = malloc(1000))) { 1617 fatal_error("Cannot malloc exclude_paths"); 1618 } 1619 log_msg(3, "Trying to write test string to exclude_paths"); 1620 strcpy(exclude_paths, "/blah /froo"); 1621 log_msg(3, "...Success!"); 1622 sprintf(sz_datefile, sz_datefile_wildcard, 0); 1549 char *skeleton_filelist; 1550 // The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist(). 1551 1552 asprintf(&sz_datefile, sz_datefile_wildcard, 0); 1623 1553 if (!include_paths && !userdef_filelist) { 1624 1554 fatal_error … … 1626 1556 } 1627 1557 // make hole for filelist 1628 sprintf(command, "mkdir -p %s/archives", scratchdir);1558 asprintf(&command, "mkdir -p %s/archives", scratchdir); 1629 1559 paranoid_system(command); 1630 sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1560 paranoid_free(command); 1561 1562 asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1631 1563 make_hole_for_file(sz_filelist); 1632 1564 1633 1565 if (differential == 0) { 1634 1566 // restore last good datefile if it exists 1635 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);1567 asprintf(&command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1636 1568 run_program_and_log_output(command, 3); 1569 paranoid_free(command); 1570 1637 1571 // backup last known good datefile just in case :) 1638 1572 if (does_file_exist(sz_datefile)) { 1639 sprintf(command, "mv -f %s %s.aborted", sz_datefile,1573 asprintf(&command, "mv -f %s %s.aborted", sz_datefile, 1640 1574 sz_datefile); 1641 1575 paranoid_system(command); 1576 paranoid_free(command); 1642 1577 } 1643 1578 make_hole_for_file(sz_datefile); … … 1654 1589 log_msg(2, "Differential backup. Yay."); 1655 1590 } 1591 paranoid_free(sz_datefile); 1656 1592 1657 1593 // use user-specified filelist (if specified) … … 1660 1596 "Using the user-specified filelist - %s - instead of calculating one", 1661 1597 userdef_filelist); 1662 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1598 asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist); 1663 1599 if (run_program_and_log_output(command, 3)) { 1664 1600 fatal_error("Failed to copy user-specified filelist"); 1665 1601 } 1602 paranoid_free(command); 1666 1603 } else { 1667 1604 log_msg(2, "include_paths = '%s'", include_paths); 1668 1605 log_msg(1, "Calculating filelist"); 1669 sprintf(exclude_paths, " %s %s %s %s %s %s . .. \1606 asprintf(&exclude_paths, " %s %s %s %s %s %s . .. \ 1670 1607 " MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \ 1671 1608 /proc /sys /tmp /root/images/mondo /root/images/mindi ", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir); … … 1674 1611 log_msg(2, 1675 1612 "Generating skeleton filelist so that we can track our progress"); 1676 sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir); 1677 make_hole_for_file(g_skeleton_filelist); 1613 asprintf(&skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir); 1614 make_hole_for_file(skeleton_filelist); 1615 1678 1616 log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries); 1679 1617 log_msg(2, "Opening out filelist to %s", sz_filelist); … … 1685 1623 log_msg(1, "Including only '/' in %s", sz_filelist); 1686 1624 open_and_list_dir("/", exclude_paths, fout, 1687 time_of_last_full_backup );1625 time_of_last_full_backup, skeleton_filelist); 1688 1626 } else { 1689 1627 p = include_paths; … … 1692 1630 log_msg(1, "Including %s in filelist %s", q, sz_filelist); 1693 1631 open_and_list_dir(q, exclude_paths, fout, 1694 time_of_last_full_backup );1632 time_of_last_full_backup, skeleton_filelist); 1695 1633 p += strlen(q); 1696 1634 while (*p == ' ') { … … 1700 1638 } 1701 1639 paranoid_fclose(fout); 1640 paranoid_free(skeleton_filelist); 1641 paranoid_free(exclude_paths); 1702 1642 } 1703 1643 log_msg(2, "Copying new filelist to scratchdir"); 1704 sprintf(command, "mkdir -p %s/archives", scratchdir);1644 asprintf(&command, "mkdir -p %s/archives", scratchdir); 1705 1645 paranoid_system(command); 1706 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1646 paranoid_free(command); 1647 1648 asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1707 1649 paranoid_system(command); 1708 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir); 1650 paranoid_free(command); 1651 1652 asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir); 1709 1653 paranoid_system(command); 1710 log_msg(2, "Freeing variables");1654 paranoid_free(command); 1711 1655 paranoid_free(sz_filelist); 1712 paranoid_free(command); 1713 paranoid_free(exclude_paths); 1714 paranoid_free(tmp); 1715 paranoid_free(g_skeleton_filelist); 1656 1716 1657 log_msg(2, "Exiting"); 1717 1658 return (0); 1718 1659 } 1719 1720 1721 1660 1722 1661 … … 1781 1720 } 1782 1721 } 1783 1784 1722 1785 1723 … … 1824 1762 } 1825 1763 paranoid_free(fname); 1826 asprintf(&fname, tmp); 1827 paranoid_free(tmp); 1764 fname = tmp; 1828 1765 } 1829 1766 while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) { … … 1845 1782 asprintf(&tmp, fname + 1); 1846 1783 paranoid_free(fname); 1847 asprintf(&fname, tmp); 1848 paranoid_free(tmp); 1784 fname = tmp; 1849 1785 } 1850 1786 log_msg(5, "Found '%s'", fname); … … 1862 1798 1863 1799 1864 1865 1866 1867 1868 1800 /** 1869 1801 * Add all files listed in @p list_of_files_fname to the directory structure rooted at … … 1878 1810 { 1879 1811 FILE *fin; 1880 char *tmp; 1812 char *tmp = NULL; 1813 int n = 0; 1881 1814 struct s_node *nod; 1882 1815 1883 malloc_string(tmp);1884 1816 log_msg(3, "Adding %s to filelist", list_of_files_fname); 1885 1817 if (!(fin = fopen(list_of_files_fname, "r"))) { … … 1887 1819 return (1); 1888 1820 } 1889 for ( fgets(tmp, MAX_STR_LEN, fin); !feof(fin);1890 fgets(tmp, MAX_STR_LEN, fin)) {1821 for (getline(&tmp, &n, fin); !feof(fin); 1822 getline(&tmp, &n, fin)) { 1891 1823 if (!tmp[0]) { 1892 1824 continue; -
trunk/mondo/mondo/common/libmondo-verify.c
r87 r120 1 1 /* $Id$ */ 2 /*3 copyright : (C) 2002 Mondo Hugo Rabson <hugorabson@msn.com>4 edited by : by Stan Benoit 4/2002 troff@nakedsoul.org5 */6 7 2 8 3 /** -
trunk/tools/quality
r119 r120 32 32 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r strcat | wc -l` strcat" 33 33 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r strcpy | wc -l` strcpy" 34 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r fgets | wc -l` fgets" 34 35 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r malloc_string | wc -l` malloc_string" 35 36 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r MAX_STR_LEN | wc -l` MAX_STR_LEN" 37 echo "monodrescue uses : `find . -name '*.c' -o -name '*.h' | egrep -v '\.svn' | egrep -v '/\*' | xargs grep -r goto | wc -l` goto" 36 38 37 39 echo " "
Note:
See TracChangeset
for help on using the changeset viewer.