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

Last change on this file since 2937 was 2937, checked in by Bruno Cornec, 9 years ago

svn merge -r 2849:2935 ../3.0

  • Adds 3 binaries called potentially by udev o support USB key mount at restore time (Victor Gattegno)
  • mindi only sets the boot flag of a USB device if none is present already (should avoid flip/flop situation)
  • Fix a compatibility bug in analyze-my-lvm whete exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Precise that -J is not supported by mondorestore yet.
  • Fix a compatibility bug in mindi where exclude lists with '|' was incorrectly analyzed (' ' still expected)
  • Install an MBR on USB devices when possible
  • Improve error message in case mondorestore isn't found
  • Adds support for more virtio devices for KVM restore
  • Improve mbr.bin handling
  • Fix an issue in test of FindKernel? for Xen and non Xen cases
    • Fix #492 by removing an extra useless fi
    • Move fvat nd fat modules to CDROM_MODS in order to have them in the initrd to support saving logs to a USB device e.g.
    • Fix an error when dmidecode reports comments before system name
    • Fix previous broken patch on comment management for bkphw
    • Improve msgs printed during kbd analysis
    • Fix a small remaining pb with new comment support
    • Try to again improve the mount/umount stuff in mondo -Adds mention to OEL, CentOS, ScientifLinux? as RHEL clones
  • Fix a panadoid_free done on the wrong variable (solve a memory leak)
  • Solve #495 by skipping the potential (auto-read-only) when analyzin /proc/mdstat result
  • Fix some markup in man pages
  • adds the post-nuke script sample for Debian (Guillaume Pernot/Andrée? Leidenfrost)
  • Avoid a useless umount when changing of afio set, let insist_on_cd check and perform if needed
  • Copy everything under .ssh of root account to allow for sshfs mount without passwd at restore time.
  • Adds support for bnx2i driver
  • Try to fix #496 by supporting the protocol in the output of the mount command (sshfs#...)
  • Uses the -d option of the mount command to avoid leaving loop devices in use. Probably provoked by the usage of a more recent busybox, but anyway that option doesn't hurt, and does nothing for non-loop devices. Should fix the problems reported on the ML with NFS and more than 8 ISO images (8 being the default number of loop devices available)
  • Attempt to fix #436 by adding some newtDrawForm where appropriate.
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
  • Initialize some global fields with an empty string, now that newt Draws more regularly progress forms
  • Mindi progression still not good, but showing now 3% when calling mindi. Would need a specific handling for the progress bar to evolve more afterwards
  • Add compatibility with the latest SSSTK + PSP content for HP ProLiant? + branding homogeneous now. We only take conrep out of the SSSTK pending a package availability. Using hpacuscripting now. Review of parameters called following test made.
  • Fix #501 by pushing BOOT_SIZE to 36864 for certain Ubuntu cases
  • Fix some remaining inconsistencis in the ProLiant? HW backup. ready for usage.
  • Fix an issue on udevadm call (needs an intermediate variable)
  • Fix a remaining ProLiant? tool call
  • Remove again some wrong variable initialization for Net in order to not have strange messages now we call Draw more often
  • Adds support for hwaddr (MAC addresses) at restore time, and map to the correct NIC if it's found at restore time (based on code from Stefan Heijmans)
  • Try to Fix #499 by changing init in order to never exit, and rebooting using sysrq in /proc (not portable). Maybe should move to using a real init, and a separated rcS script.
  • Fixes the shell msg error by using setsid as per Busybox FAQ
  • Fix #491 by correctly checking Xen kernel used for a dom0 env (apollo13)
  • Improves logging in Die()
  • Improve again ProLiant? HW support, by adding references to the yet to come SSSTK rpm so that conrep is called at its future right place.
  • Improve mindi support for kernel 3.x
  • Fix #499 for good, by using a real init from busybox and moving our init script to etc/init.d/rcS. We also now call the reboot from busybox to exit, which indeed reset the system correctly (in a VM at least which wasn't the case before). Reauires a new mindi-busybox as well.
  • Attempt to solve #503 by handling /lib64 separately for udev and only if not a link (to /lib) for Ubuntu 64
  • Improve again previous tests for bug #503
  • Improve -d option description for NFS
  • Allow http download for ftp content
  • New italian mirror
  • Fix #505 by documenting environment variables
    • Fix a bug where on OBDR mode compression was turned off to create the OBDR content but not back on (report from the mailing list)
  • solve http://trac.mondorescue.org/ticket/520 by Victor Gattegno
  • Fix #524 as option -U needs a size also
  • Removes useless gendf option
  • Fix #511 now stabgrub is called also after conf file modifications
  • Adds support for SUID binaries
  • remove a useless xenkernelname variable from mindi
  • Should fix #512 by clearing old scratchdir before changing to a new
  • Simplify the function engaging SCSI for Smart Array controllers, and support as many controller as we have
  • Add some binaries used on SLES 10 by udev
  • Fix a syntax issue in newt-specific.c
  • Fix a memory free bug where a used variable was freed to early
  • Fix a memory free bug where a used variable was misused in asprintf/free
  • Fix #498 by using an external program (hpsa_obdr_mode) which can set the mode of the tape to CD-ROM or Sequential at will.

