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

Last change on this file since 3138 was 3138, checked in by Bruno Cornec, 11 years ago

r5337@localhost: bruno | 2013-06-13 01:56:06 +0200

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