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