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