source: MondoRescue/branches/2.2.9/mondo/src/common/libmondo-fork.c@ 2178

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