Changeset 1113 in MondoRescue for branches/stable/mondo/src/common/libmondo-fork.c
- Timestamp:
- Feb 8, 2007, 3:08:10 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-fork.c
r1107 r1113 1 /* libmondo-fork.c 2 $Id$ 3 */ 4 5 1 /* libmondo-fork.c - subroutines for handling forking/pthreads/etc. 2 * $Id$ 3 */ 6 4 #include "my-stuff.h" 7 5 #include "mr_mem.h" … … 9 7 #include "libmondo-fork.h" 10 8 #include "libmondo-string-EXT.h" 11 #include " libmondo-gui-EXT.h"9 #include "newt-specific-EXT.h" 12 10 #include "libmondo-files-EXT.h" 13 11 #include "libmondo-tools-EXT.h" 14 #include " lib-common-externs.h"12 #include "mr_mem.h" 15 13 16 14 /*@unused@*/ … … 96 94 97 95 /*@ buffers *** */ 98 char *midway_call, *ultimate_call, *tmp, *command, *incoming, 99 *old_stderr, *cd_number_str; 100 char *p; 96 char *midway_call, *ultimate_call, *tmp; 97 char *p = NULL; 98 char *cd_number_str = NULL; 99 char *command = NULL; 100 101 101 102 102 /*@*********** End Variables ***************************************/ … … 107 107 assert_string_is_neither_NULL_nor_zerolength(isofile); 108 108 assert_string_is_neither_NULL_nor_zerolength(logstub); 109 109 110 midway_call = mr_malloc(1200); 110 111 ultimate_call = mr_malloc(1200); 111 112 tmp = mr_malloc(1200); 112 command = mr_malloc(1200); 113 malloc_string(incoming); 114 malloc_string(old_stderr); 115 malloc_string(cd_number_str); 116 117 incoming[0] = '\0'; 118 old_stderr[0] = '\0'; 119 120 sprintf(cd_number_str, "%d", cd_no); 113 114 mr_asprintf(&cd_number_str, "%d", cd_no); 121 115 resolve_naff_tokens(midway_call, basic_call, isofile, "_ISO_"); 122 116 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_"); 117 mr_free(cd_number_str); 118 123 119 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_"); 124 120 mr_msg(4, "basic call = '%s'", basic_call); … … 126 122 mr_msg(4, "tmp = '%s'", tmp); 127 123 mr_msg(4, "ultimate call = '%s'", ultimate_call); 128 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);124 mr_asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE); 129 125 130 126 log_to_screen 131 ( "Please be patient. Do not be alarmed by on-screen inactivity.");127 (_("Please be patient. Do not be alarmed by on-screen inactivity.")); 132 128 mr_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", 133 129 what_i_am_doing); 134 strcpy(tmp, command);135 130 if (bkpinfo->manual_cd_tray) { 136 p = strstr(tmp, "2>>"); 131 /* Find everything after a 2>> and remove it */ 132 p = strstr(command, "2>>"); 137 133 if (p) { 138 sprintf(p, " "); 139 while (*p == ' ') { 140 p++; 141 } 142 for (; *p != ' '; p++) { 134 for (; *p != ' ' && *p != '\0'; p++) { 143 135 *p = ' '; 144 136 } 145 137 } 146 strcpy(command, tmp);147 138 #ifndef _XWIN 148 139 if (!g_text_mode) { … … 157 148 if (retval) { 158 149 mr_msg(2, "Basic call '%s' returned an error.", basic_call); 159 popup_and_OK( "Press ENTER to continue.");150 popup_and_OK(_("Press ENTER to continue.")); 160 151 popup_and_OK 161 ( "mkisofs and/or cdrecord returned an error. CD was not created");152 (_("mkisofs and/or cdrecord returned an error. CD was not created")); 162 153 } 163 154 } … … 170 161 (what_i_am_doing, command); 171 162 } 163 mr_free(command); 172 164 173 165 mr_free(midway_call); 174 166 mr_free(ultimate_call); 175 167 mr_free(tmp); 176 mr_free(command);177 mr_free(incoming);178 mr_free(old_stderr);179 mr_free(cd_number_str);180 /*181 if (bkpinfo->backup_media_type == dvd && !bkpinfo->please_dont_eject_when_restoring)182 {183 mr_msg(3, "Ejecting DVD device");184 eject_device(bkpinfo->media_device);185 }186 */187 168 return (retval); 188 169 } 189 190 191 170 192 171 … … 200 179 { 201 180 /*@ buffer ****************************************************** */ 202 char callstr[MAX_STR_LEN * 2]; 203 char incoming[MAX_STR_LEN * 2]; 204 char tmp[MAX_STR_LEN * 2]; 205 char initial_label[MAX_STR_LEN * 2]; 181 char *callstr = NULL; 182 char *incoming = NULL; 206 183 207 184 /*@ int ********************************************************* */ 208 int res; 185 int res = 0; 186 size_t n = 0; 209 187 int i; 210 188 int len; … … 223 201 return (1); 224 202 } 225 // if (debug_level == TRUE) { debug_level=5; }226 227 // assert_string_is_neither_NULL_nor_zerolength(program);228 203 229 204 if (debug_level <= g_loglevel) { … … 231 206 log_if_failure = TRUE; 232 207 } 233 sprintf(callstr,208 mr_asprintf(&callstr, 234 209 "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err", 235 210 program); … … 260 235 "--------------------------------start of output-----------------------------"); 261 236 } 237 mr_free(callstr); 238 262 239 if (log_if_failure 263 240 && … … 270 247 fin = fopen("/tmp/mondo-run-prog-thing.tmp", "r"); 271 248 if (fin) { 272 for ( fgets(incoming, MAX_STR_LEN, fin); !feof(fin);273 fgets(incoming, MAX_STR_LEN, fin)) {249 for (mr_getline(&incoming, &n, fin); !feof(fin); 250 mr_getline(&incoming, &n, fin)) { 274 251 /* patch by Heiko Schlittermann */ 275 252 p = incoming; … … 287 264 } 288 265 } 266 mr_free(incoming); 289 267 paranoid_fclose(fin); 290 268 } … … 303 281 return (res); 304 282 } 305 306 283 307 284 … … 325 302 326 303 /*@ buffers **************************************************** */ 327 char tmp[MAX_STR_LEN * 2];328 char command[MAX_STR_LEN * 2];329 char lockfile[MAX_STR_LEN];304 char *tmp = NULL; 305 char *command = NULL; 306 char *lockfile = NULL; 330 307 331 308 /*@ end vars *************************************************** */ … … 333 310 assert_string_is_neither_NULL_nor_zerolength(basic_call); 334 311 335 sprintf(lockfile, "/tmp/mojo-jojo.blah.XXXXXX");312 mr_asprintf(&lockfile, "/tmp/mojo-jojo.blah.XXXXXX"); 336 313 mkstemp(lockfile); 337 sprintf(command,314 mr_asprintf(&command, 338 315 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", 339 316 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile); 340 317 open_evalcall_form(what_i_am_doing); 341 sprintf(tmp, "Executing %s", basic_call);318 mr_asprintf(&tmp, "Executing %s", basic_call); 342 319 mr_msg(2, tmp); 320 mr_free(tmp); 321 343 322 if (!(fin = popen(command, "r"))) { 344 323 log_OS_error("Unable to popen-in command"); 345 sprintf(tmp, "Failed utterly to call '%s'", command);324 mr_asprintf(&tmp, _("Failed utterly to call '%s'"), command); 346 325 log_to_screen(tmp); 326 mr_free(tmp); 327 mr_free(lockfile); 328 mr_free(command); 347 329 return (1); 348 330 } 331 mr_free(command); 332 349 333 if (!does_file_exist(lockfile)) { 350 log_to_screen( "Waiting for external binary to start");334 log_to_screen(_("Waiting for external binary to start")); 351 335 for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) { 352 336 mr_msg(3, "Waiting for lockfile %s to exist", lockfile); … … 375 359 res = pclose(fin); 376 360 /* Log actual pclose errors. */ 377 if (errno) mr_msg(5, "pclose err: %d", errno); 361 if (errno) { 362 mr_msg(5, "pclose err: %d", errno); 363 } 378 364 /* Check if we have a valid status. If we do, extract the called program's exit code. */ 379 365 /* If we don't, highlight this fact by returning -1. */ … … 385 371 close_evalcall_form(); 386 372 unlink(lockfile); 373 mr_free(lockfile); 374 387 375 return (retval); 388 376 } 389 377 390 378 391 392 393 379 /** 394 * Apparently u nused. @bug This has a purpose, but what?380 * Apparently used. @bug This has a purpose, but what? 395 381 */ 396 382 #define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8" … … 404 390 // if dir=='w' then copy from orig to archived 405 391 // if dir=='r' then copy from archived to orig 406 char *tmp ;407 char *buf ;392 char *tmp = NULL; 393 char *buf = NULL; 408 394 long int bytes_to_be_read, bytes_read_in, bytes_written_out = 409 395 0, bufcap, subsliceno = 0; 410 396 int retval = 0; 411 FILE *fin ;412 FILE *fout ;413 FILE *ftmp ;397 FILE *fin = NULL; 398 FILE *fout = NULL; 399 FILE *ftmp = NULL; 414 400 415 401 mr_msg(5, "Opening."); … … 526 512 } 527 513 528 529 530 531 514 /** 532 515 * Feed @p input_device through ntfsclone to @p output_fname. … … 539 522 // BACKUP 540 523 int res = -1; 541 char *command;524 char *command = NULL; 542 525 543 526 if (!does_file_exist(input_device)) { … … 547 530 fatal_error("ntfsclone not found"); 548 531 } 549 malloc_string(command); 550 sprintf(command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device); 532 mr_asprintf(&command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device); 551 533 res = run_program_and_log_output(command, 5); 552 534 mr_free(command); 535 553 536 unlink(output_fname); 554 537 return (res); … … 556 539 557 540 558 559 560 561 541 int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd) 562 542 { 563 543 564 /*@ int *************************************************************** */565 544 int res = 0; 566 545 int percentage = 0; … … 569 548 int last_pcno = 0; 570 549 571 /*@ buffers *********************************************************** */ 572 char *command; 550 char *command = NULL; 573 551 char *tempfile; 574 552 char *title; … … 577 555 578 556 malloc_string(title); 579 malloc_string(command);580 557 malloc_string(tempfile); 581 558 assert_string_is_neither_NULL_nor_zerolength(cmd); … … 586 563 call_program_and_get_last_line_of_output 587 564 ("mktemp -q /tmp/mondo.XXXXXXXX")); 588 sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,565 mr_asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile, 589 566 tempfile); 590 567 mr_msg(3, command); … … 592 569 if (!(pin = popen(command, "r"))) { 593 570 log_OS_error("fmt err"); 571 mr_free(command); 594 572 return (1); 595 573 } 574 mr_free(command); 575 596 576 maxpc = 100; 597 577 // OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD OLD … … 618 598 } 619 599 unlink(tempfile); 620 mr_free(command);621 600 mr_free(tempfile); 622 601 mr_free(title); 623 602 return (res); 624 603 } 625 626 627 604 628 605 … … 643 620 pthread_exit((void *) (&res)); 644 621 } 645 646 647 622 648 623 … … 659 634 660 635 /*@ buffers *********************************************************** */ 661 char *command ;636 char *command = NULL; 662 637 char *title; 663 638 /*@ pointers ********************************************************** */ … … 672 647 673 648 malloc_string(title); 674 malloc_string(command);675 649 strcpy(title, tt); 676 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);650 mr_asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE); 677 651 mr_msg(3, "command = '%s'", command); 678 652 if ((res = … … 703 677 update_evalcall_form(percentage); 704 678 } 679 mr_free(command); 680 705 681 log_file_end_to_screen(MONDO_LOGFILE, ""); 706 682 close_evalcall_form(); … … 712 688 } 713 689 mr_msg(3, "Parent res = %d", res); 714 mr_free(command);715 690 mr_free(title); 716 691 return (res); 717 692 } 718 719 720 693 721 694 … … 730 703 // RESTORE 731 704 int res = -1; 732 char *command ;705 char *command = NULL; 733 706 734 707 if ( !find_home_of_exe("ntfsclone")) { 735 708 fatal_error("ntfsclone not found"); 736 709 } 737 malloc_string(command); 738 sprintf(command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo); 710 mr_asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo); 739 711 res = run_program_and_log_output(command, 5); 740 712 mr_free(command);
Note:
See TracChangeset
for help on using the changeset viewer.