source: MondoRescue/branches/3.3/mondo/src/common/libmondo-fork.c@ 3856

Last change on this file since 3856 was 3855, checked in by Bruno Cornec, 4 months ago

Fix save_disklist_to_file and resolve_naff_tokens protos

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