[1] | 1 | /***************************************************************************
|
---|
[2085] | 2 | $Id: libmondo-cli.c 2273 2009-07-12 00:05:36Z 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>
|
---|
[1917] | 13 | #include "my-stuff.h"
|
---|
[2211] | 14 | #include "mr_mem.h"
|
---|
[2241] | 15 | #include "mr_str.h"
|
---|
[1917] | 16 | #include "mondostructures.h"
|
---|
| 17 | #include "libmondo-cli-EXT.h"
|
---|
| 18 | #include "libmondo.h"
|
---|
[1] | 19 |
|
---|
| 20 | extern int g_loglevel;
|
---|
| 21 | extern bool g_text_mode;
|
---|
[116] | 22 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
[1917] | 23 | extern char *MONDO_OPTIONS;
|
---|
[1] | 24 |
|
---|
| 25 | /*@ file pointer **************************************************/
|
---|
| 26 | extern FILE *g_tape_stream;
|
---|
| 27 |
|
---|
| 28 | /*@ long long *****************************************************/
|
---|
| 29 | extern long long g_tape_posK;
|
---|
| 30 |
|
---|
| 31 | /*@ long **********************************************************/
|
---|
| 32 | extern long g_noof_sets;
|
---|
| 33 |
|
---|
| 34 | /*@ bool******** **************************************************/
|
---|
[116] | 35 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
| 36 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
[1] | 37 | extern bool g_cd_recovery;
|
---|
| 38 |
|
---|
[1656] | 39 | extern void setup_tmpdir(char *path);
|
---|
[1] | 40 | extern double g_kernel_version;
|
---|
| 41 | extern int g_current_media_number;
|
---|
| 42 | extern pid_t g_main_pid;
|
---|
[116] | 43 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
|
---|
[1] | 44 |
|
---|
[2007] | 45 | /* Stuff that handles the -I and -E option when a whole disk DSF is used */
|
---|
| 46 | typedef struct mounted_fs_struct {
|
---|
| 47 | char device[MAX_STR_LEN]; /* The name of the device */
|
---|
| 48 | char mount_point[MAX_STR_LEN]; /* The devices mount point */
|
---|
| 49 | unsigned char check; /* 1 == included on DSF */
|
---|
| 50 | struct mounted_fs_struct *next;
|
---|
| 51 | } MOUNTED_FS_STRUCT;
|
---|
| 52 | static MOUNTED_FS_STRUCT *DSF_Head = NULL; /* Points to the first entry of mounted_fs_struct list */
|
---|
| 53 | static MOUNTED_FS_STRUCT *DSF_Tail = NULL; /* Points to the last entry of mounted_fs_struct list */
|
---|
| 54 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr);
|
---|
| 55 | static void free_mounted_fs_list (void);
|
---|
| 56 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
|
---|
| 57 | static int create_list_of_non_NFS_mounted_file_systems (void);
|
---|
| 58 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point);
|
---|
| 59 | static MOUNTED_FS_STRUCT *find_device_in_list (char *device);
|
---|
| 60 |
|
---|
[948] | 61 | /* Do we use extended attributes and acl ?
|
---|
| 62 | * By default no, use --acl & --attr options to force their usage */
|
---|
[1917] | 63 | extern char *g_getfacl;
|
---|
| 64 | extern char *g_getfattr;
|
---|
[1] | 65 |
|
---|
[1645] | 66 | /* Reference to global bkpinfo */
|
---|
| 67 | extern struct s_bkpinfo *bkpinfo;
|
---|
| 68 |
|
---|
[1967] | 69 | extern void free_MR_global_filenames(void);
|
---|
| 70 |
|
---|
[1] | 71 | /**
|
---|
| 72 | * @addtogroup cliGroup
|
---|
| 73 | * @{
|
---|
| 74 | */
|
---|
| 75 | /**
|
---|
| 76 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
|
---|
| 77 | * @param argc The argument count, including the program name; @p argc passed to main().
|
---|
| 78 | * @param argv The argument vector; @p argv passed to main().
|
---|
| 79 | * @param bkpinfo The backup information structure to populate.
|
---|
| 80 | * @return The number of problems with the command line (0 for success).
|
---|
| 81 | */
|
---|
| 82 | int
|
---|
[1645] | 83 | handle_incoming_parameters(int argc, char *argv[])
|
---|
[1] | 84 | {
|
---|
[116] | 85 | /*@ int *** */
|
---|
| 86 | int res = 0;
|
---|
| 87 | int retval = 0;
|
---|
| 88 | int i = 0, j;
|
---|
[1] | 89 |
|
---|
[116] | 90 | /*@ buffers *************** */
|
---|
[2271] | 91 | char *tmp = NULL;
|
---|
[116] | 92 | char flag_val[128][MAX_STR_LEN];
|
---|
| 93 | bool flag_set[128];
|
---|
[1] | 94 |
|
---|
[116] | 95 | for (i = 0; i < 128; i++) {
|
---|
| 96 | flag_val[i][0] = '\0';
|
---|
| 97 | flag_set[i] = FALSE;
|
---|
| 98 | }
|
---|
| 99 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 100 | bkpinfo->media_size[j] = 650;
|
---|
| 101 | } /* default */
|
---|
| 102 | res =
|
---|
| 103 | retrieve_switches_from_command_line(argc, argv, flag_val,
|
---|
| 104 | flag_set);
|
---|
| 105 | retval += res;
|
---|
| 106 | if (!retval) {
|
---|
[1645] | 107 | res = process_switches(flag_val, flag_set);
|
---|
[116] | 108 | retval += res;
|
---|
| 109 | }
|
---|
| 110 | log_msg(3, "Switches:-");
|
---|
| 111 | for (i = 0; i < 128; i++) {
|
---|
| 112 | if (flag_set[i]) {
|
---|
[2271] | 113 | mr_asprintf(&tmp, "-%c %s", i, flag_val[i]);
|
---|
[116] | 114 | log_msg(3, tmp);
|
---|
[2271] | 115 | mr_free(tmp);
|
---|
[116] | 116 | }
|
---|
[1] | 117 | }
|
---|
[2271] | 118 | mr_asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
|
---|
[116] | 119 | paranoid_system(tmp);
|
---|
[2271] | 120 | mr_free(tmp);
|
---|
| 121 |
|
---|
| 122 | mr_asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
|
---|
[116] | 123 | paranoid_system(tmp);
|
---|
[2271] | 124 | mr_free(tmp);
|
---|
| 125 |
|
---|
[116] | 126 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
|
---|
| 127 | "/mondo.scratch.%ld", random() % 32767);
|
---|
[2271] | 128 | mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
|
---|
[116] | 129 | paranoid_system(tmp);
|
---|
[2271] | 130 | mr_free(tmp);
|
---|
| 131 |
|
---|
| 132 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
|
---|
[116] | 133 | paranoid_system(tmp);
|
---|
[2271] | 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 | */
|
---|
[1645] | 148 | int process_the_s_switch(char *value)
|
---|
[1] | 149 | {
|
---|
[116] | 150 | int j;
|
---|
[2273] | 151 | char tmp[MAX_STR_LEN], *p;
|
---|
[2271] | 152 | char *comment = NULL;
|
---|
[1] | 153 |
|
---|
[116] | 154 | assert(bkpinfo != NULL);
|
---|
| 155 | assert(value != NULL);
|
---|
[1] | 156 |
|
---|
[116] | 157 | bkpinfo->media_size[0] = -1; /* dummy value */
|
---|
| 158 | for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
|
---|
| 159 | j++, p = strchr(p, ',') + 1) {
|
---|
| 160 | strncpy(tmp, p, MAX_STR_LEN);
|
---|
| 161 | *(strchr(tmp, ',')) = '\0';
|
---|
| 162 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
|
---|
[2271] | 163 | mr_asprintf(&comment, "media_size[%d] = %ld", j, bkpinfo->media_size[j]);
|
---|
[116] | 164 | log_msg(3, comment);
|
---|
[2271] | 165 | mr_free(comment);
|
---|
[1] | 166 | }
|
---|
[116] | 167 | for (; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 168 | bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
|
---|
[1] | 169 | }
|
---|
| 170 | // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
|
---|
[116] | 171 | for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
|
---|
| 172 | if (bkpinfo->media_size[j] <= 0) {
|
---|
| 173 | log_msg(1, "You gave media #%d an invalid size\n", j);
|
---|
| 174 | return (-1);
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | return (0);
|
---|
[1] | 178 | }
|
---|
| 179 |
|
---|
[2007] | 180 | /**
|
---|
| 181 | * Frees the memory for all of the structures on the linked list of
|
---|
| 182 | * all of the non-NFS mounted file systems.
|
---|
| 183 | */
|
---|
| 184 | static void free_mounted_fs_list (void) {
|
---|
| 185 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
| 186 | MOUNTED_FS_STRUCT *DSFnext = NULL;
|
---|
| 187 |
|
---|
| 188 | DSFptr = DSF_Head;
|
---|
| 189 | while (DSFptr != NULL) {
|
---|
| 190 | DSFnext = DSFptr->next;
|
---|
| 191 | paranoid_free(DSFptr);
|
---|
| 192 | DSFptr = DSFnext;
|
---|
| 193 | }
|
---|
| 194 | DSF_Head = NULL;
|
---|
| 195 | DSF_Tail = NULL;
|
---|
| 196 | }
|
---|
[1] | 197 |
|
---|
[2007] | 198 | /**
|
---|
| 199 | * Creates a singly linked list of all of the non-NFS mounted file systems.
|
---|
| 200 | * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold
|
---|
| 201 | * the list of mounted file systems.
|
---|
| 202 | * @return None.
|
---|
| 203 | */
|
---|
| 204 | static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
|
---|
| 205 | {
|
---|
| 206 | assert (DSFptr);
|
---|
| 207 | if (DSF_Head == NULL) {
|
---|
| 208 | DSF_Head = DSFptr;
|
---|
| 209 | } else {
|
---|
| 210 | DSF_Tail->next = DSFptr;
|
---|
| 211 | }
|
---|
| 212 | DSFptr->next = NULL;
|
---|
| 213 | DSF_Tail = DSFptr;
|
---|
| 214 | }
|
---|
[1] | 215 |
|
---|
| 216 | /**
|
---|
[2007] | 217 | * Find the structure, in the singly linked list of all of the non-NFS
|
---|
| 218 | * mounted file systems, that contains the specified device.
|
---|
| 219 | * @param device The device to find
|
---|
| 220 | * @return NULL if it didn't find the device, a pointer to the
|
---|
| 221 | * structure if it did.
|
---|
| 222 | */
|
---|
| 223 | static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
|
---|
| 224 | {
|
---|
| 225 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
| 226 |
|
---|
| 227 | DSFptr = DSF_Head;
|
---|
| 228 | while (DSFptr != NULL) {
|
---|
| 229 | if (!strcmp(DSFptr->device, device)) {
|
---|
| 230 | break;
|
---|
| 231 | }
|
---|
| 232 | DSFptr = DSFptr->next;
|
---|
| 233 | }
|
---|
| 234 | return (DSFptr);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /**
|
---|
| 238 | * Find the structure, in the singly linked list of all of the non-NFS
|
---|
| 239 | * mounted file systems, that contains the specified mount point.
|
---|
| 240 | * @param mount_point The mount point to find
|
---|
| 241 | * @return NULL is it didn't find the mount point, a pointer to the
|
---|
| 242 | * structure if it did.
|
---|
| 243 | */
|
---|
| 244 | static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
|
---|
| 245 | {
|
---|
| 246 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
| 247 |
|
---|
| 248 | DSFptr = DSF_Head;
|
---|
| 249 | while (DSFptr != NULL) {
|
---|
| 250 | if (!strcmp(DSFptr->mount_point, mount_point)) {
|
---|
| 251 | break;
|
---|
| 252 | }
|
---|
| 253 | DSFptr = DSFptr->next;
|
---|
| 254 | }
|
---|
| 255 | return (DSFptr);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /**
|
---|
| 259 | * Creates a linked list of all of the non-NFS mounted file systems.
|
---|
| 260 | * We use a linked list because we don't know how many mounted file
|
---|
| 261 | * there are (and there can be a lot).
|
---|
| 262 | * @return 0 on success and greated than 0 on failure.
|
---|
| 263 | */
|
---|
| 264 | static int create_list_of_non_NFS_mounted_file_systems (void)
|
---|
| 265 | {
|
---|
| 266 | int i = 0;
|
---|
| 267 | int mount_cnt = 0;
|
---|
| 268 | char *mounted_file_system = NULL;
|
---|
| 269 | char *command = NULL;
|
---|
| 270 | char *token = NULL;
|
---|
| 271 | char token_chars[] =" :\t\r\f\a\0";
|
---|
| 272 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
| 273 |
|
---|
| 274 | free_mounted_fs_list();
|
---|
| 275 | /********
|
---|
| 276 | * Find the number of mounted file system entries and their respective mount points.
|
---|
| 277 | * I can't return all of the entries as one string because it's length can be longer
|
---|
| 278 | * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
|
---|
| 279 | * So start looping and get the number of mounted file systems and query them one by one.
|
---|
| 280 | ********/
|
---|
| 281 | /* Get the number of mounted file systems ((those that start with "/dev/" */
|
---|
[2211] | 282 | mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
|
---|
[2007] | 283 | log_msg(5, "Running: %s", command);
|
---|
[2211] | 284 | mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2007] | 285 | paranoid_free(command);
|
---|
| 286 |
|
---|
| 287 | mount_cnt = atoi(mounted_file_system);
|
---|
| 288 | log_msg (5, "mount_cnt: %d", mount_cnt);
|
---|
| 289 | paranoid_free(mounted_file_system);
|
---|
| 290 |
|
---|
| 291 | for (i=mount_cnt; i > 0; i--) {
|
---|
[2211] | 292 | mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
|
---|
[2007] | 293 | log_msg(5, "Running: %s", command);
|
---|
[2211] | 294 | mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2007] | 295 | paranoid_free(command);
|
---|
| 296 |
|
---|
| 297 | log_msg (5, "mounted_file_system: %s", mounted_file_system);
|
---|
| 298 | if ((token = strtok(mounted_file_system, token_chars)) == NULL) {
|
---|
| 299 | log_msg (4, "Could not get the list of mounted file systems");
|
---|
| 300 | paranoid_free(mounted_file_system);
|
---|
[2241] | 301 | mr_free(token);
|
---|
[2007] | 302 | return (1);
|
---|
| 303 | }
|
---|
[2241] | 304 | if (token) {
|
---|
| 305 | log_msg (5, "token: %s", token);
|
---|
| 306 | }
|
---|
[2007] | 307 | while (token != NULL) {
|
---|
| 308 | log_msg (5, "token: %s", token);
|
---|
| 309 | if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
|
---|
| 310 | fatal_error ("Cannot allocate memory");
|
---|
| 311 | }
|
---|
| 312 | add_mounted_fs_struct(DSFptr);
|
---|
| 313 | strcpy(DSFptr->device, token);
|
---|
[2241] | 314 | mr_free(token);
|
---|
[2007] | 315 | if ((token = strtok(NULL, token_chars)) == NULL) {
|
---|
| 316 | log_msg (5, "Ran out of entries on the mounted file systems list");
|
---|
[2022] | 317 | paranoid_free(mounted_file_system);
|
---|
[2241] | 318 | mr_free(token);
|
---|
[2007] | 319 | return (1);
|
---|
| 320 | }
|
---|
| 321 | log_msg (5, "token: %s", token);
|
---|
| 322 | strcpy(DSFptr->mount_point, token);
|
---|
[2241] | 323 | mr_free(token);
|
---|
[2007] | 324 | token = strtok(NULL, token_chars);
|
---|
| 325 | }
|
---|
[2022] | 326 | paranoid_free(mounted_file_system);
|
---|
[2007] | 327 | }
|
---|
| 328 | /********
|
---|
| 329 | * DSFptr = DSF_Head;
|
---|
| 330 | * while (DSFptr != NULL) {
|
---|
| 331 | * printf ("Dev: %s MP: %s Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
|
---|
| 332 | * DSFptr = DSFptr->next;
|
---|
| 333 | * }
|
---|
| 334 | ********/
|
---|
| 335 | return (0);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | /**
|
---|
| 339 | * Given a whole disk device special file, determine which mounted file systems
|
---|
| 340 | * are on the dsf's partitions and which mounted file systems are not.
|
---|
| 341 | * @param dsf The whole disk device special file.
|
---|
| 342 | * @param included_dsf_list A char pointer used to hold the list of mount points
|
---|
| 343 | * that are on the dsf. Memory for the array will be allocated within the function.
|
---|
| 344 | * @param excluded_dsf_list A char pointer used to hold the list of mount points
|
---|
| 345 | * that are not on the dsf. Memory for the array will be allocated within the function.
|
---|
| 346 | * @return 0 on success, -1 if no device special file was passed in, -2 if a device
|
---|
| 347 | * special file was passed in but it has no partitions on it, or 1 on failure
|
---|
| 348 | */
|
---|
| 349 | static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
|
---|
| 350 | int i = 0;
|
---|
| 351 | int c = 0;
|
---|
[2022] | 352 | int lastpos = 0;
|
---|
[2007] | 353 | char VG[MAX_STR_LEN];
|
---|
| 354 | char *tmp = NULL;
|
---|
| 355 | char *command = NULL;
|
---|
| 356 | char *partition_list = NULL;
|
---|
| 357 | char partitions[64][MAX_STR_LEN];
|
---|
| 358 | char *mount_list = NULL;
|
---|
| 359 | char *token = NULL;
|
---|
| 360 | char token_chars[] =" \t\r\f\a\0";
|
---|
| 361 | MOUNTED_FS_STRUCT *DSFptr = NULL;
|
---|
| 362 |
|
---|
| 363 | memset((char *)partitions, 0, sizeof(partitions));
|
---|
| 364 |
|
---|
[2022] | 365 | log_msg(5, "dsf: %s", dsf);
|
---|
| 366 |
|
---|
| 367 | /********
|
---|
| 368 | * See if a device special file was passed in (i.e. it must start with /dev/
|
---|
| 369 | ********/
|
---|
| 370 | if (strncmp(dsf, "/dev/", 5)) {
|
---|
| 371 | log_msg (5, "%s does not start with /dev/ and (probably) is not a device special file", dsf);
|
---|
| 372 | return (-1);
|
---|
[2007] | 373 | }
|
---|
[2022] | 374 | log_msg(5, " %s looks like a device special file", dsf);
|
---|
| 375 | /* Verify that the dsf exists */
|
---|
[2211] | 376 | mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
|
---|
[2022] | 377 | log_msg(5, " Executing: %s", command);
|
---|
[2211] | 378 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 379 | paranoid_free(command);
|
---|
| 380 |
|
---|
| 381 | log_msg(5, " Return value: %s", tmp);
|
---|
| 382 | c = atoi(tmp);
|
---|
| 383 | paranoid_free(tmp);
|
---|
| 384 |
|
---|
| 385 | if (!c) {
|
---|
| 386 | log_to_screen("Cannot find device special file %s", dsf);
|
---|
| 387 | return (1);
|
---|
| 388 | }
|
---|
| 389 | log_msg(5, " %s device special file exists", dsf);
|
---|
[2007] | 390 |
|
---|
| 391 | /* Get a list of the mounted file systems */
|
---|
| 392 | if (create_list_of_non_NFS_mounted_file_systems()) {
|
---|
| 393 | log_to_screen ("Could not get the list of mounted file systems");
|
---|
| 394 | return (1);
|
---|
| 395 | }
|
---|
[2022] | 396 | log_msg (5, "Processing dsf: %s", dsf);
|
---|
| 397 | /********
|
---|
| 398 | * Get a list of the dsf's partitions. There could be no partitions on the disk
|
---|
| 399 | * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
|
---|
| 400 | * Either way, it's an error.
|
---|
| 401 | ********/
|
---|
[2211] | 402 | mr_asprintf(&command,
|
---|
[2222] | 403 | "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
|
---|
[2022] | 404 | log_msg(4, "Executing: %s", command);
|
---|
[2211] | 405 | mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 406 | paranoid_free(command);
|
---|
| 407 | log_msg(4, "Partition list for %s: %s", dsf, partition_list);
|
---|
| 408 | if (!strlen(partition_list)) {
|
---|
| 409 | /* There were no partitions on the disk */
|
---|
| 410 | log_msg(4, "Cannot find any partitions on device special file %s", dsf);
|
---|
| 411 | return (-2);
|
---|
| 412 | }
|
---|
[2007] | 413 |
|
---|
[2022] | 414 | /* Fill the partition list */
|
---|
| 415 | i = 0;
|
---|
| 416 | lastpos = 0;
|
---|
[2053] | 417 | while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
|
---|
[2022] | 418 | log_msg (5, "Found partition: %s", token);
|
---|
| 419 | strcpy(partitions[i++], token);
|
---|
[2241] | 420 | mr_free(token);
|
---|
[2022] | 421 | }
|
---|
| 422 | paranoid_free(partition_list);
|
---|
[2007] | 423 |
|
---|
[2022] | 424 | /********
|
---|
| 425 | * At this point, we have a list of all of the partitions on the dsf. Now try to
|
---|
| 426 | * see which partitions have a file system on them.
|
---|
| 427 | *
|
---|
| 428 | * Loop through each partition on the disk and:
|
---|
| 429 | *
|
---|
| 430 | * - If the partition is swap, it ignores it.
|
---|
| 431 | *
|
---|
| 432 | * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
|
---|
| 433 | * to the linked list, copies to it the device name and mount point, and sets check == 1.
|
---|
| 434 | *
|
---|
| 435 | * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
|
---|
| 436 | * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
|
---|
| 437 | * to it the device name and mount point, and sets check == 1. Note that if the Volume Group
|
---|
| 438 | * contains more than one disk, it will still add the entry even if the Logical Volume's
|
---|
| 439 | * extents are not on the dsf that was passed in to the function. For example, Volume Group
|
---|
| 440 | * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
|
---|
| 441 | * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
|
---|
| 442 | * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
|
---|
| 443 | * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
|
---|
| 444 | *
|
---|
| 445 | * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
|
---|
| 446 | * software raid device, it adds an entry to the linked list, copies to it the software raid
|
---|
| 447 | * device name and mount point, and sets check == 1.
|
---|
| 448 | *
|
---|
| 449 | * - If the partition is part of a mounted software raid device, it adds an entry to the linked
|
---|
| 450 | * list, copies to it the software raid device name and mount point, and sets check == 1.
|
---|
| 451 | *
|
---|
| 452 | ********/
|
---|
| 453 | for (i=0; strlen(partitions[i]); i++) {
|
---|
| 454 | log_msg(4, "Processing partition: %s", partitions[i]);
|
---|
| 455 | /* See if it's swap. If it is, ignore it. */
|
---|
[2211] | 456 | mr_asprintf(&command,
|
---|
[2222] | 457 | "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
|
---|
[2022] | 458 | dsf, partitions[i]);
|
---|
| 459 | log_msg(4, " Running: %s", command);
|
---|
[2211] | 460 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 461 | paranoid_free(command);
|
---|
| 462 | log_msg(4, " Return value: %s", tmp);
|
---|
| 463 | c = strlen(tmp);
|
---|
| 464 | paranoid_free(tmp);
|
---|
| 465 | if (c) {
|
---|
| 466 | log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
|
---|
| 467 | continue;
|
---|
| 468 | }
|
---|
| 469 | /* It's not swap. See if we can find the mount point from the mount command. */
|
---|
[2211] | 470 | mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
|
---|
| 471 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 472 | paranoid_free(command);
|
---|
| 473 | if (strlen(tmp)) {
|
---|
| 474 | log_msg(4, " %s is mounted: %s", partitions[i], tmp);
|
---|
| 475 | if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
|
---|
| 476 | log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
|
---|
[2007] | 477 | paranoid_free(tmp);
|
---|
[2022] | 478 | return (1);
|
---|
[2007] | 479 | }
|
---|
[2022] | 480 | DSFptr->check = 1;
|
---|
[2007] | 481 | paranoid_free(tmp);
|
---|
[2022] | 482 | continue;
|
---|
| 483 | }
|
---|
| 484 | paranoid_free(tmp);
|
---|
| 485 | /* It's not swap and it's not mounted. See if it's LVM */
|
---|
| 486 | log_msg(4, " It's not mounted. Checking to see if it's LVM...");
|
---|
| 487 | /* Get the partition ID; 8e for LVM */
|
---|
[2222] | 488 | mr_asprintf(&command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
|
---|
[2022] | 489 | log_msg(4, " Running: %s", command);
|
---|
[2211] | 490 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 491 | paranoid_free(command);
|
---|
| 492 | if (strlen(tmp)) {
|
---|
| 493 | log_msg(4, " Partition ID: %s", tmp);
|
---|
| 494 | if (!strcasecmp(tmp, "8e")) {
|
---|
| 495 | /* It's LVM: Find the VG it's in */
|
---|
| 496 | log_msg(4, " It's LVM: Find the VG it's in...");
|
---|
[2211] | 497 | mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
|
---|
[2022] | 498 | log_msg(4, " Running: %s", command);
|
---|
| 499 | strcpy(VG, call_program_and_get_last_line_of_output(command));
|
---|
| 500 | paranoid_free(command);
|
---|
| 501 | log_msg(4, " Volume Group: %s", VG);
|
---|
| 502 | if (strlen(VG)) {
|
---|
| 503 | /* Found the Volume Group. Now find all of the VG's mount points */
|
---|
| 504 | log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");
|
---|
[2211] | 505 | mr_asprintf(&command,
|
---|
[2022] | 506 | "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'",
|
---|
| 507 | VG, VG);
|
---|
[2007] | 508 | log_msg(4, " Running: %s", command);
|
---|
[2211] | 509 | mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2007] | 510 | paranoid_free(command);
|
---|
[2022] | 511 | log_msg(4, " VG %s mount_list: %s", VG, mount_list);
|
---|
| 512 | lastpos = 0;
|
---|
[2053] | 513 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
[2022] | 514 | log_msg (5, "mount point token: %s", token);
|
---|
| 515 | if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
|
---|
| 516 | log_msg (4, "Can't find mount point %s in mounted file systems list", token);
|
---|
| 517 | paranoid_free(tmp);
|
---|
[2241] | 518 | mr_free(token);
|
---|
[2022] | 519 | return (1);
|
---|
| 520 | }
|
---|
| 521 | DSFptr->check = 1;
|
---|
[2241] | 522 | mr_free(token);
|
---|
[2022] | 523 | }
|
---|
| 524 | /********
|
---|
| 525 | * Now we want to see if there are any software raid devices using
|
---|
| 526 | * any of the Logical Volumes on the Volume Group.
|
---|
| 527 | *******/
|
---|
| 528 | paranoid_free(mount_list);
|
---|
[2211] | 529 | mr_asprintf(&command, "%s",
|
---|
[2022] | 530 | "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
---|
| 531 | log_msg (5, "Running: %s", command);
|
---|
[2211] | 532 | mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 533 | paranoid_free(command);
|
---|
| 534 | log_msg(4, " Software raid device list: %s", mount_list);
|
---|
| 535 | lastpos = 0;
|
---|
[2053] | 536 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
[2211] | 537 | mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
|
---|
[2022] | 538 | log_msg (5, "Running: %s", command);
|
---|
| 539 | paranoid_free(tmp);
|
---|
[2211] | 540 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2007] | 541 | paranoid_free(command);
|
---|
[2022] | 542 | log_msg(4, "Number of Software raid device: %s", tmp);
|
---|
| 543 | if (atoi(tmp)) {
|
---|
| 544 | /* This device is on our disk */
|
---|
| 545 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
---|
| 546 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
---|
[2007] | 547 | paranoid_free(tmp);
|
---|
[2241] | 548 | mr_free(token);
|
---|
[2007] | 549 | return (1);
|
---|
| 550 | }
|
---|
| 551 | DSFptr->check = 1;
|
---|
| 552 | }
|
---|
| 553 | }
|
---|
[2241] | 554 | mr_free(token);
|
---|
[2022] | 555 | paranoid_free(mount_list);
|
---|
| 556 | } else {
|
---|
| 557 | log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
|
---|
[2007] | 558 | paranoid_free(tmp);
|
---|
[2022] | 559 | return (1);
|
---|
[2007] | 560 | }
|
---|
[2022] | 561 | paranoid_free(tmp);
|
---|
| 562 | continue;
|
---|
[2007] | 563 | }
|
---|
[2022] | 564 | } else {
|
---|
| 565 | log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
|
---|
| 566 | }
|
---|
| 567 | paranoid_free(tmp);
|
---|
| 568 | /********
|
---|
| 569 | * It's not swap, mounted, or LVM. See if it's used in a software raid device.
|
---|
| 570 | ********/
|
---|
| 571 | log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
|
---|
[2211] | 572 | mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
|
---|
[2022] | 573 | log_msg(4, " Running: %s", command);
|
---|
[2211] | 574 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 575 | paranoid_free(command);
|
---|
| 576 | if (!strlen(tmp)) {
|
---|
| 577 | log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);
|
---|
[2007] | 578 | paranoid_free(tmp);
|
---|
[2022] | 579 | continue;
|
---|
| 580 | }
|
---|
| 581 | log_msg (5, " UUID: %s", tmp);
|
---|
| 582 | /* Get the Software raid device list */
|
---|
[2211] | 583 | mr_asprintf(&command, "%s",
|
---|
[2022] | 584 | "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
|
---|
| 585 | log_msg (5, " Running: %s", command);
|
---|
[2211] | 586 | mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2022] | 587 | paranoid_free(command);
|
---|
| 588 | log_msg(4, " Software raid device list: %s", mount_list);
|
---|
| 589 | /* Loop through the software raid device list to see if we can find the partition */
|
---|
| 590 | lastpos = 0;
|
---|
[2053] | 591 | while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
|
---|
[2211] | 592 | mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
|
---|
[2007] | 593 | log_msg(4, " Running: %s", command);
|
---|
[2022] | 594 | paranoid_free(tmp);
|
---|
[2211] | 595 | mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
|
---|
[2007] | 596 | paranoid_free(command);
|
---|
[2022] | 597 | if (!atoi(tmp)) {
|
---|
| 598 | log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);
|
---|
| 599 | } else {
|
---|
| 600 | if ((DSFptr = find_device_in_list(token)) == NULL) {
|
---|
| 601 | log_msg (4, "Can't find device %s in mounted file systems list", token);
|
---|
| 602 | paranoid_free(tmp);
|
---|
[2241] | 603 | mr_free(token);
|
---|
[2022] | 604 | return (1);
|
---|
[2007] | 605 | }
|
---|
[2022] | 606 | DSFptr->check = 1;
|
---|
| 607 | break;
|
---|
[2007] | 608 | }
|
---|
[2241] | 609 | mr_free(token);
|
---|
[2007] | 610 | }
|
---|
[2022] | 611 | paranoid_free(tmp);
|
---|
[2007] | 612 | }
|
---|
| 613 | paranoid_free(partition_list);
|
---|
| 614 | paranoid_free(mount_list);
|
---|
| 615 |
|
---|
| 616 | /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
|
---|
| 617 | i = 0;
|
---|
| 618 | DSFptr= DSF_Head;
|
---|
| 619 | while (DSFptr != NULL) {
|
---|
| 620 | i += strlen(DSFptr->mount_point) + 1;
|
---|
| 621 | DSFptr = DSFptr->next;
|
---|
| 622 | }
|
---|
| 623 | log_msg (5, "i: %d", i);
|
---|
| 624 | if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
---|
| 625 | fatal_error ("Cannot allocate memory");
|
---|
| 626 | }
|
---|
| 627 | if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
|
---|
| 628 | fatal_error ("Cannot allocate memory");
|
---|
| 629 | }
|
---|
| 630 | DSFptr= DSF_Head;
|
---|
| 631 | while (DSFptr != NULL) {
|
---|
| 632 | if (DSFptr->check) {
|
---|
| 633 | log_msg (5, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
|
---|
| 634 | strcat(*included_dsf_list, DSFptr->mount_point);
|
---|
| 635 | strcat(*included_dsf_list, " ");
|
---|
| 636 | } else {
|
---|
| 637 | log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, dsf);
|
---|
| 638 | strcat(*excluded_dsf_list, DSFptr->mount_point);
|
---|
| 639 | strcat(*excluded_dsf_list, " ");
|
---|
| 640 | }
|
---|
| 641 | DSFptr = DSFptr->next;
|
---|
| 642 | }
|
---|
| 643 | log_msg (5, "included_dsf_list: %s", *included_dsf_list);
|
---|
| 644 | log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
|
---|
| 645 | return (0);
|
---|
| 646 | }
|
---|
| 647 |
|
---|
| 648 |
|
---|
| 649 | /**
|
---|
[1] | 650 | * Process mondoarchive's command-line switches.
|
---|
| 651 | * @param bkpinfo The backup information structure to populate.
|
---|
| 652 | * @param flag_val An array of the argument passed to each switch (the letter is the index).
|
---|
| 653 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
|
---|
| 654 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
|
---|
| 655 | * FALSE if it's not.
|
---|
| 656 | * @return The number of problems with the switches, or 0 for success.
|
---|
| 657 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
|
---|
| 658 | */
|
---|
| 659 | int
|
---|
[1645] | 660 | process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
|
---|
[1] | 661 | {
|
---|
| 662 |
|
---|
[116] | 663 | /*@ ints *** */
|
---|
| 664 | int i = 0;
|
---|
| 665 | int retval = 0;
|
---|
| 666 | int percent = 0;
|
---|
[2022] | 667 | int lastpos = 0;
|
---|
[1] | 668 |
|
---|
[116] | 669 | /*@ buffers ** */
|
---|
[2022] | 670 | char *tmp = NULL;
|
---|
| 671 | char *tmp1 = NULL;
|
---|
[2271] | 672 | char *tmp2 = NULL;
|
---|
[2022] | 673 | char *psz = NULL;
|
---|
| 674 | char *p = NULL;
|
---|
| 675 | char *q = NULL;
|
---|
| 676 | char *token = NULL;
|
---|
[2007] | 677 | char *mounted_on_dsf = NULL;
|
---|
| 678 | char *not_mounted_on_dsf = NULL;
|
---|
[2022] | 679 | char token_chars[] =" \t\r\f\a\0";
|
---|
[1] | 680 |
|
---|
[949] | 681 | long itbs = 0L;
|
---|
[1] | 682 |
|
---|
[289] | 683 | struct stat buf;
|
---|
| 684 |
|
---|
[116] | 685 | malloc_string(tmp);
|
---|
[1] | 686 |
|
---|
[116] | 687 | assert(bkpinfo != NULL);
|
---|
| 688 | assert(flag_val != NULL);
|
---|
| 689 | assert(flag_set != NULL);
|
---|
[1] | 690 |
|
---|
[116] | 691 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
|
---|
[1] | 692 |
|
---|
[1967] | 693 | /* compulsory */
|
---|
[116] | 694 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
|
---|
| 695 | flag_set['t'] + flag_set['u'] + flag_set['r'] +
|
---|
[1690] | 696 | flag_set['w'] + flag_set['C'] + flag_set['U'];
|
---|
[1967] | 697 | if ((i == 0) && (! bkpinfo->restore_data)) {
|
---|
[116] | 698 | retval++;
|
---|
[541] | 699 | log_to_screen("You must specify the media type\n");
|
---|
[1] | 700 | }
|
---|
[116] | 701 | if (i > 1) {
|
---|
| 702 | retval++;
|
---|
[541] | 703 | log_to_screen("Please specify only one media type\n");
|
---|
[1] | 704 | }
|
---|
[1967] | 705 |
|
---|
[116] | 706 | if (flag_set['K']) {
|
---|
| 707 | g_loglevel = atoi(flag_val['K']);
|
---|
[1945] | 708 | log_msg(1,"Loglevel forced to %d",g_loglevel);
|
---|
[116] | 709 | if (g_loglevel < 3) {
|
---|
| 710 | g_loglevel = 3;
|
---|
| 711 | }
|
---|
[1] | 712 | }
|
---|
[1967] | 713 |
|
---|
| 714 | if ((flag_set['L'] && flag_set['0']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 715 | retval++;
|
---|
[541] | 716 | log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
|
---|
[1] | 717 | }
|
---|
[1967] | 718 | if (! bkpinfo->restore_data) {
|
---|
| 719 | bkpinfo->backup_data = flag_set['O'];
|
---|
| 720 | }
|
---|
[116] | 721 | bkpinfo->verify_data = flag_set['V'];
|
---|
[1967] | 722 |
|
---|
[116] | 723 | if (flag_set['I'] && !bkpinfo->backup_data) {
|
---|
[541] | 724 | log_to_screen("-I switch is ignored if just verifying");
|
---|
[116] | 725 | }
|
---|
| 726 | if (flag_set['E'] && !bkpinfo->backup_data) {
|
---|
[541] | 727 | log_to_screen("-E switch is ignored if just verifying");
|
---|
[116] | 728 | }
|
---|
[1] | 729 |
|
---|
[116] | 730 | if (!find_home_of_exe("afio")) {
|
---|
| 731 | if (find_home_of_exe("star")) {
|
---|
| 732 | flag_set['R'] = TRUE;
|
---|
| 733 | log_msg(1, "Using star instead of afio");
|
---|
| 734 | } else {
|
---|
| 735 | fatal_error
|
---|
| 736 | ("Neither afio nor star is installed. Please install at least one.");
|
---|
| 737 | }
|
---|
[1] | 738 | }
|
---|
| 739 |
|
---|
[116] | 740 | if (flag_set['R']) {
|
---|
| 741 | bkpinfo->use_star = TRUE;
|
---|
| 742 | if (flag_set['L']) {
|
---|
| 743 | fatal_error("You may not use star and lzop at the same time.");
|
---|
| 744 | }
|
---|
| 745 | if (!find_home_of_exe("star")) {
|
---|
| 746 | fatal_error
|
---|
| 747 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
|
---|
| 748 | }
|
---|
[1] | 749 | }
|
---|
[1967] | 750 |
|
---|
| 751 | if ((flag_set['W']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 752 | bkpinfo->nonbootable_backup = TRUE;
|
---|
| 753 | log_to_screen("Warning - you have opted for non-bootable backup");
|
---|
| 754 | if (flag_set['f'] || flag_set['l']) {
|
---|
| 755 | log_to_screen
|
---|
[541] | 756 | ("You don't need to specify bootloader or bootdevice");
|
---|
[116] | 757 | }
|
---|
[1] | 758 | }
|
---|
[1967] | 759 |
|
---|
[116] | 760 | if (flag_set['I']) {
|
---|
[2022] | 761 | if (bkpinfo->include_paths[0] == '-') {
|
---|
| 762 | retval++;
|
---|
| 763 | log_to_screen("Please supply a sensible value with '-I'\n");
|
---|
| 764 | }
|
---|
[116] | 765 | if (!strcmp(bkpinfo->include_paths, "/")) {
|
---|
| 766 | log_msg(2, "'/' is pleonastic.");
|
---|
| 767 | bkpinfo->include_paths[0] = '\0';
|
---|
| 768 | }
|
---|
| 769 | if (bkpinfo->include_paths[0]) {
|
---|
| 770 | strcat(bkpinfo->include_paths, " ");
|
---|
| 771 | }
|
---|
[2022] | 772 |
|
---|
[2211] | 773 | mr_asprintf(&tmp1, "%s", flag_val['I']);
|
---|
[2022] | 774 | p = tmp1;
|
---|
| 775 | q = tmp1;
|
---|
| 776 |
|
---|
| 777 | /* Cut the flag_val['I'] in parts containing all paths to test them */
|
---|
| 778 | while (p != NULL) {
|
---|
| 779 | q = strchr(p, ' ');
|
---|
| 780 | if (q != NULL) {
|
---|
| 781 | *q = '\0';
|
---|
| 782 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
| 783 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 784 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 785 | }
|
---|
| 786 | p = q+1 ;
|
---|
| 787 | } else {
|
---|
| 788 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
| 789 | log_msg(1, "ERROR ! %s doesn't exist", p);
|
---|
| 790 | fatal_error("ERROR ! You specified a directory to include which doesn't exist");
|
---|
| 791 | }
|
---|
| 792 | p = NULL;
|
---|
| 793 | }
|
---|
| 794 | }
|
---|
| 795 | paranoid_free(tmp1);
|
---|
[2053] | 796 | while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) {
|
---|
[2022] | 797 | switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) {
|
---|
[2007] | 798 | /* It's a dsf but not a whole disk dsf */
|
---|
| 799 | case -2:
|
---|
[2022] | 800 | log_to_screen("Could %s be a partition instead of a whole disk device special file?\n Ignored.", token);
|
---|
[2007] | 801 | break;
|
---|
| 802 | /* Fatal error; exit */
|
---|
| 803 | case 1:
|
---|
| 804 | fatal_error("Error processing -I option");
|
---|
| 805 | /* Everything is OK; process to archive data */
|
---|
| 806 | case 0:
|
---|
[2022] | 807 | log_to_screen("Archiving only the following file systems on %s:\n", token);
|
---|
[2007] | 808 | log_to_screen(" %s\n", mounted_on_dsf);
|
---|
| 809 | strcpy(bkpinfo->include_paths, "/");
|
---|
| 810 | if (strlen(not_mounted_on_dsf)) {
|
---|
| 811 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
|
---|
| 812 | log_to_screen("Not archiving the following file systems:\n");
|
---|
| 813 | log_to_screen(" %s\n", not_mounted_on_dsf);
|
---|
| 814 | strcat(bkpinfo->exclude_paths, not_mounted_on_dsf);
|
---|
| 815 | strcat(bkpinfo->exclude_paths, "");
|
---|
| 816 | }
|
---|
| 817 | break;
|
---|
| 818 | /* A device special file was not passed in. Process it as a path. */
|
---|
| 819 | case -1:
|
---|
[2022] | 820 | strcat(bkpinfo->include_paths, token);
|
---|
| 821 | strcat(bkpinfo->include_paths, " ");
|
---|
[2007] | 822 | break;
|
---|
[542] | 823 | }
|
---|
[2241] | 824 | mr_free(token);
|
---|
[2022] | 825 | }
|
---|
| 826 | log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
|
---|
| 827 | if (bkpinfo->exclude_paths != NULL) {
|
---|
| 828 | log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
|
---|
| 829 | }
|
---|
| 830 | log_msg(4, "Finished with the -I option");
|
---|
[116] | 831 | }
|
---|
[1] | 832 |
|
---|
[116] | 833 | if (g_kernel_version >= 2.6 && !flag_set['d']
|
---|
[1967] | 834 | && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 835 | fatal_error
|
---|
| 836 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
|
---|
[1] | 837 | }
|
---|
| 838 |
|
---|
[116] | 839 |
|
---|
| 840 | if (flag_set['J']) {
|
---|
| 841 | if (flag_set['I']) {
|
---|
| 842 | retval++;
|
---|
| 843 | log_to_screen
|
---|
[541] | 844 | ("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] | 845 | }
|
---|
| 846 | bkpinfo->make_filelist = FALSE;
|
---|
| 847 | strcpy(bkpinfo->include_paths, flag_val['J']);
|
---|
[1] | 848 | }
|
---|
[1967] | 849 |
|
---|
| 850 | if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 851 | if (!flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 852 | && strstr(flag_val['d'], "/dev/")) {
|
---|
| 853 | fatal_error
|
---|
| 854 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
|
---|
| 855 | }
|
---|
| 856 | if (flag_set['r'] && g_kernel_version <= 2.5
|
---|
| 857 | && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 858 | fatal_error
|
---|
| 859 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
|
---|
| 860 | }
|
---|
| 861 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
|
---|
| 862 | log_to_screen
|
---|
[541] | 863 | ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
|
---|
[116] | 864 | }
|
---|
| 865 |
|
---|
| 866 | if (system("which cdrecord > /dev/null 2> /dev/null")
|
---|
| 867 | && system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 868 | fatal_error
|
---|
| 869 | ("Please install dvdrecord/cdrecord and try again.");
|
---|
| 870 | }
|
---|
| 871 | if (flag_set['C']) {
|
---|
| 872 | bkpinfo->cdrw_speed = atoi(flag_val['C']);
|
---|
| 873 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 874 | fatal_error
|
---|
| 875 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 876 | }
|
---|
| 877 | if (!flag_set['L']) {
|
---|
| 878 | log_to_screen
|
---|
[541] | 879 | ("You must use -L with -C. Therefore I am setting it for you.");
|
---|
[116] | 880 | flag_set['L'] = 1;
|
---|
| 881 | flag_val['L'][0] = '\0';
|
---|
| 882 | }
|
---|
| 883 | } else {
|
---|
| 884 | log_msg(3, "flag_val['c'] = %s", flag_val['c']);
|
---|
| 885 | log_msg(3, "flag_val['w'] = %s", flag_val['w']);
|
---|
| 886 | // log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
|
---|
| 887 | if (flag_set['c']) {
|
---|
| 888 | bkpinfo->cdrw_speed = atoi(flag_val['c']);
|
---|
| 889 | } else if (flag_set['w']) {
|
---|
| 890 | bkpinfo->cdrw_speed = atoi(flag_val['w']);
|
---|
| 891 | } else if (flag_set['r']) {
|
---|
| 892 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
|
---|
| 893 | }
|
---|
| 894 |
|
---|
| 895 | if (bkpinfo->cdrw_speed < 1) {
|
---|
| 896 | fatal_error
|
---|
| 897 | ("You specified a silly speed for a CD-R[W] drive");
|
---|
| 898 | }
|
---|
| 899 | }
|
---|
[1] | 900 | }
|
---|
[1967] | 901 |
|
---|
[1969] | 902 | if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 903 | log_it("Hmm! No tape drive specified. Let's see what we can do.");
|
---|
| 904 | if (find_tape_device_and_size(flag_val['d'], tmp)) {
|
---|
| 905 | fatal_error
|
---|
| 906 | ("Tape device not specified. I couldn't find it either.");
|
---|
| 907 | }
|
---|
| 908 | flag_set['d'] = TRUE;
|
---|
[2271] | 909 | mr_asprintf(&tmp1,
|
---|
[541] | 910 | "You didn't specify a tape streamer device. I'm assuming %s",
|
---|
[116] | 911 | flag_val['d']);
|
---|
[2271] | 912 | log_to_screen(tmp1);
|
---|
| 913 | mr_free(tmp1);
|
---|
[116] | 914 | percent = 0;
|
---|
| 915 | }
|
---|
| 916 |
|
---|
[1687] | 917 | if (flag_set['U']) // USB
|
---|
| 918 | {
|
---|
| 919 | if (! flag_set['d']) {
|
---|
| 920 | fatal_error
|
---|
[1967] | 921 | ("You need to specify a device file with -d for bootable USB device usage");
|
---|
[1687] | 922 | }
|
---|
[1967] | 923 | if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
|
---|
[1687] | 924 | fatal_error("You did not specify a size (-s) for your USB device. Aborting");
|
---|
| 925 | }
|
---|
| 926 | }
|
---|
| 927 |
|
---|
[116] | 928 | if (flag_set['r']) // DVD
|
---|
| 929 | {
|
---|
| 930 | if (flag_set['m']) {
|
---|
| 931 | fatal_error
|
---|
| 932 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
|
---|
| 933 | }
|
---|
| 934 | if (!flag_set['d']) {
|
---|
| 935 | if (!find_dvd_device(flag_val['d'], FALSE)) {
|
---|
| 936 | flag_set['d'] = TRUE;
|
---|
[541] | 937 | log_to_screen("I guess DVD drive is at %s", flag_val['d']);
|
---|
[116] | 938 | }
|
---|
| 939 | }
|
---|
| 940 | if (strchr(flag_val['d'], ',')) {
|
---|
| 941 | fatal_error
|
---|
| 942 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 943 | }
|
---|
[1967] | 944 | if (! bkpinfo->restore_data) {
|
---|
| 945 | if (!find_home_of_exe("growisofs")) {
|
---|
| 946 | fatal_error
|
---|
| 947 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 948 | }
|
---|
| 949 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 950 | fatal_error
|
---|
| 951 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
|
---|
| 952 | }
|
---|
| 953 | if (!flag_set['s']) {
|
---|
| 954 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
|
---|
| 955 | strcat(flag_val['s'], "m");
|
---|
| 956 | log_to_screen
|
---|
| 957 | ("You did not specify a size (-s) for DVD. I'm guessing %s.",
|
---|
| 958 | flag_val['s']);
|
---|
| 959 | flag_set['s'] = 1;
|
---|
| 960 | }
|
---|
[116] | 961 | }
|
---|
[1] | 962 | /*
|
---|
| 963 | if (flag_set['Z']) {
|
---|
| 964 | bkpinfo->blank_dvd_first = TRUE;
|
---|
| 965 | }
|
---|
| 966 | */
|
---|
[116] | 967 | }
|
---|
[1] | 968 |
|
---|
[116] | 969 | if (flag_set['t'] || flag_set['u']) { /* tape size */
|
---|
| 970 | if (strchr(flag_val['d'], ',')) {
|
---|
| 971 | fatal_error
|
---|
| 972 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
|
---|
| 973 | }
|
---|
[1967] | 974 | if ((flag_set['O']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 975 | if (flag_set['s']) {
|
---|
| 976 | if (flag_set['t']) {
|
---|
| 977 | fatal_error
|
---|
| 978 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
|
---|
| 979 | }
|
---|
[1645] | 980 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 981 | fatal_error("Bad -s switch");
|
---|
| 982 | }
|
---|
| 983 | } else if (flag_set['u'] || flag_set['t']) {
|
---|
| 984 | for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
|
---|
| 985 | bkpinfo->media_size[i] = 0;
|
---|
| 986 | }
|
---|
| 987 | } else {
|
---|
| 988 | retval++;
|
---|
| 989 | log_to_screen("Tape size not specified.\n");
|
---|
| 990 | }
|
---|
| 991 | }
|
---|
[1967] | 992 | } else if (! bkpinfo->restore_data) { /* CD|USB size */
|
---|
[116] | 993 | if (flag_set['s']) {
|
---|
[1645] | 994 | if (process_the_s_switch(flag_val['s'])) {
|
---|
[116] | 995 | fatal_error("Bad -s switch");
|
---|
| 996 | }
|
---|
| 997 | }
|
---|
| 998 | if (flag_set['w']) {
|
---|
| 999 | bkpinfo->wipe_media_first = TRUE;
|
---|
| 1000 | } /* CD-RW */
|
---|
[1] | 1001 | }
|
---|
[1967] | 1002 |
|
---|
[116] | 1003 | if (flag_set['n']) {
|
---|
| 1004 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
|
---|
| 1005 | if (!flag_set['d']) {
|
---|
| 1006 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
|
---|
| 1007 | }
|
---|
[2224] | 1008 | /* test if we specified a user for the NFS dialog */
|
---|
| 1009 | p = strchr(bkpinfo->nfs_mount, '@');
|
---|
| 1010 | if (p != NULL) {
|
---|
| 1011 | /* User found. Store the 2 values */
|
---|
| 1012 | p++;
|
---|
| 1013 | /* new NFS mount */
|
---|
| 1014 | strcpy(tmp,p);
|
---|
| 1015 | p--;
|
---|
| 1016 | *p = '\0';
|
---|
[2229] | 1017 | mr_asprintf(&q,"%s",bkpinfo->nfs_mount);
|
---|
[2226] | 1018 | bkpinfo->nfs_user = q;
|
---|
[2224] | 1019 | strcpy(bkpinfo->nfs_mount,tmp);
|
---|
| 1020 | }
|
---|
[2271] | 1021 | mr_asprintf(&tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3",
|
---|
[116] | 1022 | bkpinfo->nfs_mount);
|
---|
| 1023 | strncpy(bkpinfo->isodir,
|
---|
[2271] | 1024 | call_program_and_get_last_line_of_output(tmp1),
|
---|
[116] | 1025 | MAX_STR_LEN / 4);
|
---|
[2271] | 1026 | mr_free(tmp1);
|
---|
| 1027 |
|
---|
[116] | 1028 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
[2223] | 1029 | log_to_screen("NFS share is not mounted. Trying to mount it for you.\n");
|
---|
[2271] | 1030 | mr_asprintf(&tmp1, "mount %s", bkpinfo->nfs_mount);
|
---|
| 1031 | i = system(tmp1);
|
---|
| 1032 | mr_free(tmp1);
|
---|
| 1033 | if (i) {
|
---|
[2223] | 1034 | log_to_screen("Unable to mount NFS share %s. Please mount manually.\n", bkpinfo->nfs_mount);
|
---|
| 1035 | retval++;
|
---|
| 1036 | } else {
|
---|
[2271] | 1037 | mr_asprintf(&tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->nfs_mount);
|
---|
[2223] | 1038 | strncpy(bkpinfo->isodir,
|
---|
[2271] | 1039 | call_program_and_get_last_line_of_output(tmp1),
|
---|
[2223] | 1040 | MAX_STR_LEN / 4);
|
---|
[2271] | 1041 | mr_free(tmp1);
|
---|
| 1042 |
|
---|
[2223] | 1043 | if (strlen(bkpinfo->isodir) < 3) {
|
---|
| 1044 | retval++;
|
---|
| 1045 | log_to_screen("NFS share %s is strangely not mounted. Please mount manually...\n", bkpinfo->nfs_mount);
|
---|
| 1046 | }
|
---|
| 1047 | }
|
---|
[116] | 1048 | }
|
---|
| 1049 | log_msg(3, "mount = %s", bkpinfo->nfs_mount);
|
---|
| 1050 | log_msg(3, "isodir= %s", bkpinfo->isodir);
|
---|
[1] | 1051 | }
|
---|
[1967] | 1052 |
|
---|
[116] | 1053 | if (flag_set['c']) {
|
---|
| 1054 | bkpinfo->backup_media_type = cdr;
|
---|
[1] | 1055 | }
|
---|
[116] | 1056 | if (flag_set['C']) {
|
---|
| 1057 | bkpinfo->backup_media_type = cdstream;
|
---|
[1] | 1058 | }
|
---|
[116] | 1059 | if (flag_set['i']) {
|
---|
| 1060 | bkpinfo->backup_media_type = iso;
|
---|
| 1061 | }
|
---|
| 1062 | if (flag_set['n']) {
|
---|
| 1063 | bkpinfo->backup_media_type = nfs;
|
---|
[1848] | 1064 | /* Never try to eject a NFS device */
|
---|
| 1065 | bkpinfo->please_dont_eject = TRUE;
|
---|
[116] | 1066 | }
|
---|
| 1067 | if (flag_set['r']) {
|
---|
| 1068 | bkpinfo->backup_media_type = dvd;
|
---|
| 1069 | }
|
---|
| 1070 | if (flag_set['t']) {
|
---|
| 1071 | bkpinfo->backup_media_type = tape;
|
---|
| 1072 | }
|
---|
| 1073 | if (flag_set['u']) {
|
---|
| 1074 | bkpinfo->backup_media_type = udev;
|
---|
| 1075 | }
|
---|
| 1076 | if (flag_set['w']) {
|
---|
| 1077 | bkpinfo->backup_media_type = cdrw;
|
---|
| 1078 | }
|
---|
[1687] | 1079 | if (flag_set['U']) {
|
---|
| 1080 | bkpinfo->backup_media_type = usb;
|
---|
[1745] | 1081 | /* Never try to eject a USB device */
|
---|
[1746] | 1082 | bkpinfo->please_dont_eject = TRUE;
|
---|
[1687] | 1083 | }
|
---|
[948] | 1084 | if (flag_set['z']) {
|
---|
| 1085 | if (find_home_of_exe("getfattr")) {
|
---|
[2211] | 1086 | mr_asprintf(&g_getfattr,"getfattr");
|
---|
[948] | 1087 | }
|
---|
| 1088 | if (find_home_of_exe("getfacl")) {
|
---|
[2211] | 1089 | mr_asprintf(&g_getfacl,"getfacl");
|
---|
[948] | 1090 | }
|
---|
| 1091 | }
|
---|
[1] | 1092 |
|
---|
[805] | 1093 | /* optional, popular */
|
---|
[116] | 1094 | if (flag_set['g']) {
|
---|
| 1095 | g_text_mode = FALSE;
|
---|
| 1096 | }
|
---|
[805] | 1097 |
|
---|
[116] | 1098 | if (flag_set['E']) {
|
---|
[2022] | 1099 | if (bkpinfo->exclude_paths[0] == '-') {
|
---|
| 1100 | retval++;
|
---|
| 1101 | log_to_screen("Please supply a sensible value with '-E'\n");
|
---|
| 1102 | }
|
---|
[116] | 1103 | if (bkpinfo->exclude_paths[0]) {
|
---|
| 1104 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 1105 | }
|
---|
[2211] | 1106 | mr_asprintf(&tmp1, "%s", flag_val['E']);
|
---|
[542] | 1107 |
|
---|
[2022] | 1108 | p = tmp1;
|
---|
| 1109 | q = tmp1;
|
---|
| 1110 |
|
---|
| 1111 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
| 1112 | while (p != NULL) {
|
---|
| 1113 | q = strchr(p, ' ');
|
---|
| 1114 | if (q != NULL) {
|
---|
| 1115 | *q = '\0';
|
---|
| 1116 | /* Fix bug 14 where ending / cause a problem later
|
---|
| 1117 | * so handled here for the moment */
|
---|
| 1118 | q--;
|
---|
| 1119 | if (*q == '/') {
|
---|
| 1120 | *q = '\0';
|
---|
| 1121 | }
|
---|
| 1122 | q++;
|
---|
| 1123 | /* End of bug fix */
|
---|
| 1124 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
| 1125 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 1126 | }
|
---|
| 1127 | p = q+1 ;
|
---|
| 1128 | } else {
|
---|
| 1129 | if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
|
---|
| 1130 | log_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
| 1131 | }
|
---|
| 1132 | p = NULL;
|
---|
| 1133 | }
|
---|
| 1134 | }
|
---|
[2271] | 1135 | mr_free(tmp1);
|
---|
[2022] | 1136 | lastpos = 0;
|
---|
[2053] | 1137 | while ((token = mr_strtok(flag_val['E'], token_chars, &lastpos)) != NULL) {
|
---|
[2022] | 1138 | switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) {
|
---|
[2007] | 1139 | case 1:
|
---|
[2036] | 1140 | log_msg(1, "WARNING ! a path doesn't exist in -E option");
|
---|
| 1141 | break;
|
---|
[2007] | 1142 | /* Everything is OK; proceed to archive data */
|
---|
| 1143 | case 0:
|
---|
| 1144 | if (strlen(mounted_on_dsf)) {
|
---|
[2022] | 1145 | log_to_screen("Excluding the following file systems on %s:\n", token);
|
---|
[2011] | 1146 | log_to_screen(" %s\n", mounted_on_dsf);
|
---|
[2007] | 1147 | log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
|
---|
| 1148 | strcat(bkpinfo->exclude_paths, mounted_on_dsf);
|
---|
[2022] | 1149 | strcat(bkpinfo->exclude_paths, " ");
|
---|
[805] | 1150 | }
|
---|
[2007] | 1151 | break;
|
---|
| 1152 | /* It's a dsf but not a whole disk dsf */
|
---|
| 1153 | case -2:
|
---|
[2022] | 1154 | log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
|
---|
[2007] | 1155 | break;
|
---|
| 1156 | /* A device special file was not passed in. Process it as a path. */
|
---|
| 1157 | case -1:
|
---|
[2036] | 1158 | strcat(bkpinfo->exclude_paths, token);
|
---|
| 1159 | strcat(bkpinfo->exclude_paths, " ");
|
---|
| 1160 | break;
|
---|
[542] | 1161 | }
|
---|
[2241] | 1162 | mr_free(token);
|
---|
[2022] | 1163 | }
|
---|
| 1164 | log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
|
---|
| 1165 | log_msg(4, "Finished with the -E option");
|
---|
[116] | 1166 | }
|
---|
[1967] | 1167 |
|
---|
[116] | 1168 | if (flag_set['e']) {
|
---|
| 1169 | bkpinfo->please_dont_eject = TRUE;
|
---|
| 1170 | }
|
---|
[1967] | 1171 |
|
---|
| 1172 | if ((flag_set['N']) && (! bkpinfo->restore_data)) // exclude NFS mounts & devices
|
---|
[116] | 1173 | {
|
---|
[1] | 1174 | // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
|
---|
[2224] | 1175 | mr_asprintf(&psz, "%s", list_of_NFS_mounts_only());
|
---|
[116] | 1176 | if (bkpinfo->exclude_paths[0]) {
|
---|
[1540] | 1177 | strncat(bkpinfo->exclude_paths, " ", 4*MAX_STR_LEN);
|
---|
[116] | 1178 | }
|
---|
[1540] | 1179 | strncat(bkpinfo->exclude_paths, psz, 4*MAX_STR_LEN);
|
---|
[2214] | 1180 | mr_free(psz);
|
---|
| 1181 |
|
---|
[116] | 1182 | log_msg(3, "-N means we're now excluding %s",
|
---|
| 1183 | bkpinfo->exclude_paths);
|
---|
| 1184 | }
|
---|
[1967] | 1185 |
|
---|
[1540] | 1186 | if (strlen(bkpinfo->exclude_paths) >= 4*MAX_STR_LEN) {
|
---|
[116] | 1187 | fatal_error
|
---|
[1540] | 1188 | ("Your '-E' parameter is too long. Increase MAX_STR_LEN");
|
---|
[116] | 1189 | }
|
---|
[1967] | 1190 |
|
---|
[116] | 1191 | if (flag_set['b']) {
|
---|
[2214] | 1192 | mr_asprintf(&psz, flag_val['b']);
|
---|
[116] | 1193 | log_msg(1, "psz = '%s'", psz);
|
---|
| 1194 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
| 1195 | psz[strlen(psz) - 1] = '\0';
|
---|
| 1196 | itbs = atol(psz) * 1024L;
|
---|
| 1197 | } else {
|
---|
| 1198 | itbs = atol(psz);
|
---|
| 1199 | }
|
---|
[2214] | 1200 | mr_free(psz);
|
---|
[116] | 1201 | log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
| 1202 | log_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
| 1203 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
| 1204 | fatal_error
|
---|
| 1205 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
| 1206 | }
|
---|
| 1207 | bkpinfo->internal_tape_block_size = itbs;
|
---|
| 1208 | }
|
---|
[1967] | 1209 |
|
---|
| 1210 | if ((flag_set['D']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1211 | bkpinfo->differential = 1;
|
---|
[1] | 1212 | // bkpinfo->differential = atoi (flag_val['D']);
|
---|
[116] | 1213 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
|
---|
| 1214 | fatal_error
|
---|
| 1215 | ("The D option should be between 1 and 9 inclusive");
|
---|
| 1216 | }
|
---|
[1] | 1217 | }
|
---|
[1967] | 1218 |
|
---|
[116] | 1219 | if (flag_set['x']) {
|
---|
| 1220 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
[1967] | 1221 | if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
|
---|
[296] | 1222 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
[116] | 1223 | }
|
---|
[1] | 1224 | }
|
---|
[1967] | 1225 |
|
---|
[116] | 1226 | if (flag_set['m']) {
|
---|
| 1227 | bkpinfo->manual_cd_tray = TRUE;
|
---|
[1] | 1228 | }
|
---|
[1967] | 1229 |
|
---|
| 1230 | if ((flag_set['k']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1231 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
|
---|
| 1232 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
| 1233 | strcpy(bkpinfo->kernel_path, "FAILSAFE");
|
---|
| 1234 | }
|
---|
| 1235 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
| 1236 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
| 1237 | retval++;
|
---|
[2271] | 1238 | mr_asprintf(&tmp1,
|
---|
[541] | 1239 | "You specified kernel '%s', which does not exist\n",
|
---|
[116] | 1240 | bkpinfo->kernel_path);
|
---|
[2271] | 1241 | log_to_screen(tmp1);
|
---|
| 1242 | mr_free(tmp1);
|
---|
[116] | 1243 | }
|
---|
| 1244 | }
|
---|
[1967] | 1245 |
|
---|
[116] | 1246 | if (flag_set['p']) {
|
---|
| 1247 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
|
---|
[1966] | 1248 | log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
|
---|
[116] | 1249 | }
|
---|
[1] | 1250 |
|
---|
[116] | 1251 | if (flag_set['d']) { /* backup directory (if ISO/NFS) */
|
---|
| 1252 | if (flag_set['i']) {
|
---|
| 1253 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
[2271] | 1254 | mr_asprintf(&tmp1, "ls -l %s", bkpinfo->isodir);
|
---|
| 1255 | if (run_program_and_log_output(tmp1, 2)) {
|
---|
| 1256 | mr_free(tmp1);
|
---|
[116] | 1257 | fatal_error
|
---|
| 1258 | ("output folder does not exist - please create it");
|
---|
| 1259 | }
|
---|
[2271] | 1260 | mr_free(tmp1);
|
---|
[116] | 1261 | } else if (flag_set['n']) {
|
---|
| 1262 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
| 1263 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
| 1264 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
|
---|
| 1265 | }
|
---|
[1] | 1266 | }
|
---|
[116] | 1267 |
|
---|
[1967] | 1268 | if ((flag_set['n']) && (! bkpinfo->restore_data)) {
|
---|
[2211] | 1269 | mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
|
---|
[2224] | 1270 | if (bkpinfo->nfs_user) {
|
---|
[2271] | 1271 | mr_asprintf(&tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->nfs_user, tmp1);
|
---|
[2224] | 1272 | } else {
|
---|
[2271] | 1273 | mr_asprintf(&tmp2, "echo hi > %s", tmp1);
|
---|
[2224] | 1274 | }
|
---|
[2271] | 1275 | i = run_program_and_log_output(tmp2, 2);
|
---|
| 1276 | mr_free(tmp2);
|
---|
| 1277 |
|
---|
| 1278 | if (i) {
|
---|
[116] | 1279 | retval++;
|
---|
[2271] | 1280 | mr_asprintf(&tmp2,
|
---|
[541] | 1281 | "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
|
---|
[116] | 1282 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
[2271] | 1283 | log_to_screen(tmp2);
|
---|
| 1284 | mr_free(tmp2);
|
---|
[116] | 1285 | }
|
---|
[1767] | 1286 | unlink(tmp1);
|
---|
[2271] | 1287 | mr_free(tmp1);
|
---|
[1] | 1288 | }
|
---|
| 1289 |
|
---|
[116] | 1290 | if (!flag_set['d']
|
---|
| 1291 | && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
|
---|
| 1292 | if (g_kernel_version >= 2.6) {
|
---|
| 1293 | if (popup_and_get_string
|
---|
[541] | 1294 | ("Device", "Please specify the device",
|
---|
[116] | 1295 | bkpinfo->media_device, MAX_STR_LEN / 4)) {
|
---|
| 1296 | retval++;
|
---|
[541] | 1297 | log_to_screen("User opted to cancel.");
|
---|
[116] | 1298 | }
|
---|
| 1299 | } else if (find_cdrw_device(bkpinfo->media_device)) {
|
---|
| 1300 | retval++;
|
---|
| 1301 | log_to_screen
|
---|
[541] | 1302 | ("Tried and failed to find CD-R[W] drive automatically.\n");
|
---|
[116] | 1303 | } else {
|
---|
| 1304 | flag_set['d'] = TRUE;
|
---|
| 1305 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
| 1306 | }
|
---|
[1] | 1307 | }
|
---|
| 1308 |
|
---|
[1967] | 1309 | if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1310 | retval++;
|
---|
[541] | 1311 | log_to_screen("Please specify the backup device/directory.\n");
|
---|
[116] | 1312 | fatal_error
|
---|
| 1313 | ("You didn't use -d to specify the backup device/directory.");
|
---|
[1] | 1314 | }
|
---|
[1967] | 1315 |
|
---|
[116] | 1316 | for (i = '0'; i <= '9'; i++) {
|
---|
| 1317 | if (flag_set[i]) {
|
---|
| 1318 | bkpinfo->compression_level = i - '0';
|
---|
| 1319 | } /* not '\0' but '0' */
|
---|
[1] | 1320 | }
|
---|
[1967] | 1321 |
|
---|
[116] | 1322 | if (flag_set['S']) {
|
---|
| 1323 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
| 1324 | random() % 32768);
|
---|
[1] | 1325 | }
|
---|
[1967] | 1326 |
|
---|
[116] | 1327 | if (flag_set['T']) {
|
---|
[1655] | 1328 | setup_tmpdir(flag_val['T']);
|
---|
[2271] | 1329 | mr_asprintf(&tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir);
|
---|
| 1330 | i = run_program_and_log_output(tmp1, 1);
|
---|
| 1331 | mr_free(tmp1);
|
---|
| 1332 |
|
---|
| 1333 | if (i) {
|
---|
[116] | 1334 | retval++;
|
---|
[2271] | 1335 | log_to_screen("Please specify a tempdir which I can write to. :)");
|
---|
[116] | 1336 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 1337 | }
|
---|
[2271] | 1338 | mr_asprintf(&tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
|
---|
| 1339 | i = run_program_and_log_output(tmp1, 1);
|
---|
| 1340 | mr_free(tmp1);
|
---|
| 1341 |
|
---|
| 1342 | if (i) {
|
---|
[116] | 1343 | retval++;
|
---|
[2271] | 1344 | log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
|
---|
[116] | 1345 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
| 1346 | }
|
---|
[1] | 1347 | }
|
---|
[1967] | 1348 |
|
---|
| 1349 | if ((flag_set['A']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1350 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
| 1351 | }
|
---|
[1967] | 1352 |
|
---|
| 1353 | if ((flag_set['B']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1354 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
| 1355 | }
|
---|
[1967] | 1356 |
|
---|
| 1357 | if ((flag_set['H']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1358 | g_cd_recovery = TRUE;
|
---|
| 1359 | }
|
---|
[1967] | 1360 |
|
---|
| 1361 | if ((flag_set['l']) && (! bkpinfo->restore_data)) {
|
---|
[1] | 1362 | #ifdef __FreeBSD__
|
---|
| 1363 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
| 1364 | #else
|
---|
| 1365 | # ifdef __IA64__
|
---|
| 1366 | # define BOOT_LOADER_CHARS "GER"
|
---|
| 1367 | # else
|
---|
| 1368 | # define BOOT_LOADER_CHARS "GLR"
|
---|
| 1369 | # endif
|
---|
| 1370 | #endif
|
---|
[116] | 1371 | if (!strchr
|
---|
| 1372 | (BOOT_LOADER_CHARS,
|
---|
| 1373 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
| 1374 | log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
|
---|
| 1375 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
| 1376 | fatal_error
|
---|
| 1377 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
| 1378 | }
|
---|
[1] | 1379 | #undef BOOT_LOADER_CHARS
|
---|
| 1380 | }
|
---|
[1967] | 1381 |
|
---|
[116] | 1382 | if (flag_set['f']) {
|
---|
| 1383 | strncpy(bkpinfo->boot_device,
|
---|
| 1384 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
| 1385 | ['f']),
|
---|
| 1386 | MAX_STR_LEN / 4);
|
---|
| 1387 | }
|
---|
[1967] | 1388 |
|
---|
| 1389 | if ((flag_set['P']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1390 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
| 1391 | }
|
---|
[1967] | 1392 |
|
---|
[116] | 1393 | if (flag_set['Q']) {
|
---|
| 1394 | i = which_boot_loader(tmp);
|
---|
| 1395 | log_msg(3, "boot loader is %c, residing at %s", i, tmp);
|
---|
[541] | 1396 | printf("boot loader is %c, residing at %s\n", i, tmp);
|
---|
[116] | 1397 | finish(0);
|
---|
| 1398 | }
|
---|
[1967] | 1399 |
|
---|
| 1400 | if ((flag_set['L']) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1401 | bkpinfo->use_lzo = TRUE;
|
---|
[1737] | 1402 | if (run_program_and_log_output("which lzop", 2)) {
|
---|
[116] | 1403 | retval++;
|
---|
| 1404 | log_to_screen
|
---|
[541] | 1405 | ("Please install LZOP. You can't use '-L' until you do.\n");
|
---|
[116] | 1406 | }
|
---|
| 1407 | }
|
---|
[1] | 1408 |
|
---|
[1967] | 1409 | if ((flag_set['G']) && (! bkpinfo->restore_data)) {
|
---|
[998] | 1410 | bkpinfo->use_gzip = TRUE;
|
---|
[1737] | 1411 | if (run_program_and_log_output("which gzip", 2)) {
|
---|
[998] | 1412 | retval++;
|
---|
| 1413 | log_to_screen
|
---|
| 1414 | ("Please install gzip. You can't use '-G' until you do.\n");
|
---|
| 1415 | }
|
---|
| 1416 | }
|
---|
| 1417 |
|
---|
[1948] | 1418 | bkpinfo->use_obdr = FALSE;
|
---|
| 1419 | if (flag_set['o']) {
|
---|
[1967] | 1420 | if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
|
---|
[1948] | 1421 | log_to_screen("OBDR support is only available for tapes. Use the -t option");
|
---|
| 1422 | fatal_error("Aborting");
|
---|
| 1423 | }
|
---|
| 1424 | bkpinfo->use_obdr = TRUE;
|
---|
| 1425 | }
|
---|
[1967] | 1426 |
|
---|
[1948] | 1427 | #ifndef __FreeBSD__
|
---|
[1967] | 1428 | if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1429 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
| 1430 | log_to_screen
|
---|
[1948] | 1431 | ("Your kernel appears not to support vfat filesystems. I am therefore");
|
---|
| 1432 | log_to_screen
|
---|
| 1433 | ("using LILO instead of SYSLINUX as the media boot loader.");
|
---|
[116] | 1434 | }
|
---|
[1967] | 1435 | if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
|
---|
[116] | 1436 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 1437 | #ifdef __IA32__
|
---|
[1948] | 1438 | log_to_screen
|
---|
| 1439 | ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
|
---|
| 1440 | log_to_screen
|
---|
| 1441 | ("your boot loader. I shall therefore use LILO instead.");
|
---|
[1] | 1442 | #endif
|
---|
| 1443 | #ifdef __IA64__
|
---|
[1948] | 1444 | log_to_screen
|
---|
| 1445 | ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
|
---|
| 1446 | log_to_screen("environment correctly. Please install it.");
|
---|
| 1447 | fatal_error("Aborting");
|
---|
[1] | 1448 | #endif
|
---|
[1948] | 1449 | }
|
---|
[1] | 1450 | #ifdef __IA64__
|
---|
[1948] | 1451 | /* We force ELILO usage on IA64 */
|
---|
| 1452 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[2085] | 1453 | #endif
|
---|
| 1454 | #endif
|
---|
[1] | 1455 |
|
---|
[1967] | 1456 | if (! bkpinfo->restore_data) {
|
---|
[1917] | 1457 | i = flag_set['O'] + flag_set['V'];
|
---|
| 1458 | if (i == 0) {
|
---|
| 1459 | retval++;
|
---|
| 1460 | log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
|
---|
| 1461 | }
|
---|
[116] | 1462 | }
|
---|
[1] | 1463 |
|
---|
[1967] | 1464 | if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
|
---|
| 1465 | fatal_error
|
---|
| 1466 | ("The -Z switch is only valid in restore mode");
|
---|
| 1467 | }
|
---|
| 1468 |
|
---|
| 1469 | if (flag_set['Z']) {
|
---|
| 1470 | if (! strcmp(flag_val['Z'], "nuke")) {
|
---|
| 1471 | bkpinfo->restore_mode = nuke;
|
---|
| 1472 | } else if (! strcmp(flag_val['Z'], "interactive")) {
|
---|
| 1473 | bkpinfo->restore_mode = interactive;
|
---|
| 1474 | } else if (! strcmp(flag_val['Z'], "compare")) {
|
---|
| 1475 | bkpinfo->restore_mode = compare;
|
---|
| 1476 | } else if (! strcmp(flag_val['Z'], "mbr")) {
|
---|
| 1477 | bkpinfo->restore_mode = mbr;
|
---|
| 1478 | } else if (! strcmp(flag_val['Z'], "iso")) {
|
---|
| 1479 | bkpinfo->restore_mode = isoonly;
|
---|
| 1480 | } else if (! strcmp(flag_val['Z'], "isonuke")) {
|
---|
| 1481 | bkpinfo->restore_mode = isonuke;
|
---|
| 1482 | } else {
|
---|
| 1483 | bkpinfo->restore_mode = interactive;
|
---|
| 1484 | }
|
---|
| 1485 | }
|
---|
| 1486 |
|
---|
[1] | 1487 | /* and finally... */
|
---|
| 1488 |
|
---|
[116] | 1489 | paranoid_free(tmp);
|
---|
| 1490 | return (retval);
|
---|
[1] | 1491 | }
|
---|
| 1492 |
|
---|
| 1493 |
|
---|
| 1494 |
|
---|
| 1495 | /**
|
---|
| 1496 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
| 1497 | * @p flag_set and @p flag_val.
|
---|
| 1498 | * @param argc The argument count (@p argc passed to main()).
|
---|
| 1499 | * @param argv The argument vector (@p argv passed to main()).
|
---|
| 1500 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
| 1501 | * has an argument then set flag_val[switch] to that argument.
|
---|
| 1502 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
| 1503 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
| 1504 | * @return The number of problems with the command line (0 for success).
|
---|
| 1505 | */
|
---|
| 1506 | int
|
---|
[116] | 1507 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
| 1508 | char flag_val[128][MAX_STR_LEN],
|
---|
| 1509 | bool flag_set[128])
|
---|
[1] | 1510 | {
|
---|
[116] | 1511 | /*@ ints ** */
|
---|
| 1512 | int opt = 0;
|
---|
[2202] | 1513 | char *tmp = NULL;
|
---|
[116] | 1514 | int i = 0;
|
---|
| 1515 | int len;
|
---|
[1] | 1516 |
|
---|
[116] | 1517 | /*@ bools *** */
|
---|
| 1518 | bool bad_switches = FALSE;
|
---|
[1] | 1519 |
|
---|
[116] | 1520 | assert(flag_val != NULL);
|
---|
| 1521 | assert(flag_set != NULL);
|
---|
[1] | 1522 |
|
---|
[116] | 1523 | for (i = 0; i < 128; i++) {
|
---|
| 1524 | flag_val[i][0] = '\0';
|
---|
| 1525 | flag_set[i] = FALSE;
|
---|
[1] | 1526 | }
|
---|
[116] | 1527 | while ((opt =
|
---|
[1917] | 1528 | getopt(argc, argv, MONDO_OPTIONS))
|
---|
[116] | 1529 | != -1) {
|
---|
| 1530 | if (opt == '?') {
|
---|
| 1531 | bad_switches = TRUE;
|
---|
| 1532 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
| 1533 | } else {
|
---|
[2229] | 1534 | if (flag_set[opt]) {
|
---|
[116] | 1535 | bad_switches = TRUE;
|
---|
[2211] | 1536 | mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
|
---|
[2229] | 1537 | flag_val[opt]);
|
---|
[116] | 1538 | log_to_screen(tmp);
|
---|
[2202] | 1539 | paranoid_free(tmp);
|
---|
[116] | 1540 | } else {
|
---|
| 1541 | flag_set[opt] = TRUE;
|
---|
| 1542 | if (optarg) {
|
---|
| 1543 | len = strlen(optarg);
|
---|
| 1544 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
| 1545 | optarg[--len] = '\0';
|
---|
| 1546 | log_to_screen
|
---|
[541] | 1547 | ("Warning - param '%s' should not have trailing slash!",
|
---|
[116] | 1548 | optarg);
|
---|
| 1549 | }
|
---|
| 1550 | if (opt == 'd') {
|
---|
| 1551 | if (strchr(flag_val[opt], '/')
|
---|
| 1552 | && flag_val[opt][0] != '/') {
|
---|
[2211] | 1553 | mr_asprintf(&tmp,
|
---|
[541] | 1554 | "-%c flag --- must be absolute path --- '%s' isn't absolute",
|
---|
[116] | 1555 | opt, flag_val[opt]);
|
---|
| 1556 | log_to_screen(tmp);
|
---|
[2202] | 1557 | paranoid_free(tmp);
|
---|
[116] | 1558 | bad_switches = TRUE;
|
---|
| 1559 | }
|
---|
| 1560 | }
|
---|
| 1561 | strcpy(flag_val[opt], optarg);
|
---|
| 1562 | }
|
---|
| 1563 | }
|
---|
[1] | 1564 | }
|
---|
| 1565 | }
|
---|
[116] | 1566 | for (i = optind; i < argc; i++) {
|
---|
| 1567 | bad_switches = TRUE;
|
---|
[2211] | 1568 | mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
|
---|
[116] | 1569 | log_to_screen(tmp);
|
---|
[2202] | 1570 | paranoid_free(tmp);
|
---|
[116] | 1571 | }
|
---|
| 1572 | return (bad_switches);
|
---|
[1] | 1573 | }
|
---|
| 1574 |
|
---|
| 1575 |
|
---|
| 1576 |
|
---|
| 1577 |
|
---|
| 1578 | /**
|
---|
| 1579 | * Print a not-so-helpful help message and exit.
|
---|
| 1580 | */
|
---|
[116] | 1581 | void help_screen()
|
---|
[1] | 1582 | {
|
---|
[1967] | 1583 | log_msg(1, "Type 'man mondoarchive' for more information\n");
|
---|
[116] | 1584 | exit(1);
|
---|
[1] | 1585 | }
|
---|
| 1586 |
|
---|
| 1587 |
|
---|
| 1588 | /**
|
---|
| 1589 | * Terminate Mondo in response to a signal.
|
---|
| 1590 | * @param sig The signal number received.
|
---|
| 1591 | */
|
---|
| 1592 | void terminate_daemon(int sig)
|
---|
| 1593 | {
|
---|
[2211] | 1594 | char *tmp = NULL;
|
---|
| 1595 | char *tmp2 = NULL;
|
---|
[1] | 1596 |
|
---|
[116] | 1597 | switch (sig) {
|
---|
[1] | 1598 | case SIGINT:
|
---|
[2211] | 1599 | mr_asprintf(&tmp, "SIGINT");
|
---|
| 1600 | mr_asprintf(&tmp2, "You interrupted me :-)");
|
---|
[1] | 1601 | break;
|
---|
| 1602 | case SIGKILL:
|
---|
[2211] | 1603 | mr_asprintf(&tmp, "SIGKILL");
|
---|
| 1604 | mr_asprintf(&tmp2,
|
---|
[541] | 1605 | "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
|
---|
[1] | 1606 | break;
|
---|
| 1607 | case SIGTERM:
|
---|
[2211] | 1608 | mr_asprintf(&tmp, "SIGTERM");
|
---|
| 1609 | mr_asprintf(&tmp2, "Got terminate signal");
|
---|
[1] | 1610 | break;
|
---|
| 1611 | case SIGHUP:
|
---|
[2211] | 1612 | mr_asprintf(&tmp, "SIGHUP");
|
---|
| 1613 | mr_asprintf(&tmp2, "Hangup on line");
|
---|
[1] | 1614 | break;
|
---|
| 1615 | case SIGSEGV:
|
---|
[2211] | 1616 | mr_asprintf(&tmp, "SIGSEGV");
|
---|
| 1617 | mr_asprintf(&tmp2,
|
---|
[541] | 1618 | "Internal programming error. Please send a backtrace as well as your log.");
|
---|
[1] | 1619 | break;
|
---|
| 1620 | case SIGPIPE:
|
---|
[2211] | 1621 | mr_asprintf(&tmp, "SIGPIPE");
|
---|
| 1622 | mr_asprintf(&tmp2, "Pipe was broken");
|
---|
[1] | 1623 | break;
|
---|
[116] | 1624 | case SIGABRT:
|
---|
[2211] | 1625 | mr_asprintf(&tmp, "SIGABRT");
|
---|
| 1626 | mr_asprintf(&tmp2,
|
---|
[541] | 1627 | "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
|
---|
[116] | 1628 | break;
|
---|
[1] | 1629 | default:
|
---|
[2211] | 1630 | mr_asprintf(&tmp, "(Unknown)");
|
---|
| 1631 | mr_asprintf(&tmp2, "(Unknown)");
|
---|
[116] | 1632 | }
|
---|
[1] | 1633 |
|
---|
[2211] | 1634 | mr_strcat(tmp, " signal received from OS");
|
---|
[116] | 1635 | log_to_screen(tmp);
|
---|
[2211] | 1636 | paranoid_free(tmp);
|
---|
| 1637 |
|
---|
[116] | 1638 | log_to_screen(tmp2);
|
---|
[2211] | 1639 | paranoid_free(tmp2);
|
---|
[116] | 1640 | if (sig == SIGABRT) {
|
---|
| 1641 | sleep(10);
|
---|
| 1642 | }
|
---|
| 1643 | kill_buffer();
|
---|
[1967] | 1644 |
|
---|
| 1645 | free_MR_global_filenames();
|
---|
| 1646 |
|
---|
[116] | 1647 | fatal_error
|
---|
[1967] | 1648 | ("MondoRescue is terminating in response to a signal from the OS");
|
---|
[116] | 1649 | finish(254); // just in case
|
---|
[1] | 1650 | }
|
---|
| 1651 |
|
---|
| 1652 |
|
---|
| 1653 |
|
---|
| 1654 |
|
---|
| 1655 | /**
|
---|
| 1656 | * Turn signal-trapping on or off.
|
---|
| 1657 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
| 1658 | */
|
---|
| 1659 | void set_signals(int on)
|
---|
| 1660 | {
|
---|
[116] | 1661 | int signals[] =
|
---|
| 1662 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
| 1663 | int i;
|
---|
| 1664 |
|
---|
| 1665 | signal(SIGPIPE, sigpipe_occurred);
|
---|
| 1666 | for (i = 0; signals[i]; i++) {
|
---|
| 1667 | if (on) {
|
---|
| 1668 | signal(signals[i], terminate_daemon);
|
---|
| 1669 | } else {
|
---|
| 1670 | signal(signals[i], termination_in_progress);
|
---|
| 1671 | }
|
---|
| 1672 | }
|
---|
[1] | 1673 | }
|
---|
| 1674 |
|
---|
| 1675 |
|
---|
| 1676 |
|
---|
| 1677 |
|
---|
| 1678 | /**
|
---|
| 1679 | * Exit immediately without cleaning up.
|
---|
| 1680 | * @param sig The signal we are exiting due to.
|
---|
| 1681 | */
|
---|
| 1682 | void termination_in_progress(int sig)
|
---|
| 1683 | {
|
---|
[116] | 1684 | log_msg(1, "Termination in progress");
|
---|
| 1685 | usleep(1000);
|
---|
| 1686 | pthread_exit(0);
|
---|
[1] | 1687 | }
|
---|
| 1688 |
|
---|
| 1689 | /* @} - end of cliGroup */
|
---|