[1] | 1 | /* libmondo-tools.c misc tools
|
---|
[99] | 2 | $Id: libmondo-tools.c 1855 2008-01-11 10:22:18Z bruno $
|
---|
[1] | 3 | .
|
---|
| 4 |
|
---|
| 5 |
|
---|
| 6 | 06/28
|
---|
| 7 | - abort if RAID partitions found but /etc/raidtab not found
|
---|
| 8 |
|
---|
| 9 | 06/25
|
---|
| 10 | - don't insist on ms-sys; recommend it
|
---|
| 11 | - don't fatal_error if can't open log file
|
---|
| 12 |
|
---|
| 13 | 06/14
|
---|
| 14 | - call mindi -V before calling mindi --makemountlist
|
---|
| 15 |
|
---|
| 16 | 04/09
|
---|
| 17 | - lots of malloc'd char*'s instead of char[]'s in post_param_config'n
|
---|
| 18 |
|
---|
| 19 | 04/02
|
---|
| 20 | - better sanity-checking, re: /etc/modules.conf
|
---|
| 21 |
|
---|
| 22 | 02/15
|
---|
| 23 | - abort if Windows dir but no ms-sys or parted
|
---|
| 24 |
|
---|
| 25 | 02/08
|
---|
| 26 | - missing ramdisk/initrd support is nonfatal now (but stupid)
|
---|
| 27 |
|
---|
| 28 | 01/16
|
---|
| 29 | - added g_kernel_version and get_kernel_version()
|
---|
| 30 |
|
---|
| 31 | 01/08/2004
|
---|
| 32 | - fixed /boot mounter thingy
|
---|
| 33 |
|
---|
| 34 | 11/14/2003
|
---|
| 35 | - if <50MB free in /root, softlink /root/images/mindi to
|
---|
| 36 | /home/root/images/mindi as a workaround
|
---|
| 37 |
|
---|
| 38 | 10/23
|
---|
| 39 | - streaming backups now generate 4MB sets; CDs, 8MB sets
|
---|
| 40 |
|
---|
| 41 | 10/21
|
---|
| 42 | - better at finding your /boot in order to mount it, if nec.
|
---|
| 43 | - link /etc/modules.conf to /etc/conf.modules if former
|
---|
| 44 | is missing but latter is not
|
---|
| 45 | - changed "/mnt/cdrom" to MNT_CDROM
|
---|
| 46 | - changed "/mnt/floppy" to MNT_FLOPPY
|
---|
| 47 |
|
---|
| 48 | 10/13
|
---|
| 49 | - added stop_magicdev_if_necessary()
|
---|
| 50 | - added restart_magicdev_if_necessary()
|
---|
| 51 |
|
---|
| 52 | 10/02
|
---|
| 53 | - don't eject if bkpinfo->please_dont_eject is TRUE
|
---|
| 54 |
|
---|
| 55 | 09/28
|
---|
| 56 | - fixed segfault in mount_..._necessary
|
---|
| 57 |
|
---|
| 58 | 09/26
|
---|
| 59 | - ask for cmp (or create workaround if possible)
|
---|
| 60 |
|
---|
| 61 | 09/25
|
---|
| 62 | - add DVD support
|
---|
| 63 |
|
---|
| 64 | 09/24
|
---|
| 65 | - don't overwrite existing media-dev value in bkpinfo IF it's
|
---|
| 66 | a tape device AND it's already populated by /dev/{something}
|
---|
| 67 | ...This helps w/ weird tape drives
|
---|
| 68 |
|
---|
| 69 | 09/23
|
---|
| 70 | - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
|
---|
| 71 | and free_libmondo_global_strings() - which are in libmondo-tools.c
|
---|
| 72 |
|
---|
| 73 | 09/18
|
---|
| 74 | - added stop_autofs_if_necessary() and restart_autofs_if_necessary()
|
---|
| 75 |
|
---|
| 76 | 09/13
|
---|
| 77 | - added log_debug_msg()
|
---|
| 78 | - turned log_it() into a macro
|
---|
| 79 |
|
---|
| 80 | 09/10
|
---|
| 81 | - reduced PPCFG_RAMDISK to 150m (was 200m)
|
---|
| 82 | - max set size is now 8MB (was 6)
|
---|
| 83 | - added 'buffer' to requisite tools
|
---|
| 84 |
|
---|
| 85 | 08/29
|
---|
| 86 | - typical set size is now 5MB
|
---|
| 87 |
|
---|
| 88 | 07/22
|
---|
| 89 | - increased PPCFG* to 200m
|
---|
| 90 |
|
---|
| 91 | 05/07
|
---|
| 92 | - changed grep -m1 to grep | head -n1 for Debian users
|
---|
| 93 | - pre_param_...() also mkdir -p /mnt/cdrom, just in case
|
---|
| 94 |
|
---|
| 95 | 05/05
|
---|
| 96 | - cleaner logging of call to dd if=<tape> of=/dev/null
|
---|
| 97 | - added Joshua Oreman's FreeBSD patches
|
---|
| 98 |
|
---|
| 99 | 05/04
|
---|
| 100 | - added Herman Kuster's multi-level bkp patch
|
---|
| 101 |
|
---|
| 102 | 05/02
|
---|
| 103 | - log_it() --- "Message repeated N times" (if it was)
|
---|
| 104 |
|
---|
| 105 | 04/24
|
---|
| 106 | - added lots of assert()'s and log_OS_error()'s
|
---|
| 107 | - reset_bkpinfop() --- reset all media_size[] array
|
---|
| 108 | - increased tmpfs ramdisk to size=100m
|
---|
| 109 |
|
---|
| 110 | 04/22
|
---|
| 111 | - post_param_configuration() --- store iso-dev and isodir
|
---|
| 112 |
|
---|
| 113 | 04/05
|
---|
| 114 | - re-enable tmpfs ramdisk/mountpt _but_ make sure size=80m
|
---|
| 115 | - in post_param_configuration(), use cdrecord in preference
|
---|
| 116 | to dvdrecord now
|
---|
| 117 |
|
---|
| 118 | 03/27
|
---|
| 119 | - disabled tmpfs ramdisk/mountpt
|
---|
| 120 |
|
---|
| 121 | 01/02/2003
|
---|
| 122 | - bkpinfo->makefilelist = TRUE
|
---|
| 123 |
|
---|
| 124 | 12/10/2002
|
---|
| 125 | - added g_loglevel
|
---|
| 126 | - fixed minor bug in clean_up_KDE_desktop_if_necessary()
|
---|
| 127 | - log versions of newt, slang, ncurses
|
---|
| 128 | - isodir defaults to / if disaster recovery
|
---|
| 129 |
|
---|
| 130 | 11/28
|
---|
| 131 | - unmount all CD devices at start
|
---|
| 132 | - added clean_up_KDE_desktop_if_necessary()
|
---|
| 133 |
|
---|
| 134 | 11/20
|
---|
| 135 | - don't use lilo.conf.anaconda; abort instead
|
---|
| 136 | - mount/unmount /boot partition for Gentoo 1.2 users
|
---|
| 137 |
|
---|
| 138 | 11/13
|
---|
| 139 | - call mindi --makemountlist as part of testing sanity of distro
|
---|
| 140 |
|
---|
| 141 | 11/08
|
---|
| 142 | - added a couple of chmod 700's (one for scratchdir, one for tmpdir)
|
---|
| 143 | to post_param_configuration()
|
---|
| 144 |
|
---|
| 145 | 10/01 - 10/31
|
---|
| 146 | - added checking of / and /root's free space to some_basic_sanity_checks()
|
---|
| 147 | - moved some subroutines here from common/libmondo-archive
|
---|
| 148 |
|
---|
| 149 | 09/01 - 09/30
|
---|
| 150 | - don't write log_it()'s string to stdout, even if text mode
|
---|
| 151 | - tell user the kernel is bad if it has no ramdisk support but allow
|
---|
| 152 | it if they want to use the failsafe kernel for booting
|
---|
| 153 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 154 | whether it will log its activities in the event of _success_
|
---|
| 155 | - if mkfs.vfat not found but mkfs.msdos found then create a softlink
|
---|
| 156 | from the former to the latter
|
---|
| 157 |
|
---|
| 158 | 08/01 - 08/31
|
---|
| 159 | - if /etc/lilo.conf not found not /etc/lilo.conf.anaconda found
|
---|
| 160 | then create a softlink from the former to the latter, to work
|
---|
| 161 | around RH7.3's b0rken LILO support
|
---|
| 162 | - handle unknown media size
|
---|
| 163 |
|
---|
| 164 | 07/27
|
---|
| 165 | - created
|
---|
| 166 | */
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * @file
|
---|
| 171 | * Miscellaneous tools that didn't really fit anywhere else.
|
---|
| 172 | */
|
---|
| 173 |
|
---|
| 174 | #include "my-stuff.h"
|
---|
| 175 | #include "mondostructures.h"
|
---|
[541] | 176 | #include "lib-common-externs.h"
|
---|
[1] | 177 | #include "libmondo-tools.h"
|
---|
[541] | 178 | #include "libmondo-gui-EXT.h"
|
---|
[1] | 179 | #include "libmondo-files-EXT.h"
|
---|
| 180 | #include "libmondo-fork-EXT.h"
|
---|
| 181 | #include "libmondo-raid-EXT.h"
|
---|
| 182 | #include <sys/socket.h>
|
---|
| 183 | #include <netdb.h>
|
---|
[1653] | 184 | #include <stdlib.h>
|
---|
[1] | 185 | #include <netinet/in.h>
|
---|
| 186 | #include <arpa/inet.h>
|
---|
[1375] | 187 | #include <sys/utsname.h>
|
---|
[1] | 188 |
|
---|
| 189 | /*@unused@*/
|
---|
[99] | 190 | //static char cvsid[] = "$Id: libmondo-tools.c 1855 2008-01-11 10:22:18Z bruno $";
|
---|
[1] | 191 |
|
---|
| 192 | extern int g_tape_buffer_size_MB;
|
---|
| 193 | extern char *g_serial_string;
|
---|
| 194 | extern bool g_text_mode;
|
---|
| 195 | extern int g_currentY;
|
---|
| 196 | extern int g_current_media_number;
|
---|
[1316] | 197 | extern char *MONDO_LOGFILE;
|
---|
[1] | 198 |
|
---|
[1645] | 199 | /* Reference to global bkpinfo */
|
---|
| 200 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 201 |
|
---|
[1] | 202 | /**
|
---|
| 203 | * @addtogroup globalGroup
|
---|
| 204 | * @{
|
---|
| 205 | */
|
---|
[128] | 206 | bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
|
---|
| 207 | g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
|
---|
| 208 | bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
|
---|
[1] | 209 | double g_kernel_version;
|
---|
| 210 |
|
---|
| 211 | /**
|
---|
| 212 | * The place where /boot is mounted.
|
---|
| 213 | */
|
---|
[128] | 214 | char *g_boot_mountpt = NULL;
|
---|
[1] | 215 |
|
---|
| 216 | /**
|
---|
| 217 | * The location of Mondo's home directory.
|
---|
| 218 | */
|
---|
[128] | 219 | char *g_mondo_home = NULL;
|
---|
[1] | 220 |
|
---|
| 221 | /**
|
---|
| 222 | * The serial string (used to differentiate between backups) of the current backup.
|
---|
| 223 | */
|
---|
[128] | 224 | char *g_serial_string = NULL;
|
---|
[1] | 225 |
|
---|
| 226 | /**
|
---|
| 227 | * The location where tmpfs is mounted, or "" if it's not mounted.
|
---|
| 228 | */
|
---|
[128] | 229 | char *g_tmpfs_mountpt = NULL;
|
---|
| 230 | char *g_magicdev_command = NULL;
|
---|
[1] | 231 |
|
---|
| 232 | /**
|
---|
| 233 | * The default maximum level to log messages at or below.
|
---|
| 234 | */
|
---|
[128] | 235 | int g_loglevel = DEFAULT_DEBUG_LEVEL;
|
---|
[1] | 236 |
|
---|
| 237 | /* @} - end of globalGroup */
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | extern pid_t g_buffer_pid;
|
---|
| 241 | extern pid_t g_main_pid;
|
---|
| 242 |
|
---|
| 243 | extern t_bkptype g_backup_media_type;
|
---|
| 244 |
|
---|
| 245 | extern bool am_I_in_disaster_recovery_mode(void);
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | /**
|
---|
| 249 | * @addtogroup utilityGroup
|
---|
| 250 | * @{
|
---|
| 251 | */
|
---|
| 252 | /**
|
---|
| 253 | * Assertion handler. Prints a friendly message to the user,
|
---|
| 254 | * offering to ignore all, dump core, break to debugger,
|
---|
| 255 | * exit, or ignore. Intended to be used with an assert() macro.
|
---|
| 256 | *
|
---|
| 257 | * @param file The file in which the assertion triggered.
|
---|
| 258 | * @param function The function (@c __FUNCTION__) in which the assertion triggered.
|
---|
| 259 | * @param line The line number of the assert() statement.
|
---|
| 260 | * @param exp The expression that failed (as a string).
|
---|
| 261 | */
|
---|
[128] | 262 | void _mondo_assert_fail(const char *file,
|
---|
| 263 | const char *function, int line, const char *exp)
|
---|
[1] | 264 | {
|
---|
[128] | 265 | static int ignoring_assertions = 0;
|
---|
| 266 | bool is_valid = TRUE;
|
---|
[1] | 267 |
|
---|
[128] | 268 | log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
|
---|
| 269 | function);
|
---|
| 270 | if (ignoring_assertions) {
|
---|
| 271 | log_it("Well, the user doesn't care...");
|
---|
| 272 | return;
|
---|
| 273 | }
|
---|
[1] | 274 | #ifndef _XWIN
|
---|
[128] | 275 | if (!g_text_mode)
|
---|
| 276 | newtSuspend();
|
---|
[1] | 277 | #endif
|
---|
[541] | 278 | printf("ASSERTION FAILED: `%s'\n", exp);
|
---|
| 279 | printf("\tat %s:%d in %s\n\n", file, line, function);
|
---|
| 280 | printf("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
|
---|
[128] | 281 | do {
|
---|
| 282 | is_valid = TRUE;
|
---|
| 283 | switch (toupper(getchar())) {
|
---|
| 284 | case 'A': // ignore (A)ll
|
---|
| 285 | ignoring_assertions = 1;
|
---|
| 286 | break;
|
---|
| 287 | case 'B': // a(B)ort
|
---|
| 288 | signal(SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
|
---|
| 289 | raise(SIGABRT);
|
---|
| 290 | break; /* "can't get here" */
|
---|
| 291 | case 'D': // (D)ebug, aka asm("int 3")
|
---|
[1] | 292 | #ifdef __IA32__
|
---|
[128] | 293 | __asm__ __volatile__("int $3"); // break to debugger
|
---|
[1] | 294 | #endif
|
---|
[128] | 295 | break;
|
---|
| 296 | case 'E': // (E)xit
|
---|
| 297 | fatal_error("Failed assertion -- see above for details");
|
---|
| 298 | break; /* "can't get here" */
|
---|
| 299 | case 'I': // (I)gnore
|
---|
| 300 | break;
|
---|
| 301 | /* These next two work as follows:
|
---|
| 302 | the `default' catches the user's invalid choice and says so;
|
---|
| 303 | the '\n' catches the newline on the end and prints the prompt again.
|
---|
| 304 | */
|
---|
| 305 | case '\n':
|
---|
| 306 | printf
|
---|
[541] | 307 | ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
|
---|
[128] | 308 | break;
|
---|
| 309 | default:
|
---|
| 310 | is_valid = FALSE;
|
---|
[541] | 311 | printf("Invalid choice.\n");
|
---|
[128] | 312 | break;
|
---|
| 313 | }
|
---|
| 314 | } while (!is_valid);
|
---|
| 315 |
|
---|
| 316 | if (ignoring_assertions) {
|
---|
| 317 | log_it("Ignoring ALL assertions from now on.");
|
---|
| 318 | } else {
|
---|
| 319 | log_it("Ignoring assertion: %s", exp);
|
---|
[1] | 320 | }
|
---|
| 321 |
|
---|
[128] | 322 | getchar(); // skip \n
|
---|
[1] | 323 |
|
---|
| 324 | #ifndef _XWIN
|
---|
[128] | 325 | if (!g_text_mode)
|
---|
| 326 | newtResume();
|
---|
[1] | 327 | #endif
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | /**
|
---|
| 331 | * Clean's up users' KDE desktops.
|
---|
| 332 | * @bug Details about this function are unknown.
|
---|
| 333 | */
|
---|
| 334 | void clean_up_KDE_desktop_if_necessary(void)
|
---|
| 335 | {
|
---|
[128] | 336 | char *tmp;
|
---|
[1] | 337 |
|
---|
[128] | 338 | malloc_string(tmp);
|
---|
| 339 | strcpy(tmp,
|
---|
| 340 | "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
|
---|
[1] | 341 | file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
|
---|
[273] | 342 | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
|
---|
[275] | 343 | else { print $0;};}' $file.old > $file ; fi ; done");
|
---|
[128] | 344 | run_program_and_log_output(tmp, 5);
|
---|
| 345 | paranoid_free(tmp);
|
---|
[1] | 346 | }
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | /**
|
---|
| 350 | * Locate mondoarchive's home directory. Searches in /usr/local/mondo, /usr/share/mondo,
|
---|
| 351 | * /usr/local/share/mondo, /opt, or if all else fails, search /usr.
|
---|
| 352 | *
|
---|
| 353 | * @param home_sz String to store the home directory ("" if it could not be found).
|
---|
| 354 | * @return 0 for success, nonzero for failure.
|
---|
| 355 | */
|
---|
| 356 | int find_and_store_mondoarchives_home(char *home_sz)
|
---|
| 357 | {
|
---|
[128] | 358 | assert(home_sz != NULL);
|
---|
[424] | 359 | strcpy(home_sz, MONDO_SHARE);
|
---|
[182] | 360 | return (0);
|
---|
[1] | 361 | }
|
---|
| 362 |
|
---|
| 363 |
|
---|
[1375] | 364 | char *get_architecture(void) {
|
---|
[1] | 365 | #ifdef __IA32__
|
---|
[1375] | 366 | # ifdef __X86_64__
|
---|
| 367 | return ("x86_64");
|
---|
| 368 | # else
|
---|
| 369 | return ("i386");
|
---|
| 370 | # endif
|
---|
[1] | 371 | #endif
|
---|
| 372 | #ifdef __IA64__
|
---|
[128] | 373 | return ("ia64");
|
---|
[1] | 374 | #endif
|
---|
[128] | 375 | return ("unknown");
|
---|
[1] | 376 | }
|
---|
| 377 |
|
---|
| 378 |
|
---|
[1375] | 379 | char *get_uname_m(void) {
|
---|
[1] | 380 |
|
---|
[1375] | 381 | struct utsname utsn;
|
---|
| 382 | char *tmp = NULL;
|
---|
| 383 |
|
---|
| 384 | uname(&utsn);
|
---|
[1381] | 385 | asprintf(&tmp, utsn.machine);
|
---|
[1375] | 386 | return (tmp);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 |
|
---|
| 391 | double get_kernel_version(void)
|
---|
[1] | 392 | {
|
---|
[128] | 393 | char *p, tmp[200];
|
---|
| 394 | double d;
|
---|
[1] | 395 | #ifdef __FreeBSD__
|
---|
[128] | 396 | // JOSH - FIXME :)
|
---|
| 397 | d = 5.2; // :-)
|
---|
[1] | 398 | #else
|
---|
[128] | 399 | strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
|
---|
| 400 | p = strchr(tmp, '.');
|
---|
| 401 | if (p) {
|
---|
| 402 | p = strchr(++p, '.');
|
---|
| 403 | if (p) {
|
---|
| 404 | while (*p) {
|
---|
| 405 | *p = *(p + 1);
|
---|
| 406 | p++;
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
[1] | 410 | // log_msg(1, "tmp = '%s'", tmp);
|
---|
[128] | 411 | d = atof(tmp);
|
---|
[1] | 412 | #endif
|
---|
[128] | 413 | log_msg(1, "g_kernel_version = %f", d);
|
---|
| 414 | return (d);
|
---|
[1] | 415 | }
|
---|
| 416 |
|
---|
| 417 |
|
---|
| 418 |
|
---|
| 419 |
|
---|
| 420 |
|
---|
| 421 | /**
|
---|
| 422 | * Get the current time.
|
---|
| 423 | * @return number of seconds since the epoch.
|
---|
| 424 | */
|
---|
[128] | 425 | long get_time()
|
---|
[1] | 426 | {
|
---|
[128] | 427 | return (long) time((void *) 0);
|
---|
[1] | 428 | }
|
---|
| 429 |
|
---|
| 430 |
|
---|
| 431 |
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 |
|
---|
| 436 | /**
|
---|
| 437 | * Initialize a RAID volume structure, setting fields to zero. The
|
---|
| 438 | * actual hard drive is unaffected.
|
---|
| 439 | *
|
---|
| 440 | * @param raidrec The RAID volume structure to initialize.
|
---|
| 441 | * @note This function is system dependent.
|
---|
| 442 | */
|
---|
| 443 | #ifdef __FreeBSD__
|
---|
[128] | 444 | void initialize_raidrec(struct vinum_volume *raidrec)
|
---|
[1] | 445 | {
|
---|
[128] | 446 | int i, j;
|
---|
| 447 | raidrec->volname[0] = '\0';
|
---|
| 448 | raidrec->plexes = 0;
|
---|
| 449 | for (i = 0; i < 9; ++i) {
|
---|
| 450 | raidrec->plex[i].raidlevel = -1;
|
---|
| 451 | raidrec->plex[i].stripesize = 0;
|
---|
| 452 | raidrec->plex[i].subdisks = 0;
|
---|
| 453 | for (j = 0; j < 9; ++j) {
|
---|
| 454 | strcpy(raidrec->plex[i].sd[j].which_device, "");
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
[1] | 457 | }
|
---|
| 458 | #else
|
---|
[128] | 459 | void initialize_raidrec(struct raid_device_record *raidrec)
|
---|
[1] | 460 | {
|
---|
[128] | 461 | assert(raidrec != NULL);
|
---|
| 462 | raidrec->raid_device[0] = '\0';
|
---|
[558] | 463 | raidrec->raid_level = -9;
|
---|
[128] | 464 | raidrec->persistent_superblock = 1;
|
---|
[558] | 465 | raidrec->chunk_size = 64;
|
---|
| 466 | raidrec->parity = -1;
|
---|
[128] | 467 | raidrec->data_disks.entries = 0;
|
---|
| 468 | raidrec->spare_disks.entries = 0;
|
---|
| 469 | raidrec->parity_disks.entries = 0;
|
---|
| 470 | raidrec->failed_disks.entries = 0;
|
---|
| 471 | raidrec->additional_vars.entries = 0;
|
---|
[1] | 472 | }
|
---|
| 473 | #endif
|
---|
| 474 |
|
---|
| 475 |
|
---|
| 476 |
|
---|
| 477 |
|
---|
| 478 | /**
|
---|
| 479 | * Insert modules that Mondo requires.
|
---|
[1236] | 480 | * Currently inserts @c msdos, @c vfat, and @c loop for Linux;
|
---|
[1] | 481 | * @c msdosfs and @c ext2fs for FreeBSD.
|
---|
| 482 | */
|
---|
| 483 | void insmod_crucial_modules(void)
|
---|
| 484 | {
|
---|
| 485 | #ifdef __FreeBSD__
|
---|
[128] | 486 | system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
|
---|
| 487 | system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
|
---|
[1] | 488 | #else
|
---|
[1236] | 489 | system("modprobe -a msdos vfat loop &> /dev/null");
|
---|
[1] | 490 | #endif
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 |
|
---|
| 494 | /**
|
---|
[541] | 495 | * Log a trace message to the trace file.
|
---|
| 496 | * @bug This function seems orphaned. Please remove.
|
---|
| 497 | */
|
---|
| 498 | void log_trace(char *o)
|
---|
| 499 | {
|
---|
| 500 | /*@ pointers **************************************************** */
|
---|
| 501 | FILE *fout;
|
---|
| 502 |
|
---|
| 503 | /*@ buffers ***************************************************** */
|
---|
| 504 | char output[MAX_STR_LEN];
|
---|
| 505 |
|
---|
| 506 | /*@ int ****************************************************** */
|
---|
| 507 | int i;
|
---|
| 508 |
|
---|
| 509 | /*@ end vars *************************************************** */
|
---|
| 510 |
|
---|
| 511 | if (o[0] == '\0') {
|
---|
| 512 | return;
|
---|
| 513 | }
|
---|
| 514 | strcpy(output, o);
|
---|
| 515 | i = (int) strlen(output);
|
---|
| 516 | if (i <= 0) {
|
---|
| 517 | return;
|
---|
| 518 | }
|
---|
| 519 | if (output[i - 1] < 32) {
|
---|
| 520 | output[i - 1] = '\0';
|
---|
| 521 | }
|
---|
| 522 | if (g_text_mode
|
---|
| 523 | /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
|
---|
| 524 | printf("%s\n", output);
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | fout = fopen(MONDO_TRACEFILE, "a");
|
---|
| 528 | if (fout) {
|
---|
| 529 | fprintf(fout, "%s\n", output);
|
---|
| 530 | paranoid_fclose(fout);
|
---|
| 531 | } else {
|
---|
| 532 | log_OS_error("Cannot write to tracefile");
|
---|
| 533 | }
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 |
|
---|
| 537 |
|
---|
| 538 |
|
---|
| 539 |
|
---|
| 540 | /**
|
---|
[1] | 541 | * Finish configuring the backup information structure. Call this function
|
---|
| 542 | * to set the parameters that depend on those that can be given on the command
|
---|
| 543 | * line.
|
---|
| 544 | *
|
---|
| 545 | * @param bkpinfo The backup information structure. Fields modified/used:
|
---|
| 546 | * - Used: @c bkpinfo->backup_data
|
---|
| 547 | * - Used: @c bkpinfo->backup_media_type
|
---|
| 548 | * - Used: @c bkpinfo->cdrw_speed
|
---|
| 549 | * - Used: @c bkpinfo->compression_level
|
---|
| 550 | * - Used: @c bkpinfo->include_paths
|
---|
[20] | 551 | * - Used: @c bkpinfo->prefix
|
---|
[1] | 552 | * - Used: @c bkpinfo->isodir
|
---|
| 553 | * - Used: @c bkpinfo->manual_cd_tray
|
---|
| 554 | * - Used: @c bkpinfo->make_cd_use_lilo
|
---|
| 555 | * - Used: @c bkpinfo->media_device
|
---|
| 556 | * - Used: @c bkpinfo->nfs_mount
|
---|
| 557 | * - Used: @c bkpinfo->nonbootable_backup
|
---|
| 558 | * - Used: @c bkpinfo->scratchdir
|
---|
| 559 | * - Used: @c bkpinfo->tmpdir
|
---|
| 560 | * - Used: @c bkpinfo->use_lzo
|
---|
| 561 | * - Modified: @c bkpinfo->call_before_iso
|
---|
| 562 | * - Modified: @c bkpinfo->call_make_iso
|
---|
| 563 | * - Modified: @c bkpinfo->optimal_set_size
|
---|
| 564 | * - Modified: @c bkpinfo->zip_exe
|
---|
| 565 | * - Modified: @c bkpinfo->zip_suffix
|
---|
| 566 | *
|
---|
| 567 | * @return number of errors, or 0 for success.
|
---|
| 568 | * @note Also creates directories that are specified in the @c bkpinfo structure but
|
---|
| 569 | * do not exist.
|
---|
| 570 | */
|
---|
[1645] | 571 | int post_param_configuration()
|
---|
[1] | 572 | {
|
---|
[128] | 573 | char *extra_cdrom_params;
|
---|
| 574 | char *mondo_mkisofs_sz;
|
---|
| 575 | char *command;
|
---|
| 576 | char *mtpt;
|
---|
| 577 | char *hostname, *ip_address;
|
---|
| 578 | int retval = 0;
|
---|
| 579 | long avm = 0;
|
---|
| 580 | char *colon;
|
---|
| 581 | char *cdr_exe;
|
---|
| 582 | char *tmp;
|
---|
[163] | 583 | char call_before_iso_user[MAX_STR_LEN] = "\0";
|
---|
[128] | 584 | int rdsiz_MB;
|
---|
| 585 | char *iso_dev;
|
---|
| 586 | char *iso_mnt;
|
---|
| 587 | char *iso_tmp;
|
---|
| 588 | char *iso_path;
|
---|
[1] | 589 |
|
---|
[128] | 590 | assert(bkpinfo != NULL);
|
---|
| 591 | malloc_string(extra_cdrom_params);
|
---|
| 592 | malloc_string(mondo_mkisofs_sz);
|
---|
| 593 | malloc_string(command);
|
---|
| 594 | malloc_string(mtpt);
|
---|
| 595 | malloc_string(hostname);
|
---|
| 596 | malloc_string(ip_address);
|
---|
| 597 | malloc_string(cdr_exe);
|
---|
| 598 | malloc_string(tmp);
|
---|
| 599 | malloc_string(iso_dev);
|
---|
| 600 | malloc_string(iso_mnt);
|
---|
| 601 | malloc_string(iso_tmp);
|
---|
| 602 | malloc_string(iso_path);
|
---|
| 603 | bkpinfo->optimal_set_size =
|
---|
[686] | 604 | (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
|
---|
[128] | 605 | 1024;
|
---|
[1] | 606 |
|
---|
[128] | 607 | log_msg(1, "Foo");
|
---|
| 608 | if (bkpinfo->backup_media_type == tape) {
|
---|
| 609 | log_msg(1, "Bar");
|
---|
| 610 | sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
|
---|
| 611 | log_msg(1, "tmp = '%s'", tmp);
|
---|
| 612 | if (run_program_and_log_output(tmp, 3)) {
|
---|
| 613 | fatal_error
|
---|
| 614 | ("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.");
|
---|
| 615 | }
|
---|
[1] | 616 | }
|
---|
[128] | 617 | make_hole_for_dir(bkpinfo->scratchdir);
|
---|
| 618 | if (bkpinfo->backup_media_type == iso)
|
---|
| 619 | make_hole_for_dir(bkpinfo->isodir);
|
---|
[1] | 620 |
|
---|
[128] | 621 | run_program_and_log_output("uname -a", 5);
|
---|
[678] | 622 | run_program_and_log_output("cat /etc/*-release", 5);
|
---|
[128] | 623 | run_program_and_log_output("cat /etc/*issue*", 5);
|
---|
| 624 | sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
|
---|
| 625 | sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
|
---|
| 626 | paranoid_system(command);
|
---|
| 627 | rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
|
---|
[1] | 628 | #ifdef __FreeBSD__
|
---|
[128] | 629 | strcpy(tmp,
|
---|
| 630 | call_program_and_get_last_line_of_output
|
---|
| 631 | ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
|
---|
| 632 | avm += atol(tmp);
|
---|
| 633 | strcpy(tmp,
|
---|
| 634 | call_program_and_get_last_line_of_output
|
---|
| 635 | ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
|
---|
| 636 | avm += atol(tmp);
|
---|
| 637 | sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
|
---|
| 638 | g_tmpfs_mountpt);
|
---|
[1] | 639 | #else
|
---|
[128] | 640 | strcpy(tmp,
|
---|
| 641 | call_program_and_get_last_line_of_output
|
---|
[911] | 642 | ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1"));
|
---|
[128] | 643 | avm += atol(tmp);
|
---|
| 644 | sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
|
---|
| 645 | g_tmpfs_mountpt, rdsiz_MB, 'm');
|
---|
| 646 | run_program_and_log_output("cat /proc/cpuinfo", 5);
|
---|
| 647 | run_program_and_log_output
|
---|
| 648 | ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
|
---|
| 649 | 5);
|
---|
[1] | 650 | #endif
|
---|
[128] | 651 | if (avm / 1024 > rdsiz_MB * 3) {
|
---|
| 652 | if (run_program_and_log_output(command, 5)) {
|
---|
| 653 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 654 | log_it("Failed to mount tmpfs");
|
---|
| 655 | } else {
|
---|
| 656 | log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
|
---|
| 657 | }
|
---|
| 658 | } else {
|
---|
| 659 | g_tmpfs_mountpt[0] = '\0';
|
---|
| 660 | log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
|
---|
[1] | 661 | }
|
---|
[128] | 662 |
|
---|
| 663 | if (bkpinfo->use_lzo) {
|
---|
| 664 | strcpy(bkpinfo->zip_exe, "lzop");
|
---|
| 665 | strcpy(bkpinfo->zip_suffix, "lzo");
|
---|
[998] | 666 | } else if (bkpinfo->use_gzip) {
|
---|
| 667 | strcpy(bkpinfo->zip_exe, "gzip");
|
---|
| 668 | strcpy(bkpinfo->zip_suffix, "gz");
|
---|
[128] | 669 | } else if (bkpinfo->compression_level != 0) {
|
---|
| 670 | strcpy(bkpinfo->zip_exe, "bzip2");
|
---|
| 671 | strcpy(bkpinfo->zip_suffix, "bz2");
|
---|
| 672 | } else {
|
---|
| 673 | bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
|
---|
[1] | 674 | }
|
---|
| 675 |
|
---|
| 676 | // DVD
|
---|
| 677 |
|
---|
[128] | 678 | if (bkpinfo->backup_media_type == dvd) {
|
---|
| 679 | extra_cdrom_params[0] = '\0';
|
---|
| 680 | mondo_mkisofs_sz[0] = '\0';
|
---|
| 681 | if (find_home_of_exe("growisofs")) {
|
---|
| 682 | strcpy(cdr_exe, "growisofs");
|
---|
| 683 | } // unlikely to be used
|
---|
| 684 | else {
|
---|
| 685 | fatal_error("Please install growisofs.");
|
---|
| 686 | }
|
---|
| 687 | if (bkpinfo->nonbootable_backup) {
|
---|
| 688 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
|
---|
| 689 | } else if
|
---|
[1] | 690 | #ifdef __FreeBSD__
|
---|
[128] | 691 | (TRUE)
|
---|
[1] | 692 | #else
|
---|
[128] | 693 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 694 | #endif
|
---|
| 695 | #ifdef __IA64__
|
---|
[128] | 696 | {
|
---|
| 697 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
|
---|
| 698 | }
|
---|
[1] | 699 | #else
|
---|
| 700 | {
|
---|
[128] | 701 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
|
---|
[1] | 702 | }
|
---|
[128] | 703 | #endif
|
---|
| 704 | else
|
---|
| 705 | {
|
---|
| 706 | strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
|
---|
| 707 | }
|
---|
| 708 | if (bkpinfo->manual_cd_tray) {
|
---|
| 709 | fatal_error("Manual CD tray + DVD not supported yet.");
|
---|
| 710 | // -m isn't supported by growisofs, BTW...
|
---|
| 711 | } else {
|
---|
| 712 | sprintf(bkpinfo->call_make_iso,
|
---|
| 713 | "%s %s -Z %s . 2>> _ERR_",
|
---|
| 714 | mondo_mkisofs_sz,
|
---|
| 715 | extra_cdrom_params, bkpinfo->media_device);
|
---|
| 716 | }
|
---|
[153] | 717 | if (getenv ("SUDO_COMMAND")) {
|
---|
[679] | 718 | sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
|
---|
| 719 | if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
|
---|
| 720 | popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
| 721 | fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
|
---|
| 722 | }
|
---|
[153] | 723 | }
|
---|
[128] | 724 | log_msg(2, "call_make_iso (DVD res) is ... %s",
|
---|
| 725 | bkpinfo->call_make_iso);
|
---|
| 726 | } // end of DVD code
|
---|
[1] | 727 |
|
---|
| 728 | // CD-R or CD-RW
|
---|
[128] | 729 | if (bkpinfo->backup_media_type == cdrw
|
---|
| 730 | || bkpinfo->backup_media_type == cdr) {
|
---|
| 731 | extra_cdrom_params[0] = '\0';
|
---|
| 732 | if (!bkpinfo->manual_cd_tray) {
|
---|
| 733 | strcat(extra_cdrom_params, "-waiti ");
|
---|
| 734 | }
|
---|
| 735 | if (bkpinfo->backup_media_type == cdrw) {
|
---|
| 736 | strcat(extra_cdrom_params, "blank=fast ");
|
---|
| 737 | }
|
---|
| 738 | if (find_home_of_exe("cdrecord")) {
|
---|
| 739 | strcpy(cdr_exe, "cdrecord");
|
---|
| 740 | } else if (find_home_of_exe("dvdrecord")) {
|
---|
| 741 | strcpy(cdr_exe, "dvdrecord");
|
---|
| 742 | } else {
|
---|
| 743 | fatal_error("Please install either cdrecord or dvdrecord.");
|
---|
| 744 | }
|
---|
| 745 | if (bkpinfo->nonbootable_backup) {
|
---|
| 746 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
|
---|
| 747 | } else if
|
---|
[1] | 748 | #ifdef __FreeBSD__
|
---|
[128] | 749 | (TRUE)
|
---|
[1] | 750 | #else
|
---|
[128] | 751 | (bkpinfo->make_cd_use_lilo)
|
---|
[1] | 752 | #endif
|
---|
| 753 | #ifdef __IA64__
|
---|
| 754 | {
|
---|
[128] | 755 | strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
|
---|
[1] | 756 | }
|
---|
[128] | 757 | #else
|
---|
[1] | 758 | {
|
---|
[128] | 759 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
|
---|
[1] | 760 | }
|
---|
[128] | 761 | #endif
|
---|
| 762 | else
|
---|
| 763 | {
|
---|
| 764 | strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
|
---|
| 765 | }
|
---|
| 766 | if (bkpinfo->manual_cd_tray) {
|
---|
[163] | 767 | if (bkpinfo->call_before_iso[0] == '\0') {
|
---|
[128] | 768 | sprintf(bkpinfo->call_before_iso,
|
---|
[1666] | 769 | "%s -o %s/"MONDO_TMPISOS" . 2>> _ERR_",
|
---|
[163] | 770 | mondo_mkisofs_sz, bkpinfo->tmpdir);
|
---|
| 771 | } else {
|
---|
| 772 | strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
|
---|
| 773 | sprintf (bkpinfo->call_before_iso,
|
---|
[1666] | 774 | "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )",
|
---|
[163] | 775 | mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
|
---|
| 776 | }
|
---|
| 777 | log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
|
---|
[128] | 778 | sprintf(bkpinfo->call_make_iso,
|
---|
[1666] | 779 | "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS,
|
---|
[128] | 780 | cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
|
---|
| 781 | extra_cdrom_params, bkpinfo->media_device,
|
---|
| 782 | bkpinfo->cdrw_speed, bkpinfo->tmpdir);
|
---|
| 783 | } else {
|
---|
| 784 | sprintf(bkpinfo->call_make_iso,
|
---|
| 785 | "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
|
---|
| 786 | mondo_mkisofs_sz, cdr_exe,
|
---|
| 787 | (bkpinfo->please_dont_eject) ? " " : "-eject",
|
---|
| 788 | extra_cdrom_params, bkpinfo->media_device,
|
---|
| 789 | bkpinfo->cdrw_speed);
|
---|
| 790 | }
|
---|
| 791 | } // end of CD code
|
---|
[1] | 792 |
|
---|
[128] | 793 | /*
|
---|
| 794 | if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
|
---|
| 795 | {
|
---|
| 796 | sprintf (tmp,
|
---|
| 797 | "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
|
---|
| 798 | bkpinfo->media_device, bkpinfo->internal_tape_block_size);
|
---|
| 799 | if (system(tmp))
|
---|
| 800 | {
|
---|
| 801 | retval++;
|
---|
| 802 | fprintf (stderr,
|
---|
| 803 | "Cannot write to tape device. Is the tape set read-only?\n");
|
---|
| 804 | }
|
---|
| 805 | } // end of tape code
|
---|
| 806 | */
|
---|
[1] | 807 |
|
---|
| 808 |
|
---|
[128] | 809 | if (bkpinfo->backup_media_type == iso) {
|
---|
| 810 |
|
---|
[1] | 811 | /* Patch by Conor Daly <conor.daly@met.ie>
|
---|
| 812 | * 23-june-2004
|
---|
| 813 | * Break up isodir into iso_mnt and iso_path
|
---|
| 814 | * These will be used along with iso-dev at restore time
|
---|
| 815 | * to locate the ISOs where ever they're mounted
|
---|
| 816 | */
|
---|
| 817 |
|
---|
[128] | 818 | log_it("isodir = %s", bkpinfo->isodir);
|
---|
[165] | 819 | sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
|
---|
[128] | 820 | bkpinfo->isodir);
|
---|
| 821 | log_it("command = %s", command);
|
---|
| 822 | log_it("res of it = %s",
|
---|
| 823 | call_program_and_get_last_line_of_output(command));
|
---|
| 824 | sprintf(iso_dev, "%s",
|
---|
| 825 | call_program_and_get_last_line_of_output(command));
|
---|
| 826 | sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
|
---|
| 827 | write_one_liner_data_file(tmp,
|
---|
| 828 | call_program_and_get_last_line_of_output
|
---|
| 829 | (command));
|
---|
[1] | 830 |
|
---|
[128] | 831 | sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
|
---|
| 832 | iso_dev);
|
---|
| 833 | log_it("command = %s", command);
|
---|
| 834 | log_it("res of it = %s",
|
---|
| 835 | call_program_and_get_last_line_of_output(command));
|
---|
| 836 | sprintf(iso_mnt, "%s",
|
---|
| 837 | call_program_and_get_last_line_of_output(command));
|
---|
| 838 | sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
|
---|
| 839 | write_one_liner_data_file(tmp,
|
---|
| 840 | call_program_and_get_last_line_of_output
|
---|
| 841 | (command));
|
---|
| 842 | log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
|
---|
| 843 | sprintf(iso_tmp, "%s", bkpinfo->isodir);
|
---|
| 844 | if (strlen(iso_tmp) < strlen(iso_mnt)) {
|
---|
| 845 | iso_path[0] = '\0';
|
---|
| 846 | } else {
|
---|
| 847 | sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
|
---|
| 848 | }
|
---|
| 849 | sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
|
---|
| 850 | write_one_liner_data_file(tmp, iso_path);
|
---|
| 851 | log_it("isodir: %s", iso_path);
|
---|
[148] | 852 | sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
|
---|
| 853 | write_one_liner_data_file(tmp, bkpinfo->prefix);
|
---|
| 854 | log_it("iso-prefix: %s", bkpinfo->prefix);
|
---|
[1] | 855 |
|
---|
| 856 | /* End patch */
|
---|
[128] | 857 | } // end of iso code
|
---|
[1] | 858 |
|
---|
[128] | 859 | if (bkpinfo->backup_media_type == nfs) {
|
---|
| 860 | strcpy(hostname, bkpinfo->nfs_mount);
|
---|
| 861 | colon = strchr(hostname, ':');
|
---|
| 862 | if (!colon) {
|
---|
| 863 | log_it("nfs mount doesn't have a colon in it");
|
---|
| 864 | retval++;
|
---|
| 865 | } else {
|
---|
| 866 | struct hostent *hent;
|
---|
[1] | 867 |
|
---|
[128] | 868 | *colon = '\0';
|
---|
| 869 | hent = gethostbyname(hostname);
|
---|
| 870 | if (!hent) {
|
---|
| 871 | log_it("Can't resolve NFS mount (%s): %s", hostname,
|
---|
| 872 | hstrerror(h_errno));
|
---|
| 873 | retval++;
|
---|
| 874 | } else {
|
---|
| 875 | strcpy(ip_address, inet_ntoa
|
---|
| 876 | ((struct in_addr)
|
---|
| 877 | *((struct in_addr *) hent->h_addr)));
|
---|
| 878 | strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
|
---|
| 879 | strcpy(bkpinfo->nfs_mount, ip_address);
|
---|
| 880 | }
|
---|
| 881 | }
|
---|
[1645] | 882 | store_nfs_config();
|
---|
[128] | 883 | }
|
---|
[1] | 884 |
|
---|
[128] | 885 | log_it("Finished processing incoming params");
|
---|
| 886 | if (retval) {
|
---|
| 887 | fprintf(stderr, "Type 'man mondoarchive' for help.\n");
|
---|
| 888 | }
|
---|
| 889 | if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
|
---|
| 890 | log_it("tmpdir or scratchdir are blank/missing");
|
---|
| 891 | retval++;
|
---|
| 892 | }
|
---|
| 893 | if (bkpinfo->include_paths[0] == '\0') {
|
---|
| 894 | // fatal_error ("Why no backup path?");
|
---|
| 895 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 896 | }
|
---|
| 897 | chmod(bkpinfo->scratchdir, 0700);
|
---|
| 898 | g_backup_media_type = bkpinfo->backup_media_type;
|
---|
| 899 | paranoid_free(mtpt);
|
---|
| 900 | paranoid_free(extra_cdrom_params);
|
---|
| 901 | paranoid_free(mondo_mkisofs_sz);
|
---|
| 902 | paranoid_free(command);
|
---|
| 903 | paranoid_free(hostname);
|
---|
| 904 | paranoid_free(ip_address);
|
---|
| 905 | paranoid_free(cdr_exe);
|
---|
| 906 | paranoid_free(tmp);
|
---|
| 907 | paranoid_free(iso_dev);
|
---|
| 908 | paranoid_free(iso_mnt);
|
---|
| 909 | paranoid_free(iso_tmp);
|
---|
| 910 | paranoid_free(iso_path);
|
---|
| 911 | return (retval);
|
---|
[1] | 912 | }
|
---|
| 913 |
|
---|
| 914 |
|
---|
| 915 |
|
---|
| 916 | /**
|
---|
| 917 | * Do some miscellaneous setup tasks to be performed before filling @c bkpinfo.
|
---|
| 918 | * Seeds the random-number generator, loads important modules, checks the sanity
|
---|
| 919 | * of the user's Linux distribution, and deletes logfile.
|
---|
| 920 | * @param bkpinfo The backup information structure. Will be initialized.
|
---|
| 921 | * @return number of errors (0 for success)
|
---|
| 922 | */
|
---|
[1645] | 923 | int pre_param_configuration()
|
---|
[1] | 924 | {
|
---|
[128] | 925 | int res = 0;
|
---|
[1652] | 926 | char *tmp = NULL;
|
---|
[1] | 927 |
|
---|
[128] | 928 | make_hole_for_dir(MNT_CDROM);
|
---|
| 929 | assert(bkpinfo != NULL);
|
---|
| 930 | srandom((unsigned long) (time(NULL)));
|
---|
| 931 | insmod_crucial_modules();
|
---|
| 932 | if (bkpinfo->disaster_recovery) {
|
---|
| 933 | if (!does_nonMS_partition_exist()) {
|
---|
| 934 | fatal_error
|
---|
| 935 | ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
|
---|
| 936 | }
|
---|
| 937 | }
|
---|
[1] | 938 |
|
---|
[128] | 939 | unlink(MONDO_TRACEFILE);
|
---|
[1747] | 940 | asprintf(&tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);
|
---|
[1652] | 941 | run_program_and_log_output(tmp, FALSE);
|
---|
| 942 | paranoid_free(tmp);
|
---|
[128] | 943 | if (find_and_store_mondoarchives_home(g_mondo_home)) {
|
---|
| 944 | fprintf(stderr,
|
---|
| 945 | "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
|
---|
| 946 | res++;
|
---|
| 947 | return (res);
|
---|
| 948 | }
|
---|
| 949 | res += some_basic_system_sanity_checks();
|
---|
| 950 | if (res) {
|
---|
| 951 | log_it("Your distribution did not pass Mondo's sanity test.");
|
---|
| 952 | }
|
---|
| 953 | g_current_media_number = 1;
|
---|
| 954 | bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
|
---|
| 955 | return (res);
|
---|
[1] | 956 | }
|
---|
| 957 |
|
---|
[1655] | 958 | void setup_tmpdir(char *path) {
|
---|
[1653] | 959 |
|
---|
| 960 | char *tmp = NULL;
|
---|
[1654] | 961 | char *p = NULL;
|
---|
[1] | 962 |
|
---|
[1655] | 963 | if (bkpinfo->tmpdir != NULL) {
|
---|
| 964 | /* purging a potential old tmpdir */
|
---|
| 965 | asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
|
---|
[1657] | 966 | system(tmp);
|
---|
[1655] | 967 | paranoid_free(tmp);
|
---|
| 968 | }
|
---|
| 969 |
|
---|
[1657] | 970 | if (path != NULL) {
|
---|
| 971 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
|
---|
| 972 | } else if (getenv("TMPDIR")) {
|
---|
[1653] | 973 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
|
---|
| 974 | } else if (getenv("TMP")) {
|
---|
| 975 | asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
|
---|
| 976 | } else {
|
---|
| 977 | asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
|
---|
| 978 | }
|
---|
[1654] | 979 | p = mkdtemp(tmp);
|
---|
| 980 | if (p == NULL) {
|
---|
| 981 | log_it("Failed to create global tmp directory %s for Mondo.",tmp);
|
---|
[1653] | 982 | finish(-1);
|
---|
| 983 | }
|
---|
[1654] | 984 | strcpy(bkpinfo->tmpdir,p);
|
---|
| 985 | paranoid_free(tmp);
|
---|
[1658] | 986 |
|
---|
[1653] | 987 | //sprintf(bkpinfo->tmpdir, "%s/tmpfs/mondo.tmp.%d", "/tmp", (int) (random() % 32768)); // for mondorestore
|
---|
| 988 | }
|
---|
[1] | 989 |
|
---|
| 990 |
|
---|
| 991 | /**
|
---|
| 992 | * Reset all fields of the backup information structure to a sensible default.
|
---|
| 993 | * @param bkpinfo The @c bkpinfo to reset.
|
---|
| 994 | */
|
---|
[1645] | 995 | void reset_bkpinfo()
|
---|
[1] | 996 | {
|
---|
[128] | 997 | int i;
|
---|
[1] | 998 |
|
---|
[128] | 999 | log_msg(1, "Hi");
|
---|
| 1000 | assert(bkpinfo != NULL);
|
---|
| 1001 | memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
|
---|
[1653] | 1002 |
|
---|
| 1003 | /* special case for tmpdir as used eveywhere after */
|
---|
[1656] | 1004 | setup_tmpdir(NULL);
|
---|
[1653] | 1005 |
|
---|
[128] | 1006 | bkpinfo->manual_cd_tray = FALSE;
|
---|
| 1007 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
| 1008 | bkpinfo->media_device[0] = '\0';
|
---|
| 1009 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 1010 | bkpinfo->media_size[i] = -1;
|
---|
| 1011 | }
|
---|
| 1012 | bkpinfo->boot_loader = '\0';
|
---|
| 1013 | bkpinfo->boot_device[0] = '\0';
|
---|
| 1014 | bkpinfo->zip_exe[0] = '\0';
|
---|
| 1015 | bkpinfo->zip_suffix[0] = '\0';
|
---|
| 1016 | bkpinfo->restore_path[0] = '\0';
|
---|
| 1017 | bkpinfo->use_lzo = FALSE;
|
---|
[998] | 1018 | bkpinfo->use_gzip = FALSE;
|
---|
[128] | 1019 | bkpinfo->do_not_compress_these[0] = '\0';
|
---|
| 1020 | bkpinfo->verify_data = FALSE;
|
---|
| 1021 | bkpinfo->backup_data = FALSE;
|
---|
| 1022 | bkpinfo->restore_data = FALSE;
|
---|
| 1023 | bkpinfo->disaster_recovery =
|
---|
| 1024 | (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
|
---|
| 1025 | if (bkpinfo->disaster_recovery) {
|
---|
| 1026 | strcpy(bkpinfo->isodir, "/");
|
---|
| 1027 | } else {
|
---|
[541] | 1028 | strcpy(bkpinfo->isodir, "/root/images/mondo");
|
---|
[128] | 1029 | }
|
---|
[148] | 1030 | strcpy(bkpinfo->prefix, STD_PREFIX);
|
---|
[1] | 1031 |
|
---|
[128] | 1032 | bkpinfo->scratchdir[0] = '\0';
|
---|
| 1033 | bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
|
---|
| 1034 | bkpinfo->optimal_set_size = 0;
|
---|
| 1035 | bkpinfo->backup_media_type = none;
|
---|
| 1036 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 1037 | bkpinfo->exclude_paths[0] = '\0';
|
---|
| 1038 | bkpinfo->call_before_iso[0] = '\0';
|
---|
| 1039 | bkpinfo->call_make_iso[0] = '\0';
|
---|
| 1040 | bkpinfo->call_burn_iso[0] = '\0';
|
---|
| 1041 | bkpinfo->call_after_iso[0] = '\0';
|
---|
| 1042 | bkpinfo->image_devs[0] = '\0';
|
---|
| 1043 | bkpinfo->postnuke_tarball[0] = '\0';
|
---|
| 1044 | bkpinfo->kernel_path[0] = '\0';
|
---|
| 1045 | bkpinfo->nfs_mount[0] = '\0';
|
---|
| 1046 | bkpinfo->nfs_remote_dir[0] = '\0';
|
---|
| 1047 | bkpinfo->wipe_media_first = FALSE;
|
---|
| 1048 | bkpinfo->differential = FALSE;
|
---|
| 1049 | bkpinfo->cdrw_speed = 0;
|
---|
[1] | 1050 | // patch by Herman Kuster
|
---|
[128] | 1051 | bkpinfo->differential = 0;
|
---|
[1] | 1052 | // patch end
|
---|
[128] | 1053 | bkpinfo->compression_level = 3;
|
---|
[1] | 1054 | }
|
---|
| 1055 |
|
---|
| 1056 |
|
---|
| 1057 |
|
---|
| 1058 |
|
---|
| 1059 | /**
|
---|
| 1060 | * Get the remaining free space (in MB) on @p partition.
|
---|
| 1061 | * @param partition The partition to check free space on (either a device or a mountpoint).
|
---|
| 1062 | * @return The free space on @p partition, in MB.
|
---|
| 1063 | */
|
---|
[128] | 1064 | long free_space_on_given_partition(char *partition)
|
---|
[1] | 1065 | {
|
---|
[128] | 1066 | char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
|
---|
| 1067 | long res;
|
---|
[1] | 1068 |
|
---|
[128] | 1069 | assert_string_is_neither_NULL_nor_zerolength(partition);
|
---|
[1] | 1070 |
|
---|
[1744] | 1071 | sprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);
|
---|
[128] | 1072 | if (system(command)) {
|
---|
| 1073 | return (-1);
|
---|
| 1074 | } // partition does not exist
|
---|
[305] | 1075 | sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
|
---|
[128] | 1076 | partition);
|
---|
| 1077 | strcpy(out_sz, call_program_and_get_last_line_of_output(command));
|
---|
| 1078 | if (strlen(out_sz) == 0) {
|
---|
| 1079 | return (-1);
|
---|
| 1080 | } // error within df, probably
|
---|
| 1081 | res = atol(out_sz);
|
---|
| 1082 | return (res);
|
---|
[1] | 1083 | }
|
---|
| 1084 |
|
---|
| 1085 |
|
---|
| 1086 |
|
---|
| 1087 | /**
|
---|
| 1088 | * Check the user's system for sanity. Checks performed:
|
---|
| 1089 | * - make sure user has enough RAM (32mb required, 64mb recommended)
|
---|
| 1090 | * - make sure user has enough free space in @c /
|
---|
| 1091 | * - check kernel for ramdisk support
|
---|
| 1092 | * - make sure afio, cdrecord, mkisofs, bzip2, awk, md5sum, strings, mindi, and buffer exist
|
---|
| 1093 | * - make sure CD-ROM is unmounted
|
---|
| 1094 | * - make sure /etc/modules.conf exists
|
---|
| 1095 | * - make sure user's mountlist is OK by running <tt>mindi --makemountlist</tt>
|
---|
| 1096 | *
|
---|
| 1097 | * @return number of problems with the user's setup (0 for success)
|
---|
| 1098 | */
|
---|
[128] | 1099 | int some_basic_system_sanity_checks()
|
---|
[1] | 1100 | {
|
---|
| 1101 |
|
---|
[128] | 1102 | /*@ buffers ************ */
|
---|
| 1103 | char tmp[MAX_STR_LEN];
|
---|
| 1104 | // char command[MAX_STR_LEN];
|
---|
[1] | 1105 |
|
---|
[128] | 1106 | /*@ int's *************** */
|
---|
| 1107 | int retval = 0;
|
---|
[1] | 1108 |
|
---|
[128] | 1109 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 1110 | "Checking sanity of your Linux distribution");
|
---|
[1] | 1111 | #ifndef __FreeBSD__
|
---|
[1737] | 1112 | if (system("which mkfs.vfat 2> /dev/null 1> /dev/null")
|
---|
| 1113 | && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) {
|
---|
[128] | 1114 | log_it
|
---|
| 1115 | ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
|
---|
| 1116 | run_program_and_log_output
|
---|
| 1117 | ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
|
---|
| 1118 | }
|
---|
| 1119 | strcpy(tmp,
|
---|
| 1120 | call_program_and_get_last_line_of_output
|
---|
| 1121 | ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
|
---|
| 1122 | if (atol(tmp) < 35000) {
|
---|
| 1123 | retval++;
|
---|
[541] | 1124 | log_to_screen("You must have at least 32MB of RAM to use Mondo.");
|
---|
[128] | 1125 | }
|
---|
| 1126 | if (atol(tmp) < 66000) {
|
---|
| 1127 | log_to_screen
|
---|
[541] | 1128 | ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
|
---|
[128] | 1129 | }
|
---|
[1] | 1130 | #endif
|
---|
| 1131 |
|
---|
[128] | 1132 | if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
|
---|
| 1133 | retval++;
|
---|
| 1134 | log_to_screen
|
---|
| 1135 | ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
|
---|
| 1136 | fatal_error
|
---|
| 1137 | ("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. :)");
|
---|
| 1138 | }
|
---|
[1] | 1139 | #ifndef __FreeBSD__
|
---|
[128] | 1140 | if (run_program_and_log_output
|
---|
[273] | 1141 | ("grep ramdisk /proc/devices", FALSE)) {
|
---|
[128] | 1142 | if (!ask_me_yes_or_no
|
---|
[541] | 1143 | ("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] | 1144 | {
|
---|
| 1145 | // retval++;
|
---|
| 1146 | log_to_screen
|
---|
[541] | 1147 | ("It looks as if your kernel lacks ramdisk and initrd support.");
|
---|
[128] | 1148 | log_to_screen
|
---|
[541] | 1149 | ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
|
---|
[128] | 1150 | }
|
---|
| 1151 | }
|
---|
[1] | 1152 | #endif
|
---|
[128] | 1153 | retval += whine_if_not_found(MKE2FS_OR_NEWFS);
|
---|
| 1154 | retval += whine_if_not_found("mkisofs");
|
---|
| 1155 | if (system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 1156 | retval += whine_if_not_found("cdrecord");
|
---|
| 1157 | }
|
---|
| 1158 | retval += whine_if_not_found("bzip2");
|
---|
[998] | 1159 | retval += whine_if_not_found("gzip");
|
---|
[128] | 1160 | retval += whine_if_not_found("awk");
|
---|
| 1161 | retval += whine_if_not_found("md5sum");
|
---|
| 1162 | retval += whine_if_not_found("strings");
|
---|
| 1163 | retval += whine_if_not_found("mindi");
|
---|
| 1164 | retval += whine_if_not_found("buffer");
|
---|
[1] | 1165 |
|
---|
[128] | 1166 | // abort if Windows partition but no ms-sys and parted
|
---|
[1855] | 1167 | if (!run_program_and_log_output("mount | grep -Ew 'vfat|fat|dos' | grep -vE \"/dev/fd|nexdisk\"", 0)) {
|
---|
[541] | 1168 | log_to_screen("I think you have a Windows 9x partition.");
|
---|
[128] | 1169 | retval += whine_if_not_found("parted");
|
---|
[1] | 1170 | }
|
---|
| 1171 |
|
---|
[128] | 1172 | if (!find_home_of_exe("cmp")) {
|
---|
| 1173 | if (!find_home_of_exe("true")) {
|
---|
| 1174 | whine_if_not_found("cmp");
|
---|
| 1175 | } else {
|
---|
| 1176 | log_to_screen
|
---|
[541] | 1177 | ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
|
---|
[128] | 1178 | if (run_program_and_log_output
|
---|
| 1179 | ("cp -f `which true` /usr/bin/cmp", 0)) {
|
---|
| 1180 | fatal_error("Failed to create dummy 'cmp' file.");
|
---|
| 1181 | }
|
---|
| 1182 | }
|
---|
[1] | 1183 | }
|
---|
[128] | 1184 | run_program_and_log_output
|
---|
| 1185 | ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
|
---|
| 1186 | strcpy(tmp,
|
---|
| 1187 | call_program_and_get_last_line_of_output
|
---|
| 1188 | ("mount | grep -E \"cdr(om|w)\""));
|
---|
| 1189 | if (strcmp("", tmp)) {
|
---|
| 1190 | if (strstr(tmp, "autofs")) {
|
---|
| 1191 | log_to_screen
|
---|
[541] | 1192 | ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
|
---|
[128] | 1193 | log_to_screen
|
---|
[541] | 1194 | ("if a CD actually is inserted. If a CD is inserted, please");
|
---|
| 1195 | log_to_screen("eject it. Thank you.");
|
---|
[128] | 1196 | log_it
|
---|
| 1197 | ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
|
---|
| 1198 | } else
|
---|
| 1199 | if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
|
---|
| 1200 | retval++;
|
---|
| 1201 | fatal_error
|
---|
| 1202 | ("Your CD-ROM drive is mounted. Please unmount it.");
|
---|
| 1203 | }
|
---|
| 1204 | }
|
---|
[1] | 1205 | #ifndef __FreeBSD__
|
---|
[128] | 1206 | if (!does_file_exist("/etc/modules.conf")) {
|
---|
| 1207 | if (does_file_exist("/etc/conf.modules")) {
|
---|
| 1208 | log_it("Linking /etc/modules.conf to /etc/conf.modules");
|
---|
| 1209 | run_program_and_log_output
|
---|
| 1210 | ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
|
---|
| 1211 | } else if (does_file_exist("/etc/modprobe.d")) {
|
---|
| 1212 | log_it
|
---|
| 1213 | ("Directory /etc/modprobe.d found. mindi will use its contents.");
|
---|
| 1214 | } else if (does_file_exist("/etc/modprobe.conf")) {
|
---|
| 1215 | log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
|
---|
| 1216 | run_program_and_log_output
|
---|
| 1217 | ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
|
---|
| 1218 | } else {
|
---|
| 1219 | retval++;
|
---|
| 1220 | log_to_screen
|
---|
[541] | 1221 | ("Please find out what happened to /etc/modules.conf");
|
---|
[128] | 1222 | }
|
---|
[1] | 1223 | }
|
---|
| 1224 | #endif
|
---|
| 1225 |
|
---|
[128] | 1226 | run_program_and_log_output("cat /etc/fstab", 5);
|
---|
[1] | 1227 | #ifdef __FreeBSD__
|
---|
[128] | 1228 | run_program_and_log_output("vinum printconfig", 5);
|
---|
[1] | 1229 | #else
|
---|
[128] | 1230 | run_program_and_log_output("cat /etc/raidtab", 5);
|
---|
[1] | 1231 | #endif
|
---|
| 1232 |
|
---|
[128] | 1233 | if (run_program_and_log_output("mindi -V", 1)) {
|
---|
[541] | 1234 | log_to_screen("Could not ascertain mindi's version number.");
|
---|
[128] | 1235 | log_to_screen
|
---|
[541] | 1236 | ("You have not installed Mondo and/or Mindi properly.");
|
---|
| 1237 | log_to_screen("Please uninstall and reinstall them both.");
|
---|
[128] | 1238 | fatal_error("Please reinstall Mondo and Mindi.");
|
---|
| 1239 | }
|
---|
[1644] | 1240 | sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);
|
---|
| 1241 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1242 | sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir);
|
---|
| 1243 | log_to_screen(tmp);
|
---|
[128] | 1244 | log_to_screen
|
---|
[541] | 1245 | ("Please run that command by hand and examine /var/log/mindi.log");
|
---|
[128] | 1246 | log_to_screen
|
---|
[541] | 1247 | ("for more information. Perhaps your /etc/fstab file is insane.");
|
---|
[128] | 1248 | log_to_screen
|
---|
[541] | 1249 | ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
|
---|
[128] | 1250 | retval++;
|
---|
| 1251 | }
|
---|
[1] | 1252 |
|
---|
[196] | 1253 | if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
|
---|
[128] | 1254 | && !does_file_exist("/etc/raidtab")) {
|
---|
| 1255 | log_to_screen
|
---|
[541] | 1256 | ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
|
---|
[558] | 1257 | create_raidtab_from_mdstat("/etc/raidtab");
|
---|
[128] | 1258 | }
|
---|
| 1259 |
|
---|
| 1260 | if (retval) {
|
---|
[541] | 1261 | mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
|
---|
[128] | 1262 | } else {
|
---|
[541] | 1263 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[128] | 1264 | }
|
---|
| 1265 | return (retval);
|
---|
[1] | 1266 | }
|
---|
| 1267 |
|
---|
| 1268 | /**
|
---|
| 1269 | * Retrieve the line containing @p label from the config file.
|
---|
| 1270 | * @param config_file The file to read from, usually @c /tmp/mondo-restore.cfg.
|
---|
| 1271 | * @param label What to read from the file.
|
---|
| 1272 | * @param value Where to put it.
|
---|
| 1273 | * @return 0 for success, 1 for failure.
|
---|
| 1274 | */
|
---|
[128] | 1275 | int read_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1276 | {
|
---|
[128] | 1277 | /*@ buffer ****************************************************** */
|
---|
| 1278 | char command[MAX_STR_LEN * 2];
|
---|
| 1279 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1280 |
|
---|
[128] | 1281 | /*@ end vars *************************************************** */
|
---|
[1] | 1282 |
|
---|
[128] | 1283 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1284 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
| 1285 | if (!does_file_exist(config_file)) {
|
---|
| 1286 | sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
|
---|
| 1287 | config_file);
|
---|
| 1288 | log_to_screen(tmp);
|
---|
| 1289 | value[0] = '\0';
|
---|
| 1290 | return (1);
|
---|
[1279] | 1291 | } else if ((value != NULL) && (strstr(value, "/dev/") && strstr(value, "t0") && !strcmp(label, "media-dev"))) {
|
---|
| 1292 | log_msg(2, "FYI, I can't read new value for %s - already got %s", label, value);
|
---|
[128] | 1293 | return (0);
|
---|
| 1294 | } else {
|
---|
[148] | 1295 | sprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",
|
---|
| 1296 | label, config_file);
|
---|
[128] | 1297 | strcpy(value, call_program_and_get_last_line_of_output(command));
|
---|
| 1298 | if (strlen(value) == 0) {
|
---|
| 1299 | return (1);
|
---|
| 1300 | } else {
|
---|
| 1301 | return (0);
|
---|
| 1302 | }
|
---|
[1] | 1303 | }
|
---|
| 1304 | }
|
---|
| 1305 |
|
---|
| 1306 |
|
---|
| 1307 |
|
---|
| 1308 | /**
|
---|
| 1309 | * Remount @c supermount if it was unmounted earlier.
|
---|
| 1310 | */
|
---|
| 1311 | void remount_supermounts_if_necessary()
|
---|
| 1312 | {
|
---|
[128] | 1313 | if (g_remount_cdrom_at_end) {
|
---|
| 1314 | run_program_and_log_output("mount " MNT_CDROM, FALSE);
|
---|
| 1315 | }
|
---|
| 1316 | if (g_remount_floppy_at_end) {
|
---|
| 1317 | run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
|
---|
| 1318 | }
|
---|
[1] | 1319 | }
|
---|
| 1320 |
|
---|
| 1321 | /**
|
---|
| 1322 | * Unmount @c supermount if it's mounted.
|
---|
| 1323 | */
|
---|
| 1324 | void unmount_supermounts_if_necessary()
|
---|
| 1325 | {
|
---|
[128] | 1326 | if (run_program_and_log_output
|
---|
| 1327 | ("mount | grep cdrom | grep super", FALSE) == 0) {
|
---|
| 1328 | g_remount_cdrom_at_end = TRUE;
|
---|
| 1329 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 1330 | }
|
---|
| 1331 | if (run_program_and_log_output
|
---|
| 1332 | ("mount | grep floppy | grep super", FALSE) == 0) {
|
---|
| 1333 | g_remount_floppy_at_end = TRUE;
|
---|
| 1334 | run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
|
---|
| 1335 | }
|
---|
[1] | 1336 | }
|
---|
| 1337 |
|
---|
| 1338 | /**
|
---|
| 1339 | * Whether we had to stop autofs (if so, restart it at end).
|
---|
| 1340 | */
|
---|
[128] | 1341 | bool g_autofs_stopped = FALSE;
|
---|
[1] | 1342 |
|
---|
| 1343 | /**
|
---|
| 1344 | * Path to the autofs initscript ("" if none exists).
|
---|
| 1345 | */
|
---|
| 1346 | char g_autofs_exe[MAX_STR_LEN];
|
---|
| 1347 |
|
---|
| 1348 | /**
|
---|
| 1349 | * Autofs initscript in Xandros Linux distribution.
|
---|
| 1350 | */
|
---|
| 1351 | #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"
|
---|
| 1352 |
|
---|
| 1353 | /**
|
---|
| 1354 | * Autofs initscript in most Linux distributions.
|
---|
| 1355 | */
|
---|
| 1356 | #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"
|
---|
| 1357 |
|
---|
| 1358 | /**
|
---|
| 1359 | * If autofs is mounted, stop it (restart at end).
|
---|
| 1360 | */
|
---|
| 1361 | void stop_autofs_if_necessary()
|
---|
| 1362 | {
|
---|
[128] | 1363 | char tmp[MAX_STR_LEN];
|
---|
| 1364 |
|
---|
| 1365 | g_autofs_exe[0] = '\0';
|
---|
| 1366 | if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
|
---|
| 1367 | strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
|
---|
| 1368 | } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
|
---|
| 1369 | strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
|
---|
| 1370 | }
|
---|
| 1371 |
|
---|
| 1372 | if (!g_autofs_exe[0]) {
|
---|
| 1373 | log_msg(3, "No autofs detected.");
|
---|
| 1374 | } else {
|
---|
| 1375 | log_msg(3, "%s --- autofs detected", g_autofs_exe);
|
---|
[1] | 1376 | // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);
|
---|
[128] | 1377 | sprintf(tmp, "%s stop", g_autofs_exe);
|
---|
| 1378 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 1379 | log_it("Failed to stop autofs - I assume it wasn't running");
|
---|
| 1380 | } else {
|
---|
| 1381 | g_autofs_stopped = TRUE;
|
---|
| 1382 | log_it("Stopped autofs OK");
|
---|
| 1383 | }
|
---|
| 1384 | }
|
---|
[1] | 1385 | }
|
---|
| 1386 |
|
---|
| 1387 | /**
|
---|
| 1388 | * If autofs was stopped earlier, restart it.
|
---|
| 1389 | */
|
---|
| 1390 | void restart_autofs_if_necessary()
|
---|
| 1391 | {
|
---|
[128] | 1392 | char tmp[MAX_STR_LEN];
|
---|
| 1393 |
|
---|
| 1394 | if (!g_autofs_stopped || !g_autofs_exe[0]) {
|
---|
| 1395 | log_msg(3, "No autofs detected.");
|
---|
| 1396 | return;
|
---|
| 1397 | }
|
---|
| 1398 | sprintf(tmp, "%s start", g_autofs_exe);
|
---|
| 1399 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 1400 | log_it("Failed to start autofs");
|
---|
| 1401 | } else {
|
---|
| 1402 | g_autofs_stopped = FALSE;
|
---|
| 1403 | log_it("Started autofs OK");
|
---|
| 1404 | }
|
---|
[1] | 1405 | }
|
---|
| 1406 |
|
---|
| 1407 |
|
---|
| 1408 | /**
|
---|
| 1409 | * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
|
---|
| 1410 | */
|
---|
| 1411 | void mount_boot_if_necessary()
|
---|
| 1412 | {
|
---|
[128] | 1413 | char tmp[MAX_STR_LEN];
|
---|
| 1414 | char command[MAX_STR_LEN];
|
---|
[1] | 1415 |
|
---|
[128] | 1416 | log_msg(1, "Started sub");
|
---|
| 1417 | log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
|
---|
| 1418 | g_boot_mountpt[0] = '\0';
|
---|
| 1419 | log_msg(4, "Done. Great. Seeting command to something");
|
---|
| 1420 | strcpy(command,
|
---|
[911] | 1421 | "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
|
---|
[128] | 1422 | log_msg(4, "Cool. Command = '%s'", command);
|
---|
| 1423 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 1424 | log_msg(4, "tmp = '%s'", tmp);
|
---|
| 1425 | if (tmp[0]) {
|
---|
| 1426 | log_it("/boot is at %s according to /etc/fstab", tmp);
|
---|
[1791] | 1427 | strcpy(command, "mount | grep -Ew '/boot'");
|
---|
| 1428 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
[1818] | 1429 | if (!strcmp(tmp,"")) {
|
---|
[1791] | 1430 | if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) {
|
---|
| 1431 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1432 | strcpy(g_boot_mountpt, "/boot");
|
---|
| 1433 | log_msg(1, "Mounted /boot");
|
---|
| 1434 | } else {
|
---|
| 1435 | log_it("...ignored cos it's a label or uuid :-)");
|
---|
| 1436 | }
|
---|
[128] | 1437 | } else {
|
---|
[1791] | 1438 | sprintf(command, "mount | grep -E '^%s'", tmp);
|
---|
| 1439 | log_msg(3, "command = %s", command);
|
---|
| 1440 | if (run_program_and_log_output(command, 5)) {
|
---|
| 1441 | strcpy(g_boot_mountpt, tmp);
|
---|
| 1442 | sprintf(tmp,
|
---|
| 1443 | "%s (your /boot partition) is not mounted. I'll mount it before backing up",
|
---|
| 1444 | g_boot_mountpt);
|
---|
| 1445 | log_it(tmp);
|
---|
| 1446 | sprintf(tmp, "mount %s", g_boot_mountpt);
|
---|
| 1447 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1448 | g_boot_mountpt[0] = '\0';
|
---|
| 1449 | log_msg(1, "Plan B");
|
---|
| 1450 | if (!run_program_and_log_output("mount /boot", 5)) {
|
---|
| 1451 | strcpy(g_boot_mountpt, "/boot");
|
---|
| 1452 | log_msg(1, "Plan B worked");
|
---|
| 1453 | } else {
|
---|
| 1454 | log_msg(1,
|
---|
[128] | 1455 | "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
|
---|
[1791] | 1456 | }
|
---|
[128] | 1457 | }
|
---|
| 1458 | }
|
---|
| 1459 | }
|
---|
| 1460 | }
|
---|
[1] | 1461 | }
|
---|
[128] | 1462 | log_msg(1, "Ended sub");
|
---|
[1] | 1463 | }
|
---|
| 1464 |
|
---|
| 1465 |
|
---|
| 1466 | /**
|
---|
| 1467 | * If we mounted /boot earlier, unmount it.
|
---|
| 1468 | */
|
---|
| 1469 | void unmount_boot_if_necessary()
|
---|
| 1470 | {
|
---|
[128] | 1471 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1472 |
|
---|
[128] | 1473 | log_msg(3, "starting");
|
---|
| 1474 | if (g_boot_mountpt[0]) {
|
---|
| 1475 | sprintf(tmp, "umount %s", g_boot_mountpt);
|
---|
| 1476 | if (run_program_and_log_output(tmp, 5)) {
|
---|
| 1477 | log_it("WARNING - unable to unmount /boot");
|
---|
| 1478 | }
|
---|
| 1479 | }
|
---|
| 1480 | log_msg(3, "leaving");
|
---|
[1] | 1481 | }
|
---|
| 1482 |
|
---|
| 1483 |
|
---|
| 1484 |
|
---|
| 1485 | /**
|
---|
| 1486 | * Write a line to a configuration file. Writes a line of the form,
|
---|
| 1487 | * @c label @c value.
|
---|
| 1488 | * @param config_file The file to write to. Usually @c mondo-restore.cfg.
|
---|
| 1489 | * @param label What to call this bit of data you're writing.
|
---|
| 1490 | * @param value The bit of data you're writing.
|
---|
| 1491 | * @return 0 for success, 1 for failure.
|
---|
| 1492 | */
|
---|
[128] | 1493 | int write_cfg_var(char *config_file, char *label, char *value)
|
---|
[1] | 1494 | {
|
---|
[128] | 1495 | /*@ buffers ***************************************************** */
|
---|
| 1496 | char command[MAX_STR_LEN * 2];
|
---|
| 1497 | char tempfile[MAX_STR_LEN];
|
---|
| 1498 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1499 |
|
---|
| 1500 |
|
---|
[128] | 1501 | /*@ end vars *************************************************** */
|
---|
| 1502 | assert_string_is_neither_NULL_nor_zerolength(config_file);
|
---|
| 1503 | assert_string_is_neither_NULL_nor_zerolength(label);
|
---|
| 1504 | assert(value != NULL);
|
---|
| 1505 | if (!does_file_exist(config_file)) {
|
---|
| 1506 | sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
|
---|
| 1507 | config_file);
|
---|
| 1508 | log_to_screen(tmp);
|
---|
| 1509 | return (1);
|
---|
| 1510 | }
|
---|
[1644] | 1511 | sprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);
|
---|
[128] | 1512 | if (does_file_exist(config_file)) {
|
---|
[911] | 1513 | sprintf(command, "grep -vE '^%s .*$' %s > %s",
|
---|
[148] | 1514 | label, config_file, tempfile);
|
---|
[128] | 1515 | paranoid_system(command);
|
---|
| 1516 | }
|
---|
| 1517 | sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
|
---|
| 1518 | paranoid_system(command);
|
---|
| 1519 | sprintf(command, "mv -f %s %s", tempfile, config_file);
|
---|
| 1520 | paranoid_system(command);
|
---|
| 1521 | unlink(tempfile);
|
---|
| 1522 | return (0);
|
---|
[1] | 1523 | }
|
---|
| 1524 |
|
---|
[541] | 1525 |
|
---|
[1] | 1526 | /**
|
---|
[541] | 1527 | * The standard log_debug_msg() (log_msg() also due to a macro). Writes some describing
|
---|
| 1528 | * information to the logfile.
|
---|
| 1529 | */
|
---|
| 1530 | void standard_log_debug_msg(int debug_level, const char *szFile,
|
---|
| 1531 | const char *szFunction, int nLine,
|
---|
| 1532 | const char *fmt, ...)
|
---|
| 1533 | {
|
---|
| 1534 | va_list args;
|
---|
| 1535 | int i;
|
---|
| 1536 | static int depth = 0;
|
---|
| 1537 | char *tmp;
|
---|
| 1538 | FILE *fout;
|
---|
| 1539 |
|
---|
| 1540 | if (depth > 5) {
|
---|
| 1541 | depth--;
|
---|
| 1542 | return;
|
---|
| 1543 | }
|
---|
| 1544 | depth++;
|
---|
| 1545 |
|
---|
| 1546 | malloc_string(tmp);
|
---|
| 1547 |
|
---|
| 1548 | if (debug_level <= g_loglevel) {
|
---|
| 1549 | va_start(args, fmt);
|
---|
| 1550 | if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
|
---|
| 1551 | return;
|
---|
| 1552 | } // fatal_error("Failed to openout to logfile - sheesh..."); }
|
---|
| 1553 |
|
---|
| 1554 | // add tabs to distinguish log levels
|
---|
| 1555 | if (debug_level > 0) {
|
---|
| 1556 | for (i = 1; i < debug_level; i++)
|
---|
| 1557 | fprintf(fout, "\t");
|
---|
| 1558 | if (getpid() == g_main_pid)
|
---|
| 1559 | fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
|
---|
| 1560 | nLine);
|
---|
| 1561 | else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
|
---|
| 1562 | fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
|
---|
| 1563 | nLine);
|
---|
| 1564 | else
|
---|
| 1565 | fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
|
---|
| 1566 | szFunction, nLine);
|
---|
| 1567 | }
|
---|
| 1568 | vfprintf(fout, fmt, args);
|
---|
| 1569 |
|
---|
| 1570 | // do not slow down the progran if standard debug level
|
---|
| 1571 | // must be enabled: if no flush, the log won't be up-to-date if there
|
---|
| 1572 | // is a segfault
|
---|
| 1573 | //if (g_dwDebugLevel != 1)
|
---|
| 1574 |
|
---|
| 1575 | va_end(args);
|
---|
| 1576 | fprintf(fout, "\n");
|
---|
| 1577 | paranoid_fclose(fout);
|
---|
| 1578 | }
|
---|
| 1579 | depth--;
|
---|
| 1580 | paranoid_free(tmp);
|
---|
| 1581 | }
|
---|
| 1582 |
|
---|
| 1583 | /**
|
---|
| 1584 | * Function pointer to the @c log_debug_msg function to use. Points to standard_log_debug_msg() by default.
|
---|
| 1585 | */
|
---|
| 1586 | void (*log_debug_msg) (int, const char *, const char *, int, const char *,
|
---|
| 1587 | ...) = standard_log_debug_msg;
|
---|
| 1588 |
|
---|
| 1589 |
|
---|
| 1590 | /**
|
---|
[1] | 1591 | * If @p y, malloc @p x, else free @p x.
|
---|
| 1592 | * @bug This function seems orphaned. Please remove.
|
---|
| 1593 | */
|
---|
| 1594 | #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }
|
---|
| 1595 |
|
---|
| 1596 | /**
|
---|
| 1597 | * Allocate or free important globals, depending on @p mal.
|
---|
| 1598 | * @param mal If TRUE, malloc; if FALSE, free.
|
---|
| 1599 | */
|
---|
| 1600 | void do_libmondo_global_strings_thing(int mal)
|
---|
| 1601 | {
|
---|
[128] | 1602 | if (mal) {
|
---|
| 1603 | malloc_string(g_boot_mountpt);
|
---|
| 1604 | malloc_string(g_mondo_home);
|
---|
| 1605 | malloc_string(g_tmpfs_mountpt);
|
---|
| 1606 | malloc_string(g_serial_string);
|
---|
| 1607 | malloc_string(g_magicdev_command);
|
---|
| 1608 | } else {
|
---|
| 1609 | paranoid_free(g_boot_mountpt);
|
---|
| 1610 | paranoid_free(g_mondo_home);
|
---|
| 1611 | paranoid_free(g_tmpfs_mountpt);
|
---|
| 1612 | paranoid_free(g_serial_string);
|
---|
| 1613 | paranoid_free(g_magicdev_command);
|
---|
| 1614 | }
|
---|
[541] | 1615 |
|
---|
| 1616 | /*
|
---|
| 1617 | char**list_of_arrays[] = {
|
---|
| 1618 | &g_boot_mountpt,
|
---|
| 1619 | &g_mondo_home,
|
---|
| 1620 | &g_tmpfs_mountpt,
|
---|
| 1621 | &g_serial_string,
|
---|
| 1622 | &g_magicdev_command,
|
---|
| 1623 | NULL};
|
---|
| 1624 |
|
---|
| 1625 | char**ppcurr;
|
---|
| 1626 | int i;
|
---|
| 1627 |
|
---|
| 1628 | for(i=0;list_of_arrays[i];i++)
|
---|
| 1629 | {
|
---|
| 1630 | log_msg(5, "Allocating %d", i);
|
---|
| 1631 | ppcurr = list_of_arrays[i];
|
---|
| 1632 | if (mal)
|
---|
| 1633 | { *ppcurr = malloc(MAX_STR_LEN); }
|
---|
| 1634 | else
|
---|
| 1635 | {
|
---|
| 1636 | if (*ppcurr)
|
---|
| 1637 | {
|
---|
| 1638 | free(*ppcurr);
|
---|
| 1639 | }
|
---|
| 1640 | }
|
---|
| 1641 | }
|
---|
| 1642 | log_msg(5, "Returning");
|
---|
| 1643 | */
|
---|
[1] | 1644 | }
|
---|
| 1645 |
|
---|
| 1646 | /**
|
---|
| 1647 | * Allocate important globals.
|
---|
| 1648 | * @see do_libmondo_global_strings_thing
|
---|
| 1649 | */
|
---|
| 1650 | void malloc_libmondo_global_strings(void)
|
---|
| 1651 | {
|
---|
[128] | 1652 | do_libmondo_global_strings_thing(1);
|
---|
[1] | 1653 | }
|
---|
| 1654 |
|
---|
| 1655 | /**
|
---|
| 1656 | * Free important globals.
|
---|
| 1657 | * @see do_libmondo_global_strings_thing
|
---|
| 1658 | */
|
---|
| 1659 | void free_libmondo_global_strings(void)
|
---|
| 1660 | {
|
---|
[128] | 1661 | do_libmondo_global_strings_thing(0);
|
---|
[1] | 1662 | }
|
---|
| 1663 |
|
---|
| 1664 |
|
---|
| 1665 |
|
---|
| 1666 | /**
|
---|
| 1667 | * Stop @c magicdev if it's running.
|
---|
| 1668 | * The command used to start it is saved in @p g_magicdev_command.
|
---|
| 1669 | */
|
---|
| 1670 | void stop_magicdev_if_necessary()
|
---|
| 1671 | {
|
---|
[128] | 1672 | strcpy(g_magicdev_command,
|
---|
| 1673 | call_program_and_get_last_line_of_output
|
---|
| 1674 | ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
|
---|
| 1675 | if (g_magicdev_command[0]) {
|
---|
| 1676 | log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
|
---|
| 1677 | paranoid_system("killall magicdev");
|
---|
| 1678 | }
|
---|
[1] | 1679 | }
|
---|
| 1680 |
|
---|
| 1681 |
|
---|
| 1682 | /**
|
---|
| 1683 | * Restart magicdev if it was stopped.
|
---|
| 1684 | */
|
---|
| 1685 | void restart_magicdev_if_necessary()
|
---|
| 1686 | {
|
---|
[128] | 1687 | char *tmp;
|
---|
| 1688 |
|
---|
| 1689 | malloc_string(tmp);
|
---|
| 1690 | if (g_magicdev_command && g_magicdev_command[0]) {
|
---|
| 1691 | sprintf(tmp, "%s &", g_magicdev_command);
|
---|
| 1692 | paranoid_system(tmp);
|
---|
| 1693 | }
|
---|
| 1694 | paranoid_free(tmp);
|
---|
[1] | 1695 | }
|
---|
| 1696 |
|
---|
| 1697 | /* @} - end of utilityGroup */
|
---|