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

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

Improvements for USB support in mindi when called from mondo
Changelogs in C files removed from common

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