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

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