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

Last change on this file since 3147 was 3147, checked in by Bruno Cornec, 11 years ago
  • First pass on svn merge -r 2935:3146 ../3.0
  • Property svn:keywords set to Id
File size: 19.1 KB
Line 
1/* libmondo-fork.c
2 $Id: libmondo-fork.c 3147 2013-06-19 06:34:46Z 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 3147 2013-06-19 06:34:46Z 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 char *p;
45
46 /*@ pointers **************************************************** */
47 FILE *fin = NULL;
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 system(newcall);
62 mr_free(newcall);
63
64 if ((fin = fopen(tmpf, "r"))) {
65 while (!feof(fin)) {
66 mr_getline(tmp, fin);
67 mr_chomp(tmp);
68 /* In case of extreme debug ;-)
69 log_msg(9, "Loop result: ***%s***", tmp);
70 */
71 /* There is empty content at the end of the file that needs to be skiped */
72 if (strlen(tmp) > 0) {
73 mr_free(result);
74 mr_asprintf(result, "%s", tmp);
75 }
76 mr_free(tmp);
77 }
78 if (logit) {
79 log_msg(9, "Pre-Result: %s", result);
80 }
81 mr_strip_spaces(result);
82 paranoid_pclose(fin);
83 } else {
84 log_OS_error("Unable to open resulting file");
85 }
86 mr_free(tmpf);
87 if (logit) {
88 log_msg(4, "Result: %s", result);
89 }
90 return(result);
91}
92
93#define MONDO_POPMSG "Your PC will not retract the CD tray automatically. Please call mondoarchive with the -m (manual CD tray) flag."
94
95/**
96 * Call mkisofs to create an ISO image.
97 * @param bkpinfo The backup information structure. Fields used:
98 * - @c bkpinfo->manual_cd_tray
99 * - @c bkpinfo->backup_media_type
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 char *q;
262
263 /*@ end vars *************************************************** */
264
265 assert(program != NULL);
266 if (!program[0]) {
267 log_msg(2, "Warning - asked to run zerolength program");
268 return (1);
269 }
270
271 if (debug_level <= g_loglevel) {
272 log_if_success = TRUE;
273 log_if_failure = TRUE;
274 }
275 mr_asprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err", program, bkpinfo->tmpdir, bkpinfo->tmpdir);
276 while ((p = strchr(callstr, '\r'))) {
277 *p = ' ';
278 }
279 while ((p = strchr(callstr, '\n'))) {
280 *p = ' ';
281 } /* single '=' is intentional */
282
283
284 res = system(callstr);
285 if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
286 log_msg(0, "running: %s", callstr);
287 log_msg(0, "--------------------------------start of output-----------------------------");
288 }
289 mr_free(callstr);
290
291 mr_asprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
292 if (log_if_failure && system(callstr)) {
293 log_OS_error("Command failed");
294 }
295 mr_free(callstr);
296
297 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
298 unlink(tmp1);
299 mr_free(tmp1);
300
301 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
302 fin = fopen(tmp1, "r");
303 if (fin) {
304 for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); q = fgets(incoming, MAX_STR_LEN, fin)) {
305 p = incoming;
306 while (p && *p) {
307 if ((p = strchr(p, '%'))) {
308 memmove(p, p + 1, strlen(p) + 1);
309 p += 2;
310 }
311 }
312 strip_spaces(incoming);
313 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
314 log_msg(0, incoming);
315 }
316 }
317 paranoid_fclose(fin);
318 }
319 unlink(tmp1);
320 mr_free(tmp1);
321
322 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
323 log_msg(0,
324 "--------------------------------end of output------------------------------");
325 if (res) {
326 log_msg(0, "...ran with res=%d", res);
327 } else {
328 log_msg(0, "...ran just fine. :-)");
329 }
330 }
331 return (res);
332}
333
334
335
336/**
337 * Run a program and log its output to the screen.
338 * @param basic_call The program to run.
339 * @param what_i_am_doing The title of the evalcall form.
340 * @return The return value of the command (varies, but 0 almost always means success).
341 * @see run_program_and_log_output
342 * @see log_to_screen
343 */
344int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing)
345{
346 /*@ int ******************************************************** */
347 int retval = 0;
348 int res = 0;
349 int i;
350
351 /*@ pointers **************************************************** */
352 FILE *fin;
353
354 /*@ buffers **************************************************** */
355 char *command = NULL;
356 char *lockfile = NULL;
357
358 /*@ end vars *************************************************** */
359
360 assert_string_is_neither_NULL_nor_zerolength(basic_call);
361
362 mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
363
364 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);
365 open_evalcall_form(what_i_am_doing);
366 log_msg(2, "Executing %s", basic_call);
367
368 if (!(fin = popen(command, "r"))) {
369 log_OS_error("Unable to popen-in command");
370 log_to_screen("Failed utterly to call '%s'", command);
371 mr_free(command);
372 mr_free(lockfile);
373 return (1);
374 }
375 mr_free(command);
376
377 if (!does_file_exist(lockfile)) {
378 log_to_screen("Waiting for '%s' to start",command);
379 for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
380 log_msg(3, "Waiting for lockfile %s to exist", lockfile);
381 }
382 }
383
384 for (; does_file_exist(lockfile); sleep(1)) {
385 log_file_end_to_screen(MONDO_LOGFILE, "");
386 update_evalcall_form(1);
387 }
388
389 /* Evaluate the status returned by pclose to get the exit code of the called program. */
390 errno = 0;
391 res = pclose(fin);
392 /* Log actual pclose errors. */
393 if (errno) log_msg(5, "pclose err: %d", errno);
394 /* Check if we have a valid status. If we do, extract the called program's exit code. */
395 /* If we don't, highlight this fact by returning -1. */
396 if (WIFEXITED(res)) {
397 retval = WEXITSTATUS(res);
398 } else {
399 retval = -1;
400 }
401 close_evalcall_form();
402 unlink(lockfile);
403 mr_free(lockfile);
404
405 return (retval);
406}
407
408
409
410
411/**
412 * Apparently unused. @bug This has a purpose, but what?
413 */
414#define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8"
415#define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka"
416
417
418
419
420int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
421{
422// if dir=='w' then copy from orig to archived
423// if dir=='r' then copy from archived to orig
424 char *tmp = NULL;
425 char *tmp1 = NULL;
426 char *buf = NULL;
427 char *filestr = NULL;
428 long int bytes_to_be_read, bytes_read_in, bytes_written_out =
429 0, bufcap, subsliceno = 0;
430 int retval = 0;
431 FILE *fin;
432 FILE *fout;
433 FILE *ftmp;
434 int tmpcap = 512;
435
436 log_msg(5, "Opening.");
437
438 bufcap = 256L * 1024L;
439 if (!(buf = malloc(bufcap))) {
440 fatal_error("Failed to malloc() buf");
441 }
442
443 if (direction == 'w') {
444 fin = f_orig;
445 fout = f_archived;
446 mr_asprintf(tmp, "%-64s", PIMP_START_SZ);
447 if (fwrite(tmp, 1, 64, fout) != 64) {
448 mr_free(tmp);
449 fatal_error("Can't write the introductory block");
450 }
451 mr_free(tmp);
452
453 while (1) {
454 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
455 if (bytes_read_in == 0) {
456 break;
457 }
458 mr_asprintf(tmp, "%-64ld", bytes_read_in);
459 if (fwrite(tmp, 1, 64, fout) != 64) {
460 mr_free(tmp);
461 fatal_error("Cannot write introductory block");
462 }
463 mr_free(tmp);
464
465 log_msg(7,
466 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
467 subsliceno, bytes_read_in, bytes_to_be_read);
468 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
469 mr_asprintf(tmp, "%-64ld", subsliceno);
470 if (fwrite(tmp, 1, 64, fout) != 64) {
471 mr_free(tmp);
472 fatal_error("Cannot write post-thingy block");
473 }
474 mr_free(tmp);
475 log_msg(7, "Subslice #%d written OK", subsliceno);
476 subsliceno++;
477 }
478 mr_asprintf(tmp, "%-64ld", 0L);
479 if (fwrite(tmp, 1, 64L, fout) != 64L) {
480 mr_free(tmp);
481 fatal_error("Cannot write final introductory block");
482 }
483 mr_free(tmp);
484
485 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
486 if (fwrite(tmp, 1, 64, fout) != 64) {
487 mr_free(tmp);
488 fatal_error("Can't write the final block");
489 }
490 mr_free(tmp);
491 } else {
492 fin = f_archived;
493 fout = f_orig;
494 if (!(tmp1 = malloc(tmpcap))) {
495 fatal_error("Failed to malloc() tmp");
496 }
497 if (fread(tmp1, 1, 64L, fin) != 64L) {
498 mr_free(tmp1);
499 fatal_error("Cannot read the introductory block");
500 }
501 log_msg(5, "tmp1 is %s", tmp1);
502 if (!strstr(tmp1, PIMP_START_SZ)) {
503 mr_free(tmp1);
504 fatal_error("Can't find intro blk");
505 }
506 if (fread(tmp1, 1, 64L, fin) != 64L) {
507 mr_free(tmp1);
508 fatal_error("Cannot read introductory blk");
509 }
510 bytes_to_be_read = atol(tmp1);
511 while (bytes_to_be_read > 0) {
512 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read);
513 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
514 if (bytes_read_in != bytes_to_be_read) {
515 mr_free(tmp1);
516 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives.");
517 }
518 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
519 if (fread(tmp1, 1, 64, fin) != 64) {
520 mr_free(tmp1);
521 fatal_error("Cannot read post-thingy block");
522 }
523 if (atol(tmp1) != subsliceno) {
524 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1);
525 }
526 log_msg(7, "Subslice #%ld read OK", subsliceno);
527 subsliceno++;
528 if (fread(tmp1, 1, 64, fin) != 64) {
529 mr_free(tmp1);
530 fatal_error("Cannot read introductory block");
531 }
532 bytes_to_be_read = atol(tmp1);
533 }
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 sprintf(tmp, "I am here - %lld", (long long)ftello(fin));
554 if (fread(tmp, 1, tmpcap, fin)) {
555 fatal_error("Can't fread here");
556 }
557 log_msg(0, "tmp = '%s'", tmp);
558 if (fwrite(tmp, 1, tmpcap, ftmp)) {
559 fatal_error("Can't fwrite there");
560 }
561 fclose(ftmp);
562 mr_free(tmp1);
563 fatal_error("Missing terminating block");
564 }
565 }
566 mr_free(tmp1);
567 }
568
569 paranoid_free(buf);
570 log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
571 return (retval);
572}
573
574
575
576
577/**
578 * Feed @p input_device through ntfsclone to @p output_fname.
579 * @param input_device The device to image.
580 * @param output_fname The file to write.
581 * @return 0 for success, nonzero for failure.
582 */
583int feed_into_ntfsprog(char *input_device, char *output_fname)
584{
585// BACKUP
586 int res = -1;
587 char *command = NULL;
588
589 if (!does_file_exist(input_device)) {
590 fatal_error("input device does not exist");
591 }
592 command = find_home_of_exe("ntfsclone");
593 if (!command) {
594 mr_free(command);
595 fatal_error("ntfsclone not found");
596 }
597 mr_free(command);
598
599 mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
600 res = run_program_and_log_output(command, 5);
601 mr_free(command);
602
603 unlink(output_fname);
604 return (res);
605}
606
607
608void *run_prog_in_bkgd_then_exit(void *info)
609{
610 char *sz_command;
611 static int res = 4444;
612
613 res = 999;
614 sz_command = (char *) info;
615 log_msg(4, "sz_command = '%s'", sz_command);
616 res = system(sz_command);
617 if (res > 256 && res != 4444) {
618 res = res / 256;
619 }
620 log_msg(4, "child res = %d", res);
621 sz_command[0] = '\0';
622 pthread_exit((void *) (&res));
623}
624
625
626
627
628int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) {
629
630 /*@ int *************************************************************** */
631 int res = 0;
632 int percentage = 0;
633 int maxpc = 100;
634 int pcno = 0;
635 int last_pcno = 0;
636 int counter = 0;
637
638 /*@ buffers *********************************************************** */
639 char *command = NULL;
640 char *title = 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 mr_asprintf(title, "%s", tt);
659 open_evalcall_form(title);
660 mr_free(title);
661
662 for (sleep(1); command[0] != '\0'; sleep(1)) {
663 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
664 if (pcno < 0 || pcno > 100) {
665 log_msg(8, "Weird pc# %d", pcno);
666 continue;
667 }
668 percentage = pcno * 100 / maxpc;
669 if (pcno <= 5 && last_pcno >= 40) {
670 close_evalcall_form();
671 mr_asprintf(title, "Verifying...");
672 open_evalcall_form(title);
673 mr_free(title);
674 }
675 if (counter++ >= 5) {
676 counter = 0;
677 log_file_end_to_screen(MONDO_LOGFILE, "");
678 }
679 last_pcno = pcno;
680 update_evalcall_form(percentage);
681 }
682 mr_free(command);
683
684 log_file_end_to_screen(MONDO_LOGFILE, "");
685 close_evalcall_form();
686 pthread_join(childthread, (void *) (&pchild_result));
687 if (pchild_result) {
688 res = *pchild_result;
689 } else {
690 res = 666;
691 }
692 log_msg(3, "Parent res = %d", res);
693 return (res);
694}
695
696
697/**
698 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
699 * @param input_fifo The ntfsclone file to read.
700 * @param output_device Where to put the output.
701 * @return The return value of ntfsclone (0 for success).
702 */
703int feed_outfrom_ntfsprog(char *output_device, char *input_fifo)
704{
705// RESTORE
706 int res = -1;
707 char *command = NULL;
708
709 command = find_home_of_exe("ntfsclone");
710 if (!command) {
711 mr_free(command);
712 fatal_error("ntfsclone not found");
713 }
714 mr_free(command);
715
716 mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
717 res = run_program_and_log_output(command, 5);
718 mr_free(command);
719 return (res);
720}
Note: See TracBrowser for help on using the repository browser.