source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-fork.c@ 2303

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