1 | /***************************************************************************
|
---|
2 | $Id: mondo-cli.c 1903 2008-04-09 23:13:58Z 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 1903 2008-04-09 23:13:58Z bruno $";
|
---|
24 |
|
---|
25 | extern bool g_text_mode;
|
---|
26 | extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ?????
|
---|
27 | extern bool g_sigpipe;
|
---|
28 |
|
---|
29 | extern struct mr_ar_conf *mr_conf;
|
---|
30 |
|
---|
31 | /*@ file pointer **************************************************/
|
---|
32 | extern FILE *g_tape_stream;
|
---|
33 |
|
---|
34 | /*@ long long *****************************************************/
|
---|
35 | extern long long g_tape_posK;
|
---|
36 |
|
---|
37 | /*@ long **********************************************************/
|
---|
38 | extern long g_noof_sets;
|
---|
39 |
|
---|
40 | /*@ bool******** **************************************************/
|
---|
41 | bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
42 | bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup
|
---|
43 | extern bool g_cd_recovery;
|
---|
44 |
|
---|
45 | extern 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 | */
|
---|
54 | bool g_ISO_restore_mode = FALSE;
|
---|
55 |
|
---|
56 | extern double g_kernel_version;
|
---|
57 | extern int g_current_media_number;
|
---|
58 | extern pid_t g_main_pid;
|
---|
59 | extern 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 */
|
---|
63 | char *g_getfacl = NULL;
|
---|
64 | char *g_getfattr = NULL;
|
---|
65 |
|
---|
66 | /* Reference to global bkpinfo */
|
---|
67 | extern 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 | */
|
---|
80 | int
|
---|
81 | handle_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 | */
|
---|
146 | int 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 | */
|
---|
181 | int
|
---|
182 | process_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 | /* Never try to eject a NFS device */
|
---|
475 | bkpinfo->please_dont_eject = TRUE;
|
---|
476 | }
|
---|
477 | if (flag_set['r']) {
|
---|
478 | bkpinfo->backup_media_type = dvd;
|
---|
479 | }
|
---|
480 | if (flag_set['t']) {
|
---|
481 | bkpinfo->backup_media_type = tape;
|
---|
482 | }
|
---|
483 | if (flag_set['u']) {
|
---|
484 | bkpinfo->backup_media_type = udev;
|
---|
485 | }
|
---|
486 | if (flag_set['w']) {
|
---|
487 | bkpinfo->backup_media_type = cdrw;
|
---|
488 | }
|
---|
489 | if (flag_set['U']) {
|
---|
490 | bkpinfo->backup_media_type = usb;
|
---|
491 | /* Never try to eject a USB device */
|
---|
492 | bkpinfo->please_dont_eject = TRUE;
|
---|
493 | }
|
---|
494 | if (flag_set['z']) {
|
---|
495 | if (find_home_of_exe("getfattr")) {
|
---|
496 | mr_asprintf(&g_getfattr,"getfattr");
|
---|
497 | }
|
---|
498 | if (find_home_of_exe("getfacl")) {
|
---|
499 | mr_asprintf(&g_getfacl,"getfacl");
|
---|
500 | }
|
---|
501 | }
|
---|
502 |
|
---|
503 | /* optional, popular */
|
---|
504 | if (flag_set['g']) {
|
---|
505 | g_text_mode = FALSE;
|
---|
506 | }
|
---|
507 |
|
---|
508 | if (flag_set['E']) {
|
---|
509 | if (bkpinfo->exclude_paths != NULL) {
|
---|
510 | mr_strcat(bkpinfo->exclude_paths, " ");
|
---|
511 | }
|
---|
512 | mr_asprintf(&tmp1, flag_val['E']);
|
---|
513 | p = tmp1;
|
---|
514 | q = tmp1;
|
---|
515 |
|
---|
516 | /* Cut the flag_val['E'] in parts containing all paths to test them */
|
---|
517 | while (p != NULL) {
|
---|
518 | q = strchr(p, ' ');
|
---|
519 | if (q != NULL) {
|
---|
520 | *q = '\0';
|
---|
521 | /* Fix bug 14 where ending / cause a problem later
|
---|
522 | * so handled here for the moment */
|
---|
523 | q--;
|
---|
524 | if (*q == '/') {
|
---|
525 | *q = '\0';
|
---|
526 | }
|
---|
527 | q++;
|
---|
528 | /* End of bug fix */
|
---|
529 | if (stat(p, &buf) != 0) {
|
---|
530 | mr_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
531 | }
|
---|
532 | p = q+1 ;
|
---|
533 | } else {
|
---|
534 | if (stat(p, &buf) != 0) {
|
---|
535 | mr_msg(1, "WARNING ! %s doesn't exist", p);
|
---|
536 | }
|
---|
537 | p = NULL;
|
---|
538 | }
|
---|
539 | }
|
---|
540 | mr_free(tmp1);
|
---|
541 | mr_strcat(bkpinfo->exclude_paths, flag_val['E']);
|
---|
542 | }
|
---|
543 | if (flag_set['e']) {
|
---|
544 | bkpinfo->please_dont_eject = TRUE;
|
---|
545 | }
|
---|
546 | if (flag_set['N']) // exclude NFS mounts & devices
|
---|
547 | {
|
---|
548 | mr_asprintf(&psz, list_of_NFS_mounts_only());
|
---|
549 | if (bkpinfo->exclude_paths != NULL) {
|
---|
550 | mr_strcat(bkpinfo->exclude_paths, " ");
|
---|
551 | }
|
---|
552 | mr_strcat(bkpinfo->exclude_paths, psz);
|
---|
553 | mr_free(psz);
|
---|
554 | mr_msg(3, "-N means we're now excluding %s",
|
---|
555 | bkpinfo->exclude_paths);
|
---|
556 | }
|
---|
557 | if (flag_set['b']) {
|
---|
558 | mr_asprintf(&psz, flag_val['b']);
|
---|
559 | mr_msg(1, "psz = '%s'", psz);
|
---|
560 | if (psz[strlen(psz) - 1] == 'k') {
|
---|
561 | psz[strlen(psz) - 1] = '\0';
|
---|
562 | itbs = atol(psz) * 1024L;
|
---|
563 | } else {
|
---|
564 | itbs = atol(psz);
|
---|
565 | }
|
---|
566 | mr_free(psz);
|
---|
567 |
|
---|
568 | mr_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
|
---|
569 | mr_msg(1, "Internal tape block size is now %ld bytes", itbs);
|
---|
570 | if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) {
|
---|
571 | fatal_error
|
---|
572 | ("Are you nuts? Silly, your internal tape block size is. Abort, I shall.");
|
---|
573 | }
|
---|
574 | bkpinfo->internal_tape_block_size = itbs;
|
---|
575 | }
|
---|
576 |
|
---|
577 | if (flag_set['D']) {
|
---|
578 | bkpinfo->differential = TRUE;
|
---|
579 | } else {
|
---|
580 | bkpinfo->differential = mr_conf->differential;
|
---|
581 | }
|
---|
582 |
|
---|
583 | if (flag_set['x']) {
|
---|
584 | strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
|
---|
585 | if (run_program_and_log_output("which ntfsclone", 2)) {
|
---|
586 | fatal_error("Please install ntfsprogs package/tarball.");
|
---|
587 | }
|
---|
588 | }
|
---|
589 | if (flag_set['m']) {
|
---|
590 | bkpinfo->manual_tray = TRUE;
|
---|
591 | }
|
---|
592 | if (flag_set['k']) {
|
---|
593 | mr_allocstr(bkpinfo->kernel_path, flag_val['k']);
|
---|
594 | if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
|
---|
595 | mr_allocstr(bkpinfo->kernel_path, "FAILSAFE");
|
---|
596 | }
|
---|
597 | if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
|
---|
598 | && !does_file_exist(bkpinfo->kernel_path)) {
|
---|
599 | retval++;
|
---|
600 | mr_asprintf(&tmp2,
|
---|
601 | _("You specified kernel '%s', which does not exist\n"),
|
---|
602 | bkpinfo->kernel_path);
|
---|
603 | log_to_screen(tmp2);
|
---|
604 | mr_free(tmp2);
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | if (flag_set['p']) {
|
---|
609 | mr_allocstr(bkpinfo->prefix, flag_val['p']);
|
---|
610 | }
|
---|
611 |
|
---|
612 | if (flag_set['d']) { /* backup directory (if ISO/NFS/USB) */
|
---|
613 | if (flag_set['i']) {
|
---|
614 | strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
|
---|
615 | mr_asprintf(&tmp2, "ls -l %s", bkpinfo->isodir);
|
---|
616 | if (run_program_and_log_output(tmp2, 2)) {
|
---|
617 | fatal_error
|
---|
618 | ("output folder does not exist - please create it");
|
---|
619 | }
|
---|
620 | mr_free(tmp2);
|
---|
621 | } else if (flag_set['n']) {
|
---|
622 | strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
|
---|
623 | } else { /* backup device (if tape/CD-R/CD-RW) */
|
---|
624 | mr_asprintf(&tmp2,flag_val['d']);
|
---|
625 | mr_free(bkpinfo->media_device);
|
---|
626 | bkpinfo->media_device = tmp2;
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | if (flag_set['n']) {
|
---|
631 | mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
|
---|
632 | mr_asprintf(&tmp2, "echo hi > %s", tmp1);
|
---|
633 | if (run_program_and_log_output(tmp2, 2)) {
|
---|
634 | retval++;
|
---|
635 | mr_free(tmp2);
|
---|
636 | mr_asprintf(&tmp2,
|
---|
637 | _("Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n"),
|
---|
638 | bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
|
---|
639 | log_to_screen(tmp2);
|
---|
640 | }
|
---|
641 | mr_free(tmp2);
|
---|
642 | unlink(tmp1);
|
---|
643 | mr_free(tmp1);
|
---|
644 | }
|
---|
645 |
|
---|
646 | if (!flag_set['d']
|
---|
647 | && (flag_set['w'] || flag_set['C'] || flag_set['U'])) {
|
---|
648 | if (bkpinfo->media_device) {
|
---|
649 | mr_msg(4, "Using device %s", bkpinfo->media_device);
|
---|
650 | strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
|
---|
651 | flag_set['d'] = TRUE;
|
---|
652 | } else {
|
---|
653 | fatal_error(_("No device provided either on command line or in the configuration file"));
|
---|
654 | }
|
---|
655 | }
|
---|
656 |
|
---|
657 | if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) {
|
---|
658 | retval++;
|
---|
659 | log_to_screen(_("Please specify the backup device/directory.\n"));
|
---|
660 | fatal_error
|
---|
661 | ("You didn't use -d to specify the backup device/directory.");
|
---|
662 | }
|
---|
663 |
|
---|
664 | /* optional, obscure */
|
---|
665 | for (i = '0'; i <= '9'; i++) {
|
---|
666 | if (flag_set[i]) {
|
---|
667 | bkpinfo->compression_level = i - '0';
|
---|
668 | } /* not '\0' but '0' */
|
---|
669 | }
|
---|
670 | if (flag_set['S']) {
|
---|
671 | sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
|
---|
672 | random() % 32768);
|
---|
673 | }
|
---|
674 | if (flag_set['T']) {
|
---|
675 | setup_tmpdir(flag_val['T']);
|
---|
676 | mr_asprintf(&tmp2, "touch %s/.foo.dat", flag_val['T']);
|
---|
677 | if (run_program_and_log_output(tmp2, 1)) {
|
---|
678 | retval++;
|
---|
679 | log_to_screen
|
---|
680 | (_("Please specify a tempdir which I can write to. :)"));
|
---|
681 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
682 | }
|
---|
683 | mr_free(tmp2);
|
---|
684 |
|
---|
685 | mr_asprintf(&tmp2, "ln -sf %s/.foo.dat %s/.bar.dat", bkpinfo->tmpdir, bkpinfo->tmpdir);
|
---|
686 | if (run_program_and_log_output(tmp2, 1)) {
|
---|
687 | retval++;
|
---|
688 | log_to_screen
|
---|
689 | (_("Please don't specify a SAMBA or VFAT or NFS tmpdir."));
|
---|
690 | fatal_error("I cannot write to the tempdir you specified.");
|
---|
691 | }
|
---|
692 | mr_free(tmp2);
|
---|
693 | }
|
---|
694 |
|
---|
695 | if (flag_set['A']) {
|
---|
696 | strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
|
---|
697 | }
|
---|
698 | if (flag_set['B']) {
|
---|
699 | strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
|
---|
700 | }
|
---|
701 | if (flag_set['H']) {
|
---|
702 | g_cd_recovery = TRUE;
|
---|
703 | }
|
---|
704 | if (flag_set['l']) {
|
---|
705 | #ifdef __FreeBSD__
|
---|
706 | # define BOOT_LOADER_CHARS "GLBMR"
|
---|
707 | #else
|
---|
708 | # ifdef __IA64__
|
---|
709 | # define BOOT_LOADER_CHARS "GER"
|
---|
710 | # else
|
---|
711 | # define BOOT_LOADER_CHARS "GLR"
|
---|
712 | # endif
|
---|
713 | #endif
|
---|
714 | if (!strchr
|
---|
715 | (BOOT_LOADER_CHARS,
|
---|
716 | (bkpinfo->boot_loader = flag_val['l'][0]))) {
|
---|
717 | mr_msg(1, "%c? What is %c? I need G, L, E or R.",
|
---|
718 | bkpinfo->boot_loader, bkpinfo->boot_loader);
|
---|
719 | fatal_error
|
---|
720 | ("Please specify GRUB, LILO, ELILO or RAW with the -l switch");
|
---|
721 | }
|
---|
722 | #undef BOOT_LOADER_CHARS
|
---|
723 | }
|
---|
724 |
|
---|
725 | if (flag_set['f']) {
|
---|
726 | strncpy(bkpinfo->boot_device,
|
---|
727 | resolve_softlinks_to_get_to_actual_device_file(flag_val
|
---|
728 | ['f']),
|
---|
729 | MAX_STR_LEN / 4);
|
---|
730 | }
|
---|
731 |
|
---|
732 | if (flag_set['Q']) {
|
---|
733 | if (bkpinfo->boot_device == NULL) {
|
---|
734 | fatal_error("-f option required when using -Q\n");
|
---|
735 | }
|
---|
736 | i = which_boot_loader(bkpinfo->boot_device);
|
---|
737 | mr_msg(3, "boot loader is %c, residing at %s", i, bkpinfo->boot_device);
|
---|
738 | log_to_screen(_("boot loader is %c, residing at %s\n"), i, tmp);
|
---|
739 | finish(0);
|
---|
740 | }
|
---|
741 |
|
---|
742 | if (flag_set['P']) {
|
---|
743 | strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
|
---|
744 | }
|
---|
745 |
|
---|
746 | if (!flag_set['o']
|
---|
747 | &&
|
---|
748 | !run_program_and_log_output
|
---|
749 | ("grep -Ei suse /etc/issue.net | grep -E '9.0' | grep 64", 2)) {
|
---|
750 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
751 | log_to_screen
|
---|
752 | (_("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."));
|
---|
753 | }
|
---|
754 |
|
---|
755 | if (flag_set['o']) {
|
---|
756 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
757 | }
|
---|
758 | #ifndef __FreeBSD__
|
---|
759 | else {
|
---|
760 | if (!is_this_a_valid_disk_format("vfat")) {
|
---|
761 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
762 | log_to_screen
|
---|
763 | (_("Your kernel appears not to support vfat filesystems. I am therefore"));
|
---|
764 | log_to_screen
|
---|
765 | (_("using LILO instead of SYSLINUX as the media boot loader."));
|
---|
766 | }
|
---|
767 | if (run_program_and_log_output("which mkfs.vfat", 2)) {
|
---|
768 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
769 | #ifdef __IA32__
|
---|
770 | log_to_screen
|
---|
771 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"));
|
---|
772 | log_to_screen
|
---|
773 | (_("your boot loader. I shall therefore use LILO instead."));
|
---|
774 | #endif
|
---|
775 | #ifdef __IA64__
|
---|
776 | log_to_screen
|
---|
777 | (_("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"));
|
---|
778 | log_to_screen(_("environment correctly. Please install it."));
|
---|
779 | fatal_error("Aborting");
|
---|
780 | #endif
|
---|
781 | }
|
---|
782 | #ifdef __IA64__
|
---|
783 | /* We force ELILO usage on IA64 */
|
---|
784 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
785 | #endif
|
---|
786 | }
|
---|
787 | #endif
|
---|
788 |
|
---|
789 | if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) {
|
---|
790 | paranoid_system("touch /boot/boot.b");
|
---|
791 | }
|
---|
792 |
|
---|
793 | i = flag_set['O'] + flag_set['V'];
|
---|
794 | if (i == 0) {
|
---|
795 | retval++;
|
---|
796 | log_to_screen(_("Specify backup (-O), verify (-V) or both (-OV).\n"));
|
---|
797 | }
|
---|
798 |
|
---|
799 | /* and finally... */
|
---|
800 |
|
---|
801 | mr_free(tmp);
|
---|
802 | return (retval);
|
---|
803 | }
|
---|
804 |
|
---|
805 |
|
---|
806 | /**
|
---|
807 | * Get the switches from @p argc and @p argv using getopt() and place them in
|
---|
808 | * @p flag_set and @p flag_val.
|
---|
809 | * @param argc The argument count (@p argc passed to main()).
|
---|
810 | * @param argv The argument vector (@p argv passed to main()).
|
---|
811 | * @param flag_val An array indexed by switch letter - if a switch is set and
|
---|
812 | * has an argument then set flag_val[switch] to that argument.
|
---|
813 | * @param flag_set An array indexed by switch letter - if a switch is set then
|
---|
814 | * set flag_set[switch] to TRUE, else set it to FALSE.
|
---|
815 | * @return The number of problems with the command line (0 for success).
|
---|
816 | */
|
---|
817 | int
|
---|
818 | retrieve_switches_from_command_line(int argc, char *argv[],
|
---|
819 | char flag_val[128][MAX_STR_LEN],
|
---|
820 | bool flag_set[128])
|
---|
821 | {
|
---|
822 | /*@ ints ** */
|
---|
823 | int opt = 0;
|
---|
824 | char *tmp = NULL;
|
---|
825 | int i = 0;
|
---|
826 | int len = 0;
|
---|
827 |
|
---|
828 | /*@ bools *** */
|
---|
829 | bool bad_switches = FALSE;
|
---|
830 |
|
---|
831 | assert(flag_val != NULL);
|
---|
832 | assert(flag_set != NULL);
|
---|
833 |
|
---|
834 | for (i = 0; i < 128; i++) {
|
---|
835 | flag_val[i][0] = '\0';
|
---|
836 | flag_set[i] = FALSE;
|
---|
837 | }
|
---|
838 | while ((opt =
|
---|
839 | getopt(argc, argv,
|
---|
840 | "0123456789A:B:C:DE:FGHI:J:K:LNOP:QRS:T:UVWb:c:d:ef:gik:l:mn:op:rs:tuw:x:z"))
|
---|
841 | != -1) {
|
---|
842 | if (opt == '?') {
|
---|
843 | bad_switches = TRUE;
|
---|
844 | /*log_it("Invalid option: %c\n",optopt); */
|
---|
845 | } else {
|
---|
846 | if (flag_set[optopt]) {
|
---|
847 | bad_switches = TRUE;
|
---|
848 | mr_asprintf(&tmp, _("Switch -%c previously defined as %s\n"), opt,
|
---|
849 | flag_val[i]);
|
---|
850 | log_to_screen(tmp);
|
---|
851 | mr_free(tmp);
|
---|
852 | } else {
|
---|
853 | flag_set[opt] = TRUE;
|
---|
854 | if (optarg) {
|
---|
855 | len = strlen(optarg);
|
---|
856 | if (optarg[0] != '/' && optarg[len - 1] == '/') {
|
---|
857 | optarg[--len] = '\0';
|
---|
858 | log_to_screen
|
---|
859 | (_("Warning - param '%s' should not have trailing slash!"),
|
---|
860 | optarg);
|
---|
861 | }
|
---|
862 | if (opt == 'd') {
|
---|
863 | if (strchr(flag_val[opt], '/')
|
---|
864 | && flag_val[opt][0] != '/') {
|
---|
865 | mr_asprintf(&tmp,
|
---|
866 | _("-%c flag --- must be absolute path --- '%s' isn't absolute"),
|
---|
867 | opt, flag_val[opt]);
|
---|
868 | log_to_screen(tmp);
|
---|
869 | mr_free(tmp);
|
---|
870 | bad_switches = TRUE;
|
---|
871 | }
|
---|
872 | }
|
---|
873 | strcpy(flag_val[opt], optarg);
|
---|
874 | }
|
---|
875 | }
|
---|
876 | }
|
---|
877 | }
|
---|
878 | for (i = optind; i < argc; i++) {
|
---|
879 | bad_switches = TRUE;
|
---|
880 | mr_asprintf(&tmp, _("Invalid arg -- %s\n"), argv[i]);
|
---|
881 | log_to_screen(tmp);
|
---|
882 | mr_free(tmp);
|
---|
883 | }
|
---|
884 | return (bad_switches);
|
---|
885 | }
|
---|
886 |
|
---|
887 |
|
---|
888 | /**
|
---|
889 | * Terminate Mondo in response to a signal.
|
---|
890 | * @param sig The signal number received.
|
---|
891 | */
|
---|
892 | void terminate_daemon(int sig)
|
---|
893 | {
|
---|
894 | char *tmp = NULL;
|
---|
895 | char *tmp2 = NULL;
|
---|
896 |
|
---|
897 | switch (sig) {
|
---|
898 | case SIGINT:
|
---|
899 | mr_asprintf(&tmp, _("SIGINT signal received from OS"));
|
---|
900 | mr_asprintf(&tmp2, _("You interrupted me :-)"));
|
---|
901 | break;
|
---|
902 | case SIGKILL:
|
---|
903 | mr_asprintf(&tmp, _("SIGKILL signal received from OS"));
|
---|
904 | mr_asprintf(&tmp2,
|
---|
905 | _("I seriously have no clue how this signal even got to me. Something's wrong with your system."));
|
---|
906 | break;
|
---|
907 | case SIGTERM:
|
---|
908 | mr_asprintf(&tmp, _("SIGTERM signal received from OS"));
|
---|
909 | mr_asprintf(&tmp2, _("Got terminate signal"));
|
---|
910 | break;
|
---|
911 | case SIGHUP:
|
---|
912 | mr_asprintf(&tmp, _("SIGHUP signal received from OS"));
|
---|
913 | mr_asprintf(&tmp2, _("Hangup on line"));
|
---|
914 | break;
|
---|
915 | case SIGSEGV:
|
---|
916 | mr_asprintf(&tmp, _("SIGSEGV signal received from OS"));
|
---|
917 | mr_asprintf(&tmp2,
|
---|
918 | _("Internal programming error. Please send a backtrace as well as your log."));
|
---|
919 | break;
|
---|
920 | case SIGPIPE:
|
---|
921 | mr_asprintf(&tmp, _("SIGPIPE signal received from OS"));
|
---|
922 | mr_asprintf(&tmp2, _("Pipe was broken"));
|
---|
923 | break;
|
---|
924 | case SIGABRT:
|
---|
925 | mr_asprintf(&tmp, _("SIGABRT signal received from OS"));
|
---|
926 | mr_asprintf(&tmp2,
|
---|
927 | _("Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."));
|
---|
928 | break;
|
---|
929 | default:
|
---|
930 | mr_asprintf(&tmp, _("(Unknown)"));
|
---|
931 | mr_asprintf(&tmp2, _("(Unknown)"));
|
---|
932 | }
|
---|
933 |
|
---|
934 | log_to_screen(tmp);
|
---|
935 | log_to_screen(tmp2);
|
---|
936 | mr_free(tmp);
|
---|
937 | mr_free(tmp2);
|
---|
938 | if (sig == SIGABRT) {
|
---|
939 | sleep(10);
|
---|
940 | }
|
---|
941 | kill_buffer();
|
---|
942 | fatal_error
|
---|
943 | ("Mondoarchive is terminating in response to a signal from the OS");
|
---|
944 | finish(254); // just in case
|
---|
945 | }
|
---|
946 |
|
---|
947 |
|
---|
948 | /**
|
---|
949 | * Turn signal-trapping on or off.
|
---|
950 | * @param on If TRUE, turn it on; if FALSE, turn it off (we still trap it, just don't do as much).
|
---|
951 | */
|
---|
952 | void set_signals(int on)
|
---|
953 | {
|
---|
954 | int signals[] =
|
---|
955 | { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 };
|
---|
956 | int i;
|
---|
957 |
|
---|
958 | signal(SIGPIPE, sigpipe_occurred);
|
---|
959 | for (i = 0; signals[i]; i++) {
|
---|
960 | if (on) {
|
---|
961 | signal(signals[i], terminate_daemon);
|
---|
962 | } else {
|
---|
963 | signal(signals[i], termination_in_progress);
|
---|
964 | }
|
---|
965 | }
|
---|
966 | }
|
---|
967 |
|
---|
968 |
|
---|
969 | /**
|
---|
970 | * Exit immediately without cleaning up.
|
---|
971 | * @param sig The signal we are exiting due to.
|
---|
972 | */
|
---|
973 | void termination_in_progress(int sig)
|
---|
974 | {
|
---|
975 | mr_msg(1, "Termination in progress");
|
---|
976 | usleep(1000);
|
---|
977 | pthread_exit(0);
|
---|
978 | }
|
---|
979 |
|
---|
980 | /* @} - end of cliGroup */
|
---|