Changeset 2275 in MondoRescue
- Timestamp:
- Jul 13, 2009, 2:34:31 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-fork.c
r2226 r2275 101 101 102 102 /*@ buffers *** */ 103 char *midway_call, *ultimate_call, *tmp, *command, *incoming, 104 *old_stderr, *cd_number_str; 103 char *midway_call, *ultimate_call, *tmp, *incoming, *old_stderr; 104 105 char *cd_number_str = NULL; 106 char *command = NULL; 105 107 char *p; 106 108 char *tmp1 = NULL; 109 char *tmp2 = NULL; 107 110 108 111 /*@*********** End Variables ***************************************/ … … 123 126 fatal_error("Cannot malloc tmp"); 124 127 } 125 if (!(command = malloc(1200))) {126 fatal_error("Cannot malloc command");127 }128 128 malloc_string(incoming); 129 129 malloc_string(old_stderr); 130 malloc_string(cd_number_str);131 130 132 131 incoming[0] = '\0'; … … 139 138 } 140 139 141 sprintf(cd_number_str, "%d", cd_no);140 mr_asprintf(&cd_number_str, "%d", cd_no); 142 141 resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_"); 143 142 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_"); 143 mr_free(cd_number_str); 144 144 145 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 145 146 log_msg(4, "basic call = '%s'", tmp1); … … 147 148 log_msg(4, "tmp = '%s'", tmp); 148 149 log_msg(4, "ultimate call = '%s'", ultimate_call); 149 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);150 mr_asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 150 151 151 152 log_to_screen … … 153 154 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", 154 155 what_i_am_doing); 155 strcpy(tmp, command);156 156 if (bkpinfo->manual_cd_tray) { 157 p = strstr(tmp, "2>>"); 157 mr_asprintf(&tmp2, "%s", command); 158 p = strstr(tmp2, "2>>"); 158 159 if (p) { 159 sprintf(p, " "); 160 *p++ = ' '; 161 *p++ = ' '; 162 *p++ = ' '; 160 163 while (*p == ' ') { 161 164 p++; 162 165 } 163 for (; *p != ' '; p++) {166 for (; (*p != ' ') && (*p != '\0'); p++) { 164 167 *p = ' '; 165 168 } 166 169 } 167 strcpy(command, tmp); 170 mr_free(command); 171 command = tmp2; 168 172 #ifndef _XWIN 169 173 if (!g_text_mode) { … … 179 183 log_msg(2, "Basic call '%s' returned an error.", tmp1); 180 184 popup_and_OK("Press ENTER to continue."); 181 popup_and_OK 182 ("mkisofs and/or cdrecord returned an error. CD was not created"); 185 popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created"); 183 186 } 184 187 } … … 186 189 else { 187 190 log_msg(3, "command = '%s'", command); 188 // yes_this_is_a_goto: 189 retval = 190 run_external_binary_with_percentage_indicator_NEW 191 (what_i_am_doing, command); 192 } 193 191 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command); 192 } 193 mr_free(command); 194 194 mr_free(tmp1); 195 195 paranoid_free(midway_call); 196 196 paranoid_free(ultimate_call); 197 197 paranoid_free(tmp); 198 paranoid_free(command);199 198 paranoid_free(incoming); 200 199 paranoid_free(old_stderr); 201 paranoid_free(cd_number_str);202 200 return (retval); 203 201 } … … 256 254 { 257 255 /*@ buffer ****************************************************** */ 258 char callstr[MAX_STR_LEN * 2];256 char *callstr = NULL; 259 257 char incoming[MAX_STR_LEN * 2]; 260 258 char tmp[MAX_STR_LEN * 2]; 259 char *tmp1 = NULL; 261 260 char initial_label[MAX_STR_LEN * 2]; 262 261 … … 279 278 return (1); 280 279 } 281 // if (debug_level == TRUE) { debug_level=5; }282 283 // assert_string_is_neither_NULL_nor_zerolength(program);284 280 285 281 if (debug_level <= g_loglevel) { … … 287 283 log_if_failure = TRUE; 288 284 } 289 sprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err",285 mr_asprintf(&callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err", 290 286 program, bkpinfo->tmpdir, bkpinfo->tmpdir); 291 287 while ((p = strchr(callstr, '\r'))) { … … 315 311 "--------------------------------start of output-----------------------------"); 316 312 } 317 sprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir); 313 mr_free(callstr); 314 315 mr_asprintf(&callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir); 318 316 if (log_if_failure && system(callstr)) { 319 317 log_OS_error("Command failed"); 320 318 } 321 sprintf(tmp, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir); 322 unlink(tmp); 323 sprintf(tmp, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir); 324 fin = fopen(tmp, "r"); 319 mr_free(callstr); 320 321 mr_asprintf(&tmp1, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir); 322 unlink(tmp1); 323 mr_free(tmp1); 324 325 mr_asprintf(&tmp1, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir); 326 fin = fopen(tmp1, "r"); 325 327 if (fin) { 326 328 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); 327 329 fgets(incoming, MAX_STR_LEN, fin)) { 328 /* patch by Heiko Schlittermann */329 330 p = incoming; 330 331 while (p && *p) { … … 334 335 } 335 336 } 336 /* end of patch */337 337 strip_spaces(incoming); 338 338 if ((res == 0 && log_if_success) … … 343 343 paranoid_fclose(fin); 344 344 } 345 unlink(tmp); 345 unlink(tmp1); 346 mr_free(tmp1); 347 346 348 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) { 347 349 log_msg(0, … … 353 355 } 354 356 } 355 // else356 // { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); }357 357 return (res); 358 358 } … … 379 379 380 380 /*@ buffers **************************************************** */ 381 char tmp[MAX_STR_LEN * 2]; 382 char command[MAX_STR_LEN * 2]; 383 char lockfile[MAX_STR_LEN]; 381 char *tmp = NULL; 382 char *command = NULL; 383 char *lockfile = NULL; 384 char tmp1[MAX_STR_LEN *2]; 384 385 385 386 /*@ end vars *************************************************** */ … … 387 388 assert_string_is_neither_NULL_nor_zerolength(basic_call); 388 389 389 sprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);390 391 sprintf(command,390 mr_asprintf(&lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir); 391 392 mr_asprintf(&command, 392 393 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", 393 394 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 394 395 open_evalcall_form(what_i_am_doing); 395 sprintf(tmp, "Executing %s", basic_call);396 mr_asprintf(&tmp, "Executing %s", basic_call); 396 397 log_msg(2, tmp); 398 mr_free(tmp); 399 397 400 if (!(fin = popen(command, "r"))) { 398 401 log_OS_error("Unable to popen-in command"); 399 sprintf(tmp, "Failed utterly to call '%s'", command);402 mr_asprintf(&tmp, "Failed utterly to call '%s'", command); 400 403 log_to_screen(tmp); 404 mr_free(tmp); 405 mr_free(command); 406 mr_free(lockfile); 401 407 return (1); 402 408 } 409 mr_free(command); 410 403 411 if (!does_file_exist(lockfile)) { 404 412 log_to_screen("Waiting for external binary to start"); … … 412 420 while (does_file_exist(lockfile)) { 413 421 while (!feof(fin)) { 414 if (!fgets(tmp , 512, fin))422 if (!fgets(tmp1, 512, fin)) 415 423 break; 416 log_to_screen(tmp );424 log_to_screen(tmp1); 417 425 } 418 426 usleep(500000); … … 439 447 close_evalcall_form(); 440 448 unlink(lockfile); 449 mr_free(lockfile); 450 441 451 return (retval); 442 452 } … … 458 468 // if dir=='w' then copy from orig to archived 459 469 // if dir=='r' then copy from archived to orig 460 char *tmp; 461 char *buf; 462 char filestr[MAX_STR_LEN]; 470 char *tmp = NULL; 471 char *tmp1 = NULL; 472 char *buf = NULL; 473 char *filestr = NULL; 463 474 long int bytes_to_be_read, bytes_read_in, bytes_written_out = 464 475 0, bufcap, subsliceno = 0; … … 470 481 471 482 log_msg(5, "Opening."); 472 if (!(tmp = malloc(tmpcap))) { 473 fatal_error("Failed to malloc() tmp"); 474 } 475 tmp[0] = '\0'; 483 476 484 bufcap = 256L * 1024L; 477 485 if (!(buf = malloc(bufcap))) { … … 482 490 fin = f_orig; 483 491 fout = f_archived; 484 sprintf(tmp, "%-64s", PIMP_START_SZ);492 mr_asprintf(&tmp, "%-64s", PIMP_START_SZ); 485 493 if (fwrite(tmp, 1, 64, fout) != 64) { 494 mr_free(tmp); 486 495 fatal_error("Can't write the introductory block"); 487 496 } 497 mr_free(tmp); 498 488 499 while (1) { 489 500 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin); … … 491 502 break; 492 503 } 493 sprintf(tmp, "%-64ld", bytes_read_in);504 mr_asprintf(&tmp, "%-64ld", bytes_read_in); 494 505 if (fwrite(tmp, 1, 64, fout) != 64) { 506 mr_free(tmp); 495 507 fatal_error("Cannot write introductory block"); 496 508 } 509 mr_free(tmp); 510 497 511 log_msg(7, 498 512 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", 499 513 subsliceno, bytes_read_in, bytes_to_be_read); 500 514 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 501 sprintf(tmp, "%-64ld", subsliceno);515 mr_asprintf(&tmp, "%-64ld", subsliceno); 502 516 if (fwrite(tmp, 1, 64, fout) != 64) { 517 mr_free(tmp); 503 518 fatal_error("Cannot write post-thingy block"); 504 519 } 520 mr_free(tmp); 505 521 log_msg(7, "Subslice #%d written OK", subsliceno); 506 522 subsliceno++; 507 523 } 508 sprintf(tmp, "%-64ld", 0L);524 mr_asprintf(&tmp, "%-64ld", 0L); 509 525 if (fwrite(tmp, 1, 64L, fout) != 64L) { 526 mr_free(tmp); 510 527 fatal_error("Cannot write final introductory block"); 511 528 } 529 mr_free(tmp); 530 531 mr_asprintf(&tmp, "%-64s", PIMP_END_SZ); 532 if (fwrite(tmp, 1, 64, fout) != 64) { 533 mr_free(tmp); 534 fatal_error("Can't write the final block"); 535 } 536 mr_free(tmp); 512 537 } else { 513 538 fin = f_archived; 514 539 fout = f_orig; 515 if (fread(tmp, 1, 64L, fin) != 64L) { 540 if (!(tmp1 = malloc(tmpcap))) { 541 fatal_error("Failed to malloc() tmp"); 542 } 543 if (fread(tmp1, 1, 64L, fin) != 64L) { 544 mr_free(tmp1); 516 545 fatal_error("Cannot read the introductory block"); 517 546 } 518 log_msg(5, "tmp is %s", tmp); 519 if (!strstr(tmp, PIMP_START_SZ)) { 547 log_msg(5, "tmp1 is %s", tmp1); 548 if (!strstr(tmp1, PIMP_START_SZ)) { 549 mr_free(tmp1); 520 550 fatal_error("Can't find intro blk"); 521 551 } 522 if (fread(tmp, 1, 64L, fin) != 64L) { 552 if (fread(tmp1, 1, 64L, fin) != 64L) { 553 mr_free(tmp1); 523 554 fatal_error("Cannot read introductory blk"); 524 555 } 525 bytes_to_be_read = atol(tmp );556 bytes_to_be_read = atol(tmp1); 526 557 while (bytes_to_be_read > 0) { 527 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, 528 bytes_to_be_read); 558 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read); 529 559 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin); 530 560 if (bytes_read_in != bytes_to_be_read) { 531 fatal_error532 561 mr_free(tmp1); 562 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives."); 533 563 } 534 564 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 535 if (fread(tmp, 1, 64, fin) != 64) { 565 if (fread(tmp1, 1, 64, fin) != 64) { 566 mr_free(tmp1); 536 567 fatal_error("Cannot read post-thingy block"); 537 568 } 538 if (atol(tmp) != subsliceno) { 539 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", 540 subsliceno, atol(tmp), tmp); 569 if (atol(tmp1) != subsliceno) { 570 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1); 541 571 } 542 572 log_msg(7, "Subslice #%ld read OK", subsliceno); 543 573 subsliceno++; 544 if (fread(tmp, 1, 64, fin) != 64) { 574 if (fread(tmp1, 1, 64, fin) != 64) { 575 mr_free(tmp1); 545 576 fatal_error("Cannot read introductory block"); 546 577 } 547 bytes_to_be_read = atol(tmp); 548 } 549 } 550 551 // log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in); 552 553 if (direction == 'w') { 554 sprintf(tmp, "%-64s", PIMP_END_SZ); 555 if (fwrite(tmp, 1, 64, fout) != 64) { 556 fatal_error("Can't write the final block"); 557 } 558 } else { 559 log_msg(1, "tmpA is %s", tmp); 560 if (!strstr(tmp, PIMP_END_SZ)) { 561 if (fread(tmp, 1, 64, fin) != 64) { 578 bytes_to_be_read = atol(tmp1); 579 } 580 log_msg(1, "tmpA is %s", tmp1); 581 if (!strstr(tmp1, PIMP_END_SZ)) { 582 if (fread(tmp1, 1, 64, fin) != 64) { 583 mr_free(tmp1); 562 584 fatal_error("Can't read the final block"); 563 585 } 564 log_msg(5, "tmpB is %s", tmp );565 if (!strstr(tmp , PIMP_END_SZ)) {566 sprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);586 log_msg(5, "tmpB is %s", tmp1); 587 if (!strstr(tmp1, PIMP_END_SZ)) { 588 mr_asprintf(&filestr, "%s/out.leftover", bkpinfo->tmpdir); 567 589 ftmp = fopen(filestr, "w"); 568 bytes_read_in = fread(tmp, 1, 64, fin); 590 mr_free(filestr); 591 592 bytes_read_in = fread(tmp1, 1, 64, fin); 569 593 log_msg(1, "bytes_read_in = %ld", bytes_read_in); 570 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } 571 fwrite(tmp, 1, bytes_read_in, ftmp); 572 sprintf(tmp, "I am here - %lld", (long long)ftello(fin)); 573 // log_msg(0, tmp); 574 fread(tmp, 1, tmpcap, fin); 575 log_msg(0, "tmp = '%s'", tmp); 576 fwrite(tmp, 1, tmpcap, ftmp); 594 595 fwrite(tmp1, 1, bytes_read_in, ftmp); 596 fread(tmp1, 1, tmpcap, fin); 597 log_msg(0, "tmp1 = '%s'", tmp1); 598 fwrite(tmp1, 1, tmpcap, ftmp); 577 599 fclose(ftmp); 600 mr_free(tmp1); 578 601 fatal_error("Missing terminating block"); 579 602 } 580 603 } 604 mr_free(tmp1); 581 605 } 582 606 583 607 paranoid_free(buf); 584 paranoid_free(tmp);585 608 log_msg(3, "Successfully copied %ld bytes", bytes_written_out); 586 609 return (retval); … … 600 623 // BACKUP 601 624 int res = -1; 602 char*command ;625 char*command = NULL; 603 626 604 627 if (!does_file_exist(input_device)) { … … 608 631 fatal_error("ntfsclone not found"); 609 632 } 610 malloc_string(command); 611 sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device); 633 mr_asprintf(&command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device); 612 634 res = run_program_and_log_output(command, 5); 613 paranoid_free(command); 635 mr_free(command); 636 614 637 unlink(output_fname); 615 638 return (res); … … 649 672 650 673 /*@ buffers *********************************************************** */ 651 char *command ;674 char *command = NULL; 652 675 char *title; 653 676 /*@ pointers ********************************************************** */ … … 662 685 663 686 malloc_string(title); 664 malloc_string(command);665 687 strcpy(title, tt); 666 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);688 mr_asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE); 667 689 log_msg(3, "command = '%s'", command); 668 if ((res = 669 pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, 670 (void *) command))) { 690 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) { 671 691 fatal_error("Unable to create an archival thread"); 672 692 } … … 693 713 update_evalcall_form(percentage); 694 714 } 715 mr_free(command); 716 695 717 log_file_end_to_screen(MONDO_LOGFILE, ""); 696 718 close_evalcall_form(); … … 702 724 } 703 725 log_msg(3, "Parent res = %d", res); 704 paranoid_free(command);705 726 paranoid_free(title); 706 727 return (res); … … 720 741 // RESTORE 721 742 int res = -1; 722 char *command ;743 char *command = NULL; 723 744 724 745 if ( !find_home_of_exe("ntfsclone")) { 725 746 fatal_error("ntfsclone not found"); 726 747 } 727 malloc_string(command); 728 sprintf(command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo); 748 mr_asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo); 729 749 res = run_program_and_log_output(command, 5); 730 paranoid_free(command);750 mr_free(command); 731 751 return (res); 732 752 }
Note:
See TracChangeset
for help on using the changeset viewer.