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