source: MondoRescue/branches/3.3/mondo/src/common/libmondo-fork.c@ 3863

Last change on this file since 3863 was 3863, checked in by Bruno Cornec, 2 months ago

eliminate the last sprintf from libmondo-fork.c

  • Property svn:keywords set to Id
File size: 19.7 KB
Line 
1/* libmondo-fork.c
2 $Id: libmondo-fork.c 3863 2024-03-07 10:50:40Z bruno $
3
4- subroutines for handling forking/pthreads/etc.
5*/
6
7
8#include "my-stuff.h"
9#include "mr_mem.h"
10#include "mr_str.h"
11#include "mr_sys.h"
12#include "mondostructures.h"
13#include "libmondo-string-EXT.h"
14#include "libmondo-gui-EXT.h"
15#include "libmondo-files-EXT.h"
16#include "libmondo-tools-EXT.h"
17#include "lib-common-externs.h"
18
19/*@unused@*/
20//static char cvsid[] = "$Id: libmondo-fork.c 3863 2024-03-07 10:50:40Z bruno $";
21
22extern t_bkptype g_backup_media_type;
23extern bool g_text_mode;
24extern char *MONDO_LOGFILE;
25extern char *MONDO_LOGFILENAME;
26
27/* Reference to global bkpinfo */
28extern struct s_bkpinfo *bkpinfo;
29pid_t g_buffer_pid = 0;
30
31
32/**
33 * Call a program and retrieve its last line of output.
34 * @param call The program to run.
35 * @return The last line of its output or the empty string.
36 * @note The returned value points to storage that needs to be freed by the
37 * caller
38 */
39char *call_program_and_get_last_line_of_output(const char *call) {
40 /*@ buffers ***************************************************** */
41 char *result = NULL;
42 char *resultbkp = NULL;
43 char *result2 = NULL;
44
45 /*@ pointers **************************************************** */
46 FILE *fin = NULL;
47 char *eng_call = NULL;
48
49 /*@******************************************************************** */
50
51 assert_string_is_neither_NULL_nor_zerolength(call);
52 mr_asprintf(eng_call,"LANG=C LANGUAGE=C %s",call);
53 log_msg(5, "cpaglloo called with '%s'", eng_call);
54 if ((fin = popen(eng_call, "r"))) {
55 while (!feof(fin)) {
56 mr_free(result);
57 mr_getline(result, fin);
58 if (strlen(result) > 1) {
59 log_msg(7, "result = '%s'", result);
60 /* in case we have to loop, we keep the
61 * previous value */
62 mr_free(resultbkp);
63 mr_asprintf(resultbkp, "%s", result);
64 } else {
65 /* we had to loop and got nothing useul, so we keep the
66 * previous value */
67 mr_free(result);
68 result = resultbkp;
69 }
70 }
71 paranoid_pclose(fin);
72 } else {
73 log_OS_error("Unable to open resulting file");
74 }
75 mr_free(eng_call);
76 if (result != NULL) {
77 result2 = mr_strip_spaces(result);
78 mr_free(result);
79 log_msg(5, "cpaglloo returns '%s'", result2);
80 } else {
81 mr_asprintf(result2, "");
82 }
83 return(result2);
84}
85
86
87#define MONDO_POPMSG "Your machine will not retract the CD tray automatically. Please call mondoarchive with the -m (manual CD tray) flag."
88
89/**
90 * Call mkisofs to create an ISO image.
91 * @param bkpinfo The backup information structure. Fields used:
92 * - @c bkpinfo->manual_cd_tray
93 * - @c bkpinfo->backup_media_type
94 * @param basic_call The call to mkisofs. May contain tokens that will be resolved to actual data. The tokens are:
95 * - @c _ISO_ will become the ISO file (@p isofile)
96 * - @c _CD#_ becomes the CD number (@p cd_no)
97 * - @c _ERR_ becomes the logfile (@p g_logfile)
98 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs).
99 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number.
100 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog.
101 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure).
102 */
103int
104eval_call_to_make_ISO(char *basic_call, char *isofile,
105 int cd_no, char *what_i_am_doing)
106{
107
108 /*@ int's *** */
109 int retval = 0;
110
111
112 /*@ buffers *** */
113 char *midway_call = NULL;
114 char *ultimate_call = NULL;
115 char *tmp = NULL;
116
117 char *cd_number_str = NULL;
118 char *command = NULL;
119 char *p= NULL;
120 char *tmp1 = NULL;
121 char *tmp2 = NULL;
122
123/*@*********** End Variables ***************************************/
124
125 log_msg(3, "Starting");
126 assert(bkpinfo != NULL);
127 assert_string_is_neither_NULL_nor_zerolength(isofile);
128
129 if (!(midway_call = malloc(1200))) {
130 fatal_error("Cannot malloc midway_call");
131 }
132 if (!(ultimate_call = malloc(1200))) {
133 fatal_error("Cannot malloc ultimate_call");
134 }
135 if (!(tmp = malloc(1200))) {
136 fatal_error("Cannot malloc tmp");
137 }
138
139 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
140 mr_asprintf(tmp1, "su - %s -c \"%s\"", bkpinfo->netfs_user, basic_call);
141 } else {
142 mr_asprintf(tmp1, "%s", basic_call);
143 }
144
145 mr_asprintf(cd_number_str, "%d", cd_no);
146 resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_");
147 log_msg(4, "basic call = '%s'", tmp1);
148 mr_free(tmp1);
149
150 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
151 log_msg(4, "midway_call = '%s'", midway_call);
152 mr_free(cd_number_str);
153
154 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
155 log_msg(4, "ultimate call = '%s'", ultimate_call);
156 mr_asprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
157
158 /* Copy the current logfile - of course incomplete to the media */
159 mr_system("gzip -c9 %s > ./archives/%d.%s", MONDO_LOGFILE, cd_number_str, MONDO_LOGFILENAME);
160
161 log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity.");
162 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing);
163 if (bkpinfo->manual_cd_tray) {
164 mr_asprintf(tmp2, "%s", command);
165 p = strstr(tmp2, "2>>");
166 if (p) {
167 /* overwrites the 2>> */
168 *p++ = ' ';
169 *p++ = ' ';
170 *p++ = ' ';
171 /* skip remaining spaces */
172 for (; (*p == ' ') && (*p != '\0'); p++);
173 /* overwrites what is after the 2>> */
174 for (; (*p != ' ') && (*p != '\0'); p++) {
175 *p = ' ';
176 }
177 }
178 mr_free(command);
179 command = tmp2;
180 if (!g_text_mode) {
181 newtSuspend();
182 }
183 log_msg(1, "command = '%s'", command);
184 retval += system(command);
185 if (!g_text_mode) {
186 newtResume();
187 }
188 if (retval) {
189 popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created");
190 }
191 }
192 /* if text mode then do the above & RETURN; if not text mode, do this... */
193 else {
194 log_msg(3, "command = '%s'", command);
195 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
196 }
197 mr_free(command);
198 paranoid_free(midway_call);
199 paranoid_free(ultimate_call);
200 paranoid_free(tmp);
201 return (retval);
202}
203
204
205/**
206 * Call copy of data to create an USB image.
207 * @param bkpinfo The backup information structure. Fields used:
208 * - @c bkpinfo->backup_media_type
209 * @return Exit code of @c copy (0 is success, anything else indicates failure).
210 */
211int
212eval_call_to_make_USB(char *command, char *what_i_am_doing) {
213
214 /*@ int's *** */
215 int retval = 0;
216
217
218/*@*********** End Variables ***************************************/
219
220 log_msg(3, "Starting");
221 assert(bkpinfo != NULL);
222
223 log_to_screen
224 ("Please be patient. Do not be alarmed by on-screen inactivity.");
225 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
226 what_i_am_doing);
227
228 if (!g_text_mode) {
229 newtSuspend();
230 }
231 log_msg(1, "command = '%s'", command);
232 if (!g_text_mode) {
233 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
234 } else {
235 retval += system(command);
236 }
237 if (!g_text_mode) {
238 newtResume();
239 }
240
241 return (retval);
242}
243
244
245
246
247/**
248 * Run a program and log its output (stdout and stderr) to the logfile.
249 * @param program The program to run. Passed to the shell, so you can use pipes etc.
250 * @param debug_level If @p g_loglevel is higher than this, do not log the output.
251 * @return The exit code of @p program (depends on the command, but 0 almost always indicates success).
252 */
253int run_program_and_log_output(char *program, int debug_level)
254{
255 /*@ buffer ****************************************************** */
256 char *callstr = NULL;
257 char *incoming = NULL;
258 char *tmp1 = NULL;
259 char *tmp2 = NULL;
260
261 /*@ int ********************************************************* */
262 int res;
263 bool log_if_failure = FALSE;
264 bool log_if_success = FALSE;
265
266 /*@ pointers *************************************************** */
267 FILE *fin;
268 char *p;
269
270 /*@ end vars *************************************************** */
271
272 assert(program != NULL);
273 if (!program[0]) {
274 log_msg(2, "Warning - asked to run zerolength program");
275 return(1);
276 }
277
278 if (debug_level <= g_loglevel) {
279 log_if_success = TRUE;
280 log_if_failure = TRUE;
281 }
282 mr_asprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err", program, bkpinfo->tmpdir, bkpinfo->tmpdir);
283 while ((p = strchr(callstr, '\r'))) {
284 *p = ' ';
285 }
286 while ((p = strchr(callstr, '\n'))) {
287 *p = ' ';
288 } /* single '=' is intentional */
289
290
291 res = system(callstr);
292 if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
293 log_msg(0, "running: %s", callstr);
294 log_msg(0, "--------------------------------start of output-----------------------------");
295 }
296 mr_free(callstr);
297
298 mr_asprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
299 if (log_if_failure && system(callstr)) {
300 log_OS_error("Command failed");
301 }
302 mr_free(callstr);
303
304 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
305 unlink(tmp1);
306 mr_free(tmp1);
307
308 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
309 fin = fopen(tmp1, "r");
310 if (fin) {
311 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
312 // Removes % char
313 tmp2 = mr_stresc(incoming, "%", '\\', '\'');
314 mr_free(incoming);
315 incoming = tmp2;
316
317 // Remove spaces
318 tmp2 = mr_strip_spaces(incoming);
319 mr_free(incoming);
320 incoming = tmp2;
321 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
322 log_msg(0, incoming);
323 }
324 mr_free(incoming);
325 }
326 mr_free(incoming);
327 paranoid_fclose(fin);
328 }
329 unlink(tmp1);
330 mr_free(tmp1);
331
332 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
333 log_msg(0,
334 "--------------------------------end of output------------------------------");
335 if (res) {
336 log_msg(0, "...ran with res=%d", res);
337 } else {
338 log_msg(0, "...ran just fine. :-)");
339 }
340 }
341 return(res);
342}
343
344
345
346/**
347 * Run a program and log its output to the screen.
348 * @param basic_call The program to run.
349 * @param what_i_am_doing The title of the evalcall form.
350 * @return The return value of the command (varies, but 0 almost always means success).
351 * @see run_program_and_log_output
352 * @see log_to_screen
353 */
354int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing)
355{
356 /*@ int ******************************************************** */
357 int retval = 0;
358 int res = 0;
359 int i;
360
361 /*@ pointers **************************************************** */
362 FILE *fin;
363
364 /*@ buffers **************************************************** */
365 char *command = NULL;
366 char *lockfile = NULL;
367
368 /*@ end vars *************************************************** */
369
370 assert_string_is_neither_NULL_nor_zerolength(basic_call);
371
372 mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
373
374 mr_asprintf(command, "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
375 open_evalcall_form(what_i_am_doing);
376 log_msg(2, "Executing %s", basic_call);
377
378 if (!(fin = popen(command, "r"))) {
379 log_OS_error("Unable to popen-in command");
380 log_to_screen("Failed utterly to call '%s'", command);
381 mr_free(command);
382 mr_free(lockfile);
383 return (1);
384 }
385
386 if (!does_file_exist(lockfile)) {
387 log_to_screen("Waiting for '%s' to start",command);
388 for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
389 log_msg(3, "Waiting for lockfile %s to exist", lockfile);
390 }
391 }
392 mr_free(command);
393
394 for (; does_file_exist(lockfile); sleep(1)) {
395 log_file_end_to_screen(MONDO_LOGFILE, "");
396 update_evalcall_form(1);
397 }
398
399 /* Evaluate the status returned by pclose to get the exit code of the called program. */
400 errno = 0;
401 res = pclose(fin);
402 /* Log actual pclose errors. */
403 if (errno) log_msg(5, "pclose err: %d", errno);
404 /* Check if we have a valid status. If we do, extract the called program's exit code. */
405 /* If we don't, highlight this fact by returning -1. */
406 if (WIFEXITED(res)) {
407 retval = WEXITSTATUS(res);
408 } else {
409 retval = -1;
410 }
411 close_evalcall_form();
412 unlink(lockfile);
413 mr_free(lockfile);
414
415 return (retval);
416}
417
418
419
420
421/**
422 * Apparently unused. @bug This has a purpose, but what?
423 */
424#define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8"
425#define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka"
426
427
428
429
430int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
431{
432// if dir=='w' then copy from orig to archived
433// if dir=='r' then copy from archived to orig
434 char *tmp = NULL;
435 char *tmp1 = NULL;
436 char *buf = NULL;
437 char *filestr = NULL;
438 long int bytes_to_be_read, bytes_read_in, bytes_written_out =
439 0, bufcap, subsliceno = 0;
440 int retval = 0;
441 FILE *fin;
442 FILE *fout;
443 FILE *ftmp;
444 int tmpcap = 512;
445
446 log_msg(5, "Opening.");
447
448 bufcap = 256L * 1024L;
449 if (!(buf = malloc(bufcap))) {
450 fatal_error("Failed to malloc() buf");
451 }
452
453 if (direction == 'w') {
454 fin = f_orig;
455 fout = f_archived;
456 mr_asprintf(tmp, "%-64s", PIMP_START_SZ);
457 if (fwrite(tmp, 1, 64, fout) != 64) {
458 mr_free(tmp);
459 fatal_error("Can't write the introductory block");
460 }
461 mr_free(tmp);
462
463 while (1) {
464 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
465 if (bytes_read_in == 0) {
466 break;
467 }
468 mr_asprintf(tmp, "%-64ld", bytes_read_in);
469 if (fwrite(tmp, 1, 64, fout) != 64) {
470 mr_free(tmp);
471 fatal_error("Cannot write introductory block");
472 }
473 mr_free(tmp);
474
475 log_msg(7,
476 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
477 subsliceno, bytes_read_in, bytes_to_be_read);
478 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
479 mr_asprintf(tmp, "%-64ld", subsliceno);
480 if (fwrite(tmp, 1, 64, fout) != 64) {
481 mr_free(tmp);
482 fatal_error("Cannot write post-thingy block");
483 }
484 mr_free(tmp);
485 log_msg(7, "Subslice #%d written OK", subsliceno);
486 subsliceno++;
487 }
488 mr_asprintf(tmp, "%-64ld", 0L);
489 if (fwrite(tmp, 1, 64L, fout) != 64L) {
490 mr_free(tmp);
491 fatal_error("Cannot write final introductory block");
492 }
493 mr_free(tmp);
494
495 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
496 if (fwrite(tmp, 1, 64, fout) != 64) {
497 mr_free(tmp);
498 fatal_error("Can't write the final block");
499 }
500 mr_free(tmp);
501 } else {
502 fin = f_archived;
503 fout = f_orig;
504 if (!(tmp1 = malloc(tmpcap))) {
505 fatal_error("Failed to malloc() tmp");
506 }
507 if (fread(tmp1, 1, 64L, fin) != 64L) {
508 mr_free(tmp1);
509 fatal_error("Cannot read the introductory block");
510 }
511 log_msg(5, "tmp1 is %s", tmp1);
512 if (!strstr(tmp1, PIMP_START_SZ)) {
513 mr_free(tmp1);
514 fatal_error("Can't find intro blk");
515 }
516 if (fread(tmp1, 1, 64L, fin) != 64L) {
517 mr_free(tmp1);
518 fatal_error("Cannot read introductory blk");
519 }
520 bytes_to_be_read = atol(tmp1);
521 while (bytes_to_be_read > 0) {
522 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read);
523 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
524 if (bytes_read_in != bytes_to_be_read) {
525 mr_free(tmp1);
526 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives.");
527 }
528 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
529 if (fread(tmp1, 1, 64, fin) != 64) {
530 mr_free(tmp1);
531 fatal_error("Cannot read post-thingy block");
532 }
533 if (atol(tmp1) != subsliceno) {
534 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1);
535 }
536 log_msg(7, "Subslice #%ld read OK", subsliceno);
537 subsliceno++;
538 if (fread(tmp1, 1, 64, fin) != 64) {
539 mr_free(tmp1);
540 fatal_error("Cannot read introductory block");
541 }
542 bytes_to_be_read = atol(tmp1);
543 }
544 }
545
546 if (direction == 'w') {
547 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
548 if (fwrite(tmp, 1, 64, fout) != 64) {
549 mr_free(tmp);
550 fatal_error("Can't write the final block");
551 }
552 mr_free(tmp);
553 } else {
554 log_msg(1, "tmpA is %s", tmp1);
555 if (!strstr(tmp1, PIMP_END_SZ)) {
556 if (fread(tmp1, 1, 64, fin) != 64) {
557 mr_free(tmp1);
558 fatal_error("Can't read the final block");
559 }
560 log_msg(5, "tmpB is %s", tmp1);
561 if (!strstr(tmp1, PIMP_END_SZ)) {
562 mr_asprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);
563 ftmp = fopen(filestr, "w");
564 mr_free(filestr);
565
566 bytes_read_in = fread(tmp1, 1, 64, fin);
567 log_msg(1, "bytes_read_in = %ld", bytes_read_in);
568
569 if (fwrite(tmp, 1, bytes_read_in, ftmp)) {
570 fatal_error("Can't fwrite here");
571 }
572
573 mr_asprintf(tmp, "I am here - %lld", (long long)ftello(fin));
574 if (fread(tmp, 1, tmpcap, fin)) {
575 mr_free(tmp);
576 fatal_error("Can't fread here");
577 }
578 log_msg(0, "tmp = '%s'", tmp);
579 if (fwrite(tmp, 1, tmpcap, ftmp)) {
580 mr_free(tmp);
581 fatal_error("Can't fwrite there");
582 }
583 fclose(ftmp);
584 mr_free(tmp);
585 fatal_error("Missing terminating block");
586 }
587 }
588 }
589 mr_free(tmp1);
590
591 paranoid_free(buf);
592 log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
593 return (retval);
594}
595
596
597
598
599/**
600 * Feed @p input_device through ntfsclone to @p output_fname.
601 * @param input_device The device to image.
602 * @param output_fname The file to write.
603 * @return 0 for success, nonzero for failure.
604 */
605int feed_into_ntfsprog(char *input_device, char *output_fname)
606{
607// BACKUP
608 int res = -1;
609 char *command = NULL;
610
611 if (!does_file_exist(input_device)) {
612 fatal_error("input device does not exist");
613 }
614 if ( !find_home_of_exe("ntfsclone")) {
615 fatal_error("ntfsclone not found");
616 }
617 mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
618 res = run_program_and_log_output(command, 5);
619 mr_free(command);
620
621 unlink(output_fname);
622 return (res);
623}
624
625
626void *run_prog_in_bkgd_then_exit(void *info)
627{
628 char *sz_command;
629 static int res = 4444;
630
631 res = 999;
632 sz_command = (char *) info;
633 log_msg(4, "sz_command = '%s'", sz_command);
634 res = system(sz_command);
635 if (res > 256 && res != 4444) {
636 res = res / 256;
637 }
638 log_msg(4, "child res = %d", res);
639 sz_command[0] = '\0';
640 pthread_exit((void *) (&res));
641}
642
643
644
645
646int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) {
647
648 /*@ int *************************************************************** */
649 int res = 0;
650 int percentage = 0;
651 int maxpc = 100;
652 int pcno = 0;
653 int counter = 0;
654
655 /*@ buffers *********************************************************** */
656 char *command = NULL;
657 /*@ pointers ********************************************************** */
658 static int chldres = 0;
659 int *pchild_result;
660 pthread_t childthread;
661
662 pchild_result = &chldres;
663 assert_string_is_neither_NULL_nor_zerolength(cmd);
664 assert_string_is_neither_NULL_nor_zerolength(tt);
665 *pchild_result = 999;
666
667 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
668 log_msg(3, "command = '%s'", command);
669 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) {
670 fatal_error("Unable to create an archival thread");
671 }
672
673 log_msg(8, "Parent running");
674 open_evalcall_form(tt);
675
676 for (sleep(1); command[0] != '\0'; sleep(1)) {
677 if (strstr(cmd,"mindi") != NULL) {
678 pcno = grab_percentage_from_last_line_of_file(MINDI_RUNFILE);
679 } else {
680 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
681 }
682 if (pcno < 0 || pcno > 100) {
683 log_msg(8, "Weird pc# %d", pcno);
684 continue;
685 }
686 percentage = pcno * 100 / maxpc;
687 if (counter++ >= 5) {
688 counter = 0;
689 log_file_end_to_screen(MONDO_LOGFILE, "");
690 }
691 update_evalcall_form(percentage);
692 }
693 mr_free(command);
694
695 log_file_end_to_screen(MONDO_LOGFILE, "");
696 close_evalcall_form();
697 pthread_join(childthread, (void *) (&pchild_result));
698 if (pchild_result) {
699 res = *pchild_result;
700 } else {
701 res = 666;
702 }
703 log_msg(3, "Parent res = %d", res);
704 return (res);
705}
706
707
708/**
709 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
710 * @param input_fifo The ntfsclone file to read.
711 * @param output_device Where to put the output.
712 * @return The return value of ntfsclone (0 for success).
713 */
714int feed_outfrom_ntfsprog(char *output_device, char *input_fifo)
715{
716// RESTORE
717 int res = -1;
718 char *command = NULL;
719
720 if ( !find_home_of_exe("ntfsclone")) {
721 fatal_error("ntfsclone not found");
722 }
723 mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
724 res = run_program_and_log_output(command, 5);
725 mr_free(command);
726 return (res);
727}
Note: See TracBrowser for help on using the repository browser.