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

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

Memory management improvements again for libmondo-fork.c & libmondo-files.c

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