[1] | 1 | /***************************************************************************
|
---|
| 2 | mondo-cli.c
|
---|
| 3 | -------------------
|
---|
| 4 | begin : Fri Apr 19 16:40:35 EDT 2002
|
---|
| 5 | copyright : (C) 2002 Mondo Hugo Rabson
|
---|
| 6 | email : Hugo Rabson <hugorabson@msn.com>
|
---|
| 7 | edited by : by Stan Benoit 4/2002
|
---|
| 8 | email : troff@nakedsoul.org
|
---|
[116] | 9 | cvsid : $Id: mondo-cli.c 213 2005-12-15 00:41:46Z bcornec $
|
---|
[1] | 10 | ***************************************************************************/
|
---|
| 11 |
|
---|
| 12 | /***************************************************************************
|
---|
| 13 | * *
|
---|
| 14 | * This program is free software; you can redistribute it and/or modify *
|
---|
| 15 | * it under the terms of the GNU General Public License as published by *
|
---|
| 16 | * the Free Software Foundation; either version 2 of the License, or *
|
---|
| 17 | * (at your option) any later version. *
|
---|
| 18 | * *
|
---|
| 19 | ***************************************************************************/
|
---|
| 20 |
|
---|
| 21 | /***************************************************************************
|
---|
| 22 | UPDATE LOG
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | 08/04
|
---|
| 26 | - if user specifies a dumb -T value, abort
|
---|
| 27 |
|
---|
| 28 | 07/22
|
---|
| 29 | - handle -Q sensibly (don't abort if only -Q supplied)
|
---|
| 30 |
|
---|
| 31 | 07/17
|
---|
| 32 | - better checking of NFS dir's validity
|
---|
| 33 |
|
---|
| 34 | 06/19
|
---|
| 35 | - added AUX_VER
|
---|
| 36 |
|
---|
| 37 | 04/17
|
---|
| 38 | - added '-b' support
|
---|
| 39 | 04/03
|
---|
| 40 | - added star support
|
---|
| 41 |
|
---|
| 42 | 02/06
|
---|
| 43 | - fixed "Please give /dev entry" error msg
|
---|
| 44 |
|
---|
| 45 | 01/20/2004
|
---|
| 46 | - added 2.6.x-kernel "device = /dev/...." support to param reader
|
---|
| 47 | - better handling of SCSI and /dev entries
|
---|
| 48 | - touch /boot/boot.b if necessary
|
---|
| 49 |
|
---|
| 50 | 09/26/2003
|
---|
| 51 | - typo in command-line handling of 'r'
|
---|
| 52 |
|
---|
| 53 | 09/25
|
---|
| 54 | - added DVD write support
|
---|
| 55 |
|
---|
| 56 | 09/24
|
---|
| 57 | - if tape backup (-t) but user doesn't specify tape drive then
|
---|
| 58 | make an educated guess using find_tape_device_and_size()
|
---|
| 59 |
|
---|
| 60 | 09/18
|
---|
| 61 | - insist on partimagehack being present if -x found
|
---|
| 62 |
|
---|
| 63 | 09/16
|
---|
| 64 | - added support for multiple -I's and -E's in call to mondoarchive
|
---|
| 65 | - the '-D' flag doesn't take a value now
|
---|
| 66 |
|
---|
| 67 | 07/14
|
---|
| 68 | - fatal error if -E too short
|
---|
| 69 |
|
---|
| 70 | 05/14
|
---|
| 71 | - if 'n' and user doesn't have rights to write to output dir
|
---|
| 72 | then error out
|
---|
| 73 |
|
---|
| 74 | 05/05
|
---|
| 75 | - added Joshua Oreman's FreeBSD patches
|
---|
| 76 |
|
---|
| 77 | 05/04
|
---|
| 78 | - added Herman Kuster's multi-level bkp patch
|
---|
| 79 |
|
---|
| 80 | 05/02
|
---|
| 81 | - write errors to screen, not just to log
|
---|
| 82 |
|
---|
| 83 | 04/25
|
---|
| 84 | - added lots of assert()'s and log_OS_error()'s
|
---|
| 85 |
|
---|
| 86 | 04/21
|
---|
| 87 | - line 570 --- resolve boot device if softlink
|
---|
| 88 |
|
---|
| 89 | 04/08
|
---|
| 90 | - changed a bunch of fprintf(stderr,...)'s to log_it()'s
|
---|
| 91 | - fixed final / removal in retrieve_switches_from_command_line()
|
---|
| 92 |
|
---|
| 93 | 04/04
|
---|
| 94 | - added -e
|
---|
| 95 |
|
---|
| 96 | 03/15
|
---|
| 97 | - reject relative paths if -d flag (Alessandro Polverini)
|
---|
| 98 |
|
---|
| 99 | 01/02/2003
|
---|
| 100 | - added -J flag (to let user specify incoming filelist)
|
---|
| 101 |
|
---|
| 102 | 12/13/2002
|
---|
| 103 | - various strcpy() calls replaced with strncpy() calls
|
---|
| 104 |
|
---|
| 105 | 12/10
|
---|
| 106 | - added g_loglevel
|
---|
| 107 |
|
---|
| 108 | 11/25
|
---|
| 109 | - line 614 --- if commmand-line param ends in '/' then drop that '/'
|
---|
| 110 |
|
---|
| 111 | 11/19
|
---|
| 112 | - rewrote finish() to kill processes more softly
|
---|
| 113 | - if user calls with '-l RAW' then
|
---|
| 114 |
|
---|
| 115 | 09/01 - 09/30
|
---|
| 116 | - added -N to let user exclude all NFS-related mounts and devices
|
---|
| 117 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 118 | whether it will log its activities in the event of _success_
|
---|
| 119 |
|
---|
| 120 | 08/01 - 08/31
|
---|
| 121 | - if no device specified when backing up to tape streamer then assume /dev/st0
|
---|
| 122 | - abort if tape user specifies tape size (just for testing porpoises)
|
---|
| 123 | - tape users no longer need to specify tape size
|
---|
| 124 | - added some comments
|
---|
| 125 | - added bkpinfo->backup_media_type
|
---|
| 126 | - renamed from mondo-archive.c to mondo-cli.c
|
---|
| 127 |
|
---|
| 128 | 07/01 - 07/31
|
---|
| 129 | - better check for mkfs.vfat
|
---|
| 130 | - more sanity-checking for -d flag
|
---|
| 131 | - if isodir does not exist then abort
|
---|
| 132 | - removed "the rest are..." comment from log
|
---|
| 133 | - do not permit '-H' and '-t' in the same command line
|
---|
| 134 | - if not '-o' then insist on vfat-friendly kernel
|
---|
| 135 |
|
---|
| 136 | 06/01 - 06/30
|
---|
| 137 | - added signal-trapping
|
---|
| 138 | - added '-W' (won't make bootable CD or floppies) flag
|
---|
| 139 | - added missing 'j++' to -s switch's code
|
---|
| 140 | - expanded -s switch
|
---|
| 141 | - added -u switch
|
---|
| 142 | - if dvdrecord exists and cdrecord doesn't then use
|
---|
| 143 | dvdrecord instead of cdrecord
|
---|
| 144 |
|
---|
| 145 | 04/01 - 04/30
|
---|
| 146 | - if CD-ROM is supermounted then unmount, run, and remount
|
---|
| 147 | - replace MONDO_VERSION #define with VERSION from ../config.h
|
---|
| 148 | - if CD-ROM is mounted at start then abort
|
---|
| 149 | - improved homedir-locating code
|
---|
| 150 | - improved "backup will occupy N CD's" calculation a bit
|
---|
| 151 | - added -m (manual CD tray) flag
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | *******************************************************************/
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * @file
|
---|
| 158 | * Functions for handling command-line arguments passed to mondoarchive.
|
---|
| 159 | */
|
---|
| 160 |
|
---|
| 161 | /** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
|
---|
| 162 |
|
---|
| 163 | #include <pthread.h>
|
---|
| 164 | #include "../common/my-stuff.h"
|
---|
| 165 | #include "../common/mondostructures.h"
|
---|
| 166 | #include "mondo-cli-EXT.h"
|
---|
| 167 | #include "../common/libmondo.h"
|
---|
| 168 |
|
---|
[116] | 169 | //static char cvsid[] = "$Id: mondo-cli.c 213 2005-12-15 00:41:46Z bcornec $";
|
---|
[1] | 170 |
|
---|
| 171 | extern int g_loglevel;
|
---|
| 172 | extern bool g_text_mode;
|
---|
[116] | 173 | extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks
|
---|
| 174 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
[1] | 175 | extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];
|
---|
| 176 | extern char g_tmpfs_mountpt[MAX_STR_LEN];
|
---|
| 177 | extern bool g_sigpipe;
|
---|
| 178 |
|
---|
| 179 | /*@ file pointer **************************************************/
|
---|
| 180 | extern FILE *g_tape_stream;
|
---|
| 181 |
|
---|
| 182 | /*@ long long *****************************************************/
|
---|
| 183 | extern long long g_tape_posK;
|
---|
| 184 |
|
---|
| 185 | /*@ long **********************************************************/
|
---|
| 186 | extern long g_noof_sets;
|
---|
| 187 |
|
---|
| 188 | /*@ bool******** **************************************************/
|
---|
[116] | 189 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
| 190 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
[1] | 191 | extern bool g_cd_recovery;
|
---|
| 192 |
|
---|
| 193 | /**
|
---|
| 194 | * Whether we're restoring from ISOs. Obviously not, since this is the
|
---|
| 195 | * backup program.
|
---|
| 196 | * @note You @b MUST declare this variable somewhere in your program if
|
---|
| 197 | * you use libmondo. Otherwise the link will fail.
|
---|
| 198 | * @ingroup globalGroup
|
---|
| 199 | */
|
---|
| 200 | bool g_ISO_restore_mode = FALSE;
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | extern double g_kernel_version;
|
---|
| 204 |
|
---|
| 205 | extern int g_current_media_number;
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 | extern pid_t g_main_pid;
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 |
|
---|
[116] | 214 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
[1] | 215 |
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | /**
|
---|
| 219 | * @addtogroup cliGroup
|
---|
| 220 | * @{
|
---|
| 221 | */
|
---|
| 222 | /**
|
---|
| 223 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
| 224 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
| 225 | * @param argv The argument vector; @p argv passed to main().
|
---|
| 226 | * @param bkpinfo The backup information structure to populate.
|
---|
| 227 | * @return The number of problems with the command line (0 for success).
|
---|
| 228 | */
|
---|
| 229 | int
|
---|
[116] | 230 | handle_incoming_parameters(int argc, char *argv[],
|
---|
| 231 | struct s_bkpinfo *bkpinfo)
|
---|
[1] | 232 | {
|
---|
[116] | 233 | /*@ int *** */
|
---|
| 234 | int res = 0;
|
---|
| 235 | int retval = 0;
|
---|
| 236 | int i = 0, j;
|
---|
[1] | 237 |
|
---|
[116] | 238 | /*@ buffers *************** */
|
---|
| 239 | char *tmp;
|
---|
| 240 | char flag_val[128][MAX_STR_LEN];
|
---|
| 241 | bool flag_set[128];
|
---|
[1] | 242 |
|
---|
[116] | 243 | malloc_string(tmp);
|
---|
| 244 | sensibly_set_tmpdir_and_scratchdir(bkpinfo);
|
---|
| 245 | for (i = 0; i < 128; i++) {
|
---|
| 246 | flag_val[i][0] = '\0';
|
---|
| 247 | flag_set[i] = FALSE;
|
---|
| 248 | }
|
---|
| 249 | // strcpy (bkpinfo->tmpdir, "/root/images/mondo");
|
---|
| 250 | // strcpy (bkpinfo->scratchdir, "/home");
|
---|
| 251 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 252 | bkpinfo->media_size[j] = 650;
|
---|
| 253 | } /* default */
|
---|
| 254 | res =
|
---|
| 255 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
| 256 | flag_set);
|
---|
| 257 | retval += res;
|
---|
| 258 | if (!retval) {
|
---|
| 259 | res = process_switches(bkpinfo, flag_val, flag_set);
|
---|
| 260 | retval += res;
|
---|
| 261 | }
|
---|
[1] | 262 | /*
|
---|
| 263 | if (!retval)
|
---|
| 264 | {
|
---|
| 265 | */
|
---|
[116] | 266 | log_msg(3, "Switches:-");
|
---|
| 267 | for (i = 0; i < 128; i++) {
|
---|
| 268 | if (flag_set[i]) {
|
---|
| 269 | sprintf(tmp, "-%c %s", i, flag_val[i]);
|
---|
| 270 | log_msg(3, tmp);
|
---|
| 271 | }
|
---|
[1] | 272 | }
|
---|
| 273 | // }
|
---|
[116] | 274 | sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
|
---|
| 275 | paranoid_system(tmp);
|
---|
| 276 | sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
|
---|
| 277 | paranoid_system(tmp);
|
---|
| 278 | sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld",
|
---|
| 279 | random() % 32767);
|
---|
| 280 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
|
---|
| 281 | "/mondo.scratch.%ld", random() % 32767);
|
---|
| 282 | sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
| 283 | paranoid_system(tmp);
|
---|
| 284 | sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
| 285 | paranoid_system(tmp);
|
---|
| 286 | if (bkpinfo->nfs_mount[0] != '\0') {
|
---|
| 287 | store_nfs_config(bkpinfo);
|
---|
| 288 | }
|
---|
| 289 | paranoid_free(tmp);
|
---|
| 290 | return (retval);
|
---|
[1] | 291 | }
|
---|
| 292 |
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | /**
|
---|
| 297 | * Store the sizespec(s) stored in @p value into @p bkpinfo.
|
---|
| 298 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
|
---|
| 299 | * @param value The sizespec (e.g. "2g", "40m").
|
---|
| 300 | * @return 0, always.
|
---|
| 301 | * @bug Return code not needed.
|
---|
| 302 | */
|
---|
| 303 | int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value)
|
---|
| 304 | {
|
---|
[116] | 305 | int j;
|
---|
| 306 | char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
|
---|
[1] | 307 |
|
---|
[116] | 308 | assert(bkpinfo != NULL);
|
---|
| 309 | assert(value != NULL);
|
---|
[1] | 310 |
|
---|
[116] | 311 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
| 312 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
| 313 | j++, p = strchr(p, ',') + 1) {
|
---|
| 314 | strncpy(tmp, p, MAX_STR_LEN);
|
---|
| 315 | *(strchr(tmp, ',')) = '\0';
|
---|
| 316 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
| 317 | sprintf(comment, "media_size[%d] = %ld", j,
|
---|
| 318 | bkpinfo->media_size[j]);
|
---|
| 319 | log_msg(3, comment);
|
---|
[1] | 320 | }
|
---|
[116] | 321 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 322 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
[1] | 323 | }
|
---|
| 324 | // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
|
---|
[116] | 325 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 326 | if (bkpinfo->media_size[j] <= 0) {
|
---|
| 327 | log_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
| 328 | return (-1);
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | return (0);
|
---|
[1] | 332 | }
|
---|
| 333 |
|
---|
| 334 |
|
---|
| 335 |
|
---|
| 336 | /**
|
---|
| 337 | * Process mondoarchive's command-line switches.
|
---|
| 338 | * @param bkpinfo The backup information structure to populate.
|
---|
| 339 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
| 340 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
| 341 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
| 342 | * FALSE if it's not.
|
---|
| 343 | * @return The number of problems with the switches, or 0 for success.
|
---|
| 344 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
| 345 | */
|
---|
| 346 | int
|
---|
[116] | 347 | process_switches(struct s_bkpinfo *bkpinfo,
|
---|
| 348 | char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
[1] | 349 | {
|
---|
| 350 |
|
---|
[116] | 351 | /*@ ints *** */
|
---|
| 352 | int i = 0;
|
---|
| 353 | int retval = 0;
|
---|
| 354 | int percent = 0;
|
---|
[1] | 355 |
|
---|
[116] | 356 | /*@ buffers ** */
|
---|
| 357 | char *tmp;
|
---|
| 358 | char *psz;
|
---|
[1] | 359 |
|
---|
[116] | 360 | long itbs;
|
---|
[1] | 361 |
|
---|
[116] | 362 | malloc_string(tmp);
|
---|
| 363 | malloc_string(psz);
|
---|
[1] | 364 |
|
---|
[116] | 365 | assert(bkpinfo != NULL);
|
---|
| 366 | assert(flag_val != NULL);
|
---|
| 367 | assert(flag_set != NULL);
|
---|
[1] | 368 |
|
---|
[116] | 369 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1] | 370 |
|
---|
| 371 | /* compulsory */
|
---|
[116] | 372 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
| 373 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
| 374 | flag_set['w'] + flag_set['C'];
|
---|
| 375 | if (i == 0) {
|
---|
| 376 | retval++;
|
---|
| 377 | log_to_screen("You must specify the media type\n");
|
---|
[1] | 378 | }
|
---|
[116] | 379 | if (i > 1) {
|
---|
| 380 | retval++;
|
---|
| 381 | log_to_screen("Please specify only one media type\n");
|
---|
[1] | 382 | }
|
---|
[116] | 383 | if (flag_set['K']) {
|
---|
| 384 | g_loglevel = atoi(flag_val['K']);
|
---|
| 385 | if (g_loglevel < 3) {
|
---|
| 386 | g_loglevel = 3;
|
---|
| 387 | }
|
---|
[1] | 388 | }
|
---|
[116] | 389 | if (flag_set['L'] && flag_set['0']) {
|
---|
| 390 | retval++;
|
---|
| 391 | log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
|
---|
[1] | 392 | }
|
---|
[116] | 393 | bkpinfo->backup_data = flag_set['O'];
|
---|
| 394 | bkpinfo->verify_data = flag_set['V'];
|
---|
| 395 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
| 396 | log_to_screen("-I switch is ignored if just verifying");
|
---|
| 397 | }
|
---|
| 398 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
| 399 | log_to_screen("-E switch is ignored if just verifying");
|
---|
| 400 | }
|
---|
[1] | 401 |
|
---|
[116] | 402 | if (!find_home_of_exe("afio")) {
|
---|
| 403 | if (find_home_of_exe("star")) {
|
---|
| 404 | flag_set['R'] = TRUE;
|
---|
| 405 | log_msg(1, "Using star instead of afio");
|
---|
| 406 | } else {
|
---|
| 407 | fatal_error
|
---|
| 408 | ("Neither afio nor star is installed. Please install at least one.");
|
---|
| 409 | }
|
---|
[1] | 410 | }
|
---|
| 411 |
|
---|
[116] | 412 | if (flag_set['R']) {
|
---|
| 413 | bkpinfo->use_star = TRUE;
|
---|
| 414 | if (flag_set['L']) {
|
---|
| 415 | fatal_error("You may not use star and lzop at the same time.");
|
---|
| 416 | }
|
---|
| 417 | if (!find_home_of_exe("star")) {
|
---|
| 418 | fatal_error
|
---|
| 419 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
| 420 | }
|
---|
[1] | 421 | }
|
---|
[116] | 422 | if (flag_set['W']) {
|
---|
| 423 | bkpinfo->nonbootable_backup = TRUE;
|
---|
| 424 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
| 425 | if (flag_set['f'] || flag_set['l']) {
|
---|
| 426 | log_to_screen
|
---|
| 427 | ("You don't need to specify bootloader or bootdevice");
|
---|
| 428 | }
|
---|
[1] | 429 | }
|
---|
[116] | 430 | if (flag_set['t'] && flag_set['H']) {
|
---|
| 431 | fatal_error
|
---|
| 432 | ("Sorry, you may not nuke w/o warning from tape. Drop -H, please.");
|
---|
| 433 | }
|
---|
| 434 | if (flag_set['I']) {
|
---|
| 435 | if (!strcmp(bkpinfo->include_paths, "/")) {
|
---|
| 436 | log_msg(2, "'/' is pleonastic.");
|
---|
| 437 | bkpinfo->include_paths[0] = '\0';
|
---|
| 438 | }
|
---|
| 439 | if (bkpinfo->include_paths[0]) {
|
---|
| 440 | strcat(bkpinfo->include_paths, " ");
|
---|
| 441 | }
|
---|
| 442 | strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
|
---|
| 443 | flag_val['I'],
|
---|
| 444 | MAX_STR_LEN - strlen(bkpinfo->include_paths));
|
---|
| 445 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
| 446 | if (bkpinfo->include_paths[0] == '-') {
|
---|
| 447 | retval++;
|
---|
| 448 | log_to_screen("Please supply a sensible value with '-I'\n");
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
[1] | 451 |
|
---|
[116] | 452 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
| 453 | && (flag_set['c'] || flag_set['w'])) {
|
---|
| 454 | fatal_error
|
---|
| 455 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
[1] | 456 | }
|
---|
| 457 |
|
---|
[116] | 458 |
|
---|
| 459 | if (flag_set['J']) {
|
---|
| 460 | if (flag_set['I']) {
|
---|
| 461 | retval++;
|
---|
| 462 | log_to_screen
|
---|
| 463 | ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)");
|
---|
| 464 | }
|
---|
| 465 | bkpinfo->make_filelist = FALSE;
|
---|
| 466 | strcpy(bkpinfo->include_paths, flag_val['J']);
|
---|
[1] | 467 | }
|
---|
[116] | 468 | if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) {
|
---|
| 469 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 470 | && strstr(flag_val['d'], "/dev/")) {
|
---|
| 471 | fatal_error
|
---|
| 472 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
| 473 | }
|
---|
| 474 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 475 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 476 | fatal_error
|
---|
| 477 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
| 478 | }
|
---|
| 479 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 480 | log_to_screen
|
---|
| 481 | ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
| 485 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 486 | fatal_error
|
---|
| 487 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
| 488 | }
|
---|
| 489 | if (flag_set['C']) {
|
---|
| 490 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
| 491 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 492 | fatal_error
|
---|
| 493 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 494 | }
|
---|
| 495 | if (!flag_set['L']) {
|
---|
| 496 | log_to_screen
|
---|
| 497 | ("You must use -L with -C. Therefore I am setting it for you.");
|
---|
| 498 | flag_set['L'] = 1;
|
---|
| 499 | flag_val['L'][0] = '\0';
|
---|
| 500 | }
|
---|
| 501 | } else {
|
---|
| 502 | log_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
| 503 | log_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
| 504 | // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
|
---|
| 505 | if (flag_set['c']) {
|
---|
| 506 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
| 507 | } else if (flag_set['w']) {
|
---|
| 508 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
| 509 | } else if (flag_set['r']) {
|
---|
| 510 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
| 511 | }
|
---|
| 512 |
|
---|
| 513 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 514 | fatal_error
|
---|
| 515 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
[1] | 518 | }
|
---|
[116] | 519 | if (flag_set['t'] && !flag_set['d']) {
|
---|
| 520 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
| 521 | if (find_tape_device_and_size(flag_val['d'], tmp)) {
|
---|
| 522 | fatal_error
|
---|
| 523 | ("Tape device not specified. I couldn't find it either.");
|
---|
| 524 | }
|
---|
| 525 | flag_set['d'] = TRUE;
|
---|
| 526 | sprintf(tmp,
|
---|
| 527 | "You didn't specify a tape streamer device. I'm assuming %s",
|
---|
| 528 | flag_val['d']);
|
---|
| 529 | log_to_screen(tmp);
|
---|
| 530 | percent = 0;
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | if (flag_set['r']) // DVD
|
---|
| 534 | {
|
---|
| 535 | if (flag_set['m']) {
|
---|
| 536 | fatal_error
|
---|
| 537 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
| 538 | }
|
---|
| 539 | if (!flag_set['d']) {
|
---|
| 540 | if (!find_dvd_device(flag_val['d'], FALSE)) {
|
---|
| 541 | flag_set['d'] = TRUE;
|
---|
| 542 | log_to_screen("I guess DVD drive is at %s", flag_val['d']);
|
---|
| 543 | }
|
---|
| 544 | }
|
---|
| 545 | if (!find_home_of_exe("growisofs")) {
|
---|
| 546 | fatal_error
|
---|
| 547 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 548 | }
|
---|
| 549 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 550 | fatal_error
|
---|
| 551 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 552 | }
|
---|
| 553 | if (strchr(flag_val['d'], ',')) {
|
---|
| 554 | fatal_error
|
---|
| 555 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 556 | }
|
---|
| 557 | if (!flag_set['s']) {
|
---|
| 558 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
| 559 | strcat(flag_val['s'], "m");
|
---|
| 560 | log_to_screen
|
---|
| 561 | ("You did not specify a size (-s) for DVD. I'm guessing %s.",
|
---|
| 562 | flag_val['s']);
|
---|
| 563 | flag_set['s'] = 1;
|
---|
| 564 | }
|
---|
[1] | 565 | /*
|
---|
| 566 | if (flag_set['Z']) {
|
---|
| 567 | bkpinfo->blank_dvd_first = TRUE;
|
---|
| 568 | }
|
---|
| 569 | */
|
---|
[116] | 570 | }
|
---|
[1] | 571 |
|
---|
[116] | 572 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
| 573 | if (strchr(flag_val['d'], ',')) {
|
---|
| 574 | fatal_error
|
---|
| 575 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 576 | }
|
---|
| 577 | if (flag_set['O']) {
|
---|
| 578 | if (flag_set['s']) {
|
---|
| 579 | if (flag_set['t']) {
|
---|
| 580 | fatal_error
|
---|
| 581 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
| 582 | }
|
---|
| 583 | if (process_the_s_switch(bkpinfo, flag_val['s'])) {
|
---|
| 584 | fatal_error("Bad -s switch");
|
---|
| 585 | }
|
---|
| 586 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
| 587 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 588 | bkpinfo->media_size[i] = 0;
|
---|
| 589 | }
|
---|
| 590 | } else {
|
---|
| 591 | retval++;
|
---|
| 592 | log_to_screen("Tape size not specified.\n");
|
---|
| 593 | }
|
---|
| 594 | }
|
---|
| 595 | } else { /* CD size */
|
---|
| 596 | if (flag_set['s']) {
|
---|
| 597 | if (process_the_s_switch(bkpinfo, flag_val['s'])) {
|
---|
| 598 | fatal_error("Bad -s switch");
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | if (flag_set['w']) {
|
---|
| 602 | bkpinfo->wipe_media_first = TRUE;
|
---|
| 603 | } /* CD-RW */
|
---|
[1] | 604 | }
|
---|
[116] | 605 | if (flag_set['n']) {
|
---|
| 606 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
|
---|
| 607 | if (!flag_set['d']) {
|
---|
| 608 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
|
---|
| 609 | }
|
---|
| 610 | sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
|
---|
| 611 | bkpinfo->nfs_mount);
|
---|
| 612 | strncpy(bkpinfo->isodir,
|
---|
| 613 | call_program_and_get_last_line_of_output(tmp),
|
---|
| 614 | MAX_STR_LEN / 4);
|
---|
| 615 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
| 616 | retval++;
|
---|
| 617 | log_to_screen("NFS share is not mounted. Please mount it.\n");
|
---|
| 618 | }
|
---|
| 619 | log_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
| 620 | log_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
[1] | 621 | }
|
---|
[116] | 622 | if (flag_set['c']) {
|
---|
| 623 | bkpinfo->backup_media_type = cdr;
|
---|
[1] | 624 | }
|
---|
[116] | 625 | if (flag_set['C']) {
|
---|
| 626 | bkpinfo->backup_media_type = cdstream;
|
---|
[1] | 627 | }
|
---|
[116] | 628 | if (flag_set['i']) {
|
---|
| 629 | bkpinfo->backup_media_type = iso;
|
---|
| 630 | }
|
---|
| 631 | if (flag_set['n']) {
|
---|
| 632 | bkpinfo->backup_media_type = nfs;
|
---|
| 633 | }
|
---|
| 634 | if (flag_set['r']) {
|
---|
| 635 | bkpinfo->backup_media_type = dvd;
|
---|
| 636 | }
|
---|
| 637 | if (flag_set['t']) {
|
---|
| 638 | bkpinfo->backup_media_type = tape;
|
---|
| 639 | }
|
---|
| 640 | if (flag_set['u']) {
|
---|
| 641 | bkpinfo->backup_media_type = udev;
|
---|
| 642 | }
|
---|
| 643 | if (flag_set['w']) {
|
---|
| 644 | bkpinfo->backup_media_type = cdrw;
|
---|
| 645 | }
|
---|
[1] | 646 |
|
---|
| 647 | /* optional, popular */
|
---|
[116] | 648 | if (flag_set['g']) {
|
---|
| 649 | g_text_mode = FALSE;
|
---|
| 650 | }
|
---|
| 651 | if (flag_set['E']) {
|
---|
| 652 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 653 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 654 | }
|
---|
| 655 | strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
|
---|
| 656 | flag_val['E'],
|
---|
| 657 | MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
|
---|
| 658 | }
|
---|
| 659 | if (flag_set['e']) {
|
---|
| 660 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 661 | }
|
---|
| 662 | if (flag_set['N']) // exclude NFS mounts & devices
|
---|
| 663 | {
|
---|
[1] | 664 | // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
|
---|
[116] | 665 | strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
|
---|
| 666 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 667 | strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN);
|
---|
| 668 | }
|
---|
| 669 | strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN);
|
---|
| 670 | log_msg(3, "-N means we're now excluding %s",
|
---|
| 671 | bkpinfo->exclude_paths);
|
---|
| 672 | }
|
---|
| 673 | if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) {
|
---|
| 674 | fatal_error
|
---|
| 675 | ("Your '-E' parameter is too long. Please use '-J'. (See manual.)");
|
---|
| 676 | }
|
---|
| 677 | if (flag_set['b']) {
|
---|
| 678 | strcpy(psz, flag_val['b']);
|
---|
| 679 | log_msg(1, "psz = '%s'", psz);
|
---|
| 680 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
| 681 | psz[strlen(psz) - 1] = '\0';
|
---|
| 682 | itbs = atol(psz) * 1024L;
|
---|
| 683 | } else {
|
---|
| 684 | itbs = atol(psz);
|
---|
| 685 | }
|
---|
| 686 | log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
| 687 | log_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
| 688 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
| 689 | fatal_error
|
---|
| 690 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
| 691 | }
|
---|
| 692 | bkpinfo->internal_tape_block_size = itbs;
|
---|
| 693 | }
|
---|
| 694 | if (flag_set['D']) {
|
---|
| 695 | bkpinfo->differential = 1;
|
---|
[1] | 696 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
[116] | 697 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
| 698 | fatal_error
|
---|
| 699 | ("The D option should be between 1 and 9 inclusive");
|
---|
| 700 | }
|
---|
[1] | 701 | }
|
---|
[116] | 702 | if (flag_set['x']) {
|
---|
| 703 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
| 704 | if (run_program_and_log_output("which partimagehack", 2)) {
|
---|
| 705 | fatal_error("Please install partimagehack RPM/tarball.");
|
---|
| 706 | }
|
---|
[1] | 707 | }
|
---|
[116] | 708 | if (flag_set['m']) {
|
---|
| 709 | bkpinfo->manual_cd_tray = TRUE;
|
---|
[1] | 710 | }
|
---|
[116] | 711 | if (flag_set['k']) {
|
---|
| 712 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
|
---|
| 713 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
| 714 | strcpy(bkpinfo->kernel_path, "FAILSAFE");
|
---|
| 715 | }
|
---|
| 716 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
| 717 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
| 718 | retval++;
|
---|
| 719 | sprintf(tmp,
|
---|
| 720 | "You specified kernel '%s', which does not exist\n",
|
---|
| 721 | bkpinfo->kernel_path);
|
---|
| 722 | log_to_screen(tmp);
|
---|
| 723 | }
|
---|
| 724 | }
|
---|
| 725 | if (flag_set['p']) {
|
---|
| 726 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
|
---|
| 727 | }
|
---|
[1] | 728 |
|
---|
| 729 |
|
---|
[116] | 730 | if (flag_set['d']) { /* backup directory (if ISO/NFS) */
|
---|
| 731 | if (flag_set['i']) {
|
---|
| 732 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 733 | sprintf(tmp, "ls -l %s", bkpinfo->isodir);
|
---|
| 734 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 735 | fatal_error
|
---|
| 736 | ("output folder does not exist - please create it");
|
---|
| 737 | }
|
---|
| 738 | } else if (flag_set['n']) {
|
---|
| 739 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
| 740 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
| 741 |
|
---|
| 742 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 743 | }
|
---|
[1] | 744 | }
|
---|
[116] | 745 |
|
---|
| 746 | if (flag_set['n']) {
|
---|
| 747 | sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
|
---|
| 748 | bkpinfo->nfs_remote_dir);
|
---|
| 749 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 750 | retval++;
|
---|
| 751 | sprintf(tmp,
|
---|
| 752 | "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
|
---|
| 753 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
| 754 | log_to_screen(tmp);
|
---|
| 755 | }
|
---|
[1] | 756 | }
|
---|
| 757 |
|
---|
[116] | 758 | if (!flag_set['d']
|
---|
| 759 | && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
|
---|
| 760 | if (g_kernel_version >= 2.6) {
|
---|
| 761 | if (popup_and_get_string
|
---|
| 762 | ("Device", "Please specify the device",
|
---|
| 763 | bkpinfo->media_device, MAX_STR_LEN / 4)) {
|
---|
| 764 | retval++;
|
---|
| 765 | log_to_screen("User opted to cancel.");
|
---|
| 766 | }
|
---|
| 767 | } else if (find_cdrw_device(bkpinfo->media_device)) {
|
---|
| 768 | retval++;
|
---|
| 769 | log_to_screen
|
---|
| 770 | ("Tried and failed to find CD-R[W] drive automatically.\n");
|
---|
| 771 | } else {
|
---|
| 772 | flag_set['d'] = TRUE;
|
---|
| 773 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
| 774 | }
|
---|
[1] | 775 | }
|
---|
| 776 |
|
---|
[116] | 777 | if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
|
---|
| 778 | retval++;
|
---|
| 779 | log_to_screen("Please specify the backup device/directory.\n");
|
---|
| 780 | fatal_error
|
---|
| 781 | ("You didn't use -d to specify the backup device/directory.");
|
---|
[1] | 782 | }
|
---|
[116] | 783 | /* optional, obscure */
|
---|
| 784 | for (i = '0'; i <= '9'; i++) {
|
---|
| 785 | if (flag_set[i]) {
|
---|
| 786 | bkpinfo->compression_level = i - '0';
|
---|
| 787 | } /* not '\0' but '0' */
|
---|
[1] | 788 | }
|
---|
[116] | 789 | if (flag_set['S']) {
|
---|
| 790 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
| 791 | random() % 32768);
|
---|
[1] | 792 | }
|
---|
[116] | 793 | if (flag_set['T']) {
|
---|
| 794 | sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
|
---|
| 795 | random() % 32768);
|
---|
| 796 | sprintf(tmp, "touch %s/.foo.dat", flag_val['T']);
|
---|
| 797 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 798 | retval++;
|
---|
| 799 | log_to_screen
|
---|
| 800 | ("Please specify a tempdir which I can write to. :)");
|
---|
| 801 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 802 | }
|
---|
| 803 | sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'],
|
---|
| 804 | flag_val['T']);
|
---|
| 805 | if (run_program_and_log_output(tmp, 1)) {
|
---|
| 806 | retval++;
|
---|
| 807 | log_to_screen
|
---|
| 808 | ("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
|
---|
| 809 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 810 | }
|
---|
[1] | 811 | }
|
---|
[116] | 812 | if (flag_set['A']) {
|
---|
| 813 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
| 814 | }
|
---|
| 815 | if (flag_set['B']) {
|
---|
| 816 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
| 817 | }
|
---|
| 818 | if (flag_set['F']) {
|
---|
| 819 | g_skip_floppies = TRUE;
|
---|
| 820 | }
|
---|
| 821 | if (flag_set['H']) {
|
---|
| 822 | g_cd_recovery = TRUE;
|
---|
| 823 | }
|
---|
| 824 | if (flag_set['l']) {
|
---|
[1] | 825 | #ifdef __FreeBSD__
|
---|
| 826 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
| 827 | #else
|
---|
| 828 | # ifdef __IA64__
|
---|
| 829 | # define BOOT_LOADER_CHARS "GER"
|
---|
| 830 | # else
|
---|
| 831 | # define BOOT_LOADER_CHARS "GLR"
|
---|
| 832 | # endif
|
---|
| 833 | #endif
|
---|
[116] | 834 | if (!strchr
|
---|
| 835 | (BOOT_LOADER_CHARS,
|
---|
| 836 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
| 837 | log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
|
---|
| 838 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
| 839 | fatal_error
|
---|
| 840 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
| 841 | }
|
---|
[1] | 842 | #undef BOOT_LOADER_CHARS
|
---|
| 843 | }
|
---|
[116] | 844 | if (flag_set['f']) {
|
---|
| 845 | strncpy(bkpinfo->boot_device,
|
---|
| 846 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
| 847 | ['f']),
|
---|
| 848 | MAX_STR_LEN / 4);
|
---|
| 849 | }
|
---|
| 850 | if (flag_set['P']) {
|
---|
| 851 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
| 852 | }
|
---|
| 853 | if (flag_set['Q']) {
|
---|
| 854 | i = which_boot_loader(tmp);
|
---|
| 855 | log_msg(3, "boot loader is %c, residing at %s", i, tmp);
|
---|
| 856 | printf("boot loader is %c, residing at %s\n", i, tmp);
|
---|
| 857 | finish(0);
|
---|
| 858 | }
|
---|
| 859 | if (flag_set['L']) {
|
---|
| 860 | bkpinfo->use_lzo = TRUE;
|
---|
| 861 | if (run_program_and_log_output("which lzop", FALSE)) {
|
---|
| 862 | retval++;
|
---|
| 863 | log_to_screen
|
---|
| 864 | ("Please install LZOP. You can't use '-L' until you do.\n");
|
---|
| 865 | }
|
---|
| 866 | }
|
---|
[1] | 867 |
|
---|
[116] | 868 | if (!flag_set['o']
|
---|
| 869 | &&
|
---|
| 870 | !run_program_and_log_output
|
---|
| 871 | ("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) {
|
---|
| 872 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 873 | log_to_screen
|
---|
| 874 | ("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary.");
|
---|
| 875 | }
|
---|
| 876 | if (flag_set['o']) {
|
---|
| 877 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 878 | }
|
---|
[1] | 879 | #ifndef __FreeBSD__
|
---|
[116] | 880 | else {
|
---|
| 881 | if (!is_this_a_valid_disk_format("vfat")) {
|
---|
| 882 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 883 | log_to_screen
|
---|
| 884 | ("Your kernel appears not to support vfat filesystems. I am therefore");
|
---|
| 885 | log_to_screen
|
---|
| 886 | ("using LILO instead of SYSLINUX as the CD/floppy's boot loader.");
|
---|
| 887 | }
|
---|
| 888 | if (run_program_and_log_output("which mkfs.vfat", FALSE)) {
|
---|
| 889 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 890 | #ifdef __IA32__
|
---|
[116] | 891 | log_to_screen
|
---|
| 892 | ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
|
---|
| 893 | log_to_screen
|
---|
| 894 | ("your boot loader. I shall therefore use LILO instead.");
|
---|
[1] | 895 | #endif
|
---|
| 896 | #ifdef __IA64__
|
---|
[116] | 897 | log_to_screen
|
---|
| 898 | ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
|
---|
| 899 | log_to_screen("environment correctly. Please install it.");
|
---|
| 900 | fatal_error("Aborting");
|
---|
[1] | 901 | #endif
|
---|
[116] | 902 | }
|
---|
[1] | 903 | #ifdef __IA64__
|
---|
[116] | 904 | /* We force ELILO usage on IA64 */
|
---|
| 905 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 906 | #endif
|
---|
[116] | 907 | }
|
---|
[1] | 908 | #endif
|
---|
| 909 |
|
---|
[116] | 910 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
|
---|
| 911 | paranoid_system("touch /boot/boot.b");
|
---|
| 912 | }
|
---|
[1] | 913 |
|
---|
[116] | 914 | i = flag_set['O'] + flag_set['V'];
|
---|
| 915 | if (i == 0) {
|
---|
| 916 | retval++;
|
---|
| 917 | log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
|
---|
| 918 | }
|
---|
[1] | 919 |
|
---|
| 920 | /* and finally... */
|
---|
| 921 |
|
---|
[116] | 922 | paranoid_free(tmp);
|
---|
| 923 | paranoid_free(psz);
|
---|
| 924 | return (retval);
|
---|
[1] | 925 | }
|
---|
| 926 |
|
---|
| 927 |
|
---|
| 928 |
|
---|
| 929 | /**
|
---|
| 930 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
| 931 | * @p flag_set and @p flag_val.
|
---|
| 932 | * @param argc The argument count (@p argc passed to main()).
|
---|
| 933 | * @param argv The argument vector (@p argv passed to main()).
|
---|
| 934 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
| 935 | * has an argument then set flag_val[switch] to that argument.
|
---|
| 936 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
| 937 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
| 938 | * @return The number of problems with the command line (0 for success).
|
---|
| 939 | */
|
---|
| 940 | int
|
---|
[116] | 941 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
| 942 | char flag_val[128][MAX_STR_LEN],
|
---|
| 943 | bool flag_set[128])
|
---|
[1] | 944 | {
|
---|
[116] | 945 | /*@ ints ** */
|
---|
| 946 | int opt = 0;
|
---|
| 947 | char tmp[MAX_STR_LEN];
|
---|
| 948 | int i = 0;
|
---|
| 949 | int len;
|
---|
[1] | 950 |
|
---|
[116] | 951 | /*@ bools *** */
|
---|
| 952 | bool bad_switches = FALSE;
|
---|
[1] | 953 |
|
---|
[116] | 954 | assert(flag_val != NULL);
|
---|
| 955 | assert(flag_set != NULL);
|
---|
[1] | 956 |
|
---|
[116] | 957 | for (i = 0; i < 128; i++) {
|
---|
| 958 | flag_val[i][0] = '\0';
|
---|
| 959 | flag_set[i] = FALSE;
|
---|
[1] | 960 | }
|
---|
[116] | 961 | while ((opt =
|
---|
| 962 | getopt(argc, argv,
|
---|
| 963 | "0123456789A:B:C:DE:FHI:J:K:LNOP:QRS:T:VWb:c:d:ef:gik:l:mn:op:rs:tuw:x:"))
|
---|
| 964 | != -1) {
|
---|
| 965 | if (opt == '?') {
|
---|
| 966 | bad_switches = TRUE;
|
---|
| 967 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
| 968 | } else {
|
---|
| 969 | if (flag_set[optopt]) {
|
---|
| 970 | bad_switches = TRUE;
|
---|
| 971 | sprintf(tmp, "Switch -%c previously defined as %s\n", opt,
|
---|
| 972 | flag_val[i]);
|
---|
| 973 | log_to_screen(tmp);
|
---|
| 974 | } else {
|
---|
| 975 | flag_set[opt] = TRUE;
|
---|
| 976 | if (optarg) {
|
---|
| 977 | len = strlen(optarg);
|
---|
| 978 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
| 979 | optarg[--len] = '\0';
|
---|
| 980 | log_to_screen
|
---|
| 981 | ("Warning - param '%s' should not have trailing slash!",
|
---|
| 982 | optarg);
|
---|
| 983 | }
|
---|
| 984 | if (opt == 'd') {
|
---|
| 985 | if (strchr(flag_val[opt], '/')
|
---|
| 986 | && flag_val[opt][0] != '/') {
|
---|
| 987 | sprintf(tmp,
|
---|
| 988 | "-%c flag --- must be absolute path --- '%s' isn't absolute",
|
---|
| 989 | opt, flag_val[opt]);
|
---|
| 990 | log_to_screen(tmp);
|
---|
| 991 | bad_switches = TRUE;
|
---|
| 992 | }
|
---|
| 993 | }
|
---|
| 994 | strcpy(flag_val[opt], optarg);
|
---|
| 995 | }
|
---|
| 996 | }
|
---|
[1] | 997 | }
|
---|
| 998 | }
|
---|
[116] | 999 | for (i = optind; i < argc; i++) {
|
---|
| 1000 | bad_switches = TRUE;
|
---|
| 1001 | sprintf(tmp, "Invalid arg -- %s\n", argv[i]);
|
---|
| 1002 | log_to_screen(tmp);
|
---|
| 1003 | }
|
---|
| 1004 | return (bad_switches);
|
---|
[1] | 1005 | }
|
---|
| 1006 |
|
---|
| 1007 |
|
---|
| 1008 |
|
---|
| 1009 |
|
---|
| 1010 | /**
|
---|
| 1011 | * Print a not-so-helpful help message and exit.
|
---|
| 1012 | */
|
---|
[116] | 1013 | void help_screen()
|
---|
[1] | 1014 | {
|
---|
[116] | 1015 | log_msg(1, "Type 'man mondo-archive' for more information\n");
|
---|
| 1016 | exit(1);
|
---|
[1] | 1017 | }
|
---|
| 1018 |
|
---|
| 1019 |
|
---|
| 1020 | /**
|
---|
| 1021 | * Terminate Mondo in response to a signal.
|
---|
| 1022 | * @param sig The signal number received.
|
---|
| 1023 | */
|
---|
| 1024 | void terminate_daemon(int sig)
|
---|
| 1025 | {
|
---|
[116] | 1026 | char tmp[64];
|
---|
| 1027 | char tmp2[MAX_STR_LEN];
|
---|
| 1028 | // char command[512];
|
---|
| 1029 | // pid_t pid;
|
---|
[1] | 1030 |
|
---|
[116] | 1031 | switch (sig) {
|
---|
[1] | 1032 | case SIGINT:
|
---|
| 1033 | sprintf(tmp, "SIGINT");
|
---|
| 1034 | strcpy(tmp2, "You interrupted me :-)");
|
---|
| 1035 | break;
|
---|
| 1036 | case SIGKILL:
|
---|
| 1037 | sprintf(tmp, "SIGKILL");
|
---|
[116] | 1038 | strcpy(tmp2,
|
---|
| 1039 | "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
|
---|
[1] | 1040 | break;
|
---|
| 1041 | case SIGTERM:
|
---|
| 1042 | sprintf(tmp, "SIGTERM");
|
---|
[116] | 1043 | strcpy(tmp2, "Got terminate signal");
|
---|
[1] | 1044 | break;
|
---|
| 1045 | case SIGHUP:
|
---|
| 1046 | sprintf(tmp, "SIGHUP");
|
---|
[116] | 1047 | strcpy(tmp2, "Hangup on line");
|
---|
[1] | 1048 | break;
|
---|
| 1049 | case SIGSEGV:
|
---|
| 1050 | sprintf(tmp, "SIGSEGV");
|
---|
[116] | 1051 | strcpy(tmp2,
|
---|
| 1052 | "Internal programming error. Please send a backtrace as well as your log.");
|
---|
[1] | 1053 | break;
|
---|
| 1054 | case SIGPIPE:
|
---|
| 1055 | sprintf(tmp, "SIGPIPE");
|
---|
[116] | 1056 | strcpy(tmp2, "Pipe was broken");
|
---|
[1] | 1057 | break;
|
---|
[116] | 1058 | case SIGABRT:
|
---|
| 1059 | sprintf(tmp, "SIGABRT");
|
---|
| 1060 | sprintf(tmp2,
|
---|
| 1061 | "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
|
---|
| 1062 | break;
|
---|
[1] | 1063 | default:
|
---|
| 1064 | sprintf(tmp, "(Unknown)");
|
---|
[116] | 1065 | }
|
---|
[1] | 1066 |
|
---|
[116] | 1067 | strcat(tmp, " signal received from OS");
|
---|
| 1068 | log_to_screen(tmp);
|
---|
| 1069 | log_to_screen(tmp2);
|
---|
| 1070 | if (sig == SIGABRT) {
|
---|
| 1071 | sleep(10);
|
---|
| 1072 | }
|
---|
| 1073 | kill_buffer();
|
---|
| 1074 | fatal_error
|
---|
| 1075 | ("Mondoarchive is terminating in response to a signal from the OS");
|
---|
| 1076 | finish(254); // just in case
|
---|
[1] | 1077 | }
|
---|
| 1078 |
|
---|
| 1079 |
|
---|
| 1080 |
|
---|
| 1081 |
|
---|
| 1082 | /**
|
---|
| 1083 | * Turn signal-trapping on or off.
|
---|
| 1084 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
| 1085 | */
|
---|
| 1086 | void set_signals(int on)
|
---|
| 1087 | {
|
---|
[116] | 1088 | int signals[] =
|
---|
| 1089 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
| 1090 | int i;
|
---|
| 1091 |
|
---|
| 1092 | signal(SIGPIPE, sigpipe_occurred);
|
---|
| 1093 | for (i = 0; signals[i]; i++) {
|
---|
| 1094 | if (on) {
|
---|
| 1095 | signal(signals[i], terminate_daemon);
|
---|
| 1096 | } else {
|
---|
| 1097 | signal(signals[i], termination_in_progress);
|
---|
| 1098 | }
|
---|
| 1099 | }
|
---|
[1] | 1100 | }
|
---|
| 1101 |
|
---|
| 1102 |
|
---|
| 1103 |
|
---|
| 1104 |
|
---|
| 1105 | /**
|
---|
| 1106 | * Exit immediately without cleaning up.
|
---|
| 1107 | * @param sig The signal we are exiting due to.
|
---|
| 1108 | */
|
---|
| 1109 | void termination_in_progress(int sig)
|
---|
| 1110 | {
|
---|
[116] | 1111 | log_msg(1, "Termination in progress");
|
---|
| 1112 | usleep(1000);
|
---|
| 1113 | pthread_exit(0);
|
---|
[1] | 1114 | }
|
---|
| 1115 |
|
---|
| 1116 | /* @} - end of cliGroup */
|
---|