Changeset 2521 in MondoRescue
- Timestamp:
- Jan 4, 2010, 7:42:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-filelist.c
r2469 r2521 78 78 { 79 79 /*@ buffers *********************** */ 80 char *dev; 81 char *filelist; 82 char *tempfile; 83 char *cksumlist; 84 char *tmp; 80 char *dev = NULL; 81 char *filelist = NULL; 82 char *tempfile = NULL; 85 83 long noof_sets; 86 84 … … 92 90 int i, retval = 0; 93 91 94 malloc_string(dev);95 malloc_string(filelist);96 malloc_string(tempfile);97 malloc_string(cksumlist);98 malloc_string(tmp);99 92 mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets"); 100 93 101 94 log_to_screen("Dividing filelist into sets. Please wait."); 102 95 i = 0; 103 sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 104 sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir); 96 mr_asprintf(&filelist, "%s/archives/filelist.full", bkpinfo->scratchdir); 105 97 if (!does_file_exist(filelist)) { 106 98 log_it("filelist %s not found", filelist); 99 mr_free(filelist); 107 100 fatal_error("call_filelist_chopper() -- filelist not found!"); 108 101 } 109 102 110 noof_sets = 111 chop_filelist(filelist, bkpinfo->tmpdir, 112 bkpinfo->optimal_set_size); 103 noof_sets = chop_filelist(filelist, bkpinfo->tmpdir, bkpinfo->optimal_set_size); 104 mr_free(filelist); 113 105 estimate_noof_media_required(noof_sets); // for cosmetic purposes 114 106 115 sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);107 mr_asprintf(&tempfile, "%s/biggielist.txt", bkpinfo->tmpdir); 116 108 if (!(fout = fopen(tempfile, "a"))) { 117 109 log_OS_error("Cannot append to biggielist"); 118 110 retval++; 119 goto end_of_func; 120 } 111 mr_free(tempfile); 112 return (retval); 113 } 114 mr_free(tempfile); 115 121 116 log_it(bkpinfo->image_devs); 122 117 123 118 ptr = bkpinfo->image_devs; 124 119 120 malloc_string(dev); 125 121 while (ptr && *ptr) { 126 122 strcpy(dev, ptr); … … 140 136 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 141 137 142 end_of_func:143 paranoid_free(filelist);144 paranoid_free(tempfile);145 paranoid_free(cksumlist);146 138 paranoid_free(dev); 147 paranoid_free(tmp);148 139 return (retval); 149 140 } … … 153 144 int sort_file(char *orig_fname) 154 145 { 155 char *tmp_fname ;156 char *command ;146 char *tmp_fname = NULL; 147 char *command = NULL; 157 148 int retval = 0; 158 149 159 150 log_msg(5, "Sorting file %s", orig_fname); 160 malloc_string(tmp_fname);161 malloc_string(command);162 sprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);163 151 164 152 if (!does_file_exist(orig_fname)) { … … 167 155 } // no sense in trying to sort an empty file 168 156 169 sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, 170 MONDO_LOGFILE); 157 mr_asprintf(&tmp_fname, "%s/sortfile", bkpinfo->tmpdir); 158 159 mr_asprintf(&command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE); 171 160 retval = system(command); 161 mr_free(command); 162 172 163 if (retval) { 173 164 log_msg(2, "Failed to sort %s - oh dear", orig_fname); 174 165 } else { 175 log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now", 176 orig_fname, tmp_fname, orig_fname); 177 sprintf(command, "mv -f %s %s", tmp_fname, orig_fname); 166 log_msg(5, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname); 167 mr_asprintf(&command, "mv -f %s %s", tmp_fname, orig_fname); 178 168 retval += run_program_and_log_output(command, 5); 169 mr_free(command); 170 179 171 if (retval) { 180 log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, 181 orig_fname); 172 log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, orig_fname); 182 173 } else { 183 174 log_msg(5, "%s was sorted OK.", orig_fname); 184 175 } 185 176 } 186 paranoid_free(tmp_fname); 187 paranoid_free(command); 177 mr_free(tmp_fname); 188 178 log_msg(5, "Finished sorting file %s", orig_fname); 189 179 return (retval); … … 218 208 219 209 /*@ buffers ************************************* */ 220 char *outfname ;221 char *biggie_fname ;210 char *outfname = NULL; 211 char *biggie_fname = NULL; 222 212 char *incoming; 223 char *tmp; 224 char *acl_fname; 225 char *xattr_fname; 213 char *tmp = NULL; 226 214 227 215 /*@ pointers *********************************** */ … … 233 221 struct stat buf; 234 222 int err = 0; 235 236 malloc_string(outfname);237 malloc_string(biggie_fname);238 incoming = malloc(MAX_STR_LEN * 2);239 malloc_string(tmp);240 malloc_string(acl_fname);241 malloc_string(xattr_fname);242 223 243 224 assert_string_is_neither_NULL_nor_zerolength(filelist); … … 259 240 curr_set_no = 0; 260 241 curr_set_size = 0; 261 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);262 sprintf(biggie_fname, "%s/biggielist.txt", outdir);242 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 243 mr_asprintf(&biggie_fname, "%s/biggielist.txt", outdir); 263 244 log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname); 264 245 if (!(fbig = fopen(biggie_fname, "w"))) { 265 246 log_OS_error("Cannot openout biggie_fname"); 266 247 err++; 267 goto end_of_func; 248 mr_free(outfname); 249 mr_free(biggie_fname); 250 return (curr_set_no + 1); 268 251 } 269 252 if (!(fout = fopen(outfname, "w"))) { 270 253 log_OS_error("Cannot openout outfname"); 271 254 err++; 272 goto end_of_func; 273 } 255 mr_free(outfname); 256 mr_free(biggie_fname); 257 return (curr_set_no + 1); 258 } 259 incoming = malloc(MAX_STR_LEN * 2); 260 274 261 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin); 275 262 while (!feof(fin)) { … … 294 281 siz = (long) (buf.st_size >> 10); 295 282 } 296 if (siz > max_sane_size_for_a_file) 297 // && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz")) 298 { 283 if (siz > max_sane_size_for_a_file) { 299 284 fprintf(fbig, "%s\n", incoming); 300 285 } else { … … 304 289 paranoid_fclose(fout); 305 290 sort_file(outfname); 291 mr_free(outfname); 306 292 curr_set_no++; 307 293 curr_set_size = 0; 308 sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no); 294 295 mr_asprintf(&outfname, "%s/filelist.%ld", outdir, curr_set_no); 309 296 if (!(fout = fopen(outfname, "w"))) { 310 297 log_OS_error("Unable to openout outfname"); 311 298 err++; 312 goto end_of_func; 299 mr_free(outfname); 300 mr_free(biggie_fname); 301 paranoid_free(incoming); 302 return (curr_set_no + 1); 313 303 } 314 sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);315 304 update_evalcall_form((int) (lino * 100 / noof_lines)); 316 /* if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */317 305 } 318 306 } 319 307 (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin); 320 308 } 309 paranoid_free(incoming); 321 310 paranoid_fclose(fin); 322 311 paranoid_fclose(fout); … … 329 318 g_noof_sets = curr_set_no; 330 319 sort_file(outfname); 320 mr_free(outfname); 321 331 322 sort_file(biggie_fname); 332 sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir); 333 sprintf(tmp, "%ld", curr_set_no); 323 mr_free(biggie_fname); 324 325 mr_asprintf(&outfname, "%s/LAST-FILELIST-NUMBER", outdir); 326 mr_asprintf(&tmp, "%ld", curr_set_no); 334 327 if (write_one_liner_data_file(outfname, tmp)) { 335 328 log_OS_error … … 337 330 err = 1; 338 331 } 332 mr_free(tmp); 333 mr_free(outfname); 334 339 335 if (curr_set_no == 0) { 340 sprintf(tmp, "Only one fileset. Fine.");336 mr_asprintf(&tmp, "Only one fileset. Fine."); 341 337 } else { 342 sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);338 mr_asprintf(&tmp, "Filelist divided into %ld sets", curr_set_no + 1); 343 339 } 344 340 log_msg(1, tmp); 341 mr_free(tmp); 345 342 close_evalcall_form(); 346 343 /* This is to work around an obscure bug in Newt; open a form, close it, … … 356 353 } 357 354 #endif 358 end_of_func:359 paranoid_free(outfname);360 paranoid_free(biggie_fname);361 paranoid_free(incoming);362 paranoid_free(tmp);363 paranoid_free(acl_fname);364 paranoid_free(xattr_fname);365 355 return (err ? 0 : curr_set_no + 1); 366 356 } … … 452 442 FILE *fin; 453 443 FILE *pout; 454 char *pout_command ;444 char *pout_command = NULL; 455 445 char *syscall; 456 446 char *file_to_analyze; … … 463 453 return (1); 464 454 } 465 malloc_string(pout_command); 466 sprintf(pout_command, "gzip -c1 > %s", auxlist_fname); 455 mr_asprintf(&pout_command, "gzip -c1 > %s", auxlist_fname); 467 456 if (!(pout = popen(pout_command, "w"))) { 468 457 log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname); 469 458 fclose(fin); 470 paranoid_free(pout_command);459 mr_free(pout_command); 471 460 return (4); 472 461 } 462 mr_free(pout_command); 463 473 464 malloc_string(file_to_analyze); 474 465 for ((void)fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin); … … 490 481 paranoid_pclose(pout); 491 482 paranoid_free(file_to_analyze); 492 paranoid_free(pout_command);493 483 return (0); 494 484 } … … 497 487 int get_acl_list(char *filelist, char *facl_fname) 498 488 { 499 char *command ;489 char *command = NULL; 500 490 int retval = 0; 501 491 502 492 if (g_getfacl != NULL) { 503 malloc_string(command); 504 sprintf(command, "touch %s", facl_fname); 493 mr_asprintf(&command, "touch %s", facl_fname); 505 494 run_program_and_log_output(command, 8); 506 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 507 sprintf(command, 495 mr_free(command); 496 497 mr_asprintf(&command, 508 498 "getfacl --all-effective -P %s 2>> %s | gzip -c1 > %s 2>> %s", 509 499 filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE); 510 500 log_it("%s",command); 511 501 retval = system(command); 512 paranoid_free(command);502 mr_free(command); 513 503 } 514 504 return (retval); … … 522 512 523 513 if (g_getfattr != NULL) { 524 malloc_string(command); 525 sprintf(command, "touch %s", fattr_fname); 514 mr_asprintf(&command, "touch %s", fattr_fname); 526 515 run_program_and_log_output(command, 8); 527 paranoid_free(command); 528 // sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary 516 mr_free(command); 529 517 retval = 530 518 gen_aux_list(filelist, "getfattr --en=hex -P -m - -d \"%s\"", … … 539 527 { 540 528 const int my_depth = 8; 541 char *command, *syscall_pin, *syscall_pout, *incoming; 542 char *current_subset_file, *current_master_file, *masklist; 529 char *command = NULL; 530 char *syscall_pin = NULL; 531 char *syscall_pout = NULL; 532 char *incoming; 533 char *current_subset_file, *current_master_file; 534 char *masklist = NULL; 543 535 int retval = 0; 544 536 int i; … … 546 538 FILE *pin, *pout, *faclin; 547 539 548 malloc_string(command);549 540 log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, 550 541 original_exat_fname, executable); 551 542 if (!orig_msklist || !orig_msklist[0] 552 543 || !does_file_exist(orig_msklist)) { 553 log_msg(1, 554 "No masklist provided. I shall therefore set ALL attributes."); 555 sprintf(command, "gzip -dc %s | %s --restore - 2>> %s", 556 original_exat_fname, executable, MONDO_LOGFILE); 544 log_msg(1, "No masklist provided. I shall therefore set ALL attributes."); 545 mr_asprintf(&command, "gzip -dc %s | %s --restore - 2>> %s", original_exat_fname, executable, MONDO_LOGFILE); 557 546 log_msg(1, "command = %s", command); 558 547 retval = system(command); 559 paranoid_free(command);548 mr_free(command); 560 549 log_msg(1, "Returning w/ retval=%d", retval); 561 550 return (retval); … … 565 554 "original_exat_fname %s is empty or missing, so no need to set EXAT list", 566 555 original_exat_fname); 567 paranoid_free(command);568 556 return (0); 569 557 } 570 558 malloc_string(incoming); 571 malloc_string(masklist);572 559 malloc_string(current_subset_file); 573 560 malloc_string(current_master_file); 574 malloc_string(syscall_pin); 575 malloc_string(syscall_pout); 576 sprintf(masklist, "%s/masklist", bkpinfo->tmpdir); 577 sprintf(command, "cp -f %s %s", orig_msklist, masklist); 561 mr_asprintf(&masklist, "%s/masklist", bkpinfo->tmpdir); 562 mr_asprintf(&command, "cp -f %s %s", orig_msklist, masklist); 578 563 run_program_and_log_output(command, 1); 564 mr_free(command); 565 579 566 sort_file(masklist); 580 567 current_subset_file[0] = current_master_file[0] = '\0'; 581 sprintf(syscall_pin, "gzip -dc %s", original_exat_fname); 582 sprintf(syscall_pout, "%s --restore - 2>> %s", executable, 583 MONDO_LOGFILE); 584 585 log_msg(1, "syscall_pin = %s", syscall_pin); 568 569 mr_asprintf(&syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE); 586 570 log_msg(1, "syscall_pout = %s", syscall_pout); 587 571 pout = popen(syscall_pout, "w"); 572 mr_free(syscall_pout); 573 588 574 if (!pout) { 589 575 log_it("Unable to openout to syscall_pout"); 576 mr_free(masklist); 590 577 return (1); 591 578 } 579 580 mr_asprintf(&syscall_pin, "gzip -dc %s", original_exat_fname); 581 log_msg(1, "syscall_pin = %s", syscall_pin); 592 582 pin = popen(syscall_pin, "r"); 583 mr_free(syscall_pin); 584 593 585 if (!pin) { 594 586 pclose(pout); … … 601 593 pclose(pout); 602 594 log_it("Unable to openin masklist"); 595 mr_free(masklist); 603 596 return (1); 604 597 } … … 674 667 675 668 unlink(masklist); 669 mr_free(masklist); 670 676 671 paranoid_free(current_subset_file); 677 672 paranoid_free(current_master_file); 678 paranoid_free(syscall_pout);679 paranoid_free(syscall_pin);680 paranoid_free(masklist);681 673 paranoid_free(incoming); 682 paranoid_free(command);683 674 return (retval); 684 675 } … … 718 709 /*@ buffers ***************************************************** */ 719 710 char val_sz[MAX_STR_LEN]; 720 char cfg_fname[MAX_STR_LEN]; 721 /* char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */ 711 char *cfg_fname = NULL; 722 712 723 713 /*@ long ******************************************************** */ … … 729 719 730 720 strcpy(val_sz,""); 731 sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);721 mr_asprintf(&cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir); 732 722 read_cfg_var(cfg_fname, "last-filelist-number", val_sz); 723 mr_free(cfg_fname); 724 733 725 val_i = atoi(val_sz); 734 726 if (val_i <= 0) { … … 870 862 871 863 /*@ buffers **************************************************** */ 872 char command_to_open_fname[MAX_STR_LEN];864 char *command_to_open_fname = NULL; 873 865 char fname[MAX_STR_LEN]; 874 866 char tmp[MAX_STR_LEN]; 867 char *tmp1 = NULL; 875 868 int pos_in_fname; 876 869 /*@ int ******************************************************** */ … … 888 881 } 889 882 log_to_screen("Loading filelist"); 890 sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);891 sprintf(tmp, "zcat %s | wc -l", filelist_fname);892 l og_msg(6, "tmp = %s", tmp);893 lines_in_filelist =894 atol(call_program_and_get_last_line_of_output(tmp)); 883 mr_asprintf(&tmp1, "zcat %s | wc -l", filelist_fname); 884 log_msg(6, "tmp1 = %s", tmp1); 885 lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp1)); 886 mr_free(tmp1); 887 895 888 if (lines_in_filelist < 3) { 896 889 log_to_screen("Warning - surprisingly short filelist."); … … 907 900 (filelist->down)->right = (filelist->down)->down = FALSE; 908 901 (filelist->down)->expanded = (filelist->down)->selected = FALSE; 902 903 mr_asprintf(&command_to_open_fname, "gzip -dc %s", filelist_fname); 909 904 if (!(pin = popen(command_to_open_fname, "r"))) { 910 905 log_OS_error("Unable to openin filelist_fname"); 906 mr_free(command_to_open_fname); 911 907 return (NULL); 912 908 } 909 mr_free(command_to_open_fname); 910 913 911 open_evalcall_form("Loading filelist from disk"); 914 912 for ((void)fgets(fname, MAX_STR_LEN, pin); !feof(pin); … … 1205 1203 /*@ buffers ***************************************************** */ 1206 1204 static char current_filename[MAX_STR_LEN]; 1207 char tmp[MAX_STR_LEN + 2];1208 1205 1209 1206 /*@ end vars *************************************************** */ … … 1225 1222 pathname[j] != '\0' 1226 1223 && pathname[j] == current_filename[j]; j++); 1227 if (current_filename[j] == '/' 1228 || current_filename[j] == '\0') { 1229 node->selected = on_or_off; 1230 sprintf(tmp, "%s is now %s\n", current_filename, 1231 (on_or_off ? "ON" : "OFF")); 1224 if (current_filename[j] == '/' 1225 || current_filename[j] == '\0') { 1226 node->selected = on_or_off; 1232 1227 } 1233 1228 } … … 1530 1525 int i; 1531 1526 FILE *fout; 1532 char *command ;1527 char *command = NULL; 1533 1528 time_t time_of_last_full_backup = 0; 1534 1529 struct stat statbuf; … … 1536 1531 char *tmp2 = NULL; 1537 1532 1538 malloc_string(command);1539 1533 malloc_string(tmp); 1540 1534 malloc_string(g_skeleton_filelist); … … 1548 1542 } 1549 1543 // make hole for filelist 1550 sprintf(command, "mkdir -p %s/archives", scratchdir);1544 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1551 1545 paranoid_system(command); 1546 mr_free(command); 1547 1552 1548 mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir); 1553 1549 make_hole_for_file(sz_filelist); … … 1555 1551 if (differential == 0) { 1556 1552 // restore last good datefile if it exists 1557 sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);1553 mr_asprintf(&command, "cp -f %s.aborted %s", sz_datefile, sz_datefile); 1558 1554 run_program_and_log_output(command, 3); 1555 mr_free(command); 1556 1559 1557 // backup last known good datefile just in case :) 1560 1558 if (does_file_exist(sz_datefile)) { 1561 sprintf(command, "mv -f %s %s.aborted", sz_datefile,1559 mr_asprintf(&command, "mv -f %s %s.aborted", sz_datefile, 1562 1560 sz_datefile); 1563 1561 paranoid_system(command); 1562 mr_free(command); 1564 1563 } 1565 1564 make_hole_for_file(sz_datefile); … … 1583 1582 "Using the user-specified filelist - %s - instead of calculating one", 1584 1583 userdef_filelist); 1585 sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);1584 mr_asprintf(&command, "cp -f %s %s", userdef_filelist, sz_filelist); 1586 1585 if (run_program_and_log_output(command, 3)) { 1586 mr_free(command); 1587 1587 fatal_error("Failed to copy user-specified filelist"); 1588 1588 } 1589 mr_free(command); 1589 1590 } else { 1590 1591 log_msg(2, "include_paths = '%s'", include_paths); … … 1639 1640 } 1640 1641 log_msg(2, "Copying new filelist to scratchdir"); 1641 sprintf(command, "mkdir -p %s/archives", scratchdir);1642 mr_asprintf(&command, "mkdir -p %s/archives", scratchdir); 1642 1643 paranoid_system(command); 1643 sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1644 mr_free(command); 1645 1646 mr_asprintf(&command, "cp -f %s %s/archives/", sz_filelist, scratchdir); 1644 1647 paranoid_system(command); 1645 sprintf(command, "mv -f %s %s", sz_filelist, tmpdir); 1648 mr_free(command); 1649 1650 mr_asprintf(&command, "mv -f %s %s", sz_filelist, tmpdir); 1646 1651 paranoid_system(command); 1652 mr_free(command); 1653 1647 1654 paranoid_free(sz_filelist); 1648 1655 log_msg(2, "Freeing variables"); 1649 paranoid_free(command);1650 1656 paranoid_free(exclude_paths); 1651 1657 paranoid_free(tmp); … … 1822 1828 } 1823 1829 1824 /*1825 if (strlen(fname)>3 && fname[strlen(fname)-1]=='/') { fname[strlen(fname)-1] = '\0'; }1826 if (strlen(fname)==0) { continue; }1827 sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);1828 system(temporary_string);1829 */1830 1831 1830 log_msg(5, "Looking for '%s'", fname); 1832 1831 found_node = find_string_at_node(filelist, fname); 1833 1832 if (found_node) { 1834 1833 if (found_node->selected) { 1835 // if (use_star)1836 1834 if (fname[0] == '/') { 1837 1835 strcpy(tmp, fname + 1);
Note:
See TracChangeset
for help on using the changeset viewer.