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