That program will have to be downloaded from http://cciss.sf.net

  • Adds support for the route command in mindi-busybox
  • Force block size back to 32768 in OBDR mode after skipping the 2 tape marks, to read the additional rootfs data corerctly - Fix #498 for good it seems
  • Adds support for a new pata_atiixp driver
  • Fix #525 and improve printing when no /etc/raidtab, but still md devices
  • Exclude /run similarly to /sys and /proc
  • Fix a bug in mindi when having multiple swap partiions with same starting string (/dev/dm-1 and /dev/dm-16). We now add a space in the grep to avoid mischoice.
  • Fix grub installation if we had to go in the hack part which wasn't using the correct variables to make decisions !
  • Remove all mention of mondorescue.com from code
  • Fix some website typo on the download page and precise that we now develop on Mageia
  • Exclude sysfs devpts and tmpfs partitions found in RHEL 6.2 from analyze by mindi (made error messages)
  • Force activation of first partition which should not be optional as everything is destroyed before
  • Fix a bug in analyze-my-lvm where LVs were created in random order (the one of lvscan) instead of using the dm-xxx order, which creates issues at restore time between the mapping created then and the one we had at backup time which could be inconssistent

-mondoarchive now exists if the mt command is missing when needed

  • Proper fix for analyze-my-lvm
  • Fix #500 and #473 by adding support of old metadata format for mdadm if using grub < 0.9x or lilo on a md boot device (to be tested)
  • Really never inject or eject when the -e option is passed or device is inappropriate (USB, Net, ...)
  • Fix #577 by having factor back as a float (not a long ! it's a decimal value) and making the appropriate cast.
  • Fix #578 by improving the regexp used for CD/DVD detection with -scanbus option
  • Adds more verbosity when LVM creation fails.
  • Fix #579 by checking with pipes on both sides of the string
  • debugfs should be excluded from the device considered for fstab analysis
  • Property svn:keywords set to Id
