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