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