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