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