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

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