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