source: MondoRescue/branches/stable/mondo/src/common/libmondo-archive.c@ 1954

Last change on this file since 1954 was 1939, checked in by Bruno Cornec, 16 years ago

svn merge -r 1923:1938 $SVN_M/branches/2.2.6

  • Property svn:keywords set to Id
File size: 97.4 KB
RevLine 
[1]1/* libmondo-archive.c
[99]2 $Id: libmondo-archive.c 1939 2008-05-16 23:29:54Z bruno $
[1]3
4subroutines to handle the archiving of files
5*/
6
7/**
8 * @file
9 * Functions to handle backing up data.
10 * This is the main file (at least the longest one) in libmondo.
11 */
[1107]12#include <sys/sem.h>
13#include <sys/types.h>
14#include <sys/ipc.h>
15#include <stdarg.h>
[1152]16#include <stdlib.h>
[1107]17#include <unistd.h>
[1]18
[1067]19#include "my-stuff.h"
[1193]20#include "mondostructures.h"
[1256]21
[1107]22#include "mr_mem.h"
[1123]23#include "mr_msg.h"
[1107]24#include "mr_err.h"
25#include "mr_str.h"
26#include "mr_file.h"
[1543]27#include "mr_gettext.h"
[1638]28#include "mr_conf.h"
[1107]29
[1]30#include "libmondo-string-EXT.h"
31#include "libmondo-stream-EXT.h"
32#include "libmondo-devices-EXT.h"
33#include "libmondo-tools-EXT.h"
[1118]34#include "newt-specific-EXT.h"
[1]35#include "libmondo-fork-EXT.h"
36#include "libmondo-files-EXT.h"
37#include "libmondo-filelist-EXT.h"
38#include "libmondo-tools-EXT.h"
39#include "libmondo-verify-EXT.h"
40#include "libmondo-archive.h"
[1063]41
[1]42#define DVDRWFORMAT 1
43
44#ifndef _SEMUN_H
[128]45#define _SEMUN_H
[1]46
47 /**
48 * The semaphore union, provided only in case the user's system doesn't.
49 */
[128]50union semun {
51 int val;
52 struct semid_ds *buf;
53 unsigned short int *array;
54 struct seminfo *__buf;
55};
[1594]56#endif
[1]57
[1639]58extern struct mr_ar_conf *mr_conf;
[1638]59
[1]60/*@unused@*/
[99]61//static char cvsid[] = "$Id: libmondo-archive.c 1939 2008-05-16 23:29:54Z bruno $";
[1]62
63/* *************************** external global vars ******************/
64extern int g_current_media_number;
65extern int g_currentY;
66extern bool g_text_mode;
67extern bool g_exiting;
68extern long g_current_progress;
[128]69extern FILE *g_tape_stream;
[1]70extern long long g_tape_posK;
71extern char *g_tmpfs_mountpt;
72extern bool g_cd_recovery;
73extern char *g_serial_string;
74
[948]75extern char *g_getfacl;
76extern char *g_getfattr;
[1326]77extern char *MONDO_LOGFILE;
[948]78
[1663]79/* Reference to global bkpinfo */
80extern struct s_bkpinfo *bkpinfo;
[948]81
82
[1663]83
[1]84/**
85 * @addtogroup globalGroup
86 * @{
87 */
88/**
89 * The current backup media type in use.
90 */
[128]91t_bkptype g_backup_media_type = none;
[1107]92char *g_backup_media_string = NULL;
[1]93
94/**
95 * Incremented by each archival thread when it starts up. After that,
96 * this is the number of threads running.
97 */
98int g_current_thread_no = 0;
99
100/* @} - end of globalGroup */
101
102extern int g_noof_rows;
103
104/* Semaphore-related code */
105
106static int set_semvalue(void);
107static void del_semvalue(void);
108static int semaphore_p(void);
109static int semaphore_v(void);
110
111static int g_sem_id;
112static int g_sem_key;
113
114
115
116
117/**
118 * Initialize the semaphore.
119 * @see del_semvalue
120 * @see semaphore_p
121 * @see semaphore_v
122 * @return 1 for success, 0 for failure.
123 */
[128]124static int set_semvalue(void) // initializes semaphore
[1]125{
[128]126 union semun sem_union;
127 sem_union.val = 1;
128 if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
129 return (0);
130 }
131 return (1);
[1]132}
133
134/**
135 * Frees (deletes) the semaphore. Failure is indicated by a log
136 * message.
137 * @see set_semvalue
138 */
[128]139static void del_semvalue(void) // deletes semaphore
[1]140{
[128]141 union semun sem_union;
[1]142
[128]143 if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
[1107]144 mr_msg(3, "Failed to delete semaphore");
[128]145 }
[1]146}
147
148/**
149 * Acquire (increment) the semaphore (change status to P).
150 * @return 1 for success, 0 for failure.
151 * @see semaphore_v
152 */
[128]153static int semaphore_p(void) // changes status to 'P' (waiting)
[1]154{
[128]155 struct sembuf sem_b;
[1]156
[128]157 sem_b.sem_num = 0;
158 sem_b.sem_op = -1; // P()
159 sem_b.sem_flg = SEM_UNDO;
160 if (semop(g_sem_id, &sem_b, 1) == -1) {
[1107]161 mr_msg(3, "semaphore_p failed");
[128]162 return (0);
163 }
164 return (1);
[1]165}
166
167/**
168 * Free (decrement) the semaphore (change status to V).
169 * @return 1 for success, 0 for failure.
170 */
[128]171static int semaphore_v(void) // changes status to 'V' (free)
[1]172{
[128]173 struct sembuf sem_b;
[1]174
[128]175 sem_b.sem_num = 0;
176 sem_b.sem_op = 1; // V()
177 sem_b.sem_flg = SEM_UNDO;
178 if (semop(g_sem_id, &sem_b, 1) == -1) {
[1107]179 mr_msg(3, "semaphore_v failed");
[128]180 return (0);
181 }
182 return (1);
[1]183}
184
185
186//------------------------------------------------------
187
188
189/**
190 * Size in megabytes of the buffer afforded to the executable "buffer".
191 * This figure is used when we calculate how much data we have probably 'lost'
192 * when writing off the end of tape N, so that we can then figure out how much
193 * data we must recreate & write to the start of tape N+1.
194 */
195extern int g_tape_buffer_size_MB;
196
197
198
199
200int
[1663]201archive_this_fileset_with_star(char *filelist, char *fname, int setno)
[1]202{
[128]203 int retval = 0;
204 unsigned int res = 0;
205 int tries = 0;
[1118]206 char *command = NULL;
207 char *tmp = NULL;
208 char *p =NULL;
209 char *tmp1 = NULL;
[1]210
[1118]211 malloc_string(tmp1);
[1]212
[128]213 if (!does_file_exist(filelist)) {
[1118]214 mr_asprintf(&tmp,
215 "(archive_this_fileset) - filelist %s does not exist",
216 filelist);
[128]217 log_to_screen(tmp);
[1118]218 mr_free(tmp);
[128]219 return (1);
[1]220 }
221
[1118]222 mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
[128]223 if (system(tmp)) {
224 fatal_error("Unable to write tarball to scratchdir");
225 }
[1118]226 mr_free(tmp);
[128]227
[1118]228 mr_asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
229 filelist, fname);
[1769]230
[128]231 if (bkpinfo->compression_level > 0) {
[1118]232 mr_asprintf(&tmp, "%s -bz", command);
233 mr_free(command);
234 command = tmp;
[128]235 }
[1118]236 mr_asprintf(&tmp, "%s 2>> %s", command, MONDO_LOGFILE);
237 mr_free(command);
238 command = tmp;
[1107]239 mr_msg(4, "command = '%s'", command);
[128]240
241 for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
[1107]242 mr_msg(5, "command='%s'", command);
[128]243 res = system(command);
[1118]244 strcpy(tmp1, last_line_of_file(MONDO_LOGFILE));
[1107]245 mr_msg(1, "res=%d; tmp='%s'", res, tmp);
[128]246 if (bkpinfo->use_star && (res == 254 || res == 65024)
247 && strstr(tmp, "star: Processed all possible files")
248 && tries > 0) {
[1107]249 mr_msg(1, "Star returned nonfatal error");
[128]250 res = 0;
251 }
252 if (res) {
253 log_OS_error(command);
254 p = strstr(command, "-acl ");
255 if (p) {
256 p[0] = p[1] = p[2] = p[3] = ' ';
[1107]257 mr_msg(1, "new command = '%s'", command);
[128]258 } else {
[1107]259 mr_msg(3,
[128]260 "Attempt #%d failed. Pausing 3 seconds and retrying...",
261 tries + 1);
262 sleep(3);
263 }
264 }
265 }
[1118]266 mr_free(command);
267
[128]268 retval += res;
269 if (retval) {
[1107]270 mr_msg(3, "Failed to write set %d", setno);
[128]271 } else if (tries > 1) {
[1107]272 mr_msg(3, "Succeeded in writing set %d, on try #%d", setno,
[128]273 tries);
274 }
275
276 return (retval);
[1]277}
278
279
280/**
281 * Call @c afio to archive the filelist @c filelist to the file @c fname.
282 *
283 * @param bkpinfo The backup information structure. Fields used:
284 * - @c compression_level
285 * - @c scratchdir (only verifies existence)
286 * - @c tmpdir (only verifies existence)
[1769]287 * - @c compression_tool
288 * - @c compression_suffix
[1]289 * @param filelist The path to a file containing a list of files to be archived
290 * in this fileset.
291 * @param fname The output file to archive to.
292 * @param setno This fileset number.
293 * @return The number of errors encountered (0 for success).
294 * @ingroup LLarchiveGroup
295 */
296int
[1663]297archive_this_fileset(char *filelist, char *fname, int setno)
[1]298{
299
[1118]300 /*@ int ************************************************************ */
[128]301 int retval = 0;
302 int res = 0;
303 int i = 0;
304 int tries = 0;
305 static int free_ramdisk_space = 9999;
[1]306
[1118]307 /*@ buffers ******************************************************** */
308 char *command = NULL;
309 char *zipparams = NULL;
310 char *tmp = NULL;
311 char *tmp1 = NULL;
[1]312
[128]313 assert(bkpinfo != NULL);
314 assert_string_is_neither_NULL_nor_zerolength(filelist);
315 assert_string_is_neither_NULL_nor_zerolength(fname);
[1]316
[128]317 if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
[1663]318 return (archive_this_fileset_with_star(filelist, fname, setno));
[128]319 }
[1]320
[128]321 if (!does_file_exist(filelist)) {
[1118]322 mr_asprintf(&tmp,
323 "(archive_this_fileset) - filelist %s does not exist",
324 filelist);
[128]325 log_to_screen(tmp);
[1118]326 mr_free(tmp);
[128]327 return (1);
328 }
[1118]329 mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
[128]330 if (system(tmp)) {
331 fatal_error("Unable to write tarball to scratchdir");
332 }
[1118]333 mr_free(tmp);
[128]334
335
336 if (bkpinfo->compression_level > 0) {
[1769]337 mr_asprintf(&zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->compression_tool,
[1118]338 bkpinfo->compression_level);
[1213]339 mr_asprintf(&tmp, "%s/do-not-compress-these", MONDO_SHARE);
[128]340 if (does_file_exist(tmp)) {
[1186]341 mr_asprintf(&tmp1, " -E +%s", tmp);
342 mr_strcat(zipparams, tmp1);
343 mr_free(tmp1);
[128]344 } else {
[1107]345 mr_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
[128]346 }
[1118]347 mr_free(tmp);
[128]348 } else {
[1118]349 mr_asprintf(&zipparams, " ");
[128]350 }
351
[1]352// make_hole_for_file(fname);
353
[128]354 if (!does_file_exist(bkpinfo->tmpdir)) {
355 log_OS_error("tmpdir not found");
356 fatal_error("tmpdir not found");
357 }
358 if (!does_file_exist(bkpinfo->scratchdir)) {
359 log_OS_error("scratchdir not found");
360 fatal_error("scratchdir not found");
361 }
[1118]362 mr_asprintf(&command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
[1769]363 fname, bkpinfo->compression_suffix);
[128]364 paranoid_system(command);
[1118]365 mr_free(command);
[1]366
[1118]367 mr_asprintf(&command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
[1638]368 mr_conf->external_tape_blocksize, zipparams, fname, filelist, MONDO_LOGFILE);
[1118]369 mr_free(zipparams);
[1]370
[1118]371 mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
[128]372 if (system(tmp)) {
373 fatal_error("Unable to write tarball to scratchdir");
374 }
[1118]375 mr_free(tmp);
[1]376
[128]377 for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
[1107]378 mr_msg(5, "command='%s'", command);
[128]379 res = system(command);
380 if (res) {
381 log_OS_error(command);
[1107]382 mr_msg(3,
[128]383 "Attempt #%d failed. Pausing 3 seconds and retrying...",
384 tries + 1);
385 sleep(3);
386 }
387 }
[1118]388 mr_free(command);
389
[128]390 retval += res;
391 if (retval) {
[1107]392 mr_msg(3, "Failed to write set %d", setno);
[128]393 } else if (tries > 1) {
[1107]394 mr_msg(3, "Succeeded in writing set %d, on try #%d", setno,
[128]395 tries);
396 }
[1]397
[128]398 if (g_tmpfs_mountpt[0] != '\0') {
399 i = atoi(call_program_and_get_last_line_of_output
[305]400 ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
[128]401 if (i > 0) {
402 if (free_ramdisk_space > i) {
403 free_ramdisk_space = i;
[1107]404 mr_msg(2, "min(free_ramdisk_space) is now %d",
[128]405 free_ramdisk_space);
406 if (free_ramdisk_space < 10) {
407 fatal_error
408 ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
409 }
410 }
411 }
412 }
413 return (retval);
[1]414}
415
416
417/**
418 * Wrapper function for all the backup commands.
419 * Calls these other functions: @c prepare_filelist(),
420 * @c call_filelist_chopper(), @c copy_mondo_and_mindi_stuff_to_scratchdir(),
421 * @c call_mindi_to_supply_boot_disks(), @c do_that_initial_phase(),
422 * @c make_those_afios_phase(), @c make_those_slices_phase(), and
423 * @c do_that_final_phase(). If anything fails before @c do_that_initial_phase(),
424 * @c fatal_error is called with a suitable message.
425 * @param bkpinfo The backup information structure. Uses most fields.
426 * @return The number of non-fatal errors encountered (0 for success).
427 * @ingroup archiveGroup
428 */
[1663]429int backup_data()
[1]430{
[128]431 int retval = 0, res = 0;
[1118]432 char *tmp = NULL;
[1]433
[128]434 assert(bkpinfo != NULL);
[1663]435 set_g_cdrom_and_g_dvd_to_bkpinfo_value();
[1118]436
[128]437 if (bkpinfo->backup_media_type == dvd) {
[1]438#ifdef DVDRWFORMAT
[128]439 if (!find_home_of_exe("dvd+rw-format")) {
440 fatal_error
441 ("Cannot find dvd+rw-format. Please install it or fix your PATH.");
442 }
[1]443#endif
[128]444 if (!find_home_of_exe("growisofs")) {
445 fatal_error
446 ("Cannot find growisofs. Please install it or fix your PATH.");
447 }
[1]448 }
449
[1663]450 if ((res = prepare_filelist())) { /* generate scratchdir/filelist.full */
[128]451 fatal_error("Failed to generate filelist catalog");
452 }
[1663]453 if (call_filelist_chopper()) {
[128]454 fatal_error("Failed to run filelist chopper");
455 }
[1]456
[1118]457 mr_asprintf(&tmp, "gzip -9 %s/archives/filelist.full",
458 bkpinfo->scratchdir);
[128]459 if (run_program_and_log_output(tmp, 2)) {
460 fatal_error("Failed to gzip filelist.full");
461 }
[1118]462 mr_free(tmp);
463 mr_asprintf(&tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
464 bkpinfo->tmpdir);
[128]465 if (run_program_and_log_output(tmp, 2)) {
466 fatal_error("Failed to copy to tmpdir");
467 }
[1118]468 mr_free(tmp);
[1]469
[1663]470 copy_mondo_and_mindi_stuff_to_scratchdir(); // payload, too, if it exists
[1]471#if __FreeBSD__ == 5
[1669]472 mr_allocstr(bkpinfo->kernel_path, "/boot/kernel/kernel");
[1]473#elif __FreeBSD__ == 4
[1669]474 mr_allocstr(bkpinfo->kernel_path, "/kernel");
[1]475#elif linux
[128]476 if (figure_out_kernel_path_interactively_if_necessary
477 (bkpinfo->kernel_path)) {
478 fatal_error
479 ("Kernel not found. Please specify manually with the '-k' switch.");
480 }
[1]481#else
482#error "I don't know about this system!"
483#endif
[1663]484 if ((res = call_mindi_to_supply_boot_disks())) {
[128]485 fatal_error("Failed to generate boot+data disks");
486 }
[1663]487 retval += do_that_initial_phase(); // prepare
[1118]488 mr_asprintf(&tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
[128]489 run_program_and_log_output(tmp, 1);
[1118]490 mr_free(tmp);
[1663]491 retval += make_those_afios_phase(); // backup regular files
492 retval += make_those_slices_phase(); // backup BIG files
493 retval += do_that_final_phase(); // clean up
[1107]494 mr_msg(1, "Creation of archives... complete.");
[128]495 if (bkpinfo->verify_data) {
496 sleep(2);
497 }
498 return (retval);
[1]499}
500
501
502/**
503 * Call Mindi to generate boot and data disks.
504 * @note This binds correctly to the new Perl version of mindi.
505 * @param bkpinfo The backup information structure. Fields used:
506 * - @c backup_media_type
507 * - @c boot_loader
508 * - @c boot_device
509 * - @c compression_level
510 * - @c differential
511 * - @c exclude_paths
512 * - @c image_devs
513 * - @c kernel_path
514 * - @c make_cd_use_lilo
515 * - @c media_device
516 * - @c media_size
517 * - @c nonbootable_backup
518 * - @c tmpdir
519 *
520 * @return The number of errors encountered (0 for success)
521 * @bug The code to automagically determine the boot drive
522 * is messy and system-dependent. In particular, it breaks
523 * for Linux RAID and LVM users.
524 * @ingroup MLarchiveGroup
525 */
[1663]526int call_mindi_to_supply_boot_disks()
[1]527{
[128]528 /*@ buffer ************************************************************ */
[1118]529 char *tmp = NULL;
[1693]530 char *tmp1 = NULL;
531 char *tmp2 = NULL;
[1118]532 char *command = NULL;
533 char *bootldr_str = NULL;
534 char *tape_device = NULL;
535 char *last_filelist_number = NULL;
536 char *broken_bios_sz = NULL;
537 char *cd_recovery_sz = NULL;
538 char *tape_size_sz = NULL;
539 char *devs_to_exclude = NULL;
540 char *use_lilo_sz = NULL;
541 char *bootdev = NULL;
[1]542
[128]543 /*@ char ************************************************************** */
[1]544 char ch = '\0';
545
[128]546 /*@ long ********************************************************** */
547 long lines_in_filelist = 0;
[1]548
[1118]549 /*@ int ************************************************************* */
[128]550 int res = 0;
551 long estimated_total_noof_slices = 0;
[1]552
[1087]553 FILE *fd = NULL;
[1091]554 FILE *fd1 = NULL;
[1087]555
[128]556 assert(bkpinfo != NULL);
557 malloc_string(last_filelist_number);
558 malloc_string(devs_to_exclude);
559 malloc_string(bootdev);
[1]560
[1118]561 mr_asprintf(&tmp,
[911]562 "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
[128]563 bkpinfo->exclude_paths);
[1118]564
[128]565 strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
[1118]566 mr_free(tmp);
567
568 mr_asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
[1107]569 mr_msg(2, tmp);
[1118]570 mr_free(tmp);
[128]571 mvaddstr_and_log_it(g_currentY, 0,
572 "Calling MINDI to create boot+data disks");
[1118]573 mr_asprintf(&tmp, "%s/filelist.full", bkpinfo->tmpdir);
[128]574 if (!does_file_exist(tmp)) {
[1118]575 mr_free(tmp);
576 mr_asprintf(&tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
[128]577 if (!does_file_exist(tmp)) {
578 fatal_error
579 ("Cannot find filelist.full, so I cannot count its lines");
580 }
581 }
582 lines_in_filelist = count_lines_in_file(tmp);
583 strcpy(last_filelist_number, last_line_of_file(tmp));
[1118]584 mr_free(tmp);
[1]585
[1118]586 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[1365]587 mr_asprintf(&tape_size_sz, "%ld", bkpinfo->media_size);
[1118]588 mr_asprintf(&tape_device, bkpinfo->media_device);
589 } else {
590 mr_asprintf(&tape_size_sz, " ");
591 mr_asprintf(&tape_device, " ");
592 }
593 /* BERLIOS: This parameter is not used after? */
594 mr_free(tape_size_sz);
595
596 mr_asprintf(&broken_bios_sz, "yes"); /* assume so */
597 if (g_cd_recovery) {
598 mr_asprintf(&cd_recovery_sz, "yes");
599 } else {
600 mr_asprintf(&cd_recovery_sz, "no");
601 }
602
[128]603 if (!bkpinfo->nonbootable_backup
604 && (bkpinfo->boot_loader == '\0'
605 || bkpinfo->boot_device[0] == '\0')) {
606
[1]607#ifdef __FreeBSD__
[128]608 strcpy(bootdev, call_program_and_get_last_line_of_output
609 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
610 if (!bootdev[0]) {
611 strcpy(bootdev, call_program_and_get_last_line_of_output
612 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
613 }
[1]614#else
[1903]615#ifdef __IA64__
[128]616 strcpy(bootdev, call_program_and_get_last_line_of_output
[1903]617 ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
618#else
619 strcpy(bootdev, call_program_and_get_last_line_of_output
[128]620 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
[1903]621#endif
[128]622 if (strstr(bootdev, "/dev/cciss/")) {
[1903]623#ifdef __IA64__
[128]624 strcpy(bootdev, call_program_and_get_last_line_of_output
[1903]625 ("mount | grep ' /boot/efi ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
626#else
627 strcpy(bootdev, call_program_and_get_last_line_of_output
[128]628 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
[1903]629#endif
[128]630 }
631 if (!bootdev[0]) {
632 strcpy(bootdev, call_program_and_get_last_line_of_output
633 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
634 if (strstr(bootdev, "/dev/cciss/")) {
635 strcpy(bootdev, call_program_and_get_last_line_of_output
636 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
637 }
638 }
[1]639#endif
[128]640 if (bootdev[0])
641 ch = which_boot_loader(bootdev);
642 else
643 ch = 'U';
[1118]644
[128]645 if (bkpinfo->boot_loader != '\0') {
[1118]646 mr_asprintf(&tmp, "User specified boot loader. It is '%c'.",
[128]647 bkpinfo->boot_loader);
[1107]648 mr_msg(2, tmp);
[1118]649 mr_free(tmp);
[128]650 } else {
651 bkpinfo->boot_loader = ch;
652 }
653 if (bkpinfo->boot_device[0] != '\0') {
[1118]654 mr_asprintf(&tmp, "User specified boot device. It is '%s'.",
[128]655 bkpinfo->boot_device);
[1107]656 mr_msg(2, tmp);
[1118]657 mr_free(tmp);
[128]658 } else {
659 strcpy(bkpinfo->boot_device, bootdev);
660 }
661 }
[1]662
[128]663 if (
[1]664#ifdef __FreeBSD__
[128]665 bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
[1]666#endif
667#ifdef __IA64__
[128]668 bkpinfo->boot_loader != 'E' &&
[1]669#endif
[128]670 bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G'
[1118]671 && bkpinfo->boot_loader != 'R' && !bkpinfo->nonbootable_backup)
672 {
[128]673 fatal_error
[1118]674 ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda.\nType 'man mondoarchive' to read the manual.");
[1]675 }
[128]676 if (bkpinfo->boot_loader == 'L') {
[1671]677 mr_asprintf(&bootldr_str, "LILO");
[128]678 if (!does_file_exist("/etc/lilo.conf")) {
679 fatal_error
[1118]680 ("The de facto standard location for your boot loader's config file is /etc/lilo.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?");
[128]681 }
682 } else if (bkpinfo->boot_loader == 'G') {
[1671]683 mr_asprintf(&bootldr_str, "GRUB");
[128]684 if (!does_file_exist("/etc/grub.conf")
685 && does_file_exist("/boot/grub/grub.conf")) {
686 run_program_and_log_output
687 ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
688 }
689 /* Detect Debian's grub config file */
690 else if (!does_file_exist("/etc/grub.conf")
691 && does_file_exist("/boot/grub/menu.lst")) {
692 run_program_and_log_output
693 ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
694 }
695 if (!does_file_exist("/etc/grub.conf")) {
696 fatal_error
[1118]697 ("The de facto standard location for your boot loader's config file is /etc/grub.conf.\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
[128]698 }
699 } else if (bkpinfo->boot_loader == 'E') {
[1671]700 mr_asprintf(&bootldr_str, "ELILO");
[1564]701 /* BERLIOS: fix it for Debian, Mandrake, ... */
[128]702 if (!does_file_exist("/etc/elilo.conf")
703 && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
704 run_program_and_log_output
705 ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
706 5);
707 }
[1564]708 if (!does_file_exist("/etc/elilo.conf")
709 && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) {
710 run_program_and_log_output
711 ("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf",
712 5);
713 }
[1570]714 if (!does_file_exist("/etc/elilo.conf")
715 && does_file_exist("/boot/efi/efi/debian/elilo.conf")) {
716 run_program_and_log_output
717 ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf",
718 5);
[1572]719 }
[1570]720 if (!does_file_exist("/etc/elilo.conf")
[1621]721 && does_file_exist("/boot/efi/debian/elilo.conf")) {
[1570]722 run_program_and_log_output
723 ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf",
724 5);
725 }
[128]726 if (!does_file_exist("/etc/elilo.conf")) {
727 fatal_error
[1118]728 ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf\nBut I cannot find it there. What is wrong with your Linux distribution?\nTry finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
[128]729 }
730 } else if (bkpinfo->boot_loader == 'R') {
[1671]731 mr_asprintf(&bootldr_str, "RAW");
[1]732 }
733#ifdef __FreeBSD__
[128]734 else if (bkpinfo->boot_loader == 'D') {
[1671]735 mr_asprintf(&bootldr_str, "DD");
[128]736 }
[1]737
[128]738 else if (bkpinfo->boot_loader == 'B') {
[1671]739 mr_asprintf(&bootldr_str, "BOOT0");
[128]740 }
[1]741#endif
[128]742 else {
[1671]743 mr_asprintf(&bootldr_str, "unknown");
[128]744 }
[1118]745 mr_asprintf(&tmp, "Your boot loader is %s and it boots from %s",
[128]746 bootldr_str, bkpinfo->boot_device);
747 log_to_screen(tmp);
[1118]748 mr_free(tmp);
749 mr_asprintf(&tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
750 if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
751 mr_msg(1, "Unable to write one-liner boot device");
752 }
753
[1087]754 estimated_total_noof_slices =
755 size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
[1118]756 mr_asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir);
[1087]757 if (system(command)) {
758 res++;
759 log_OS_error("Unable to make images directory");
[128]760 }
[1118]761 mr_free(command);
762
[1087]763 /* Prepare interface with mindi through a configuration file
764 * under /var/cache/mondo by default
765 * and the mondorestore configuration file at the same time that
766 * will be included by mindi on the initrd */
767
768 fd = mr_fopen(MONDO_CACHE"/mindi.conf", "w");
769 fd1 = mr_fopen(MONDORESTORECFG, "a");
770
[1669]771 mr_fprintf(fd, "mindi_use_own_kernel=yes\n");
772 if (strcmp(mr_conf->mondo_kernel,"FAILSAFE") == 0) {
773 } else {
774 }
[1087]775 mr_fprintf(fd, "mindi_kernel=%s\n", bkpinfo->kernel_path);
[1671]776 mr_fprintf(fd, "mindi_additional_mods=%s\n", mr_conf->additional_modules);
[1087]777
[1158]778 mr_fprintf(fd1, "files-in-filelist=%ld\n", lines_in_filelist);
779 mr_fprintf(fd1, "internal-tape-block-size=%ld\n", bkpinfo->internal_tape_block_size);
780 mr_fprintf(fd1, "total-slices=%ld\n", estimated_total_noof_slices);
781 mr_fprintf(fd1, "excluded-devs=%s\n", devs_to_exclude);
782 mr_fprintf(fd1, "image-devs=%s\n", bkpinfo->image_devs);
783 mr_fprintf(fd1, "last-filelist-number=%s\n", last_filelist_number);
784 mr_fprintf(fd1, "bootloader.name=%s\n", bootldr_str);
785 mr_fprintf(fd1, "bootloader.device=%s\n", bkpinfo->boot_device);
[1087]786
[1671]787 mr_free(bootldr_str);
788
[128]789 switch (bkpinfo->backup_media_type) {
790 case cdr:
[1158]791 mr_fprintf(fd1, "backup-media-type=cdr\n");
[128]792 break;
793 case cdrw:
[1158]794 mr_fprintf(fd1, "backup-media-type=cdrw\n");
[128]795 break;
796 case cdstream:
[1158]797 mr_fprintf(fd1, "backup-media-type=cdstream\n");
[128]798 break;
799 case tape:
[1158]800 mr_fprintf(fd1, "backup-media-type=tape\n");
[128]801 break;
802 case udev:
[1158]803 mr_fprintf(fd1, "backup-media-type=udev\n");
[128]804 break;
805 case iso:
[1158]806 mr_fprintf(fd1, "backup-media-type=iso\n");
[128]807 break;
808 case nfs:
[1158]809 mr_fprintf(fd1, "backup-media-type=nfs\n");
[128]810 break;
811 case dvd:
[1158]812 mr_fprintf(fd1, "backup-media-type=dvd\n");
[128]813 break;
[1063]814 case usb:
[1158]815 mr_fprintf(fd1, "backup-media-type=usb\n");
[1063]816 break;
[128]817 default:
818 fatal_error("Unknown backup_media_type");
819 }
[1087]820
821 if (bkpinfo->backup_media_type == usb) {
822 mr_fprintf(fd, "mindi_write_usb=yes\n");
823 mr_fprintf(fd, "mindi_usb_device=%s\n", bkpinfo->media_device);
[128]824 }
[1087]825 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
826 mr_fprintf(fd, "mindi_write_tape=yes\n");
827 mr_fprintf(fd, "mindi_tape_device=%s\n", bkpinfo->media_device);
[1158]828 mr_fprintf(fd1, "media-dev=%s\n", bkpinfo->media_device);
[1365]829 mr_fprintf(fd1, "media-size=%ld\n", bkpinfo->media_size);
[128]830 }
[1087]831 if (bkpinfo->compression_level > 0) {
[1158]832 mr_fprintf(fd1, "use-comp=yes\n");
[128]833 } else {
[1158]834 mr_fprintf(fd1, "use-comp=no\n");
[128]835 }
[1769]836 if (bkpinfo->compression_tool) {
837 mr_fprintf(fd1, "compression_tool=%s\n",bkpinfo->compression_tool);
[1087]838 }
[1769]839 if (bkpinfo->compression_suffix) {
840 mr_fprintf(fd1, "compression_suffix=%s\n",bkpinfo->compression_suffix);
[1087]841 }
[1769]842 if (bkpinfo->compression_type != none) {
843 mr_fprintf(fd1, "compression_type=%d\n",bkpinfo->compression_type);
844 }
[1087]845 if (bkpinfo->use_star) {
[1158]846 mr_fprintf(fd1, "use-star=yes\n");
[1087]847 } else {
[1158]848 mr_fprintf(fd1, "use-star=no\n");
[1087]849 }
[949]850 if (g_getfattr) {
[1158]851 mr_fprintf(fd1, "xattr=yes\n");
[1087]852 } else {
[1158]853 mr_fprintf(fd1, "xattr=no\n");
[949]854 }
855 if (g_getfacl) {
[1158]856 mr_fprintf(fd1, "acl=yes\n");
[1087]857 } else {
[1158]858 mr_fprintf(fd1, "acl=no\n");
[949]859 }
860
[1087]861 if (g_cd_recovery) {
[1158]862 mr_fprintf(fd1, "use-cdrecovery=yes\n");
[1087]863 } else {
[1158]864 mr_fprintf(fd1, "use-cdrecovery=no\n");
[128]865 }
[1118]866
[1087]867 if (bkpinfo->make_cd_use_lilo) {
[1158]868 mr_fprintf(fd1, "use-lilo=yes\n");
[1087]869 } else {
[1158]870 mr_fprintf(fd1, "use-lilo=no\n");
[128]871 }
[1087]872 if (bkpinfo->nonbootable_backup) {
[1158]873 mr_fprintf(fd1, "non-bootable=yes\n");
[1063]874 } else {
[1158]875 mr_fprintf(fd1, "non-bootable=no\n");
[1063]876 }
[1087]877 if (bkpinfo->differential) {
[1639]878 mr_fprintf(fd1, "differential=yes\n");
[1087]879 } else {
[1639]880 mr_fprintf(fd1, "differential=no\n");
[1087]881 }
[1669]882 if (mr_conf->mondo_create_mindi_cd) {
883 mr_fprintf(fd1, "mindi_write_cd=yes\n");
884 } else {
885 mr_fprintf(fd1, "mindi_write_cd=no\n");
886 }
[1063]887
[1087]888 mr_fclose(fd);
[1158]889 mr_fprintf(fd1, "datestamp=%s\n", mr_date());
[1087]890 mr_fclose(fd1);
891
[1118]892 mr_asprintf(&command, "mindi --custom '%s' '%s/images'",
[1093]893 bkpinfo->tmpdir, bkpinfo->scratchdir);
894 //bkpinfo->tmpdir, // parameter #2
895 //bkpinfo->scratchdir, // parameter #3
[1087]896 //bkpinfo->kernel_path, // parameter #4
897 //tape_device, // parameter #5
898 //tape_size_sz, // parameter #6
899 //lines_in_filelist, // parameter #7 (INT)
900 //use_lzo_sz, // parameter #8
901 //cd_recovery_sz, // parameter #9
902 //bkpinfo->image_devs, // parameter #10
903 //broken_bios_sz, // parameter #11 always yes
904 //last_filelist_number, // parameter #12 (STRING)
905 //estimated_total_noof_slices, // parameter #13 (INT)
906 //devs_to_exclude, // parameter #14
907 //use_comp_sz, // parameter #15
908 //use_lilo_sz, // parameter #16
909 //use_star_sz, // parameter #17
910 //bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
911 //bkpinfo->differential, // parameter #19 (INT)
912 //use_gzip_sz); // parameter #20 (STRING)
[1]913
[1107]914 mr_msg(2, command);
[1]915
[1087]916 res = run_program_and_log_to_screen(command, "Generating boot+data disks");
[1118]917 mr_free(command);
[128]918 if (bkpinfo->nonbootable_backup) {
919 res = 0;
920 } // hack
921 if (!res) {
922 log_to_screen("Boot+data disks were created OK");
[1438]923 mr_asprintf(&command, "mkdir -p "MINDI_CACHE);
[1107]924 mr_msg(2, command);
[128]925 run_program_and_log_output(command, FALSE);
[1118]926 mr_free(command);
927
928 mr_asprintf(&command,
[1438]929 "cp -f %s/images/mindi.iso %s/mondorescue.iso",
930 bkpinfo->scratchdir, MINDI_CACHE);
[1107]931 mr_msg(2, command);
[128]932 run_program_and_log_output(command, FALSE);
[1118]933 mr_free(command);
934
[128]935 if (bkpinfo->nonbootable_backup) {
[1118]936 mr_asprintf(&command, "cp -f %s/all.tar.gz %s/images",
[128]937 bkpinfo->tmpdir, bkpinfo->scratchdir);
938 if (system(command)) {
[1770]939 fatal_error("Unable to create temporary all tarball");
[128]940 }
[1118]941 mr_free(command);
942
[128]943 }
[1118]944/* BERLIOS: Not executed ?
[128]945 sprintf(command, "cp -f %s/mindi-*oot*.img %s/images",
[1770]946*/
947 /* For USB we already have everything on the key */
948 if (bkpinfo->backup_media_type == usb) {
949 mr_asprintf(&command, "rm -rf %s/images", bkpinfo->scratchdir);
950 run_program_and_log_output(command, FALSE);
951 mr_free(command);
952 } else {
953 mr_asprintf(&tmp, "cp -f %s/images/all.tar.gz %s",
[1118]954 bkpinfo->scratchdir, bkpinfo->tmpdir);
[1770]955 if (system(tmp)) {
956 fatal_error("Cannot find all.tar.gz in tmpdir");
957 mr_free(tmp);
958 }
[128]959 }
[1118]960
[128]961 if (res) {
962 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
963 } else {
964 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
965 }
966 } else {
967 log_to_screen("Mindi failed to create your boot+data disks.");
[1118]968 mr_asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
969 malloc_string(tmp);
970 strcpy(tmp,call_program_and_get_last_line_of_output(command));
971 mr_free(command);
[128]972 if (strlen(tmp) > 1) {
[155]973 popup_and_OK(tmp);
[128]974 }
[1118]975 mr_free(tmp);
[128]976 }
[1080]977 mr_free(last_filelist_number);
978 mr_free(devs_to_exclude);
979 mr_free(bootdev);
[128]980 return (res);
[1]981}
982
983
984/**
985 * Maximum number of filesets allowed in this function.
986 */
987#define MAX_NOOF_SETS_HERE 32767
988
989/**
990 * Offset of the bkpinfo pointer (in bytes) from the
991 * buffer passed to create_afio_files_in_background.
992 */
993#define BKPINFO_LOC_OFFSET (16+MAX_NOOF_SETS_HERE/8+16)
994
995/**
996 * Main function for each @c afio thread.
997 * @param inbuf A transfer block containing:
998 * - @c p_last_set_archived: [offset 0] pointer to an @c int
999 * containing the last set archived.
1000 * - @c p_archival_threads_running: [offset 4] pointer to an @c int
1001 * containing the number of archival threads currently running.
1002 * - @c p_next_set_to_archive: [offset 8] pointer to an @c int containing
1003 * the next set that should be archived.
1004 * - @c p_list_of_fileset_flags: [offset 12] @c char pointer pointing to a
1005 * bit array, where each bit corresponds to a filelist (1=needs
1006 * to be archived, 0=archived).
1007 * - @c bkpinfo: [offset BKPINFO_LOC_OFFSET] pointer to backup information
1008 * structure. Fields used:
1009 * - @c tmpdir
[1769]1010 * - @c compression_suffix
[1]1011 *
1012 * Any of the above may be modified by the caller at any time.
1013 *
1014 * @bug Assumes @c int pointers are 4 bytes.
1015 * @see archive_this_fileset
1016 * @see make_afioballs_and_images
1017 * @return NULL, always.
1018 * @ingroup LLarchiveGroup
1019 */
[128]1020void *create_afio_files_in_background(void *inbuf)
[1]1021{
[128]1022 long int archiving_set_no;
1023 char *archiving_filelist_fname;
1024 char *archiving_afioball_fname;
[948]1025 char *curr_xattr_list_fname = NULL;
[128]1026 char *curr_acl_list_fname;
[1]1027
[1663]1028 struct s_bkpinfo *bkpinfo_bis;
[1118]1029 char *tmp = NULL;
[128]1030 int res = 0, retval = 0;
1031 int *p_archival_threads_running;
1032 int *p_last_set_archived;
1033 int *p_next_set_to_archive;
1034 char *p_list_of_fileset_flags;
1035 int this_thread_no = g_current_thread_no++;
[1]1036
[128]1037 malloc_string(archiving_filelist_fname);
1038 malloc_string(archiving_afioball_fname);
1039 p_last_set_archived = (int *) inbuf;
1040 p_archival_threads_running = (int *) (inbuf + 4);
1041 p_next_set_to_archive = (int *) (inbuf + 8);
1042 p_list_of_fileset_flags = (char *) (inbuf + 12);
[1663]1043 bkpinfo_bis = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
[1]1044
[128]1045 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
1046 bkpinfo->tmpdir, 0L);
1047 for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname);
1048 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
1049 bkpinfo->tmpdir, archiving_set_no)) {
1050 if (g_exiting) {
1051 fatal_error("Execution run aborted (pthread)");
1052 }
1053 if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
1054 fatal_error
1055 ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
1056 }
1057 if (!semaphore_p()) {
[1107]1058 mr_msg(3, "P sem failed (pid=%d)", (int) getpid());
[128]1059 fatal_error("Cannot get semaphore P");
1060 }
1061 if (archiving_set_no < *p_next_set_to_archive) {
1062 archiving_set_no = *p_next_set_to_archive;
1063 }
1064 *p_next_set_to_archive = *p_next_set_to_archive + 1;
1065 if (!semaphore_v()) {
1066 fatal_error("Cannot get semaphore V");
1067 }
[1]1068
[128]1069 /* backup this set of files */
1070 sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
[1769]1071 bkpinfo->tmpdir, archiving_set_no, bkpinfo->compression_suffix);
[128]1072 sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
1073 bkpinfo->tmpdir, archiving_set_no);
1074 if (!does_file_exist(archiving_filelist_fname)) {
[1107]1075 mr_msg(3,
[1627]1076 "[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
1077 getpid(), this_thread_no,
[128]1078 archiving_set_no);
1079 break;
1080 }
[1]1081
[1118]1082 mr_asprintf(&tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
[1769]1083 archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->compression_suffix);
[128]1084 if (does_file_exist(tmp)) {
[1627]1085 mr_msg(4, "[%d:%d] - waiting for storer",
1086 getpid(), this_thread_no);
[128]1087 while (does_file_exist(tmp)) {
1088 sleep(1);
1089 }
[1107]1090 mr_msg(4, "[%d] - continuing", getpid());
[128]1091 }
[1118]1092 mr_free(tmp);
[1]1093
[1627]1094 mr_msg(4, "[%d:%d] - EXATing %d...", getpid(),
[128]1095 this_thread_no, archiving_set_no);
[948]1096 if (g_getfattr) {
[1118]1097 mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]1098 bkpinfo->tmpdir, archiving_set_no);
[948]1099 get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
[1118]1100 mr_free(curr_xattr_list_fname);
[948]1101 }
1102 if (g_getfacl) {
[1118]1103 mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
[128]1104 bkpinfo->tmpdir, archiving_set_no);
[948]1105 get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
[1118]1106 mr_free(curr_acl_list_fname);
[948]1107 }
[1]1108
[1627]1109 mr_msg(4, "[%d:%d] - archiving %d...", getpid(),
[128]1110 this_thread_no, archiving_set_no);
[1663]1111 res =
1112 archive_this_fileset(archiving_filelist_fname,
[128]1113 archiving_afioball_fname,
1114 archiving_set_no);
1115 retval += res;
[1]1116
[128]1117 if (res) {
[1118]1118 mr_asprintf(&tmp,
1119 "Errors occurred while archiving set %ld. Please review logs.",
1120 archiving_set_no);
[128]1121 log_to_screen(tmp);
[1118]1122 mr_free(tmp);
[128]1123 }
1124 if (!semaphore_p()) {
1125 fatal_error("Cannot get semaphore P");
1126 }
1127
1128 set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
1129
1130 if (*p_last_set_archived < archiving_set_no) {
1131 *p_last_set_archived = archiving_set_no;
1132 } // finished archiving this one
1133
1134 if (!semaphore_v()) {
1135 fatal_error("Cannot get semaphore V");
1136 }
[1627]1137 mr_msg(4, "[%d:%d] - archived %d OK", getpid(),
[128]1138 this_thread_no, archiving_set_no);
1139 archiving_set_no++;
1140 }
1141 if (!semaphore_p()) {
1142 fatal_error("Cannot get semaphore P");
1143 }
1144 (*p_archival_threads_running)--;
1145 if (!semaphore_v()) {
1146 fatal_error("Cannot get semaphore V");
1147 }
[1627]1148 mr_msg(3, "[%d:%d] - exiting", getpid(),
[128]1149 this_thread_no);
[1080]1150 mr_free(archiving_filelist_fname);
1151 mr_free(archiving_afioball_fname);
[128]1152 pthread_exit(NULL);
[1]1153}
1154
1155
1156/**
1157 * Finalize the backup.
1158 * For streaming backups, this writes the closing block
1159 * to the stream. For CD-based backups, this creates
1160 * the final ISO image.
1161 * @param bkpinfo The backup information structure, used only
1162 * for the @c backup_media_type.
1163 * @ingroup MLarchiveGroup
1164 */
[1663]1165int do_that_final_phase()
[1]1166{
1167
[128]1168 /*@ int ************************************** */
1169 int res = 0;
1170 int retval = 0;
[1]1171
[128]1172 /*@ buffers ********************************** */
[1]1173
[128]1174 assert(bkpinfo != NULL);
1175 mvaddstr_and_log_it(g_currentY, 0,
1176 "Writing any remaining data to media ");
[1]1177
[1770]1178 mr_msg(1, "Closing tape/CD/USB ... ");
[1118]1179 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[128]1180 /* write tape/cdstream */
[1663]1181 closeout_tape();
[1118]1182 } else {
[1087]1183 /* write final ISO/USB */
[1663]1184 res = write_final_iso_if_necessary();
[128]1185 retval += res;
1186 if (res) {
[1107]1187 mr_msg(1, "write_final_iso_if_necessary returned an error");
[128]1188 }
[1]1189 }
[1107]1190 mr_msg(2, "Fork is exiting ... ");
[1]1191
[128]1192 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
[1]1193
[128]1194 /* final stuff */
1195 if (retval) {
1196 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
1197 } else {
1198 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1199 }
[1]1200
[128]1201 return (retval);
[1]1202}
1203
1204
1205/**
1206 * Initialize the backup.
1207 * Does the following:
1208 * - Sets up the serial number.
1209 * - For streaming backups, opens the tape stream and writes the data disks
1210 * and backup headers.
1211 * - For CD-based backups, wipes the ISOs in the target directory.
1212 *
1213 * @param bkpinfo The backup information structure. Fields used:
1214 * - @c backup_media_type
[1594]1215 * - @c writer_speed
[20]1216 * - @c prefix
[1]1217 * - @c isodir
1218 * - @c media_device
1219 * - @c scratchdir
1220 * - @c tmpdir
1221 * @return The number of errors encountered (0 for success).
1222 * @ingroup MLarchiveGroup
1223 */
[1663]1224int do_that_initial_phase()
[1]1225{
[128]1226 /*@ int *************************************** */
1227 int retval = 0;
[1]1228
[128]1229 /*@ buffers *********************************** */
[1164]1230 char *command, *tmp_file, *data_disks_file;
[1]1231
[128]1232 assert(bkpinfo != NULL);
1233 malloc_string(command);
1234
[1118]1235 mr_asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
1236
[128]1237 snprintf(g_serial_string, MAX_STR_LEN - 1,
1238 call_program_and_get_last_line_of_output("dd \
[1]1239if=/dev/urandom bs=16 count=1 2> /dev/null | \
1240hexdump | tr -s ' ' '0' | head -n1"));
[1168]1241 mr_strip_spaces(g_serial_string);
[128]1242 strcat(g_serial_string, "...word.");
[1107]1243 mr_msg(2, "g_serial_string = '%s'", g_serial_string);
[128]1244 assert(strlen(g_serial_string) < MAX_STR_LEN);
[1]1245
[1164]1246 mr_asprintf(&tmp_file, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
1247 if (write_one_liner_data_file(tmp_file, g_serial_string)) {
[1107]1248 mr_msg(1, "%ld: Failed to write serial string", __LINE__);
[128]1249 }
[1164]1250 mr_free(tmp_file);
[1]1251
[128]1252 mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
1253 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1254 if (bkpinfo->backup_media_type == cdstream) {
[1594]1255 openout_cdstream(bkpinfo->media_device, bkpinfo->writer_speed);
[128]1256 } else {
1257 openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
1258 }
1259 if (!g_tape_stream) {
1260 fatal_error("Cannot open backup (streaming) device");
1261 }
[1107]1262 mr_msg(1, "Backup (stream) opened OK");
[128]1263 write_data_disks_to_stream(data_disks_file);
1264 } else {
[1770]1265 if (bkpinfo->backup_media_type == usb) {
1266 mr_msg(1, "Backing up to USB's");
1267 } else {
1268 mr_msg(1, "Backing up to CD's");
1269 }
[1]1270 }
[1118]1271 mr_free(data_disks_file);
[1]1272
[1118]1273 mr_asprintf(&command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
1274 bkpinfo->nfs_remote_dir, bkpinfo->prefix);
[128]1275 paranoid_system(command);
[1118]1276 mr_free(command);
1277
[128]1278 wipe_archives(bkpinfo->scratchdir);
1279 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1280 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[684]1281 write_header_block_to_stream((off_t)0, "start-of-tape",
[128]1282 BLK_START_OF_TAPE);
[684]1283 write_header_block_to_stream((off_t)0, "start-of-backup",
[128]1284 BLK_START_OF_BACKUP);
1285 }
1286 return (retval);
[1]1287}
1288
1289
1290/**
1291 * Get the <tt>N</tt>th bit of @c array.
1292 * @param array The bit-array (as a @c char pointer).
1293 * @param N The number of the bit you want.
1294 * @return TRUE (bit is set) or FALSE (bit is not set).
1295 * @see set_bit_N_of_array
1296 * @ingroup utilityGroup
1297 */
[128]1298bool get_bit_N_of_array(char *array, int N)
[1]1299{
[128]1300 int element_number;
1301 int bit_number;
1302 int mask;
1303
1304 element_number = N / 8;
1305 bit_number = N % 8;
1306 mask = 1 << bit_number;
1307 if (array[element_number] & mask) {
1308 return (TRUE);
1309 } else {
1310 return (FALSE);
1311 }
[1]1312}
1313
1314
1315/**
1316 * @addtogroup LLarchiveGroup
1317 * @{
1318 */
1319/**
1320 * Start up threads to archive your files.
1321 *
1322 * This function starts @c ARCH_THREADS threads,
1323 * each starting execution in @c create_afio_files_in_background().
1324 * Each thread will archive individual filesets, based on the
1325 * pointers passed to it and continually updated, until all files
1326 * have been backed up. This function coordinates the threads
1327 * and copies their output to the @c scratchdir.
1328 *
1329 * @param bkpinfo The backup information structure. Fields used:
1330 * - @c backup_media_type
1331 * - @c scratchdir
1332 * - @c tmpdir
[1769]1333 * - @c compression_suffix
[1]1334 *
1335 * @return The number of errors encountered (0 for success)
1336 */
[1663]1337int make_afioballs_and_images()
[1]1338{
1339
[128]1340 /*@ int ************************************************** */
1341 int retval = 0;
1342 long int storing_set_no = 0;
1343 int res = 0;
1344 bool done_storing = FALSE;
1345 char *result_str;
1346 char *transfer_block;
1347 void *vp;
1348 void **pvp;
[1]1349
[128]1350 /*@ buffers ********************************************** */
1351 char *storing_filelist_fname;
1352 char *storing_afioball_fname;
[1135]1353 char *tmp = NULL;
[128]1354 char *media_usage_comment;
1355 pthread_t archival_thread[ARCH_THREADS];
1356 char *p_list_of_fileset_flags;
1357 int *p_archival_threads_running;
1358 int *p_last_set_archived;
1359 int *p_next_set_to_archive;
1360 int noof_threads;
1361 int i;
[948]1362 char *curr_xattr_list_fname = NULL;
[1939]1363 char *curr_acl_list_fname = NULL;
[128]1364 int misc_counter_that_is_not_important = 0;
[1]1365
[1107]1366 mr_msg(8, "here");
[128]1367 assert(bkpinfo != NULL);
[1135]1368 /* BERLIOS: To be removed */
[128]1369 malloc_string(result_str);
1370 malloc_string(curr_xattr_list_fname);
1371 malloc_string(curr_acl_list_fname);
1372 malloc_string(storing_filelist_fname);
1373 malloc_string(media_usage_comment);
1374 malloc_string(storing_afioball_fname);
1375 transfer_block =
[1080]1376 mr_malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
[128]1377 memset((void *) transfer_block, 0,
1378 sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
1379 p_last_set_archived = (int *) transfer_block;
1380 p_archival_threads_running = (int *) (transfer_block + 4);
1381 p_next_set_to_archive = (int *) (transfer_block + 8);
1382 p_list_of_fileset_flags = (char *) (transfer_block + 12);
1383 memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
1384 (void *) bkpinfo, sizeof(struct s_bkpinfo));
1385 pvp = &vp;
1386 vp = (void *) result_str;
1387 *p_archival_threads_running = 0;
1388 *p_last_set_archived = -1;
1389 *p_next_set_to_archive = 0;
1390 log_to_screen("Archiving regular files");
[1118]1391 open_progress_form(_("Backing up filesystem"),
1392 _("I am backing up your live filesystem now."),
1393 _("Please wait. This may take a couple of hours."),
1394 _("Working..."),
[1663]1395 get_last_filelist_number() + 1);
[1]1396
[128]1397 srand((unsigned int) getpid());
1398 g_sem_key = 1234 + random() % 30000;
1399 if ((g_sem_id =
1400 semget((key_t) g_sem_key, 1,
1401 IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
1402 fatal_error("MABAI - unable to semget");
[1]1403 }
[128]1404 if (!set_semvalue()) {
1405 fatal_error("Unable to init semaphore");
1406 } // initialize semaphore
1407 for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
[1107]1408 mr_msg(8, "Creating thread #%d", noof_threads);
[128]1409 (*p_archival_threads_running)++;
1410 if ((res =
1411 pthread_create(&archival_thread[noof_threads], NULL,
1412 create_afio_files_in_background,
1413 (void *) transfer_block))) {
1414 fatal_error("Unable to create an archival thread");
1415 }
[1]1416 }
1417
[1107]1418 mr_msg(8, "About to enter while() loop");
[128]1419 while (!done_storing) {
1420 if (g_exiting) {
1421 fatal_error("Execution run aborted (main loop)");
1422 }
1423 if (*p_archival_threads_running == 0
1424 && *p_last_set_archived == storing_set_no - 1) {
[1107]1425 mr_msg(2,
[128]1426 "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
1427 *p_last_set_archived, storing_set_no);
1428 done_storing = TRUE;
1429 } else
1430 if (!get_bit_N_of_array
1431 (p_list_of_fileset_flags, storing_set_no)) {
1432 misc_counter_that_is_not_important =
1433 (misc_counter_that_is_not_important + 1) % 5;
1434 if (!misc_counter_that_is_not_important) {
1435 update_progress_form(media_usage_comment);
1436 }
1437 sleep(1);
[1118]1438 } else {
[128]1439 // store set N
1440 sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
1441 bkpinfo->tmpdir, storing_set_no);
1442 sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
[1769]1443 bkpinfo->tmpdir, storing_set_no, bkpinfo->compression_suffix);
[948]1444 if (g_getfattr) {
1445 sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]1446 bkpinfo->tmpdir, storing_set_no);
[948]1447 }
1448 if (g_getfacl) {
1449 sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
[128]1450 bkpinfo->tmpdir, storing_set_no);
[948]1451 }
[128]1452
[1107]1453 mr_msg(2, "Storing set %d", storing_set_no);
[128]1454 while (!does_file_exist(storing_filelist_fname)
1455 || !does_file_exist(storing_afioball_fname)) {
[1107]1456 mr_msg(2,
[128]1457 "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
1458 storing_filelist_fname, storing_afioball_fname);
1459 sleep(5);
1460 }
[1663]1461 strcpy(media_usage_comment, percent_media_full_comment());
[128]1462 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
1463 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1464 register_in_tape_catalog(fileset, storing_set_no, -1,
1465 storing_afioball_fname);
1466 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
1467 storing_afioball_fname);
1468 iamhere("Writing EXAT files");
[1663]1469 res += write_EXAT_files_to_tape(curr_xattr_list_fname,
[1118]1470 curr_acl_list_fname);
1471 // archives themselves
[128]1472 res +=
[1939]1473 write_EXAT_files_to_tape(curr_xattr_list_fname,
1474 curr_acl_list_fname);
1475 // archives themselves
1476 res +=
[1663]1477 move_files_to_stream(storing_afioball_fname,
[128]1478 NULL);
1479 } else {
[948]1480 if (g_getfacl) {
1481 if (g_getfattr) {
[1663]1482 res = move_files_to_cd(storing_filelist_fname,
[128]1483 curr_xattr_list_fname,
1484 curr_acl_list_fname,
1485 storing_afioball_fname, NULL);
[948]1486 } else {
[1663]1487 res = move_files_to_cd(storing_filelist_fname,
[948]1488 curr_acl_list_fname,
1489 storing_afioball_fname, NULL);
1490 }
1491 } else {
1492 if (g_getfattr) {
[1663]1493 res = move_files_to_cd(storing_filelist_fname,
[948]1494 curr_xattr_list_fname,
1495 storing_afioball_fname, NULL);
1496 } else {
[1663]1497 res = move_files_to_cd(storing_filelist_fname,
[948]1498 storing_afioball_fname, NULL);
1499 }
1500 }
[128]1501 }
1502 retval += res;
1503 g_current_progress++;
1504 update_progress_form(media_usage_comment);
1505 if (res) {
[1135]1506 mr_asprintf(&tmp,
1507 "Failed to add archive %ld's files to CD dir\n",
1508 storing_set_no);
[128]1509 log_to_screen(tmp);
[1135]1510 mr_free(tmp);
[128]1511 fatal_error
1512 ("Is your hard disk full? If not, please send the author the logfile.");
1513 }
1514 storing_set_no++;
1515 // sleep(2);
[1]1516 }
1517 }
[128]1518 close_progress_form();
[1]1519
[1107]1520 mr_msg(2, "Joining background threads to foreground thread");
[128]1521 for (i = 0; i < noof_threads; i++) {
1522 pthread_join(archival_thread[i], pvp);
[1107]1523 mr_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
[128]1524 }
1525 del_semvalue();
[1107]1526 mr_msg(2, "Done.");
[128]1527 if (retval) {
[1135]1528 mr_asprintf(&tmp,
1529 "Your regular files have been archived (with errors).");
[128]1530 } else {
[1135]1531 mr_asprintf(&tmp,
1532 "Your regular files have been archived successfully");
[128]1533 }
1534 log_to_screen(tmp);
[1135]1535 mr_free(tmp);
[1080]1536 mr_free(transfer_block);
1537 mr_free(result_str);
1538 mr_free(storing_filelist_fname);
1539 mr_free(media_usage_comment);
1540 mr_free(storing_afioball_fname);
1541 mr_free(curr_xattr_list_fname);
1542 mr_free(curr_acl_list_fname);
[128]1543 return (retval);
[1]1544}
1545
1546
[128]1547void pause_for_N_seconds(int how_long, char *msg)
[1]1548{
[128]1549 int i;
1550 open_evalcall_form(msg);
1551 for (i = 0; i < how_long; i++) {
1552 update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
1553 sleep(1);
1554 }
1555 close_evalcall_form();
[1]1556}
1557
1558
1559/**
[1693]1560 * Create a USB image in @c destfile, from files in @c bkpinfo->scratchdir.
1561 *
1562 * @param bkpinfo The backup information structure. Fields used:
1563 * - @c backup_media_type
1564 * - @c nonbootable_backup
1565 * - @c scratchdir
1566 *
1567 * @param destfile Where to put the generated USB image.
1568 * @return The number of errors encountered (0 for success)
1569 */
1570int make_usb_fs()
1571{
1572 /*@ int ********************************************** */
1573 int retval = 0;
1574 int res;
1575
1576 /*@ buffers ****************************************** */
1577 char *tmp = NULL;
1578 char *tmp1 = NULL;
1579 char *result_sz = NULL;
1580 char *message_to_screen = NULL;
1581 char *old_pwd;
1582
1583 malloc_string(old_pwd);
1584 assert(bkpinfo != NULL);
1585
1586 log_msg(2, "make_usb_fs --- scratchdir=%s", bkpinfo->scratchdir);
1587 (void) getcwd(old_pwd, MAX_STR_LEN - 1);
1588 asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
1589 run_program_and_log_output(tmp, FALSE);
1590 paranoid_free(tmp);
1591 chdir(bkpinfo->scratchdir);
1592
1593 asprintf(&message_to_screen, "Copying data to make %s #%d",
1594 media_descriptor_string(bkpinfo->backup_media_type),
1595 g_current_media_number);
1596 log_msg(1, message_to_screen);
1597
[1770]1598 asprintf(&tmp1, "%s1", bkpinfo->media_device);
1599 if (is_this_device_mounted(tmp1)) {
[1693]1600 log_msg(1, "USB device mounted. Remounting it at the right place");
[1770]1601 asprintf(&tmp, "umount %s", tmp1);
[1693]1602 run_program_and_log_output(tmp, FALSE);
1603 paranoid_free(tmp);
1604 }
[1770]1605 paranoid_free(tmp);
1606
[1693]1607 log_msg(1, "Mounting USB device.");
1608 asprintf(&tmp1, "%s/usb", bkpinfo->tmpdir);
1609 asprintf(&tmp, "mkdir -p %s", tmp1);
1610 run_program_and_log_output(tmp, FALSE);
1611 paranoid_free(tmp);
1612 /* Mindi always create one single parition on the USB dev */
1613 asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, tmp1);
1614 run_program_and_log_output(tmp, FALSE);
1615 paranoid_free(tmp);
1616
1617 if (bkpinfo->nonbootable_backup) {
1618 log_msg(1, "Making nonbootable USB backup not implemented yet");
1619 } else {
1620 log_msg(1, "Making bootable backup");
1621
1622 /* Command to execute */
[1770]1623 asprintf(&tmp,"mv %s/* %s", bkpinfo->scratchdir, tmp1);
[1693]1624 res = eval_call_to_make_USB(tmp, message_to_screen);
1625 if (res) {
1626 asprintf(&result_sz, "%s ...failed",tmp);
1627 } else {
1628 asprintf(&result_sz, "%s ...OK",tmp);
1629 }
1630 log_to_screen(result_sz);
1631 paranoid_free(result_sz);
1632 paranoid_free(tmp);
1633 retval += res;
1634 }
1635 paranoid_free(message_to_screen);
1636 paranoid_free(tmp1);
1637
1638 if (is_this_device_mounted(bkpinfo->media_device)) {
1639 asprintf(&tmp, "umount %s1", bkpinfo->media_device);
1640 run_program_and_log_output(tmp, FALSE);
1641 paranoid_free(tmp);
1642 }
1643
1644 chdir(old_pwd);
1645 if (retval) {
1646 log_msg(1, "WARNING - make_usb_fs returned an error");
1647 }
1648 paranoid_free(old_pwd);
1649 return (retval);
1650}
1651
1652
1653/**
[1]1654 * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
1655 *
1656 * @param bkpinfo The backup information structure. Fields used:
1657 * - @c backup_media_type
1658 * - @c call_after_iso
1659 * - @c call_before_iso
1660 * - @c call_burn_iso
1661 * - @c call_make_iso
[1609]1662 * - @c manual_tray
[1]1663 * - @c nonbootable_backup
1664 * - @c scratchdir
1665 *
1666 * @param destfile Where to put the generated ISO image.
1667 * @return The number of errors encountered (0 for success)
1668 */
[1663]1669int make_iso_fs(char *destfile)
[1]1670{
[128]1671 /*@ int ********************************************** */
1672 int retval = 0;
1673 int res;
[1]1674
[128]1675 /*@ buffers ****************************************** */
[1138]1676 char *tmp = NULL;
[128]1677 char *old_pwd;
[1138]1678 char *message_to_screen = NULL;
1679 char *sz_blank_disk = NULL;
[1137]1680 char *tmp2 = NULL;
1681 char *tmp3 = NULL;
[1]1682
[128]1683 malloc_string(old_pwd);
1684 assert(bkpinfo != NULL);
1685 assert_string_is_neither_NULL_nor_zerolength(destfile);
[1]1686
[1138]1687 mr_asprintf(&tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
[1137]1688 mr_asprintf(&tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
[128]1689 if (does_file_exist(tmp)) {
[1137]1690 mr_asprintf(&tmp3, "cp -f %s %s", tmp, tmp2);
[128]1691 paranoid_system(tmp3);
[1137]1692 mr_free(tmp3);
[1]1693 }
[128]1694 if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
[1137]1695 mr_asprintf(&tmp3, "cp -f %s %s", tmp2, tmp);
[128]1696 paranoid_system(tmp3);
[1137]1697 mr_free(tmp3);
[1]1698 }
[1080]1699 mr_free(tmp2);
[1138]1700 mr_free(tmp);
1701
[1609]1702 if (bkpinfo->backup_media_type != iso && bkpinfo->manual_tray) {
[1136]1703 popup_and_OK(_("Please insert new media and press Enter."));
[128]1704 }
[1]1705
[1107]1706 mr_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
[128]1707 bkpinfo->scratchdir, destfile);
[1136]1708 /* BERLIOS: Do not ignore getcwd result */
[128]1709 (void) getcwd(old_pwd, MAX_STR_LEN - 1);
[1594]1710 chmod(bkpinfo->scratchdir,0755);
[128]1711 chdir(bkpinfo->scratchdir);
[1]1712
[128]1713 if (bkpinfo->call_before_iso[0] != '\0') {
[1138]1714 mr_asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
[128]1715 g_current_media_number);
[1663]1716 res = eval_call_to_make_ISO(bkpinfo->call_before_iso,
[1138]1717 destfile, g_current_media_number,
1718 MONDO_LOGFILE, message_to_screen);
[128]1719 if (res) {
[1138]1720 log_to_screen("%s...failed", message_to_screen);
[128]1721 } else {
[1138]1722 log_to_screen("%s...OK", message_to_screen);
[128]1723 }
[1138]1724 mr_free(message_to_screen);
[128]1725 retval += res;
[1]1726 }
1727
[128]1728 if (bkpinfo->call_make_iso[0] != '\0') {
[1107]1729 mr_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
[1138]1730 mr_asprintf(&message_to_screen, "Making an ISO (%s #%d)",
1731 bkpinfo->backup_media_string,
1732 g_current_media_number);
[1]1733
[1138]1734 /* if g_current_media_number >= 2 then pause & ask */
[1594]1735 if (bkpinfo->backup_media_type != iso) {
1736 pause_and_ask_for_cdr(2);
1737 }
[128]1738 if (retval) {
1739 log_to_screen
1740 ("Serious error(s) occurred already. I shan't try to write to media.");
1741 } else {
[1663]1742 res = eval_call_to_make_ISO(bkpinfo->call_make_iso,
[1594]1743 destfile, g_current_media_number,
[1138]1744 MONDO_LOGFILE, message_to_screen);
[128]1745 if (res) {
1746 log_to_screen("%s...failed to write", message_to_screen);
1747 } else {
1748 log_to_screen("%s...OK", message_to_screen);
[1592]1749 mr_asprintf(&tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
[1326]1750 if (!run_program_and_log_output(tmp, 1)) {
[128]1751 log_to_screen
1752 ("Despite nonfatal errors, growisofs confirms the write was successful.");
1753 }
[1592]1754 mr_free(tmp);
[128]1755 }
1756 retval += res;
[1]1757#ifdef DVDRWFORMAT
[1138]1758 mr_asprintf(&tmp,
1759 "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
1760 MONDO_LOGFILE);
[128]1761 if (g_backup_media_type == dvd
1762 && (res || !run_program_and_log_output(tmp, 1))) {
1763 log_to_screen
1764 ("Failed to write to disk. I shall blank it and then try again.");
1765 sleep(5);
[1136]1766 sync();
[128]1767 pause_for_N_seconds(5, "Letting DVD drive settle");
[1]1768
[1136]1769 // dvd+rw-format --- OPTION 2
[128]1770 if (!bkpinfo->please_dont_eject) {
1771 log_to_screen("Ejecting media to clear drive status.");
1772 eject_device(bkpinfo->media_device);
1773 inject_device(bkpinfo->media_device);
1774 }
1775 pause_for_N_seconds(5, "Letting DVD drive settle");
[1138]1776 mr_asprintf(&sz_blank_disk, "dvd+rw-format -force %s",
1777 bkpinfo->media_device);
[1107]1778 mr_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
[1138]1779 res = run_external_binary_with_percentage_indicator_NEW
[128]1780 ("Blanking DVD disk", sz_blank_disk);
1781 if (res) {
1782 log_to_screen
1783 ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
1784 pause_for_N_seconds(5,
1785 "Letting DVD drive settle... and trying again.");
[1138]1786 res = run_external_binary_with_percentage_indicator_NEW
[128]1787 ("Blanking DVD disk", sz_blank_disk);
1788 if (res) {
1789 log_to_screen("Format failed a second time.");
1790 }
1791 } else {
1792 log_to_screen
1793 ("Format succeeded. Sleeping for 5 seconds to take a breath...");
1794 }
[1138]1795 mr_free(sz_blank_disk);
[128]1796 pause_for_N_seconds(5, "Letting DVD drive settle");
1797 if (!bkpinfo->please_dont_eject) {
1798 log_to_screen("Ejecting media to clear drive status.");
1799 eject_device(bkpinfo->media_device);
1800 inject_device(bkpinfo->media_device);
1801 }
1802 pause_for_N_seconds(5, "Letting DVD drive settle");
1803 res =
[1663]1804 eval_call_to_make_ISO(bkpinfo->call_make_iso,
[1594]1805 destfile,
[128]1806 g_current_media_number,
1807 MONDO_LOGFILE,
1808 message_to_screen);
1809 retval += res;
1810 if (!bkpinfo->please_dont_eject) {
1811 log_to_screen("Ejecting media.");
1812 eject_device(bkpinfo->media_device);
1813 }
1814 if (res) {
1815 log_to_screen("Dagnabbit. It still failed.");
1816 } else {
1817 log_to_screen
1818 ("OK, this time I successfully backed up to DVD.");
1819 }
1820 }
[1138]1821 mr_free(tmp);
[128]1822#endif
1823 if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
1824 eject_device(bkpinfo->media_device);
1825 }
[1]1826 }
[1138]1827 mr_free(message_to_screen);
[128]1828 } else {
[1592]1829 fatal_error("call_make_iso undefined. Not normal in this case");
[1]1830 }
[128]1831
1832 if (bkpinfo->backup_media_type == cdr
1833 || bkpinfo->backup_media_type == cdrw) {
1834 if (is_this_device_mounted(bkpinfo->media_device)) {
[1107]1835 mr_msg(2,
[128]1836 "Warning - %s mounted. I'm unmounting it before I burn to it.",
1837 bkpinfo->media_device);
[1139]1838 mr_asprintf(&tmp, "umount %s", bkpinfo->media_device);
[128]1839 run_program_and_log_output(tmp, FALSE);
[1139]1840 mr_free(tmp);
[128]1841 }
[1]1842 }
1843
[1139]1844 if (bkpinfo->call_after_iso != NULL) {
1845 mr_asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
1846 bkpinfo->backup_media_string,
1847 g_current_media_number);
[1663]1848 res = eval_call_to_make_ISO(bkpinfo->call_after_iso,
[1139]1849 destfile, g_current_media_number,
1850 MONDO_LOGFILE, message_to_screen);
[128]1851 if (res) {
[1139]1852 log_to_screen("%s...failed", message_to_screen);
[128]1853 } else {
[1139]1854 log_to_screen("%s...OK", message_to_screen);
[128]1855 }
[1139]1856 mr_free(message_to_screen);
[128]1857 retval += res;
[1]1858 }
1859
[128]1860 chdir(old_pwd);
1861 if (retval) {
[1107]1862 mr_msg(1, "WARNING - make_iso_fs returned an error");
[1]1863 }
[1080]1864 mr_free(old_pwd);
[128]1865 return (retval);
[1]1866}
1867
1868
1869bool is_dev_an_NTFS_dev(char *bigfile_fname)
1870{
[128]1871 char *tmp;
1872 char *command;
1873 malloc_string(tmp);
[1137]1874 bool ret = TRUE;
1875 mr_asprintf(&command,
1876 "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
1877 bigfile_fname);
[1107]1878 mr_msg(1, "command = '%s'", command);
[128]1879 strcpy(tmp, call_program_and_get_last_line_of_output(command));
[1107]1880 mr_msg(1, "--> tmp = '%s'", tmp);
[1137]1881 mr_free(command);
[128]1882 if (strstr(tmp, "NTFS")) {
1883 iamhere("TRUE");
1884 } else {
1885 iamhere("FALSE");
[1137]1886 ret = FALSE;
[128]1887 }
[1137]1888 return(ret);
[1]1889}
1890
1891
1892/**
1893 * Back up big files by chopping them up.
1894 * This function backs up all "big" files (where "big" depends
1895 * on your backup media) in "chunks" (whose size again depends
1896 * on your media).
1897 *
1898 * @param bkpinfo The backup information structure. Fields used:
1899 * - @c backup_media_type
1900 * - @c optimal_set_size
1901 * @param biggielist_fname The path to a file containing a list of
1902 * all "big" files.
1903 * @return The number of errors encountered (0 for success)
1904 * @see slice_up_file_etc
1905 */
1906int
[1663]1907make_slices_and_images(char *biggielist_fname)
[1]1908{
1909
[128]1910 /*@ pointers ******************************************* */
[1142]1911 FILE *fin = NULL;
1912 char *p = NULL;
[1]1913
[128]1914 /*@ buffers ******************************************** */
[1142]1915 char *tmp = NULL;
[1139]1916 char *bigfile_fname = NULL;
[1142]1917 char *sz_devfile = NULL;
[296]1918 char *ntfsprog_fifo = NULL;
[128]1919 /*@ long *********************************************** */
1920 long biggie_file_number = 0;
1921 long noof_biggie_files = 0;
1922 long estimated_total_noof_slices = 0;
[1]1923
[128]1924 /*@ int ************************************************ */
1925 int retval = 0;
1926 int res = 0;
[1139]1927 size_t n = 0;
[128]1928 pid_t pid;
1929 FILE *ftmp = NULL;
1930 bool delete_when_done;
[296]1931 bool use_ntfsprog;
[684]1932 off_t biggie_fsize;
[1]1933
[128]1934 assert(bkpinfo != NULL);
1935 assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
[1]1936
[128]1937 estimated_total_noof_slices =
[1663]1938 size_of_all_biggiefiles_K() / bkpinfo->optimal_set_size + 1;
[1]1939
[1107]1940 mr_msg(1, "size of all biggiefiles = %ld",
[1663]1941 size_of_all_biggiefiles_K());
[1107]1942 mr_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
[1663]1943 size_of_all_biggiefiles_K(), bkpinfo->optimal_set_size,
[128]1944 estimated_total_noof_slices);
[1]1945
[128]1946 if (length_of_file(biggielist_fname) < 6) {
[1107]1947 mr_msg(1, "No biggiefiles; fair enough...");
[128]1948 return (0);
[1]1949 }
[1142]1950 mr_asprintf(&tmp, "I am now backing up all large files.");
[128]1951 log_to_screen(tmp);
1952 noof_biggie_files = count_lines_in_file(biggielist_fname);
1953 open_progress_form("Backing up big files", tmp,
1954 "Please wait. This may take some time.", "",
1955 estimated_total_noof_slices);
[1142]1956 mr_free(tmp);
1957
[128]1958 if (!(fin = fopen(biggielist_fname, "r"))) {
1959 log_OS_error("Unable to openin biggielist");
1960 return (1);
[1]1961 }
[1142]1962 for (mr_getline(&bigfile_fname, &n, fin); !feof(fin);
1963 mr_getline(&bigfile_fname, &n, fin), biggie_file_number++) {
[296]1964 use_ntfsprog = FALSE;
[128]1965 if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
1966 bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
1967 }
1968 biggie_fsize = length_of_file(bigfile_fname);
1969 delete_when_done = FALSE;
1970
1971 if (!does_file_exist(bigfile_fname)) {
1972 ftmp = fopen(bigfile_fname, "w");
[1302]1973 if (ftmp == NULL) {
1974 mr_msg(3, "Unable to write to %s", bigfile_fname);
1975 // So skip it as it doesn't exist
1976 continue;
1977 } else {
1978 paranoid_fclose(ftmp);
1979 }
[128]1980 delete_when_done = TRUE;
1981 } else {
[812]1982 // Call ntfsclone (formerly partimagehack) if it's a /dev entry
1983 // (i.e. a partition to be imaged)
[1107]1984 mr_msg(2, "bigfile_fname = %s", bigfile_fname);
[296]1985 use_ntfsprog = FALSE;
[128]1986 if (!strncmp(bigfile_fname, "/dev/", 5)
1987 && is_dev_an_NTFS_dev(bigfile_fname)) {
[296]1988 use_ntfsprog = TRUE;
[1107]1989 mr_msg(2,
[296]1990 "Calling ntfsclone in background because %s is an NTFS partition",
[128]1991 bigfile_fname);
[1142]1992 mr_asprintf(&sz_devfile, "%s/%d.%d.000",
[812]1993 bkpinfo->tmpdir,
[128]1994 (int) (random() % 32768),
1995 (int) (random() % 32768));
1996 mkfifo(sz_devfile, 0x770);
[296]1997 ntfsprog_fifo = sz_devfile;
[128]1998 switch (pid = fork()) {
1999 case -1:
2000 fatal_error("Fork failure");
2001 case 0:
[1107]2002 mr_msg(2,
[296]2003 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
[128]2004 bigfile_fname, sz_devfile);
[296]2005 res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
[1142]2006 mr_free(sz_devfile);
[128]2007 exit(res);
2008 break;
2009 default:
[1107]2010 mr_msg(2,
[296]2011 "feed_into_ntfsprog() called in background --- pid=%ld",
[128]2012 (long int) (pid));
[1142]2013 mr_free(sz_devfile);
2014 break;
[128]2015 }
2016 }
[1142]2017 // Otherwise, use good old 'dd' and 'bzip2'
[128]2018 else {
[296]2019 ntfsprog_fifo = NULL;
[128]2020 }
[1]2021
[1142]2022 // Whether partition or biggiefile, just do your thang :-)
2023 mr_msg(5, "Bigfile #%ld is '%s' (%ld KB)",
[128]2024 biggie_file_number + 1, bigfile_fname,
2025 (long) biggie_fsize >> 10);
2026 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2027 write_header_block_to_stream(biggie_fsize, bigfile_fname,
[296]2028 use_ntfsprog ?
[128]2029 BLK_START_A_PIHBIGGIE :
2030 BLK_START_A_NORMBIGGIE);
2031 }
2032 res =
[1663]2033 slice_up_file_etc(bigfile_fname,
[296]2034 ntfsprog_fifo, biggie_file_number,
2035 noof_biggie_files, use_ntfsprog);
[128]2036 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[684]2037 write_header_block_to_stream((off_t)0,
[128]2038 calc_checksum_of_file
2039 (bigfile_fname),
2040 BLK_STOP_A_BIGGIE);
2041 }
2042 retval += res;
2043 p = strrchr(bigfile_fname, '/');
2044 if (p) {
2045 p++;
2046 } else {
2047 p = bigfile_fname;
2048 }
2049 if (res) {
[1142]2050 mr_asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
[128]2051 } else {
[1142]2052 mr_asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname);
[128]2053 }
[1142]2054 mr_msg(4,tmp);
2055 mr_free(tmp);
[128]2056 if (delete_when_done) {
2057 unlink(bigfile_fname);
2058 delete_when_done = FALSE;
2059 }
2060 }
2061 if (!g_text_mode) {
2062 newtDrawRootText(0, g_noof_rows - 2, tmp);
2063 newtRefresh();
2064 }
2065 }
[1142]2066 mr_free(bigfile_fname);
2067 paranoid_fclose(fin);
2068
[1107]2069 mr_msg(1, "Finished backing up bigfiles");
2070 mr_msg(1, "estimated slices = %ld; actual slices = %ld",
[128]2071 estimated_total_noof_slices, g_current_progress);
2072 close_progress_form();
2073 return (retval);
[1]2074}
2075
2076
2077/**
2078 * Single-threaded version of @c make_afioballs_and_images().
2079 * @see make_afioballs_and_images
2080 */
[1663]2081int make_afioballs_and_images_OLD()
[1]2082{
2083
[128]2084 /*@ int ************************************************** */
2085 int retval = 0;
2086 long int curr_set_no = 0;
2087 int res = 0;
[1]2088
[128]2089 /*@ buffers ********************************************** */
[1142]2090 char *curr_filelist_fname = NULL;
2091 char *curr_afioball_fname = NULL;
2092 char *curr_xattr_list_fname = NULL;
2093 char *curr_acl_list_fname = NULL;
2094 char *media_usage_comment = NULL;
2095 char *tmp= mr_malloc(MAX_STR_LEN * 2);
[1]2096
[1142]2097 /* BERLIOS: Useless ?
2098 mr_asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
2099 */
[128]2100 malloc_string(media_usage_comment);
2101 log_to_screen("Archiving regular files");
[1]2102
[1142]2103 open_progress_form(_("Backing up filesystem"),
2104 _("I am backing up your live filesystem now."),
2105 _("Please wait. This may take a couple of hours."),
2106 _("Working..."),
[1663]2107 get_last_filelist_number() + 1);
[128]2108
[1142]2109 mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
2110 0L);
[128]2111
[1142]2112 curr_set_no = 0;
2113 while (does_file_exist(curr_filelist_fname)) {
[128]2114 /* backup this set of files */
[1142]2115 mr_asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
[1769]2116 bkpinfo->tmpdir, curr_set_no, bkpinfo->compression_suffix);
[128]2117
[1107]2118 mr_msg(1, "EXAT'g set %ld", curr_set_no);
[948]2119 if (g_getfattr) {
[1142]2120 mr_asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
[128]2121 bkpinfo->tmpdir, curr_set_no);
[948]2122 get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
2123 }
2124 if (g_getfacl) {
[1142]2125 mr_asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
[128]2126 bkpinfo->tmpdir, curr_set_no);
[948]2127 get_acl_list(curr_filelist_fname, curr_acl_list_fname);
2128 }
[128]2129
[1107]2130 mr_msg(1, "Archiving set %ld", curr_set_no);
[1663]2131 res = archive_this_fileset(curr_filelist_fname,
[128]2132 curr_afioball_fname, curr_set_no);
2133 retval += res;
2134 if (res) {
[1142]2135 mr_asprintf(&tmp,
2136 "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
2137 curr_set_no);
[128]2138 log_to_screen(tmp);
[1142]2139 mr_free(tmp);
[128]2140 }
2141
[1663]2142 strcpy(media_usage_comment, percent_media_full_comment());
[128]2143
2144 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
2145 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2146 register_in_tape_catalog(fileset, curr_set_no, -1,
2147 curr_afioball_fname);
2148 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
2149 curr_afioball_fname);
2150 iamhere("Writing EXAT files");
[1939]2151 res +=
2152 write_EXAT_files_to_tape(curr_xattr_list_fname,
2153 curr_acl_list_fname);
[1142]2154 // archives themselves
[1663]2155 res = move_files_to_stream(curr_afioball_fname, NULL);
[128]2156 } else {
[948]2157 if (g_getfacl) {
2158 if (g_getfattr) {
[1663]2159 res = move_files_to_cd(curr_filelist_fname,
[948]2160 curr_xattr_list_fname,
2161 curr_acl_list_fname,
2162 curr_afioball_fname, NULL);
2163 } else {
[1663]2164 res = move_files_to_cd(curr_filelist_fname,
[948]2165 curr_acl_list_fname,
2166 curr_afioball_fname, NULL);
2167 }
2168 } else {
2169 if (g_getfattr) {
[1663]2170 res = move_files_to_cd(curr_filelist_fname,
[948]2171 curr_xattr_list_fname,
2172 curr_afioball_fname, NULL);
2173 } else {
[1663]2174 res = move_files_to_cd(curr_filelist_fname,
[948]2175 curr_afioball_fname, NULL);
2176 }
2177 }
[128]2178 }
2179 retval += res;
2180 g_current_progress++;
2181 update_progress_form(media_usage_comment);
[1]2182
[128]2183 if (res) {
[1142]2184 mr_asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
2185 curr_set_no);
[128]2186 log_to_screen(tmp);
[1142]2187 mr_free(tmp);
[128]2188 fatal_error
2189 ("Is your hard disk is full? If not, please send the author the logfile.");
2190 }
[1142]2191 mr_free(curr_filelist_fname);
2192 mr_free(curr_afioball_fname);
2193 mr_free(curr_xattr_list_fname);
2194 mr_free(curr_acl_list_fname);
2195 mr_asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
2196 bkpinfo->tmpdir, ++curr_set_no);
[1]2197 }
[1142]2198 mr_free(curr_filelist_fname);
[128]2199 close_progress_form();
2200 if (retval) {
[1142]2201 log_to_screen
2202 ("Your regular files have been archived (with errors).");
[128]2203 } else {
[1142]2204 log_to_screen
2205 ("Your regular files have been archived successfully.");
[128]2206 }
[1080]2207 mr_free(media_usage_comment);
[128]2208 return (retval);
[1]2209}
2210
[128]2211/* @} - end of LLarchiveGroup */
2212
2213
[1]2214/**
2215 * Wrapper around @c make_afioballs_and_images().
2216 * @param bkpinfo the backup information structure. Only the
2217 * @c backup_media_type field is used within this function.
2218 * @return return code of make_afioballs_and_images
2219 * @see make_afioballs_and_images
2220 * @ingroup MLarchiveGroup
2221 */
[1663]2222int make_those_afios_phase()
[1]2223{
[128]2224 /*@ int ******************************************* */
2225 int res = 0;
2226 int retval = 0;
[1]2227
[128]2228 assert(bkpinfo != NULL);
[1]2229
[128]2230 mvaddstr_and_log_it(g_currentY, 0,
2231 "Archiving regular files to media ");
[1]2232
[128]2233 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[684]2234 write_header_block_to_stream((off_t)0, "start-of-afioballs",
[128]2235 BLK_START_AFIOBALLS);
[1]2236#if __FreeBSD__ == 5
[1107]2237 mr_msg(1,
[128]2238 "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
[1663]2239 res = make_afioballs_and_images_OLD();
[1]2240#else
[1663]2241 res = make_afioballs_and_images_OLD();
[1]2242#endif
[684]2243 write_header_block_to_stream((off_t)0, "stop-afioballs",
[128]2244 BLK_STOP_AFIOBALLS);
2245 } else {
[1663]2246 res = make_afioballs_and_images();
[128]2247 }
[1]2248
[128]2249 retval += res;
2250 if (res) {
2251 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
[1107]2252 mr_msg(1, "make_afioballs_and_images returned an error");
[128]2253 } else {
2254 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2255 }
2256 return (retval);
[1]2257}
2258
2259/**
2260 * Wrapper around @c make_slices_and_images().
2261 * @param bkpinfo The backup information structure. Fields used:
2262 * - @c backup_media_type
2263 * - @c scratchdir
2264 * - @c tmpdir
2265 * @return The number of errors encountered (0 for success)
2266 * @ingroup MLarchiveGroup
2267 */
[1663]2268int make_those_slices_phase()
[1]2269{
2270
[128]2271 /*@ int ***************************************************** */
2272 int res = 0;
2273 int retval = 0;
[1]2274
[128]2275 /*@ buffers ************************************************** */
[1143]2276 char *biggielist = NULL;
2277 char *command = NULL;
2278 char *blah = NULL;
2279 char *xattr_fname = NULL;
[1146]2280 char *acl_fname = NULL;
[1]2281
[128]2282 assert(bkpinfo != NULL);
2283 /* slice big files */
2284 mvaddstr_and_log_it(g_currentY, 0,
2285 "Archiving large files to media ");
[1154]2286 mr_asprintf(&biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
[948]2287 if (g_getfattr) {
[1154]2288 mr_asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
[948]2289 }
2290 if (g_getfacl) {
[1154]2291 mr_asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
[948]2292 }
[1]2293
[1154]2294 mr_asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir, biggielist);
[128]2295 paranoid_system(command);
[1147]2296 mr_free(command);
2297
2298 mr_asprintf(&blah, "biggielist = %s", biggielist);
[1107]2299 mr_msg(2, blah);
[1147]2300 mr_free(blah);
[128]2301
2302 if (!does_file_exist(biggielist)) {
[1107]2303 mr_msg(1, "BTW, the biggielist does not exist");
[128]2304 }
2305
[948]2306 if (g_getfattr) {
2307 get_fattr_list(biggielist, xattr_fname);
[1154]2308 mr_asprintf(&command, "cp %s %s/archives/", xattr_fname, bkpinfo->scratchdir);
[948]2309 paranoid_system(command);
[1147]2310 mr_free(command);
[948]2311 }
2312 if (g_getfacl) {
2313 get_acl_list(biggielist, acl_fname);
[1154]2314 mr_asprintf(&command, "cp %s %s/archives/", acl_fname, bkpinfo->scratchdir);
[948]2315 paranoid_system(command);
[1147]2316 mr_free(command);
[948]2317 }
[128]2318
2319 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[1663]2320 res += write_EXAT_files_to_tape(xattr_fname, acl_fname);
[1147]2321 mr_asprintf(&blah, "%ld", count_lines_in_file(biggielist));
[684]2322 write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
[1147]2323 mr_free(blah);
[128]2324 }
[1154]2325 if (g_getfattr) {
2326 mr_free(xattr_fname);
2327 }
2328 if (g_getfacl) {
2329 mr_free(acl_fname);
2330 }
2331
[1663]2332 res = make_slices_and_images(biggielist);
[1154]2333 mr_free(biggielist);
2334
[128]2335 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
[684]2336 write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
[128]2337 BLK_STOP_BIGGIEFILES);
2338 }
2339 retval += res;
2340 if (res) {
[1107]2341 mr_msg(1, "make_slices_and_images returned an error");
[128]2342 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2343 } else {
2344 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2345 }
2346 return (retval);
[1]2347}
2348
2349
2350/**
2351 * @addtogroup LLarchiveGroup
2352 * @{
2353 */
2354/**
2355 * Function pointer to an appropriate @c move_files_to_cd routine.
2356 * You can set this to your own function (for example, one to
2357 * transfer files over the network) or leave it as is.
2358 */
[1663]2359int (*move_files_to_cd) (char *, ...) =
[128]2360 _move_files_to_cd;
[1]2361
2362/**
2363 * Move some files to the ISO scratch directory.
2364 * This function moves files specified as parameters, into the directory
2365 * @c bkpinfo->scratchdir, where the files that will be stored on the next
2366 * CD are waiting.
2367 *
2368 * @param bkpinfo The backup information structure. Fields used:
2369 * - @c media_size
2370 * - @c scratchdir
2371 * @param files_to_add The files to add to the scratchdir.
2372 * @warning The list of @c files_to_add must be terminated with @c NULL.
2373 * @note If and when the space occupied by the scratchdir would exceed
2374 * the capacity of the current CD,
2375 * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
2376 * scratchdir is emptied.
2377 *
2378 * @return The number of errors encountered (0 for success)
2379 */
[1663]2380int _move_files_to_cd(char *files_to_add, ...)
[1]2381{
2382
[128]2383 /*@ int ************************************************************ */
2384 int retval = 0;
[1]2385 int res = 0;
2386
[128]2387 /*@ buffers ******************************************************** */
[1154]2388 char *tmp = NULL;
2389 char *curr_file = NULL;
2390 char *cf = NULL;
[1]2391
[128]2392 /*@ long ************************************************************ */
2393 va_list ap;
2394 long long would_occupy;
[1]2395
[128]2396 assert(bkpinfo != NULL);
2397 would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
2398 va_start(ap, files_to_add); // initialize the variable arguments
2399 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2400 if (!cf) {
2401 continue;
2402 }
[1154]2403 mr_asprintf(&curr_file, cf);
[128]2404 if (!does_file_exist(curr_file)) {
[1107]2405 mr_msg(1,
[128]2406 "Warning - you're trying to add a non-existent file - '%s' to the CD",
2407 curr_file);
2408 } else {
[1107]2409 mr_msg(8, "Trying to add file %s to CD", curr_file);
[128]2410 would_occupy += length_of_file(curr_file) / 1024;
2411 }
[1154]2412 mr_free(curr_file);
[1]2413 }
[128]2414 va_end(ap);
[1]2415
[1365]2416 if (bkpinfo->media_size <= 0L) {
[128]2417 fatal_error("move_files_to_cd() - unknown media size");
[1]2418 }
[1365]2419 if (would_occupy / 1024 > bkpinfo->media_size) {
[1154]2420 /* FALSE because this is not the last CD we'll write */
[1663]2421 res = write_iso_and_go_on(FALSE);
[128]2422 retval += res;
2423 if (res) {
[1107]2424 mr_msg(1, "WARNING - write_iso_and_go_on returned an error");
[128]2425 }
2426 }
[1]2427
[128]2428 va_start(ap, files_to_add); // initialize the variable arguments
2429 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2430 if (!cf) {
2431 continue;
2432 }
[1154]2433 mr_asprintf(&curr_file, cf);
[1]2434
[1154]2435 mr_asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
2436 bkpinfo->scratchdir);
[128]2437 res = run_program_and_log_output(tmp, 5);
2438 retval += res;
2439 if (res) {
[1107]2440 mr_msg(1, "(move_files_to_cd) '%s' failed", tmp);
[128]2441 } else {
[1107]2442 mr_msg(8, "Moved %s to CD OK", tmp);
[128]2443 }
[1154]2444 mr_free(tmp);
2445 mr_free(curr_file);
[128]2446 // unlink (curr_file);
[1]2447 }
[128]2448 va_end(ap);
2449
2450 if (retval) {
[1107]2451 mr_msg(1,
[128]2452 "Warning - errors occurred while I was adding files to CD dir");
[1]2453 }
[128]2454 return (retval);
[1]2455}
2456
2457/* @} - end of LLarchiveGroup */
2458
2459
2460/**
2461 * @addtogroup LLarchiveGroup
2462 * @{
2463 */
2464/**
2465 * Function pointer to an appropriate @c move_files_to_stream routine.
2466 * You can set this to your own function (for example, one to
2467 * transfer files over the network) or leave it as is.
2468 */
[1663]2469int (*move_files_to_stream) (char *, ...) =
[128]2470 _move_files_to_stream;
[1]2471
2472/**
2473 * Copy some files to tape.
2474 * This function copies the files specified as parameters into the tape stream.
2475 *
2476 * @param bkpinfo The backup information structure. Used only in the call to
2477 * @c write_file_to_stream_from_file().
2478 *
2479 * @param files_to_add The files to copy to the tape stream.
2480 * @warning The list of @c files_to_add must be terminated with @c NULL.
2481 * @note Files may be split across multiple tapes if necessary.
2482 *
2483 * @return The number of errors encountered (0 for success)
2484 */
2485int
[1663]2486_move_files_to_stream(char *files_to_add, ...)
[1]2487{
2488
[128]2489 /*@ int ************************************************************ */
2490 int retval = 0;
[1]2491 int res = 0;
[128]2492 /*@ buffers ******************************************************** */
[1]2493
[128]2494 /*@ char *********************************************************** */
[1]2495 char start_chr;
2496 char stop_chr;
[1154]2497 char *curr_file = NULL;
2498 char *cf = NULL;
[128]2499 /*@ long long ****************************************************** */
[684]2500 off_t length_of_incoming_file = (off_t)0;
[128]2501 t_archtype type;
2502 va_list ap;
[1]2503
[128]2504 assert(bkpinfo != NULL);
2505 va_start(ap, files_to_add);
2506 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2507 if (!cf) {
2508 continue;
2509 }
[1154]2510 mr_asprintf(&curr_file, cf);
[128]2511 if (!does_file_exist(curr_file)) {
[1107]2512 mr_msg(1,
[128]2513 "Warning - you're trying to add a non-existent file - '%s' to the tape",
2514 curr_file);
2515 }
[1154]2516 /* create header chars */
[128]2517 start_chr = BLK_START_AN_AFIO_OR_SLICE;
2518 stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
[1154]2519 /* ask for new tape if necessary */
[128]2520 length_of_incoming_file = length_of_file(curr_file);
2521 write_header_block_to_stream(length_of_incoming_file, curr_file,
2522 start_chr);
2523 if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
2524 type = fileset;
2525 } else if (strstr(curr_file, "slice")) {
2526 type = biggieslice;
2527 } else {
2528 type = other;
2529 }
[1663]2530 res = write_file_to_stream_from_file(curr_file);
[128]2531 retval += res;
2532 unlink(curr_file);
[1154]2533 mr_free(curr_file);
2534 /* write closing header */
[684]2535 write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
[128]2536 }
2537 va_end(ap);
[1]2538
[128]2539 if (retval) {
[1107]2540 mr_msg(1,
[128]2541 "Warning - errors occurred while I was adding file to tape");
2542 }
2543 return (retval);
[1]2544}
2545
2546/* @} - end of LLarchiveGroup */
2547
2548
2549/**
2550 * @addtogroup utilityGroup
2551 * @{
2552 */
2553/**
2554 * Make sure the user has a valid CD-R(W) in the CD drive.
2555 * @param cdrw_dev Set to the CD-R(W) device checked.
2556 * @param keep_looping If TRUE, keep pestering user until they insist
2557 * or insert a correct CD; if FALSE, only check once.
2558 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
2559 */
[128]2560int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
2561 bool keep_looping)
[1]2562{
[128]2563 int res = 0;
[1594]2564 char *bkp = NULL;
2565 char *cdrecord = NULL;
[1]2566
[128]2567 malloc_string(bkp);
2568 strcpy(bkp, cdrw_dev);
2569 if (find_cdrw_device(cdrw_dev)) {
2570 strcpy(cdrw_dev, bkp);
2571 } else {
2572 if (!system("which cdrecord > /dev/null 2> /dev/null")) {
[1594]2573 mr_asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
[128]2574 } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
[1594]2575 mr_asprintf(&cdrecord, "dvdrecord dev=%s -atip", cdrw_dev);
[128]2576 } else {
[1107]2577 mr_msg(2, "Oh well. I guess I'll just pray then.");
[128]2578 }
[1594]2579 if (cdrecord != NULL) {
[128]2580 if (!keep_looping) {
2581 retract_CD_tray_and_defeat_autorun();
2582 res = run_program_and_log_output(cdrecord, 5);
2583 } else {
2584 while ((res = run_program_and_log_output(cdrecord, 5))) {
2585 retract_CD_tray_and_defeat_autorun();
2586 if (ask_me_yes_or_no
2587 ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
2588 {
[1107]2589 mr_msg(1, "Well, he insisted...");
[128]2590 break;
2591 }
2592 }
2593 }
2594 }
[1594]2595 mr_free(cdrecord);
[128]2596 }
[1]2597// retract_CD_tray_and_defeat_autorun();
[1080]2598 mr_free(bkp);
[128]2599 return (res);
[1]2600}
2601
2602
2603/**
2604 * Asks the user to put a CD-R(W) in the drive.
2605 * @param ask_for_one_if_more_than_this (unused)
2606 */
2607void
[1594]2608pause_and_ask_for_cdr(int ask_for_one_if_more_than_this)
[1]2609{
2610
[128]2611 /*@ buffers ********************************************* */
[1154]2612 char *tmp = NULL;
2613 char *szmsg = NULL;
2614 char *cdrom_dev = NULL;
2615 char *cdrw_dev = NULL;
2616 char *our_serial_str = NULL;
[128]2617 bool ok_go_ahead_burn_it;
2618 int cd_number = -1;
2619 int attempt_to_mount_returned_this = 999;
[1154]2620 char *mtpt = NULL;
2621 char *szcdno = NULL;
2622 char *szserfname = NULL;
2623 char *szunmount = NULL;
[1]2624
[128]2625 malloc_string(szmsg);
2626 malloc_string(cdrom_dev);
2627 malloc_string(cdrw_dev);
2628 malloc_string(mtpt);
2629 malloc_string(szcdno);
2630 malloc_string(szserfname);
2631 malloc_string(our_serial_str);
2632 malloc_string(szunmount);
[1]2633
[128]2634 sprintf(szmsg, "I am about to burn %s #%d",
2635 media_descriptor_string(g_backup_media_type),
2636 g_current_media_number);
2637 log_to_screen(szmsg);
2638 if (g_current_media_number < ask_for_one_if_more_than_this) {
2639 return;
2640 }
2641 log_to_screen("Scanning CD-ROM drive...");
[1663]2642 sprintf(mtpt, "%s/cd.mtpt", bkpinfo->tmpdir);
[128]2643 make_hole_for_dir(mtpt);
[1]2644
[128]2645 gotos_make_me_puke:
2646 ok_go_ahead_burn_it = TRUE;
2647 if (!find_cdrom_device(cdrom_dev, FALSE)) {
[1]2648/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
[1107]2649 mr_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
[1]2650 retract_CD_tray_and_defeat_autorun();
2651*/
[1594]2652 mr_asprintf(&tmp, "umount %s", cdrom_dev);
[128]2653 run_program_and_log_output(tmp, 1);
[1594]2654 mr_free(tmp);
[128]2655 sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
2656 sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
2657 sprintf(szunmount, "umount %s", mtpt);
2658 cd_number = -1;
2659 our_serial_str[0] = '\0';
[1594]2660 mr_asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt);
2661 attempt_to_mount_returned_this = run_program_and_log_output(tmp, 1);
2662 mr_free(tmp);
2663 if (attempt_to_mount_returned_this) {
[1107]2664 mr_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
[128]2665 log_to_screen("If there's a CD/DVD in the drive, it's blank.");
2666 } else if (!does_file_exist(szcdno)
2667 || !does_file_exist(szserfname)) {
2668 log_to_screen
2669 ("%s has data on it but it's probably not a Mondo CD.",
2670 media_descriptor_string(g_backup_media_type));
2671 } else {
2672 log_to_screen("%s found in drive. It's a Mondo disk.",
2673 media_descriptor_string(g_backup_media_type));
2674 cd_number = atoi(last_line_of_file(szcdno));
[1594]2675 mr_asprintf(&tmp, "cat %s 2> /dev/null", szserfname);
[128]2676 strcpy(our_serial_str,
2677 call_program_and_get_last_line_of_output(tmp));
[1594]2678 mr_free(tmp);
[128]2679 // FIXME - should be able to use last_line_of_file(), surely?
2680 }
2681 run_program_and_log_output(szunmount, 1);
[1107]2682 mr_msg(2, "paafcd: cd_number = %d", cd_number);
2683 mr_msg(2, "our serial str = %s; g_serial_string = %s",
[128]2684 our_serial_str, g_serial_string);
2685 if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
[1107]2686 mr_msg(2, "This %s is part of this backup set!",
[128]2687 media_descriptor_string(g_backup_media_type));
2688 ok_go_ahead_burn_it = FALSE;
2689 if (cd_number == g_current_media_number - 1) {
2690 log_to_screen
2691 ("I think you've left the previous %s in the drive.",
2692 media_descriptor_string(g_backup_media_type));
2693 } else {
2694 log_to_screen
2695 ("Please remove this %s. It is part of the backup set you're making now.",
2696 media_descriptor_string(g_backup_media_type));
2697 }
2698 } else {
2699 log_to_screen("...but not part of _our_ backup set.");
2700 }
2701 } else {
[1107]2702 mr_msg(2,
[128]2703 "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
2704 media_descriptor_string(g_backup_media_type));
2705 if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
2706 ok_go_ahead_burn_it = FALSE;
2707 log_to_screen("There isn't a writable %s in the drive.",
2708 media_descriptor_string(g_backup_media_type));
2709 }
[1]2710 }
2711
[128]2712 if (!ok_go_ahead_burn_it) {
2713 eject_device(cdrom_dev);
[1594]2714 mr_asprintf(&tmp,
[128]2715 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
2716 media_descriptor_string(g_backup_media_type),
2717 g_current_media_number,
2718 media_descriptor_string(g_backup_media_type));
2719 popup_and_OK(tmp);
[1594]2720 mr_free(tmp);
[128]2721 goto gotos_make_me_puke;
2722 } else {
[1107]2723 mr_msg(2, "paafcd: OK, going ahead and burning it.");
[128]2724 }
[1]2725
[1107]2726 mr_msg(2,
[128]2727 "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
2728 media_descriptor_string(g_backup_media_type));
[1]2729
[128]2730 // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
[1]2731
[128]2732 log_to_screen("Proceeding w/ %s in drive.",
2733 media_descriptor_string(g_backup_media_type));
[1080]2734 mr_free(szmsg);
2735 mr_free(cdrom_dev);
2736 mr_free(cdrw_dev);
2737 mr_free(mtpt);
2738 mr_free(szcdno);
2739 mr_free(szserfname);
2740 mr_free(our_serial_str);
2741 mr_free(szunmount);
[1]2742}
2743
2744
2745/**
2746 * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
2747 * @param array The bit array (as a @c char pointer).
2748 * @param N The bit number to set or reset.
2749 * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
2750 * @see get_bit_N_of_array
2751 */
[128]2752void set_bit_N_of_array(char *array, int N, bool true_or_false)
[1]2753{
[128]2754 int bit_number;
2755 int mask, orig_val, to_add;
2756 int element_number;
[1]2757
[128]2758 assert(array != NULL);
[1]2759
[128]2760 element_number = N / 8;
2761 bit_number = N % 8;
2762 to_add = (1 << bit_number);
2763 mask = 255 - to_add;
2764 orig_val = array[element_number] & mask;
2765 // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
2766 if (true_or_false) {
2767 array[element_number] = orig_val | to_add;
2768 }
[1]2769}
2770
2771/* @} - end of utilityGroup */
2772
2773
2774/**
2775 * Chop up @c filename.
2776 * @param bkpinfo The backup information structure. Fields used:
2777 * - @c backup_media_type
2778 * - @c compression_level
2779 * - @c optimal_set_size
2780 * - @c tmpdir
2781 * - @c use_lzo
[1769]2782 * - @c compression_tool
2783 * - @c compression_suffix
[1]2784 *
2785 * @param biggie_filename The file to chop up.
[296]2786 * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
[1]2787 * @param biggie_file_number The sequence number of this biggie file (starting from 0).
2788 * @param noof_biggie_files The number of biggie files there are total.
2789 * @return The number of errors encountered (0 for success)
2790 * @see make_slices_and_images
2791 * @ingroup LLarchiveGroup
2792 */
2793int
[1663]2794slice_up_file_etc(char *biggie_filename,
[296]2795 char *ntfsprog_fifo, long biggie_file_number,
2796 long noof_biggie_files, bool use_ntfsprog)
[1]2797{
2798
[128]2799 /*@ buffers ************************************************** */
[1154]2800 char *tmp = NULL;
2801 char *checksum_line = NULL;
2802 char *command = NULL;
2803 char *tempblock = NULL;
2804 char *curr_slice_fname_uncompressed = NULL;
2805 char *curr_slice_fname_compressed = NULL;
2806 char *file_to_archive = NULL;
2807 char *file_to_openin = NULL;
[128]2808 /*@ pointers ************************************************** */
[1154]2809 char *pB = NULL;
2810 FILE *fin = NULL;
2811 FILE *fout = NULL;
[1]2812
[128]2813 /*@ bool ****************************************************** */
2814 bool finished = FALSE;
[1]2815
[128]2816 /*@ long ****************************************************** */
2817 size_t blksize = 0;
2818 long slice_num = 0;
2819 long i;
2820 long optimal_set_size;
2821 bool should_I_compress_slices;
[1154]2822 char *suffix = NULL; // for compressed slices
[1]2823
[128]2824 /*@ long long ************************************************** */
[684]2825 off_t totalread = (off_t)0;
2826 off_t totallength = (off_t)0;
2827 off_t length;
[1]2828
[128]2829 /*@ int ******************************************************** */
2830 int retval = 0;
2831 int res = 0;
[1154]2832 size_t n = 0;
[1]2833
[128]2834 /*@ structures ************************************************** */
2835 struct s_filename_and_lstat_info biggiestruct;
[1]2836// struct stat statbuf;
2837
[128]2838 assert(bkpinfo != NULL);
2839 assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
[1]2840
[128]2841 biggiestruct.for_backward_compatibility = '\n';
[296]2842 biggiestruct.use_ntfsprog = use_ntfsprog;
[128]2843 optimal_set_size = bkpinfo->optimal_set_size;
[1]2844
[128]2845 if (optimal_set_size < 999) {
2846 fatal_error("bkpinfo->optimal_set_size is insanely small");
2847 }
[296]2848 if (ntfsprog_fifo) {
2849 file_to_openin = ntfsprog_fifo;
[1155]2850 mr_asprintf(&checksum_line, "IGNORE");
[1107]2851 mr_msg(2,
[128]2852 "Not calculating checksum for %s: it would take too long",
2853 biggie_filename);
[296]2854 if ( !find_home_of_exe("ntfsresize")) {
2855 fatal_error("ntfsresize not found");
2856 }
[1155]2857 mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
[296]2858 log_it("command = %s", command);
[1155]2859 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
2860 mr_free(command);
2861
[296]2862 log_it("res of it = %s", tmp);
[684]2863 totallength = (off_t)atoll(tmp);
[1155]2864 mr_free(tmp);
[128]2865 } else {
2866 file_to_openin = biggie_filename;
[693]2867 if (strchr(biggie_filename,'\'') != NULL) {
[1155]2868 mr_asprintf(&command, "md5sum \"%s\"", biggie_filename);
[693]2869 } else {
[1155]2870 mr_asprintf(&command, "md5sum '%s'", biggie_filename);
[693]2871 }
[128]2872 if (!(fin = popen(command, "r"))) {
2873 log_OS_error("Unable to popen-in command");
[1155]2874 mr_free(command);
[128]2875 return (1);
2876 }
[1155]2877 mr_free(command);
2878 mr_getline(&checksum_line, &n, fin);
[128]2879 pclose(fin);
[167]2880 totallength = length_of_file (biggie_filename);
[128]2881 }
2882 lstat(biggie_filename, &biggiestruct.properties);
[1155]2883 if (strlen(biggie_filename) <= MAX_STR_LEN) {
2884 strcpy(biggiestruct.filename, biggie_filename);
2885 } else {
2886 fatal_error("biggie_filename too big");
2887 }
[128]2888 pB = strchr(checksum_line, ' ');
2889 if (!pB) {
2890 pB = strchr(checksum_line, '\t');
2891 }
2892 if (pB) {
2893 *pB = '\0';
2894 }
[1155]2895 if (strlen(checksum_line) <= 64) {
2896 strcpy(biggiestruct.checksum, checksum_line);
2897 } else {
2898 fatal_error("checksum_line too big");
2899 }
2900 mr_free(checksum_line);
[1]2901
[1155]2902 mr_asprintf(&tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
[1164]2903 fout = mr_fopen(tmp, "w");
[1155]2904 mr_free(tmp);
2905
[128]2906 (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
[1904]2907 if (fout) {
2908 mr_fclose(fout);
2909 }
[128]2910 length = totallength / optimal_set_size / 1024;
[1107]2911 mr_msg(1, "Opening in %s; slicing it and writing to CD/tape",
[128]2912 file_to_openin);
2913 if (!(fin = fopen(file_to_openin, "r"))) {
2914 log_OS_error("Unable to openin biggie_filename");
[1155]2915 mr_asprintf(&tmp, "Cannot archive bigfile '%s': not found",
2916 biggie_filename);
[128]2917 log_to_screen(tmp);
[1080]2918 mr_free(tmp);
[128]2919 return (1);
2920 }
2921 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2922 res =
[1663]2923 move_files_to_stream(slice_fname(biggie_file_number, 0,
[128]2924 bkpinfo->tmpdir, ""), NULL);
2925 } else {
2926 res =
[1663]2927 move_files_to_cd(slice_fname(biggie_file_number, 0,
[128]2928 bkpinfo->tmpdir, ""), NULL);
2929 }
[1164]2930 if (is_this_file_compressed(biggie_filename)
2931 || bkpinfo->compression_level == 0) {
2932 mr_asprintf(&suffix, "");
2933 should_I_compress_slices = FALSE;
2934 } else {
[1769]2935 mr_asprintf(&suffix, bkpinfo->compression_suffix);
[1164]2936 should_I_compress_slices = TRUE;
2937 }
[128]2938 i = bkpinfo->optimal_set_size / 256;
2939 for (slice_num = 1; !finished; slice_num++) {
[1155]2940 mr_asprintf(&curr_slice_fname_uncompressed,
[128]2941 slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
2942 ""));
[1155]2943 mr_asprintf(&curr_slice_fname_compressed,
[128]2944 slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
2945 suffix));
[1]2946
[1663]2947 mr_asprintf(&tmp, percent_media_full_comment());
[128]2948 update_progress_form(tmp);
[1155]2949 mr_free(tmp);
2950
[128]2951 if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
2952 log_OS_error(curr_slice_fname_uncompressed);
[1155]2953 mr_free(curr_slice_fname_uncompressed);
2954 mr_free(curr_slice_fname_compressed);
2955 mr_free(suffix);
[128]2956 return (1);
[1]2957 }
[1155]2958 tempblock = mr_malloc(256 * 1024);
[128]2959 if ((i == bkpinfo->optimal_set_size / 256)
2960 && (totalread < 1.1 * totallength)) {
2961 for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
2962 blksize = fread(tempblock, 1, 256 * 1024, fin);
2963 if (blksize > 0) {
2964 totalread = totalread + blksize;
2965 (void) fwrite(tempblock, 1, blksize, fout);
2966 } else {
2967 break;
2968 }
2969 }
2970 } else {
2971 i = 0;
2972 }
[1155]2973 mr_free(tempblock);
[128]2974 paranoid_fclose(fout);
2975 if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
[1]2976 {
[128]2977 if (!does_file_exist(curr_slice_fname_uncompressed)) {
[1107]2978 mr_msg(2,
[128]2979 "Warning - '%s' doesn't exist. How can I compress slice?",
2980 curr_slice_fname_uncompressed);
2981 }
2982 if (should_I_compress_slices && bkpinfo->compression_level > 0) {
[1769]2983 mr_asprintf(&command, "%s -%d %s", bkpinfo->compression_tool,
[1155]2984 bkpinfo->compression_level,
2985 curr_slice_fname_uncompressed);
[1107]2986 mr_msg(2, command);
[128]2987 if ((res = system(command))) {
2988 log_OS_error(command);
2989 }
[1155]2990 mr_free(command);
[128]2991 // did_I_compress_slice = TRUE;
2992 } else {
[1155]2993 /* BERLIOS: Useless
2994 mr_asprintf(&command, "mv %s %s 2>> %s",
2995 curr_slice_fname_uncompressed,
2996 curr_slice_fname_compressed, MONDO_LOGFILE);
2997 */
[128]2998 res = 0; // don't do it :)
2999 // did_I_compress_slice = FALSE;
3000 }
3001 retval += res;
3002 if (res) {
[1107]3003 mr_msg(2, "Failed to compress the slice");
[128]3004 }
[1769]3005 if ((bkpinfo->compression_type == lzo)
[128]3006 && strcmp(curr_slice_fname_compressed,
3007 curr_slice_fname_uncompressed)) {
3008 unlink(curr_slice_fname_uncompressed);
3009 }
3010 if (res) {
[1155]3011 mr_asprintf(&tmp, "Problem with slice # %ld", slice_num);
[128]3012 } else {
[1155]3013 mr_asprintf(&tmp,
3014 "%s - Bigfile #%ld, slice #%ld compressed OK ",
3015 biggie_filename, biggie_file_number + 1,
3016 slice_num);
[128]3017 }
3018 if (!g_text_mode) {
3019 newtDrawRootText(0, g_noof_rows - 2, tmp);
3020 newtRefresh();
3021 } else {
[1107]3022 mr_msg(2, tmp);
[128]3023 }
[1155]3024 mr_free(tmp);
3025 mr_asprintf(&file_to_archive, curr_slice_fname_compressed);
[128]3026 g_current_progress++;
3027 } else { /* if i==0 then ... */
[1]3028
[128]3029 finished = TRUE;
[1155]3030 mr_asprintf(&file_to_archive, curr_slice_fname_uncompressed);
[128]3031 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3032 break;
3033 }
3034 }
3035
3036 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3037 register_in_tape_catalog(biggieslice, biggie_file_number,
3038 slice_num, file_to_archive);
3039 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
3040 file_to_archive);
[1663]3041 res = move_files_to_stream(file_to_archive, NULL);
[128]3042 } else {
[1663]3043 res = move_files_to_cd(file_to_archive, NULL);
[128]3044 }
[1155]3045 mr_free(file_to_archive);
[128]3046 retval += res;
3047 if (res) {
[1155]3048 mr_asprintf(&tmp,
3049 "Failed to add slice %ld of bigfile %ld to scratchdir",
3050 slice_num, biggie_file_number + 1);
[128]3051 log_to_screen(tmp);
[1155]3052 mr_free(tmp);
[128]3053 fatal_error
3054 ("Hard disk full. You should have bought a bigger one.");
3055 }
[1155]3056 mr_free(curr_slice_fname_uncompressed);
3057 mr_free(curr_slice_fname_compressed);
[1]3058 }
[1155]3059 mr_free(suffix);
[128]3060 paranoid_fclose(fin);
3061 if (retval) {
[1155]3062 mr_asprintf(&tmp, "Sliced bigfile #%ld...FAILED",
3063 biggie_file_number + 1);
[128]3064 } else {
[1155]3065 mr_asprintf(&tmp, "Sliced bigfile #%ld...OK!",
3066 biggie_file_number + 1);
[1]3067 }
[1107]3068 mr_msg(1, tmp);
[1080]3069 mr_free(tmp);
[128]3070 return (retval);
[1]3071}
3072
3073
3074/**
3075 * Remove the archives in @c d.
3076 * This could possibly include any of:
3077 * - all afioballs (compressed and not)
3078 * - all filelists
3079 * - all slices
3080 * - all checksums
3081 * - a zero filler file
3082 *
3083 * @param d The directory to wipe the archives from.
3084 * @ingroup utilityGroup
3085 */
[128]3086void wipe_archives(char *d)
[1]3087{
[128]3088 /*@ buffers ********************************************* */
[1155]3089 char *tmp = NULL;
3090 char *dir = NULL;
[1]3091
[128]3092 assert_string_is_neither_NULL_nor_zerolength(d);
[1]3093
[1155]3094 mr_asprintf(&dir, "%s/archives", d);
3095 mr_asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
[128]3096 run_program_and_log_output(tmp, FALSE);
[1155]3097 mr_free(tmp);
3098 mr_asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;",
3099 dir);
[128]3100 run_program_and_log_output(tmp, FALSE);
[1155]3101 mr_free(tmp);
3102
3103 mr_asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
[128]3104 run_program_and_log_output(tmp, FALSE);
[1155]3105 mr_free(tmp);
3106
3107 mr_asprintf(&tmp, "rm -f %s/cklist*", dir);
[128]3108 run_program_and_log_output(tmp, FALSE);
[1155]3109 mr_free(tmp);
3110
3111 mr_asprintf(&tmp, "rm -f %s/zero", dir);
[128]3112 run_program_and_log_output(tmp, FALSE);
[1155]3113 mr_free(tmp);
3114
[1107]3115 mr_msg(1, "Wiped %s's archives", dir);
[1155]3116 mr_asprintf(&tmp, "ls -l %s", dir);
[128]3117 run_program_and_log_output(tmp, FALSE);
[1080]3118 mr_free(tmp);
[1155]3119
[1080]3120 mr_free(dir);
[1]3121}
3122
3123
3124/**
3125 * @addtogroup LLarchiveGroup
3126 * @{
3127 */
3128/**
3129 * Write the final ISO image.
3130 * @param bkpinfo The backup information structure. Used only
3131 * in the call to @c write_iso_and_go_on().
3132 * @return The number of errors encountered (0 for success)
3133 * @see write_iso_and_go_on
3134 * @see make_iso_fs
3135 * @bug The final ISO is written even if there are no files on it. In practice,
3136 * however, this occurs rarely.
3137 */
[1663]3138int write_final_iso_if_necessary()
[1]3139{
[128]3140 /*@ int ***************************************************** */
3141 int res;
[1]3142
[128]3143 /*@ buffers ************************************************** */
[1155]3144 char *tmp = NULL;
[1]3145
[128]3146 assert(bkpinfo != NULL);
[1]3147
3148// I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway
3149
[1155]3150 mr_asprintf(&tmp, "Writing the final ISO");
[1107]3151 mr_msg(2, tmp);
[1193]3152 /* BERLIOS: Doesn't work on allocated chains anymore
[128]3153 center_string(tmp, 80);
[1193]3154 */
[1]3155#ifndef _XWIN
[128]3156 if (!g_text_mode) {
3157 newtPushHelpLine(tmp);
3158 }
[1]3159#endif
[1155]3160 mr_free(tmp);
[1663]3161 res = write_iso_and_go_on(TRUE);
[1]3162#ifndef _XWIN
[128]3163 if (!g_text_mode) {
3164 newtPopHelpLine();
3165 }
[1]3166#endif
[1107]3167 mr_msg(2, "Returning from writing final ISO (res=%d)", res);
[128]3168 return (res);
[1]3169}
3170
3171
3172/**
[20]3173 * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
[1]3174 * @param bkpinfo The backup information structure. Fields used:
3175 * - @c backup_media_type
[20]3176 * - @c prefix
[1]3177 * - @c isodir
[1609]3178 * - @c manual_tray
[1]3179 * - @c media_size
3180 * - @c nfs_mount
3181 * - @c nfs_remote_dir
3182 * - @c scratchdir
3183 * - @c verify_data
3184 *
3185 * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
3186 * @return The number of errors encountered (0 for success)
3187 * @see make_iso_fs
3188 */
[1663]3189int write_iso_and_go_on(bool last_cd)
[1]3190{
[128]3191 /*@ pointers **************************************************** */
3192 FILE *fout;
[1]3193
[128]3194 /*@ buffers ***************************************************** */
3195 char *tmp;
3196 char *cdno_fname;
3197 char *lastcd_fname;
3198 char *isofile;
[1]3199
[128]3200 /*@ bool ******************************************************** */
3201 bool that_one_was_ok;
3202 bool orig_vfy_flag_val;
[1]3203
[128]3204 /*@ int *********************************************************** */
3205 int res = 0;
[1]3206
[128]3207 assert(bkpinfo != NULL);
3208 orig_vfy_flag_val = bkpinfo->verify_data;
[1365]3209 if (bkpinfo->media_size <= 0L) {
[128]3210 fatal_error("write_iso_and_go_on() - unknown media size");
3211 }
[1]3212
[1107]3213 mr_msg(1, "OK, time to make %s #%d",
[1155]3214 bkpinfo->backup_media_string,
[128]3215 g_current_media_number);
[1]3216
[128]3217 /* label the ISO with its number */
[1]3218
[1155]3219 mr_asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER",
3220 bkpinfo->scratchdir);
[128]3221 fout = fopen(cdno_fname, "w");
3222 fprintf(fout, "%d", g_current_media_number);
3223 paranoid_fclose(fout);
[1155]3224 mr_free(cdno_fname);
[1]3225
[1213]3226 mr_asprintf(&tmp, "cp -f %s/autorun %s/", MONDO_SHARE,
[1155]3227 bkpinfo->scratchdir);
[128]3228 if (run_program_and_log_output(tmp, FALSE)) {
[1107]3229 mr_msg(2, "Warning - unable to copy autorun to scratchdir");
[1]3230 }
[1155]3231 mr_free(tmp);
[128]3232
3233 /* last CD or not? Label accordingly */
[1155]3234 mr_asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST",
3235 bkpinfo->scratchdir);
[128]3236 if (last_cd) {
3237 unlink(lastcd_fname);
[1107]3238 mr_msg(2,
[128]3239 "OK, you're telling me this is the last CD. Fair enough.");
3240 } else {
3241 fout = fopen(lastcd_fname, "w");
3242 fprintf(fout,
3243 "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
3244 paranoid_fclose(fout);
[1]3245 }
[1155]3246 mr_free(lastcd_fname);
3247
[1365]3248 if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 > bkpinfo->media_size) {
[1155]3249 mr_asprintf(&tmp,
[1087]3250 "Warning! %s is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
3251 media_descriptor_string(bkpinfo->backup_media_type),
[128]3252 (long) space_occupied_by_cd(bkpinfo->scratchdir),
[1365]3253 bkpinfo->media_size);
[128]3254 log_to_screen(tmp);
[1155]3255 mr_free(tmp);
[128]3256 }
[1087]3257 if (bkpinfo->backup_media_type != usb) {
[1155]3258 mr_asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
[128]3259 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
3260 g_current_media_number);
[1087]3261 } else {
3262 }
[128]3263 for (that_one_was_ok = FALSE; !that_one_was_ok;) {
[1087]3264 if (bkpinfo->backup_media_type != usb) {
[1663]3265 res = make_iso_fs(isofile);
[1087]3266 } else {
[1693]3267 res = make_usb_fs();
[1087]3268 }
[128]3269 if (g_current_media_number == 1 && !res
3270 && (bkpinfo->backup_media_type == cdr
3271 || bkpinfo->backup_media_type == cdrw)) {
3272 if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
3273 {
[1107]3274 mr_msg(3, "*Sigh* Mike, I hate your computer.");
[1609]3275 bkpinfo->manual_tray = TRUE;
[128]3276 } // if it can't be found then force pausing
3277 else {
[1107]3278 mr_msg(3, "Great. Found Mike's CD-ROM drive.");
[128]3279 }
[1]3280 }
[128]3281 if (bkpinfo->verify_data && !res) {
3282 log_to_screen
3283 ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
3284 media_descriptor_string(g_backup_media_type));
3285 chdir("/");
[1770]3286 iamhere("Before calling verification of image()");
3287 if (bkpinfo->backup_media_type == usb) {
3288 res += verify_usb_image();
3289 } else {
3290 res += verify_cd_image();
3291 }
3292 iamhere("After calling verification of image()");
[1]3293 }
[128]3294 if (!res) {
3295 that_one_was_ok = TRUE;
3296 } else {
[1155]3297 mr_asprintf(&tmp, "Failed to burn %s #%d. Retry?",
3298 bkpinfo->backup_media_string,
3299 g_current_media_number);
[128]3300 res = ask_me_yes_or_no(tmp);
[1155]3301 mr_free(tmp);
[128]3302 if (!res) {
3303 if (ask_me_yes_or_no("Abort the backup?")) {
3304 fatal_error("FAILED TO BACKUP");
3305 } else {
3306 break;
3307 }
3308 } else {
[1107]3309 mr_msg(2, "Retrying, at user's request...");
[128]3310 res = 0;
3311 }
3312 }
[1]3313 }
[1155]3314 mr_free(isofile);
3315
[128]3316 g_current_media_number++;
3317 wipe_archives(bkpinfo->scratchdir);
[1155]3318 mr_asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
3319 bkpinfo->scratchdir, bkpinfo->scratchdir);
[128]3320 if (system(tmp)) {
[1155]3321 mr_msg(2,
3322 "Error occurred when I tried to delete the redundant IMGs and GZs");
[128]3323 }
[1155]3324 mr_free(tmp);
[1]3325
[128]3326 if (last_cd) {
[1770]3327 mr_msg(2, "This was your last media.");
[128]3328 } else {
[1107]3329 mr_msg(2, "Continuing to backup your data...");
[128]3330 }
[1]3331
[128]3332 bkpinfo->verify_data = orig_vfy_flag_val;
3333 return (0);
[1]3334}
3335
3336/* @} - end of LLarchiveGroup */
3337
3338
3339/**
3340 * Verify the user's data.
3341 * @param bkpinfo The backup information structure. Fields used:
3342 * - @c backup_data
3343 * - @c backup_media_type
3344 * - @c media_device
3345 * - @c verify_data
3346 *
3347 * @return The number of errors encountered (0 for success)
3348 * @ingroup verifyGroup
3349 */
[1663]3350int verify_data()
[1]3351{
[128]3352 int res = 0, retval = 0, cdno = 0;
[1155]3353 char *tmp = NULL;
[128]3354 long diffs = 0;
[1]3355
[128]3356 assert(bkpinfo != NULL);
3357 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3358 chdir("/");
3359 mvaddstr_and_log_it(g_currentY, 0,
3360 "Verifying archives against live filesystem");
[1663]3361 verify_tape_backups();
[128]3362 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
3363 } else if (bkpinfo->backup_data)
3364 //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
[1]3365 {
[1107]3366 mr_msg(2,
[128]3367 "Not verifying again. Per-CD/ISO verification already carried out.");
[1770]3368 sprintf(tmp, "cat %s/changed.files > %s/changed.files 2> /dev/null",bkpinfo->tmpdir, MONDO_CACHE);
[1663]3369 paranoid_system(tmp);
[128]3370 } else {
3371 g_current_media_number = cdno;
3372 chdir("/");
3373 for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
3374 if (cdno != g_current_media_number) {
[1107]3375 mr_msg(2,
[128]3376 "Warning - had to change g_current_media_number from %d to %d",
3377 g_current_media_number, cdno);
3378 g_current_media_number = cdno;
3379 }
3380 if (bkpinfo->backup_media_type != iso) {
[1663]3381 insist_on_this_cd_number(cdno);
[128]3382 }
[1663]3383 res = verify_cd_image(); // sets verify_data to FALSE if it's time to stop verifying
[128]3384 retval += res;
3385 if (res) {
[1155]3386 mr_asprintf(&tmp,
[1663]3387 "Warnings/errors were reported while checking %s #%d",
3388 media_descriptor_string(bkpinfo->backup_media_type),
3389 g_current_media_number);
[128]3390 log_to_screen(tmp);
[1155]3391 mr_free(tmp);
[1]3392
[128]3393 }
[1]3394 }
[1155]3395 mr_asprintf(&tmp,
[1663]3396 "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> %s/changed.files",
[1770]3397 MONDO_LOGFILE, MONDO_CACHE);
[128]3398 system(tmp);
[1155]3399 mr_free(tmp);
[128]3400
[1155]3401 mr_asprintf(&tmp,
[1663]3402 "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> %s/changed.files",
[1770]3403 MONDO_LOGFILE, MONDO_CACHE);
[128]3404 system(tmp);
[1155]3405 mr_free(tmp);
3406
[128]3407 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3408 eject_device(bkpinfo->media_device);
[1]3409 }
[1770]3410 sprintf(tmp, "%s/changed.files", MONDO_CACHE);
[1663]3411 diffs = count_lines_in_file(tmp);
[1]3412
[128]3413 if (diffs > 0) {
3414 if (retval == 0) {
3415 retval = (int) (-diffs);
3416 }
[1]3417 }
[128]3418 return (retval);
[1]3419}
3420
3421
[1152]3422void setenv_mondo_var(void) {
[259]3423
[1152]3424 char *tmp = NULL;
3425 char *p = NULL;
[1256]3426 char *path_min = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
[1152]3427
3428 mr_setenv("MONDO_SHARE",MONDO_SHARE);
3429 mr_setenv("MONDORESTORECFG",MONDORESTORECFG);
3430 mr_setenv("MONDO_CACHE",MONDO_CACHE);
[1256]3431 /* Add the ARCH environment variable for ia64 purposes */
3432 mr_setenv("ARCH", get_architecture());
[1152]3433
[1256]3434
[1152]3435 if ((p = getenv("PATH")) == NULL) {
[1158]3436 mr_asprintf(&tmp, path_min);
3437 } else {
3438 mr_asprintf(&tmp, "%s:%s",p, path_min);
[1152]3439 }
3440 mr_setenv("PATH",tmp);
3441 mr_free(tmp);
[259]3442}
Note: See TracBrowser for help on using the repository browser.