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