File size: 31.8 KB
Line 
1/***************************************************************************
2$Id: libmondo-cli.c 2937 2012-01-28 00:51:28Z bruno $
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>
13#include "my-stuff.h"
14#include "mr_mem.h"
15#include "mr_str.h"
16#include "mondostructures.h"
17#include "libmondo-cli-EXT.h"
18#include "libmondo.h"
19
20extern int g_loglevel;
21extern bool g_text_mode;
22extern char g_startdir[MAX_STR_LEN];    ///< ????? @bug ?????
23extern char *MONDO_OPTIONS;
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******** **************************************************/
35bool g_debugging = FALSE;       ///< ????? @bug ????? @ingroup globalGroup
36bool g_running_live = FALSE;    ///< ????? @bug ????? @ingroup globalGroup
37extern bool g_cd_recovery;
38
39extern void setup_tmpdir(char *path);
40void mr_make_devlist_from_pathlist(char *pathlist, char mode);
41extern double g_kernel_version;
42extern int g_current_media_number;
43extern pid_t g_main_pid;
44extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
45
46/* Do we use extended attributes and acl ?
47 * By default no, use -z option to force their usage */
48extern char *g_getfacl;
49extern char *g_getfattr;
50
51/* Reference to global bkpinfo */
52extern struct s_bkpinfo *bkpinfo;
53
54extern void free_MR_global_filenames(void);
55
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
68handle_incoming_parameters(int argc, char *argv[])
69{
70    /*@ int *** */
71    int res = 0;
72    int retval = 0;
73    int i = 0, j;
74
75    /*@ buffers *************** */
76    char *tmp = NULL;
77    char flag_val[128][MAX_STR_LEN];
78    bool flag_set[128];
79
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 */
87    res = retrieve_switches_from_command_line(argc, argv, flag_val, flag_set);
88    retval += res;
89    if (!retval) {
90        res = process_switches(flag_val, flag_set);
91        retval += res;
92    }
93    log_msg(3, "Switches:-");
94    for (i = 0; i < 128; i++) {
95        if (flag_set[i]) {
96            log_msg(3, "-%c %s", i, flag_val[i]);
97        }
98    }
99    mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
100    paranoid_system(tmp);
101    mr_free(tmp);
102
103    mr_asprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
104    paranoid_system(tmp);
105    mr_free(tmp);
106    return (retval);
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 */
119int process_the_s_switch(char *value)
120{
121    int j;
122    char tmp[MAX_STR_LEN], *p; 
123
124    assert(bkpinfo != NULL);
125    assert(value != NULL);
126
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);
133        log_msg(3, "media_size[%d] = %ld", j, bkpinfo->media_size[j]);
134    }
135    for (; j <= MAX_NOOF_MEDIA; j++) {
136        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
137    }
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);
145}
146
147/**
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
158process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
159{
160
161    /*@ ints *** */
162    int i = 0;
163    int retval = 0;
164    int percent = 0;
165    int lastpos = 0;
166
167    /*@ buffers ** */
168    char *tmp1 = NULL;
169    char *tmp2 = NULL;
170    char *psz = NULL;
171    char *p = NULL;
172    char *q = NULL;
173
174    long itbs = 0L;
175
176    struct stat buf;
177
178    assert(bkpinfo != NULL);
179    assert(flag_val != NULL);
180    assert(flag_set != NULL);
181
182    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
183
184    /* compulsory */
185    i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
186        flag_set['t'] + flag_set['u'] + flag_set['r'] +
187        flag_set['w'] + flag_set['C'] + flag_set['U'];
188    if ((i == 0) && (! bkpinfo->restore_data)) {
189        retval++;
190        log_to_screen("You must specify the media type\n");
191    }
192    if (i > 1) {
193        retval++;
194        log_to_screen("Please specify only one media type\n");
195    }
196
197    if (flag_set['K']) {
198        g_loglevel = atoi(flag_val['K']);
199            log_msg(1,"Loglevel forced to %d",g_loglevel);
200        if (g_loglevel < 3) {
201            g_loglevel = 3;
202        }
203    }
204
205    if ((flag_set['L'] && flag_set['0']) && (! bkpinfo->restore_data)) {
206        retval++;
207        log_to_screen("You cannot have 'no compression' _and_ LZOP.\n");
208    }
209    if (! bkpinfo->restore_data) {
210        bkpinfo->backup_data = flag_set['O'];
211    }
212    bkpinfo->verify_data = flag_set['V'];
213
214    if (flag_set['I'] && !bkpinfo->backup_data) {
215        log_to_screen("-I switch is ignored if just verifying");
216    }
217    if (flag_set['E'] && !bkpinfo->backup_data) {
218        log_to_screen("-E switch is ignored if just verifying");
219    }
220
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);
227            flag_set['R'] = TRUE;
228            log_msg(1, "Using star instead of afio");
229        } else {
230            mr_free(tmp1);
231            fatal_error("Neither afio nor star is installed. Please install at least one.");
232        }
233    }
234    mr_free(tmp1);
235
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        }
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.");
245        }
246        mr_free(tmp1);
247    }
248
249    if ((flag_set['W']) && (! bkpinfo->restore_data)) {
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
254                ("You don't need to specify bootloader or bootdevice");
255        }
256    }
257
258    if (flag_set['I']) {
259        if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') {
260            retval++;
261            log_to_screen("Please supply a sensible value with '-I'\n");
262        }
263
264        mr_asprintf(tmp1, "%s", flag_val['I']);
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) {
270            q = strchr(p, '|');
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        }
286        mr_free(tmp1);
287        mr_make_devlist_from_pathlist(flag_val['I'], 'I');
288        log_msg(4, "Finished with the -I option");
289    }
290
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.");
293    }
294
295
296    if (flag_set['J']) {
297        if (flag_set['I']) {
298            retval++;
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. :-)");
300        }
301        bkpinfo->make_filelist = FALSE;
302        mr_asprintf(bkpinfo->include_paths, "%s", flag_val['J']);
303    }
304
305    if ((flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) && (! bkpinfo->restore_data)) {
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.");
308        }
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.");
311        }
312        if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) {
313            log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...");
314        }
315
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.");
318        }
319        if (flag_set['C']) {
320            bkpinfo->cdrw_speed = atoi(flag_val['C']);
321            if (bkpinfo->cdrw_speed < 1) {
322                fatal_error("You specified a silly speed for a CD-R[W] drive");
323            }
324            if (!flag_set['L']) {
325                log_to_screen("You must use -L with -C. Therefore I am setting it for you.");
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) {
341                fatal_error("You specified a silly speed for a CD-R[W] drive");
342            }
343        }
344    }
345
346    if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
347        log_it("Hmm! No tape drive specified. Let's see what we can do.");
348        if ((tmp1 = mr_find_tape_device()) == NULL) {
349            fatal_error("Tape device not specified. I couldn't find it either.");
350        }
351        strcpy(flag_val['d'], tmp1);
352        mr_free(tmp1);
353        flag_set['d'] = TRUE;
354        strcpy(flag_val['d'], p);
355        mr_free(p);
356        log_to_screen("You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']);
357        percent = 0;
358    }
359
360    if (flag_set['U'])          // USB
361    {
362        if (! flag_set['d']) {
363            fatal_error("You need to specify a device file with -d for bootable USB device usage");
364        }
365        if ((!flag_set['s']) && (! bkpinfo->restore_data)) {
366            fatal_error("You did not specify a size (-s) for your USB device. Aborting");
367        }
368    }
369
370    if (flag_set['r'])          // DVD
371    {
372        if (flag_set['m']) {
373            fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m.");
374        }
375        if (!flag_set['d']) {
376            if ((tmp1 = find_dvd_device(flag_val['d'])) != NULL) {
377                strcpy(flag_val['d'],tmp1);
378                mr_free(tmp1);
379                flag_set['d'] = TRUE;
380                log_to_screen("I guess DVD drive is at %s", flag_val['d']);
381            }
382        }
383        if (strchr(flag_val['d'], ',')) {
384            fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
385        }
386        if (! bkpinfo->restore_data) {
387            tmp1 = find_home_of_exe("growisofs");
388            if (!tmp1) {
389                mr_free(tmp1);
390                fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it.");
391            }
392            mr_free(tmp1);
393
394            tmp1 = find_home_of_exe("dvd+rw-format");
395            if (!tmp1) {
396                mr_free(tmp1);
397                fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it.");
398            }
399            mr_free(tmp1);
400
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");
404                log_to_screen("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']);
405                flag_set['s'] = 1;
406            }
407        }
408    }
409
410    if (flag_set['t'] || flag_set['u']) {   /* tape size */
411        if (strchr(flag_val['d'], ',')) {
412            fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag.");
413        }
414        if ((flag_set['O']) && (! bkpinfo->restore_data)) {
415            if (flag_set['s']) {
416                if (flag_set['t']) {
417                    fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway.");
418                }
419                if (process_the_s_switch(flag_val['s'])) {
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        }
431    } else if (! bkpinfo->restore_data) {           /* CD|USB size */
432        if (flag_set['s']) {
433            if (process_the_s_switch(flag_val['s'])) {
434                fatal_error("Bad -s switch");
435            }
436        }
437        if (flag_set['w']) {
438            bkpinfo->wipe_media_first = TRUE;
439        }                       /* CD-RW */
440    }
441
442    if (flag_set['n']) {
443        mr_free(bkpinfo->netfs_mount);
444        mr_asprintf(bkpinfo->netfs_mount, "%s", flag_val['n']);
445        if (!flag_set['d']) {
446            mr_free(bkpinfo->netfs_remote_dir);
447            mr_asprintf(bkpinfo->netfs_remote_dir, "/");
448        }
449        /* test for protocol */
450        p = strstr(bkpinfo->netfs_mount, "://");
451        if (p == NULL) {
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
462        } else {
463            /* Isolate the protocol */
464            *p = '\0';
465            mr_asprintf(q,"%s",bkpinfo->netfs_mount);
466
467            /* Skip proto now */
468            p++;
469            p++;
470            p++;
471        }
472        /* whatever done before proto is pointed to by q */
473        bkpinfo->netfs_proto = q;
474
475        /* p points on to the string server:/path */
476        /* Store the 2 values */
477        bkpinfo->netfs_mount = p;
478
479        /* test if we specified a user */
480        p = strchr(bkpinfo->netfs_mount, '@');
481        if (p != NULL) {
482            /* User found. Store the 2 values */
483            bkpinfo->netfs_user = bkpinfo->netfs_mount;
484            p++;
485            /* new netfs mount */
486            bkpinfo->netfs_mount = p;
487            p--;
488            *p = '\0';
489        }
490        mr_asprintf(tmp1, "mount | grep -E \"^[a-z]*#*[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount);
491        mr_free(bkpinfo->isodir);
492        bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1,TRUE);
493        mr_free(tmp1);
494
495        if (strlen(bkpinfo->isodir) < 3) {
496            log_to_screen("Network share is not mounted. Trying to mount it for you.\n");
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                }
506            } else {
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                }
515            }
516            i = system(tmp1);
517            mr_free(tmp1);
518
519            if (i) {
520                log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
521                retval++;
522            } else {
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                }
528                mr_free(bkpinfo->isodir);
529                bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1,TRUE);
530                mr_free(tmp1);
531
532                if (strlen(bkpinfo->isodir) < 3) {
533                    retval++;
534                    log_to_screen("Network share %s is strangely not mounted. Please mount manually...\n", bkpinfo->netfs_mount);
535                }
536            }
537        }
538        log_msg(3, "proto = %s", bkpinfo->netfs_proto);
539        log_msg(3, "mount = %s", bkpinfo->netfs_mount);
540        if (bkpinfo->netfs_user) {
541            log_msg(3, "user = %s", bkpinfo->netfs_user);
542        }
543        log_msg(3, "isodir= %s", bkpinfo->isodir);
544    }
545
546    if (flag_set['c']) {
547        bkpinfo->backup_media_type = cdr;
548    }
549    if (flag_set['C']) {
550        bkpinfo->backup_media_type = cdstream;
551    }
552    if (flag_set['i']) {
553        bkpinfo->backup_media_type = iso;
554    }
555    if (flag_set['n']) {
556        bkpinfo->backup_media_type = netfs;
557        /* Never try to eject a Network device */
558        bkpinfo->please_dont_eject = TRUE;
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    }
572    if (flag_set['U']) {
573        bkpinfo->backup_media_type = usb;
574        /* Never try to eject a USB device */
575        bkpinfo->please_dont_eject = TRUE;
576    }
577    if (flag_set['z']) {
578        tmp1 = find_home_of_exe("getfattr");
579        if (tmp1) {
580            mr_asprintf(g_getfattr,"getfattr");
581        }
582        mr_free(tmp1);
583
584        tmp1 = find_home_of_exe("getfacl");
585        if (tmp1) {
586            mr_asprintf(g_getfacl,"getfacl");
587        }
588        mr_free(tmp1);
589    }
590
591    /* optional, popular */
592    if (flag_set['g']) {
593        g_text_mode = FALSE;
594    }
595
596    if (flag_set['E']) {
597        if (bkpinfo->exclude_paths && bkpinfo->exclude_paths[0] == '-') {
598            retval++;
599            log_to_screen("Please supply a sensible value with '-E'\n");
600        }
601        mr_asprintf(tmp1, "%s", flag_val['E']);
602
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) {
608            q = strchr(p, '|');
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        }
630        mr_free(tmp1);
631        lastpos = 0;
632
633        mr_make_devlist_from_pathlist(flag_val['E'], 'E');
634        log_msg(4, "Finished with the -E option");
635    }
636
637    if (flag_set['e']) {
638        bkpinfo->please_dont_eject = TRUE;
639    }
640
641    if ((flag_set['N']) && (! bkpinfo->restore_data))       // exclude Network mounts & devices
642    {
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        }
651
652        if (bkpinfo->exclude_paths != NULL) {
653            log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths);
654        }
655    }
656
657    if (flag_set['b']) {
658        mr_asprintf(psz, "%s", flag_val['b']);
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        }
666        mr_free(psz);
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) {
670            fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
671        }
672        bkpinfo->internal_tape_block_size = itbs;
673    }
674
675    if ((flag_set['D']) && (! bkpinfo->restore_data)) {
676        bkpinfo->differential = 1;
677//      bkpinfo->differential = atoi (flag_val['D']);
678        if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
679            fatal_error("The D option should be between 1 and 9 inclusive");
680        }
681    }
682
683    if (flag_set['x']) {
684        mr_asprintf(bkpinfo->image_devs, "%s", flag_val['x']);
685        if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
686            fatal_error("Please install ntfsprogs package/tarball.");
687        }
688    }
689
690    if (flag_set['m']) {
691        bkpinfo->manual_cd_tray = TRUE;
692    }
693
694    if ((flag_set['k']) && (! bkpinfo->restore_data)) {
695        mr_free(bkpinfo->kernel_path);
696        mr_asprintf(bkpinfo->kernel_path, "%s", flag_val['k']);
697        if (!does_file_exist(bkpinfo->kernel_path)) {
698            retval++;
699            log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path);
700        }
701    }
702
703    if (flag_set['p']) {
704        mr_free(bkpinfo->prefix);
705        mr_asprintf(bkpinfo->prefix, "%s", flag_val['p']);
706        log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
707    }
708
709    if (flag_set['d']) {        /* backup directory (if ISO/NETFS) */
710        if (flag_set['i']) {
711            mr_free(bkpinfo->isodir);
712            mr_asprintf(bkpinfo->isodir, "%s", flag_val['d']);
713            mr_asprintf(tmp1, "ls -l %s", bkpinfo->isodir);
714            if (run_program_and_log_output(tmp1, 2)) {
715                mr_free(tmp1);
716                fatal_error("output folder does not exist - please create it");
717            }
718            mr_free(tmp1);
719        } else if (flag_set['n']) {
720            mr_free(bkpinfo->netfs_remote_dir);
721            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
722        } else {                /* backup device (if tape/CD-R/CD-RW) */
723            mr_free(bkpinfo->media_device);
724            mr_asprintf(bkpinfo->media_device, "%s", flag_val['d']);
725        }
726    }
727
728    if ((flag_set['n']) && (! bkpinfo->restore_data)) {
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);
732        } else {
733            mr_asprintf(tmp2, "echo hi > %s", tmp1);
734        }
735        i = run_program_and_log_output(tmp2, 2);
736        mr_free(tmp2);
737
738        if (i) {
739            retval++;
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);
741        }
742        unlink(tmp1);
743        mr_free(tmp1);
744    }
745
746    if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
747        if (g_kernel_version >= 2.6) {
748            tmp2 = popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device);
749            if (tmp2 == NULL) {
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) {
756                retval++;
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);
761            }
762        }
763    }
764
765    if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
766        retval++;
767        log_to_screen("Please specify the backup device/directory.\n");
768        fatal_error("You didn't use -d to specify the backup device/directory.");
769    }
770
771    for (i = '0'; i <= '9'; i++) {
772        if (flag_set[i]) {
773            bkpinfo->compression_level = i - '0';
774        }                       /* not '\0' but '0' */
775    }
776
777    if (flag_set['S']) {
778        /* Before changing remove old ones if any */
779        if (bkpinfo->scratchdir) {
780            chdir("/tmp");
781            mr_asprintf(tmp1, "rm -Rf %s", bkpinfo->scratchdir);
782            paranoid_system(tmp1);
783            mr_free(tmp1);
784        }
785        mr_asprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], random() % 32768);
786    }
787
788    if (flag_set['T']) {
789        setup_tmpdir(flag_val['T']);
790        mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir);
791        i = run_program_and_log_output(tmp1, 1);
792        mr_free(tmp1);
793
794        if (i) {
795            log_to_screen("Please specify a tempdir which I can write to. :)");
796            fatal_error("I cannot write to the tempdir you specified.");
797        }
798        mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
799        i = run_program_and_log_output(tmp1, 1);
800        mr_free(tmp1);
801
802        if (i) {
803            retval++;
804            log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
805            fatal_error("I cannot write to the tempdir you specified.");
806        }
807    }
808
809    if ((flag_set['A']) && (! bkpinfo->restore_data)) {
810        mr_asprintf(bkpinfo->call_after_iso, "%s", flag_val['A']);
811    }
812
813    if ((flag_set['B']) && (! bkpinfo->restore_data)) {
814        mr_asprintf(bkpinfo->call_before_iso, "%s", flag_val['B']);
815    }
816
817    if ((flag_set['H']) && (! bkpinfo->restore_data)) {
818        g_cd_recovery = TRUE;
819    }
820
821    if ((flag_set['l']) && (! bkpinfo->restore_data)) {
822#ifdef __FreeBSD__
823#  define BOOT_LOADER_CHARS "GLBMR"
824#else
825#  ifdef __IA64__
826#    define BOOT_LOADER_CHARS "GER"
827#  else
828#    define BOOT_LOADER_CHARS "GLR"
829#  endif
830#endif
831        if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) {
832            log_msg(1, "%c? What is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader);
833            fatal_error("Please specify GRUB, LILO, ELILO  or RAW with the -l switch");
834        }
835#undef BOOT_LOADER_CHARS
836    }
837
838    if (flag_set['f']) {
839        mr_free(bkpinfo->boot_device);
840        bkpinfo->boot_device = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
841    }
842
843    if ((flag_set['P']) && (! bkpinfo->restore_data)) {
844        mr_free(bkpinfo->postnuke_tarball);
845        mr_asprintf(bkpinfo->postnuke_tarball, "%s", flag_val['P']);
846    }
847
848    if (flag_set['Q']) {
849        i = which_boot_loader(NULL);
850        log_msg(3, "boot loader is %c", i);
851        printf("boot loader is %c\n", i);
852        finish(0);
853    }
854
855    if ((flag_set['L']) && (! bkpinfo->restore_data)) {
856        bkpinfo->use_lzo = TRUE;
857        if (run_program_and_log_output("which lzop", 2)) {
858            retval++;
859            log_to_screen("Please install LZOP. You can't use '-L' until you do.\n");
860        }
861    }
862
863    if ((flag_set['G']) && (! bkpinfo->restore_data)) {
864        bkpinfo->use_gzip = TRUE;
865        if (run_program_and_log_output("which gzip", 2)) {
866            retval++;
867            log_to_screen("Please install gzip. You can't use '-G' until you do.\n");
868        }
869    }
870
871    if ((flag_set['Y']) && (! bkpinfo->restore_data)) {
872        bkpinfo->use_lzma = TRUE;
873        if (run_program_and_log_output("which lzma", 2)) {
874            retval++;
875            log_to_screen("Please install lzma. You can't use '-Y' until you do.\n");
876        }
877    }
878
879    bkpinfo->use_obdr = FALSE;
880    if (flag_set['o']) {
881        if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
882            log_to_screen("OBDR support is only available for tapes. Use the -t option");
883            fatal_error("Aborting");
884        }
885        bkpinfo->use_obdr = TRUE;
886    }
887
888#ifndef __FreeBSD__
889    if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
890        bkpinfo->make_cd_use_lilo = TRUE;
891        log_to_screen("Your kernel appears not to support vfat filesystems. I am therefore");
892        log_to_screen("using LILO instead of SYSLINUX as the media boot loader.");
893    }
894    if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
895        bkpinfo->make_cd_use_lilo = TRUE;
896#ifdef __IA32__
897        log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
898        log_to_screen("your boot loader. I shall therefore use LILO instead.");
899#endif
900#ifdef __IA64__
901        log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
902        log_to_screen("environment correctly. Please install it.");
903        fatal_error("Aborting");
904#endif
905    }
906#ifdef __IA64__
907    /* We force ELILO usage on IA64 */
908    bkpinfo->make_cd_use_lilo = TRUE;
909#endif
910#endif
911
912    if (! bkpinfo->restore_data) {
913        i = flag_set['O'] + flag_set['V'];
914        if (i == 0) {
915            retval++;
916            log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
917        }
918    }
919
920    if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
921            fatal_error("The -Z switch is only valid in restore mode");
922    }
923
924    if (flag_set['Z']) {
925        if (! strcmp(flag_val['Z'], "nuke")) {
926            bkpinfo->restore_mode = nuke;
927        } else if (! strcmp(flag_val['Z'], "interactive")) {
928            bkpinfo->restore_mode = interactive;
929        } else if (! strcmp(flag_val['Z'], "compare")) {
930            bkpinfo->restore_mode = compare;
931        } else if (! strcmp(flag_val['Z'], "mbr")) {
932            bkpinfo->restore_mode = mbr;
933        } else if (! strcmp(flag_val['Z'], "iso")) {
934            bkpinfo->restore_mode = isoonly;
935        } else if (! strcmp(flag_val['Z'], "isonuke")) {
936            bkpinfo->restore_mode = isonuke;
937        } else {
938            bkpinfo->restore_mode = interactive;
939        }
940    }
941
942/* and finally... */
943
944    return (retval);
945}
946
947
948
949/**
950 * Get the switches from @p argc and @p argv using getopt() and place them in
951 * @p flag_set and @p flag_val.
952 * @param argc The argument count (@p argc passed to main()).
953 * @param argv The argument vector (@p argv passed to main()).
954 * @param flag_val An array indexed by switch letter - if a switch is set and
955 * has an argument then set flag_val[switch] to that argument.
956 * @param flag_set An array indexed by switch letter - if a switch is set then
957 * set flag_set[switch] to TRUE, else set it to FALSE.
958 * @return The number of problems with the command line (0 for success).
959 */
960int retrieve_switches_from_command_line(int argc, char *argv[], char flag_val[128][MAX_STR_LEN], bool flag_set[128])
961{
962    /*@ ints ** */
963    int opt = 0;
964    int i = 0;
965    int len;
966
967    /*@ bools *** */
968    bool bad_switches = FALSE;
969
970    assert(flag_val != NULL);
971    assert(flag_set != NULL);
972
973    for (i = 0; i < 128; i++) {
974        flag_val[i][0] = '\0';
975        flag_set[i] = FALSE;
976    }
977    while ((opt = getopt(argc, argv, MONDO_OPTIONS)) != -1) {
978        if (opt == '?') {
979            bad_switches = TRUE;
980        } else {
981            if (flag_set[opt]) {
982                bad_switches = TRUE;
983                log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]);
984            } else {
985                flag_set[opt] = TRUE;
986                if (optarg) {
987                    len = strlen(optarg);
988                    if (optarg[0] != '/' && optarg[len - 1] == '/') {
989                        optarg[--len] = '\0';
990                        log_to_screen
991                            ("Warning - param '%s' should not have trailing slash!",
992                             optarg);
993                    }
994                    if (opt == 'd') {
995                        if (strchr(flag_val[opt], '/')
996                            && flag_val[opt][0] != '/') {
997                            log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
998                            bad_switches = TRUE;
999                        }
1000                    }
1001                    strcpy(flag_val[opt], optarg);
1002                }
1003            }
1004        }
1005    }
1006    for (i = optind; i < argc; i++) {
1007        bad_switches = TRUE;
1008        log_to_screen("Invalid arg -- %s\n", argv[i]);
1009    }
1010    return (bad_switches);
1011}
1012
1013
1014
1015
1016/**
1017 * Print a not-so-helpful help message and exit.
1018 */
1019void help_screen()
1020{
1021    log_msg(1, "Type 'man mondoarchive' for more information\n");
1022    exit(1);
1023}
1024
1025
1026/**
1027 * Terminate Mondo in response to a signal.
1028 * @param sig The signal number received.
1029 */
1030void terminate_daemon(int sig)
1031{
1032    char *tmp = NULL;
1033    char *tmp2 = NULL;
1034
1035    switch (sig) {
1036    case SIGINT:
1037        mr_asprintf(tmp, "SIGINT");
1038        mr_asprintf(tmp2, "You interrupted me :-)");
1039        break;
1040    case SIGKILL:
1041        mr_asprintf(tmp, "SIGKILL");
1042        mr_asprintf(tmp2, "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
1043        break;
1044    case SIGTERM:
1045        mr_asprintf(tmp, "SIGTERM");
1046        mr_asprintf(tmp2, "Got terminate signal");
1047        break;
1048    case SIGHUP:
1049        mr_asprintf(tmp, "SIGHUP");
1050        mr_asprintf(tmp2, "Hangup on line");
1051        break;
1052    case SIGSEGV:
1053        mr_asprintf(tmp, "SIGSEGV");
1054        mr_asprintf(tmp2, "Internal programming error. Please send a backtrace as well as your log.");
1055        break;
1056    case SIGPIPE:
1057        mr_asprintf(tmp, "SIGPIPE");
1058        mr_asprintf(tmp2, "Pipe was broken");
1059        break;
1060    case SIGABRT:
1061        mr_asprintf(tmp, "SIGABRT");
1062        mr_asprintf(tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
1063        break;
1064    default:
1065        mr_asprintf(tmp, "(Unknown)");
1066        mr_asprintf(tmp2, "(Unknown)");
1067    }
1068
1069    mr_strcat(tmp, " signal received from OS");
1070    log_to_screen(tmp);
1071    mr_free(tmp);
1072
1073    log_to_screen(tmp2);
1074    mr_free(tmp2);
1075    if (sig == SIGABRT) {
1076        sleep(10);
1077    }
1078    kill_buffer();
1079
1080    free_MR_global_filenames();
1081
1082    fatal_error("MondoRescue is terminating in response to a signal from the OS");
1083    finish(254);                // just in case
1084}
1085
1086
1087
1088
1089/**
1090 * Turn signal-trapping on or off.
1091 * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
1092 */
1093void set_signals(int on)
1094{
1095    int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
1096    int i;
1097
1098    signal(SIGPIPE, sigpipe_occurred);
1099    for (i = 0; signals[i]; i++) {
1100        if (on) {
1101            signal(signals[i], terminate_daemon);
1102        } else {
1103            signal(signals[i], termination_in_progress);
1104        }
1105    }
1106}
1107
1108
1109
1110
1111/**
1112 * Exit immediately without cleaning up.
1113 * @param sig The signal we are exiting due to.
1114 */
1115void termination_in_progress(int sig)
1116{
1117    log_msg(1, "Termination in progress");
1118    usleep(1000);
1119    pthread_exit(0);
1120}
1121
1122/* @} - end of cliGroup */
Note: See TracBrowser for help on using the repository browser.