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