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