- Timestamp:
- Nov 22, 2005, 5:47:53 PM (19 years ago)
- Location:
- trunk/mondo/mondo/common
- Files:
-
- 2 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-fork.c
r89 r130 1 /* libmondo-fork.c 2 $Id$ 3 4 - subroutines for handling forking/pthreads/etc. 5 6 7 06/20/2004 8 - create fifo /var/log/partimagehack-debug.log and empty it 9 to keep ramdisk from filling up 10 11 04/13/2004 12 - >= should be <= g_loglevel 13 14 11/15/2003 15 - changed a few []s to char*s 16 17 10/12 18 - rewrote partimagehack handling (multiple fifos, chunks, etc.) 19 20 10/11 21 - partimagehack now has debug level of N (set in my-stuff.h) 22 23 10/08 24 - call to partimagehack when restoring will now log errors to /var/log/....log 25 26 10/06 27 - cleaned up logging a bit 28 29 09/30 30 - line 735 - missing char* cmd in sprintf() 31 32 09/28 33 - added run_external_binary_with_percentage_indicator() 34 - rewritten eval_call_to_make_ISO() 35 36 09/18 37 - call mkstemp instead of mktemp 38 39 09/13 40 - major NTFS hackage 41 42 09/12 43 - paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack 44 45 09/11 46 - forward-ported unbroken feed_*_partimage() subroutines 47 from early August 2003 48 49 09/08 50 - detect & use partimagehack if it exists 51 52 09/05 53 - finally finished partimagehack hack :) 54 55 07/04 56 - added subroutines to wrap around partimagehack 57 58 04/27 59 - don't echo (...res=%d...) at end of log_it() 60 unnecessarily 61 - replace newtFinished() and newtInit() with 62 newtSuspend() and newtResume() 63 64 04/24 65 - added some assert()'s and log_OS_error()'s 66 67 04/09 68 - cleaned up run_program_and_log_output() 69 70 04/07 71 - cleaned up code a bit 72 - let run_program_and_log_output() accept -1 (only log if _no error_) 73 74 01/02/2003 75 - in eval_call_to_make_ISO(), append output to MONDO_LOGFILE 76 instead of a temporary stderr text file 77 78 12/10 79 - patch by Heiko Schlittermann to handle % chars in issue.net 80 81 11/18 82 - if mkisofs in eval_call_to_make_ISO() returns an error then return it, 83 whether ISO was created or not 84 85 10/30 86 - if mkisofs in eval_call_to_make_ISO() returns an error then find out if 87 the output (ISO) file has been created; if it has then return 0 anyway 88 89 08/01 - 09/30 90 - run_program_and_log_output() now takes boolean operator to specify 91 whether it will log its activities in the event of _success_ 92 - system() now includes 2>/dev/null 93 - enlarged some tmp[]'s 94 - added run_program_and_log_to_screen() and run_program_and_log_output() 95 96 07/24 97 - created 1 /* $Id$ 2 subroutines for handling forking/pthreads/etc. 98 3 */ 99 4 … … 126 31 { 127 32 /*@ buffers ***************************************************** */ 128 static char result[512];129 char *tmp ;33 static char *result = NULL; 34 char *tmp = NULL; 130 35 131 36 /*@ pointers **************************************************** */ 132 37 FILE *fin; 133 38 134 /*@ initialize data ********************************************* */ 135 malloc_string(tmp); 136 result[0] = '\0'; 137 tmp[0] = '\0'; 39 int n = 0; 138 40 139 41 /*@******************************************************************** */ … … 141 43 assert_string_is_neither_NULL_nor_zerolength(call); 142 44 if ((fin = popen(call, "r"))) { 143 for ( fgets(tmp, MAX_STR_LEN, fin); !feof(fin);144 fgets(tmp, MAX_STR_LEN, fin)) {45 for (getline(&tmp, &n, fin); !feof(fin); 46 getline(&tmp, &n, fin)) { 145 47 if (strlen(tmp) > 1) { 146 strcpy(result, tmp); 48 if (result != NULL) { 49 paranoid_free(result); 50 } 51 asprintf(&result, tmp); 147 52 } 148 53 } … … 152 57 } 153 58 strip_spaces(result); 59 paranoid_free(tmp); 154 60 return (result); 155 61 } 156 157 158 159 160 161 62 162 63 #define MONDO_POPMSG "Your PC will not retract the CD tray automatically. Please call mondoarchive with the -m (manual CD tray) flag." … … 190 91 191 92 /*@ buffers *** */ 192 char *midway_call, *ultimate_call, *tmp, *command, *incoming,193 * old_stderr, *cd_number_str;93 char *midway_call, *ultimate_call, *tmp, *command, 94 *cd_number_str; 194 95 char *p; 195 96 … … 210 111 fatal_error("Cannot malloc tmp"); 211 112 } 212 if (!(command = malloc(1200))) { 213 fatal_error("Cannot malloc command"); 214 } 215 malloc_string(incoming); 216 malloc_string(old_stderr); 217 malloc_string(cd_number_str); 218 219 incoming[0] = '\0'; 220 old_stderr[0] = '\0'; 221 222 sprintf(cd_number_str, "%d", cd_no); 113 114 asprintf(&cd_number_str, "%d", cd_no); 223 115 resolve_naff_tokens(midway_call, basic_call, isofile, "_ISO_"); 224 116 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_"); 117 paranoid_free(cd_number_str); 118 225 119 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 226 120 log_msg(4, "basic call = '%s'", basic_call); … … 228 122 log_msg(4, "tmp = '%s'", tmp); 229 123 log_msg(4, "ultimate call = '%s'", ultimate_call); 230 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);124 asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 231 125 232 126 log_to_screen … … 246 140 } 247 141 } 248 strcpy(command, tmp); 142 paranoid_free(command); 143 asprintf(&command, tmp); 249 144 #ifndef _XWIN 250 145 if (!g_text_mode) { … … 272 167 (what_i_am_doing, command); 273 168 } 169 paranoid_free(command); 274 170 275 171 paranoid_free(midway_call); 276 172 paranoid_free(ultimate_call); 277 173 paranoid_free(tmp); 278 paranoid_free(command);279 paranoid_free(incoming);280 paranoid_free(old_stderr);281 paranoid_free(cd_number_str);282 /*283 if (bkpinfo->backup_media_type == dvd && !bkpinfo->please_dont_eject_when_restoring)284 {285 log_msg(3, "Ejecting DVD device");286 eject_device(bkpinfo->media_device);287 }288 */289 174 return (retval); 290 175 } 291 292 293 176 294 177 … … 302 185 { 303 186 /*@ buffer ****************************************************** */ 304 char callstr[MAX_STR_LEN * 2];305 char incoming[MAX_STR_LEN * 2];187 char *callstr; 188 char *incoming = NULL; 306 189 char tmp[MAX_STR_LEN * 2]; 307 char initial_label[MAX_STR_LEN * 2];308 190 309 191 /*@ int ********************************************************* */ 310 192 int res; 311 193 int i; 194 int n = 0; 312 195 int len; 313 196 bool log_if_failure = FALSE; … … 325 208 return (1); 326 209 } 327 // if (debug_level == TRUE) { debug_level=5; }328 329 // assert_string_is_neither_NULL_nor_zerolength(program);330 210 331 211 if (debug_level <= g_loglevel) { … … 333 213 log_if_failure = TRUE; 334 214 } 335 sprintf(callstr,215 asprintf(&callstr, 336 216 "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err", 337 217 program); … … 355 235 strcat(tmp, "-"); 356 236 } 357 strcpy(initial_label, tmp);358 237 res = system(callstr); 359 238 if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) { … … 362 241 "--------------------------------start of output-----------------------------"); 363 242 } 243 paranoid_free(callstr); 244 364 245 if (log_if_failure 365 246 && … … 372 253 fin = fopen("/tmp/mondo-run-prog-thing.tmp", "r"); 373 254 if (fin) { 374 for ( fgets(incoming, MAX_STR_LEN, fin); !feof(fin);375 fgets(incoming, MAX_STR_LEN, fin)) {255 for (getline(&incoming, &n, fin); !feof(fin); 256 getline(&incoming, &n, fin)) { 376 257 /* patch by Heiko Schlittermann */ 377 258 p = incoming; … … 389 270 } 390 271 } 272 paranoid_free(incoming); 391 273 paranoid_fclose(fin); 392 274 } … … 407 289 408 290 409 410 291 /** 411 292 * Run a program and log its output to the screen. … … 421 302 int retval = 0; 422 303 int res = 0; 304 int n = 0; 423 305 int i; 424 306 … … 427 309 428 310 /*@ buffers **************************************************** */ 429 char tmp[MAX_STR_LEN * 2];430 char command[MAX_STR_LEN * 2];431 char lockfile[MAX_STR_LEN];311 char *tmp; 312 char *command; 313 char *lockfile; 432 314 433 315 /*@ end vars *************************************************** */ … … 435 317 assert_string_is_neither_NULL_nor_zerolength(basic_call); 436 318 437 sprintf(lockfile, "/tmp/mojo-jojo.blah.XXXXXX");319 asprintf(&lockfile, "/tmp/mojo-jojo.blah.XXXXXX"); 438 320 mkstemp(lockfile); 439 sprintf(command,321 asprintf(&command, 440 322 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", 441 323 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 442 324 open_evalcall_form(what_i_am_doing); 443 sprintf(tmp, "Executing %s", basic_call);325 asprintf(&tmp, "Executing %s", basic_call); 444 326 log_msg(2, tmp); 327 paranoid_free(tmp); 328 445 329 if (!(fin = popen(command, "r"))) { 446 330 log_OS_error("Unable to popen-in command"); 447 sprintf(tmp, "Failed utterly to call '%s'", command);331 asprintf(&tmp, "Failed utterly to call '%s'", command); 448 332 log_to_screen(tmp); 333 paranoid_free(tmp); 334 paranoid_free(lockfile); 335 paranoid_free(command); 449 336 return (1); 450 337 } 338 paranoid_free(command); 339 451 340 if (!does_file_exist(lockfile)) { 452 341 log_to_screen("Waiting for external binary to start"); … … 458 347 /* This only can update when newline goes into the file, 459 348 but it's *much* prettier/faster on Qt. */ 349 tmp = NULL; 460 350 while (does_file_exist(lockfile)) { 461 351 while (!feof(fin)) { 462 if (! fgets(tmp, 512, fin))352 if (!getline(&tmp, &n, fin)) 463 353 break; 464 354 log_to_screen(tmp); … … 466 356 usleep(500000); 467 357 } 358 paranoid_free(tmp); 468 359 #else 469 360 /* This works on Newt, and it gives quicker updates. */ … … 488 379 close_evalcall_form(); 489 380 unlink(lockfile); 381 paranoid_free(lockfile); 382 490 383 return (retval); 491 384 } 492 493 494 495 385 496 386 … … 531 421 532 422 /** 533 * Apparently u nused. @bug This has a purpose, but what?423 * Apparently used. @bug This has a purpose, but what? 534 424 */ 535 425 #define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8" … … 560 450 561 451 log_msg(5, "Opening."); 562 malloc_string(tmp);563 tmp[0] = '\0';564 452 bufcap = 256L * 1024L; 565 453 if (!(buf = malloc(bufcap))) { … … 570 458 fin = f_orig; 571 459 fout = f_archived; 572 sprintf(tmp, "%-64s", PIMP_START_SZ);460 asprintf(&tmp, "%-64s", PIMP_START_SZ); 573 461 if (fwrite(tmp, 1, 64, fout) != 64) { 574 462 fatal_error("Can't write the introductory block"); 575 463 } 464 paranoid_free(tmp); 465 576 466 while (1) { 577 467 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin); … … 579 469 break; 580 470 } 581 sprintf(tmp, "%-64ld", bytes_read_in);471 asprintf(&tmp, "%-64ld", bytes_read_in); 582 472 if (fwrite(tmp, 1, 64, fout) != 64) { 583 473 fatal_error("Cannot write introductory block"); 584 474 } 475 paranoid_free(tmp); 476 585 477 log_msg(7, 586 478 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", 587 479 subsliceno, bytes_read_in, bytes_to_be_read); 588 480 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 589 sprintf(tmp, "%-64ld", subsliceno);481 asprintf(&tmp, "%-64ld", subsliceno); 590 482 if (fwrite(tmp, 1, 64, fout) != 64) { 591 483 fatal_error("Cannot write post-thingy block"); 592 484 } 485 paranoid_free(tmp); 486 593 487 log_msg(7, "Subslice #%d written OK", subsliceno); 594 488 subsliceno++; 595 489 } 596 sprintf(tmp, "%-64ld", 0L);490 asprintf(&tmp, "%-64ld", 0L); 597 491 if (fwrite(tmp, 1, 64L, fout) != 64L) { 598 492 fatal_error("Cannot write final introductory block"); … … 601 495 fin = f_archived; 602 496 fout = f_orig; 497 if (!(tmp = malloc(64L))) { 498 fatal_error("Failed to malloc() tmp"); 499 } 603 500 if (fread(tmp, 1, 64L, fin) != 64L) { 604 501 fatal_error("Cannot read the introductory block"); … … 640 537 641 538 if (direction == 'w') { 642 sprintf(tmp, "%-64s", PIMP_END_SZ);539 asprintf(&tmp, "%-64s", PIMP_END_SZ); 643 540 if (fwrite(tmp, 1, 64, fout) != 64) { 644 541 fatal_error("Can't write the final block"); 645 542 } 543 paranoid_free(tmp); 646 544 } else { 647 545 log_msg(1, "tmpA is %s", tmp); … … 657 555 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } 658 556 fwrite(tmp, 1, bytes_read_in, ftmp); 659 sprintf(tmp, "I am here - %ld", ftell(fin)); 660 // log_msg(0, tmp); 557 paranoid_free(tmp); 558 559 if (!(tmp = malloc(512))) { 560 fatal_error("Failed to malloc() tmp"); 561 } 661 562 fread(tmp, 1, 512, fin); 662 563 log_msg(0, "tmp = '%s'", tmp); … … 666 567 } 667 568 } 569 paranoid_free(tmp); 668 570 } 669 571 670 572 paranoid_free(buf); 671 paranoid_free(tmp);672 573 log_msg(3, "Successfully copied %ld bytes", bytes_written_out); 673 574 return (retval); … … 686 587 { 687 588 char *curr_fifo; 688 char *prev_fifo ;589 char *prev_fifo = NULL; 689 590 char *next_fifo; 690 591 char *command; … … 699 600 char *tmp; 700 601 701 malloc_string(tmpstub);702 malloc_string(curr_fifo);703 malloc_string(prev_fifo);704 malloc_string(next_fifo);705 malloc_string(command);706 malloc_string(sz_call_to_partimage);707 malloc_string(tmp);708 709 602 log_msg(1, "g_tmpfs_mountpt = %s", g_tmpfs_mountpt); 710 603 if (g_tmpfs_mountpt && g_tmpfs_mountpt[0] 711 604 && does_file_exist(g_tmpfs_mountpt)) { 712 strcpy(tmpstub, g_tmpfs_mountpt);605 asprintf(&tmpstub, g_tmpfs_mountpt); 713 606 } else { 714 strcpy(tmpstub, "/tmp");607 asprintf(&tmpstub, "/tmp"); 715 608 } 716 609 paranoid_system("rm -f /tmp/*PARTIMAGE*"); 717 sprintf(command, "rm -Rf %s/pih-fifo-*", tmpstub);610 asprintf(&command, "rm -Rf %s/pih-fifo-*", tmpstub); 718 611 paranoid_system(command); 719 sprintf(tmpstub + strlen(tmpstub), "/pih-fifo-%ld", 720 (long int) random()); 612 paranoid_free(command); 613 614 asprintf(&tmp, "%s/pih-fifo-%ld", tmpstub, (long int) random()); 615 paranoid_free(tmpstub); 616 tmpstub = tmp; 617 paranoid_free(tmp); 618 721 619 mkfifo(tmpstub, S_IRWXU | S_IRWXG); // never used, though... 722 sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);723 sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);620 asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number); 621 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 724 622 mkfifo(curr_fifo, S_IRWXU | S_IRWXG); 725 623 mkfifo(next_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo already exists before we call partimage 726 sz_call_to_partimage[0] = 2; 727 sz_call_to_partimage[1] = 0; 728 sprintf(sz_call_to_partimage + 2, 729 "partimagehack " PARTIMAGE_PARAMS 730 " save %s %s > /tmp/stdout 2> /tmp/stderr", input_device, 624 asprintf(&sz_call_to_partimage, 625 "%c%cpartimagehack " PARTIMAGE_PARAMS 626 " save %s %s > /tmp/stdout 2> /tmp/stderr", 2, 0, input_device, 731 627 tmpstub); 732 628 log_msg(5, "curr_fifo = %s", curr_fifo); … … 750 646 log_to_screen("Working with partimagehack..."); 751 647 while (sz_call_to_partimage[0] > 0) { 752 sprintf(tmp, "%s\n", NEXT_SUBVOL_PLEASE);648 asprintf(&tmp, "%s\n", NEXT_SUBVOL_PLEASE); 753 649 if (fwrite(tmp, 1, 128, fout) != 128) { 754 650 fatal_error("Cannot write interim block"); 755 651 } 652 paranoid_free(tmp); 653 756 654 log_msg(5, "fifo_number=%d", fifo_number); 757 655 log_msg(4, "Cat'ting %s", curr_fifo); … … 759 657 fatal_error("Unable to openin from fifo"); 760 658 } 761 // if (!sz_call_to_partimage[0]) { break; } 762 log_msg(5, "Deleting %s", prev_fifo); 763 unlink(prev_fifo); // just in case 659 if (prev_fifo != NULL) { 660 log_msg(5, "Deleting %s", prev_fifo); 661 unlink(prev_fifo); // just in case 662 paranoid_free(prev_fifo); 663 } 764 664 copy_from_src_to_dest(fin, fout, 'w'); 765 665 paranoid_fclose(fin); 766 666 fifo_number++; 767 strcpy(prev_fifo, curr_fifo); 768 strcpy(curr_fifo, next_fifo); 667 668 prev_fifo = curr_fifo; 669 curr_fifo = next_fifo; 769 670 log_msg(5, "Creating %s", next_fifo); 770 sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);671 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 771 672 mkfifo(next_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo exists before we cat this one 772 673 system("sync"); 773 674 sleep(5); 774 675 } 775 sprintf(tmp, "%s\n", NO_MORE_SUBVOLS);676 asprintf(&tmp, "%s\n", NO_MORE_SUBVOLS); 776 677 if (fwrite(tmp, 1, 128, fout) != 128) { 777 678 fatal_error("Cannot write interim block"); … … 786 687 fatal_error("Cannot write interim block"); 787 688 } 689 paranoid_free(tmp); 788 690 paranoid_fclose(fout); 789 691 log_to_screen("Cleaning up after partimagehack..."); … … 791 693 paranoid_system("sync"); 792 694 unlink(next_fifo); 695 paranoid_free(next_fifo); 696 793 697 unlink(curr_fifo); 698 paranoid_free(curr_fifo); 699 794 700 unlink(prev_fifo); 701 paranoid_free(prev_fifo); 702 795 703 log_to_screen("Finished cleaning up."); 796 704 … … 800 708 pthread_join(partimage_thread, NULL); 801 709 res = sz_call_to_partimage[1]; 710 paranoid_free(sz_call_to_partimage); 802 711 log_msg(2, "pthread_join() joined OK."); 803 712 log_msg(1, "Partimagehack(save) returned %d", res); 804 713 unlink(tmpstub); 805 paranoid_free(curr_fifo);806 paranoid_free(prev_fifo);807 paranoid_free(next_fifo);808 714 paranoid_free(tmpstub); 809 paranoid_free(tmp); 810 paranoid_free(command); 715 811 716 return (res); 812 717 } … … 835 740 return (res); 836 741 } 837 838 839 840 742 841 743 … … 853 755 char *command; 854 756 char *tempfile; 855 char *title;856 757 /*@ pointers ********************************************************** */ 857 758 FILE *pin; 858 759 859 malloc_string(title);860 malloc_string(command);861 malloc_string(tempfile);862 760 assert_string_is_neither_NULL_nor_zerolength(cmd); 863 assert_string_is_neither_NULL_nor_zerolength(title); 864 865 strcpy(title, tt); 866 strcpy(tempfile, 761 762 asprintf(&tempfile, 867 763 call_program_and_get_last_line_of_output 868 764 ("mktemp -q /tmp/mondo.XXXXXXXX")); 869 sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,765 asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile, 870 766 tempfile); 871 767 log_msg(3, command); 872 open_evalcall_form(title); 768 open_evalcall_form(tt); 769 873 770 if (!(pin = popen(command, "r"))) { 874 771 log_OS_error("fmt err"); 772 paranoid_free(command); 773 paranoid_free(tempfile); 875 774 return (1); 876 775 } 776 paranoid_free(command); 777 877 778 maxpc = 100; 878 779 // OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD … … 886 787 if (pcno <= 5 && last_pcno > 40) { 887 788 close_evalcall_form(); 888 strcpy(title, "Verifying..."); 889 open_evalcall_form(title); 789 open_evalcall_form("Verifying..."); 890 790 } 891 791 last_pcno = pcno; … … 899 799 } 900 800 unlink(tempfile); 901 paranoid_free(command);902 801 paranoid_free(tempfile); 903 paranoid_free(title);904 802 return (res); 905 803 } 906 907 908 804 909 805 … … 924 820 pthread_exit((void *) (&res)); 925 821 } 926 927 928 822 929 823 … … 941 835 /*@ buffers *********************************************************** */ 942 836 char *command; 943 char *title;944 837 /*@ pointers ********************************************************** */ 945 838 static int chldres = 0; … … 952 845 *pchild_result = 999; 953 846 954 malloc_string(title); 955 malloc_string(command); 956 strcpy(title, tt); 957 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 847 asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE); 958 848 log_msg(3, "command = '%s'", command); 959 849 if ((res = … … 964 854 965 855 log_msg(8, "Parent running"); 966 open_evalcall_form(t itle);856 open_evalcall_form(tt); 967 857 for (sleep(1); command[0] != '\0'; sleep(1)) { 968 858 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE); … … 974 864 if (pcno <= 5 && last_pcno >= 40) { 975 865 close_evalcall_form(); 976 strcpy(title, "Verifying..."); 977 open_evalcall_form(title); 866 open_evalcall_form("Verifying..."); 978 867 } 979 868 if (counter++ >= 5) { … … 984 873 update_evalcall_form(percentage); 985 874 } 875 paranoid_free(command); 876 986 877 log_file_end_to_screen(MONDO_LOGFILE, ""); 987 878 close_evalcall_form(); … … 993 884 } 994 885 log_msg(3, "Parent res = %d", res); 995 paranoid_free(command);996 paranoid_free(title);997 886 return (res); 998 887 } 999 888 1000 1001 1002 889 #define PIH_LOG "/var/log/partimage-debug.log" 1003 1004 890 1005 891 /** … … 1014 900 // RESTORE 1015 901 char *tmp; 1016 // char *command;1017 902 char *stuff; 1018 903 char *sz_call_to_partimage; … … 1021 906 char *curr_fifo; 1022 907 char *prev_fifo; 1023 char *oldest_fifo ;908 char *oldest_fifo = NULL; 1024 909 char *next_fifo; 1025 910 char *afternxt_fifo; … … 1029 914 FILE *fout; 1030 915 1031 malloc_string(curr_fifo);1032 malloc_string(prev_fifo);1033 malloc_string(next_fifo);1034 malloc_string(afternxt_fifo);1035 malloc_string(oldest_fifo);1036 malloc_string(tmp);1037 sz_call_to_partimage = malloc(1000);1038 malloc_string(stuff);1039 malloc_string(tmpstub);1040 1041 916 log_msg(1, "output_device=%s", output_device); 1042 917 log_msg(1, "input_fifo=%s", input_fifo); 1043 /* I don't trust g_tmpfs_mountpt 1044 if (g_tmpfs_mountpt[0]) 1045 { 1046 strcpy(tmpstub, g_tmpfs_mountpt); 1047 } 1048 else 1049 { 1050 */ 1051 strcpy(tmpstub, "/tmp"); 1052 // } 918 asprintf(&tmpstub, "/tmp"); 919 1053 920 log_msg(1, "tmpstub was %s", tmpstub); 1054 strcpy(stuff, tmpstub); 1055 sprintf(tmpstub, "%s/pih-fifo-%ld", stuff, (long int) random()); 921 asprintf(&stuff, tmpstub); 922 paranoid_free(tmpstub); 923 924 asprintf(&tmpstub, "%s/pih-fifo-%ld", stuff, (long int) random()); 925 paranoid_free(stuff); 926 1056 927 log_msg(1, "tmpstub is now %s", tmpstub); 1057 928 unlink("/tmp/PARTIMAGEHACK-POSITION"); 1058 929 unlink(PAUSE_PARTIMAGE_FNAME); 1059 930 paranoid_system("rm -f /tmp/*PARTIMAGE*"); 1060 sprintf(curr_fifo, "%s.%03d", tmpstub, fifo_number);1061 sprintf(next_fifo, "%s.%03d", tmpstub, fifo_number + 1);1062 sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2);931 asprintf(&curr_fifo, "%s.%03d", tmpstub, fifo_number); 932 asprintf(&next_fifo, "%s.%03d", tmpstub, fifo_number + 1); 933 asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2); 1063 934 mkfifo(PIH_LOG, S_IRWXU | S_IRWXG); 1064 935 mkfifo(curr_fifo, S_IRWXU | S_IRWXG); … … 1077 948 fatal_error("partimagehack not found"); 1078 949 } 1079 sz_call_to_partimage[0] = 2; 1080 sz_call_to_partimage[1] = 0; 1081 sprintf(sz_call_to_partimage + 2, 1082 "partimagehack " PARTIMAGE_PARAMS 1083 " restore %s %s > /dev/null 2>> %s", output_device, curr_fifo, 950 asprintf(&sz_call_to_partimage, 951 "%c%cpartimagehack " PARTIMAGE_PARAMS 952 " restore %s %s > /dev/null 2>> %s", 2, 0, output_device, curr_fifo, 1084 953 MONDO_LOGFILE); 1085 954 log_msg(1, "output_device = %s", output_device); … … 1101 970 sleep(1); 1102 971 } 972 973 if (!(tmp = malloc(128))) { 974 fatal_error("Failed to malloc() tmp"); 975 } 1103 976 while (sz_call_to_partimage[0] > 0) { 1104 977 if (fread(tmp, 1, 128, fin) != 128) { … … 1123 996 fatal_error("Cannot openout to curr_fifo"); 1124 997 } 1125 log_msg(6, "Deleting %s", oldest_fifo);1126 998 copy_from_src_to_dest(fout, fin, 'r'); 1127 999 paranoid_fclose(fout); 1128 1000 fifo_number++; 1129 unlink(oldest_fifo); // just in case 1130 strcpy(oldest_fifo, prev_fifo); 1131 strcpy(prev_fifo, curr_fifo); 1132 strcpy(curr_fifo, next_fifo); 1133 strcpy(next_fifo, afternxt_fifo); 1134 sprintf(afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2); 1001 if (oldest_fifo != NULL) { 1002 log_msg(6, "Deleting %s", oldest_fifo); 1003 unlink(oldest_fifo); // just in case 1004 paranoid_free(oldest_fifo); 1005 } 1006 oldest_fifo = prev_fifo; 1007 prev_fifo = curr_fifo; 1008 curr_fifo = next_fifo; 1009 next_fifo = afternxt_fifo; 1010 asprintf(&afternxt_fifo, "%s.%03d", tmpstub, fifo_number + 2); 1135 1011 log_msg(6, "Creating %s", afternxt_fifo); 1136 1012 mkfifo(afternxt_fifo, S_IRWXU | S_IRWXG); // make sure _next_ fifo already exists before we access current fifo … … 1139 1015 usleep(1000L * 100L); 1140 1016 } 1017 paranoid_free(tmp); 1018 paranoid_free(tmpstub); 1019 1141 1020 paranoid_fclose(fin); 1142 1021 paranoid_system("sync"); … … 1145 1024 pthread_join(partimage_thread, NULL); 1146 1025 res = sz_call_to_partimage[1]; 1026 paranoid_free(sz_call_to_partimage); 1027 1147 1028 log_msg(1, "Yay. Partimagehack (restore) returned %d", res); 1148 1029 unlink(prev_fifo); 1030 paranoid_free(prev_fifo); 1031 1149 1032 unlink(curr_fifo); 1033 paranoid_free(curr_fifo); 1034 1150 1035 unlink(next_fifo); 1036 paranoid_free(next_fifo); 1037 1151 1038 unlink(afternxt_fifo); 1039 paranoid_free(afternxt_fifo); 1040 1152 1041 unlink(PIH_LOG); 1153 paranoid_free(tmp); 1154 paranoid_free(sz_call_to_partimage); 1155 paranoid_free(stuff); 1156 paranoid_free(prev_fifo); 1157 paranoid_free(curr_fifo); 1158 paranoid_free(next_fifo); 1159 paranoid_free(afternxt_fifo); 1042 /* BERLIOS : pas de unlink(oldest_fifo) ??? */ 1160 1043 paranoid_free(oldest_fifo); 1161 paranoid_free(tmpstub); 1044 1162 1045 return (res); 1163 1046 }
Note:
See TracChangeset
for help on using the changeset viewer.