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

Last change on this file since 1693 was 1693, checked in by Bruno Cornec, 17 years ago
  • Remove useless copy from mindi to mondo at end of USB handling
  • Fix PB macro vs tools/*2build issue
  • make_usb_fs change of interface (doesn't need a parameter)
  • Fix USB support in mondo to avoid multiple copies of files
  • Use first partiion in mondo for USB device
  • Fixes for USB CLI for both mondo/mindi
  • Try to add USB support for mondoarchive with new functions
  • du => deb for similarity with other distro type under pbconf
  • migrate gento build files under pb
  • remove now obsolete rpm spec file and gentoo build files from distributions
  • Remove DOCDIR usage in mindi + various build fixes

(merge -r1680:1692 $SVN_M/branches/2.2.5)

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