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