source: MondoRescue/branches/3.1/mondo/src/common/libmondo-cli.c@ 3148

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

2nd phase for svn merge -r 2935:3146 ../3.0

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