[1] | 1 | /* libmondo-tools.c misc tools
|
---|
[99] | 2 | $Id: libmondo-tools.c 1080 2007-01-28 18:04:41Z bruno $
|
---|
[1] | 3 | */
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * @file
|
---|
| 8 | * Miscellaneous tools that didn't really fit anywhere else.
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include "my-stuff.h"
|
---|
[1080] | 12 | #include "mr_mem.h"
|
---|
[1] | 13 | #include "mondostructures.h"
|
---|
[541] | 14 | #include "lib-common-externs.h"
|
---|
[1] | 15 | #include "libmondo-tools.h"
|
---|
[541] | 16 | #include "libmondo-gui-EXT.h"
|
---|
[1] | 17 | #include "libmondo-files-EXT.h"
|
---|
| 18 | #include "libmondo-fork-EXT.h"
|
---|
| 19 | #include "libmondo-raid-EXT.h"
|
---|
| 20 | #include <sys/socket.h>
|
---|
| 21 | #include <netdb.h>
|
---|
| 22 | #include <netinet/in.h>
|
---|
| 23 | #include <arpa/inet.h>
|
---|
| 24 |
|
---|
| 25 | /*@unused@*/
|
---|
[99] | 26 | //static char cvsid[] = "$Id: libmondo-tools.c 1080 2007-01-28 18:04:41Z bruno $";
|
---|
[1] | 27 |
|
---|
| 28 | extern int g_tape_buffer_size_MB;
|
---|
| 29 | extern char *g_erase_tmpdir_and_scratchdir;
|
---|
| 30 | extern char *g_serial_string;
|
---|
| 31 | extern bool g_text_mode;
|
---|
| 32 | extern int g_currentY;
|
---|
| 33 | extern int g_current_media_number;
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * @addtogroup globalGroup
|
---|
| 37 | * @{
|
---|
| 38 | */
|
---|
[128] | 39 | bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
|
---|
| 40 | g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
|
---|
| 41 | bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
|
---|
[1] | 42 | double g_kernel_version;
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * The place where /boot is mounted.
|
---|
| 46 | */
|
---|
[128] | 47 | char *g_boot_mountpt = NULL;
|
---|
[1] | 48 |
|
---|
| 49 | /**
|
---|
| 50 | * The location of Mondo's home directory.
|
---|
| 51 | */
|
---|
[128] | 52 | char *g_mondo_home = NULL;
|
---|
[1] | 53 |
|
---|
| 54 | /**
|
---|
| 55 | * The serial string (used to differentiate between backups) of the current backup.
|
---|
| 56 | */
|
---|
[128] | 57 | char *g_serial_string = NULL;
|
---|
[1] | 58 |
|
---|
| 59 | /**
|
---|
| 60 | * The location where tmpfs is mounted, or "" if it's not mounted.
|
---|
| 61 | */
|
---|
[128] | 62 | char *g_tmpfs_mountpt = NULL;
|
---|
| 63 | char *g_magicdev_command = NULL;
|
---|
[1] | 64 |
|
---|
| 65 | /**
|
---|
| 66 | * The default maximum level to log messages at or below.
|
---|
| 67 | */
|
---|
[128] | 68 | int g_loglevel = DEFAULT_DEBUG_LEVEL;
|
---|
[1] | 69 |
|
---|
| 70 | /* @} - end of globalGroup */
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | extern pid_t g_buffer_pid;
|
---|
| 74 | extern pid_t g_main_pid;
|
---|
| 75 |
|
---|
| 76 | extern t_bkptype g_backup_media_type;
|
---|
| 77 |
|
---|
| 78 | extern bool am_I_in_disaster_recovery_mode(void);
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
| 82 | * @addtogroup utilityGroup
|
---|
| 83 | * @{
|
---|
| 84 | */
|
---|
| 85 | /**
|
---|
| 86 | * Assertion handler. Prints a friendly message to the user,
|
---|
| 87 | * offering to ignore all, dump core, break to debugger,
|
---|
| 88 | * exit, or ignore. Intended to be used with an assert() macro.
|
---|
| 89 | *
|
---|
| 90 | * @param file The file in which the assertion triggered.
|
---|
| 91 | * @param function The function (@c __FUNCTION__) in which the assertion triggered.
|
---|
| 92 | * @param line The line number of the assert() statement.
|
---|
| 93 | * @param exp The expression that failed (as a string).
|
---|
| 94 | */
|
---|
[128] | 95 | void _mondo_assert_fail(const char *file,
|
---|
| 96 | const char *function, int line, const char *exp)
|
---|
[1] | 97 | {
|
---|
[128] | 98 | static int ignoring_assertions = 0;
|
---|
| 99 | bool is_valid = TRUE;
|
---|
[1] | 100 |
|
---|
[128] | 101 | log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
|
---|
| 102 | function);
|
---|
| 103 | if (ignoring_assertions) {
|
---|
| 104 | log_it("Well, the user doesn't care...");
|
---|
| 105 | return;
|
---|
| 106 | }
|
---|
[1] | 107 | #ifndef _XWIN
|
---|
[128] | 108 | if (!g_text_mode)
|
---|
| 109 | newtSuspend();
|
---|
[1] | 110 | #endif
|
---|
[541] | 111 | printf("ASSERTION FAILED: `%s'\n", exp);
|
---|
| 112 | printf("\tat %s:%d in %s\n\n", file, line, function);
|
---|
| 113 | printf("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
|
---|
[128] | 114 | do {
|
---|
| 115 | is_valid = TRUE;
|
---|
| 116 | switch (toupper(getchar())) {
|
---|
| 117 | case 'A': // ignore (A)ll
|
---|
| 118 | ignoring_assertions = 1;
|
---|
| 119 | break;
|
---|
| 120 | case 'B': // a(B)ort
|
---|
| 121 | signal(SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
|
---|
| 122 | raise(SIGABRT);
|
---|
| 123 | break; /* "can't get here" */
|
---|
| 124 | case 'D': // (D)ebug, aka asm("int 3")
|
---|
[1] | 125 | #ifdef __IA32__
|
---|
[128] | 126 | __asm__ __volatile__("int $3"); // break to debugger
|
---|
[1] | 127 | #endif
|
---|
[128] | 128 | break;
|
---|
| 129 | case 'E': // (E)xit
|
---|
| 130 | fatal_error("Failed assertion -- see above for details");
|
---|
| 131 | break; /* "can't get here" */
|
---|
| 132 | case 'I': // (I)gnore
|
---|
| 133 | break;
|
---|
| 134 | /* These next two work as follows:
|
---|
| 135 | the `default' catches the user's invalid choice and says so;
|
---|
| 136 | the '\n' catches the newline on the end and prints the prompt again.
|
---|
| 137 | */
|
---|
| 138 | case '\n':
|
---|
| 139 | printf
|
---|
[541] | 140 | ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
|
---|
[128] | 141 | break;
|
---|
| 142 | default:
|
---|
| 143 | is_valid = FALSE;
|
---|
[541] | 144 | printf("Invalid choice.\n");
|
---|
[128] | 145 | break;
|
---|
| 146 | }
|
---|
| 147 | } while (!is_valid);
|
---|
| 148 |
|
---|
| 149 | if (ignoring_assertions) {
|
---|
| 150 | log_it("Ignoring ALL assertions from now on.");
|
---|
| 151 | } else {
|
---|
| 152 | log_it("Ignoring assertion: %s", exp);
|
---|
[1] | 153 | }
|
---|
| 154 |
|
---|
[128] | 155 | getchar(); // skip \n
|
---|
[1] | 156 |
|
---|
| 157 | #ifndef _XWIN
|
---|
[128] | 158 | if (!g_text_mode)
|
---|
| 159 | newtResume();
|
---|
[1] | 160 | #endif
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /**
|
---|
| 164 | * Clean's up users' KDE desktops.
|
---|
| 165 | * @bug Details about this function are unknown.
|
---|
| 166 | */
|
---|
| 167 | void clean_up_KDE_desktop_if_necessary(void)
|
---|
| 168 | {
|
---|
[128] | 169 | char *tmp;
|
---|
[1] | 170 |
|
---|
[128] | 171 | malloc_string(tmp);
|
---|
| 172 | strcpy(tmp,
|
---|
| 173 | "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
|
---|
[1] | 174 | file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
|
---|
[273] | 175 | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
|
---|
[275] | 176 | else { print $0;};}' $file.old > $file ; fi ; done");
|
---|
[128] | 177 | run_program_and_log_output(tmp, 5);
|
---|
[1080] | 178 | mr_free(tmp);
|
---|
[1] | 179 | }
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | /**
|
---|
[1061] | 183 | * Locate mondoarchive's home directory. Searches in /usr/share/mondo,
|
---|
[1] | 184 | * /usr/local/share/mondo, /opt, or if all else fails, search /usr.
|
---|
| 185 | *
|
---|
| 186 | * @param home_sz String to store the home directory ("" if it could not be found).
|
---|
| 187 | * @return 0 for success, nonzero for failure.
|
---|
| 188 | */
|
---|
| 189 | int find_and_store_mondoarchives_home(char *home_sz)
|
---|
| 190 | {
|
---|
[128] | 191 | assert(home_sz != NULL);
|
---|
[424] | 192 | strcpy(home_sz, MONDO_SHARE);
|
---|
[182] | 193 | return (0);
|
---|
[1] | 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | char *get_architecture()
|
---|
| 198 | {
|
---|
| 199 | #ifdef __IA32__
|
---|
[128] | 200 | return ("i386");
|
---|
[1] | 201 | #endif
|
---|
| 202 | #ifdef __IA64__
|
---|
[128] | 203 | return ("ia64");
|
---|
[1] | 204 | #endif
|
---|
[128] | 205 | return ("unknown");
|
---|
[1] | 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | double get_kernel_version()
|
---|
| 211 | {
|
---|
[128] | 212 | char *p, tmp[200];
|
---|
| 213 | double d;
|
---|
[1] | 214 | #ifdef __FreeBSD__
|
---|
[128] | 215 | // JOSH - FIXME :)
|
---|
| 216 | d = 5.2; // :-)
|
---|
[1] | 217 | #else
|
---|
[128] | 218 | strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
|
---|
| 219 | p = strchr(tmp, '.');
|
---|
| 220 | if (p) {
|
---|
| 221 | p = strchr(++p, '.');
|
---|
| 222 | if (p) {
|
---|
| 223 | while (*p) {
|
---|
| 224 | *p = *(p + 1);
|
---|
| 225 | p++;
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
[1] | 229 | // log_msg(1, "tmp = '%s'", tmp);
|
---|
[128] | 230 | d = atof(tmp);
|
---|
[1] | 231 | #endif
|
---|
[128] | 232 | log_msg(1, "g_kernel_version = %f", d);
|
---|
| 233 | return (d);
|
---|
[1] | 234 | }
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | /**
|
---|
| 241 | * Get the current time.
|
---|
| 242 | * @return number of seconds since the epoch.
|
---|
| 243 | */
|
---|
[128] | 244 | long get_time()
|
---|
[1] | 245 | {
|
---|
[128] | 246 | return (long) time((void *) 0);
|
---|
[1] | 247 | }
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 |
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 |
|
---|
| 255 | /**
|
---|
| 256 | * Initialize a RAID volume structure, setting fields to zero. The
|
---|
| 257 | * actual hard drive is unaffected.
|
---|
| 258 | *
|
---|
| 259 | * @param raidrec The RAID volume structure to initialize.
|
---|
| 260 | * @note This function is system dependent.
|
---|
| 261 | */
|
---|
| 262 | #ifdef __FreeBSD__
|
---|
[128] | 263 | void initialize_raidrec(struct vinum_volume *raidrec)
|
---|
[1] | 264 | {
|
---|
[128] | 265 | int i, j;
|
---|
| 266 | raidrec->volname[0] = '\0';
|
---|
| 267 | raidrec->plexes = 0;
|
---|
| 268 | for (i = 0; i < 9; ++i) {
|
---|
| 269 | raidrec->plex[i].raidlevel = -1;
|
---|
| 270 | raidrec->plex[i].stripesize = 0;
|
---|
| 271 | raidrec->plex[i].subdisks = 0;
|
---|
| 272 | for (j = 0; j < 9; ++j) {
|
---|
| 273 | strcpy(raidrec->plex[i].sd[j].which_device, "");
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
[1] | 276 | }
|
---|
| 277 | #else
|
---|
[128] | 278 | void initialize_raidrec(struct raid_device_record *raidrec)
|
---|
[1] | 279 | {
|
---|
[128] | 280 | assert(raidrec != NULL);
|
---|
| 281 | raidrec->raid_device[0] = '\0';
|
---|
[558] | 282 | raidrec->raid_level = -9;
|
---|
[128] | 283 | raidrec->persistent_superblock = 1;
|
---|
[558] | 284 | raidrec->chunk_size = 64;
|
---|
| 285 | raidrec->parity = -1;
|
---|
[128] | 286 | raidrec->data_disks.entries = 0;
|
---|
| 287 | raidrec->spare_disks.entries = 0;
|
---|
| 288 | raidrec->parity_disks.entries = 0;
|
---|
| 289 | raidrec->failed_disks.entries = 0;
|
---|
| 290 | raidrec->additional_vars.entries = 0;
|
---|
[1] | 291 | }
|
---|
| 292 | #endif
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 |
|
---|
| 297 | /**
|
---|
| 298 | * Insert modules that Mondo requires.
|
---|
| 299 | * Currently inserts @c dos, @c fat, @c vfat, and @c osst for Linux;
|
---|
| 300 | * @c msdosfs and @c ext2fs for FreeBSD.
|
---|
| 301 | */
|
---|
| 302 | void insmod_crucial_modules(void)
|
---|
| 303 | {
|
---|
| 304 | #ifdef __FreeBSD__
|
---|
[128] | 305 | system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
|
---|
| 306 | system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
|
---|
[1] | 307 | #else
|
---|
[128] | 308 | system("modprobe dos &> /dev/null");
|
---|
| 309 | system("modprobe fat &> /dev/null");
|
---|
| 310 | system("modprobe vfat &> /dev/null");
|
---|
| 311 | // system("modprobe osst &> /dev/null");
|
---|
[1] | 312 | #endif
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | /**
|
---|
[541] | 317 | * Log a trace message to the trace file.
|
---|
| 318 | * @bug This function seems orphaned. Please remove.
|
---|
| 319 | */
|
---|
| 320 | void log_trace(char *o)
|
---|
| 321 | {
|
---|
| 322 | /*@ pointers **************************************************** */
|
---|
| 323 | FILE *fout;
|
---|
| 324 |
|
---|
| 325 | /*@ buffers ***************************************************** */
|
---|
| 326 | char output[MAX_STR_LEN];
|
---|
| 327 |
|
---|
| 328 | /*@ int ****************************************************** */
|
---|
| 329 | int i;
|
---|
| 330 |
|
---|
| 331 | /*@ end vars *************************************************** */
|
---|
| 332 |
|
---|
| 333 | if (o[0] == '\0') {
|
---|
| 334 | return;
|
---|
| 335 | }
|
---|
| 336 | strcpy(output, o);
|
---|
| 337 | i = (int) strlen(output);
|
---|
| 338 | if (i <= 0) {
|
---|
| 339 | return;
|
---|
| 340 | }
|
---|
| 341 | if (output[i - 1] < 32) {
|
---|
| 342 | output[i - 1] = '\0';
|
---|
| 343 | }
|
---|
| 344 | if (g_text_mode
|
---|
| 345 | /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
|
---|
| 346 | printf("%s\n", output);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | fout = fopen(MONDO_TRACEFILE, "a");
|
---|
| 350 | if (fout) {
|
---|
| 351 | fprintf(fout, "%s\n", output);
|
---|
| 352 | paranoid_fclose(fout);
|
---|
| 353 | } else {
|
---|
| 354 | log_OS_error("Cannot write to tracefile");
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 |
|
---|
| 360 |
|
---|
| 361 |
|
---|
| 362 | /**
|
---|
[1] | 363 | * Finish configuring the backup information structure. Call this function
|
---|
| 364 | * to set the parameters that depend on those that can be given on the command
|
---|
| 365 | * line.
|
---|
| 366 | *
|
---|
| 367 | * @param bkpinfo The backup information structure. Fields modified/used:
|
---|
| 368 | * - Used: @c bkpinfo->backup_data
|
---|
| 369 | * - Used: @c bkpinfo->backup_media_type
|
---|
| 370 | * - Used: @c bkpinfo->cdrw_speed
|
---|
| 371 | * - Used: @c bkpinfo->compression_level
|
---|
| 372 | * - Used: @c bkpinfo->include_paths
|
---|
[20] | 373 | * - Used: @c bkpinfo->prefix
|
---|
[1] | 374 | * - Used: @c bkpinfo->isodir
|
---|
| 375 | * - Used: @c bkpinfo->manual_cd_tray
|
---|
| 376 | * - Used: @c bkpinfo->make_cd_use_lilo
|
---|
| 377 | * - Used: @c bkpinfo->media_device
|
---|
| 378 | * - Used: @c bkpinfo->nfs_mount
|
---|
| 379 | * - Used: @c bkpinfo->nonbootable_backup
|
---|
| 380 | * - Used: @c bkpinfo->scratchdir
|
---|
| 381 | * - Used: @c bkpinfo->tmpdir
|
---|
| 382 | * - Used: @c bkpinfo->use_lzo
|
---|
| 383 | * - Modified: @c bkpinfo->call_before_iso
|
---|
| 384 | * - Modified: @c bkpinfo->call_make_iso
|
---|
| 385 | * - Modified: @c bkpinfo->optimal_set_size
|
---|
| 386 | * - Modified: @c bkpinfo->zip_exe
|
---|
| 387 | * - Modified: @c bkpinfo->zip_suffix
|
---|
| 388 | *
|
---|
| 389 | * @return number of errors, or 0 for success.
|
---|
| 390 | * @note Also creates directories that are specified in the @c bkpinfo structure but
|
---|
| 391 | * do not exist.
|
---|
| 392 | */
|
---|
[128] | 393 | int post_param_configuration(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 394 | {
|
---|
[128] | 395 | char *extra_cdrom_params;
|
---|
| 396 | char *mondo_mkisofs_sz;
|
---|
| 397 | char *command;
|
---|
| 398 | char *mtpt;
|
---|
| 399 | char *hostname, *ip_address;
|
---|
| 400 | int retval = 0;
|
---|
| 401 | long avm = 0;
|
---|
| 402 | char *colon;
|
---|
| 403 | char *cdr_exe;
|
---|
| 404 | char *tmp;
|
---|
[163] | 405 | char call_before_iso_user[MAX_STR_LEN] = "\0";
|
---|
[128] | 406 | int rdsiz_MB;
|
---|
| 407 | char *iso_dev;
|
---|
| 408 | char *iso_mnt;
|
---|
| 409 | char *iso_tmp;
|
---|
| 410 | char *iso_path;
|
---|
[1] | 411 |
|
---|
[128] | 412 | assert(bkpinfo != NULL);
|
---|
| 413 | malloc_string(extra_cdrom_params);
|
---|
| 414 | malloc_string(mondo_mkisofs_sz);
|
---|
| 415 | malloc_string(command);
|
---|
| 416 | malloc_string(mtpt);
|
---|
| 417 | malloc_string(hostname);
|
---|
| 418 | malloc_string(ip_address);
|
---|
| 419 | malloc_string(cdr_exe);
|
---|
| 420 | malloc_string(tmp);
|
---|
| 421 | malloc_string(iso_dev);
|
---|
| 422 | malloc_string(iso_mnt);
|
---|
| 423 | malloc_string(iso_tmp);
|
---|
| 424 | malloc_string(iso_path);
|
---|
| 425 | bkpinfo->optimal_set_size =
|
---|
[686] | 426 | (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
|
---|
[128] | 427 | 1024;
|
---|
[1] | 428 |
|
---|
[128] | 429 | log_msg(1, "Foo");
|
---|
| 430 | if (bkpinfo->backup_media_type == tape) {
|
---|
| 431 | log_msg(1, "Bar");
|
---|
| 432 | sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
|
---|
| 433 | log_msg(1, "tmp = '%s'", tmp);
|
---|
| 434 | if (run_program_and_log_output(tmp, 3)) {
|
---|
| 435 | fatal_error
|
---|
| 436 | ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
|
---|
| 437 | }
|
---|
[1] | 438 | }
|
---|
[128] | 439 | make_hole_for_dir(bkpinfo->scratchdir);
|
---|
| 440 | make_hole_for_dir(bkpinfo->tmpdir);
|
---|
| 441 | if (bkpinfo->backup_media_type == iso)
|
---|
| 442 | make_hole_for_dir(bkpinfo->isodir);
|
---|
[1] | 443 |
|
---|
[128] | 444 | run_program_and_log_output("uname -a", 5);
|
---|
[678] | 445 | run_program_and_log_output("cat /etc/*-release", 5);
|
---|
[128] | 446 | run_program_and_log_output("cat /etc/*issue*", 5);
|
---|
| 447 | sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
|
---|
| 448 | sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
|
---|
| 449 | paranoid_system(command);
|
---|
| 450 | rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
|
---|
[1] | 451 | #ifdef __FreeBSD__
|
---|
[128] | 452 | strcpy(tmp,
|
---|
| 453 | call_program_and_get_last_line_of_output
|
---|
| 454 | ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
|
---|
| 455 | avm += atol(tmp);
|
---|
| 456 | strcpy(tmp,
|
---|
| 457 | call_program_and_get_last_line_of_output
|
---|
| 458 | ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
|
---|
| 459 | avm += atol(tmp);
|
---|
| 460 | sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
|
---|
| 461 | g_tmpfs_mountpt);
|
---|
[1] | 462 | #else
|
---|
[128] | 463 | strcpy(tmp,
|
---|
| 464 | call_program_and_get_last_line_of_output
|
---|
[911] | 465 | ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1"));
|
---|
[128] | 466 | avm += atol(tmp);
|
---|
| 467 | sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
|
---|
| 468 | g_tmpfs_mountpt, rdsiz_MB, 'm');
|
---|
| 469 | run_program_and_log_output("cat /proc/cpuinfo", 5);
|
---|
| 470 | run_program_and_log_output
|
---|
| 471 | ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
|
---|
| 472 | 5);
|
---|
[1] | 473 | #endif
|
---|
[128] | 474 | if (avm / 1024 > rdsiz_MB * 3) {
|
---|
| 475 | if (run_program_and_log_output(command, 5)) {
|
---|
| 476 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 477 | log_it("Failed to mount tmpfs");
|
---|
| 478 | } else {
|
---|
| 479 | log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
|
---|
| 480 | }
|
---|
| 481 | } else {
|
---|
| 482 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 483 | log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
|
---|
[1] | 484 | }
|
---|
[128] | 485 |
|
---|
| 486 | if (bkpinfo->use_lzo) {
|
---|
| 487 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
| 488 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
[998] | 489 | } else if (bkpinfo->use_gzip) {
|
---|
| 490 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
| 491 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
[128] | 492 | } else if (bkpinfo->compression_level != 0) {
|
---|
| 493 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
| 494 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
| 495 | } else {
|
---|
| 496 | bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
|
---|
[1] | 497 | }
|
---|
| 498 |
|
---|
| 499 | // DVD
|
---|
| 500 |
|
---|
[128] | 501 | if (bkpinfo->backup_media_type == dvd) {
|
---|
| 502 | extra_cdrom_params[0] = '\0';
|
---|
| 503 | mondo_mkisofs_sz[0] = '\0';
|
---|
| 504 | if (find_home_of_exe("growisofs")) {
|
---|
| 505 | strcpy(cdr_exe, "growisofs");
|
---|
| 506 | } // unlikely to be used
|
---|
| 507 | else {
|
---|
| 508 | fatal_error("Please install growisofs.");
|
---|
| 509 | }
|
---|
| 510 | if (bkpinfo->nonbootable_backup) {
|
---|
| 511 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
|
---|
| 512 | } else if
|
---|
[1] | 513 | #ifdef __FreeBSD__
|
---|
[128] | 514 | (TRUE)
|
---|
[1] | 515 | #else
|
---|
[128] | 516 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 517 | #endif
|
---|
| 518 | #ifdef __IA64__
|
---|
[128] | 519 | {
|
---|
| 520 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
|
---|
| 521 | }
|
---|
[1] | 522 | #else
|
---|
| 523 | {
|
---|
[128] | 524 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
|
---|
[1] | 525 | }
|
---|
[128] | 526 | #endif
|
---|
| 527 | else
|
---|
| 528 | {
|
---|
| 529 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
|
---|
| 530 | }
|
---|
| 531 | if (bkpinfo->manual_cd_tray) {
|
---|
| 532 | fatal_error("Manual CD tray + DVD not supported yet.");
|
---|
| 533 | // -m isn't supported by growisofs, BTW...
|
---|
| 534 | } else {
|
---|
| 535 | sprintf(bkpinfo->call_make_iso,
|
---|
| 536 | "%s %s -Z %s . 2>> _ERR_",
|
---|
| 537 | mondo_mkisofs_sz,
|
---|
| 538 | extra_cdrom_params, bkpinfo->media_device);
|
---|
| 539 | }
|
---|
[153] | 540 | if (getenv ("SUDO_COMMAND")) {
|
---|
[679] | 541 | sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
|
---|
| 542 | if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
|
---|
| 543 | popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
| 544 | fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
| 545 | }
|
---|
[153] | 546 | }
|
---|
[128] | 547 | log_msg(2, "call_make_iso (DVD res) is ... %s",
|
---|
| 548 | bkpinfo->call_make_iso);
|
---|
| 549 | } // end of DVD code
|
---|
[1] | 550 |
|
---|
| 551 | // CD-R or CD-RW
|
---|
[128] | 552 | if (bkpinfo->backup_media_type == cdrw
|
---|
| 553 | || bkpinfo->backup_media_type == cdr) {
|
---|
| 554 | extra_cdrom_params[0] = '\0';
|
---|
| 555 | if (!bkpinfo->manual_cd_tray) {
|
---|
| 556 | strcat(extra_cdrom_params, "-waiti ");
|
---|
| 557 | }
|
---|
| 558 | if (bkpinfo->backup_media_type == cdrw) {
|
---|
| 559 | strcat(extra_cdrom_params, "blank=fast ");
|
---|
| 560 | }
|
---|
| 561 | if (find_home_of_exe("cdrecord")) {
|
---|
| 562 | strcpy(cdr_exe, "cdrecord");
|
---|
| 563 | } else if (find_home_of_exe("dvdrecord")) {
|
---|
| 564 | strcpy(cdr_exe, "dvdrecord");
|
---|
| 565 | } else {
|
---|
| 566 | fatal_error("Please install either cdrecord or dvdrecord.");
|
---|
| 567 | }
|
---|
| 568 | if (bkpinfo->nonbootable_backup) {
|
---|
| 569 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
|
---|
| 570 | } else if
|
---|
[1] | 571 | #ifdef __FreeBSD__
|
---|
[128] | 572 | (TRUE)
|
---|
[1] | 573 | #else
|
---|
[128] | 574 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 575 | #endif
|
---|
| 576 | #ifdef __IA64__
|
---|
| 577 | {
|
---|
[128] | 578 | strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
|
---|
[1] | 579 | }
|
---|
[128] | 580 | #else
|
---|
[1] | 581 | {
|
---|
[128] | 582 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
|
---|
[1] | 583 | }
|
---|
[128] | 584 | #endif
|
---|
| 585 | else
|
---|
| 586 | {
|
---|
| 587 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
|
---|
| 588 | }
|
---|
| 589 | if (bkpinfo->manual_cd_tray) {
|
---|
[163] | 590 | if (bkpinfo->call_before_iso[0] == '\0') {
|
---|
[128] | 591 | sprintf(bkpinfo->call_before_iso,
|
---|
[163] | 592 | "%s -o %s/temporary.iso . 2>> _ERR_",
|
---|
| 593 | mondo_mkisofs_sz, bkpinfo->tmpdir);
|
---|
| 594 | } else {
|
---|
| 595 | strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
|
---|
| 596 | sprintf (bkpinfo->call_before_iso,
|
---|
| 597 | "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )",
|
---|
| 598 | mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
|
---|
| 599 | }
|
---|
| 600 | log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
|
---|
[128] | 601 | sprintf(bkpinfo->call_make_iso,
|
---|
| 602 | "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
|
---|
| 603 | cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
|
---|
| 604 | extra_cdrom_params, bkpinfo->media_device,
|
---|
| 605 | bkpinfo->cdrw_speed, bkpinfo->tmpdir);
|
---|
| 606 | } else {
|
---|
| 607 | sprintf(bkpinfo->call_make_iso,
|
---|
| 608 | "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
|
---|
| 609 | mondo_mkisofs_sz, cdr_exe,
|
---|
| 610 | (bkpinfo->please_dont_eject) ? " " : "-eject",
|
---|
| 611 | extra_cdrom_params, bkpinfo->media_device,
|
---|
| 612 | bkpinfo->cdrw_speed);
|
---|
| 613 | }
|
---|
| 614 | } // end of CD code
|
---|
[1] | 615 |
|
---|
[128] | 616 | /*
|
---|
| 617 | if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
|
---|
| 618 | {
|
---|
| 619 | sprintf (tmp,
|
---|
| 620 | "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
|
---|
| 621 | bkpinfo->media_device, bkpinfo->internal_tape_block_size);
|
---|
| 622 | if (system(tmp))
|
---|
| 623 | {
|
---|
| 624 | retval++;
|
---|
| 625 | fprintf (stderr,
|
---|
| 626 | "Cannot write to tape device. Is the tape set read-only?\n");
|
---|
| 627 | }
|
---|
| 628 | } // end of tape code
|
---|
| 629 | */
|
---|
[1] | 630 |
|
---|
| 631 |
|
---|
[128] | 632 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 633 |
|
---|
[1] | 634 | /* Patch by Conor Daly <conor.daly@met.ie>
|
---|
| 635 | * 23-june-2004
|
---|
| 636 | * Break up isodir into iso_mnt and iso_path
|
---|
| 637 | * These will be used along with iso-dev at restore time
|
---|
| 638 | * to locate the ISOs where ever they're mounted
|
---|
| 639 | */
|
---|
| 640 |
|
---|
[128] | 641 | log_it("isodir = %s", bkpinfo->isodir);
|
---|
[165] | 642 | sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
|
---|
[128] | 643 | bkpinfo->isodir);
|
---|
| 644 | log_it("command = %s", command);
|
---|
| 645 | log_it("res of it = %s",
|
---|
| 646 | call_program_and_get_last_line_of_output(command));
|
---|
| 647 | sprintf(iso_dev, "%s",
|
---|
| 648 | call_program_and_get_last_line_of_output(command));
|
---|
| 649 | sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
|
---|
| 650 | write_one_liner_data_file(tmp,
|
---|
| 651 | call_program_and_get_last_line_of_output
|
---|
| 652 | (command));
|
---|
[1] | 653 |
|
---|
[128] | 654 | sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
|
---|
| 655 | iso_dev);
|
---|
| 656 | log_it("command = %s", command);
|
---|
| 657 | log_it("res of it = %s",
|
---|
| 658 | call_program_and_get_last_line_of_output(command));
|
---|
| 659 | sprintf(iso_mnt, "%s",
|
---|
| 660 | call_program_and_get_last_line_of_output(command));
|
---|
| 661 | sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
|
---|
| 662 | write_one_liner_data_file(tmp,
|
---|
| 663 | call_program_and_get_last_line_of_output
|
---|
| 664 | (command));
|
---|
| 665 | log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
|
---|
| 666 | sprintf(iso_tmp, "%s", bkpinfo->isodir);
|
---|
| 667 | if (strlen(iso_tmp) < strlen(iso_mnt)) {
|
---|
| 668 | iso_path[0] = '\0';
|
---|
| 669 | } else {
|
---|
| 670 | sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
|
---|
| 671 | }
|
---|
| 672 | sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
|
---|
| 673 | write_one_liner_data_file(tmp, iso_path);
|
---|
| 674 | log_it("isodir: %s", iso_path);
|
---|
[148] | 675 | sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
|
---|
| 676 | write_one_liner_data_file(tmp, bkpinfo->prefix);
|
---|
| 677 | log_it("iso-prefix: %s", bkpinfo->prefix);
|
---|
[1] | 678 |
|
---|
| 679 | /* End patch */
|
---|
[128] | 680 | } // end of iso code
|
---|
[1] | 681 |
|
---|
[128] | 682 | if (bkpinfo->backup_media_type == nfs) {
|
---|
| 683 | strcpy(hostname, bkpinfo->nfs_mount);
|
---|
| 684 | colon = strchr(hostname, ':');
|
---|
| 685 | if (!colon) {
|
---|
| 686 | log_it("nfs mount doesn't have a colon in it");
|
---|
| 687 | retval++;
|
---|
| 688 | } else {
|
---|
| 689 | struct hostent *hent;
|
---|
[1] | 690 |
|
---|
[128] | 691 | *colon = '\0';
|
---|
| 692 | hent = gethostbyname(hostname);
|
---|
| 693 | if (!hent) {
|
---|
| 694 | log_it("Can't resolve NFS mount (%s): %s", hostname,
|
---|
| 695 | hstrerror(h_errno));
|
---|
| 696 | retval++;
|
---|
| 697 | } else {
|
---|
| 698 | strcpy(ip_address, inet_ntoa
|
---|
| 699 | ((struct in_addr)
|
---|
| 700 | *((struct in_addr *) hent->h_addr)));
|
---|
| 701 | strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
|
---|
| 702 | strcpy(bkpinfo->nfs_mount, ip_address);
|
---|
| 703 | }
|
---|
| 704 | }
|
---|
| 705 | store_nfs_config(bkpinfo);
|
---|
| 706 | }
|
---|
[1] | 707 |
|
---|
[128] | 708 | log_it("Finished processing incoming params");
|
---|
| 709 | if (retval) {
|
---|
| 710 | fprintf(stderr, "Type 'man mondoarchive' for help.\n");
|
---|
| 711 | }
|
---|
| 712 | sprintf(tmp, "%s", MONDO_TMPISOS); /* added #define 22 apr 2002 */
|
---|
| 713 | if (does_file_exist(tmp)) {
|
---|
| 714 | unlink(tmp);
|
---|
| 715 | }
|
---|
| 716 | if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
|
---|
| 717 | log_it("tmpdir or scratchdir are blank/missing");
|
---|
| 718 | retval++;
|
---|
| 719 | }
|
---|
| 720 | if (bkpinfo->include_paths[0] == '\0') {
|
---|
| 721 | // fatal_error ("Why no backup path?");
|
---|
| 722 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 723 | }
|
---|
| 724 | chmod(bkpinfo->scratchdir, 0700);
|
---|
| 725 | chmod(bkpinfo->tmpdir, 0700);
|
---|
| 726 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
[1080] | 727 | mr_free(mtpt);
|
---|
| 728 | mr_free(extra_cdrom_params);
|
---|
| 729 | mr_free(mondo_mkisofs_sz);
|
---|
| 730 | mr_free(command);
|
---|
| 731 | mr_free(hostname);
|
---|
| 732 | mr_free(ip_address);
|
---|
| 733 | mr_free(cdr_exe);
|
---|
| 734 | mr_free(tmp);
|
---|
| 735 | mr_free(iso_dev);
|
---|
| 736 | mr_free(iso_mnt);
|
---|
| 737 | mr_free(iso_tmp);
|
---|
| 738 | mr_free(iso_path);
|
---|
[128] | 739 | return (retval);
|
---|
[1] | 740 | }
|
---|
| 741 |
|
---|
| 742 |
|
---|
| 743 |
|
---|
| 744 | /**
|
---|
| 745 | * Do some miscellaneous setup tasks to be performed before filling @c bkpinfo.
|
---|
| 746 | * Seeds the random-number generator, loads important modules, checks the sanity
|
---|
| 747 | * of the user's Linux distribution, and deletes logfile.
|
---|
| 748 | * @param bkpinfo The backup information structure. Will be initialized.
|
---|
| 749 | * @return number of errors (0 for success)
|
---|
| 750 | */
|
---|
| 751 | int pre_param_configuration(struct s_bkpinfo *bkpinfo)
|
---|
| 752 | {
|
---|
[128] | 753 | int res = 0;
|
---|
[1] | 754 |
|
---|
[128] | 755 | make_hole_for_dir(MNT_CDROM);
|
---|
| 756 | assert(bkpinfo != NULL);
|
---|
| 757 | srandom((unsigned long) (time(NULL)));
|
---|
| 758 | insmod_crucial_modules();
|
---|
| 759 | reset_bkpinfo(bkpinfo); // also sets defaults ('/'=backup path, 3=compression level)
|
---|
| 760 | if (bkpinfo->disaster_recovery) {
|
---|
| 761 | if (!does_nonMS_partition_exist()) {
|
---|
| 762 | fatal_error
|
---|
| 763 | ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
|
---|
| 764 | }
|
---|
| 765 | }
|
---|
[1] | 766 |
|
---|
[128] | 767 | unlink(MONDO_TRACEFILE);
|
---|
| 768 | run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
|
---|
| 769 | if (find_and_store_mondoarchives_home(g_mondo_home)) {
|
---|
| 770 | fprintf(stderr,
|
---|
| 771 | "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
|
---|
| 772 | res++;
|
---|
| 773 | return (res);
|
---|
| 774 | }
|
---|
| 775 | res += some_basic_system_sanity_checks();
|
---|
| 776 | if (res) {
|
---|
| 777 | log_it("Your distribution did not pass Mondo's sanity test.");
|
---|
| 778 | }
|
---|
| 779 | g_current_media_number = 1;
|
---|
| 780 | bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
|
---|
| 781 | return (res);
|
---|
[1] | 782 | }
|
---|
| 783 |
|
---|
| 784 |
|
---|
| 785 |
|
---|
| 786 |
|
---|
| 787 | /**
|
---|
| 788 | * Reset all fields of the backup information structure to a sensible default.
|
---|
| 789 | * @param bkpinfo The @c bkpinfo to reset.
|
---|
| 790 | */
|
---|
[128] | 791 | void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 792 | {
|
---|
[128] | 793 | int i;
|
---|
[1] | 794 |
|
---|
[128] | 795 | log_msg(1, "Hi");
|
---|
| 796 | assert(bkpinfo != NULL);
|
---|
| 797 | memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
|
---|
| 798 | bkpinfo->manual_cd_tray = FALSE;
|
---|
| 799 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
| 800 | bkpinfo->media_device[0] = '\0';
|
---|
| 801 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 802 | bkpinfo->media_size[i] = -1;
|
---|
| 803 | }
|
---|
| 804 | bkpinfo->boot_loader = '\0';
|
---|
| 805 | bkpinfo->boot_device[0] = '\0';
|
---|
| 806 | bkpinfo->zip_exe[0] = '\0';
|
---|
| 807 | bkpinfo->zip_suffix[0] = '\0';
|
---|
| 808 | bkpinfo->restore_path[0] = '\0';
|
---|
| 809 | bkpinfo->use_lzo = FALSE;
|
---|
[998] | 810 | bkpinfo->use_gzip = FALSE;
|
---|
[128] | 811 | bkpinfo->do_not_compress_these[0] = '\0';
|
---|
| 812 | bkpinfo->verify_data = FALSE;
|
---|
| 813 | bkpinfo->backup_data = FALSE;
|
---|
| 814 | bkpinfo->restore_data = FALSE;
|
---|
| 815 | bkpinfo->disaster_recovery =
|
---|
| 816 | (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
|
---|
| 817 | if (bkpinfo->disaster_recovery) {
|
---|
| 818 | strcpy(bkpinfo->isodir, "/");
|
---|
| 819 | } else {
|
---|
[541] | 820 | strcpy(bkpinfo->isodir, "/root/images/mondo");
|
---|
[128] | 821 | }
|
---|
[148] | 822 | strcpy(bkpinfo->prefix, STD_PREFIX);
|
---|
[1] | 823 |
|
---|
[128] | 824 | bkpinfo->scratchdir[0] = '\0';
|
---|
| 825 | bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
|
---|
| 826 | sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore
|
---|
| 827 | bkpinfo->optimal_set_size = 0;
|
---|
| 828 | bkpinfo->backup_media_type = none;
|
---|
| 829 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 830 | bkpinfo->exclude_paths[0] = '\0';
|
---|
| 831 | bkpinfo->call_before_iso[0] = '\0';
|
---|
| 832 | bkpinfo->call_make_iso[0] = '\0';
|
---|
| 833 | bkpinfo->call_burn_iso[0] = '\0';
|
---|
| 834 | bkpinfo->call_after_iso[0] = '\0';
|
---|
| 835 | bkpinfo->image_devs[0] = '\0';
|
---|
| 836 | bkpinfo->postnuke_tarball[0] = '\0';
|
---|
| 837 | bkpinfo->kernel_path[0] = '\0';
|
---|
| 838 | bkpinfo->nfs_mount[0] = '\0';
|
---|
| 839 | bkpinfo->nfs_remote_dir[0] = '\0';
|
---|
| 840 | bkpinfo->wipe_media_first = FALSE;
|
---|
| 841 | bkpinfo->differential = FALSE;
|
---|
| 842 | bkpinfo->cdrw_speed = 0;
|
---|
[1] | 843 | // patch by Herman Kuster
|
---|
[128] | 844 | bkpinfo->differential = 0;
|
---|
[1] | 845 | // patch end
|
---|
[128] | 846 | bkpinfo->compression_level = 3;
|
---|
[1] | 847 | }
|
---|
| 848 |
|
---|
| 849 |
|
---|
| 850 |
|
---|
| 851 |
|
---|
| 852 | /**
|
---|
| 853 | * Get the remaining free space (in MB) on @p partition.
|
---|
| 854 | * @param partition The partition to check free space on (either a device or a mountpoint).
|
---|
| 855 | * @return The free space on @p partition, in MB.
|
---|
| 856 | */
|
---|
[128] | 857 | long free_space_on_given_partition(char *partition)
|
---|
[1] | 858 | {
|
---|
[128] | 859 | char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
|
---|
| 860 | long res;
|
---|
[1] | 861 |
|
---|
[128] | 862 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
[1] | 863 |
|
---|
[305] | 864 | sprintf(command, "df -m -P %s &> /dev/null", partition);
|
---|
[128] | 865 | if (system(command)) {
|
---|
| 866 | return (-1);
|
---|
| 867 | } // partition does not exist
|
---|
[305] | 868 | sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
|
---|
[128] | 869 | partition);
|
---|
| 870 | strcpy(out_sz, call_program_and_get_last_line_of_output(command));
|
---|
| 871 | if (strlen(out_sz) == 0) {
|
---|
| 872 | return (-1);
|
---|
| 873 | } // error within df, probably
|
---|
| 874 | res = atol(out_sz);
|
---|
| 875 | return (res);
|
---|
[1] | 876 | }
|
---|
| 877 |
|
---|
| 878 |
|
---|
| 879 |
|
---|
| 880 | /**
|
---|
| 881 | * Check the user's system for sanity. Checks performed:
|
---|
| 882 | * - make sure user has enough RAM (32mb required, 64mb recommended)
|
---|
| 883 | * - make sure user has enough free space in @c /
|
---|
| 884 | * - check kernel for ramdisk support
|
---|
| 885 | * - make sure afio, cdrecord, mkisofs, bzip2, awk, md5sum, strings, mindi, and buffer exist
|
---|
| 886 | * - make sure CD-ROM is unmounted
|
---|
| 887 | * - make sure /etc/modules.conf exists
|
---|
| 888 | * - make sure user's mountlist is OK by running <tt>mindi --makemountlist</tt>
|
---|
| 889 | *
|
---|
| 890 | * @return number of problems with the user's setup (0 for success)
|
---|
| 891 | */
|
---|
[128] | 892 | int some_basic_system_sanity_checks()
|
---|
[1] | 893 | {
|
---|
| 894 |
|
---|
[128] | 895 | /*@ buffers ************ */
|
---|
| 896 | char tmp[MAX_STR_LEN];
|
---|
| 897 | // char command[MAX_STR_LEN];
|
---|
[1] | 898 |
|
---|
[128] | 899 | /*@ int's *************** */
|
---|
| 900 | int retval = 0;
|
---|
| 901 | long Lres;
|
---|
[1] | 902 |
|
---|
| 903 |
|
---|
[128] | 904 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 905 | "Checking sanity of your Linux distribution");
|
---|
[1] | 906 | #ifndef __FreeBSD__
|
---|
[128] | 907 | if (system("which mkfs.vfat &> /dev/null")
|
---|
| 908 | && !system("which mkfs.msdos &> /dev/null")) {
|
---|
| 909 | log_it
|
---|
| 910 | ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
|
---|
| 911 | run_program_and_log_output
|
---|
| 912 | ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
|
---|
| 913 | }
|
---|
| 914 | strcpy(tmp,
|
---|
| 915 | call_program_and_get_last_line_of_output
|
---|
| 916 | ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
|
---|
| 917 | if (atol(tmp) < 35000) {
|
---|
| 918 | retval++;
|
---|
[541] | 919 | log_to_screen("You must have at least 32MB of RAM to use Mondo.");
|
---|
[128] | 920 | }
|
---|
| 921 | if (atol(tmp) < 66000) {
|
---|
| 922 | log_to_screen
|
---|
[541] | 923 | ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
|
---|
[128] | 924 | }
|
---|
[1] | 925 | #endif
|
---|
| 926 |
|
---|
[1044] | 927 | Lres = free_space_on_given_partition("/var/cache");
|
---|
[128] | 928 | log_it("Free space on given partition = %ld MB", Lres);
|
---|
[1] | 929 |
|
---|
[128] | 930 | if (Lres < 50) {
|
---|
[1044] | 931 | fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner.");
|
---|
[128] | 932 | }
|
---|
[1] | 933 |
|
---|
[128] | 934 | if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
|
---|
| 935 | retval++;
|
---|
| 936 | log_to_screen
|
---|
| 937 | ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
|
---|
| 938 | fatal_error
|
---|
| 939 | ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
|
---|
| 940 | }
|
---|
[1] | 941 | #ifndef __FreeBSD__
|
---|
[128] | 942 | if (run_program_and_log_output
|
---|
[273] | 943 | ("grep ramdisk /proc/devices", FALSE)) {
|
---|
[128] | 944 | if (!ask_me_yes_or_no
|
---|
[541] | 945 | ("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))
|
---|
[128] | 946 | {
|
---|
| 947 | // retval++;
|
---|
| 948 | log_to_screen
|
---|
[541] | 949 | ("It looks as if your kernel lacks ramdisk and initrd support.");
|
---|
[128] | 950 | log_to_screen
|
---|
[541] | 951 | ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
|
---|
[128] | 952 | }
|
---|
| 953 | }
|
---|
[1] | 954 | #endif
|
---|
[128] | 955 | retval += whine_if_not_found(MKE2FS_OR_NEWFS);
|
---|
| 956 | retval += whine_if_not_found("mkisofs");
|
---|
| 957 | if (system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 958 | retval += whine_if_not_found("cdrecord");
|
---|
| 959 | }
|
---|
| 960 | retval += whine_if_not_found("bzip2");
|
---|
[998] | 961 | retval += whine_if_not_found("gzip");
|
---|
[128] | 962 | retval += whine_if_not_found("awk");
|
---|
| 963 | retval += whine_if_not_found("md5sum");
|
---|
| 964 | retval += whine_if_not_found("strings");
|
---|
| 965 | retval += whine_if_not_found("mindi");
|
---|
| 966 | retval += whine_if_not_found("buffer");
|
---|
[1] | 967 |
|
---|
[128] | 968 | // abort if Windows partition but no ms-sys and parted
|
---|
| 969 | if (!run_program_and_log_output
|
---|
[680] | 970 | ("mount | grep -w vfat | grep -vE \"/dev/fd|nexdisk\"", 0)
|
---|
[128] | 971 | ||
|
---|
| 972 | !run_program_and_log_output
|
---|
[680] | 973 | ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
|
---|
[541] | 974 | log_to_screen("I think you have a Windows 9x partition.");
|
---|
[128] | 975 | retval += whine_if_not_found("parted");
|
---|
[1] | 976 | #ifndef __IA64__
|
---|
[128] | 977 | /* IA64 always has one vfat partition for EFI even without Windows */
|
---|
| 978 | // retval +=
|
---|
| 979 | if (!find_home_of_exe("ms-sys")) {
|
---|
[541] | 980 | log_to_screen("Please install ms-sys just in case.");
|
---|
[128] | 981 | }
|
---|
| 982 | #endif
|
---|
[1] | 983 | }
|
---|
| 984 |
|
---|
[128] | 985 | if (!find_home_of_exe("cmp")) {
|
---|
| 986 | if (!find_home_of_exe("true")) {
|
---|
| 987 | whine_if_not_found("cmp");
|
---|
| 988 | } else {
|
---|
| 989 | log_to_screen
|
---|
[541] | 990 | ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
|
---|
[128] | 991 | if (run_program_and_log_output
|
---|
| 992 | ("cp -f `which true` /usr/bin/cmp", 0)) {
|
---|
| 993 | fatal_error("Failed to create dummy 'cmp' file.");
|
---|
| 994 | }
|
---|
| 995 | }
|
---|
[1] | 996 | }
|
---|
[128] | 997 | run_program_and_log_output
|
---|
| 998 | ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
|
---|
| 999 | strcpy(tmp,
|
---|
| 1000 | call_program_and_get_last_line_of_output
|
---|
| 1001 | ("mount | grep -E \"cdr(om|w)\""));
|
---|
| 1002 | if (strcmp("", tmp)) {
|
---|
| 1003 | if (strstr(tmp, "autofs")) {
|
---|
| 1004 | log_to_screen
|
---|
[541] | 1005 | ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
|
---|
[128] | 1006 | log_to_screen
|
---|
[541] | 1007 | ("if a CD actually is inserted. If a CD is inserted, please");
|
---|
| 1008 | log_to_screen("eject it. Thank you.");
|
---|
[128] | 1009 | log_it
|
---|
| 1010 | ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
|
---|
| 1011 | } else
|
---|
| 1012 | if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
|
---|
| 1013 | retval++;
|
---|
| 1014 | fatal_error
|
---|
| 1015 | ("Your CD-ROM drive is mounted. Please unmount it.");
|
---|
| 1016 | }
|
---|
| 1017 | }
|
---|
[1] | 1018 | #ifndef __FreeBSD__
|
---|
[128] | 1019 | if (!does_file_exist("/etc/modules.conf")) {
|
---|
| 1020 | if (does_file_exist("/etc/conf.modules")) {
|
---|
| 1021 | log_it("Linking /etc/modules.conf to /etc/conf.modules");
|
---|
| 1022 | run_program_and_log_output
|
---|
| 1023 | ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
|
---|
| 1024 | } else if (does_file_exist("/etc/modprobe.d")) {
|
---|
| 1025 | log_it
|
---|
| 1026 | ("Directory /etc/modprobe.d found. mindi will use its contents.");
|
---|
| 1027 | } else if (does_file_exist("/etc/modprobe.conf")) {
|
---|
| 1028 | log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
|
---|
| 1029 | run_program_and_log_output
|
---|
| 1030 | ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
|
---|
| 1031 | } else {
|
---|
| 1032 | retval++;
|
---|
| 1033 | log_to_screen
|
---|
[541] | 1034 | ("Please find out what happened to /etc/modules.conf");
|
---|
[128] | 1035 | }
|
---|
[1] | 1036 | }
|
---|
| 1037 | #endif
|
---|
| 1038 |
|
---|
[128] | 1039 | run_program_and_log_output("cat /etc/fstab", 5);
|
---|
[1] | 1040 | #ifdef __FreeBSD__
|
---|
[128] | 1041 | run_program_and_log_output("vinum printconfig", 5);
|
---|
[1] | 1042 | #else
|
---|
[128] | 1043 | run_program_and_log_output("cat /etc/raidtab", 5);
|
---|
[1] | 1044 | #endif
|
---|
| 1045 |
|
---|
[128] | 1046 | if (run_program_and_log_output("mindi -V", 1)) {
|
---|
[541] | 1047 | log_to_screen("Could not ascertain mindi's version number.");
|
---|
[128] | 1048 | log_to_screen
|
---|
[541] | 1049 | ("You have not installed Mondo and/or Mindi properly.");
|
---|
| 1050 | log_to_screen("Please uninstall and reinstall them both.");
|
---|
[128] | 1051 | fatal_error("Please reinstall Mondo and Mindi.");
|
---|
| 1052 | }
|
---|
| 1053 | if (run_program_and_log_output
|
---|
| 1054 | ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
|
---|
| 1055 | log_to_screen
|
---|
[541] | 1056 | ("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
|
---|
[128] | 1057 | log_to_screen
|
---|
[541] | 1058 | ("Please run that command by hand and examine /var/log/mindi.log");
|
---|
[128] | 1059 | log_to_screen
|
---|
[541] | 1060 | ("for more information. Perhaps your /etc/fstab file is insane.");
|
---|
[128] | 1061 | log_to_screen
|
---|
[541] | 1062 | ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
|
---|
[128] | 1063 | retval++;
|
---|
| 1064 | }
|
---|
[1] | 1065 |
|
---|
[196] | 1066 | if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
|
---|
[128] | 1067 | && !does_file_exist("/etc/raidtab")) {
|
---|
| 1068 | log_to_screen
|
---|
[541] | 1069 | ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
|
---|
[558] | 1070 | create_raidtab_from_mdstat("/etc/raidtab");
|
---|
[128] | 1071 | }
|
---|
| 1072 |
|
---|
| 1073 | if (retval) {
|
---|
[541] | 1074 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1075 | } else {
|
---|
[541] | 1076 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1077 | }
|
---|
| 1078 | return (retval);
|
---|
[1] | 1079 | }
|
---|
| 1080 |
|
---|
| 1081 | /**
|
---|
| 1082 | * Retrieve the line containing @p label from the config file.
|
---|
| 1083 | * @param config_file The file to read from, usually @c /tmp/mondo-restore.cfg.
|
---|
| 1084 | * @param label What to read from the file.
|
---|
| 1085 | * @param value Where to put it.
|
---|
| 1086 | * @return 0 for success, 1 for failure.
|
---|
| 1087 | */
|
---|
[128] | 1088 | int read_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1089 | {
|
---|
[128] | 1090 | /*@ buffer ****************************************************** */
|
---|
| 1091 | char command[MAX_STR_LEN * 2];
|
---|
| 1092 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1093 |
|
---|
[128] | 1094 | /*@ end vars *************************************************** */
|
---|
[1] | 1095 |
|
---|
[128] | 1096 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1097 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
| 1098 | if (!does_file_exist(config_file)) {
|
---|
| 1099 | sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
|
---|
| 1100 | config_file);
|
---|
| 1101 | log_to_screen(tmp);
|
---|
| 1102 | value[0] = '\0';
|
---|
| 1103 | return (1);
|
---|
| 1104 | } else if (strstr(value, "/dev/") && strstr(value, "t0")
|
---|
| 1105 | && !strcmp(label, "media-dev")) {
|
---|
| 1106 | log_msg(2, "FYI, I shan't read new value for %s - already got %s",
|
---|
| 1107 | label, value);
|
---|
| 1108 | return (0);
|
---|
| 1109 | } else {
|
---|
[148] | 1110 | sprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",
|
---|
| 1111 | label, config_file);
|
---|
[128] | 1112 | strcpy(value, call_program_and_get_last_line_of_output(command));
|
---|
| 1113 | if (strlen(value) == 0) {
|
---|
| 1114 | return (1);
|
---|
| 1115 | } else {
|
---|
| 1116 | return (0);
|
---|
| 1117 | }
|
---|
[1] | 1118 | }
|
---|
| 1119 | }
|
---|
| 1120 |
|
---|
| 1121 |
|
---|
| 1122 |
|
---|
| 1123 | /**
|
---|
| 1124 | * Remount @c supermount if it was unmounted earlier.
|
---|
| 1125 | */
|
---|
| 1126 | void remount_supermounts_if_necessary()
|
---|
| 1127 | {
|
---|
[128] | 1128 | if (g_remount_cdrom_at_end) {
|
---|
| 1129 | run_program_and_log_output("mount " MNT_CDROM, FALSE);
|
---|
| 1130 | }
|
---|
| 1131 | if (g_remount_floppy_at_end) {
|
---|
| 1132 | run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
|
---|
| 1133 | }
|
---|
[1] | 1134 | }
|
---|
| 1135 |
|
---|
| 1136 | /**
|
---|
| 1137 | * Unmount @c supermount if it's mounted.
|
---|
| 1138 | */
|
---|
| 1139 | void unmount_supermounts_if_necessary()
|
---|
| 1140 | {
|
---|
[128] | 1141 | if (run_program_and_log_output
|
---|
| 1142 | ("mount | grep cdrom | grep super", FALSE) == 0) {
|
---|
| 1143 | g_remount_cdrom_at_end = TRUE;
|
---|
| 1144 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 1145 | }
|
---|
| 1146 | if (run_program_and_log_output
|
---|
| 1147 | ("mount | grep floppy | grep super", FALSE) == 0) {
|
---|
| 1148 | g_remount_floppy_at_end = TRUE;
|
---|
| 1149 | run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
|
---|
| 1150 | }
|
---|
[1] | 1151 | }
|
---|
| 1152 |
|
---|
| 1153 | /**
|
---|
| 1154 | * Whether we had to stop autofs (if so, restart it at end).
|
---|
| 1155 | */
|
---|
[128] | 1156 | bool g_autofs_stopped = FALSE;
|
---|
[1] | 1157 |
|
---|
| 1158 | /**
|
---|
| 1159 | * Path to the autofs initscript ("" if none exists).
|
---|
| 1160 | */
|
---|
| 1161 | char g_autofs_exe[MAX_STR_LEN];
|
---|
| 1162 |
|
---|
| 1163 | /**
|
---|
| 1164 | * Autofs initscript in Xandros Linux distribution.
|
---|
| 1165 | */
|
---|
| 1166 | #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"
|
---|
| 1167 |
|
---|
| 1168 | /**
|
---|
| 1169 | * Autofs initscript in most Linux distributions.
|
---|
| 1170 | */
|
---|
| 1171 | #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"
|
---|
| 1172 |
|
---|
| 1173 | /**
|
---|
| 1174 | * If autofs is mounted, stop it (restart at end).
|
---|
| 1175 | */
|
---|
| 1176 | void stop_autofs_if_necessary()
|
---|
| 1177 | {
|
---|
[128] | 1178 | char tmp[MAX_STR_LEN];
|
---|
| 1179 |
|
---|
| 1180 | g_autofs_exe[0] = '\0';
|
---|
| 1181 | if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
|
---|
| 1182 | strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
|
---|
| 1183 | } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
|
---|
| 1184 | strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
| 1187 | if (!g_autofs_exe[0]) {
|
---|
| 1188 | log_msg(3, "No autofs detected.");
|
---|
| 1189 | } else {
|
---|
| 1190 | log_msg(3, "%s --- autofs detected", g_autofs_exe);
|
---|
[1] | 1191 | // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);
|
---|
[128] | 1192 | sprintf(tmp, "%s stop", g_autofs_exe);
|
---|
| 1193 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 1194 | log_it("Failed to stop autofs - I assume it wasn't running");
|
---|
| 1195 | } else {
|
---|
| 1196 | g_autofs_stopped = TRUE;
|
---|
| 1197 | log_it("Stopped autofs OK");
|
---|
| 1198 | }
|
---|
| 1199 | }
|
---|
[1] | 1200 | }
|
---|
| 1201 |
|
---|
| 1202 | /**
|
---|
| 1203 | * If autofs was stopped earlier, restart it.
|
---|
| 1204 | */
|
---|
| 1205 | void restart_autofs_if_necessary()
|
---|
| 1206 | {
|
---|
[128] | 1207 | char tmp[MAX_STR_LEN];
|
---|
| 1208 |
|
---|
| 1209 | if (!g_autofs_stopped || !g_autofs_exe[0]) {
|
---|
| 1210 | log_msg(3, "No autofs detected.");
|
---|
| 1211 | return;
|
---|
| 1212 | }
|
---|
| 1213 | sprintf(tmp, "%s start", g_autofs_exe);
|
---|
| 1214 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 1215 | log_it("Failed to start autofs");
|
---|
| 1216 | } else {
|
---|
| 1217 | g_autofs_stopped = FALSE;
|
---|
| 1218 | log_it("Started autofs OK");
|
---|
| 1219 | }
|
---|
[1] | 1220 | }
|
---|
| 1221 |
|
---|
| 1222 |
|
---|
| 1223 | /**
|
---|
| 1224 | * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
|
---|
| 1225 | */
|
---|
| 1226 | void mount_boot_if_necessary()
|
---|
| 1227 | {
|
---|
[128] | 1228 | char tmp[MAX_STR_LEN];
|
---|
| 1229 | char command[MAX_STR_LEN];
|
---|
[1] | 1230 |
|
---|
[128] | 1231 | log_msg(1, "Started sub");
|
---|
| 1232 | log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
|
---|
| 1233 | g_boot_mountpt[0] = '\0';
|
---|
| 1234 | log_msg(4, "Done. Great. Seeting command to something");
|
---|
| 1235 | strcpy(command,
|
---|
[911] | 1236 | "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
|
---|
[128] | 1237 | log_msg(4, "Cool. Command = '%s'", command);
|
---|
| 1238 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 1239 | log_msg(4, "tmp = '%s'", tmp);
|
---|
| 1240 | if (tmp[0]) {
|
---|
| 1241 | log_it("/boot is at %s according to /etc/fstab", tmp);
|
---|
| 1242 | if (strstr(tmp, "LABEL=")) {
|
---|
| 1243 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1244 | strcpy(g_boot_mountpt, "/boot");
|
---|
| 1245 | log_msg(1, "Mounted /boot");
|
---|
| 1246 | } else {
|
---|
| 1247 | log_it("...ignored cos it's a label :-)");
|
---|
| 1248 | }
|
---|
| 1249 | } else {
|
---|
[911] | 1250 | sprintf(command, "mount | grep -E '^%s'", tmp);
|
---|
[128] | 1251 | log_msg(3, "command = %s", command);
|
---|
| 1252 | if (run_program_and_log_output(command, 5)) {
|
---|
| 1253 | strcpy(g_boot_mountpt, tmp);
|
---|
| 1254 | sprintf(tmp,
|
---|
| 1255 | "%s (your /boot partition) is not mounted. I'll mount it before backing up",
|
---|
| 1256 | g_boot_mountpt);
|
---|
| 1257 | log_it(tmp);
|
---|
| 1258 | sprintf(tmp, "mount %s", g_boot_mountpt);
|
---|
| 1259 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1260 | g_boot_mountpt[0] = '\0';
|
---|
| 1261 | log_msg(1, "Plan B");
|
---|
| 1262 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1263 | strcpy(g_boot_mountpt, "/boot");
|
---|
| 1264 | log_msg(1, "Plan B worked");
|
---|
| 1265 | } else {
|
---|
| 1266 | log_msg(1,
|
---|
| 1267 | "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
|
---|
| 1268 | }
|
---|
| 1269 | }
|
---|
| 1270 | }
|
---|
| 1271 | }
|
---|
[1] | 1272 | }
|
---|
[128] | 1273 | log_msg(1, "Ended sub");
|
---|
[1] | 1274 | }
|
---|
| 1275 |
|
---|
| 1276 |
|
---|
| 1277 | /**
|
---|
| 1278 | * If we mounted /boot earlier, unmount it.
|
---|
| 1279 | */
|
---|
| 1280 | void unmount_boot_if_necessary()
|
---|
| 1281 | {
|
---|
[128] | 1282 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1283 |
|
---|
[128] | 1284 | log_msg(3, "starting");
|
---|
| 1285 | if (g_boot_mountpt[0]) {
|
---|
| 1286 | sprintf(tmp, "umount %s", g_boot_mountpt);
|
---|
| 1287 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1288 | log_it("WARNING - unable to unmount /boot");
|
---|
| 1289 | }
|
---|
| 1290 | }
|
---|
| 1291 | log_msg(3, "leaving");
|
---|
[1] | 1292 | }
|
---|
| 1293 |
|
---|
| 1294 |
|
---|
| 1295 |
|
---|
| 1296 | /**
|
---|
| 1297 | * Write a line to a configuration file. Writes a line of the form,
|
---|
| 1298 | * @c label @c value.
|
---|
| 1299 | * @param config_file The file to write to. Usually @c mondo-restore.cfg.
|
---|
| 1300 | * @param label What to call this bit of data you're writing.
|
---|
| 1301 | * @param value The bit of data you're writing.
|
---|
| 1302 | * @return 0 for success, 1 for failure.
|
---|
| 1303 | */
|
---|
[128] | 1304 | int write_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1305 | {
|
---|
[128] | 1306 | /*@ buffers ***************************************************** */
|
---|
| 1307 | char command[MAX_STR_LEN * 2];
|
---|
| 1308 | char tempfile[MAX_STR_LEN];
|
---|
| 1309 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1310 |
|
---|
| 1311 |
|
---|
[128] | 1312 | /*@ end vars *************************************************** */
|
---|
| 1313 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1314 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
| 1315 | assert(value != NULL);
|
---|
| 1316 | if (!does_file_exist(config_file)) {
|
---|
| 1317 | sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
|
---|
| 1318 | config_file);
|
---|
| 1319 | log_to_screen(tmp);
|
---|
| 1320 | return (1);
|
---|
| 1321 | }
|
---|
| 1322 | strcpy(tempfile,
|
---|
| 1323 | call_program_and_get_last_line_of_output
|
---|
| 1324 | ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
|
---|
| 1325 | if (does_file_exist(config_file)) {
|
---|
[911] | 1326 | sprintf(command, "grep -vE '^%s .*$' %s > %s",
|
---|
[148] | 1327 | label, config_file, tempfile);
|
---|
[128] | 1328 | paranoid_system(command);
|
---|
| 1329 | }
|
---|
| 1330 | sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
|
---|
| 1331 | paranoid_system(command);
|
---|
| 1332 | sprintf(command, "mv -f %s %s", tempfile, config_file);
|
---|
| 1333 | paranoid_system(command);
|
---|
| 1334 | unlink(tempfile);
|
---|
| 1335 | return (0);
|
---|
[1] | 1336 | }
|
---|
| 1337 |
|
---|
[541] | 1338 |
|
---|
[1] | 1339 | /**
|
---|
[541] | 1340 | * The standard log_debug_msg() (log_msg() also due to a macro). Writes some describing
|
---|
| 1341 | * information to the logfile.
|
---|
| 1342 | */
|
---|
| 1343 | void standard_log_debug_msg(int debug_level, const char *szFile,
|
---|
| 1344 | const char *szFunction, int nLine,
|
---|
| 1345 | const char *fmt, ...)
|
---|
| 1346 | {
|
---|
| 1347 | va_list args;
|
---|
| 1348 | int i;
|
---|
| 1349 | static int depth = 0;
|
---|
| 1350 | char *tmp;
|
---|
| 1351 | FILE *fout;
|
---|
| 1352 |
|
---|
| 1353 | if (depth > 5) {
|
---|
| 1354 | depth--;
|
---|
| 1355 | return;
|
---|
| 1356 | }
|
---|
| 1357 | depth++;
|
---|
| 1358 |
|
---|
| 1359 | malloc_string(tmp);
|
---|
| 1360 |
|
---|
| 1361 | if (debug_level <= g_loglevel) {
|
---|
| 1362 | va_start(args, fmt);
|
---|
| 1363 | if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
|
---|
| 1364 | return;
|
---|
| 1365 | } // fatal_error("Failed to openout to logfile - sheesh..."); }
|
---|
| 1366 |
|
---|
| 1367 | // add tabs to distinguish log levels
|
---|
| 1368 | if (debug_level > 0) {
|
---|
| 1369 | for (i = 1; i < debug_level; i++)
|
---|
| 1370 | fprintf(fout, "\t");
|
---|
| 1371 | if (getpid() == g_main_pid)
|
---|
| 1372 | fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
|
---|
| 1373 | nLine);
|
---|
| 1374 | else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
|
---|
| 1375 | fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
|
---|
| 1376 | nLine);
|
---|
| 1377 | else
|
---|
| 1378 | fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
|
---|
| 1379 | szFunction, nLine);
|
---|
| 1380 | }
|
---|
| 1381 | vfprintf(fout, fmt, args);
|
---|
| 1382 |
|
---|
| 1383 | // do not slow down the progran if standard debug level
|
---|
| 1384 | // must be enabled: if no flush, the log won't be up-to-date if there
|
---|
| 1385 | // is a segfault
|
---|
| 1386 | //if (g_dwDebugLevel != 1)
|
---|
| 1387 |
|
---|
| 1388 | va_end(args);
|
---|
| 1389 | fprintf(fout, "\n");
|
---|
| 1390 | paranoid_fclose(fout);
|
---|
| 1391 | }
|
---|
| 1392 | depth--;
|
---|
[1080] | 1393 | mr_free(tmp);
|
---|
[541] | 1394 | }
|
---|
| 1395 |
|
---|
| 1396 | /**
|
---|
| 1397 | * Function pointer to the @c log_debug_msg function to use. Points to standard_log_debug_msg() by default.
|
---|
| 1398 | */
|
---|
| 1399 | void (*log_debug_msg) (int, const char *, const char *, int, const char *,
|
---|
| 1400 | ...) = standard_log_debug_msg;
|
---|
| 1401 |
|
---|
| 1402 |
|
---|
| 1403 | /**
|
---|
[1] | 1404 | * If @p y, malloc @p x, else free @p x.
|
---|
| 1405 | * @bug This function seems orphaned. Please remove.
|
---|
| 1406 | */
|
---|
[1080] | 1407 | #define do_alloc_or_free_depending(x,y) { if(y) {x=mr_malloc(MAX_STR_LEN);} else {mr_free(x);} }
|
---|
[1] | 1408 |
|
---|
| 1409 | /**
|
---|
| 1410 | * Allocate or free important globals, depending on @p mal.
|
---|
| 1411 | * @param mal If TRUE, malloc; if FALSE, free.
|
---|
| 1412 | */
|
---|
| 1413 | void do_libmondo_global_strings_thing(int mal)
|
---|
| 1414 | {
|
---|
[128] | 1415 | if (mal) {
|
---|
| 1416 | iamhere("Malloc'ing globals");
|
---|
| 1417 | malloc_string(g_boot_mountpt);
|
---|
| 1418 | malloc_string(g_mondo_home);
|
---|
| 1419 | malloc_string(g_tmpfs_mountpt);
|
---|
| 1420 | malloc_string(g_erase_tmpdir_and_scratchdir);
|
---|
| 1421 | malloc_string(g_serial_string);
|
---|
| 1422 | malloc_string(g_magicdev_command);
|
---|
| 1423 | } else {
|
---|
| 1424 | iamhere("Freeing globals");
|
---|
[1080] | 1425 | mr_free(g_boot_mountpt);
|
---|
| 1426 | mr_free(g_mondo_home);
|
---|
| 1427 | mr_free(g_tmpfs_mountpt);
|
---|
| 1428 | mr_free(g_erase_tmpdir_and_scratchdir);
|
---|
| 1429 | mr_free(g_serial_string);
|
---|
| 1430 | mr_free(g_magicdev_command);
|
---|
[128] | 1431 | }
|
---|
[541] | 1432 |
|
---|
| 1433 | /*
|
---|
| 1434 | char**list_of_arrays[] = {
|
---|
| 1435 | &g_boot_mountpt,
|
---|
| 1436 | &g_mondo_home,
|
---|
| 1437 | &g_tmpfs_mountpt,
|
---|
| 1438 | &g_erase_tmpdir_and_scratchdir,
|
---|
| 1439 | &g_serial_string,
|
---|
| 1440 | &g_magicdev_command,
|
---|
| 1441 | NULL};
|
---|
| 1442 |
|
---|
| 1443 | char**ppcurr;
|
---|
| 1444 | int i;
|
---|
| 1445 |
|
---|
| 1446 | for(i=0;list_of_arrays[i];i++)
|
---|
| 1447 | {
|
---|
| 1448 | log_msg(5, "Allocating %d", i);
|
---|
| 1449 | ppcurr = list_of_arrays[i];
|
---|
| 1450 | if (mal)
|
---|
| 1451 | { *ppcurr = malloc(MAX_STR_LEN); }
|
---|
| 1452 | else
|
---|
| 1453 | {
|
---|
| 1454 | if (*ppcurr)
|
---|
| 1455 | {
|
---|
| 1456 | free(*ppcurr);
|
---|
| 1457 | }
|
---|
| 1458 | }
|
---|
| 1459 | }
|
---|
| 1460 | log_msg(5, "Returning");
|
---|
| 1461 | */
|
---|
[1] | 1462 | }
|
---|
| 1463 |
|
---|
| 1464 | /**
|
---|
| 1465 | * Allocate important globals.
|
---|
| 1466 | * @see do_libmondo_global_strings_thing
|
---|
| 1467 | */
|
---|
| 1468 | void malloc_libmondo_global_strings(void)
|
---|
| 1469 | {
|
---|
[128] | 1470 | do_libmondo_global_strings_thing(1);
|
---|
[1] | 1471 | }
|
---|
| 1472 |
|
---|
| 1473 | /**
|
---|
| 1474 | * Free important globals.
|
---|
| 1475 | * @see do_libmondo_global_strings_thing
|
---|
| 1476 | */
|
---|
| 1477 | void free_libmondo_global_strings(void)
|
---|
| 1478 | {
|
---|
[128] | 1479 | do_libmondo_global_strings_thing(0);
|
---|
[1] | 1480 | }
|
---|
| 1481 |
|
---|
| 1482 |
|
---|
| 1483 |
|
---|
| 1484 | /**
|
---|
| 1485 | * Stop @c magicdev if it's running.
|
---|
| 1486 | * The command used to start it is saved in @p g_magicdev_command.
|
---|
| 1487 | */
|
---|
| 1488 | void stop_magicdev_if_necessary()
|
---|
| 1489 | {
|
---|
[128] | 1490 | strcpy(g_magicdev_command,
|
---|
| 1491 | call_program_and_get_last_line_of_output
|
---|
| 1492 | ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
|
---|
| 1493 | if (g_magicdev_command[0]) {
|
---|
| 1494 | log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
|
---|
| 1495 | paranoid_system("killall magicdev");
|
---|
| 1496 | }
|
---|
[1] | 1497 | }
|
---|
| 1498 |
|
---|
| 1499 |
|
---|
| 1500 | /**
|
---|
| 1501 | * Restart magicdev if it was stopped.
|
---|
| 1502 | */
|
---|
| 1503 | void restart_magicdev_if_necessary()
|
---|
| 1504 | {
|
---|
[128] | 1505 | char *tmp;
|
---|
| 1506 |
|
---|
| 1507 | malloc_string(tmp);
|
---|
| 1508 | if (g_magicdev_command && g_magicdev_command[0]) {
|
---|
| 1509 | sprintf(tmp, "%s &", g_magicdev_command);
|
---|
| 1510 | paranoid_system(tmp);
|
---|
| 1511 | }
|
---|
[1080] | 1512 | mr_free(tmp);
|
---|
[1] | 1513 | }
|
---|
| 1514 |
|
---|
| 1515 | /* @} - end of utilityGroup */
|
---|