source: MondoRescue/branches/stable/mondo/src/common/libmondo-fork.c@ 1168

Last change on this file since 1168 was 1168, checked in by Bruno Cornec, 17 years ago

strip_spaces => mr_strip_spaces in mr_str.c and corrected at the same time :-)

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