Changeset 3871 in MondoRescue for branches/3.3/mondo/src/common/libmondo-fork.c
- Timestamp:
- Mar 7, 2024, 6:06:33 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mondo/src/common/libmondo-fork.c
r3866 r3871 15 15 #include "libmondo-files-EXT.h" 16 16 #include "libmondo-tools-EXT.h" 17 #include "lib-common-externs.h" 17 18 18 19 19 /*@unused@*/ … … 87 87 #define MONDO_POPMSG "Your machine will not retract the CD tray automatically. Please call mondoarchive with the -m (manual CD tray) flag." 88 88 89 90 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) { 91 92 /*@ int *************************************************************** */ 93 int res = 0; 94 int percentage = 0; 95 int maxpc = 100; 96 int pcno = 0; 97 int counter = 0; 98 99 /*@ buffers *********************************************************** */ 100 char *command = NULL; 101 /*@ pointers ********************************************************** */ 102 static int chldres = 0; 103 int *pchild_result; 104 pthread_t childthread; 105 106 pchild_result = &chldres; 107 assert_string_is_neither_NULL_nor_zerolength(cmd); 108 assert_string_is_neither_NULL_nor_zerolength(tt); 109 *pchild_result = 999; 110 111 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE); 112 log_msg(3, "command = '%s'", command); 113 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) { 114 fatal_error("Unable to create an archival thread"); 115 } 116 117 log_msg(8, "Parent running"); 118 open_evalcall_form(tt); 119 120 for (sleep(1); command[0] != '\0'; sleep(1)) { 121 if (strstr(cmd,"mindi") != NULL) { 122 pcno = grab_percentage_from_last_line_of_file(MINDI_RUNFILE); 123 } else { 124 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE); 125 } 126 if (pcno < 0 || pcno > 100) { 127 log_msg(8, "Weird pc# %d", pcno); 128 continue; 129 } 130 percentage = pcno * 100 / maxpc; 131 if (counter++ >= 5) { 132 counter = 0; 133 log_file_end_to_screen(MONDO_LOGFILE, ""); 134 } 135 update_evalcall_form(percentage); 136 } 137 mr_free(command); 138 139 log_file_end_to_screen(MONDO_LOGFILE, ""); 140 close_evalcall_form(); 141 pthread_join(childthread, (void *) (&pchild_result)); 142 if (pchild_result) { 143 res = *pchild_result; 144 } else { 145 res = 666; 146 } 147 log_msg(3, "Parent res = %d", res); 148 return (res); 149 } 150 151 89 152 /** 90 153 * Call mkisofs to create an ISO image. … … 645 708 646 709 647 648 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) {649 650 /*@ int *************************************************************** */651 int res = 0;652 int percentage = 0;653 int maxpc = 100;654 int pcno = 0;655 int counter = 0;656 657 /*@ buffers *********************************************************** */658 char *command = NULL;659 /*@ pointers ********************************************************** */660 static int chldres = 0;661 int *pchild_result;662 pthread_t childthread;663 664 pchild_result = &chldres;665 assert_string_is_neither_NULL_nor_zerolength(cmd);666 assert_string_is_neither_NULL_nor_zerolength(tt);667 *pchild_result = 999;668 669 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);670 log_msg(3, "command = '%s'", command);671 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) {672 fatal_error("Unable to create an archival thread");673 }674 675 log_msg(8, "Parent running");676 open_evalcall_form(tt);677 678 for (sleep(1); command[0] != '\0'; sleep(1)) {679 if (strstr(cmd,"mindi") != NULL) {680 pcno = grab_percentage_from_last_line_of_file(MINDI_RUNFILE);681 } else {682 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);683 }684 if (pcno < 0 || pcno > 100) {685 log_msg(8, "Weird pc# %d", pcno);686 continue;687 }688 percentage = pcno * 100 / maxpc;689 if (counter++ >= 5) {690 counter = 0;691 log_file_end_to_screen(MONDO_LOGFILE, "");692 }693 update_evalcall_form(percentage);694 }695 mr_free(command);696 697 log_file_end_to_screen(MONDO_LOGFILE, "");698 close_evalcall_form();699 pthread_join(childthread, (void *) (&pchild_result));700 if (pchild_result) {701 res = *pchild_result;702 } else {703 res = 666;704 }705 log_msg(3, "Parent res = %d", res);706 return (res);707 }708 709 710 710 /** 711 711 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
Note:
See TracChangeset
for help on using the changeset viewer.