source: MondoRescue/branches/stable/mondo/src/mondoarchive/mondo-cli.c@ 1842

Last change on this file since 1842 was 1842, checked in by Bruno Cornec, 16 years ago
  • Fix lack of /etc/raidtab at restore rime in the right place
  • Adds support for nls_utf8 and pata_serverworks Patches from Dirk Husung (husung_at_tu-harburg.de)
  • Add efibootmgr to deplist.txt in order to be able to modify EFI menu at restore time on ia64
  • Usage of the new testver param of pb 0.8.12 to deliver 2.2.5 packages in a test dir.
  • Update pbcl files for upcoming delivery of 2.2.5
  • Fix an issue on parted output (K instead of KB) in parted2fdisk at restore time
  • Adds support for alb/aft types of bonding on Intel cards (Mark Pinkerton <Mark.Pinkerton_at_emageon.com>)
  • Escape variables in a perl script like mindi-bkphw
  • Better Proliant support at restore time now.
  • Fix a label bug where the variable label should also be re-initialized at each loop
  • start-nfs should NOT do exit => kernel panix as init exits
  • some other fixes for init on denymods
  • Adds boot options denymods (for udev) and forcemods (if not udev)
  • kqemu is denied. Probably should also be done for kvm stuff
  • Fix again the bug on modules link at root of the initrd. Hopefully for good.
  • Wait more around the USB CD emulated by iLO as it takes up to 5 seconds to come up
  • Attempt to fix udev support for RHEL 5.1
  • Better support for automatic iLO Virtual Media with udev
  • Some VMWare support improvements (however, it seems that VMWare support won't be possible anytime soon)
  • during init at restore time, copy all static evices availble for udev, as some distro implementation are no

t yet supported correctly for udev. Not very elegant, but should solve our current issues

  • Fedora 8 now supported as a build target for pb
  • svn.log removed.
  • dependencies reviewd for rhel_3
  • Attempt to fix the lack of modules loaded at restore time - especially fs device drivers
  • removes bkphw dir before potential creation
  • render mount command more vebose at restore time
  • Should fix #217
  • Increase BOOT_SIZE and EXTRA_SIZE to support features such as HW recovery
  • Handles udev.files files which could be symlinks
  • Improve udev support for distro with compressed modules (mdv e.g.)
  • Fix modules.dep copy
  • /sbin/pam_console_apply is needed by mdv udev conf
  • Adds support for nohw boot option to avoid re-setuping the HW conf
  • Improved support for Proliant on cpqacuxe
  • RstHW should be called after driver initialization
  • For debian/ubuntu mindi dpends on mindi-busybox
  • Update mindi-busybox pbcl for correct debian changelog generation, and up2date infos
  • Should fix #215
  • Fix #214 (Thanks to xdelaruelle)
  • Fix again svn.log not used anymore with new pb version
  • Adaptation of build process to upcoming 0.8.12 version of pb
  • Remove MONOTONIC clock to continue to support 2.4 kernels (RHEL 3 e.g. or ESX)
  • Attempt to solve ia64 BMC access through the serial port
  • parted2fdisk binary no more generated
  • do not require perl modules (strict.pm) at restore time
  • try to avoid modprobe messages at restore time
  • on ia64 now use the perl script parted2fdisk at retore time also
  • Also modprobe modules for udev after decompressing the additional ones
  • replace gzip -v9 by gzip -c9. Fix a bug at least on ia64
  • For all modules supported, create symlinks under the mountpoint and extract dev files as some are not automat ically created at the moment
  • Support /vmfs/volumes for ESX
  • Finally do not use vdf for ESX. Only creates issues.
  • Avoids continuing hw support if no product name found
  • Improves ia64 support for bootable image build
  • Fix a potential problem with ramdisk_blocksize param
  • MAKEDEV should also be included in deplist.txt
  • More fixes for udev support for Debian
  • Do not mount /boot if it's already mounted - avoids ESX hang
  • Fix NICs renumbering on Debian at least
  • Udev startup improvement to support iLO + NFS so modprobing all modules seems required as of now
  • Update to version 1.7.3 of busybox for pb
  • Load USB earlier in order to support KBD such as with iLO
  • Do busybox ldd first in order to create a potential /lib64 link correctly and then use it later in the image
  • Use variable DF in mindi to be able to support the ESX vdf
  • Fix mindi for Debian x86_64 where /lib64 is a link
  • Fix issue at restore time for ext2fs params not reused (Fix from Klaus Ade Johnstad <klaus_at_skolelinux.no>)
  • Do not copy udev files if they do not exist In udev case do not insert modules at all (udev should do it alone) May avoid the issue with rhel4.5 kernel ? To be tested
  • Update dependencies for rpm base build as well
  • And also perl is a debian/ubuntu dep
  • Better debian/ubuntu dependecies requirements (mtools)
  • Fix modes on mindi-bkphw (Thanks Phil Walker phil.walker_at_hp.com)
  • Complete rev [1771] for upper case RESTORE cli with syslinux as well
  • Update mindi-busybox to 1.7.3
  • Use RESTORE consistently across mondo to restore without interaction (report from Takeshi Shoji t.shoji_at_tripodw.jp)

(merge -r1769:1841 $SVN_M/branches/2.2.5)

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