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

Last change on this file since 3871 was 3871, checked in by Bruno Cornec, 2 months ago

Fix syntax issues

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