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