source: MondoRescue/branches/3.0/mondo/src/common/libmondo-cli.c@ 3144

Last change on this file since 3144 was 3141, checked in by Bruno Cornec, 12 years ago

r5345@localhost: bruno | 2013-06-13 12:46:54 +0200

  • Solving #702 by adding a -F option which is meant to be used especially when mondoarchive is launched from cron, to avoid going into a loop where mondoarchive asks questions to the admin, where they cannot be answerd, which fills the logs and the underlying file system. With -F mondoarchive will exits at the first interaction request instead.
  • Property svn:keywords set to Id
File size: 33.0 KB
RevLine 
[1]1/***************************************************************************
[2085]2$Id: libmondo-cli.c 3141 2013-06-13 16:05:57Z bruno $
[1]3*******************************************************************/
4
5/**
6 * @file
7 * Functions for handling command-line arguments passed to mondoarchive.
8 */
9
10/** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
11
12#include <pthread.h>
[1917]13#include "my-stuff.h"
[2211]14#include "mr_mem.h"
[2241]15#include "mr_str.h"
[1917]16#include "mondostructures.h"
17#include "libmondo-cli-EXT.h"
18#include "libmondo.h"
[1]19
20extern int g_loglevel;
21extern bool g_text_mode;
[3141]22extern bool g_fail_immediately;
[116]23extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
[1917]24extern char *MONDO_OPTIONS;
[1]25
26/*@ file pointer **************************************************/
27extern FILE *g_tape_stream;
28
29/*@ long long *****************************************************/
30extern long long g_tape_posK;
31
32/*@ long **********************************************************/
33extern long g_noof_sets;
34
35/*@ bool******** **************************************************/
[116]36bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
37bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
[1]38extern bool g_cd_recovery;
39
[1656]40extern void setup_tmpdir(char *path);
[2424]41void mr_make_devlist_from_pathlist(char *pathlist, char mode);
[1]42extern double g_kernel_version;
43extern int g_current_media_number;
44extern pid_t g_main_pid;
[116]45extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
[1]46
[948]47/* Do we use extended attributes and acl ?
[2772]48 * By default no, use -z option to force their usage */
[1917]49extern char *g_getfacl;
50extern char *g_getfattr;
[1]51
[1645]52/* Reference to global bkpinfo */
53extern struct s_bkpinfo *bkpinfo;
54
[1967]55extern void free_MR_global_filenames(void);
56
[3138]57long g_max_biggie_size = BIGGIEMAXSIZE;
58
[1]59/**
60 * @addtogroup cliGroup
61 * @{
62 */
63/**
64 * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv.
65 * @param argc The argument count, including the program name; @p argc passed to main().
66 * @param argv The argument vector; @p argv passed to main().
67 * @param bkpinfo The backup information structure to populate.
68 * @return The number of problems with the command line (0 for success).
69 */
70int
[1645]71handle_incoming_parameters(int argc, char *argv[])
[1]72{
[116]73 /*@ int *** */
74 int res = 0;
75 int retval = 0;
76 int i = 0, j;
[1]77
[116]78 /*@ buffers *************** */
79 char *tmp;
80 char flag_val[128][MAX_STR_LEN];
81 bool flag_set[128];
[1]82
[1702]83 tmp = malloc(9*MAX_STR_LEN);
[116]84 for (i = 0; i < 128; i++) {
85 flag_val[i][0] = '\0';
86 flag_set[i] = FALSE;
87 }
88 for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
89 bkpinfo->media_size[j] = 650;
90 } /* default */
91 res =
92 retrieve_switches_from_command_line(argc, argv, flag_val,
93 flag_set);
94 retval += res;
95 if (!retval) {
[1645]96 res = process_switches(flag_val, flag_set);
[116]97 retval += res;
98 }
[1]99/*
100 if (!retval)
101 {
102*/
[116]103 log_msg(3, "Switches:-");
104 for (i = 0; i < 128; i++) {
105 if (flag_set[i]) {
106 sprintf(tmp, "-%c %s", i, flag_val[i]);
107 log_msg(3, tmp);
108 }
[1]109 }
110// }
[2907]111 /* Before erasing dirs go into a safe place */
[3060]112 if (chdir("/tmp")) {
113 // FIXME
114 }
[116]115 sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
116 paranoid_system(tmp);
117 sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
118 paranoid_system(tmp);
119 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
120 "/mondo.scratch.%ld", random() % 32767);
121 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
122 paranoid_system(tmp);
123 sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
124 paranoid_system(tmp);
125 paranoid_free(tmp);
126 return (retval);
[1]127}
128
129
130
131
132/**
133 * Store the sizespec(s) stored in @p value into @p bkpinfo.
134 * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated.
135 * @param value The sizespec (e.g. "2g", "40m").
136 * @return 0, always.
137 * @bug Return code not needed.
138 */
[1645]139int process_the_s_switch(char *value)
[1]140{
[116]141 int j;
142 char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
[1]143
[116]144 assert(bkpinfo != NULL);
145 assert(value != NULL);
[1]146
[116]147 bkpinfo->media_size[0] = -1; /* dummy value */
148 for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
149 j++, p = strchr(p, ',') + 1) {
150 strncpy(tmp, p, MAX_STR_LEN);
151 *(strchr(tmp, ',')) = '\0';
152 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
153 sprintf(comment, "media_size[%d] = %ld", j,
154 bkpinfo->media_size[j]);
155 log_msg(3, comment);
[1]156 }
[116]157 for (; j <= MAX_NOOF_MEDIA; j++) {
158 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
[1]159 }
160// bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
[116]161 for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
162 if (bkpinfo->media_size[j] <= 0) {
163 log_msg(1, "You gave media #%d an invalid size\n", j);
164 return (-1);
165 }
166 }
167 return (0);
[1]168}
169
[2007]170/**
[1]171 * Process mondoarchive's command-line switches.
172 * @param bkpinfo The backup information structure to populate.
173 * @param flag_val An array of the argument passed to each switch (the letter is the index).
174 * If a switch is not set or has no argument, the field in @p flag_val doesn't matter.
175 * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set,
176 * FALSE if it's not.
177 * @return The number of problems with the switches, or 0 for success.
178 * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here?
179 */
180int
[1645]181process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
[1]182{
183
[116]184 /*@ ints *** */
185 int i = 0;
186 int retval = 0;
[1]187
[116]188 /*@ buffers ** */
[2022]189 char *tmp = NULL;
190 char *tmp1 = NULL;
191 char *psz = NULL;
192 char *p = NULL;
193 char *q = NULL;
[1]194
[949]195 long itbs = 0L;
[1]196
[289]197 struct stat buf;
198
[116]199 malloc_string(tmp);
[1]200
[116]201 assert(bkpinfo != NULL);
202 assert(flag_val != NULL);
203 assert(flag_set != NULL);
[1]204
[116]205 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
[1]206
[1967]207 /* compulsory */
[116]208 i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
209 flag_set['t'] + flag_set['u'] + flag_set['r'] +
[1690]210 flag_set['w'] + flag_set['C'] + flag_set['U'];
[1967]211 if ((i == 0) && (! bkpinfo->restore_data)) {
[116]212 retval++;
[541]213 log_to_screen("You must specify the media type\n");
[1]214 }
[116]215 if (i > 1) {
216 retval++;
[541]217 log_to_screen("Please specify only one media type\n");
[1]218 }
[1967]219
[116]220 if (flag_set['K']) {
221 g_loglevel = atoi(flag_val['K']);
[1945]222 log_msg(1,"Loglevel forced to %d",g_loglevel);
[116]223 if (g_loglevel < 3) {
224 g_loglevel = 3;
225 }
[1]226 }
[1967]227
228 if ((flag_set['L'] && flag_set['0']) && (! bkpinfo->restore_data)) {
[116]229 retval++;
[541]230 log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
[1]231 }
[1967]232 if (! bkpinfo->restore_data) {
233 bkpinfo->backup_data = flag_set['O'];
234 }
[116]235 bkpinfo->verify_data = flag_set['V'];
[1967]236
[116]237 if (flag_set['I'] && !bkpinfo->backup_data) {
[541]238 log_to_screen("-I switch is ignored if just verifying");
[116]239 }
240 if (flag_set['E'] && !bkpinfo->backup_data) {
[541]241 log_to_screen("-E switch is ignored if just verifying");
[116]242 }
[1]243
[116]244 if (!find_home_of_exe("afio")) {
245 if (find_home_of_exe("star")) {
246 flag_set['R'] = TRUE;
247 log_msg(1, "Using star instead of afio");
248 } else {
249 fatal_error
250 ("Neither afio nor star is installed. Please install at least one.");
251 }
[1]252 }
253
[116]254 if (flag_set['R']) {
255 bkpinfo->use_star = TRUE;
256 if (flag_set['L']) {
257 fatal_error("You may not use star and lzop at the same time.");
258 }
259 if (!find_home_of_exe("star")) {
260 fatal_error
261 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks.");
262 }
[1]263 }
[1967]264
265 if ((flag_set['W']) && (! bkpinfo->restore_data)) {
[116]266 bkpinfo->nonbootable_backup = TRUE;
267 log_to_screen("Warning - you have opted for non-bootable backup");
268 if (flag_set['f'] || flag_set['l']) {
269 log_to_screen
[541]270 ("You don't need to specify bootloader or bootdevice");
[116]271 }
[1]272 }
[1967]273
[116]274 if (flag_set['I']) {
[2022]275 if (bkpinfo->include_paths[0] == '-') {
276 retval++;
277 log_to_screen("Please supply a sensible value with '-I'\n");
278 }
[116]279 if (!strcmp(bkpinfo->include_paths, "/")) {
280 log_msg(2, "'/' is pleonastic.");
281 bkpinfo->include_paths[0] = '\0';
282 }
283 if (bkpinfo->include_paths[0]) {
[2713]284 strcat(bkpinfo->include_paths, "|");
[116]285 }
[2290]286
[2211]287 mr_asprintf(&tmp1, "%s", flag_val['I']);
[2022]288 p = tmp1;
289 q = tmp1;
290
291 /* Cut the flag_val['I'] in parts containing all paths to test them */
292 while (p != NULL) {
[2713]293 q = strchr(p, '|');
[2022]294 if (q != NULL) {
295 *q = '\0';
296 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
297 log_msg(1, "ERROR ! %s doesn't exist", p);
298 fatal_error("ERROR ! You specified a directory to include which doesn't exist");
299 }
300 p = q+1 ;
301 } else {
302 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
303 log_msg(1, "ERROR ! %s doesn't exist", p);
304 fatal_error("ERROR ! You specified a directory to include which doesn't exist");
305 }
306 p = NULL;
307 }
308 }
309 paranoid_free(tmp1);
[2424]310 mr_make_devlist_from_pathlist(flag_val['I'], 'I');
[2022]311 log_msg(4, "Finished with the -I option");
[116]312 }
[1]313
[116]314 if (g_kernel_version >= 2.6 && !flag_set['d']
[1967]315 && (flag_set['c'] || flag_set['w']) && (! bkpinfo->restore_data)) {
[116]316 fatal_error
317 ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
[1]318 }
319
[116]320
321 if (flag_set['J']) {
322 if (flag_set['I']) {
323 retval++;
324 log_to_screen
[541]325 ("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]326 }
327 bkpinfo->make_filelist = FALSE;
328 strcpy(bkpinfo->include_paths, flag_val['J']);
[1]329 }
[1967]330
331 if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
[116]332 if (!flag_set['r'] && g_kernel_version <= 2.5
333 && strstr(flag_val['d'], "/dev/")) {
334 fatal_error
335 ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag.");
336 }
337 if (flag_set['r'] && g_kernel_version <= 2.5
338 && !strstr(flag_val['d'], "/dev/")) {
339 fatal_error
340 ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag.");
341 }
342 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
343 log_to_screen
[541]344 ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
[116]345 }
346
347 if (system("which cdrecord > /dev/null 2> /dev/null")
348 && system("which dvdrecord > /dev/null 2> /dev/null")) {
349 fatal_error
350 ("Please install dvdrecord/cdrecord and try again.");
351 }
352 if (flag_set['C']) {
353 bkpinfo->cdrw_speed = atoi(flag_val['C']);
354 if (bkpinfo->cdrw_speed < 1) {
355 fatal_error
356 ("You specified a silly speed for a CD-R[W] drive");
357 }
358 if (!flag_set['L']) {
359 log_to_screen
[541]360 ("You must use -L with -C. Therefore I am setting it for you.");
[116]361 flag_set['L'] = 1;
362 flag_val['L'][0] = '\0';
363 }
364 } else {
365 log_msg(3, "flag_val['c'] = %s", flag_val['c']);
366 log_msg(3, "flag_val['w'] = %s", flag_val['w']);
367// log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
368 if (flag_set['c']) {
369 bkpinfo->cdrw_speed = atoi(flag_val['c']);
370 } else if (flag_set['w']) {
371 bkpinfo->cdrw_speed = atoi(flag_val['w']);
372 } else if (flag_set['r']) {
373 bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */
374 }
375
376 if (bkpinfo->cdrw_speed < 1) {
377 fatal_error
378 ("You specified a silly speed for a CD-R[W] drive");
379 }
380 }
[1]381 }
[1967]382
[1969]383 if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
[116]384 log_it("Hmm! No tape drive specified. Let's see what we can do.");
385 if (find_tape_device_and_size(flag_val['d'], tmp)) {
386 fatal_error
387 ("Tape device not specified. I couldn't find it either.");
388 }
389 flag_set['d'] = TRUE;
390 sprintf(tmp,
[541]391 "You didn't specify a tape streamer device. I'm assuming %s",
[116]392 flag_val['d']);
393 log_to_screen(tmp);
394 }
395
[1687]396 if (flag_set['U']) // USB
397 {
398 if (! flag_set['d']) {
399 fatal_error
[1967]400 ("You need to specify a device file with -d for bootable USB device usage");
[1687]401 }
[1967]402 if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
[1687]403 fatal_error("You did not specify a size (-s) for your USB device. Aborting");
404 }
405 }
406
[116]407 if (flag_set['r']) // DVD
408 {
409 if (flag_set['m']) {
410 fatal_error
411 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
412 }
413 if (!flag_set['d']) {
414 if (!find_dvd_device(flag_val['d'], FALSE)) {
415 flag_set['d'] = TRUE;
[541]416 log_to_screen("I guess DVD drive is at %s", flag_val['d']);
[116]417 }
418 }
419 if (strchr(flag_val['d'], ',')) {
420 fatal_error
421 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
422 }
[1967]423 if (! bkpinfo->restore_data) {
424 if (!find_home_of_exe("growisofs")) {
425 fatal_error
426 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
427 }
428 if (!find_home_of_exe("dvd+rw-format")) {
429 fatal_error
430 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
431 }
432 if (!flag_set['s']) {
433 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
434 strcat(flag_val['s'], "m");
435 log_to_screen
436 ("You did not specify a size (-s) for DVD. I'm guessing %s.",
437 flag_val['s']);
438 flag_set['s'] = 1;
439 }
[116]440 }
[1]441/*
442 if (flag_set['Z']) {
443 bkpinfo->blank_dvd_first = TRUE;
444 }
445*/
[116]446 }
[1]447
[116]448 if (flag_set['t'] || flag_set['u']) { /* tape size */
449 if (strchr(flag_val['d'], ',')) {
450 fatal_error
451 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
452 }
[1967]453 if ((flag_set['O']) && (! bkpinfo->restore_data)) {
[116]454 if (flag_set['s']) {
455 if (flag_set['t']) {
456 fatal_error
457 ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
458 }
[1645]459 if (process_the_s_switch(flag_val['s'])) {
[116]460 fatal_error("Bad -s switch");
461 }
462 } else if (flag_set['u'] || flag_set['t']) {
463 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
464 bkpinfo->media_size[i] = 0;
465 }
466 } else {
467 retval++;
468 log_to_screen("Tape size not specified.\n");
469 }
470 }
[1967]471 } else if (! bkpinfo->restore_data) { /* CD|USB size */
[116]472 if (flag_set['s']) {
[1645]473 if (process_the_s_switch(flag_val['s'])) {
[116]474 fatal_error("Bad -s switch");
475 }
476 }
477 if (flag_set['w']) {
478 bkpinfo->wipe_media_first = TRUE;
479 } /* CD-RW */
[1]480 }
[1967]481
[116]482 if (flag_set['n']) {
[2380]483 strncpy(bkpinfo->netfs_mount, flag_val['n'], MAX_STR_LEN);
[116]484 if (!flag_set['d']) {
[2380]485 strncpy(bkpinfo->netfs_remote_dir, "/", MAX_STR_LEN);
[116]486 }
[2380]487 /* test for protocol */
[2426]488 p = strstr(bkpinfo->netfs_mount, "://");
[2380]489 if (p == NULL) {
[2426]490 /* protocol not found assuming NFS for compatibility */
491 mr_asprintf(&q,"nfs");
492
493 p = strchr(bkpinfo->netfs_mount, ':');
494 if (p == NULL) {
495 fatal_error("No protocol specified for remote share mount, nor any old NFS syntax found.\nPlease do man mondoarchive as syntax changed");
[2380]496 }
[2387]497 /* p points on to the string server:/path */
[2426]498 p = bkpinfo->netfs_mount;
[2387]499
[2426]500 } else {
501 /* Isolate the protocol */
[2380]502 *p = '\0';
503 mr_asprintf(&q,"%s",bkpinfo->netfs_mount);
[2426]504
505 /* Skip proto now */
506 p++;
507 p++;
508 p++;
[2380]509 }
[2426]510 /* whatever done before proto is pointed to by q */
511 bkpinfo->netfs_proto = q;
512
513 /* p points on to the string server:/path */
514 /* Store the 2 values */
[2946]515 /* using memmove instead of strcpy as per #584 */
516 memmove(bkpinfo->netfs_mount, p, MAX_STR_LEN);
[2426]517
[2380]518 /* test if we specified a user */
519 p = strchr(bkpinfo->netfs_mount, '@');
[2224]520 if (p != NULL) {
521 /* User found. Store the 2 values */
522 p++;
[2380]523 /* new netfs mount */
[2224]524 strcpy(tmp,p);
525 p--;
526 *p = '\0';
[2380]527 mr_asprintf(&q,"%s",bkpinfo->netfs_mount);
528 bkpinfo->netfs_user = q;
529 strcpy(bkpinfo->netfs_mount,tmp);
[2224]530 }
[2877]531 sprintf(tmp, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user,
[2380]532 bkpinfo->netfs_mount);
[116]533 strncpy(bkpinfo->isodir,
534 call_program_and_get_last_line_of_output(tmp),
535 MAX_STR_LEN / 4);
536 if (strlen(bkpinfo->isodir) < 3) {
[2380]537 log_to_screen("Network share is not mounted. Trying to mount it for you.\n");
[2847]538 if (bkpinfo->netfs_user) {
539 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
540 sprintf(tmp, "sshfs %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
[3111]541 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) {
542 sprintf(tmp, "mount -t cifs %s -o user=%s", bkpinfo->netfs_mount, bkpinfo->netfs_user);
[2847]543 } else if (strstr(bkpinfo->netfs_proto, "nfs")) {
544 sprintf(tmp, "mount %s@%s", bkpinfo->netfs_user, bkpinfo->netfs_mount);
545 } else {
546 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto);
547 fatal_error("Bad Protocol\n");
548 }
[2380]549 } else {
[2847]550 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
551 sprintf(tmp, "sshfs %s", bkpinfo->netfs_mount);
[3111]552 } else if (strstr(bkpinfo->netfs_proto, "smbfs")) {
553 sprintf(tmp, "mount -t cifs %s", bkpinfo->netfs_mount);
[2847]554 } else if (strstr(bkpinfo->netfs_proto, "nfs")) {
555 sprintf(tmp, "mount %s", bkpinfo->netfs_mount);
556 } else {
557 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto);
558 fatal_error("Bad Protocol\n");
559 }
[2380]560 }
[2223]561 if (system(tmp)) {
[2380]562 log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
[2223]563 retval++;
564 } else {
[2847]565 if (bkpinfo->netfs_user) {
566 sprintf(tmp, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user,
567 bkpinfo->netfs_mount);
568 } else {
569 sprintf(tmp, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
570 }
[2223]571 strncpy(bkpinfo->isodir,
572 call_program_and_get_last_line_of_output(tmp),
573 MAX_STR_LEN / 4);
574 if (strlen(bkpinfo->isodir) < 3) {
575 retval++;
[2380]576 log_to_screen("Network share %s is strangely not mounted. Please mount manually...\n", bkpinfo->netfs_mount);
[2223]577 }
578 }
[116]579 }
[2435]580 log_msg(3, "proto = %s", bkpinfo->netfs_proto);
[2380]581 log_msg(3, "mount = %s", bkpinfo->netfs_mount);
[2435]582 if (bkpinfo->netfs_user) {
583 log_msg(3, "user = %s", bkpinfo->netfs_user);
584 }
[116]585 log_msg(3, "isodir= %s", bkpinfo->isodir);
[1]586 }
[1967]587
[116]588 if (flag_set['c']) {
589 bkpinfo->backup_media_type = cdr;
[1]590 }
[116]591 if (flag_set['C']) {
592 bkpinfo->backup_media_type = cdstream;
[1]593 }
[116]594 if (flag_set['i']) {
595 bkpinfo->backup_media_type = iso;
596 }
597 if (flag_set['n']) {
[2380]598 bkpinfo->backup_media_type = netfs;
599 /* Never try to eject a Network device */
[1848]600 bkpinfo->please_dont_eject = TRUE;
[116]601 }
602 if (flag_set['r']) {
603 bkpinfo->backup_media_type = dvd;
604 }
605 if (flag_set['t']) {
606 bkpinfo->backup_media_type = tape;
607 }
608 if (flag_set['u']) {
609 bkpinfo->backup_media_type = udev;
610 }
611 if (flag_set['w']) {
612 bkpinfo->backup_media_type = cdrw;
613 }
[1687]614 if (flag_set['U']) {
615 bkpinfo->backup_media_type = usb;
[1745]616 /* Never try to eject a USB device */
[1746]617 bkpinfo->please_dont_eject = TRUE;
[1687]618 }
[948]619 if (flag_set['z']) {
620 if (find_home_of_exe("getfattr")) {
[2211]621 mr_asprintf(&g_getfattr,"getfattr");
[948]622 }
623 if (find_home_of_exe("getfacl")) {
[2211]624 mr_asprintf(&g_getfacl,"getfacl");
[948]625 }
626 }
[1]627
[805]628 /* optional, popular */
[116]629 if (flag_set['g']) {
630 g_text_mode = FALSE;
631 }
[805]632
[116]633 if (flag_set['E']) {
[2698]634 if (bkpinfo->exclude_paths && (bkpinfo->exclude_paths[0] == '-')) {
[2022]635 retval++;
636 log_to_screen("Please supply a sensible value with '-E'\n");
637 }
[2211]638 mr_asprintf(&tmp1, "%s", flag_val['E']);
[542]639
[2022]640 p = tmp1;
641 q = tmp1;
642
643 /* Cut the flag_val['E'] in parts containing all paths to test them */
644 while (p != NULL) {
[2713]645 q = strchr(p, '|');
[2022]646 if (q != NULL) {
647 *q = '\0';
648 /* Fix bug 14 where ending / cause a problem later
649 * so handled here for the moment */
650 q--;
651 if (*q == '/') {
652 *q = '\0';
653 }
654 q++;
655 /* End of bug fix */
656 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
657 log_msg(1, "WARNING ! %s doesn't exist", p);
658 }
659 p = q+1 ;
660 } else {
661 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
662 log_msg(1, "WARNING ! %s doesn't exist", p);
663 }
664 p = NULL;
665 }
666 }
667 paranoid_free(tmp1);
[2424]668
669 mr_make_devlist_from_pathlist(flag_val['E'], 'E');
[2022]670 log_msg(4, "Finished with the -E option");
[116]671 }
[1967]672
[116]673 if (flag_set['e']) {
674 bkpinfo->please_dont_eject = TRUE;
675 }
[1967]676
[3138]677 if (flag_set['M']) {
678 g_max_biggie_size = atol(flag_val['M']);
679 log_msg(1, "Max size for biggie file is now %ld KB", g_max_biggie_size);
680 }
681
[2380]682 if ((flag_set['N']) && (! bkpinfo->restore_data)) // exclude Network mounts & devices
[116]683 {
[2713]684 psz = list_of_NETFS_mounts_only();
685 log_msg(5, "-N means we'll exclude %s", psz);
686 if (bkpinfo->exclude_paths) {
687 mr_strcat(bkpinfo->exclude_paths, "|%s", psz);
688 mr_free(psz);
689 } else {
690 bkpinfo->exclude_paths = psz;
691 }
[2214]692
[2697]693 if (bkpinfo->exclude_paths != NULL) {
694 log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths);
695 }
[116]696 }
[1967]697
[116]698 if (flag_set['b']) {
[2309]699 mr_asprintf(&psz, "%s", flag_val['b']);
[116]700 log_msg(1, "psz = '%s'", psz);
701 if (psz[strlen(psz) - 1] == 'k') {
702 psz[strlen(psz) - 1] = '\0';
703 itbs = atol(psz) * 1024L;
704 } else {
705 itbs = atol(psz);
706 }
[2214]707 mr_free(psz);
[116]708 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
709 log_msg(1, "Internal tape block size is now %ld bytes", itbs);
710 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
711 fatal_error
712 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
713 }
714 bkpinfo->internal_tape_block_size = itbs;
715 }
[1967]716
717 if ((flag_set['D']) && (! bkpinfo->restore_data)) {
[116]718 bkpinfo->differential = 1;
[1]719// bkpinfo->differential = atoi (flag_val['D']);
[116]720 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
721 fatal_error
722 ("The D option should be between 1 and 9 inclusive");
723 }
[1]724 }
[1967]725
[116]726 if (flag_set['x']) {
727 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
[1967]728 if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
[296]729 fatal_error("Please install ntfsprogs package/tarball.");
[116]730 }
[1]731 }
[1967]732
[116]733 if (flag_set['m']) {
734 bkpinfo->manual_cd_tray = TRUE;
[1]735 }
[1967]736
737 if ((flag_set['k']) && (! bkpinfo->restore_data)) {
[116]738 strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
739 if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
740 strcpy(bkpinfo->kernel_path, "FAILSAFE");
741 }
742 if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
743 && !does_file_exist(bkpinfo->kernel_path)) {
744 retval++;
745 sprintf(tmp,
[541]746 "You specified kernel '%s', which does not exist\n",
[116]747 bkpinfo->kernel_path);
748 log_to_screen(tmp);
749 }
750 }
[1967]751
[116]752 if (flag_set['p']) {
753 strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
[1966]754 log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
[116]755 }
[1]756
[2380]757 if (flag_set['d']) { /* backup directory (if ISO/NETFS) */
[116]758 if (flag_set['i']) {
759 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
760 sprintf(tmp, "ls -l %s", bkpinfo->isodir);
[1737]761 if (run_program_and_log_output(tmp, 2)) {
[116]762 fatal_error
763 ("output folder does not exist - please create it");
764 }
765 } else if (flag_set['n']) {
[2380]766 strncpy(bkpinfo->netfs_remote_dir, flag_val['d'], MAX_STR_LEN);
[116]767 } else { /* backup device (if tape/CD-R/CD-RW) */
768 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
769 }
[1]770 }
[116]771
[1967]772 if ((flag_set['n']) && (! bkpinfo->restore_data)) {
[2380]773 mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir);
774 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
775 sprintf(tmp, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
[2224]776 } else {
777 sprintf(tmp, "echo hi > %s", tmp1);
778 }
[1737]779 if (run_program_and_log_output(tmp, 2)) {
[116]780 retval++;
781 sprintf(tmp,
[541]782 "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
[2380]783 bkpinfo->netfs_remote_dir, bkpinfo->netfs_mount);
[116]784 log_to_screen(tmp);
785 }
[1767]786 unlink(tmp1);
787 paranoid_free(tmp1);
[1]788 }
789
[116]790 if (!flag_set['d']
791 && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
792 if (g_kernel_version >= 2.6) {
793 if (popup_and_get_string
[541]794 ("Device", "Please specify the device",
[116]795 bkpinfo->media_device, MAX_STR_LEN / 4)) {
796 retval++;
[541]797 log_to_screen("User opted to cancel.");
[116]798 }
799 } else if (find_cdrw_device(bkpinfo->media_device)) {
800 retval++;
801 log_to_screen
[541]802 ("Tried and failed to find CD-R[W] drive automatically.\n");
[116]803 } else {
804 flag_set['d'] = TRUE;
805 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
806 }
[1]807 }
808
[1967]809 if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
[116]810 retval++;
[541]811 log_to_screen("Please specify the backup device/directory.\n");
[116]812 fatal_error
813 ("You didn't use -d to specify the backup device/directory.");
[1]814 }
[1967]815
[116]816 for (i = '0'; i <= '9'; i++) {
817 if (flag_set[i]) {
818 bkpinfo->compression_level = i - '0';
819 } /* not '\0' but '0' */
[1]820 }
[1967]821
[116]822 if (flag_set['S']) {
[2907]823 /* Before changing remove old ones if any */
824 if (bkpinfo->scratchdir) {
[3060]825 if (chdir("/tmp")) {
826 // FIXME
827 }
[2912]828 mr_asprintf(&tmp1, "rm -Rf %s", bkpinfo->scratchdir);
829 paranoid_system(tmp1);
830 mr_free(tmp1);
[2907]831 }
[116]832 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
833 random() % 32768);
[1]834 }
[1967]835
[116]836 if (flag_set['T']) {
[1655]837 setup_tmpdir(flag_val['T']);
838 sprintf(tmp, "touch %s/.foo.dat", bkpinfo->tmpdir);
[116]839 if (run_program_and_log_output(tmp, 1)) {
840 retval++;
841 log_to_screen
[541]842 ("Please specify a tempdir which I can write to. :)");
[116]843 fatal_error("I cannot write to the tempdir you specified.");
844 }
[1655]845 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
[116]846 if (run_program_and_log_output(tmp, 1)) {
847 retval++;
848 log_to_screen
[541]849 ("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
[116]850 fatal_error("I cannot write to the tempdir you specified.");
851 }
[1]852 }
[1967]853
854 if ((flag_set['A']) && (! bkpinfo->restore_data)) {
[116]855 strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
856 }
[1967]857
858 if ((flag_set['B']) && (! bkpinfo->restore_data)) {
[116]859 strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
860 }
[1967]861
862 if ((flag_set['H']) && (! bkpinfo->restore_data)) {
[116]863 g_cd_recovery = TRUE;
864 }
[1967]865
866 if ((flag_set['l']) && (! bkpinfo->restore_data)) {
[1]867#ifdef __FreeBSD__
868# define BOOT_LOADER_CHARS "GLBMR"
869#else
870# ifdef __IA64__
871# define BOOT_LOADER_CHARS "GER"
872# else
873# define BOOT_LOADER_CHARS "GLR"
874# endif
875#endif
[116]876 if (!strchr
877 (BOOT_LOADER_CHARS,
878 (bkpinfo->boot_loader = flag_val['l'][0]))) {
879 log_msg(1, "%c? WTF is %c? I need G, L, E or R.",
880 bkpinfo->boot_loader, bkpinfo->boot_loader);
881 fatal_error
882 ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
883 }
[1]884#undef BOOT_LOADER_CHARS
885 }
[1967]886
[116]887 if (flag_set['f']) {
888 strncpy(bkpinfo->boot_device,
889 resolve_softlinks_to_get_to_actual_device_file(flag_val
890 ['f']),
891 MAX_STR_LEN / 4);
892 }
[1967]893
894 if ((flag_set['P']) && (! bkpinfo->restore_data)) {
[116]895 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
896 }
[1967]897
[116]898 if (flag_set['Q']) {
899 i = which_boot_loader(tmp);
900 log_msg(3, "boot loader is %c, residing at %s", i, tmp);
[541]901 printf("boot loader is %c, residing at %s\n", i, tmp);
[116]902 finish(0);
903 }
[1967]904
905 if ((flag_set['L']) && (! bkpinfo->restore_data)) {
[116]906 bkpinfo->use_lzo = TRUE;
[1737]907 if (run_program_and_log_output("which lzop", 2)) {
[116]908 retval++;
909 log_to_screen
[541]910 ("Please install LZOP. You can't use '-L' until you do.\n");
[116]911 }
912 }
[1]913
[3141]914 if (flag_set['F']) {
915 log_msg(3, "-F means we will fail immediately at the first interaction request");
916 g_fail_immediately = TRUE;
917 }
918
[1967]919 if ((flag_set['G']) && (! bkpinfo->restore_data)) {
[998]920 bkpinfo->use_gzip = TRUE;
[1737]921 if (run_program_and_log_output("which gzip", 2)) {
[998]922 retval++;
923 log_to_screen
924 ("Please install gzip. You can't use '-G' until you do.\n");
925 }
926 }
927
[1948]928 bkpinfo->use_obdr = FALSE;
929 if (flag_set['o']) {
[1967]930 if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
[1948]931 log_to_screen("OBDR support is only available for tapes. Use the -t option");
932 fatal_error("Aborting");
933 }
934 bkpinfo->use_obdr = TRUE;
935 }
[1967]936
[1948]937#ifndef __FreeBSD__
[1967]938 if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
[116]939 bkpinfo->make_cd_use_lilo = TRUE;
940 log_to_screen
[1948]941 ("Your kernel appears not to support vfat filesystems. I am therefore");
942 log_to_screen
943 ("using LILO instead of SYSLINUX as the media boot loader.");
[116]944 }
[1967]945 if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
[116]946 bkpinfo->make_cd_use_lilo = TRUE;
[1]947#ifdef __IA32__
[1948]948 log_to_screen
949 ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
950 log_to_screen
951 ("your boot loader. I shall therefore use LILO instead.");
[1]952#endif
953#ifdef __IA64__
[1948]954 log_to_screen
955 ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
956 log_to_screen("environment correctly. Please install it.");
957 fatal_error("Aborting");
[1]958#endif
[1948]959 }
[1]960#ifdef __IA64__
[1948]961 /* We force ELILO usage on IA64 */
962 bkpinfo->make_cd_use_lilo = TRUE;
[2085]963#endif
964#endif
[1]965
[1967]966 if (! bkpinfo->restore_data) {
[1917]967 i = flag_set['O'] + flag_set['V'];
968 if (i == 0) {
969 retval++;
970 log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
971 }
[116]972 }
[1]973
[1967]974 if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
975 fatal_error
976 ("The -Z switch is only valid in restore mode");
977 }
978
979 if (flag_set['Z']) {
980 if (! strcmp(flag_val['Z'], "nuke")) {
981 bkpinfo->restore_mode = nuke;
982 } else if (! strcmp(flag_val['Z'], "interactive")) {
983 bkpinfo->restore_mode = interactive;
984 } else if (! strcmp(flag_val['Z'], "compare")) {
985 bkpinfo->restore_mode = compare;
986 } else if (! strcmp(flag_val['Z'], "mbr")) {
987 bkpinfo->restore_mode = mbr;
988 } else if (! strcmp(flag_val['Z'], "iso")) {
989 bkpinfo->restore_mode = isoonly;
990 } else if (! strcmp(flag_val['Z'], "isonuke")) {
991 bkpinfo->restore_mode = isonuke;
992 } else {
993 bkpinfo->restore_mode = interactive;
994 }
995 }
996
[1]997/* and finally... */
998
[116]999 paranoid_free(tmp);
1000 return (retval);
[1]1001}
1002
1003
1004
1005/**
1006 * Get the switches from @p argc and @p argv using getopt() and place them in
1007 * @p flag_set and @p flag_val.
1008 * @param argc The argument count (@p argc passed to main()).
1009 * @param argv The argument vector (@p argv passed to main()).
1010 * @param flag_val An array indexed by switch letter - if a switch is set and
1011 * has an argument then set flag_val[switch] to that argument.
1012 * @param flag_set An array indexed by switch letter - if a switch is set then
1013 * set flag_set[switch] to TRUE, else set it to FALSE.
1014 * @return The number of problems with the command line (0 for success).
1015 */
1016int
[116]1017retrieve_switches_from_command_line(int argc, char *argv[],
1018 char flag_val[128][MAX_STR_LEN],
1019 bool flag_set[128])
[1]1020{
[116]1021 /*@ ints ** */
1022 int opt = 0;
[2202]1023 char *tmp = NULL;
[116]1024 int i = 0;
1025 int len;
[1]1026
[116]1027 /*@ bools *** */
1028 bool bad_switches = FALSE;
[1]1029
[116]1030 assert(flag_val != NULL);
1031 assert(flag_set != NULL);
[1]1032
[116]1033 for (i = 0; i < 128; i++) {
1034 flag_val[i][0] = '\0';
1035 flag_set[i] = FALSE;
[1]1036 }
[116]1037 while ((opt =
[1917]1038 getopt(argc, argv, MONDO_OPTIONS))
[116]1039 != -1) {
1040 if (opt == '?') {
1041 bad_switches = TRUE;
1042 /*log_it("Invalid option: %c\n",optopt); */
1043 } else {
[2229]1044 if (flag_set[opt]) {
[116]1045 bad_switches = TRUE;
[2290]1046 mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]);
[116]1047 log_to_screen(tmp);
[2202]1048 paranoid_free(tmp);
[116]1049 } else {
1050 flag_set[opt] = TRUE;
1051 if (optarg) {
1052 len = strlen(optarg);
1053 if (optarg[0] != '/' && optarg[len - 1] == '/') {
1054 optarg[--len] = '\0';
1055 log_to_screen
[541]1056 ("Warning - param '%s' should not have trailing slash!",
[116]1057 optarg);
1058 }
1059 if (opt == 'd') {
1060 if (strchr(flag_val[opt], '/')
1061 && flag_val[opt][0] != '/') {
[2290]1062 mr_asprintf(&tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
[116]1063 log_to_screen(tmp);
[2202]1064 paranoid_free(tmp);
[116]1065 bad_switches = TRUE;
1066 }
1067 }
1068 strcpy(flag_val[opt], optarg);
1069 }
1070 }
[1]1071 }
1072 }
[116]1073 for (i = optind; i < argc; i++) {
1074 bad_switches = TRUE;
[2211]1075 mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
[116]1076 log_to_screen(tmp);
[2202]1077 paranoid_free(tmp);
[116]1078 }
1079 return (bad_switches);
[1]1080}
1081
1082
1083
1084
1085/**
1086 * Print a not-so-helpful help message and exit.
1087 */
[116]1088void help_screen()
[1]1089{
[1967]1090 log_msg(1, "Type 'man mondoarchive' for more information\n");
[116]1091 exit(1);
[1]1092}
1093
1094
1095/**
1096 * Terminate Mondo in response to a signal.
1097 * @param sig The signal number received.
1098 */
1099void terminate_daemon(int sig)
1100{
[2211]1101 char *tmp = NULL;
1102 char *tmp2 = NULL;
[1]1103
[116]1104 switch (sig) {
[1]1105 case SIGINT:
[2211]1106 mr_asprintf(&tmp, "SIGINT");
1107 mr_asprintf(&tmp2, "You interrupted me :-)");
[1]1108 break;
1109 case SIGKILL:
[2211]1110 mr_asprintf(&tmp, "SIGKILL");
[2309]1111 mr_asprintf(&tmp2, "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
[1]1112 break;
1113 case SIGTERM:
[2211]1114 mr_asprintf(&tmp, "SIGTERM");
1115 mr_asprintf(&tmp2, "Got terminate signal");
[1]1116 break;
1117 case SIGHUP:
[2211]1118 mr_asprintf(&tmp, "SIGHUP");
1119 mr_asprintf(&tmp2, "Hangup on line");
[1]1120 break;
1121 case SIGSEGV:
[2211]1122 mr_asprintf(&tmp, "SIGSEGV");
[2309]1123 mr_asprintf(&tmp2, "Internal programming error. Please send a backtrace as well as your log.");
[1]1124 break;
1125 case SIGPIPE:
[2211]1126 mr_asprintf(&tmp, "SIGPIPE");
1127 mr_asprintf(&tmp2, "Pipe was broken");
[1]1128 break;
[116]1129 case SIGABRT:
[2211]1130 mr_asprintf(&tmp, "SIGABRT");
[2290]1131 mr_asprintf(&tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
[116]1132 break;
[1]1133 default:
[2211]1134 mr_asprintf(&tmp, "(Unknown)");
1135 mr_asprintf(&tmp2, "(Unknown)");
[116]1136 }
[1]1137
[2211]1138 mr_strcat(tmp, " signal received from OS");
[116]1139 log_to_screen(tmp);
[2211]1140 paranoid_free(tmp);
1141
[116]1142 log_to_screen(tmp2);
[2211]1143 paranoid_free(tmp2);
[116]1144 if (sig == SIGABRT) {
1145 sleep(10);
1146 }
1147 kill_buffer();
[1967]1148
1149 free_MR_global_filenames();
1150
[116]1151 fatal_error
[1967]1152 ("MondoRescue is terminating in response to a signal from the OS");
[116]1153 finish(254); // just in case
[1]1154}
1155
1156
1157
1158
1159/**
1160 * Turn signal-trapping on or off.
1161 * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
1162 */
1163void set_signals(int on)
1164{
[116]1165 int signals[] =
1166 { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
1167 int i;
1168
1169 signal(SIGPIPE, sigpipe_occurred);
1170 for (i = 0; signals[i]; i++) {
1171 if (on) {
1172 signal(signals[i], terminate_daemon);
1173 } else {
1174 signal(signals[i], termination_in_progress);
1175 }
1176 }
[1]1177}
1178
1179
1180
1181
1182/**
1183 * Exit immediately without cleaning up.
1184 * @param sig The signal we are exiting due to.
1185 */
1186void termination_in_progress(int sig)
1187{
[116]1188 log_msg(1, "Termination in progress");
1189 usleep(1000);
1190 pthread_exit(0);
[1]1191}
1192
1193/* @} - end of cliGroup */
Note: See TracBrowser for help on using the repository browser.