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
RevLine 
[1]1/***************************************************************************
[1080]2$Id: mondo-cli.c 1842 2007-12-15 01:24:34Z bruno $
[1]3*******************************************************************/
4
5/**
6 * @file
7 * Functions for handling command-line arguments passed to mondoarchive.
8 */
9
10/** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
11
[1067]12#include "my-stuff.h"
[1187]13#include "mondostructures.h"
[1]14#include "mondo-cli-EXT.h"
[1187]15#include "libmondo.h"
16#include <pthread.h>
[1549]17
[1080]18#include "mr_mem.h"
[1120]19#include "mr_msg.h"
[1549]20#include "mr_gettext.h"
[1625]21#include "mr_conf.h"
[1]22
[116]23//static char cvsid[] = "$Id: mondo-cli.c 1842 2007-12-15 01:24:34Z bruno $";
[1]24
25extern bool g_text_mode;
[116]26extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
[1]27extern bool g_sigpipe;
28
[1626]29extern struct mr_ar_conf *mr_conf;
[1625]30
[1]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******** **************************************************/
[116]41bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
42bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
[1]43extern bool g_cd_recovery;
44
[1663]45extern void setup_tmpdir(char *path);
46
[1]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;
[116]59extern char *resolve_softlinks_to_get_to_actual_device_file(char *);
[1]60
[948]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;
[1]65
[1663]66/* Reference to global bkpinfo */
67extern struct s_bkpinfo *bkpinfo;
68
[1]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
[1663]81handle_incoming_parameters(int argc, char *argv[])
[1]82{
[116]83 /*@ int *** */
84 int res = 0;
85 int retval = 0;
[1378]86 int i = 0;
[1]87
[116]88 /*@ buffers *************** */
[1187]89 char *tmp = NULL;
[116]90 char flag_val[128][MAX_STR_LEN];
91 bool flag_set[128];
[1]92
[1663]93 sensibly_set_tmpdir_and_scratchdir();
[1187]94
[116]95 for (i = 0; i < 128; i++) {
96 flag_val[i][0] = '\0';
97 flag_set[i] = FALSE;
98 }
[1594]99 res = retrieve_switches_from_command_line(argc, argv, flag_val,
[116]100 flag_set);
101 retval += res;
102 if (!retval) {
[1663]103 res = process_switches(flag_val, flag_set);
[116]104 retval += res;
105 }
[1]106/*
107 if (!retval)
108 {
109*/
[1108]110 mr_msg(3, "Switches:-");
[116]111 for (i = 0; i < 128; i++) {
112 if (flag_set[i]) {
[1187]113 mr_msg(3, "-%c %s", i, flag_val[i]);
[116]114 }
[1]115 }
116// }
[1187]117 mr_asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
[116]118 paranoid_system(tmp);
[1187]119 mr_free(tmp);
120
121 mr_asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
[116]122 paranoid_system(tmp);
[1187]123 mr_free(tmp);
124
[116]125 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
126 "/mondo.scratch.%ld", random() % 32767);
[1187]127
128 mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
[116]129 paranoid_system(tmp);
[1187]130 mr_free(tmp);
131
132 mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
[116]133 paranoid_system(tmp);
[1080]134 mr_free(tmp);
[116]135 return (retval);
[1]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 */
[1663]146int process_the_s_switch(char *value)
[1]147{
[1191]148 char *tmp = NULL;
149 char *q = NULL;
[1]150
[116]151 assert(bkpinfo != NULL);
152 assert(value != NULL);
[1]153
[1434]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);
[1191]161
[1434]162 mr_msg(3, "media_size = %ld", bkpinfo->media_size);
[1365]163 if (bkpinfo->media_size <= 0L) {
164 mr_msg(1, "You gave media an invalid size\n");
165 return (-1);
[1]166 }
[116]167 return (0);
[1]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
[1663]182process_switches(char flag_val[128][MAX_STR_LEN], bool flag_set[128])
[1]183{
184
[116]185 /*@ ints *** */
186 int i = 0;
187 int retval = 0;
188 int percent = 0;
[1]189
[116]190 /*@ buffers ** */
[1191]191 char *tmp = NULL;
192 char *tmp1 = NULL;
193 char *tmp2 = NULL;
194 char *psz = NULL;
195 char *p = NULL;
196 char *q = NULL;
[1]197
[949]198 long itbs = 0L;
[1]199
[289]200 struct stat buf;
201
[116]202 malloc_string(tmp);
[1]203
[116]204 assert(bkpinfo != NULL);
205 assert(flag_val != NULL);
206 assert(flag_set != NULL);
[1]207
[1638]208 bkpinfo->internal_tape_block_size = mr_conf->internal_tape_blocksize;
[1]209
[1191]210 /* compulsory */
[1594]211 i = flag_set['i'] + flag_set['n'] +
[116]212 flag_set['t'] + flag_set['u'] + flag_set['r'] +
[1063]213 flag_set['w'] + flag_set['C'] + flag_set['U'];
[116]214 if (i == 0) {
215 retval++;
[1191]216 log_to_screen(_("You must specify the media type\n"));
[1]217 }
[116]218 if (i > 1) {
219 retval++;
[1191]220 log_to_screen(_("Please specify only one media type\n"));
[1]221 }
[116]222 if (flag_set['K']) {
[1625]223 mr_conf->log_level = atoi(flag_val['K']);
224 if (mr_conf->log_level < 3) {
225 mr_conf->log_level = 3;
[116]226 }
[1]227 }
[116]228 if (flag_set['L'] && flag_set['0']) {
229 retval++;
[1191]230 log_to_screen(_("You cannot have 'no compression' _and_ LZOP.\n"));
[1]231 }
[116]232 bkpinfo->backup_data = flag_set['O'];
233 bkpinfo->verify_data = flag_set['V'];
234 if (flag_set['I'] && !bkpinfo->backup_data) {
[1191]235 log_to_screen(_("-I switch is ignored if just verifying"));
[116]236 }
237 if (flag_set['E'] && !bkpinfo->backup_data) {
[1191]238 log_to_screen(_("-E switch is ignored if just verifying"));
[116]239 }
[1]240
[116]241 if (!find_home_of_exe("afio")) {
242 if (find_home_of_exe("star")) {
243 flag_set['R'] = TRUE;
[1108]244 mr_msg(1, "Using star instead of afio");
[116]245 } else {
246 fatal_error
247 ("Neither afio nor star is installed. Please install at least one.");
248 }
[1]249 }
250
[116]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 }
[1]260 }
[116]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
[1191]266 (_("You don't need to specify bootloader or bootdevice"));
[116]267 }
[1]268 }
[116]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, "/")) {
[1108]275 mr_msg(2, "'/' is pleonastic.");
[116]276 bkpinfo->include_paths[0] = '\0';
277 }
278 if (bkpinfo->include_paths[0]) {
279 strcat(bkpinfo->include_paths, " ");
280 }
[1080]281 mr_asprintf(&tmp1, flag_val['I']);
[603]282 p = tmp1;
283 q = tmp1;
[542]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) {
[1108]291 mr_msg(1, "ERROR ! %s doesn't exist", p);
[542]292 fatal_error("ERROR ! You specified a directory to include which doesn't exist");
293 }
[633]294 p = q+1 ;
[542]295 } else {
296 if (stat(p, &buf) != 0) {
[1108]297 mr_msg(1, "ERROR ! %s doesn't exist", p);
[542]298 fatal_error("ERROR ! You specified a directory to include which doesn't exist");
299 }
300 p = NULL;
301 }
[289]302 }
[1080]303 mr_free(tmp1);
[542]304
[116]305 strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
306 flag_val['I'],
[543]307 4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
[1108]308 mr_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
[116]309 if (bkpinfo->include_paths[0] == '-') {
310 retval++;
[1191]311 log_to_screen(_("Please supply a sensible value with '-I'\n"));
[116]312 }
313 }
[1]314
[116]315 if (g_kernel_version >= 2.6 && !flag_set['d']
[1594]316 && flag_set['w']) {
[116]317 fatal_error
318 ("If you are using the 2.6.x kernel, please specify the CD-R(W) device.");
[1]319 }
320
[116]321 if (flag_set['J']) {
322 if (flag_set['I']) {
323 retval++;
324 log_to_screen
[1191]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. :-)"));
[116]326 }
327 bkpinfo->make_filelist = FALSE;
328 strcpy(bkpinfo->include_paths, flag_val['J']);
[1]329 }
[1191]330
[1594]331 if (flag_set['w'] || flag_set['C'] || flag_set['r']) {
[116]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
[1191]344 (_("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."));
[116]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 }
[1594]352 if (flag_set['w']) {
[1108]353 mr_msg(3, "flag_val['w'] = %s", flag_val['w']);
[1594]354 bkpinfo->writer_speed = atoi(flag_val['w']);
355 }
[116]356
[1594]357 if (bkpinfo->writer_speed < 1) {
358 fatal_error
359 ("You specified a silly speed for a burner");
[116]360 }
[1]361 }
[1191]362
[116]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)) {
[1569]366 log_to_screen
367 ("Tape device not specified. I had problems to find it either");
[116]368 }
369 flag_set['d'] = TRUE;
[1191]370 mr_asprintf(&tmp2,
371 _("You didn't specify a tape streamer device. I'm assuming %s"),
[116]372 flag_val['d']);
[1191]373 log_to_screen(tmp2);
374 mr_free(tmp2);
[116]375 percent = 0;
376 }
377
[1063]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
[116]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;
[1191]398 log_to_screen(_("I guess DVD drive is at %s"), flag_val['d']);
[116]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 }
[1]414
[116]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 }
[1663]426 if (process_the_s_switch(flag_val['s'])) {
[116]427 fatal_error("Bad -s switch");
428 }
429 } else if (flag_set['u'] || flag_set['t']) {
[1638]430 /* Force autodetection */
[1365]431 bkpinfo->media_size = 0L;
[116]432 } else {
433 retval++;
434 log_to_screen("Tape size not specified.\n");
435 }
436 }
[1063]437 } else { /* CD|USB size */
[116]438 if (flag_set['s']) {
[1663]439 if (process_the_s_switch(flag_val['s'])) {
[116]440 fatal_error("Bad -s switch");
441 }
442 }
443 if (flag_set['w']) {
444 bkpinfo->wipe_media_first = TRUE;
445 } /* CD-RW */
[1]446 }
[116]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 }
[1191]452 mr_asprintf(&tmp2, "mount | grep -E '^%s .*$' | cut -d' ' -f3",
[116]453 bkpinfo->nfs_mount);
454 strncpy(bkpinfo->isodir,
[1191]455 call_program_and_get_last_line_of_output(tmp2),
[116]456 MAX_STR_LEN / 4);
[1191]457 mr_free(tmp2);
[116]458 if (strlen(bkpinfo->isodir) < 3) {
459 retval++;
[1191]460 log_to_screen(_("NFS share is not mounted. Please mount it.\n"));
[116]461 }
[1108]462 mr_msg(3, "mount = %s", bkpinfo->nfs_mount);
463 mr_msg(3, "isodir= %s", bkpinfo->isodir);
[1]464 }
[1191]465
[116]466 if (flag_set['C']) {
467 bkpinfo->backup_media_type = cdstream;
[1]468 }
[116]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 }
[1063]487 if (flag_set['U']) {
488 bkpinfo->backup_media_type = usb;
[1770]489 /* Never try to eject a USB device */
490 bkpinfo->please_dont_eject = TRUE;
[1063]491 }
[948]492 if (flag_set['z']) {
493 if (find_home_of_exe("getfattr")) {
[1080]494 mr_asprintf(&g_getfattr,"getfattr");
[948]495 }
496 if (find_home_of_exe("getfacl")) {
[1080]497 mr_asprintf(&g_getfacl,"getfacl");
[948]498 }
499 }
[1]500
[805]501 /* optional, popular */
[116]502 if (flag_set['g']) {
503 g_text_mode = FALSE;
504 }
[805]505
[116]506 if (flag_set['E']) {
[1817]507 if (bkpinfo->exclude_paths != NULL) {
508 mr_strcat(bkpinfo->exclude_paths, " ");
[116]509 }
[1080]510 mr_asprintf(&tmp1, flag_val['E']);
[605]511 p = tmp1;
512 q = tmp1;
[542]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';
[805]519 /* Fix bug 14 where ending / cause a problem later
520 * so handled here for the moment */
521 q--;
[809]522 if (*q == '/') {
[805]523 *q = '\0';
524 }
525 q++;
526 /* End of bug fix */
[542]527 if (stat(p, &buf) != 0) {
[1108]528 mr_msg(1, "WARNING ! %s doesn't exist", p);
[542]529 }
[633]530 p = q+1 ;
[542]531 } else {
532 if (stat(p, &buf) != 0) {
[1108]533 mr_msg(1, "WARNING ! %s doesn't exist", p);
[542]534 }
535 p = NULL;
536 }
[289]537 }
[1080]538 mr_free(tmp1);
[1817]539 mr_strcat(bkpinfo->exclude_paths, flag_val['E']);
[116]540 }
541 if (flag_set['e']) {
542 bkpinfo->please_dont_eject = TRUE;
543 }
544 if (flag_set['N']) // exclude NFS mounts & devices
545 {
[1191]546 mr_asprintf(&psz, list_of_NFS_mounts_only());
[1817]547 if (bkpinfo->exclude_paths != NULL) {
548 mr_strcat(bkpinfo->exclude_paths, " ");
[116]549 }
[1817]550 mr_strcat(bkpinfo->exclude_paths, psz);
[1191]551 mr_free(psz);
[1108]552 mr_msg(3, "-N means we're now excluding %s",
[116]553 bkpinfo->exclude_paths);
554 }
555 if (flag_set['b']) {
[1191]556 mr_asprintf(&psz, flag_val['b']);
[1108]557 mr_msg(1, "psz = '%s'", psz);
[116]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 }
[1191]564 mr_free(psz);
565
[1108]566 mr_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
567 mr_msg(1, "Internal tape block size is now %ld bytes", itbs);
[116]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 }
[1191]574
[116]575 if (flag_set['D']) {
[1639]576 bkpinfo->differential = TRUE;
[1680]577 } else {
578 bkpinfo->differential = mr_conf->differential;
[1]579 }
[1191]580
[116]581 if (flag_set['x']) {
582 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
[296]583 if (run_program_and_log_output("which ntfsclone", 2)) {
584 fatal_error("Please install ntfsprogs package/tarball.");
[116]585 }
[1]586 }
[116]587 if (flag_set['m']) {
[1609]588 bkpinfo->manual_tray = TRUE;
[1]589 }
[116]590 if (flag_set['k']) {
[1669]591 mr_allocstr(bkpinfo->kernel_path, flag_val['k']);
[116]592 if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
[1669]593 mr_allocstr(bkpinfo->kernel_path, "FAILSAFE");
[116]594 }
595 if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
596 && !does_file_exist(bkpinfo->kernel_path)) {
597 retval++;
[1191]598 mr_asprintf(&tmp2,
599 _("You specified kernel '%s', which does not exist\n"),
[116]600 bkpinfo->kernel_path);
[1191]601 log_to_screen(tmp2);
602 mr_free(tmp2);
[116]603 }
604 }
[1191]605
[116]606 if (flag_set['p']) {
[1628]607 mr_allocstr(bkpinfo->prefix, flag_val['p']);
[116]608 }
[1]609
[1063]610 if (flag_set['d']) { /* backup directory (if ISO/NFS/USB) */
[116]611 if (flag_set['i']) {
612 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
[1191]613 mr_asprintf(&tmp2, "ls -l %s", bkpinfo->isodir);
[1770]614 if (run_program_and_log_output(tmp2, 2)) {
[116]615 fatal_error
616 ("output folder does not exist - please create it");
617 }
[1191]618 mr_free(tmp2);
[116]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) */
[1594]622 mr_asprintf(&tmp2,flag_val['d']);
623 mr_free(bkpinfo->media_device);
624 bkpinfo->media_device = tmp2;
[116]625 }
[1]626 }
[116]627
628 if (flag_set['n']) {
[1770]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)) {
[116]632 retval++;
[1191]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"),
[116]636 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
[1191]637 log_to_screen(tmp2);
[116]638 }
[1191]639 mr_free(tmp2);
[1770]640 unlink(tmp1);
641 mr_free(tmp1);
[1]642 }
643
[116]644 if (!flag_set['d']
[1594]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;
[116]650 } else {
[1594]651 fatal_error(_("No device provided either on command line or in the configuration file"));
[116]652 }
[1]653 }
654
[116]655 if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
656 retval++;
[1191]657 log_to_screen(_("Please specify the backup device/directory.\n"));
[116]658 fatal_error
659 ("You didn't use -d to specify the backup device/directory.");
[1]660 }
[1769]661
662 /* optional, obscure */
[116]663 for (i = '0'; i <= '9'; i++) {
664 if (flag_set[i]) {
665 bkpinfo->compression_level = i - '0';
666 } /* not '\0' but '0' */
[1]667 }
[116]668 if (flag_set['S']) {
669 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
670 random() % 32768);
[1]671 }
[116]672 if (flag_set['T']) {
[1663]673 setup_tmpdir(flag_val['T']);
[1191]674 mr_asprintf(&tmp2, "touch %s/.foo.dat", flag_val['T']);
675 if (run_program_and_log_output(tmp2, 1)) {
[116]676 retval++;
677 log_to_screen
[1191]678 (_("Please specify a tempdir which I can write to. :)"));
[116]679 fatal_error("I cannot write to the tempdir you specified.");
680 }
[1191]681 mr_free(tmp2);
682
[1663]683 mr_asprintf(&tmp2, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
[1191]684 if (run_program_and_log_output(tmp2, 1)) {
[116]685 retval++;
686 log_to_screen
[1191]687 (_("Please don't specify a SAMBA or VFAT or NFS tmpdir."));
[116]688 fatal_error("I cannot write to the tempdir you specified.");
689 }
[1191]690 mr_free(tmp2);
[1]691 }
[1191]692
[116]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']) {
[1]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
[116]712 if (!strchr
713 (BOOT_LOADER_CHARS,
714 (bkpinfo->boot_loader = flag_val['l'][0]))) {
[1191]715 mr_msg(1, "%c? What is %c? I need G, L, E or R.",
[116]716 bkpinfo->boot_loader, bkpinfo->boot_loader);
717 fatal_error
718 ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
719 }
[1]720#undef BOOT_LOADER_CHARS
721 }
[1191]722
[116]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 }
[1191]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
[116]740 if (flag_set['P']) {
741 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
742 }
[1191]743
[116]744 if (!flag_set['o']
745 &&
746 !run_program_and_log_output
[1770]747 ("grep -Ei suse /etc/issue.net | grep -E '9.0' | grep 64", 2)) {
[116]748 bkpinfo->make_cd_use_lilo = TRUE;
749 log_to_screen
[1191]750 (_("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."));
[116]751 }
[1191]752
[116]753 if (flag_set['o']) {
754 bkpinfo->make_cd_use_lilo = TRUE;
755 }
[1]756#ifndef __FreeBSD__
[116]757 else {
758 if (!is_this_a_valid_disk_format("vfat")) {
759 bkpinfo->make_cd_use_lilo = TRUE;
760 log_to_screen
[1191]761 (_("Your kernel appears not to support vfat filesystems. I am therefore"));
[116]762 log_to_screen
[1581]763 (_("using LILO instead of SYSLINUX as the CD's boot loader."));
[116]764 }
[1770]765 if (run_program_and_log_output("which mkfs.vfat", 2)) {
[116]766 bkpinfo->make_cd_use_lilo = TRUE;
[1]767#ifdef __IA32__
[116]768 log_to_screen
[1191]769 (_("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"));
[116]770 log_to_screen
[1191]771 (_("your boot loader. I shall therefore use LILO instead."));
[1]772#endif
773#ifdef __IA64__
[116]774 log_to_screen
[1191]775 (_("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"));
776 log_to_screen(_("environment correctly. Please install it."));
[116]777 fatal_error("Aborting");
[1]778#endif
[116]779 }
[1]780#ifdef __IA64__
[116]781 /* We force ELILO usage on IA64 */
782 bkpinfo->make_cd_use_lilo = TRUE;
[1]783#endif
[116]784 }
[1]785#endif
786
[116]787 if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
788 paranoid_system("touch /boot/boot.b");
789 }
[1]790
[116]791 i = flag_set['O'] + flag_set['V'];
792 if (i == 0) {
793 retval++;
[1191]794 log_to_screen(_("Specify backup (-O), verify (-V) or both (-OV).\n"));
[116]795 }
[1]796
797/* and finally... */
798
[1080]799 mr_free(tmp);
[116]800 return (retval);
[1]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
[116]816retrieve_switches_from_command_line(int argc, char *argv[],
817 char flag_val[128][MAX_STR_LEN],
818 bool flag_set[128])
[1]819{
[116]820 /*@ ints ** */
821 int opt = 0;
[1191]822 char *tmp = NULL;
[116]823 int i = 0;
[1191]824 int len = 0;
[1]825
[116]826 /*@ bools *** */
827 bool bad_switches = FALSE;
[1]828
[116]829 assert(flag_val != NULL);
830 assert(flag_set != NULL);
[1]831
[116]832 for (i = 0; i < 128; i++) {
833 flag_val[i][0] = '\0';
834 flag_set[i] = FALSE;
[1]835 }
[116]836 while ((opt =
837 getopt(argc, argv,
[1063]838 "0123456789A:B:C:DE:FGHI:J:K:LNOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z"))
[116]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;
[1191]846 mr_asprintf(&tmp, _("Switch -%c previously defined as %s\n"), opt,
[116]847 flag_val[i]);
848 log_to_screen(tmp);
[1191]849 mr_free(tmp);
[116]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
[1191]857 (_("Warning - param '%s' should not have trailing slash!"),
[116]858 optarg);
859 }
860 if (opt == 'd') {
861 if (strchr(flag_val[opt], '/')
862 && flag_val[opt][0] != '/') {
[1191]863 mr_asprintf(&tmp,
864 _("-%c flag --- must be absolute path --- '%s' isn't absolute"),
[116]865 opt, flag_val[opt]);
866 log_to_screen(tmp);
[1191]867 mr_free(tmp);
[116]868 bad_switches = TRUE;
869 }
870 }
871 strcpy(flag_val[opt], optarg);
872 }
873 }
[1]874 }
875 }
[116]876 for (i = optind; i < argc; i++) {
877 bad_switches = TRUE;
[1191]878 mr_asprintf(&tmp, _("Invalid arg -- %s\n"), argv[i]);
[116]879 log_to_screen(tmp);
[1191]880 mr_free(tmp);
[116]881 }
882 return (bad_switches);
[1]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{
[1191]892 char *tmp = NULL;
893 char *tmp2 = NULL;
[1]894
[116]895 switch (sig) {
[1]896 case SIGINT:
[1191]897 mr_asprintf(&tmp, _("SIGINT signal received from OS"));
898 mr_asprintf(&tmp2, _("You interrupted me :-)"));
[1]899 break;
900 case SIGKILL:
[1191]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."));
[1]904 break;
905 case SIGTERM:
[1191]906 mr_asprintf(&tmp, _("SIGTERM signal received from OS"));
907 mr_asprintf(&tmp2, _("Got terminate signal"));
[1]908 break;
909 case SIGHUP:
[1191]910 mr_asprintf(&tmp, _("SIGHUP signal received from OS"));
911 mr_asprintf(&tmp2, _("Hangup on line"));
[1]912 break;
913 case SIGSEGV:
[1191]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."));
[1]917 break;
918 case SIGPIPE:
[1191]919 mr_asprintf(&tmp, _("SIGPIPE signal received from OS"));
920 mr_asprintf(&tmp2, _("Pipe was broken"));
[1]921 break;
[116]922 case SIGABRT:
[1191]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."));
[116]926 break;
[1]927 default:
[1191]928 mr_asprintf(&tmp, _("(Unknown)"));
929 mr_asprintf(&tmp2, _("(Unknown)"));
[116]930 }
[1]931
[116]932 log_to_screen(tmp);
933 log_to_screen(tmp2);
[1191]934 mr_free(tmp);
935 mr_free(tmp2);
[116]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
[1]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{
[116]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 }
[1]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{
[1108]973 mr_msg(1, "Termination in progress");
[116]974 usleep(1000);
975 pthread_exit(0);
[1]976}
977
978/* @} - end of cliGroup */
Note: See TracBrowser for help on using the repository browser.