Changeset 2265 in MondoRescue
- Timestamp:
- Jul 12, 2009, 2:04:40 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-filelist.c
r2241 r2265 83 83 { 84 84 /*@ buffers *********************** */ 85 char *dev; 86 char *filelist; 87 char *tempfile; 88 char *cksumlist; 89 char *tmp; 85 char *dev = NULL; 86 char *filelist = NULL; 87 char *tempfile = NULL; 90 88 long noof_sets; 91 89 … … 97 95 int i, retval = 0; 98 96 99 malloc_string(dev);100 malloc_string(filelist);101 malloc_string(tempfile);102 malloc_string(cksumlist);103 malloc_string(tmp);104 97 mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets"); 105 98 106 99 log_to_screen("Dividing filelist into sets. Please wait."); 107 100 i = 0; 108 sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 109 sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir); 101 mr_asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 110 102 if (!does_file_exist(filelist)) { 111 103 log_it("filelist %s not found", filelist); 104 mr_free(filelist); 112 105 fatal_error("call_filelist_chopper() -- filelist not found!"); 113 106 } 114 107 115 noof_sets = 116 chop_filelist(filelist, bkpinfo->tmpdir, 117 bkpinfo->optimal_set_size); 108 noof_sets = chop_filelist(filelist, bkpinfo->tmpdir, bkpinfo->optimal_set_size); 109 mr_free(filelist); 118 110 estimate_noof_media_required(noof_sets); // for cosmetic purposes 119 111 120 sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);112 mr_asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir); 121 113 if (!(fout = fopen(tempfile, "a"))) { 122 114 log_OS_error("Cannot append to biggielist"); 123 115 retval++; 124 goto end_of_func; 125 } 116 mr_free(tempfile); 117 return (retval); 118 } 119 mr_free(tempfile); 120 126 121 log_it(bkpinfo->image_devs); 127 122 128 123 ptr = bkpinfo->image_devs; 129 124 125 malloc_string(dev); 130 126 while (ptr && *ptr) { 131 127 strcpy(dev, ptr); … … 145 141 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 146 142 147 end_of_func:148 paranoid_free(filelist);149 paranoid_free(tempfile);150 paranoid_free(cksumlist);151 143 paranoid_free(dev); 152 paranoid_free(tmp);153 144 return (retval); 154 145 } … … 158 149 int sort_file(char *orig_fname) 159 150 { 160 char *tmp_fname ;161 char *command ;151 char *tmp_fname = NULL; 152 char *command = NULL; 162 153 int retval = 0; 163 154 164 155 log_msg(5, "Sorting file %s", orig_fname); 165 malloc_string(tmp_fname);166 malloc_string(command);167 sprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);168 156 169 157 if (!does_file_exist(orig_fname)) { … … 172 160 } // no sense in trying to sort an empty file 173 161 174 sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, 175 MONDO_LOGFILE); 162 mr_asprintf(&tmp_fname, "%s/sortfile", bkpinfo->tmpdir); 163 164 mr_asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE); 176 165 retval = system(command); 166 mr_free(command); 167 177 168 if (retval) { 178 169 log_msg(2, "Failed to sort %s - oh dear", orig_fname); 179 170 } else { 180 log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now", 181 orig_fname, tmp_fname, orig_fname); 182 sprintf(command, "mv -f %s %s", tmp_fname, orig_fname); 171 log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname); 172 mr_asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname); 183 173 retval += run_program_and_log_output(command, 5); 174 mr_free(command); 175 184 176 if (retval) { 185 log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, 186 orig_fname); 177 log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, orig_fname); 187 178 } else { 188 179 log_msg(5, "%s was sorted OK.", orig_fname); 189 180 } 190 181 } 191 paranoid_free(tmp_fname); 192 paranoid_free(command); 182 mr_free(tmp_fname); 193 183 log_msg(5, "Finished sorting file %s", orig_fname); 194 184 return (retval); … … 223 213 224 214 /*@ buffers ************************************* */ 225 char *outfname ;226 char *biggie_fname ;215 char *outfname = NULL; 216 char *biggie_fname = NULL; 227 217 char *incoming; 228 char *tmp; 229 char *acl_fname; 230 char *xattr_fname; 218 char *tmp = NULL; 231 219 232 220 /*@ pointers *********************************** */ … … 238 226 struct stat buf; 239 227 int err = 0; 240 241 malloc_string(outfname);242 malloc_string(biggie_fname);243 incoming = malloc(MAX_STR_LEN * 2);244 malloc_string(tmp);245 malloc_string(acl_fname);246 malloc_string(xattr_fname);247 228 248 229 assert_string_is_neither_NULL_nor_zerolength(filelist); … … 264 245 curr_set_no = 0; 265 246 curr_set_size = 0; 266 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);267 sprintf(biggie_fname, "%s/biggielist.txt", outdir);247 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 248 mr_asprintf(&biggie_fname, "%s/biggielist.txt", outdir); 268 249 log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname); 269 250 if (!(fbig = fopen(biggie_fname, "w"))) { 270 251 log_OS_error("Cannot openout biggie_fname"); 271 252 err++; 272 goto end_of_func; 253 mr_free(outfname); 254 mr_free(biggie_fname); 255 return (curr_set_no + 1); 273 256 } 274 257 if (!(fout = fopen(outfname, "w"))) { 275 258 log_OS_error("Cannot openout outfname"); 276 259 err++; 277 goto end_of_func; 278 } 260 mr_free(outfname); 261 mr_free(biggie_fname); 262 return (curr_set_no + 1); 263 } 264 incoming = malloc(MAX_STR_LEN * 2); 265 279 266 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin); 280 267 while (!feof(fin)) { … … 299 286 siz = (long) (buf.st_size >> 10); 300 287 } 301 if (siz > max_sane_size_for_a_file) 302 // && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz")) 303 { 288 if (siz > max_sane_size_for_a_file) { 304 289 fprintf(fbig, "%s\n", incoming); 305 290 } else { … … 309 294 paranoid_fclose(fout); 310 295 sort_file(outfname); 296 mr_free(outfname); 311 297 curr_set_no++; 312 298 curr_set_size = 0; 313 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no); 299 300 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 314 301 if (!(fout = fopen(outfname, "w"))) { 315 302 log_OS_error("Unable to openout outfname"); 316 303 err++; 317 goto end_of_func; 304 mr_free(outfname); 305 mr_free(biggie_fname); 306 paranoid_free(incoming); 307 return (curr_set_no + 1); 318 308 } 319 sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);320 309 update_evalcall_form((int) (lino * 100 / noof_lines)); 321 /* if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */322 310 } 323 311 } 324 312 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin); 325 313 } 314 paranoid_free(incoming); 326 315 paranoid_fclose(fin); 327 316 paranoid_fclose(fout); … … 334 323 g_noof_sets = curr_set_no; 335 324 sort_file(outfname); 325 mr_free(outfname); 326 336 327 sort_file(biggie_fname); 337 sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir); 338 sprintf(tmp, "%ld", curr_set_no); 328 mr_free(biggie_fname); 329 330 mr_asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir); 331 mr_asprintf(&tmp, "%ld", curr_set_no); 339 332 if (write_one_liner_data_file(outfname, tmp)) { 340 333 log_OS_error … … 342 335 err = 1; 343 336 } 337 mr_free(tmp); 338 mr_free(outfname); 339 344 340 if (curr_set_no == 0) { 345 sprintf(tmp, "Only one fileset. Fine.");341 mr_asprintf(&tmp, "Only one fileset. Fine."); 346 342 } else { 347 sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);343 mr_asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1); 348 344 } 349 345 log_msg(1, tmp); 346 mr_free(tmp); 350 347 close_evalcall_form(); 351 348 /* This is to work around an obscure bug in Newt; open a form, close it, … … 361 358 } 362 359 #endif 363 end_of_func:364 paranoid_free(outfname);365 paranoid_free(biggie_fname);366 paranoid_free(incoming);367 paranoid_free(tmp);368 paranoid_free(acl_fname);369 paranoid_free(xattr_fname);370 360 return (err ? 0 : curr_set_no + 1); 371 361 } … … 457 447 FILE *fin; 458 448 FILE *pout; 459 char *pout_command ;449 char *pout_command = NULL; 460 450 char *syscall; 461 451 char *file_to_analyze; … … 468 458 return (1); 469 459 } 470 malloc_string(pout_command); 471 sprintf(pout_command, "gzip -c1 > %s", auxlist_fname); 460 mr_asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname); 472 461 if (!(pout = popen(pout_command, "w"))) { 473 462 log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname); 474 463 fclose(fin); 475 paranoid_free(pout_command);464 mr_free(pout_command); 476 465 return (4); 477 466 } 467 mr_free(pout_command); 468 478 469 malloc_string(file_to_analyze); 479 470 for ((void)fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin); … … 495 486 paranoid_pclose(pout); 496 487 paranoid_free(file_to_analyze); 497 paranoid_free(pout_command);498 488 return (0); 499 489 } … … 502 492 int get_acl_list(char *filelist, char *facl_fname) 503 493 { 504 char *command ;494 char *command = NULL; 505 495 int retval = 0; 506 496 507 497 if (g_getfacl != NULL) { 508 malloc_string(command); 509 sprintf(command, "touch %s", facl_fname); 498 mr_asprintf(&command, "touch %s", facl_fname); 510 499 run_program_and_log_output(command, 8); 511 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 512 sprintf(command, 500 mr_free(command); 501 502 mr_asprintf(&command, 513 503 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s", 514 504 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE); 515 505 log_it("%s",command); 516 506 retval = system(command); 517 paranoid_free(command);507 mr_free(command); 518 508 } 519 509 return (retval); … … 527 517 528 518 if (g_getfattr != NULL) { 529 malloc_string(command); 530 sprintf(command, "touch %s", fattr_fname); 519 mr_asprintf(&command, "touch %s", fattr_fname); 531 520 run_program_and_log_output(command, 8); 532 paranoid_free(command); 533 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 521 mr_free(command); 534 522 retval = 535 523 gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"", … … 544 532 { 545 533 const int my_depth = 8; 546 char *command, *syscall_pin, *syscall_pout, *incoming; 547 char *current_subset_file, *current_master_file, *masklist; 534 char *command = NULL; 535 char *syscall_pin = NULL; 536 char *syscall_pout = NULL; 537 char *incoming; 538 char *current_subset_file, *current_master_file; 539 char *masklist = NULL; 548 540 int retval = 0; 549 541 int i; … … 551 543 FILE *pin, *pout, *faclin; 552 544 553 malloc_string(command);554 545 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 555 546 original_exat_fname, executable); 556 547 if (!orig_msklist || !orig_msklist[0] 557 548 || !does_file_exist(orig_msklist)) { 558 log_msg(1, 559 "No masklist provided. I shall therefore set ALL attributes."); 560 sprintf(command, "gzip -dc %s | %s --restore - 2>> %s", 561 original_exat_fname, executable, MONDO_LOGFILE); 549 log_msg(1, "No masklist provided. I shall therefore set ALL attributes."); 550 mr_asprintf(&command, "gzip -dc %s | %s --restore - 2>> %s", original_exat_fname, executable, MONDO_LOGFILE); 562 551 log_msg(1, "command = %s", command); 563 552 retval = system(command); 564 paranoid_free(command);553 mr_free(command); 565 554 log_msg(1, "Returning w/ retval=%d", retval); 566 555 return (retval); … … 570 559 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 571 560 original_exat_fname); 572 paranoid_free(command);573 561 return (0); 574 562 } 575 563 malloc_string(incoming); 576 malloc_string(masklist);577 564 malloc_string(current_subset_file); 578 565 malloc_string(current_master_file); 579 malloc_string(syscall_pin); 580 malloc_string(syscall_pout); 581 sprintf(masklist, "%s/masklist", bkpinfo->tmpdir); 582 sprintf(command, "cp -f %s %s", orig_msklist, masklist); 566 mr_asprintf(&masklist, "%s/masklist", bkpinfo->tmpdir); 567 mr_asprintf(&command, "cp -f %s %s", orig_msklist, masklist); 583 568 run_program_and_log_output(command, 1); 569 mr_free(command); 570 584 571 sort_file(masklist); 585 572 current_subset_file[0] = current_master_file[0] = '\0'; 586 sprintf(syscall_pin, "gzip -dc %s", original_exat_fname); 587 sprintf(syscall_pout, "%s --restore - 2>> %s", executable, 588 MONDO_LOGFILE); 589 590 log_msg(1, "syscall_pin = %s", syscall_pin); 573 574 mr_asprintf(&syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE); 591 575 log_msg(1, "syscall_pout = %s", syscall_pout); 592 576 pout = popen(syscall_pout, "w"); 577 mr_free(syscall_pout); 578 593 579 if (!pout) { 594 580 log_it("Unable to openout to syscall_pout"); 581 mr_free(masklist); 595 582 return (1); 596 583 } 584 585 mr_asprintf(&syscall_pin, "gzip -dc %s", original_exat_fname); 586 log_msg(1, "syscall_pin = %s", syscall_pin); 597 587 pin = popen(syscall_pin, "r"); 588 mr_free(syscall_pin); 589 598 590 if (!pin) { 599 591 pclose(pout); … … 606 598 pclose(pout); 607 599 log_it("Unable to openin masklist"); 600 mr_free(masklist); 608 601 return (1); 609 602 } … … 679 672 680 673 unlink(masklist); 674 mr_free(masklist); 675 681 676 paranoid_free(current_subset_file); 682 677 paranoid_free(current_master_file); 683 paranoid_free(syscall_pout);684 paranoid_free(syscall_pin);685 paranoid_free(masklist);686 678 paranoid_free(incoming); 687 paranoid_free(command);688 679 return (retval); 689 680 } … … 723 714 /*@ buffers ***************************************************** */ 724 715 char val_sz[MAX_STR_LEN]; 725 char cfg_fname[MAX_STR_LEN]; 726 /* char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */ 716 char *cfg_fname = NULL; 727 717 728 718 /*@ long ******************************************************** */ … … 734 724 735 725 strcpy(val_sz,""); 736 sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);726 mr_asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir); 737 727 read_cfg_var(cfg_fname, "last-filelist-number", val_sz); 728 mr_free(cfg_fname); 729 738 730 val_i = atoi(val_sz); 739 731 if (val_i <= 0) { … … 875 867 876 868 /*@ buffers **************************************************** */ 877 char command_to_open_fname[MAX_STR_LEN];869 char *command_to_open_fname = NULL; 878 870 char fname[MAX_STR_LEN]; 879 871 char tmp[MAX_STR_LEN]; 872 char *tmp1 = NULL; 880 873 int pos_in_fname; 881 874 /*@ int ******************************************************** */ … … 893 886 } 894 887 log_to_screen("Loading filelist"); 895 sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);896 sprintf(tmp, "zcat %s | wc -l", filelist_fname);897 l og_msg(6, "tmp = %s", tmp);898 lines_in_filelist =899 atol(call_program_and_get_last_line_of_output(tmp)); 888 mr_asprintf(&tmp1, "zcat %s | wc -l", filelist_fname); 889 log_msg(6, "tmp1 = %s", tmp1); 890 lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp1)); 891 mr_free(tmp1); 892 900 893 if (lines_in_filelist < 3) { 901 894 log_to_screen("Warning - surprisingly short filelist."); … … 912 905 (filelist->down)->right = (filelist->down)->down = FALSE; 913 906 (filelist->down)->expanded = (filelist->down)->selected = FALSE; 907 908 mr_asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname); 914 909 if (!(pin = popen(command_to_open_fname, "r"))) { 915 910 log_OS_error("Unable to openin filelist_fname"); 911 mr_free(command_to_open_fname); 916 912 return (NULL); 917 913 } 914 mr_free(command_to_open_fname); 915 918 916 open_evalcall_form("Loading filelist from disk"); 919 917 for ((void)fgets(fname, MAX_STR_LEN, pin); !feof(pin); … … 1210 1208 /*@ buffers ***************************************************** */ 1211 1209 static char current_filename[MAX_STR_LEN]; 1212 char tmp[MAX_STR_LEN + 2];1213 1210 1214 1211 /*@ end vars *************************************************** */ … … 1230 1227 pathname[j] != '\0' 1231 1228 && pathname[j] == current_filename[j]; j++); 1232 if (current_filename[j] == '/' 1233 || current_filename[j] == '\0') { 1234 node->selected = on_or_off; 1235 sprintf(tmp, "%s is now %s\n", current_filename, 1236 (on_or_off ? "ON" : "OFF")); 1229 if (current_filename[j] == '/' 1230 || current_filename[j] == '\0') { 1231 node->selected = on_or_off; 1237 1232 } 1238 1233 } … … 1588 1583 int i; 1589 1584 FILE *fout; 1590 char *command ;1585 char *command = NULL; 1591 1586 time_t time_of_last_full_backup = 0; 1592 1587 struct stat statbuf; … … 1594 1589 char *tmp2 = NULL; 1595 1590 1596 malloc_string(command);1597 1591 malloc_string(tmp); 1598 1592 malloc_string(g_skeleton_filelist); … … 1606 1600 } 1607 1601 // make hole for filelist 1608 sprintf(command, "mkdir -p %s/archives", scratchdir);1602 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1609 1603 paranoid_system(command); 1604 mr_free(command); 1605 1610 1606 mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1611 1607 make_hole_for_file(sz_filelist); … … 1613 1609 if (differential == 0) { 1614 1610 // restore last good datefile if it exists 1615 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);1611 mr_asprintf(&command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1616 1612 run_program_and_log_output(command, 3); 1613 mr_free(command); 1614 1617 1615 // backup last known good datefile just in case :) 1618 1616 if (does_file_exist(sz_datefile)) { 1619 sprintf(command, "mv -f %s %s.aborted", sz_datefile,1617 mr_asprintf(&command, "mv -f %s %s.aborted", sz_datefile, 1620 1618 sz_datefile); 1621 1619 paranoid_system(command); 1620 mr_free(command); 1622 1621 } 1623 1622 make_hole_for_file(sz_datefile); … … 1641 1640 "Using the user-specified filelist - %s - instead of calculating one", 1642 1641 userdef_filelist); 1643 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1642 mr_asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist); 1644 1643 if (run_program_and_log_output(command, 3)) { 1644 mr_free(command); 1645 1645 fatal_error("Failed to copy user-specified filelist"); 1646 1646 } 1647 mr_free(command); 1647 1648 } else { 1648 1649 log_msg(2, "include_paths = '%s'", include_paths); … … 1697 1698 } 1698 1699 log_msg(2, "Copying new filelist to scratchdir"); 1699 sprintf(command, "mkdir -p %s/archives", scratchdir);1700 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1700 1701 paranoid_system(command); 1701 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1702 mr_free(command); 1703 1704 mr_asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1702 1705 paranoid_system(command); 1703 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir); 1706 mr_free(command); 1707 1708 mr_asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir); 1704 1709 paranoid_system(command); 1710 mr_free(command); 1711 1705 1712 paranoid_free(sz_filelist); 1706 1713 log_msg(2, "Freeing variables"); 1707 paranoid_free(command);1708 1714 paranoid_free(exclude_paths); 1709 1715 paranoid_free(tmp); … … 1829 1835 } 1830 1836 1831 /*1832 if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }1833 if (strlen(fname)==0) { continue; }1834 sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);1835 system(temporary_string);1836 */1837 1838 1837 log_msg(5, "Looking for '%s'", fname); 1839 1838 found_node = find_string_at_node(filelist, fname); 1840 1839 if (found_node) { 1841 1840 if (found_node->selected) { 1842 // if (use_star)1843 1841 if (fname[0] == '/') { 1844 1842 strcpy(tmp, fname + 1);
Note:
See TracChangeset
for help on using the changeset viewer.