[58] | 1 | /* $Id: libmondo-tools.c 1185 2007-02-19 00:51:26Z 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"
|
---|
[1081] | 11 | #include "mr_mem.h"
|
---|
[1185] | 12 | #include "mr_msg.h"
|
---|
[1106] | 13 | #include "mr_file.h"
|
---|
| 14 |
|
---|
[1] | 15 | #include "mondostructures.h"
|
---|
| 16 | #include "libmondo-tools.h"
|
---|
[507] | 17 | #include "newt-specific-EXT.h"
|
---|
[1] | 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>
|
---|
[146] | 24 | #ifndef S_SPLINT_S
|
---|
[1] | 25 | #include <arpa/inet.h>
|
---|
[146] | 26 | #endif
|
---|
[1] | 27 |
|
---|
| 28 | /*@unused@*/
|
---|
[49] | 29 | //static char cvsid[] = "$Id: libmondo-tools.c 1185 2007-02-19 00:51:26Z bruno $";
|
---|
[1] | 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 | */
|
---|
[49] | 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.
|
---|
[1] | 45 | double g_kernel_version;
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
[94] | 48 | * The place where /boot is mounted. - Used locally only
|
---|
[1] | 49 | */
|
---|
[94] | 50 | static char *g_boot_mountpt = NULL;
|
---|
[1] | 51 |
|
---|
| 52 | /**
|
---|
| 53 | * The location of Mondo's home directory.
|
---|
| 54 | */
|
---|
[49] | 55 | char *g_mondo_home = NULL;
|
---|
[1] | 56 |
|
---|
| 57 | /**
|
---|
| 58 | * The serial string (used to differentiate between backups) of the current backup.
|
---|
| 59 | */
|
---|
[49] | 60 | char *g_serial_string = NULL;
|
---|
[1] | 61 |
|
---|
| 62 | /**
|
---|
| 63 | * The location where tmpfs is mounted, or "" if it's not mounted.
|
---|
| 64 | */
|
---|
[49] | 65 | char *g_tmpfs_mountpt = NULL;
|
---|
| 66 | char *g_magicdev_command = NULL;
|
---|
[1] | 67 |
|
---|
| 68 | /**
|
---|
| 69 | * The default maximum level to log messages at or below.
|
---|
| 70 | */
|
---|
[49] | 71 | int g_loglevel = DEFAULT_DEBUG_LEVEL;
|
---|
[1] | 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;
|
---|
[783] | 80 | extern char *g_backup_media_string;
|
---|
[1] | 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 | */
|
---|
[49] | 99 | void _mondo_assert_fail(const char *file,
|
---|
| 100 | const char *function, int line, const char *exp)
|
---|
[1] | 101 | {
|
---|
[49] | 102 | static int ignoring_assertions = 0;
|
---|
| 103 | bool is_valid = TRUE;
|
---|
[1] | 104 |
|
---|
[49] | 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 | }
|
---|
[1] | 111 | #ifndef _XWIN
|
---|
[49] | 112 | if (!g_text_mode)
|
---|
| 113 | newtSuspend();
|
---|
[1] | 114 | #endif
|
---|
[507] | 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? "));
|
---|
[49] | 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")
|
---|
[1] | 129 | #ifdef __IA32__
|
---|
[49] | 130 | __asm__ __volatile__("int $3"); // break to debugger
|
---|
[1] | 131 | #endif
|
---|
[49] | 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
|
---|
[507] | 144 | (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
|
---|
[49] | 145 | break;
|
---|
| 146 | default:
|
---|
| 147 | is_valid = FALSE;
|
---|
[507] | 148 | printf(_("Invalid choice.\n"));
|
---|
[49] | 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);
|
---|
[1] | 157 | }
|
---|
| 158 |
|
---|
[49] | 159 | getchar(); // skip \n
|
---|
[1] | 160 |
|
---|
| 161 | #ifndef _XWIN
|
---|
[49] | 162 | if (!g_text_mode)
|
---|
| 163 | newtResume();
|
---|
[1] | 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 | {
|
---|
[49] | 173 | char *tmp;
|
---|
[1] | 174 |
|
---|
[900] | 175 | mr_asprintf(&tmp,
|
---|
[127] | 176 | "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
|
---|
[1] | 177 | file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
|
---|
[274] | 178 | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
|
---|
[276] | 179 | else { print $0;};}' $file.old > $file ; fi ; done");
|
---|
[49] | 180 | run_program_and_log_output(tmp, 5);
|
---|
[900] | 181 | mr_free(tmp);
|
---|
[1] | 182 | }
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | /**
|
---|
[1079] | 186 | * Locate mondoarchive's home directory. Searches in /usr/share/mondo,
|
---|
[1] | 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 | */
|
---|
[94] | 192 | char *find_and_store_mondoarchives_home()
|
---|
[1] | 193 | {
|
---|
[94] | 194 | char *home_sz = NULL;
|
---|
| 195 |
|
---|
[900] | 196 | mr_asprintf(&home_sz, MONDO_SHARE);
|
---|
[94] | 197 | return (home_sz);
|
---|
[1] | 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
[1185] | 201 | char *get_architecture(void)
|
---|
[1] | 202 | {
|
---|
| 203 | #ifdef __IA32__
|
---|
[49] | 204 | return ("i386");
|
---|
[1] | 205 | #endif
|
---|
[94] | 206 | #ifdef __X86_64__
|
---|
[1185] | 207 | return ("x86_64");
|
---|
[94] | 208 | #endif
|
---|
[1] | 209 | #ifdef __IA64__
|
---|
[49] | 210 | return ("ia64");
|
---|
[1] | 211 | #endif
|
---|
[49] | 212 | return ("unknown");
|
---|
[1] | 213 | }
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 |
|
---|
[1185] | 217 | double get_kernel_version(void)
|
---|
[1] | 218 | {
|
---|
[94] | 219 | char *p, *tmp;
|
---|
[49] | 220 | double d;
|
---|
[1] | 221 | #ifdef __FreeBSD__
|
---|
[49] | 222 | // JOSH - FIXME :)
|
---|
| 223 | d = 5.2; // :-)
|
---|
[1] | 224 | #else
|
---|
[688] | 225 | tmp = call_program_and_get_last_line_of_output("uname -r");
|
---|
[49] | 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 | }
|
---|
[1086] | 236 | // mr_msg(1, "tmp = '%s'", tmp);
|
---|
[49] | 237 | d = atof(tmp);
|
---|
[1] | 238 | #endif
|
---|
[1086] | 239 | mr_msg(1, "g_kernel_version = %f", d);
|
---|
[49] | 240 | return (d);
|
---|
[1] | 241 | }
|
---|
| 242 |
|
---|
| 243 |
|
---|
| 244 | /**
|
---|
| 245 | * Get the current time.
|
---|
| 246 | * @return number of seconds since the epoch.
|
---|
| 247 | */
|
---|
[1185] | 248 | long get_time(void)
|
---|
[1] | 249 | {
|
---|
[49] | 250 | return (long) time((void *) 0);
|
---|
[1] | 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__
|
---|
[49] | 262 | void initialize_raidrec(struct vinum_volume *raidrec)
|
---|
[1] | 263 | {
|
---|
[49] | 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 | }
|
---|
[1] | 275 | }
|
---|
| 276 | #else
|
---|
[49] | 277 | void initialize_raidrec(struct raid_device_record *raidrec)
|
---|
[1] | 278 | {
|
---|
[49] | 279 | assert(raidrec != NULL);
|
---|
[783] | 280 | raidrec->raid_device = NULL;
|
---|
[561] | 281 | raidrec->raid_level = -9;
|
---|
[49] | 282 | raidrec->persistent_superblock = 1;
|
---|
[561] | 283 | raidrec->chunk_size = 64;
|
---|
| 284 | raidrec->parity = -1;
|
---|
[49] | 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;
|
---|
[1] | 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__
|
---|
[49] | 302 | system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
|
---|
| 303 | system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
|
---|
[1] | 304 | #else
|
---|
[94] | 305 | system("modprobe -a dos fat vfat loop &> /dev/null");
|
---|
[1] | 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
|
---|
[20] | 321 | * - Used: @c bkpinfo->prefix
|
---|
[1] | 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 | */
|
---|
[49] | 341 | int post_param_configuration(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 342 | {
|
---|
[94] | 343 | char *extra_cdrom_params = NULL;
|
---|
| 344 | char *mondo_mkisofs_sz = NULL;
|
---|
[689] | 345 | char *command = NULL;
|
---|
[1185] | 346 | char *hostname = NULL;
|
---|
| 347 | char *ip_address = NULL;
|
---|
[49] | 348 | int retval = 0;
|
---|
| 349 | long avm = 0;
|
---|
[689] | 350 | char *colon = NULL;
|
---|
| 351 | char *cdr_exe = NULL;
|
---|
| 352 | char *tmp = NULL;
|
---|
| 353 | char *tmp1 = NULL;
|
---|
[783] | 354 | char *call_before_iso_user = NULL;
|
---|
[49] | 355 | int rdsiz_MB;
|
---|
[1185] | 356 | char *iso_dev = NULL;
|
---|
| 357 | char *iso_mnt = NULL;
|
---|
| 358 | char *iso_tmp = NULL;
|
---|
[689] | 359 | char *iso_path = NULL;
|
---|
[1106] | 360 | FILE *fd1 = NULL;
|
---|
[1] | 361 |
|
---|
[49] | 362 | assert(bkpinfo != NULL);
|
---|
| 363 | bkpinfo->optimal_set_size =
|
---|
[687] | 364 | (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
|
---|
[49] | 365 | 1024;
|
---|
[1] | 366 |
|
---|
[1086] | 367 | mr_msg(1, "Foo");
|
---|
[49] | 368 | if (bkpinfo->backup_media_type == tape) {
|
---|
[1086] | 369 | mr_msg(1, "Bar");
|
---|
[900] | 370 | mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
|
---|
[1086] | 371 | mr_msg(1, "tmp = '%s'", tmp);
|
---|
[49] | 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 | }
|
---|
[900] | 376 | mr_free(tmp);
|
---|
[1] | 377 | }
|
---|
[49] | 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);
|
---|
[1] | 382 |
|
---|
[49] | 383 | run_program_and_log_output("uname -a", 5);
|
---|
[687] | 384 | run_program_and_log_output("cat /etc/*-release", 5);
|
---|
[49] | 385 | run_program_and_log_output("cat /etc/*issue*", 5);
|
---|
[900] | 386 | mr_asprintf(&g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
|
---|
| 387 | mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
|
---|
[49] | 388 | paranoid_system(command);
|
---|
[900] | 389 | mr_free(command);
|
---|
[49] | 390 | rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
|
---|
[1] | 391 | #ifdef __FreeBSD__
|
---|
[688] | 392 | tmp = call_program_and_get_last_line_of_output
|
---|
| 393 | ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6");
|
---|
[49] | 394 | avm += atol(tmp);
|
---|
[900] | 395 | mr_free(tmp);
|
---|
[1185] | 396 | tmp1 = call_program_and_get_last_line_of_output
|
---|
[688] | 397 | ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc");
|
---|
[49] | 398 | avm += atol(tmp);
|
---|
[900] | 399 | mr_free(tmp);
|
---|
| 400 | mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
|
---|
[127] | 401 | g_tmpfs_mountpt);
|
---|
[1] | 402 | #else
|
---|
[688] | 403 | tmp = call_program_and_get_last_line_of_output
|
---|
[914] | 404 | ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1");
|
---|
[49] | 405 | avm += atol(tmp);
|
---|
[900] | 406 | mr_free(tmp);
|
---|
| 407 | mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
|
---|
[1185] | 408 | g_tmpfs_mountpt, rdsiz_MB, 'm');
|
---|
[49] | 409 | run_program_and_log_output("cat /proc/cpuinfo", 5);
|
---|
[94] | 410 | /* BERLIOS: rpm is not necessarily there ! */
|
---|
[49] | 411 | run_program_and_log_output
|
---|
| 412 | ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
|
---|
| 413 | 5);
|
---|
[1] | 414 | #endif
|
---|
[49] | 415 | if (avm / 1024 > rdsiz_MB * 3) {
|
---|
| 416 | if (run_program_and_log_output(command, 5)) {
|
---|
[900] | 417 | mr_free(g_tmpfs_mountpt);
|
---|
[49] | 418 | log_it("Failed to mount tmpfs");
|
---|
| 419 | } else {
|
---|
| 420 | log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
|
---|
| 421 | }
|
---|
| 422 | } else {
|
---|
[900] | 423 | mr_free(g_tmpfs_mountpt);
|
---|
[49] | 424 | log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
|
---|
[1] | 425 | }
|
---|
[900] | 426 | mr_free(command);
|
---|
[49] | 427 |
|
---|
| 428 | if (bkpinfo->use_lzo) {
|
---|
[900] | 429 | mr_allocstr(bkpinfo->zip_exe, "lzop");
|
---|
| 430 | mr_allocstr(bkpinfo->zip_suffix, "lzo");
|
---|
[1043] | 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");
|
---|
[49] | 437 | } else if (bkpinfo->compression_level != 0) {
|
---|
[900] | 438 | mr_allocstr(bkpinfo->zip_exe, "bzip2");
|
---|
| 439 | mr_allocstr(bkpinfo->zip_suffix, "bz2");
|
---|
[49] | 440 | } else {
|
---|
[783] | 441 | bkpinfo->zip_exe = NULL;
|
---|
| 442 | bkpinfo->zip_suffix = NULL;
|
---|
[1] | 443 | }
|
---|
| 444 |
|
---|
| 445 | // DVD
|
---|
| 446 |
|
---|
[49] | 447 | if (bkpinfo->backup_media_type == dvd) {
|
---|
[689] | 448 | tmp = find_home_of_exe("growisofs");
|
---|
| 449 | if (!tmp) {
|
---|
[49] | 450 | fatal_error("Please install growisofs.");
|
---|
| 451 | }
|
---|
[900] | 452 | mr_free(tmp);
|
---|
[689] | 453 |
|
---|
[49] | 454 | if (bkpinfo->nonbootable_backup) {
|
---|
[900] | 455 | mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
|
---|
[49] | 456 | } else if
|
---|
[1] | 457 | #ifdef __FreeBSD__
|
---|
[49] | 458 | (TRUE)
|
---|
[1] | 459 | #else
|
---|
[49] | 460 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 461 | #endif
|
---|
| 462 | #ifdef __IA64__
|
---|
[49] | 463 | {
|
---|
[900] | 464 | mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
|
---|
[49] | 465 | }
|
---|
[1] | 466 | #else
|
---|
| 467 | {
|
---|
[900] | 468 | mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
|
---|
[1] | 469 | }
|
---|
[49] | 470 | #endif
|
---|
| 471 | else
|
---|
| 472 | {
|
---|
[900] | 473 | mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
|
---|
[49] | 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 {
|
---|
[900] | 479 | mr_asprintf(&bkpinfo->call_make_iso,
|
---|
[49] | 480 | "%s %s -Z %s . 2>> _ERR_",
|
---|
[127] | 481 | mondo_mkisofs_sz, "", bkpinfo->media_device);
|
---|
[49] | 482 | }
|
---|
[900] | 483 | mr_free(mondo_mkisofs_sz);
|
---|
[94] | 484 |
|
---|
[687] | 485 | if (getenv ("SUDO_COMMAND")) {
|
---|
[900] | 486 | mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND");
|
---|
[688] | 487 | tmp = call_program_and_get_last_line_of_output(command);
|
---|
| 488 | if (!strcmp(tmp, "1")) {
|
---|
[687] | 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.");
|
---|
[1185] | 491 | }
|
---|
[900] | 492 | mr_free(tmp);
|
---|
| 493 | mr_free(command);
|
---|
[72] | 494 | }
|
---|
[1086] | 495 | mr_msg(2, "call_make_iso (DVD res) is ... %s",
|
---|
[49] | 496 | bkpinfo->call_make_iso);
|
---|
| 497 | } // end of DVD code
|
---|
[1] | 498 |
|
---|
| 499 | // CD-R or CD-RW
|
---|
[49] | 500 | if (bkpinfo->backup_media_type == cdrw
|
---|
| 501 | || bkpinfo->backup_media_type == cdr) {
|
---|
| 502 | if (!bkpinfo->manual_cd_tray) {
|
---|
[1185] | 503 | mr_strcat(extra_cdrom_params, "-waiti ");
|
---|
[49] | 504 | }
|
---|
| 505 | if (bkpinfo->backup_media_type == cdrw) {
|
---|
[1185] | 506 | mr_strcat(extra_cdrom_params, "blank=fast ");
|
---|
[49] | 507 | }
|
---|
[689] | 508 | tmp = find_home_of_exe("cdrecord");
|
---|
| 509 | tmp1 = find_home_of_exe("dvdrecord");
|
---|
| 510 | if (tmp) {
|
---|
[900] | 511 | mr_asprintf(&cdr_exe, "cdrecord");
|
---|
[689] | 512 | } else if (tmp1) {
|
---|
[900] | 513 | mr_asprintf(&cdr_exe, "dvdrecord");
|
---|
[49] | 514 | } else {
|
---|
| 515 | fatal_error("Please install either cdrecord or dvdrecord.");
|
---|
| 516 | }
|
---|
[900] | 517 | mr_free(tmp);
|
---|
| 518 | mr_free(tmp1);
|
---|
[689] | 519 |
|
---|
[49] | 520 | if (bkpinfo->nonbootable_backup) {
|
---|
[900] | 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);
|
---|
[49] | 522 | } else if
|
---|
[1] | 523 | #ifdef __FreeBSD__
|
---|
[49] | 524 | (TRUE)
|
---|
[1] | 525 | #else
|
---|
[49] | 526 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 527 | #endif
|
---|
| 528 | #ifdef __IA64__
|
---|
| 529 | {
|
---|
[900] | 530 | mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
|
---|
[1] | 531 | }
|
---|
[49] | 532 | #else
|
---|
[1] | 533 | {
|
---|
[900] | 534 | mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
|
---|
[1] | 535 | }
|
---|
[49] | 536 | #endif
|
---|
| 537 | else
|
---|
| 538 | {
|
---|
[900] | 539 | mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
|
---|
[49] | 540 | }
|
---|
| 541 | if (bkpinfo->manual_cd_tray) {
|
---|
[783] | 542 | if (bkpinfo->call_before_iso == NULL) {
|
---|
[900] | 543 | mr_asprintf(&bkpinfo->call_before_iso,
|
---|
[164] | 544 | "%s -o %s/temporary.iso . 2>> _ERR_",
|
---|
| 545 | mondo_mkisofs_sz, bkpinfo->tmpdir);
|
---|
[783] | 546 | } else {
|
---|
[900] | 547 | mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
|
---|
| 548 | mr_asprintf(&bkpinfo->call_before_iso,
|
---|
[164] | 549 | "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )",
|
---|
| 550 | mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
|
---|
[900] | 551 | mr_free(call_before_iso_user);
|
---|
[164] | 552 | }
|
---|
| 553 | log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
|
---|
[900] | 554 | mr_asprintf(&bkpinfo->call_make_iso,
|
---|
[49] | 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 {
|
---|
[900] | 560 | mr_asprintf(&bkpinfo->call_make_iso,
|
---|
[49] | 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 | }
|
---|
[900] | 567 | mr_free(mondo_mkisofs_sz);
|
---|
| 568 | mr_free(cdr_exe);
|
---|
| 569 | mr_free(extra_cdrom_params);
|
---|
[49] | 570 | } // end of CD code
|
---|
[1] | 571 |
|
---|
[49] | 572 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 573 |
|
---|
[1] | 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 |
|
---|
[49] | 581 | log_it("isodir = %s", bkpinfo->isodir);
|
---|
[900] | 582 | mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1",
|
---|
[127] | 583 | bkpinfo->isodir);
|
---|
[49] | 584 | log_it("command = %s", command);
|
---|
[1106] | 585 | iso_dev = call_program_and_get_last_line_of_output(command);
|
---|
[900] | 586 | mr_free(command);
|
---|
[1106] | 587 | log_it("res of it = %s", iso_dev);
|
---|
[1] | 588 |
|
---|
[1106] | 589 | fd1 = mr_fopen(MONDORESTORECFG, "a");
|
---|
[1185] | 590 | mr_fprintf(fd1, "iso-dev=%s\n", iso_dev);
|
---|
[1106] | 591 |
|
---|
[900] | 592 | mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
|
---|
[1106] | 593 | iso_dev);
|
---|
| 594 | mr_free(iso_dev);
|
---|
| 595 |
|
---|
[49] | 596 | log_it("command = %s", command);
|
---|
[1106] | 597 | iso_mnt = call_program_and_get_last_line_of_output(command);
|
---|
[900] | 598 | mr_free(command);
|
---|
[94] | 599 |
|
---|
[1106] | 600 | log_it("res of it = %s", iso_mnt);
|
---|
[1185] | 601 | mr_fprintf(fd1, "iso-mnt=%s\n", iso_mnt);
|
---|
[1106] | 602 | log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
|
---|
[94] | 603 |
|
---|
[1106] | 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));
|
---|
[1185] | 607 | } else {
|
---|
| 608 | mr_asprintf(&iso_path, "");
|
---|
[49] | 609 | }
|
---|
[1106] | 610 | mr_free(iso_tmp);
|
---|
| 611 | mr_free(iso_mnt);
|
---|
[94] | 612 |
|
---|
[49] | 613 | log_it("isodir: %s", iso_path);
|
---|
[1185] | 614 | mr_fprintf(fd1, "isodir=%s\n", iso_path);
|
---|
[900] | 615 | mr_free(iso_path);
|
---|
[1106] | 616 |
|
---|
[149] | 617 | log_it("iso-prefix: %s", bkpinfo->prefix);
|
---|
[1185] | 618 | mr_fprintf(fd1, "iso-prefix=%s\n", bkpinfo->prefix);
|
---|
[1106] | 619 |
|
---|
| 620 | mr_fclose(fd1);
|
---|
[49] | 621 | } // end of iso code
|
---|
[1] | 622 |
|
---|
[49] | 623 | if (bkpinfo->backup_media_type == nfs) {
|
---|
[900] | 624 | mr_asprintf(&hostname, bkpinfo->nfs_mount);
|
---|
[49] | 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;
|
---|
[1] | 631 |
|
---|
[49] | 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 {
|
---|
[900] | 639 | mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
|
---|
[1185] | 640 | *((struct in_addr *) hent->h_addr)),
|
---|
| 641 | strchr(bkpinfo->nfs_mount, ':'));
|
---|
[900] | 642 | mr_allocstr(bkpinfo->nfs_mount, ip_address);
|
---|
| 643 | mr_free(ip_address);
|
---|
[49] | 644 | }
|
---|
| 645 | }
|
---|
[89] | 646 | store_nfs_config(bkpinfo);
|
---|
[900] | 647 | mr_free(hostname);
|
---|
[49] | 648 | }
|
---|
[1] | 649 |
|
---|
[49] | 650 | log_it("Finished processing incoming params");
|
---|
| 651 | if (retval) {
|
---|
| 652 | fprintf(stderr, "Type 'man mondoarchive' for help.\n");
|
---|
| 653 | }
|
---|
[900] | 654 | mr_asprintf(&tmp, "%s", MONDO_TMPISOS);
|
---|
[49] | 655 | if (does_file_exist(tmp)) {
|
---|
| 656 | unlink(tmp);
|
---|
| 657 | }
|
---|
[900] | 658 | mr_free(tmp);
|
---|
[94] | 659 |
|
---|
[49] | 660 | if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
|
---|
| 661 | log_it("tmpdir or scratchdir are blank/missing");
|
---|
| 662 | retval++;
|
---|
| 663 | }
|
---|
[783] | 664 | if (bkpinfo->include_paths == NULL) {
|
---|
[49] | 665 | // fatal_error ("Why no backup path?");
|
---|
[900] | 666 | mr_asprintf(&bkpinfo->include_paths, "/");
|
---|
[49] | 667 | }
|
---|
| 668 | chmod(bkpinfo->scratchdir, 0700);
|
---|
| 669 | chmod(bkpinfo->tmpdir, 0700);
|
---|
| 670 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
[900] | 671 | mr_allocstr(g_backup_media_string,bkpinfo->backup_media_string);
|
---|
[49] | 672 | return (retval);
|
---|
[1] | 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 | {
|
---|
[49] | 685 | int res = 0;
|
---|
[1] | 686 |
|
---|
[49] | 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 | }
|
---|
[1] | 698 |
|
---|
[49] | 699 | run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
|
---|
[94] | 700 | if ((g_mondo_home = find_and_store_mondoarchives_home()) == NULL) {
|
---|
[49] | 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;
|
---|
[688] | 711 | bkpinfo->postnuke_tarball = NULL;
|
---|
[900] | 712 | mr_free(bkpinfo->nfs_mount);
|
---|
[49] | 713 | return (res);
|
---|
[1] | 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 | */
|
---|
[49] | 723 | void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 724 | {
|
---|
[688] | 725 | int i = 0;
|
---|
[1] | 726 |
|
---|
[1086] | 727 | mr_msg(1, "Hi");
|
---|
[688] | 728 |
|
---|
[49] | 729 | assert(bkpinfo != NULL);
|
---|
[688] | 730 | /* BERLIOS : Useless
|
---|
[49] | 731 | memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
|
---|
[688] | 732 | */
|
---|
| 733 |
|
---|
[49] | 734 | bkpinfo->manual_cd_tray = FALSE;
|
---|
| 735 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[688] | 736 | bkpinfo->boot_loader = '\0';
|
---|
| 737 |
|
---|
[49] | 738 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 739 | bkpinfo->media_size[i] = -1;
|
---|
| 740 | }
|
---|
[688] | 741 |
|
---|
[900] | 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);
|
---|
[49] | 747 | bkpinfo->use_lzo = FALSE;
|
---|
[1043] | 748 | bkpinfo->use_gzip = FALSE;
|
---|
| 749 | bkpinfo->do_not_compress_these[0] = '\0';
|
---|
[49] | 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) {
|
---|
[900] | 756 | mr_allocstr(bkpinfo->isodir, "/");
|
---|
[49] | 757 | } else {
|
---|
[900] | 758 | mr_allocstr(bkpinfo->isodir, "/var/cache/mondo/iso");
|
---|
[49] | 759 | }
|
---|
[900] | 760 | mr_allocstr(bkpinfo->prefix, STD_PREFIX);
|
---|
[1] | 761 |
|
---|
[900] | 762 | mr_free(bkpinfo->scratchdir);
|
---|
[49] | 763 | bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
|
---|
[900] | 764 | mr_free(bkpinfo->tmpdir);
|
---|
| 765 | mr_asprintf(&bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore
|
---|
[49] | 766 | bkpinfo->optimal_set_size = 0;
|
---|
| 767 | bkpinfo->backup_media_type = none;
|
---|
[900] | 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);
|
---|
[49] | 780 | bkpinfo->wipe_media_first = FALSE;
|
---|
| 781 | bkpinfo->differential = FALSE;
|
---|
| 782 | bkpinfo->cdrw_speed = 0;
|
---|
[1] | 783 | // patch by Herman Kuster
|
---|
[49] | 784 | bkpinfo->differential = 0;
|
---|
[1] | 785 | // patch end
|
---|
[49] | 786 | bkpinfo->compression_level = 3;
|
---|
[1] | 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 | */
|
---|
[49] | 795 | long free_space_on_given_partition(char *partition)
|
---|
[1] | 796 | {
|
---|
[688] | 797 | char *command = NULL;
|
---|
| 798 | char *out_sz = NULL;
|
---|
[1185] | 799 | long res = 0L;
|
---|
[1] | 800 |
|
---|
[49] | 801 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
[1] | 802 |
|
---|
[900] | 803 | mr_asprintf(&command, "df -m -P %s &> /dev/null", partition);
|
---|
[49] | 804 | if (system(command)) {
|
---|
| 805 | return (-1);
|
---|
| 806 | } // partition does not exist
|
---|
[900] | 807 | mr_free(command);
|
---|
[94] | 808 |
|
---|
[900] | 809 | mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
|
---|
[1185] | 810 | partition);
|
---|
[688] | 811 | out_sz = call_program_and_get_last_line_of_output(command);
|
---|
[900] | 812 | mr_free(command);
|
---|
[1185] | 813 |
|
---|
[49] | 814 | if (strlen(out_sz) == 0) {
|
---|
| 815 | return (-1);
|
---|
| 816 | } // error within df, probably
|
---|
| 817 | res = atol(out_sz);
|
---|
[900] | 818 | mr_free(out_sz);
|
---|
[49] | 819 | return (res);
|
---|
[1] | 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 | */
|
---|
[49] | 835 | int some_basic_system_sanity_checks()
|
---|
[1] | 836 | {
|
---|
| 837 |
|
---|
[49] | 838 | /*@ buffers ************ */
|
---|
[689] | 839 | char *tmp = NULL;
|
---|
[1] | 840 |
|
---|
[49] | 841 | /*@ int's *************** */
|
---|
| 842 | int retval = 0;
|
---|
| 843 | long Lres;
|
---|
[1] | 844 |
|
---|
| 845 |
|
---|
[49] | 846 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 847 | "Checking sanity of your Linux distribution");
|
---|
[1] | 848 | #ifndef __FreeBSD__
|
---|
[49] | 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 | }
|
---|
[688] | 856 | tmp = call_program_and_get_last_line_of_output
|
---|
| 857 | ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2");
|
---|
[49] | 858 | if (atol(tmp) < 35000) {
|
---|
| 859 | retval++;
|
---|
[507] | 860 | log_to_screen(_("You must have at least 32MB of RAM to use Mondo."));
|
---|
[49] | 861 | }
|
---|
| 862 | if (atol(tmp) < 66000) {
|
---|
| 863 | log_to_screen
|
---|
[507] | 864 | (_("WARNING! You have very little RAM. Please upgrade to 64MB or more."));
|
---|
[49] | 865 | }
|
---|
[900] | 866 | mr_free(tmp);
|
---|
[1] | 867 | #endif
|
---|
| 868 |
|
---|
[1046] | 869 | Lres = free_space_on_given_partition("/var/cache");
|
---|
[49] | 870 | log_it("Free space on given partition = %ld MB", Lres);
|
---|
[1] | 871 |
|
---|
[49] | 872 | if (Lres < 50) {
|
---|
[1046] | 873 | fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner.");
|
---|
[49] | 874 | }
|
---|
[1] | 875 |
|
---|
[49] | 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 | }
|
---|
[1] | 883 | #ifndef __FreeBSD__
|
---|
[49] | 884 | if (run_program_and_log_output
|
---|
[274] | 885 | ("grep ramdisk /proc/devices", FALSE)) {
|
---|
[49] | 886 | if (!ask_me_yes_or_no
|
---|
[507] | 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?")))
|
---|
[49] | 888 | {
|
---|
| 889 | // retval++;
|
---|
| 890 | log_to_screen
|
---|
[507] | 891 | (_("It looks as if your kernel lacks ramdisk and initrd support."));
|
---|
[49] | 892 | log_to_screen
|
---|
[507] | 893 | (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken."));
|
---|
[49] | 894 | }
|
---|
| 895 | }
|
---|
[1] | 896 | #endif
|
---|
[49] | 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");
|
---|
[1043] | 903 | retval += whine_if_not_found("gzip");
|
---|
[49] | 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");
|
---|
[1] | 909 |
|
---|
[49] | 910 | // abort if Windows partition but no ms-sys and parted
|
---|
| 911 | if (!run_program_and_log_output
|
---|
[687] | 912 | ("mount | grep -w vfat | grep -vE \"/dev/fd|nexdisk\"", 0)
|
---|
[49] | 913 | ||
|
---|
| 914 | !run_program_and_log_output
|
---|
[687] | 915 | ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
|
---|
[507] | 916 | log_to_screen(_("I think you have a Windows 9x partition."));
|
---|
[49] | 917 | retval += whine_if_not_found("parted");
|
---|
[1] | 918 | #ifndef __IA64__
|
---|
[49] | 919 | /* IA64 always has one vfat partition for EFI even without Windows */
|
---|
| 920 | // retval +=
|
---|
[689] | 921 | tmp = find_home_of_exe("ms-sys");
|
---|
| 922 | if (!tmp) {
|
---|
[507] | 923 | log_to_screen(_("Please install ms-sys just in case."));
|
---|
[49] | 924 | }
|
---|
[900] | 925 | mr_free(tmp);
|
---|
[49] | 926 | #endif
|
---|
[1] | 927 | }
|
---|
| 928 |
|
---|
[689] | 929 | tmp = find_home_of_exe("cmp");
|
---|
| 930 | if (!tmp) {
|
---|
| 931 | whine_if_not_found("cmp");
|
---|
[1] | 932 | }
|
---|
[900] | 933 | mr_free(tmp);
|
---|
[689] | 934 |
|
---|
[49] | 935 | run_program_and_log_output
|
---|
| 936 | ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
|
---|
[688] | 937 | tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"");
|
---|
[49] | 938 | if (strcmp("", tmp)) {
|
---|
| 939 | if (strstr(tmp, "autofs")) {
|
---|
| 940 | log_to_screen
|
---|
[507] | 941 | (_("Your CD-ROM is mounted via autofs. I therefore cannot tell"));
|
---|
[49] | 942 | log_to_screen
|
---|
[507] | 943 | (_("if a CD actually is inserted. If a CD is inserted, please"));
|
---|
| 944 | log_to_screen(_("eject it. Thank you."));
|
---|
[49] | 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 | }
|
---|
[900] | 954 | mr_free(tmp);
|
---|
[1] | 955 | #ifndef __FreeBSD__
|
---|
[49] | 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
|
---|
[507] | 971 | (_("Please find out what happened to /etc/modules.conf"));
|
---|
[49] | 972 | }
|
---|
[1] | 973 | }
|
---|
| 974 | #endif
|
---|
| 975 |
|
---|
[49] | 976 | run_program_and_log_output("cat /etc/fstab", 5);
|
---|
[1] | 977 | #ifdef __FreeBSD__
|
---|
[49] | 978 | run_program_and_log_output("vinum printconfig", 5);
|
---|
[1] | 979 | #else
|
---|
[49] | 980 | run_program_and_log_output("cat /etc/raidtab", 5);
|
---|
[1] | 981 | #endif
|
---|
| 982 |
|
---|
[49] | 983 | if (run_program_and_log_output("mindi -V", 1)) {
|
---|
[507] | 984 | log_to_screen(_("Could not ascertain mindi's version number."));
|
---|
[49] | 985 | log_to_screen
|
---|
[507] | 986 | (_("You have not installed Mondo and/or Mindi properly."));
|
---|
| 987 | log_to_screen(_("Please uninstall and reinstall them both."));
|
---|
[49] | 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
|
---|
[507] | 993 | (_("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason."));
|
---|
[49] | 994 | log_to_screen
|
---|
[507] | 995 | (_("Please run that command by hand and examine /var/log/mindi.log"));
|
---|
[49] | 996 | log_to_screen
|
---|
[507] | 997 | (_("for more information. Perhaps your /etc/fstab file is insane."));
|
---|
[49] | 998 | log_to_screen
|
---|
[507] | 999 | (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see."));
|
---|
[49] | 1000 | retval++;
|
---|
| 1001 | }
|
---|
[1] | 1002 |
|
---|
[197] | 1003 | if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
|
---|
[49] | 1004 | && !does_file_exist("/etc/raidtab")) {
|
---|
| 1005 | log_to_screen
|
---|
[507] | 1006 | (_("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat"));
|
---|
[561] | 1007 | create_raidtab_from_mdstat("/etc/raidtab");
|
---|
[49] | 1008 | }
|
---|
| 1009 |
|
---|
| 1010 | if (retval) {
|
---|
[507] | 1011 | mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
|
---|
[49] | 1012 | } else {
|
---|
[507] | 1013 | mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
|
---|
[49] | 1014 | }
|
---|
| 1015 | return (retval);
|
---|
[1] | 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 | */
|
---|
[49] | 1025 | int read_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1026 | {
|
---|
[49] | 1027 | /*@ buffer ****************************************************** */
|
---|
[688] | 1028 | char *command = NULL;
|
---|
| 1029 | char *tmp = NULL;
|
---|
[1] | 1030 |
|
---|
[49] | 1031 | /*@ end vars *************************************************** */
|
---|
[1] | 1032 |
|
---|
[49] | 1033 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1034 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
[688] | 1035 |
|
---|
[49] | 1036 | if (!does_file_exist(config_file)) {
|
---|
[900] | 1037 | mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
|
---|
[127] | 1038 | config_file);
|
---|
[49] | 1039 | log_to_screen(tmp);
|
---|
[900] | 1040 | mr_free(tmp);
|
---|
[688] | 1041 | value = NULL;
|
---|
[49] | 1042 | return (1);
|
---|
[783] | 1043 | /* } BERLIOS: Useless:
|
---|
| 1044 | else if (strstr(value, "/dev/") && strstr(value, "t0")
|
---|
[49] | 1045 | && !strcmp(label, "media-dev")) {
|
---|
[1086] | 1046 | mr_msg(2, "FYI, I shan't read new value for %s - already got %s",
|
---|
[49] | 1047 | label, value);
|
---|
| 1048 | return (0);
|
---|
[783] | 1049 | */ } else {
|
---|
[1185] | 1050 | mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",
|
---|
[149] | 1051 | label, config_file);
|
---|
[688] | 1052 | value = call_program_and_get_last_line_of_output(command);
|
---|
[900] | 1053 | mr_free(command);
|
---|
[49] | 1054 | if (strlen(value) == 0) {
|
---|
| 1055 | return (1);
|
---|
| 1056 | } else {
|
---|
| 1057 | return (0);
|
---|
| 1058 | }
|
---|
[1] | 1059 | }
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 |
|
---|
| 1063 | /**
|
---|
| 1064 | * Remount @c supermount if it was unmounted earlier.
|
---|
| 1065 | */
|
---|
| 1066 | void remount_supermounts_if_necessary()
|
---|
| 1067 | {
|
---|
[49] | 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 | }
|
---|
[1] | 1074 | }
|
---|
| 1075 |
|
---|
| 1076 | /**
|
---|
| 1077 | * Unmount @c supermount if it's mounted.
|
---|
| 1078 | */
|
---|
| 1079 | void unmount_supermounts_if_necessary()
|
---|
| 1080 | {
|
---|
[49] | 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 | }
|
---|
[1] | 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 | {
|
---|
[1185] | 1098 | char *tmp = NULL;
|
---|
| 1099 | char *tmp1 = NULL;
|
---|
| 1100 | char *command = NULL;
|
---|
[1] | 1101 |
|
---|
[1086] | 1102 | mr_msg(1, "Started sub");
|
---|
| 1103 | mr_msg(4, "Setting command to something");
|
---|
[900] | 1104 | mr_asprintf(&command,
|
---|
[914] | 1105 | "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
|
---|
[1086] | 1106 | mr_msg(4, "Cool. Command = '%s'", command);
|
---|
[688] | 1107 | tmp = call_program_and_get_last_line_of_output(command);
|
---|
[900] | 1108 | mr_free(command);
|
---|
[94] | 1109 |
|
---|
[1086] | 1110 | mr_msg(4, "tmp = '%s'", tmp);
|
---|
[688] | 1111 | if (tmp) {
|
---|
[49] | 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)) {
|
---|
[900] | 1115 | mr_free(g_boot_mountpt);
|
---|
| 1116 | mr_asprintf(&g_boot_mountpt, "/boot");
|
---|
[1086] | 1117 | mr_msg(1, "Mounted /boot");
|
---|
[49] | 1118 | } else {
|
---|
| 1119 | log_it("...ignored cos it's a label :-)");
|
---|
| 1120 | }
|
---|
| 1121 | } else {
|
---|
[914] | 1122 | mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
|
---|
[1086] | 1123 | mr_msg(3, "command = %s", command);
|
---|
[49] | 1124 | if (run_program_and_log_output(command, 5)) {
|
---|
[900] | 1125 | mr_free(g_boot_mountpt);
|
---|
| 1126 | mr_asprintf(&g_boot_mountpt, tmp);
|
---|
| 1127 | mr_asprintf(&tmp1,
|
---|
[1185] | 1128 | "%s (your /boot partition) is not mounted. I'll mount it before backing up",
|
---|
| 1129 | g_boot_mountpt);
|
---|
[94] | 1130 | log_it(tmp1);
|
---|
[900] | 1131 | mr_free(tmp1);
|
---|
[94] | 1132 |
|
---|
[900] | 1133 | mr_asprintf(&tmp1, "mount %s", g_boot_mountpt);
|
---|
[94] | 1134 | if (run_program_and_log_output(tmp1, 5)) {
|
---|
[783] | 1135 | /* BERLIOS: Useless ???
|
---|
[900] | 1136 | mr_free(g_boot_mountpt);
|
---|
| 1137 | mr_asprintf(&g_boot_mountpt, " ");
|
---|
[783] | 1138 | */
|
---|
[1086] | 1139 | mr_msg(1, "Plan B");
|
---|
[49] | 1140 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
[900] | 1141 | mr_free(g_boot_mountpt);
|
---|
| 1142 | mr_asprintf(&g_boot_mountpt, "/boot");
|
---|
[1086] | 1143 | mr_msg(1, "Plan B worked");
|
---|
[49] | 1144 | } else {
|
---|
[1086] | 1145 | mr_msg(1,
|
---|
[49] | 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 | }
|
---|
[900] | 1149 | mr_free(tmp1);
|
---|
[49] | 1150 | }
|
---|
[900] | 1151 | mr_free(command);
|
---|
[49] | 1152 | }
|
---|
[1] | 1153 | }
|
---|
[900] | 1154 | mr_free(tmp);
|
---|
[1086] | 1155 | mr_msg(1, "Ended sub");
|
---|
[1] | 1156 | }
|
---|
| 1157 |
|
---|
| 1158 |
|
---|
| 1159 | /**
|
---|
| 1160 | * If we mounted /boot earlier, unmount it.
|
---|
| 1161 | */
|
---|
| 1162 | void unmount_boot_if_necessary()
|
---|
| 1163 | {
|
---|
[94] | 1164 | char *tmp;
|
---|
[1] | 1165 |
|
---|
[1086] | 1166 | mr_msg(3, "starting");
|
---|
[783] | 1167 | if (g_boot_mountpt != NULL) {
|
---|
[900] | 1168 | mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
|
---|
[49] | 1169 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1170 | log_it("WARNING - unable to unmount /boot");
|
---|
| 1171 | }
|
---|
[900] | 1172 | mr_free(tmp);
|
---|
[49] | 1173 | }
|
---|
[1086] | 1174 | mr_msg(3, "leaving");
|
---|
[1] | 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 | */
|
---|
[49] | 1186 | int write_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1187 | {
|
---|
[49] | 1188 | /*@ buffers ***************************************************** */
|
---|
[1185] | 1189 | char *command = NULL;
|
---|
| 1190 | char *tempfile = NULL;
|
---|
| 1191 | char *tmp = NULL;
|
---|
[1] | 1192 |
|
---|
| 1193 |
|
---|
[49] | 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);
|
---|
[94] | 1198 |
|
---|
[49] | 1199 | if (!does_file_exist(config_file)) {
|
---|
[900] | 1200 | mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
|
---|
[127] | 1201 | config_file);
|
---|
[49] | 1202 | log_to_screen(tmp);
|
---|
[900] | 1203 | mr_free(tmp);
|
---|
[49] | 1204 | return (1);
|
---|
| 1205 | }
|
---|
[688] | 1206 | tempfile = call_program_and_get_last_line_of_output
|
---|
| 1207 | ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX");
|
---|
[49] | 1208 | if (does_file_exist(config_file)) {
|
---|
[914] | 1209 | mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s",
|
---|
[149] | 1210 | label, config_file, tempfile);
|
---|
[49] | 1211 | paranoid_system(command);
|
---|
[900] | 1212 | mr_free(command);
|
---|
[49] | 1213 | }
|
---|
[900] | 1214 | mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
|
---|
[49] | 1215 | paranoid_system(command);
|
---|
[900] | 1216 | mr_free(command);
|
---|
[94] | 1217 |
|
---|
[900] | 1218 | mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
|
---|
[49] | 1219 | paranoid_system(command);
|
---|
[900] | 1220 | mr_free(command);
|
---|
[49] | 1221 | unlink(tempfile);
|
---|
[900] | 1222 | mr_free(tempfile);
|
---|
[49] | 1223 | return (0);
|
---|
[1] | 1224 | }
|
---|
| 1225 |
|
---|
[1185] | 1226 |
|
---|
[1] | 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 | {
|
---|
[49] | 1233 | if (mal) {
|
---|
[1000] | 1234 | /*
|
---|
[49] | 1235 | iamhere("Malloc'ing globals");
|
---|
[1000] | 1236 | */
|
---|
[688] | 1237 | g_erase_tmpdir_and_scratchdir = NULL;
|
---|
[49] | 1238 | malloc_string(g_serial_string);
|
---|
| 1239 | } else {
|
---|
| 1240 | iamhere("Freeing globals");
|
---|
[900] | 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);
|
---|
[49] | 1247 | }
|
---|
[1] | 1248 | }
|
---|
| 1249 |
|
---|
| 1250 | /**
|
---|
| 1251 | * Allocate important globals.
|
---|
| 1252 | * @see do_libmondo_global_strings_thing
|
---|
| 1253 | */
|
---|
| 1254 | void malloc_libmondo_global_strings(void)
|
---|
| 1255 | {
|
---|
[49] | 1256 | do_libmondo_global_strings_thing(1);
|
---|
[1] | 1257 | }
|
---|
| 1258 |
|
---|
| 1259 | /**
|
---|
| 1260 | * Free important globals.
|
---|
| 1261 | * @see do_libmondo_global_strings_thing
|
---|
| 1262 | */
|
---|
| 1263 | void free_libmondo_global_strings(void)
|
---|
| 1264 | {
|
---|
[49] | 1265 | do_libmondo_global_strings_thing(0);
|
---|
[1] | 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 | {
|
---|
[688] | 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) {
|
---|
[1086] | 1279 | mr_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
|
---|
[49] | 1280 | paranoid_system("killall magicdev");
|
---|
| 1281 | }
|
---|
[1] | 1282 | }
|
---|
| 1283 |
|
---|
| 1284 |
|
---|
| 1285 | /**
|
---|
| 1286 | * Restart magicdev if it was stopped.
|
---|
| 1287 | */
|
---|
| 1288 | void restart_magicdev_if_necessary()
|
---|
| 1289 | {
|
---|
[688] | 1290 | char *tmp = NULL;
|
---|
[49] | 1291 |
|
---|
[688] | 1292 | if (!g_magicdev_command) {
|
---|
[900] | 1293 | mr_asprintf(&tmp, "%s &", g_magicdev_command);
|
---|
[49] | 1294 | paranoid_system(tmp);
|
---|
[900] | 1295 | mr_free(tmp);
|
---|
[49] | 1296 | }
|
---|
[1] | 1297 | }
|
---|
| 1298 |
|
---|
| 1299 | /* @} - end of utilityGroup */
|
---|