1 | /*************************************************************************** |
---|
2 | $Id: mondo-cli.c 1378 2007-04-30 13:14:47Z 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 "my-stuff.h" |
---|
13 | #include "mondostructures.h" |
---|
14 | #include "mondo-cli-EXT.h" |
---|
15 | #include "libmondo.h" |
---|
16 | #include <pthread.h> |
---|
17 | #include "mr_mem.h" |
---|
18 | #include "mr_msg.h" |
---|
19 | |
---|
20 | //static char cvsid[] = "$Id: mondo-cli.c 1378 2007-04-30 13:14:47Z bruno $"; |
---|
21 | |
---|
22 | extern int g_loglevel; |
---|
23 | extern bool g_text_mode; |
---|
24 | extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks |
---|
25 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ????? |
---|
26 | extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN]; |
---|
27 | extern char g_tmpfs_mountpt[MAX_STR_LEN]; |
---|
28 | extern bool g_sigpipe; |
---|
29 | |
---|
30 | /*@ file pointer **************************************************/ |
---|
31 | extern FILE *g_tape_stream; |
---|
32 | |
---|
33 | /*@ long long *****************************************************/ |
---|
34 | extern long long g_tape_posK; |
---|
35 | |
---|
36 | /*@ long **********************************************************/ |
---|
37 | extern long g_noof_sets; |
---|
38 | |
---|
39 | /*@ bool******** **************************************************/ |
---|
40 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup |
---|
41 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup |
---|
42 | extern bool g_cd_recovery; |
---|
43 | |
---|
44 | /** |
---|
45 | * Whether we're restoring from ISOs. Obviously not, since this is the |
---|
46 | * backup program. |
---|
47 | * @note You @b MUST declare this variable somewhere in your program if |
---|
48 | * you use libmondo. Otherwise the link will fail. |
---|
49 | * @ingroup globalGroup |
---|
50 | */ |
---|
51 | bool g_ISO_restore_mode = FALSE; |
---|
52 | |
---|
53 | extern double g_kernel_version; |
---|
54 | extern int g_current_media_number; |
---|
55 | extern pid_t g_main_pid; |
---|
56 | extern char *resolve_softlinks_to_get_to_actual_device_file(char *); |
---|
57 | |
---|
58 | /* Do we use extended attributes and acl ? |
---|
59 | * By default no, use --acl & --attr options to force their usage */ |
---|
60 | char *g_getfacl = NULL; |
---|
61 | char *g_getfattr = NULL; |
---|
62 | |
---|
63 | /** |
---|
64 | * @addtogroup cliGroup |
---|
65 | * @{ |
---|
66 | */ |
---|
67 | /** |
---|
68 | * Populate @p bkpinfo from the command-line parameters stored in @p argc and @p argv. |
---|
69 | * @param argc The argument count, including the program name; @p argc passed to main(). |
---|
70 | * @param argv The argument vector; @p argv passed to main(). |
---|
71 | * @param bkpinfo The backup information structure to populate. |
---|
72 | * @return The number of problems with the command line (0 for success). |
---|
73 | */ |
---|
74 | int |
---|
75 | handle_incoming_parameters(int argc, char *argv[], |
---|
76 | struct s_bkpinfo *bkpinfo) |
---|
77 | { |
---|
78 | /*@ int *** */ |
---|
79 | int res = 0; |
---|
80 | int retval = 0; |
---|
81 | int i = 0; |
---|
82 | |
---|
83 | /*@ buffers *************** */ |
---|
84 | char *tmp = NULL; |
---|
85 | char flag_val[128][MAX_STR_LEN]; |
---|
86 | bool flag_set[128]; |
---|
87 | |
---|
88 | sensibly_set_tmpdir_and_scratchdir(bkpinfo); |
---|
89 | |
---|
90 | for (i = 0; i < 128; i++) { |
---|
91 | flag_val[i][0] = '\0'; |
---|
92 | flag_set[i] = FALSE; |
---|
93 | } |
---|
94 | bkpinfo->media_size = (long)650; |
---|
95 | res = |
---|
96 | retrieve_switches_from_command_line(argc, argv, flag_val, |
---|
97 | flag_set); |
---|
98 | retval += res; |
---|
99 | if (!retval) { |
---|
100 | res = process_switches(bkpinfo, flag_val, flag_set); |
---|
101 | retval += res; |
---|
102 | } |
---|
103 | /* |
---|
104 | if (!retval) |
---|
105 | { |
---|
106 | */ |
---|
107 | mr_msg(3, "Switches:-"); |
---|
108 | for (i = 0; i < 128; i++) { |
---|
109 | if (flag_set[i]) { |
---|
110 | mr_msg(3, "-%c %s", i, flag_val[i]); |
---|
111 | } |
---|
112 | } |
---|
113 | // } |
---|
114 | mr_asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); |
---|
115 | paranoid_system(tmp); |
---|
116 | mr_free(tmp); |
---|
117 | |
---|
118 | mr_asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); |
---|
119 | paranoid_system(tmp); |
---|
120 | mr_free(tmp); |
---|
121 | |
---|
122 | sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", |
---|
123 | random() % 32767); |
---|
124 | sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), |
---|
125 | "/mondo.scratch.%ld", random() % 32767); |
---|
126 | |
---|
127 | mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); |
---|
128 | paranoid_system(tmp); |
---|
129 | mr_free(tmp); |
---|
130 | |
---|
131 | mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir); |
---|
132 | paranoid_system(tmp); |
---|
133 | mr_free(tmp); |
---|
134 | return (retval); |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | /** |
---|
139 | * Store the sizespec(s) stored in @p value into @p bkpinfo. |
---|
140 | * @param bkpinfo The backup information structure; the @c bkpinfo->media_size field will be populated. |
---|
141 | * @param value The sizespec (e.g. "2g", "40m"). |
---|
142 | * @return 0, always. |
---|
143 | * @bug Return code not needed. |
---|
144 | */ |
---|
145 | int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value) |
---|
146 | { |
---|
147 | char *tmp = NULL; |
---|
148 | char *p = NULL; |
---|
149 | char *q = NULL; |
---|
150 | |
---|
151 | assert(bkpinfo != NULL); |
---|
152 | assert(value != NULL); |
---|
153 | |
---|
154 | bkpinfo->media_size = 0L; /* dummy value */ |
---|
155 | for ( p = value; strchr(p, ','); p = strchr(p, ',') + 1) { |
---|
156 | mr_asprintf(&tmp, p); |
---|
157 | q = strchr(tmp, ','); |
---|
158 | if (q != NULL) { |
---|
159 | *q = '\0'; |
---|
160 | } |
---|
161 | bkpinfo->media_size = friendly_sizestr_to_sizelong(tmp); |
---|
162 | mr_free(tmp); |
---|
163 | |
---|
164 | mr_msg(3, "media_size = %ld", bkpinfo->media_size); |
---|
165 | } |
---|
166 | if (bkpinfo->media_size <= 0L) { |
---|
167 | mr_msg(1, "You gave media an invalid size\n"); |
---|
168 | return (-1); |
---|
169 | } |
---|
170 | return (0); |
---|
171 | } |
---|
172 | |
---|
173 | |
---|
174 | /** |
---|
175 | * Process mondoarchive's command-line switches. |
---|
176 | * @param bkpinfo The backup information structure to populate. |
---|
177 | * @param flag_val An array of the argument passed to each switch (the letter is the index). |
---|
178 | * If a switch is not set or has no argument, the field in @p flag_val doesn't matter. |
---|
179 | * @param flag_set An array of <tt>bool</tt>s indexed by switch letter: TRUE if it's set, |
---|
180 | * FALSE if it's not. |
---|
181 | * @return The number of problems with the switches, or 0 for success. |
---|
182 | * @bug Maybe include a list of all switches (inc. intentionally undocumented ones not in the manual!) here? |
---|
183 | */ |
---|
184 | int |
---|
185 | process_switches(struct s_bkpinfo *bkpinfo, |
---|
186 | char flag_val[128][MAX_STR_LEN], bool flag_set[128]) |
---|
187 | { |
---|
188 | |
---|
189 | /*@ ints *** */ |
---|
190 | int i = 0; |
---|
191 | int retval = 0; |
---|
192 | int percent = 0; |
---|
193 | |
---|
194 | /*@ buffers ** */ |
---|
195 | char *tmp = NULL; |
---|
196 | char *tmp1 = NULL; |
---|
197 | char *tmp2 = NULL; |
---|
198 | char *psz = NULL; |
---|
199 | char *p = NULL; |
---|
200 | char *q = NULL; |
---|
201 | |
---|
202 | long itbs = 0L; |
---|
203 | |
---|
204 | struct stat buf; |
---|
205 | |
---|
206 | malloc_string(tmp); |
---|
207 | |
---|
208 | assert(bkpinfo != NULL); |
---|
209 | assert(flag_val != NULL); |
---|
210 | assert(flag_set != NULL); |
---|
211 | |
---|
212 | bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; |
---|
213 | |
---|
214 | /* compulsory */ |
---|
215 | i = flag_set['c'] + flag_set['i'] + flag_set['n'] + |
---|
216 | flag_set['t'] + flag_set['u'] + flag_set['r'] + |
---|
217 | flag_set['w'] + flag_set['C'] + flag_set['U']; |
---|
218 | if (i == 0) { |
---|
219 | retval++; |
---|
220 | log_to_screen(_("You must specify the media type\n")); |
---|
221 | } |
---|
222 | if (i > 1) { |
---|
223 | retval++; |
---|
224 | log_to_screen(_("Please specify only one media type\n")); |
---|
225 | } |
---|
226 | if (flag_set['K']) { |
---|
227 | g_loglevel = atoi(flag_val['K']); |
---|
228 | if (g_loglevel < 3) { |
---|
229 | g_loglevel = 3; |
---|
230 | } |
---|
231 | } |
---|
232 | if (flag_set['L'] && flag_set['0']) { |
---|
233 | retval++; |
---|
234 | log_to_screen(_("You cannot have 'no compression' _and_ LZOP.\n")); |
---|
235 | } |
---|
236 | bkpinfo->backup_data = flag_set['O']; |
---|
237 | bkpinfo->verify_data = flag_set['V']; |
---|
238 | if (flag_set['I'] && !bkpinfo->backup_data) { |
---|
239 | log_to_screen(_("-I switch is ignored if just verifying")); |
---|
240 | } |
---|
241 | if (flag_set['E'] && !bkpinfo->backup_data) { |
---|
242 | log_to_screen(_("-E switch is ignored if just verifying")); |
---|
243 | } |
---|
244 | |
---|
245 | if (!find_home_of_exe("afio")) { |
---|
246 | if (find_home_of_exe("star")) { |
---|
247 | flag_set['R'] = TRUE; |
---|
248 | mr_msg(1, "Using star instead of afio"); |
---|
249 | } else { |
---|
250 | fatal_error |
---|
251 | ("Neither afio nor star is installed. Please install at least one."); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | if (flag_set['R']) { |
---|
256 | bkpinfo->use_star = TRUE; |
---|
257 | if (flag_set['L']) { |
---|
258 | fatal_error("You may not use star and lzop at the same time."); |
---|
259 | } |
---|
260 | if (!find_home_of_exe("star")) { |
---|
261 | fatal_error |
---|
262 | ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); |
---|
263 | } |
---|
264 | } |
---|
265 | if (flag_set['W']) { |
---|
266 | bkpinfo->nonbootable_backup = TRUE; |
---|
267 | log_to_screen("Warning - you have opted for non-bootable backup"); |
---|
268 | if (flag_set['f'] || flag_set['l']) { |
---|
269 | log_to_screen |
---|
270 | (_("You don't need to specify bootloader or bootdevice")); |
---|
271 | } |
---|
272 | } |
---|
273 | if (flag_set['t'] && flag_set['H']) { |
---|
274 | fatal_error |
---|
275 | ("Sorry, you may not nuke w/o warning from tape. Drop -H, please."); |
---|
276 | } |
---|
277 | if (flag_set['I']) { |
---|
278 | if (!strcmp(bkpinfo->include_paths, "/")) { |
---|
279 | mr_msg(2, "'/' is pleonastic."); |
---|
280 | bkpinfo->include_paths[0] = '\0'; |
---|
281 | } |
---|
282 | if (bkpinfo->include_paths[0]) { |
---|
283 | strcat(bkpinfo->include_paths, " "); |
---|
284 | } |
---|
285 | mr_asprintf(&tmp1, flag_val['I']); |
---|
286 | p = tmp1; |
---|
287 | q = tmp1; |
---|
288 | |
---|
289 | /* Cut the flag_val['I'] in parts containing all paths to test them */ |
---|
290 | while (p != NULL) { |
---|
291 | q = strchr(p, ' '); |
---|
292 | if (q != NULL) { |
---|
293 | *q = '\0'; |
---|
294 | if (stat(p, &buf) != 0) { |
---|
295 | mr_msg(1, "ERROR ! %s doesn't exist", p); |
---|
296 | fatal_error("ERROR ! You specified a directory to include which doesn't exist"); |
---|
297 | } |
---|
298 | p = q+1 ; |
---|
299 | } else { |
---|
300 | if (stat(p, &buf) != 0) { |
---|
301 | mr_msg(1, "ERROR ! %s doesn't exist", p); |
---|
302 | fatal_error("ERROR ! You specified a directory to include which doesn't exist"); |
---|
303 | } |
---|
304 | p = NULL; |
---|
305 | } |
---|
306 | } |
---|
307 | mr_free(tmp1); |
---|
308 | |
---|
309 | strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths), |
---|
310 | flag_val['I'], |
---|
311 | 4*MAX_STR_LEN - strlen(bkpinfo->include_paths)); |
---|
312 | mr_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); |
---|
313 | if (bkpinfo->include_paths[0] == '-') { |
---|
314 | retval++; |
---|
315 | log_to_screen(_("Please supply a sensible value with '-I'\n")); |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | if (g_kernel_version >= 2.6 && !flag_set['d'] |
---|
320 | && (flag_set['c'] || flag_set['w'])) { |
---|
321 | fatal_error |
---|
322 | ("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); |
---|
323 | } |
---|
324 | |
---|
325 | if (flag_set['J']) { |
---|
326 | if (flag_set['I']) { |
---|
327 | retval++; |
---|
328 | log_to_screen |
---|
329 | (_("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 combine -J with -I. Thanks. :-)")); |
---|
330 | } |
---|
331 | bkpinfo->make_filelist = FALSE; |
---|
332 | strcpy(bkpinfo->include_paths, flag_val['J']); |
---|
333 | } |
---|
334 | |
---|
335 | if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) { |
---|
336 | if (!flag_set['r'] && g_kernel_version <= 2.5 |
---|
337 | && strstr(flag_val['d'], "/dev/")) { |
---|
338 | fatal_error |
---|
339 | ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); |
---|
340 | } |
---|
341 | if (flag_set['r'] && g_kernel_version <= 2.5 |
---|
342 | && !strstr(flag_val['d'], "/dev/")) { |
---|
343 | fatal_error |
---|
344 | ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); |
---|
345 | } |
---|
346 | if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) { |
---|
347 | log_to_screen |
---|
348 | (_("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk...")); |
---|
349 | } |
---|
350 | |
---|
351 | if (system("which cdrecord > /dev/null 2> /dev/null") |
---|
352 | && system("which dvdrecord > /dev/null 2> /dev/null")) { |
---|
353 | fatal_error |
---|
354 | ("Please install dvdrecord/cdrecord and try again."); |
---|
355 | } |
---|
356 | if (flag_set['C']) { |
---|
357 | bkpinfo->cdrw_speed = atoi(flag_val['C']); |
---|
358 | if (bkpinfo->cdrw_speed < 1) { |
---|
359 | fatal_error |
---|
360 | ("You specified a silly speed for a CD-R[W] drive"); |
---|
361 | } |
---|
362 | if (!flag_set['L']) { |
---|
363 | log_to_screen |
---|
364 | (_("You must use -L with -C. Therefore I am setting it for you.")); |
---|
365 | flag_set['L'] = 1; |
---|
366 | flag_val['L'][0] = '\0'; |
---|
367 | } |
---|
368 | } else { |
---|
369 | mr_msg(3, "flag_val['c'] = %s", flag_val['c']); |
---|
370 | mr_msg(3, "flag_val['w'] = %s", flag_val['w']); |
---|
371 | if (flag_set['c']) { |
---|
372 | bkpinfo->cdrw_speed = atoi(flag_val['c']); |
---|
373 | } else if (flag_set['w']) { |
---|
374 | bkpinfo->cdrw_speed = atoi(flag_val['w']); |
---|
375 | } else if (flag_set['r']) { |
---|
376 | bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */ |
---|
377 | } |
---|
378 | |
---|
379 | if (bkpinfo->cdrw_speed < 1) { |
---|
380 | fatal_error |
---|
381 | ("You specified a silly speed for a CD-R[W] drive"); |
---|
382 | } |
---|
383 | } |
---|
384 | } |
---|
385 | |
---|
386 | if (flag_set['t'] && !flag_set['d']) { |
---|
387 | log_it("Hmm! No tape drive specified. Let's see what we can do."); |
---|
388 | if (find_tape_device_and_size(flag_val['d'], tmp)) { |
---|
389 | fatal_error |
---|
390 | ("Tape device not specified. I couldn't find it either."); |
---|
391 | } |
---|
392 | flag_set['d'] = TRUE; |
---|
393 | mr_asprintf(&tmp2, |
---|
394 | _("You didn't specify a tape streamer device. I'm assuming %s"), |
---|
395 | flag_val['d']); |
---|
396 | log_to_screen(tmp2); |
---|
397 | mr_free(tmp2); |
---|
398 | percent = 0; |
---|
399 | } |
---|
400 | |
---|
401 | if (flag_set['U']) // USB |
---|
402 | { |
---|
403 | if (! flag_set['d']) { |
---|
404 | fatal_error |
---|
405 | ("You need to specify a device file with -d for bootable USB device creation"); |
---|
406 | } |
---|
407 | if (!flag_set['s']) { |
---|
408 | fatal_error("You did not specify a size (-s) for your USB device. Aborting"); |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | if (flag_set['r']) // DVD |
---|
413 | { |
---|
414 | if (flag_set['m']) { |
---|
415 | fatal_error |
---|
416 | ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); |
---|
417 | } |
---|
418 | if (!flag_set['d']) { |
---|
419 | if (!find_dvd_device(flag_val['d'], FALSE)) { |
---|
420 | flag_set['d'] = TRUE; |
---|
421 | log_to_screen(_("I guess DVD drive is at %s"), flag_val['d']); |
---|
422 | } |
---|
423 | } |
---|
424 | if (!find_home_of_exe("growisofs")) { |
---|
425 | fatal_error |
---|
426 | ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); |
---|
427 | } |
---|
428 | if (!find_home_of_exe("dvd+rw-format")) { |
---|
429 | fatal_error |
---|
430 | ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); |
---|
431 | } |
---|
432 | if (strchr(flag_val['d'], ',')) { |
---|
433 | fatal_error |
---|
434 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); |
---|
435 | } |
---|
436 | if (!flag_set['s']) { |
---|
437 | sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB |
---|
438 | strcat(flag_val['s'], "m"); |
---|
439 | log_to_screen |
---|
440 | (_("You did not specify a size (-s) for DVD. I'm guessing %s."), |
---|
441 | flag_val['s']); |
---|
442 | flag_set['s'] = 1; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | if (flag_set['t'] || flag_set['u']) { /* tape size */ |
---|
447 | if (strchr(flag_val['d'], ',')) { |
---|
448 | fatal_error |
---|
449 | ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); |
---|
450 | } |
---|
451 | if (flag_set['O']) { |
---|
452 | if (flag_set['s']) { |
---|
453 | if (flag_set['t']) { |
---|
454 | fatal_error |
---|
455 | ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); |
---|
456 | } |
---|
457 | if (process_the_s_switch(bkpinfo, flag_val['s'])) { |
---|
458 | fatal_error("Bad -s switch"); |
---|
459 | } |
---|
460 | } else if (flag_set['u'] || flag_set['t']) { |
---|
461 | bkpinfo->media_size = 0L; |
---|
462 | } else { |
---|
463 | retval++; |
---|
464 | log_to_screen("Tape size not specified.\n"); |
---|
465 | } |
---|
466 | } |
---|
467 | } else { /* CD|USB size */ |
---|
468 | if (flag_set['s']) { |
---|
469 | if (process_the_s_switch(bkpinfo, flag_val['s'])) { |
---|
470 | fatal_error("Bad -s switch"); |
---|
471 | } |
---|
472 | } |
---|
473 | if (flag_set['w']) { |
---|
474 | bkpinfo->wipe_media_first = TRUE; |
---|
475 | } /* CD-RW */ |
---|
476 | } |
---|
477 | if (flag_set['n']) { |
---|
478 | strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN); |
---|
479 | if (!flag_set['d']) { |
---|
480 | strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); |
---|
481 | } |
---|
482 | mr_asprintf(&tmp2, "mount | grep -E '^%s .*$' | cut -d' ' -f3", |
---|
483 | bkpinfo->nfs_mount); |
---|
484 | strncpy(bkpinfo->isodir, |
---|
485 | call_program_and_get_last_line_of_output(tmp2), |
---|
486 | MAX_STR_LEN / 4); |
---|
487 | mr_free(tmp2); |
---|
488 | if (strlen(bkpinfo->isodir) < 3) { |
---|
489 | retval++; |
---|
490 | log_to_screen(_("NFS share is not mounted. Please mount it.\n")); |
---|
491 | } |
---|
492 | mr_msg(3, "mount = %s", bkpinfo->nfs_mount); |
---|
493 | mr_msg(3, "isodir= %s", bkpinfo->isodir); |
---|
494 | } |
---|
495 | |
---|
496 | if (flag_set['c']) { |
---|
497 | bkpinfo->backup_media_type = cdr; |
---|
498 | } |
---|
499 | if (flag_set['C']) { |
---|
500 | bkpinfo->backup_media_type = cdstream; |
---|
501 | } |
---|
502 | if (flag_set['i']) { |
---|
503 | bkpinfo->backup_media_type = iso; |
---|
504 | } |
---|
505 | if (flag_set['n']) { |
---|
506 | bkpinfo->backup_media_type = nfs; |
---|
507 | } |
---|
508 | if (flag_set['r']) { |
---|
509 | bkpinfo->backup_media_type = dvd; |
---|
510 | } |
---|
511 | if (flag_set['t']) { |
---|
512 | bkpinfo->backup_media_type = tape; |
---|
513 | } |
---|
514 | if (flag_set['u']) { |
---|
515 | bkpinfo->backup_media_type = udev; |
---|
516 | } |
---|
517 | if (flag_set['w']) { |
---|
518 | bkpinfo->backup_media_type = cdrw; |
---|
519 | } |
---|
520 | if (flag_set['U']) { |
---|
521 | bkpinfo->backup_media_type = usb; |
---|
522 | } |
---|
523 | if (flag_set['z']) { |
---|
524 | if (find_home_of_exe("getfattr")) { |
---|
525 | mr_asprintf(&g_getfattr,"getfattr"); |
---|
526 | } |
---|
527 | if (find_home_of_exe("getfacl")) { |
---|
528 | mr_asprintf(&g_getfacl,"getfacl"); |
---|
529 | } |
---|
530 | } |
---|
531 | |
---|
532 | /* optional, popular */ |
---|
533 | if (flag_set['g']) { |
---|
534 | g_text_mode = FALSE; |
---|
535 | } |
---|
536 | |
---|
537 | if (flag_set['E']) { |
---|
538 | if (bkpinfo->exclude_paths[0]) { |
---|
539 | strcat(bkpinfo->exclude_paths, " "); |
---|
540 | } |
---|
541 | mr_asprintf(&tmp1, flag_val['E']); |
---|
542 | p = tmp1; |
---|
543 | q = tmp1; |
---|
544 | |
---|
545 | /* Cut the flag_val['E'] in parts containing all paths to test them */ |
---|
546 | while (p != NULL) { |
---|
547 | q = strchr(p, ' '); |
---|
548 | if (q != NULL) { |
---|
549 | *q = '\0'; |
---|
550 | /* Fix bug 14 where ending / cause a problem later |
---|
551 | * so handled here for the moment */ |
---|
552 | q--; |
---|
553 | if (*q == '/') { |
---|
554 | *q = '\0'; |
---|
555 | } |
---|
556 | q++; |
---|
557 | /* End of bug fix */ |
---|
558 | if (stat(p, &buf) != 0) { |
---|
559 | mr_msg(1, "WARNING ! %s doesn't exist", p); |
---|
560 | } |
---|
561 | p = q+1 ; |
---|
562 | } else { |
---|
563 | if (stat(p, &buf) != 0) { |
---|
564 | mr_msg(1, "WARNING ! %s doesn't exist", p); |
---|
565 | } |
---|
566 | p = NULL; |
---|
567 | } |
---|
568 | } |
---|
569 | mr_free(tmp1); |
---|
570 | |
---|
571 | strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths), |
---|
572 | flag_val['E'], |
---|
573 | 4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths)); |
---|
574 | } |
---|
575 | if (flag_set['e']) { |
---|
576 | bkpinfo->please_dont_eject = TRUE; |
---|
577 | } |
---|
578 | if (flag_set['N']) // exclude NFS mounts & devices |
---|
579 | { |
---|
580 | mr_asprintf(&psz, list_of_NFS_mounts_only()); |
---|
581 | if (bkpinfo->exclude_paths[0]) { |
---|
582 | strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); |
---|
583 | } |
---|
584 | strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); |
---|
585 | mr_free(psz); |
---|
586 | mr_msg(3, "-N means we're now excluding %s", |
---|
587 | bkpinfo->exclude_paths); |
---|
588 | } |
---|
589 | if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) { |
---|
590 | fatal_error |
---|
591 | ("Your '-E' parameter is too long. Please use '-J'. (See manual.)"); |
---|
592 | } |
---|
593 | if (flag_set['b']) { |
---|
594 | mr_asprintf(&psz, flag_val['b']); |
---|
595 | mr_msg(1, "psz = '%s'", psz); |
---|
596 | if (psz[strlen(psz) - 1] == 'k') { |
---|
597 | psz[strlen(psz) - 1] = '\0'; |
---|
598 | itbs = atol(psz) * 1024L; |
---|
599 | } else { |
---|
600 | itbs = atol(psz); |
---|
601 | } |
---|
602 | mr_free(psz); |
---|
603 | |
---|
604 | mr_msg(1, "'%s' --> %ld", flag_val['b'], itbs); |
---|
605 | mr_msg(1, "Internal tape block size is now %ld bytes", itbs); |
---|
606 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) { |
---|
607 | fatal_error |
---|
608 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); |
---|
609 | } |
---|
610 | bkpinfo->internal_tape_block_size = itbs; |
---|
611 | } |
---|
612 | |
---|
613 | if (flag_set['D']) { |
---|
614 | bkpinfo->differential = 1; |
---|
615 | // bkpinfo->differential = atoi (flag_val['D']); |
---|
616 | if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) { |
---|
617 | fatal_error |
---|
618 | ("The D option should be between 1 and 9 inclusive"); |
---|
619 | } |
---|
620 | } |
---|
621 | |
---|
622 | if (flag_set['x']) { |
---|
623 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4); |
---|
624 | if (run_program_and_log_output("which ntfsclone", 2)) { |
---|
625 | fatal_error("Please install ntfsprogs package/tarball."); |
---|
626 | } |
---|
627 | } |
---|
628 | if (flag_set['m']) { |
---|
629 | bkpinfo->manual_cd_tray = TRUE; |
---|
630 | } |
---|
631 | if (flag_set['k']) { |
---|
632 | strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); |
---|
633 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) { |
---|
634 | strcpy(bkpinfo->kernel_path, "FAILSAFE"); |
---|
635 | } |
---|
636 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE") |
---|
637 | && !does_file_exist(bkpinfo->kernel_path)) { |
---|
638 | retval++; |
---|
639 | mr_asprintf(&tmp2, |
---|
640 | _("You specified kernel '%s', which does not exist\n"), |
---|
641 | bkpinfo->kernel_path); |
---|
642 | log_to_screen(tmp2); |
---|
643 | mr_free(tmp2); |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | if (flag_set['p']) { |
---|
648 | strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4); |
---|
649 | } |
---|
650 | |
---|
651 | if (flag_set['d']) { /* backup directory (if ISO/NFS/USB) */ |
---|
652 | if (flag_set['i']) { |
---|
653 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); |
---|
654 | mr_asprintf(&tmp2, "ls -l %s", bkpinfo->isodir); |
---|
655 | if (run_program_and_log_output(tmp2, FALSE)) { |
---|
656 | fatal_error |
---|
657 | ("output folder does not exist - please create it"); |
---|
658 | } |
---|
659 | mr_free(tmp2); |
---|
660 | } else if (flag_set['n']) { |
---|
661 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); |
---|
662 | } else { /* backup device (if tape/CD-R/CD-RW) */ |
---|
663 | strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4); |
---|
664 | } |
---|
665 | } |
---|
666 | |
---|
667 | if (flag_set['n']) { |
---|
668 | mr_asprintf(&tmp2, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, |
---|
669 | bkpinfo->nfs_remote_dir); |
---|
670 | if (run_program_and_log_output(tmp2, FALSE)) { |
---|
671 | retval++; |
---|
672 | mr_free(tmp2); |
---|
673 | mr_asprintf(&tmp2, |
---|
674 | _("Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n"), |
---|
675 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); |
---|
676 | log_to_screen(tmp2); |
---|
677 | } |
---|
678 | mr_free(tmp2); |
---|
679 | } |
---|
680 | |
---|
681 | if (!flag_set['d'] |
---|
682 | && (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['U'])) { |
---|
683 | if (g_kernel_version >= 2.6) { |
---|
684 | if (popup_and_get_string |
---|
685 | (_("Device"), _("Please specify the device"), |
---|
686 | bkpinfo->media_device, MAX_STR_LEN / 4)) { |
---|
687 | retval++; |
---|
688 | log_to_screen(_("User opted to cancel.")); |
---|
689 | } |
---|
690 | } else if (find_cdrw_device(bkpinfo->media_device)) { |
---|
691 | retval++; |
---|
692 | log_to_screen |
---|
693 | (_("Tried and failed to find CD-R[W] drive automatically.\n")); |
---|
694 | } else { |
---|
695 | flag_set['d'] = TRUE; |
---|
696 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4); |
---|
697 | } |
---|
698 | } |
---|
699 | |
---|
700 | if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) { |
---|
701 | retval++; |
---|
702 | log_to_screen(_("Please specify the backup device/directory.\n")); |
---|
703 | fatal_error |
---|
704 | ("You didn't use -d to specify the backup device/directory."); |
---|
705 | } |
---|
706 | /* optional, obscure */ |
---|
707 | for (i = '0'; i <= '9'; i++) { |
---|
708 | if (flag_set[i]) { |
---|
709 | bkpinfo->compression_level = i - '0'; |
---|
710 | } /* not '\0' but '0' */ |
---|
711 | } |
---|
712 | if (flag_set['S']) { |
---|
713 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], |
---|
714 | random() % 32768); |
---|
715 | } |
---|
716 | if (flag_set['T']) { |
---|
717 | sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], |
---|
718 | random() % 32768); |
---|
719 | mr_asprintf(&tmp2, "touch %s/.foo.dat", flag_val['T']); |
---|
720 | if (run_program_and_log_output(tmp2, 1)) { |
---|
721 | retval++; |
---|
722 | log_to_screen |
---|
723 | (_("Please specify a tempdir which I can write to. :)")); |
---|
724 | fatal_error("I cannot write to the tempdir you specified."); |
---|
725 | } |
---|
726 | mr_free(tmp2); |
---|
727 | |
---|
728 | mr_asprintf(&tmp2, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], |
---|
729 | flag_val['T']); |
---|
730 | if (run_program_and_log_output(tmp2, 1)) { |
---|
731 | retval++; |
---|
732 | log_to_screen |
---|
733 | (_("Please don't specify a SAMBA or VFAT or NFS tmpdir.")); |
---|
734 | fatal_error("I cannot write to the tempdir you specified."); |
---|
735 | } |
---|
736 | mr_free(tmp2); |
---|
737 | } |
---|
738 | |
---|
739 | if (flag_set['A']) { |
---|
740 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); |
---|
741 | } |
---|
742 | if (flag_set['B']) { |
---|
743 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); |
---|
744 | } |
---|
745 | if (flag_set['F']) { |
---|
746 | g_skip_floppies = TRUE; |
---|
747 | } |
---|
748 | if (flag_set['H']) { |
---|
749 | g_cd_recovery = TRUE; |
---|
750 | } |
---|
751 | if (flag_set['l']) { |
---|
752 | #ifdef __FreeBSD__ |
---|
753 | # define BOOT_LOADER_CHARS "GLBMR" |
---|
754 | #else |
---|
755 | # ifdef __IA64__ |
---|
756 | # define BOOT_LOADER_CHARS "GER" |
---|
757 | # else |
---|
758 | # define BOOT_LOADER_CHARS "GLR" |
---|
759 | # endif |
---|
760 | #endif |
---|
761 | if (!strchr |
---|
762 | (BOOT_LOADER_CHARS, |
---|
763 | (bkpinfo->boot_loader = flag_val['l'][0]))) { |
---|
764 | mr_msg(1, "%c? What is %c? I need G, L, E or R.", |
---|
765 | bkpinfo->boot_loader, bkpinfo->boot_loader); |
---|
766 | fatal_error |
---|
767 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); |
---|
768 | } |
---|
769 | #undef BOOT_LOADER_CHARS |
---|
770 | } |
---|
771 | |
---|
772 | if (flag_set['f']) { |
---|
773 | strncpy(bkpinfo->boot_device, |
---|
774 | resolve_softlinks_to_get_to_actual_device_file(flag_val |
---|
775 | ['f']), |
---|
776 | MAX_STR_LEN / 4); |
---|
777 | } |
---|
778 | |
---|
779 | if (flag_set['Q']) { |
---|
780 | if (bkpinfo->boot_device == NULL) { |
---|
781 | fatal_error("-f option required when using -Q\n"); |
---|
782 | } |
---|
783 | i = which_boot_loader(bkpinfo->boot_device); |
---|
784 | mr_msg(3, "boot loader is %c, residing at %s", i, bkpinfo->boot_device); |
---|
785 | log_to_screen(_("boot loader is %c, residing at %s\n"), i, tmp); |
---|
786 | finish(0); |
---|
787 | } |
---|
788 | |
---|
789 | if (flag_set['P']) { |
---|
790 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); |
---|
791 | } |
---|
792 | |
---|
793 | if (flag_set['L']) { |
---|
794 | bkpinfo->use_lzo = TRUE; |
---|
795 | if (run_program_and_log_output("which lzop", FALSE)) { |
---|
796 | retval++; |
---|
797 | log_to_screen |
---|
798 | (_("Please install LZOP. You can't use '-L' until you do.\n")); |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | if (flag_set['G']) { |
---|
803 | bkpinfo->use_gzip = TRUE; |
---|
804 | if (run_program_and_log_output("which gzip", FALSE)) { |
---|
805 | retval++; |
---|
806 | log_to_screen |
---|
807 | ("Please install gzip. You can't use '-G' until you do.\n"); |
---|
808 | } |
---|
809 | } |
---|
810 | |
---|
811 | if (!flag_set['o'] |
---|
812 | && |
---|
813 | !run_program_and_log_output |
---|
814 | ("grep -Ei suse /etc/issue.net | grep -E '9.0' | grep 64", TRUE)) { |
---|
815 | bkpinfo->make_cd_use_lilo = TRUE; |
---|
816 | log_to_screen |
---|
817 | (_("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary.")); |
---|
818 | } |
---|
819 | |
---|
820 | if (flag_set['o']) { |
---|
821 | bkpinfo->make_cd_use_lilo = TRUE; |
---|
822 | } |
---|
823 | #ifndef __FreeBSD__ |
---|
824 | else { |
---|
825 | if (!is_this_a_valid_disk_format("vfat")) { |
---|
826 | bkpinfo->make_cd_use_lilo = TRUE; |
---|
827 | log_to_screen |
---|
828 | (_("Your kernel appears not to support vfat filesystems. I am therefore")); |
---|
829 | log_to_screen |
---|
830 | (_("using LILO instead of SYSLINUX as the CD/floppy's boot loader.")); |
---|
831 | } |
---|
832 | if (run_program_and_log_output("which mkfs.vfat", FALSE)) { |
---|
833 | bkpinfo->make_cd_use_lilo = TRUE; |
---|
834 | #ifdef __IA32__ |
---|
835 | log_to_screen |
---|
836 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as")); |
---|
837 | log_to_screen |
---|
838 | (_("your boot loader. I shall therefore use LILO instead.")); |
---|
839 | #endif |
---|
840 | #ifdef __IA64__ |
---|
841 | log_to_screen |
---|
842 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI")); |
---|
843 | log_to_screen(_("environment correctly. Please install it.")); |
---|
844 | fatal_error("Aborting"); |
---|
845 | #endif |
---|
846 | } |
---|
847 | #ifdef __IA64__ |
---|
848 | /* We force ELILO usage on IA64 */ |
---|
849 | bkpinfo->make_cd_use_lilo = TRUE; |
---|
850 | #endif |
---|
851 | } |
---|
852 | #endif |
---|
853 | |
---|
854 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) { |
---|
855 | paranoid_system("touch /boot/boot.b"); |
---|
856 | } |
---|
857 | |
---|
858 | i = flag_set['O'] + flag_set['V']; |
---|
859 | if (i == 0) { |
---|
860 | retval++; |
---|
861 | log_to_screen(_("Specify backup (-O), verify (-V) or both (-OV).\n")); |
---|
862 | } |
---|
863 | |
---|
864 | /* and finally... */ |
---|
865 | |
---|
866 | mr_free(tmp); |
---|
867 | return (retval); |
---|
868 | } |
---|
869 | |
---|
870 | |
---|
871 | /** |
---|
872 | * Get the switches from @p argc and @p argv using getopt() and place them in |
---|
873 | * @p flag_set and @p flag_val. |
---|
874 | * @param argc The argument count (@p argc passed to main()). |
---|
875 | * @param argv The argument vector (@p argv passed to main()). |
---|
876 | * @param flag_val An array indexed by switch letter - if a switch is set and |
---|
877 | * has an argument then set flag_val[switch] to that argument. |
---|
878 | * @param flag_set An array indexed by switch letter - if a switch is set then |
---|
879 | * set flag_set[switch] to TRUE, else set it to FALSE. |
---|
880 | * @return The number of problems with the command line (0 for success). |
---|
881 | */ |
---|
882 | int |
---|
883 | retrieve_switches_from_command_line(int argc, char *argv[], |
---|
884 | char flag_val[128][MAX_STR_LEN], |
---|
885 | bool flag_set[128]) |
---|
886 | { |
---|
887 | /*@ ints ** */ |
---|
888 | int opt = 0; |
---|
889 | char *tmp = NULL; |
---|
890 | int i = 0; |
---|
891 | int len = 0; |
---|
892 | |
---|
893 | /*@ bools *** */ |
---|
894 | bool bad_switches = FALSE; |
---|
895 | |
---|
896 | assert(flag_val != NULL); |
---|
897 | assert(flag_set != NULL); |
---|
898 | |
---|
899 | for (i = 0; i < 128; i++) { |
---|
900 | flag_val[i][0] = '\0'; |
---|
901 | flag_set[i] = FALSE; |
---|
902 | } |
---|
903 | while ((opt = |
---|
904 | getopt(argc, argv, |
---|
905 | "0123456789A:B:C:DE:FGHI:J:K:LNOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z")) |
---|
906 | != -1) { |
---|
907 | if (opt == '?') { |
---|
908 | bad_switches = TRUE; |
---|
909 | /*log_it("Invalid option: %c\n",optopt); */ |
---|
910 | } else { |
---|
911 | if (flag_set[optopt]) { |
---|
912 | bad_switches = TRUE; |
---|
913 | mr_asprintf(&tmp, _("Switch -%c previously defined as %s\n"), opt, |
---|
914 | flag_val[i]); |
---|
915 | log_to_screen(tmp); |
---|
916 | mr_free(tmp); |
---|
917 | } else { |
---|
918 | flag_set[opt] = TRUE; |
---|
919 | if (optarg) { |
---|
920 | len = strlen(optarg); |
---|
921 | if (optarg[0] != '/' && optarg[len - 1] == '/') { |
---|
922 | optarg[--len] = '\0'; |
---|
923 | log_to_screen |
---|
924 | (_("Warning - param '%s' should not have trailing slash!"), |
---|
925 | optarg); |
---|
926 | } |
---|
927 | if (opt == 'd') { |
---|
928 | if (strchr(flag_val[opt], '/') |
---|
929 | && flag_val[opt][0] != '/') { |
---|
930 | mr_asprintf(&tmp, |
---|
931 | _("-%c flag --- must be absolute path --- '%s' isn't absolute"), |
---|
932 | opt, flag_val[opt]); |
---|
933 | log_to_screen(tmp); |
---|
934 | mr_free(tmp); |
---|
935 | bad_switches = TRUE; |
---|
936 | } |
---|
937 | } |
---|
938 | strcpy(flag_val[opt], optarg); |
---|
939 | } |
---|
940 | } |
---|
941 | } |
---|
942 | } |
---|
943 | for (i = optind; i < argc; i++) { |
---|
944 | bad_switches = TRUE; |
---|
945 | mr_asprintf(&tmp, _("Invalid arg -- %s\n"), argv[i]); |
---|
946 | log_to_screen(tmp); |
---|
947 | mr_free(tmp); |
---|
948 | } |
---|
949 | return (bad_switches); |
---|
950 | } |
---|
951 | |
---|
952 | |
---|
953 | /** |
---|
954 | * Terminate Mondo in response to a signal. |
---|
955 | * @param sig The signal number received. |
---|
956 | */ |
---|
957 | void terminate_daemon(int sig) |
---|
958 | { |
---|
959 | char *tmp = NULL; |
---|
960 | char *tmp2 = NULL; |
---|
961 | |
---|
962 | switch (sig) { |
---|
963 | case SIGINT: |
---|
964 | mr_asprintf(&tmp, _("SIGINT signal received from OS")); |
---|
965 | mr_asprintf(&tmp2, _("You interrupted me :-)")); |
---|
966 | break; |
---|
967 | case SIGKILL: |
---|
968 | mr_asprintf(&tmp, _("SIGKILL signal received from OS")); |
---|
969 | mr_asprintf(&tmp2, |
---|
970 | _("I seriously have no clue how this signal even got to me. Something's wrong with your system.")); |
---|
971 | break; |
---|
972 | case SIGTERM: |
---|
973 | mr_asprintf(&tmp, _("SIGTERM signal received from OS")); |
---|
974 | mr_asprintf(&tmp2, _("Got terminate signal")); |
---|
975 | break; |
---|
976 | case SIGHUP: |
---|
977 | mr_asprintf(&tmp, _("SIGHUP signal received from OS")); |
---|
978 | mr_asprintf(&tmp2, _("Hangup on line")); |
---|
979 | break; |
---|
980 | case SIGSEGV: |
---|
981 | mr_asprintf(&tmp, _("SIGSEGV signal received from OS")); |
---|
982 | mr_asprintf(&tmp2, |
---|
983 | _("Internal programming error. Please send a backtrace as well as your log.")); |
---|
984 | break; |
---|
985 | case SIGPIPE: |
---|
986 | mr_asprintf(&tmp, _("SIGPIPE signal received from OS")); |
---|
987 | mr_asprintf(&tmp2, _("Pipe was broken")); |
---|
988 | break; |
---|
989 | case SIGABRT: |
---|
990 | mr_asprintf(&tmp, _("SIGABRT signal received from OS")); |
---|
991 | mr_asprintf(&tmp2, |
---|
992 | _("Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.")); |
---|
993 | break; |
---|
994 | default: |
---|
995 | mr_asprintf(&tmp, _("(Unknown)")); |
---|
996 | mr_asprintf(&tmp2, _("(Unknown)")); |
---|
997 | } |
---|
998 | |
---|
999 | log_to_screen(tmp); |
---|
1000 | log_to_screen(tmp2); |
---|
1001 | mr_free(tmp); |
---|
1002 | mr_free(tmp2); |
---|
1003 | if (sig == SIGABRT) { |
---|
1004 | sleep(10); |
---|
1005 | } |
---|
1006 | kill_buffer(); |
---|
1007 | fatal_error |
---|
1008 | ("Mondoarchive is terminating in response to a signal from the OS"); |
---|
1009 | finish(254); // just in case |
---|
1010 | } |
---|
1011 | |
---|
1012 | |
---|
1013 | /** |
---|
1014 | * Turn signal-trapping on or off. |
---|
1015 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much). |
---|
1016 | */ |
---|
1017 | void set_signals(int on) |
---|
1018 | { |
---|
1019 | int signals[] = |
---|
1020 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; |
---|
1021 | int i; |
---|
1022 | |
---|
1023 | signal(SIGPIPE, sigpipe_occurred); |
---|
1024 | for (i = 0; signals[i]; i++) { |
---|
1025 | if (on) { |
---|
1026 | signal(signals[i], terminate_daemon); |
---|
1027 | } else { |
---|
1028 | signal(signals[i], termination_in_progress); |
---|
1029 | } |
---|
1030 | } |
---|
1031 | } |
---|
1032 | |
---|
1033 | |
---|
1034 | /** |
---|
1035 | * Exit immediately without cleaning up. |
---|
1036 | * @param sig The signal we are exiting due to. |
---|
1037 | */ |
---|
1038 | void termination_in_progress(int sig) |
---|
1039 | { |
---|
1040 | mr_msg(1, "Termination in progress"); |
---|
1041 | usleep(1000); |
---|
1042 | pthread_exit(0); |
---|
1043 | } |
---|
1044 | |
---|
1045 | /* @} - end of cliGroup */ |
---|