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

Last change on this file since 2546 was 2546, checked in by bruno, 9 years ago

svn merge -r 2523:2545 /mondorescue/branches/2.2.9

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