source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-fork.c@ 2816

Last change on this file since 2816 was 2704, checked in by Bruno Cornec, 13 years ago

r4180@localhost: bruno | 2011-01-27 10:26:41 +0100

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