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

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

svn merge (in svk) -r 2714:2773 2.2.9 in 2.2.10

r4207@localhost (orig r2716): bruno | 2011-02-03 01:29:51 +0100

  • Increase boot size again to support better fedora 13/14


r4208@localhost (orig r2717): bruno | 2011-02-12 15:43:36 +0100

  • Excluding vmhgfs FS for VMWare guests mounting areas of the host.


r4209@localhost (orig r2718): bruno | 2011-02-18 00:30:35 +0100
-Extend EXTRA-SIZE for Debian 6.0 (at least)


r4210@localhost (orig r2719): bruno | 2011-02-18 00:45:40 +0100

  • Fix #462 (removes temp dir if analyze-my-lvm launched in stand alonae mode)


r4213@localhost (orig r2722): bruno | 2011-02-25 18:44:47 +0100

  • Fixes for RHEL6 support at least around dm extensions, bnx2x and cp210x dependencies


r4214@localhost (orig r2723): bruno | 2011-02-25 19:00:17 +0100

  • Adds a restore quiet option


r4215@localhost (orig r2724): bruno | 2011-02-25 19:43:50 +0100

  • Adds support for dm-log used on RHEL6 as well.


r4216@localhost (orig r2725): bruno | 2011-02-25 21:26:54 +0100

  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3


r4217@localhost (orig r2726): bruno | 2011-02-26 11:38:29 +0100

  • Fix error introduced in previous patch in the if/then/else case without member in the then


r4218@localhost (orig r2727): bruno | 2011-02-26 12:05:33 +0100

  • With mindi-busybox 1.18.3 the syntax of openvt changed. This patch keeps a compatible init script for both previous and current version.


r4219@localhost (orig r2728): bruno | 2011-02-26 15:27:40 +0100

  • Latest lvdisplay print MiB instead of MB. Impact on analyze-my-lvm fixed.


r4220@localhost (orig r2729): bruno | 2011-02-26 16:39:32 +0100

  • Adds feature rpc to mindi-busybox in case of need



r4221@localhost (orig r2730): bruno | 2011-02-26 16:42:43 +0100

  • Adds the rebot command to the list of mandatory ones at restore time


r4222@localhost (orig r2731): bruno | 2011-02-26 17:37:13 +0100

  • Adds functions and /bin/loadkeys (new location) to minimal set of commands to have
  • provides a makemessage option to mindi and this function now works with pbdistrocheck
  • Do not create an error when a phys device has 0 size and is a /dev/dm-* device


r4223@localhost (orig r2732): bruno | 2011-02-26 19:07:43 +0100

  • Syntax fix


r4224@localhost (orig r2733): bruno | 2011-02-26 19:51:16 +0100

  • Fix test on dm which was made in wrong sense
  • Adds a driver to allow raid456 to work


r4225@localhost (orig r2734): bruno | 2011-02-26 20:55:00 +0100

  • Fix 2 redirections issues


r4317@localhost (orig r2737): bruno | 2011-03-13 13:12:57 +0100

  • Add support for libahci driver, mandatory for debian 6.


r4318@localhost (orig r2738): bruno | 2011-03-13 14:46:37 +0100

  • Update from Lester Wade (lester.wade_at_hp.com) incorporating latest ML feedbacks


r4319@localhost (orig r2739): bruno | 2011-03-13 17:49:15 +0100

  • Updated Lab for TES 2011


r4323@localhost (orig r2743): bruno | 2011-03-20 01:37:40 +0100

  • Fix a seg fault bug when using the GUI in case exclude_paths was NULL (mc_at_carreira.com.pt)


r4324@localhost (orig r2744): bruno | 2011-03-20 19:38:14 +0100

  • Adds Arch Linux Keyboard support (mc_at_carreira.com.pt)


r4325@localhost (orig r2745): bruno | 2011-03-20 19:48:01 +0100

  • Avoids coredump again when exclude_path is NULL with mr_make_devlist_from_pathlist (feedback from mc_at_carreira.com.pt)


r4326@localhost (orig r2746): bruno | 2011-03-20 19:39:47 +0100

  • Remove blkid from busybox to solve #435


r4327@localhost (orig r2747): bruno | 2011-03-20 19:43:22 +0100

  • Adds reboot to fix #435


