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