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