r4328@localhost (orig r2748): bruno | 2011-03-22 00:58:07 +0100

  • Fix Arch Linux kbd printed in log file now instead of screen.


r4329@localhost (orig r2749): bruno | 2011-03-22 00:59:58 +0100

  • Again increase size for boot env to support better fedora 14 and other latest distros


r4356@localhost (orig r2750): bruno | 2011-03-25 19:30:01 +0100

  • Improve Arch Linux support for mindi tools (mc_at_carreira.com.pt)


r4357@localhost (orig r2751): bruno | 2011-03-25 19:48:33 +0100

  • Accept to work with either wodim or cdreord and genisoimage or mkisofs


r4358@localhost (orig r2752): bruno | 2011-03-25 20:20:49 +0100

  • Documents option -v of mondoarchive


r4359@localhost (orig r2753): bruno | 2011-03-29 01:34:30 +0200

  • Use modprobe instead of insmod to load loop, cd, ... modules (in order to force them at rstore time). Also drop very old aes support for mdk 9.2


r4360@localhost (orig r2754): bruno | 2011-03-29 01:38:49 +0200

  • Arch Linux support for boot message of mindi (mc_at_carreira.com.pt) using /etc/arch-release and pacman.log


r4383@localhost (orig r2755): bruno | 2011-04-07 09:49:38 +0200

  • Adds a UdevadmTrigger function at restore time to deal with the various syntax formats changes ddepending on version (mc_at_carreira.com.pt)


r4384@localhost (orig r2756): bruno | 2011-04-07 10:05:24 +0200

  • Increase again sizes for Debian 6 support (victor.gattegno_at_hp.com)


r4385@localhost (orig r2757): bruno | 2011-04-07 10:13:00 +0200
Conform to the report of size really !


r4386@localhost (orig r2758): bruno | 2011-04-07 11:31:12 +0200

  • Improved message for Arch Linux for rebuilding the initrd (mc_at_carreira.com.pt)


r4390@localhost (orig r2759): bruno | 2011-04-12 01:15:00 +0200

  • Typo in Web site


r4392@localhost (orig r2761): bruno | 2011-04-14 00:23:38 +0200

  • Adds download references for latest versions.


r4394@localhost (orig r2763): bruno | 2011-04-16 00:35:08 +0200

  • Adds support for MT back mandatory for OBDR.


r4395@localhost (orig r2764): bruno | 2011-04-20 12:18:46 +0200
Function resize_drive_proportionately_to_suit_new_drives

  • Integrate some mr_asprintf
  • Use systematically long long data types in all computation to match the struct mountlist_reference size member and have correct precision
  • Apply JB general_at_itpsg.com patch to make the partition resizing work properly according to the drive size (keeping all calculation in KB and converting only for display)


r4396@localhost (orig r2765): bruno | 2011-04-21 11:20:58 +0200

  • Remove very old code creating confusing symlinks pico to nano in init (patch from MC). Fix #477


r4397@localhost (orig r2766): bruno | 2011-04-21 11:57:44 +0200

  • text's are properly centered in open_and_list_dir (Patch from Chucky). Fix #404.


r4398@localhost (orig r2767): bruno | 2011-04-21 12:49:40 +0200

  • Attempt to fix #432 with a better message at a start.


r4399@localhost (orig r2768): bruno | 2011-04-21 13:00:37 +0200

Log content of mondo-restore.cfg


r4400@localhost (orig r2769): bruno | 2011-04-21 13:48:52 +0200

  • Introduce a new bkpinfo member (subdir) to support storing the subdir under which ISO images are stored on an external HDD. Should fix mostly #433.


r4401@localhost (orig r2770): bruno | 2011-04-21 14:14:52 +0200

  • Fix compilation issues due to level of visibility of functions


r4402@localhost (orig r2771): bruno | 2011-04-22 01:49:03 +0200

  • Adds GUI support for compresion type. Fix half of #468.


r4403@localhost (orig r2772): bruno | 2011-04-22 02:00:07 +0200

  • Adds support of ext attr through the GUI. Fix second part of #468


r4404@localhost (orig r2773): bruno | 2011-04-22 02:22:24 +0200

  • Propose more variables in the mindi.conf example
  • More explicit messages when size unsufficient in mindi for kernel + initrd as per #471
  • Better loging of labeling in mondo when in nuke mode


  • Property svn:keywords set to Id
