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