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

Last change on this file since 2850 was 2850, checked in by Bruno Cornec, 13 years ago

svn merge -r 2773:2849 2.2.9 in 2.2.10

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • Really support both mkisofs and genisoimage everywhere
  • Try to handle netfs_user better in all cases (NFS and SSHFS)
    • Improve logging in init script
    • Format improvement
    • Removes a warning when trying to launch udevadm and it doesn't exist (RHEL 5 e.g.)
    • Fix syntax description in mondoarchive man page for -E & -I with |
  • Adds download entries for new distro supported (Mageia, Fedora 15, Ubuntu 11.04)

-Fix mindi-get-perl-modules when perl dirs in @INC are symlinks (case on Ubuntu 11.04)

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