File size: 31.0 KB
Line 
1/***************************************************************************
2$Id: libmondo-cli.c 2816 2011-04-29 13:42:55Z 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 \"^[%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 (strstr(bkpinfo->netfs_proto, "sshfs")) {
498 mr_asprintf(tmp1, "sshfs %s", bkpinfo->netfs_mount);
499 } else if (strstr(bkpinfo->netfs_proto, "nfs")) {
500 mr_asprintf(tmp1, "mount %s", bkpinfo->netfs_mount);
501 } else {
502 log_to_screen("Protocol %s not supported yet for network backups.\n", bkpinfo->netfs_proto);
503 fatal_error("Bad Protocol\n");
504 }
505 i = system(tmp1);
506 mr_free(tmp1);
507 if (i) {
508 log_to_screen("Unable to mount Network share %s. Please mount manually.\n", bkpinfo->netfs_mount);
509 retval++;
510 } else {
511 mr_asprintf(tmp1, "mount | grep -E \"^[%s@]*%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_user, bkpinfo->netfs_mount);
512 mr_free(bkpinfo->isodir);
513 bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1,TRUE);
514 mr_free(tmp1);
515
516 if (strlen(bkpinfo->isodir) < 3) {
517 retval++;
518 log_to_screen("Network share %s is strangely not mounted. Please mount manually...\n", bkpinfo->netfs_mount);
519 }
520 }
521 }
522 log_msg(3, "proto = %s", bkpinfo->netfs_proto);
523 log_msg(3, "mount = %s", bkpinfo->netfs_mount);
524 if (bkpinfo->netfs_user) {
525 log_msg(3, "user = %s", bkpinfo->netfs_user);
526 }
527 log_msg(3, "isodir= %s", bkpinfo->isodir);
528 }
529
530 if (flag_set['c']) {
531 bkpinfo->backup_media_type = cdr;
532 }
533 if (flag_set['C']) {
534 bkpinfo->backup_media_type = cdstream;
535 }
536 if (flag_set['i']) {
537 bkpinfo->backup_media_type = iso;
538 }
539 if (flag_set['n']) {
540 bkpinfo->backup_media_type = netfs;
541 /* Never try to eject a Network device */
542 bkpinfo->please_dont_eject = TRUE;
543 }
544 if (flag_set['r']) {
545 bkpinfo->backup_media_type = dvd;
546 }
547 if (flag_set['t']) {
548 bkpinfo->backup_media_type = tape;
549 }
550 if (flag_set['u']) {
551 bkpinfo->backup_media_type = udev;
552 }
553 if (flag_set['w']) {
554 bkpinfo->backup_media_type = cdrw;
555 }
556 if (flag_set['U']) {
557 bkpinfo->backup_media_type = usb;
558 /* Never try to eject a USB device */
559 bkpinfo->please_dont_eject = TRUE;
560 }
561 if (flag_set['z']) {
562 tmp1 = find_home_of_exe("getfattr");
563 if (tmp1) {
564 mr_asprintf(g_getfattr,"getfattr");
565 }
566 mr_free(tmp1);
567
568 tmp1 = find_home_of_exe("getfacl");
569 if (tmp1) {
570 mr_asprintf(g_getfacl,"getfacl");
571 }
572 mr_free(tmp1);
573 }
574
575 /* optional, popular */
576 if (flag_set['g']) {
577 g_text_mode = FALSE;
578 }
579
580 if (flag_set['E']) {
581 if (bkpinfo->exclude_paths && bkpinfo->exclude_paths[0] == '-') {
582 retval++;
583 log_to_screen("Please supply a sensible value with '-E'\n");
584 }
585 mr_asprintf(tmp1, "%s", flag_val['E']);
586
587 p = tmp1;
588 q = tmp1;
589
590 /* Cut the flag_val['E'] in parts containing all paths to test them */
591 while (p != NULL) {
592 q = strchr(p, '|');
593 if (q != NULL) {
594 *q = '\0';
595 /* Fix bug 14 where ending / cause a problem later
596 * so handled here for the moment */
597 q--;
598 if (*q == '/') {
599 *q = '\0';
600 }
601 q++;
602 /* End of bug fix */
603 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
604 log_msg(1, "WARNING ! %s doesn't exist", p);
605 }
606 p = q+1 ;
607 } else {
608 if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
609 log_msg(1, "WARNING ! %s doesn't exist", p);
610 }
611 p = NULL;
612 }
613 }
614 mr_free(tmp1);
615 lastpos = 0;
616
617 mr_make_devlist_from_pathlist(flag_val['E'], 'E');
618 log_msg(4, "Finished with the -E option");
619 }
620
621 if (flag_set['e']) {
622 bkpinfo->please_dont_eject = TRUE;
623 }
624
625 if ((flag_set['N']) && (! bkpinfo->restore_data)) // exclude Network mounts & devices
626 {
627 psz = list_of_NETFS_mounts_only();
628 log_msg(5, "-N means we'll exclude %s", psz);
629 if (bkpinfo->exclude_paths) {
630 mr_strcat(bkpinfo->exclude_paths, "|%s", psz);
631 mr_free(psz);
632 } else {
633 bkpinfo->exclude_paths = psz;
634 }
635
636 if (bkpinfo->exclude_paths != NULL) {
637 log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths);
638 }
639 }
640
641 if (flag_set['b']) {
642 mr_asprintf(psz, "%s", flag_val['b']);
643 log_msg(1, "psz = '%s'", psz);
644 if (psz[strlen(psz) - 1] == 'k') {
645 psz[strlen(psz) - 1] = '\0';
646 itbs = atol(psz) * 1024L;
647 } else {
648 itbs = atol(psz);
649 }
650 mr_free(psz);
651 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
652 log_msg(1, "Internal tape block size is now %ld bytes", itbs);
653 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
654 fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
655 }
656 bkpinfo->internal_tape_block_size = itbs;
657 }
658
659 if ((flag_set['D']) && (! bkpinfo->restore_data)) {
660 bkpinfo->differential = 1;
661// bkpinfo->differential = atoi (flag_val['D']);
662 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) {
663 fatal_error("The D option should be between 1 and 9 inclusive");
664 }
665 }
666
667 if (flag_set['x']) {
668 mr_asprintf(bkpinfo->image_devs, "%s", flag_val['x']);
669 if ((run_program_and_log_output("which ntfsclone", 2)) && (! bkpinfo->restore_data)) {
670 fatal_error("Please install ntfsprogs package/tarball.");
671 }
672 }
673
674 if (flag_set['m']) {
675 bkpinfo->manual_cd_tray = TRUE;
676 }
677
678 if ((flag_set['k']) && (! bkpinfo->restore_data)) {
679 mr_free(bkpinfo->kernel_path);
680 mr_asprintf(bkpinfo->kernel_path, "%s", flag_val['k']);
681 if (!does_file_exist(bkpinfo->kernel_path)) {
682 retval++;
683 log_to_screen("You specified kernel '%s', which does not exist\n", bkpinfo->kernel_path);
684 }
685 }
686
687 if (flag_set['p']) {
688 mr_free(bkpinfo->prefix);
689 mr_asprintf(bkpinfo->prefix, "%s", flag_val['p']);
690 log_msg(1,"Prefix forced to %s",bkpinfo->prefix);
691 }
692
693 if (flag_set['d']) { /* backup directory (if ISO/NETFS) */
694 if (flag_set['i']) {
695 mr_free(bkpinfo->isodir);
696 mr_asprintf(bkpinfo->isodir, "%s", flag_val['d']);
697 mr_asprintf(tmp1, "ls -l %s", bkpinfo->isodir);
698 if (run_program_and_log_output(tmp1, 2)) {
699 mr_free(tmp1);
700 fatal_error("output folder does not exist - please create it");
701 }
702 mr_free(tmp1);
703 } else if (flag_set['n']) {
704 mr_free(bkpinfo->netfs_remote_dir);
705 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
706 } else { /* backup device (if tape/CD-R/CD-RW) */
707 mr_free(bkpinfo->media_device);
708 mr_asprintf(bkpinfo->media_device, "%s", flag_val['d']);
709 }
710 }
711
712 if ((flag_set['n']) && (! bkpinfo->restore_data)) {
713 mr_asprintf(tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->netfs_remote_dir);
714 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
715 mr_asprintf(tmp2, "su - %s -c \"echo hi > %s\"", bkpinfo->netfs_user, tmp1);
716 } else {
717 mr_asprintf(tmp2, "echo hi > %s", tmp1);
718 }
719 i = run_program_and_log_output(tmp2, 2);
720 mr_free(tmp2);
721
722 if (i) {
723 retval++;
724 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);
725 }
726 unlink(tmp1);
727 mr_free(tmp1);
728 }
729
730 if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
731 if (g_kernel_version >= 2.6) {
732 tmp2 = popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device);
733 if (tmp2 == NULL) {
734 fatal_error("User opted to cancel.");
735 }
736 bkpinfo->media_device = tmp2;
737 } else {
738 bkpinfo->media_device = find_cdrw_device();
739 if (bkpinfo->media_device == NULL) {
740 retval++;
741 log_to_screen("Tried and failed to find CD-R[W] drive automatically.\n");
742 } else {
743 flag_set['d'] = TRUE;
744 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
745 }
746 }
747 }
748
749 if ((!flag_set['d'] && !flag_set['n'] && !flag_set['C']) && (! bkpinfo->restore_data)) {
750 retval++;
751 log_to_screen("Please specify the backup device/directory.\n");
752 fatal_error("You didn't use -d to specify the backup device/directory.");
753 }
754
755 for (i = '0'; i <= '9'; i++) {
756 if (flag_set[i]) {
757 bkpinfo->compression_level = i - '0';
758 } /* not '\0' but '0' */
759 }
760
761 if (flag_set['S']) {
762 mr_asprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], random() % 32768);
763 }
764
765 if (flag_set['T']) {
766 setup_tmpdir(flag_val['T']);
767 mr_asprintf(tmp1, "touch %s/.foo.dat", bkpinfo->tmpdir);
768 i = run_program_and_log_output(tmp1, 1);
769 mr_free(tmp1);
770
771 if (i) {
772 log_to_screen("Please specify a tempdir which I can write to. :)");
773 fatal_error("I cannot write to the tempdir you specified.");
774 }
775 mr_asprintf(tmp1, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
776 i = run_program_and_log_output(tmp1, 1);
777 mr_free(tmp1);
778
779 if (i) {
780 retval++;
781 log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir.");
782 fatal_error("I cannot write to the tempdir you specified.");
783 }
784 }
785
786 if ((flag_set['A']) && (! bkpinfo->restore_data)) {
787 mr_asprintf(bkpinfo->call_after_iso, "%s", flag_val['A']);
788 }
789
790 if ((flag_set['B']) && (! bkpinfo->restore_data)) {
791 mr_asprintf(bkpinfo->call_before_iso, "%s", flag_val['B']);
792 }
793
794 if ((flag_set['H']) && (! bkpinfo->restore_data)) {
795 g_cd_recovery = TRUE;
796 }
797
798 if ((flag_set['l']) && (! bkpinfo->restore_data)) {
799#ifdef __FreeBSD__
800# define BOOT_LOADER_CHARS "GLBMR"
801#else
802# ifdef __IA64__
803# define BOOT_LOADER_CHARS "GER"
804# else
805# define BOOT_LOADER_CHARS "GLR"
806# endif
807#endif
808 if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) {
809 log_msg(1, "%c? What is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader);
810 fatal_error("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
811 }
812#undef BOOT_LOADER_CHARS
813 }
814
815 if (flag_set['f']) {
816 mr_free(bkpinfo->boot_device);
817 bkpinfo->boot_device = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
818 }
819
820 if ((flag_set['P']) && (! bkpinfo->restore_data)) {
821 mr_free(bkpinfo->postnuke_tarball);
822 mr_asprintf(bkpinfo->postnuke_tarball, "%s", flag_val['P']);
823 }
824
825 if (flag_set['Q']) {
826 i = which_boot_loader(NULL);
827 log_msg(3, "boot loader is %c", i);
828 printf("boot loader is %c\n", i);
829 finish(0);
830 }
831
832 if ((flag_set['L']) && (! bkpinfo->restore_data)) {
833 bkpinfo->use_lzo = TRUE;
834 if (run_program_and_log_output("which lzop", 2)) {
835 retval++;
836 log_to_screen("Please install LZOP. You can't use '-L' until you do.\n");
837 }
838 }
839
840 if ((flag_set['G']) && (! bkpinfo->restore_data)) {
841 bkpinfo->use_gzip = TRUE;
842 if (run_program_and_log_output("which gzip", 2)) {
843 retval++;
844 log_to_screen("Please install gzip. You can't use '-G' until you do.\n");
845 }
846 }
847
848 if ((flag_set['Y']) && (! bkpinfo->restore_data)) {
849 bkpinfo->use_lzma = TRUE;
850 if (run_program_and_log_output("which lzma", 2)) {
851 retval++;
852 log_to_screen("Please install lzma. You can't use '-Y' until you do.\n");
853 }
854 }
855
856 bkpinfo->use_obdr = FALSE;
857 if (flag_set['o']) {
858 if ((!flag_set['t']) && (! bkpinfo->restore_data)) {
859 log_to_screen("OBDR support is only available for tapes. Use the -t option");
860 fatal_error("Aborting");
861 }
862 bkpinfo->use_obdr = TRUE;
863 }
864
865#ifndef __FreeBSD__
866 if ((!is_this_a_valid_disk_format("vfat")) && (! bkpinfo->restore_data)) {
867 bkpinfo->make_cd_use_lilo = TRUE;
868 log_to_screen("Your kernel appears not to support vfat filesystems. I am therefore");
869 log_to_screen("using LILO instead of SYSLINUX as the media boot loader.");
870 }
871 if ((run_program_and_log_output("which mkfs.vfat", 2)) && (! bkpinfo->restore_data)) {
872 bkpinfo->make_cd_use_lilo = TRUE;
873#ifdef __IA32__
874 log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as");
875 log_to_screen("your boot loader. I shall therefore use LILO instead.");
876#endif
877#ifdef __IA64__
878 log_to_screen("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI");
879 log_to_screen("environment correctly. Please install it.");
880 fatal_error("Aborting");
881#endif
882 }
883#ifdef __IA64__
884 /* We force ELILO usage on IA64 */
885 bkpinfo->make_cd_use_lilo = TRUE;
886#endif
887#endif
888
889 if (! bkpinfo->restore_data) {
890 i = flag_set['O'] + flag_set['V'];
891 if (i == 0) {
892 retval++;
893 log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n");
894 }
895 }
896
897 if ((! bkpinfo->restore_data) && (flag_set['Z'])) {
898 fatal_error("The -Z switch is only valid in restore mode");
899 }
900
901 if (flag_set['Z']) {
902 if (! strcmp(flag_val['Z'], "nuke")) {
903 bkpinfo->restore_mode = nuke;
904 } else if (! strcmp(flag_val['Z'], "interactive")) {
905 bkpinfo->restore_mode = interactive;
906 } else if (! strcmp(flag_val['Z'], "compare")) {
907 bkpinfo->restore_mode = compare;
908 } else if (! strcmp(flag_val['Z'], "mbr")) {
909 bkpinfo->restore_mode = mbr;
910 } else if (! strcmp(flag_val['Z'], "iso")) {
911 bkpinfo->restore_mode = isoonly;
912 } else if (! strcmp(flag_val['Z'], "isonuke")) {
913 bkpinfo->restore_mode = isonuke;
914 } else {
915 bkpinfo->restore_mode = interactive;
916 }
917 }
918
919/* and finally... */
920
921 return (retval);
922}
923
924
925
926/**
927 * Get the switches from @p argc and @p argv using getopt() and place them in
928 * @p flag_set and @p flag_val.
929 * @param argc The argument count (@p argc passed to main()).
930 * @param argv The argument vector (@p argv passed to main()).
931 * @param flag_val An array indexed by switch letter - if a switch is set and
932 * has an argument then set flag_val[switch] to that argument.
933 * @param flag_set An array indexed by switch letter - if a switch is set then
934 * set flag_set[switch] to TRUE, else set it to FALSE.
935 * @return The number of problems with the command line (0 for success).
936 */
937int retrieve_switches_from_command_line(int argc, char *argv[], char flag_val[128][MAX_STR_LEN], bool flag_set[128])
938{
939 /*@ ints ** */
940 int opt = 0;
941 int i = 0;
942 int len;
943
944 /*@ bools *** */
945 bool bad_switches = FALSE;
946
947 assert(flag_val != NULL);
948 assert(flag_set != NULL);
949
950 for (i = 0; i < 128; i++) {
951 flag_val[i][0] = '\0';
952 flag_set[i] = FALSE;
953 }
954 while ((opt = getopt(argc, argv, MONDO_OPTIONS)) != -1) {
955 if (opt == '?') {
956 bad_switches = TRUE;
957 } else {
958 if (flag_set[opt]) {
959 bad_switches = TRUE;
960 log_to_screen("Switch -%c previously defined as %s\n", opt, flag_val[opt]);
961 } else {
962 flag_set[opt] = TRUE;
963 if (optarg) {
964 len = strlen(optarg);
965 if (optarg[0] != '/' && optarg[len - 1] == '/') {
966 optarg[--len] = '\0';
967 log_to_screen
968 ("Warning - param '%s' should not have trailing slash!",
969 optarg);
970 }
971 if (opt == 'd') {
972 if (strchr(flag_val[opt], '/')
973 && flag_val[opt][0] != '/') {
974 log_to_screen("-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
975 bad_switches = TRUE;
976 }
977 }
978 strcpy(flag_val[opt], optarg);
979 }
980 }
981 }
982 }
983 for (i = optind; i < argc; i++) {
984 bad_switches = TRUE;
985 log_to_screen("Invalid arg -- %s\n", argv[i]);
986 }
987 return (bad_switches);
988}
989
990
991
992
993/**
994 * Print a not-so-helpful help message and exit.
995 */
996void help_screen()
997{
998 log_msg(1, "Type 'man mondoarchive' for more information\n");
999 exit(1);
1000}
1001
1002
1003/**
1004 * Terminate Mondo in response to a signal.
1005 * @param sig The signal number received.
1006 */
1007void terminate_daemon(int sig)
1008{
1009 char *tmp = NULL;
1010 char *tmp2 = NULL;
1011
1012 switch (sig) {
1013 case SIGINT:
1014 mr_asprintf(tmp, "SIGINT");
1015 mr_asprintf(tmp2, "You interrupted me :-)");
1016 break;
1017 case SIGKILL:
1018 mr_asprintf(tmp, "SIGKILL");
1019 mr_asprintf(tmp2, "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
1020 break;
1021 case SIGTERM:
1022 mr_asprintf(tmp, "SIGTERM");
1023 mr_asprintf(tmp2, "Got terminate signal");
1024 break;
1025 case SIGHUP:
1026 mr_asprintf(tmp, "SIGHUP");
1027 mr_asprintf(tmp2, "Hangup on line");
1028 break;
1029 case SIGSEGV:
1030 mr_asprintf(tmp, "SIGSEGV");
1031 mr_asprintf(tmp2, "Internal programming error. Please send a backtrace as well as your log.");
1032 break;
1033 case SIGPIPE:
1034 mr_asprintf(tmp, "SIGPIPE");
1035 mr_asprintf(tmp2, "Pipe was broken");
1036 break;
1037 case SIGABRT:
1038 mr_asprintf(tmp, "SIGABRT");
1039 mr_asprintf(tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
1040 break;
1041 default:
1042 mr_asprintf(tmp, "(Unknown)");
1043 mr_asprintf(tmp2, "(Unknown)");
1044 }
1045
1046 mr_strcat(tmp, " signal received from OS");
1047 log_to_screen(tmp);
1048 mr_free(tmp);
1049
1050 log_to_screen(tmp2);
1051 mr_free(tmp2);
1052 if (sig == SIGABRT) {
1053 sleep(10);
1054 }
1055 kill_buffer();
1056
1057 free_MR_global_filenames();
1058
1059 fatal_error("MondoRescue is terminating in response to a signal from the OS");
1060 finish(254); // just in case
1061}
1062
1063
1064
1065
1066/**
1067 * Turn signal-trapping on or off.
1068 * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
1069 */
1070void set_signals(int on)
1071{
1072 int signals[] = { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
1073 int i;
1074
1075 signal(SIGPIPE, sigpipe_occurred);
1076 for (i = 0; signals[i]; i++) {
1077 if (on) {
1078 signal(signals[i], terminate_daemon);
1079 } else {
1080 signal(signals[i], termination_in_progress);
1081 }
1082 }
1083}
1084
1085
1086
1087
1088/**
1089 * Exit immediately without cleaning up.
1090 * @param sig The signal we are exiting due to.
1091 */
1092void termination_in_progress(int sig)
1093{
1094 log_msg(1, "Termination in progress");
1095 usleep(1000);
1096 pthread_exit(0);
1097}
1098
1099/* @} - end of cliGroup */
Note: See TracBrowser for help on using the repository browser.