source: MondoRescue/branches/3.0/mondo/src/common/libmondo-fork.c@ 2972

Last change on this file since 2972 was 2931, checked in by Bruno Cornec, 12 years ago
  • Really never inject or eject when the -e option is passed or device is inappropriate (USB, Net, ...)
  • Property svn:keywords set to Id
File size: 19.9 KB
Line 
1/* libmondo-fork.c
2 $Id: libmondo-fork.c 2931 2012-01-24 11:48:04Z 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 2931 2012-01-24 11:48:04Z 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 * @param basic_call The call to mkisofs. May contain tokens that will be resolved to actual data. The tokens are:
82 * - @c _ISO_ will become the ISO file (@p isofile)
83 * - @c _CD#_ becomes the CD number (@p cd_no)
84 * - @c _ERR_ becomes the logfile (@p g_logfile)
85 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs).
86 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number.
87 * @param logstub Unused.
88 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog.
89 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure).
90 * @bug @p logstub is unused.
91 */
92int
93eval_call_to_make_ISO(char *basic_call, char *isofile,
94 int cd_no, char *logstub, char *what_i_am_doing)
95{
96
97 /*@ int's *** */
98 int retval = 0;
99
100
101 /*@ buffers *** */
102 char *midway_call, *ultimate_call, *tmp, *command, *incoming,
103 *old_stderr, *cd_number_str;
104 char *p;
105 char *tmp1 = NULL;
106
107/*@*********** End Variables ***************************************/
108
109 log_msg(3, "Starting");
110 assert(bkpinfo != NULL);
111 // BERLIOS: doesn't work even if the string is correct !
112 //assert_string_is_neither_NULL_nor_zerolength(basic_call);
113 assert_string_is_neither_NULL_nor_zerolength(isofile);
114 assert_string_is_neither_NULL_nor_zerolength(logstub);
115 if (!(midway_call = malloc(1200))) {
116 fatal_error("Cannot malloc midway_call");
117 }
118 if (!(ultimate_call = malloc(1200))) {
119 fatal_error("Cannot malloc ultimate_call");
120 }
121 if (!(tmp = malloc(1200))) {
122 fatal_error("Cannot malloc tmp");
123 }
124 if (!(command = malloc(1200))) {
125 fatal_error("Cannot malloc command");
126 }
127 malloc_string(incoming);
128 malloc_string(old_stderr);
129 malloc_string(cd_number_str);
130
131 incoming[0] = '\0';
132 old_stderr[0] = '\0';
133
134 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
135 mr_asprintf(&tmp1, "su - %s -c \"%s\"", bkpinfo->netfs_user, basic_call);
136 } else {
137 mr_asprintf(&tmp1, "%s", basic_call);
138 }
139
140 sprintf(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 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
144 log_msg(4, "basic call = '%s'", tmp1);
145 log_msg(4, "midway_call = '%s'", midway_call);
146 log_msg(4, "tmp = '%s'", tmp);
147 log_msg(4, "ultimate call = '%s'", ultimate_call);
148 sprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
149
150 log_to_screen
151 ("Please be patient. Do not be alarmed by on-screen inactivity.");
152 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
153 what_i_am_doing);
154 strcpy(tmp, command);
155 if (bkpinfo->manual_cd_tray) {
156 p = strstr(tmp, "2>>");
157 if (p) {
158 sprintf(p, " ");
159 while (*p == ' ') {
160 p++;
161 }
162 for (; *p != ' '; p++) {
163 *p = ' ';
164 }
165 }
166 strcpy(command, tmp);
167#ifndef _XWIN
168 if (!g_text_mode) {
169 newtSuspend();
170 }
171#endif
172 log_msg(1, "command = '%s'", command);
173 retval += system(command);
174 if (!g_text_mode) {
175 newtResume();
176 }
177 if (retval) {
178 log_msg(2, "Basic call '%s' returned an error.", tmp1);
179 popup_and_OK("Press ENTER to continue.");
180 popup_and_OK
181 ("mkisofs and/or cdrecord returned an error. CD was not created");
182 }
183 }
184 /* if text mode then do the above & RETURN; if not text mode, do this... */
185 else {
186 log_msg(3, "command = '%s'", command);
187// yes_this_is_a_goto:
188 retval =
189 run_external_binary_with_percentage_indicator_NEW
190 (what_i_am_doing, command);
191 }
192
193 mr_free(tmp1);
194 paranoid_free(midway_call);
195 paranoid_free(ultimate_call);
196 paranoid_free(tmp);
197 paranoid_free(command);
198 paranoid_free(incoming);
199 paranoid_free(old_stderr);
200 paranoid_free(cd_number_str);
201 return (retval);
202}
203
204
205/**
206 * Call copy of data to create an USB image.
207 * @param bkpinfo The backup information structure. Fields used:
208 * - @c bkpinfo->backup_media_type
209 * @return Exit code of @c copy (0 is success, anything else indicates failure).
210 */
211int
212eval_call_to_make_USB(char *command, char *what_i_am_doing) {
213
214 /*@ int's *** */
215 int retval = 0;
216
217
218/*@*********** End Variables ***************************************/
219
220 log_msg(3, "Starting");
221 assert(bkpinfo != NULL);
222
223 log_to_screen
224 ("Please be patient. Do not be alarmed by on-screen inactivity.");
225 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
226 what_i_am_doing);
227
228 if (!g_text_mode) {
229 newtSuspend();
230 }
231 log_msg(1, "command = '%s'", command);
232 if (!g_text_mode) {
233 retval = run_external_binary_with_percentage_indicator_NEW
234 (what_i_am_doing, command);
235 } else {
236 retval += system(command);
237 }
238 if (!g_text_mode) {
239 newtResume();
240 }
241
242 return (retval);
243}
244
245
246
247
248/**
249 * Run a program and log its output (stdout and stderr) to the logfile.
250 * @param program The program to run. Passed to the shell, so you can use pipes etc.
251 * @param debug_level If @p g_loglevel is higher than this, do not log the output.
252 * @return The exit code of @p program (depends on the command, but 0 almost always indicates success).
253 */
254int run_program_and_log_output(char *program, int debug_level)
255{
256 /*@ buffer ****************************************************** */
257 char callstr[MAX_STR_LEN * 2];
258 char incoming[MAX_STR_LEN * 2];
259 char tmp[MAX_STR_LEN * 2];
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// if (debug_level == TRUE) { debug_level=5; }
281
282 // assert_string_is_neither_NULL_nor_zerolength(program);
283
284 if (debug_level <= g_loglevel) {
285 log_if_success = TRUE;
286 log_if_failure = TRUE;
287 }
288 sprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err",
289 program, bkpinfo->tmpdir, bkpinfo->tmpdir);
290 while ((p = strchr(callstr, '\r'))) {
291 *p = ' ';
292 }
293 while ((p = strchr(callstr, '\n'))) {
294 *p = ' ';
295 } /* single '=' is intentional */
296
297
298 len = (int) strlen(program);
299 for (i = 0; i < 35 - len / 2; i++) {
300 tmp[i] = '-';
301 }
302 tmp[i] = '\0';
303 strcat(tmp, " ");
304 strcat(tmp, program);
305 strcat(tmp, " ");
306 for (i = 0; i < 35 - len / 2; i++) {
307 strcat(tmp, "-");
308 }
309 strcpy(initial_label, tmp);
310 res = system(callstr);
311 if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
312 log_msg(0, "running: %s", callstr);
313 log_msg(0,
314 "--------------------------------start of output-----------------------------");
315 }
316 sprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
317 if (log_if_failure && system(callstr)) {
318 log_OS_error("Command failed");
319 }
320 sprintf(tmp, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
321 unlink(tmp);
322 sprintf(tmp, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
323 fin = fopen(tmp, "r");
324 if (fin) {
325 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
326 fgets(incoming, MAX_STR_LEN, fin)) {
327 /* patch by Heiko Schlittermann */
328 p = incoming;
329 while (p && *p) {
330 if ((p = strchr(p, '%'))) {
331 memmove(p, p + 1, strlen(p) + 1);
332 p += 2;
333 }
334 }
335 /* end of patch */
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(tmp);
345 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
346 log_msg(0,
347 "--------------------------------end of output------------------------------");
348 if (res) {
349 log_msg(0, "...ran with res=%d", res);
350 } else {
351 log_msg(0, "...ran just fine. :-)");
352 }
353 }
354// else
355// { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); }
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[MAX_STR_LEN];
383
384 /*@ end vars *************************************************** */
385
386 assert_string_is_neither_NULL_nor_zerolength(basic_call);
387
388 sprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
389
390 mr_asprintf(&command,
391 "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
392 lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
393 open_evalcall_form(what_i_am_doing);
394 mr_asprintf(&tmp, "Executing %s", basic_call);
395 log_msg(2, tmp);
396 mr_free(tmp);
397
398 if (!(fin = popen(command, "r"))) {
399 log_OS_error("Unable to popen-in command");
400 mr_asprintf(&tmp, "Failed utterly to call '%s'", command);
401 log_to_screen(tmp);
402 mr_free(tmp);
403 mr_free(command);
404 return (1);
405 }
406 if (!does_file_exist(lockfile)) {
407 log_to_screen("Waiting for '%s' to start",command);
408 for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
409 log_msg(3, "Waiting for lockfile %s to exist", lockfile);
410 }
411 }
412 mr_free(command);
413#ifdef _XWIN
414 /* This only can update when newline goes into the file,
415 but it's *much* prettier/faster on Qt. */
416 while (does_file_exist(lockfile)) {
417 while (!feof(fin)) {
418 /* TODO: Dead and wrong code */
419 if (!fgets(tmp, 512, fin))
420 break;
421 log_to_screen(tmp);
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 return (retval);
447}
448
449
450
451
452/**
453 * Apparently unused. @bug This has a purpose, but what?
454 */
455#define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8"
456#define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka"
457
458
459
460
461int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
462{
463// if dir=='w' then copy from orig to archived
464// if dir=='r' then copy from archived to orig
465 char *tmp;
466 char *buf;
467 char filestr[MAX_STR_LEN];
468 long int bytes_to_be_read, bytes_read_in, bytes_written_out =
469 0, bufcap, subsliceno = 0;
470 int retval = 0;
471 FILE *fin;
472 FILE *fout;
473 FILE *ftmp;
474 int tmpcap = 512;
475
476 log_msg(5, "Opening.");
477 if (!(tmp = malloc(tmpcap))) {
478 fatal_error("Failed to malloc() tmp");
479 }
480 tmp[0] = '\0';
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 sprintf(tmp, "%-64s", PIMP_START_SZ);
490 if (fwrite(tmp, 1, 64, fout) != 64) {
491 fatal_error("Can't write the introductory block");
492 }
493 while (1) {
494 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
495 if (bytes_read_in == 0) {
496 break;
497 }
498 sprintf(tmp, "%-64ld", bytes_read_in);
499 if (fwrite(tmp, 1, 64, fout) != 64) {
500 fatal_error("Cannot write introductory block");
501 }
502 log_msg(7,
503 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
504 subsliceno, bytes_read_in, bytes_to_be_read);
505 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
506 sprintf(tmp, "%-64ld", subsliceno);
507 if (fwrite(tmp, 1, 64, fout) != 64) {
508 fatal_error("Cannot write post-thingy block");
509 }
510 log_msg(7, "Subslice #%d written OK", subsliceno);
511 subsliceno++;
512 }
513 sprintf(tmp, "%-64ld", 0L);
514 if (fwrite(tmp, 1, 64L, fout) != 64L) {
515 fatal_error("Cannot write final introductory block");
516 }
517 } else {
518 fin = f_archived;
519 fout = f_orig;
520 if (fread(tmp, 1, 64L, fin) != 64L) {
521 fatal_error("Cannot read the introductory block");
522 }
523 log_msg(5, "tmp is %s", tmp);
524 if (!strstr(tmp, PIMP_START_SZ)) {
525 fatal_error("Can't find intro blk");
526 }
527 if (fread(tmp, 1, 64L, fin) != 64L) {
528 fatal_error("Cannot read introductory blk");
529 }
530 bytes_to_be_read = atol(tmp);
531 while (bytes_to_be_read > 0) {
532 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno,
533 bytes_to_be_read);
534 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
535 if (bytes_read_in != bytes_to_be_read) {
536 fatal_error
537 ("Danger, WIll Robinson. Failed to read whole subvol from archives.");
538 }
539 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
540 if (fread(tmp, 1, 64, fin) != 64) {
541 fatal_error("Cannot read post-thingy block");
542 }
543 if (atol(tmp) != subsliceno) {
544 log_msg(1, "Wanted subslice %ld but got %ld ('%s')",
545 subsliceno, atol(tmp), tmp);
546 }
547 log_msg(7, "Subslice #%ld read OK", subsliceno);
548 subsliceno++;
549 if (fread(tmp, 1, 64, fin) != 64) {
550 fatal_error("Cannot read introductory block");
551 }
552 bytes_to_be_read = atol(tmp);
553 }
554 }
555
556// log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in);
557
558 if (direction == 'w') {
559 sprintf(tmp, "%-64s", PIMP_END_SZ);
560 if (fwrite(tmp, 1, 64, fout) != 64) {
561 fatal_error("Can't write the final block");
562 }
563 } else {
564 log_msg(1, "tmpA is %s", tmp);
565 if (!strstr(tmp, PIMP_END_SZ)) {
566 if (fread(tmp, 1, 64, fin) != 64) {
567 fatal_error("Can't read the final block");
568 }
569 log_msg(5, "tmpB is %s", tmp);
570 if (!strstr(tmp, PIMP_END_SZ)) {
571 sprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);
572 ftmp = fopen(filestr, "w");
573 bytes_read_in = fread(tmp, 1, 64, fin);
574 log_msg(1, "bytes_read_in = %ld", bytes_read_in);
575// if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); }
576 fwrite(tmp, 1, bytes_read_in, ftmp);
577 sprintf(tmp, "I am here - %lld", (long long)ftello(fin));
578// log_msg(0, tmp);
579 fread(tmp, 1, tmpcap, fin);
580 log_msg(0, "tmp = '%s'", tmp);
581 fwrite(tmp, 1, tmpcap, ftmp);
582 fclose(ftmp);
583 fatal_error("Missing terminating block");
584 }
585 }
586 }
587
588 paranoid_free(buf);
589 paranoid_free(tmp);
590 log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
591 return (retval);
592}
593
594
595
596
597/**
598 * Feed @p input_device through ntfsclone to @p output_fname.
599 * @param input_device The device to image.
600 * @param output_fname The file to write.
601 * @return 0 for success, nonzero for failure.
602 */
603int feed_into_ntfsprog(char *input_device, char *output_fname)
604{
605// BACKUP
606 int res = -1;
607 char*command;
608
609 if (!does_file_exist(input_device)) {
610 fatal_error("input device does not exist");
611 }
612 if ( !find_home_of_exe("ntfsclone")) {
613 fatal_error("ntfsclone not found");
614 }
615 malloc_string(command);
616 sprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
617 res = run_program_and_log_output(command, 5);
618 paranoid_free(command);
619 unlink(output_fname);
620 return (res);
621}
622
623
624void *run_prog_in_bkgd_then_exit(void *info)
625{
626 char *sz_command;
627 static int res = 4444;
628
629 res = 999;
630 sz_command = (char *) info;
631 log_msg(4, "sz_command = '%s'", sz_command);
632 res = system(sz_command);
633 if (res > 256 && res != 4444) {
634 res = res / 256;
635 }
636 log_msg(4, "child res = %d", res);
637 sz_command[0] = '\0';
638 pthread_exit((void *) (&res));
639}
640
641
642
643
644int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd)
645{
646
647 /*@ int *************************************************************** */
648 int res = 0;
649 int percentage = 0;
650 int maxpc = 100;
651 int pcno = 0;
652 int last_pcno = 0;
653 int counter = 0;
654
655 /*@ buffers *********************************************************** */
656 char *command;
657 char *title;
658 /*@ pointers ********************************************************** */
659 static int chldres = 0;
660 int *pchild_result;
661 pthread_t childthread;
662
663 pchild_result = &chldres;
664 assert_string_is_neither_NULL_nor_zerolength(cmd);
665 assert_string_is_neither_NULL_nor_zerolength(tt);
666 *pchild_result = 999;
667
668 malloc_string(title);
669 malloc_string(command);
670 strcpy(title, tt);
671 sprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
672 log_msg(3, "command = '%s'", command);
673 if ((res =
674 pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit,
675 (void *) command))) {
676 fatal_error("Unable to create an archival thread");
677 }
678
679 log_msg(8, "Parent running");
680 open_evalcall_form(title);
681 for (sleep(1); command[0] != '\0'; sleep(1)) {
682 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
683 if (pcno <= 0 || pcno > 100) {
684 log_msg(8, "Weird pc#");
685 continue;
686 }
687 percentage = pcno * 100 / maxpc;
688 if (pcno <= 5 && last_pcno >= 40) {
689 close_evalcall_form();
690 strcpy(title, "Verifying...");
691 open_evalcall_form(title);
692 }
693 if (counter++ >= 5) {
694 counter = 0;
695 log_file_end_to_screen(MONDO_LOGFILE, "");
696 }
697 last_pcno = pcno;
698 update_evalcall_form(percentage);
699 }
700 log_file_end_to_screen(MONDO_LOGFILE, "");
701 close_evalcall_form();
702 pthread_join(childthread, (void *) (&pchild_result));
703 if (pchild_result) {
704 res = *pchild_result;
705 } else {
706 res = 666;
707 }
708 log_msg(3, "Parent res = %d", res);
709 paranoid_free(command);
710 paranoid_free(title);
711 return (res);
712}
713
714
715
716
717/**
718 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
719 * @param input_fifo The ntfsclone file to read.
720 * @param output_device Where to put the output.
721 * @return The return value of ntfsclone (0 for success).
722 */
723int feed_outfrom_ntfsprog(char *output_device, char *input_fifo)
724{
725// RESTORE
726 int res = -1;
727 char *command;
728
729 if ( !find_home_of_exe("ntfsclone")) {
730 fatal_error("ntfsclone not found");
731 }
732 malloc_string(command);
733 sprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
734 res = run_program_and_log_output(command, 5);
735 paranoid_free(command);
736 return (res);
737}
Note: See TracBrowser for help on using the repository browser.