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