source: MondoRescue/branches/3.1/mondo/src/common/libmondo-fork.c@ 3161

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