source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-cli.c@ 2291

Last change on this file since 2291 was 2291, checked in by Bruno Cornec, 15 years ago
  • Fix a printing error in mindi for the tar command
  • Fix all mr_asprintf which had no second param as a string

(report bug fix done originaly in 2.2.9)

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