source: MondoRescue/branches/3.2/mondo/src/common/libmondo-fork.c@ 3604

Last change on this file since 3604 was 3604, checked in by Bruno Cornec, 8 years ago

Fix #806 by setuping env var for english before callingcommands and avoid local msgs badly interpreted later on (F. Sommer)

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