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

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

Add a MONDO_LOGFILENAME variable to allow the basename to be used when compressing the log on the target media

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