source: MondoRescue/trunk/mondo/src/common/libmondo-tools.c@ 1081

Last change on this file since 1081 was 1081, checked in by Bruno Cornec, 17 years ago

merge -r1078:1080 $SVN_M/branches/stable

  • Property svn:keywords set to Id
File size: 35.9 KB
Line 
1/* $Id: libmondo-tools.c 1081 2007-01-28 22:20:07Z bruno $
2misc tools
3*/
4
5/**
6 * @file
7 * Miscellaneous tools that didn't really fit anywhere else.
8 */
9
10#include "my-stuff.h"
11#include "mr_mem.h"
12#include "mondostructures.h"
13#include "libmondo-tools.h"
14#include "newt-specific-EXT.h"
15#include "libmondo-files-EXT.h"
16#include "libmondo-fork-EXT.h"
17#include "libmondo-raid-EXT.h"
18#include <sys/socket.h>
19#include <netdb.h>
20#include <netinet/in.h>
21#ifndef S_SPLINT_S
22#include <arpa/inet.h>
23#endif
24#include "mr_mem.h"
25
26/*@unused@*/
27//static char cvsid[] = "$Id: libmondo-tools.c 1081 2007-01-28 22:20:07Z bruno $";
28
29extern int g_tape_buffer_size_MB;
30extern char *g_erase_tmpdir_and_scratchdir;
31extern char *g_serial_string;
32extern bool g_text_mode;
33extern int g_currentY;
34extern int g_current_media_number;
35
36/**
37 * @addtogroup globalGroup
38 * @{
39 */
40bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
41 g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
42bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
43double g_kernel_version;
44
45/**
46 * The place where /boot is mounted. - Used locally only
47 */
48static char *g_boot_mountpt = NULL;
49
50/**
51 * The location of Mondo's home directory.
52 */
53char *g_mondo_home = NULL;
54
55/**
56 * The serial string (used to differentiate between backups) of the current backup.
57 */
58char *g_serial_string = NULL;
59
60/**
61 * The location where tmpfs is mounted, or "" if it's not mounted.
62 */
63char *g_tmpfs_mountpt = NULL;
64char *g_magicdev_command = NULL;
65
66/**
67 * The default maximum level to log messages at or below.
68 */
69int g_loglevel = DEFAULT_DEBUG_LEVEL;
70
71/* @} - end of globalGroup */
72
73
74extern pid_t g_buffer_pid;
75extern pid_t g_main_pid;
76
77extern t_bkptype g_backup_media_type;
78extern char *g_backup_media_string;
79
80extern bool am_I_in_disaster_recovery_mode(void);
81
82
83/**
84 * @addtogroup utilityGroup
85 * @{
86 */
87/**
88 * Assertion handler. Prints a friendly message to the user,
89 * offering to ignore all, dump core, break to debugger,
90 * exit, or ignore. Intended to be used with an assert() macro.
91 *
92 * @param file The file in which the assertion triggered.
93 * @param function The function (@c __FUNCTION__) in which the assertion triggered.
94 * @param line The line number of the assert() statement.
95 * @param exp The expression that failed (as a string).
96 */
97void _mondo_assert_fail(const char *file,
98 const char *function, int line, const char *exp)
99{
100 static int ignoring_assertions = 0;
101 bool is_valid = TRUE;
102
103 log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
104 function);
105 if (ignoring_assertions) {
106 log_it("Well, the user doesn't care...");
107 return;
108 }
109#ifndef _XWIN
110 if (!g_text_mode)
111 newtSuspend();
112#endif
113 printf(_("ASSERTION FAILED: `%s'\n"), exp);
114 printf(_("\tat %s:%d in %s\n\n"), file, line, function);
115 printf(_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
116 do {
117 is_valid = TRUE;
118 switch (toupper(getchar())) {
119 case 'A': // ignore (A)ll
120 ignoring_assertions = 1;
121 break;
122 case 'B': // a(B)ort
123 signal(SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
124 raise(SIGABRT);
125 break; /* "can't get here" */
126 case 'D': // (D)ebug, aka asm("int 3")
127#ifdef __IA32__
128 __asm__ __volatile__("int $3"); // break to debugger
129#endif
130 break;
131 case 'E': // (E)xit
132 fatal_error("Failed assertion -- see above for details");
133 break; /* "can't get here" */
134 case 'I': // (I)gnore
135 break;
136 /* These next two work as follows:
137 the `default' catches the user's invalid choice and says so;
138 the '\n' catches the newline on the end and prints the prompt again.
139 */
140 case '\n':
141 printf
142 (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
143 break;
144 default:
145 is_valid = FALSE;
146 printf(_("Invalid choice.\n"));
147 break;
148 }
149 } while (!is_valid);
150
151 if (ignoring_assertions) {
152 log_it("Ignoring ALL assertions from now on.");
153 } else {
154 log_it("Ignoring assertion: %s", exp);
155 }
156
157 getchar(); // skip \n
158
159#ifndef _XWIN
160 if (!g_text_mode)
161 newtResume();
162#endif
163}
164
165/**
166 * Clean's up users' KDE desktops.
167 * @bug Details about this function are unknown.
168 */
169void clean_up_KDE_desktop_if_necessary(void)
170{
171 char *tmp;
172
173 mr_asprintf(&tmp,
174 "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
175file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
176awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
177else { print $0;};}' $file.old > $file ; fi ; done");
178 run_program_and_log_output(tmp, 5);
179 mr_free(tmp);
180}
181
182
183/**
184 * Locate mondoarchive's home directory. Searches in /usr/share/mondo,
185 * /usr/local/share/mondo, /opt, or if all else fails, search /usr.
186 *
187 * @param home_sz String to store the home directory ("" if it could not be found).
188 * @return 0 for success, nonzero for failure.
189 */
190char *find_and_store_mondoarchives_home()
191{
192 char *home_sz = NULL;
193
194 mr_asprintf(&home_sz, MONDO_SHARE);
195 return (home_sz);
196}
197
198
199char *get_architecture()
200{
201#ifdef __IA32__
202 return ("i386");
203#endif
204#ifdef __X86_64__
205 return ("x86-64");
206#endif
207#ifdef __IA64__
208 return ("ia64");
209#endif
210 return ("unknown");
211}
212
213
214
215double get_kernel_version()
216{
217 char *p, *tmp;
218 double d;
219#ifdef __FreeBSD__
220 // JOSH - FIXME :)
221 d = 5.2; // :-)
222#else
223 tmp = call_program_and_get_last_line_of_output("uname -r");
224 p = strchr(tmp, '.');
225 if (p) {
226 p = strchr(++p, '.');
227 if (p) {
228 while (*p) {
229 *p = *(p + 1);
230 p++;
231 }
232 }
233 }
234// log_msg(1, "tmp = '%s'", tmp);
235 d = atof(tmp);
236#endif
237 log_msg(1, "g_kernel_version = %f", d);
238 return (d);
239}
240
241
242
243
244
245/**
246 * Get the current time.
247 * @return number of seconds since the epoch.
248 */
249long get_time()
250{
251 return (long) time((void *) 0);
252}
253
254
255
256
257
258
259
260/**
261 * Initialize a RAID volume structure, setting fields to zero. The
262 * actual hard drive is unaffected.
263 *
264 * @param raidrec The RAID volume structure to initialize.
265 * @note This function is system dependent.
266 */
267#ifdef __FreeBSD__
268void initialize_raidrec(struct vinum_volume *raidrec)
269{
270 int i, j;
271 raidrec->volname[0] = '\0';
272 raidrec->plexes = 0;
273 for (i = 0; i < 9; ++i) {
274 raidrec->plex[i].raidlevel = -1;
275 raidrec->plex[i].stripesize = 0;
276 raidrec->plex[i].subdisks = 0;
277 for (j = 0; j < 9; ++j) {
278 strcpy(raidrec->plex[i].sd[j].which_device, "");
279 }
280 }
281}
282#else
283void initialize_raidrec(struct raid_device_record *raidrec)
284{
285 assert(raidrec != NULL);
286 raidrec->raid_device = NULL;
287 raidrec->raid_level = -9;
288 raidrec->persistent_superblock = 1;
289 raidrec->chunk_size = 64;
290 raidrec->parity = -1;
291 raidrec->data_disks.entries = 0;
292 raidrec->spare_disks.entries = 0;
293 raidrec->parity_disks.entries = 0;
294 raidrec->failed_disks.entries = 0;
295 raidrec->additional_vars.entries = 0;
296}
297#endif
298
299
300
301
302/**
303 * Insert modules that Mondo requires.
304 * Currently inserts @c dos, @c fat, @c vfat, and @c osst for Linux;
305 * @c msdosfs and @c ext2fs for FreeBSD.
306 */
307void insmod_crucial_modules(void)
308{
309#ifdef __FreeBSD__
310 system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
311 system("kldstat | grep ext2fs || kldload ext2fs 2> /dev/null");
312#else
313 system("modprobe -a dos fat vfat loop &> /dev/null");
314#endif
315}
316
317
318/**
319 * Finish configuring the backup information structure. Call this function
320 * to set the parameters that depend on those that can be given on the command
321 * line.
322 *
323 * @param bkpinfo The backup information structure. Fields modified/used:
324 * - Used: @c bkpinfo->backup_data
325 * - Used: @c bkpinfo->backup_media_type
326 * - Used: @c bkpinfo->cdrw_speed
327 * - Used: @c bkpinfo->compression_level
328 * - Used: @c bkpinfo->include_paths
329 * - Used: @c bkpinfo->prefix
330 * - Used: @c bkpinfo->isodir
331 * - Used: @c bkpinfo->manual_cd_tray
332 * - Used: @c bkpinfo->make_cd_use_lilo
333 * - Used: @c bkpinfo->media_device
334 * - Used: @c bkpinfo->nfs_mount
335 * - Used: @c bkpinfo->nonbootable_backup
336 * - Used: @c bkpinfo->scratchdir
337 * - Used: @c bkpinfo->tmpdir
338 * - Used: @c bkpinfo->use_lzo
339 * - Modified: @c bkpinfo->call_before_iso
340 * - Modified: @c bkpinfo->call_make_iso
341 * - Modified: @c bkpinfo->optimal_set_size
342 * - Modified: @c bkpinfo->zip_exe
343 * - Modified: @c bkpinfo->zip_suffix
344 *
345 * @return number of errors, or 0 for success.
346 * @note Also creates directories that are specified in the @c bkpinfo structure but
347 * do not exist.
348 */
349int post_param_configuration(struct s_bkpinfo *bkpinfo)
350{
351 char *extra_cdrom_params = NULL;
352 char *mondo_mkisofs_sz = NULL;
353 char *command = NULL;
354 char *hostname = NULL, *ip_address = NULL;
355 int retval = 0;
356 long avm = 0;
357 char *colon = NULL;
358 char *cdr_exe = NULL;
359 char *tmp = NULL;
360 char *tmp1 = NULL;
361 char *call_before_iso_user = NULL;
362 int rdsiz_MB;
363 char *iso_path = NULL;
364
365 assert(bkpinfo != NULL);
366 bkpinfo->optimal_set_size =
367 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
368 1024;
369
370 log_msg(1, "Foo");
371 if (bkpinfo->backup_media_type == tape) {
372 log_msg(1, "Bar");
373 mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
374 log_msg(1, "tmp = '%s'", tmp);
375 if (run_program_and_log_output(tmp, 3)) {
376 fatal_error
377 ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
378 }
379 mr_free(tmp);
380 }
381 make_hole_for_dir(bkpinfo->scratchdir);
382 make_hole_for_dir(bkpinfo->tmpdir);
383 if (bkpinfo->backup_media_type == iso)
384 make_hole_for_dir(bkpinfo->isodir);
385
386 run_program_and_log_output("uname -a", 5);
387 run_program_and_log_output("cat /etc/*-release", 5);
388 run_program_and_log_output("cat /etc/*issue*", 5);
389 mr_asprintf(&g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
390 mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
391 paranoid_system(command);
392 mr_free(command);
393 rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
394#ifdef __FreeBSD__
395 tmp = call_program_and_get_last_line_of_output
396 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6");
397 avm += atol(tmp);
398 mr_free(tmp);
399 tmp = call_program_and_get_last_line_of_output
400 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc");
401 avm += atol(tmp);
402 mr_free(tmp);
403 mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
404 g_tmpfs_mountpt);
405#else
406 tmp = call_program_and_get_last_line_of_output
407 ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1");
408 avm += atol(tmp);
409 mr_free(tmp);
410 mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
411 g_tmpfs_mountpt, rdsiz_MB, 'm');
412 run_program_and_log_output("cat /proc/cpuinfo", 5);
413 /* BERLIOS: rpm is not necessarily there ! */
414 run_program_and_log_output
415 ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
416 5);
417#endif
418 if (avm / 1024 > rdsiz_MB * 3) {
419 if (run_program_and_log_output(command, 5)) {
420 mr_free(g_tmpfs_mountpt);
421 log_it("Failed to mount tmpfs");
422 } else {
423 log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
424 }
425 } else {
426 mr_free(g_tmpfs_mountpt);
427 log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
428 }
429 mr_free(command);
430
431 if (bkpinfo->use_lzo) {
432 mr_allocstr(bkpinfo->zip_exe, "lzop");
433 mr_allocstr(bkpinfo->zip_suffix, "lzo");
434 } else if (bkpinfo->use_gzip) {
435 strcpy(bkpinfo->zip_exe, "gzip");
436 strcpy(bkpinfo->zip_suffix, "gz");
437 } else if (bkpinfo->use_gzip) {
438 strcpy(bkpinfo->zip_exe, "gzip");
439 strcpy(bkpinfo->zip_suffix, "gz");
440 } else if (bkpinfo->compression_level != 0) {
441 mr_allocstr(bkpinfo->zip_exe, "bzip2");
442 mr_allocstr(bkpinfo->zip_suffix, "bz2");
443 } else {
444 bkpinfo->zip_exe = NULL;
445 bkpinfo->zip_suffix = NULL;
446 }
447
448// DVD
449
450 if (bkpinfo->backup_media_type == dvd) {
451 tmp = find_home_of_exe("growisofs");
452 if (!tmp) {
453 fatal_error("Please install growisofs.");
454 }
455 mr_free(tmp);
456
457 if (bkpinfo->nonbootable_backup) {
458 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
459 } else if
460#ifdef __FreeBSD__
461 (TRUE)
462#else
463 (bkpinfo->make_cd_use_lilo)
464#endif
465#ifdef __IA64__
466 {
467 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
468 }
469#else
470 {
471 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
472 }
473#endif
474 else
475 {
476 mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
477 }
478 if (bkpinfo->manual_cd_tray) {
479 fatal_error("Manual CD tray + DVD not supported yet.");
480 // -m isn't supported by growisofs, BTW...
481 } else {
482 mr_asprintf(&bkpinfo->call_make_iso,
483 "%s %s -Z %s . 2>> _ERR_",
484 mondo_mkisofs_sz, "", bkpinfo->media_device);
485 }
486 mr_free(mondo_mkisofs_sz);
487
488 if (getenv ("SUDO_COMMAND")) {
489 mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND");
490 tmp = call_program_and_get_last_line_of_output(command);
491 if (!strcmp(tmp, "1")) {
492 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
493 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
494 }
495 mr_free(tmp);
496 mr_free(command);
497 }
498 log_msg(2, "call_make_iso (DVD res) is ... %s",
499 bkpinfo->call_make_iso);
500 } // end of DVD code
501
502// CD-R or CD-RW
503 if (bkpinfo->backup_media_type == cdrw
504 || bkpinfo->backup_media_type == cdr) {
505 if (!bkpinfo->manual_cd_tray) {
506 mr_asprintf(&extra_cdrom_params, "-waiti ");
507 }
508 if (bkpinfo->backup_media_type == cdrw) {
509 if (extra_cdrom_params != NULL) {
510 mr_asprintf(&tmp, extra_cdrom_params);
511 mr_free(extra_cdrom_params);
512 mr_asprintf(&extra_cdrom_params, "%s blank=fast ", tmp);
513 } else {
514 mr_asprintf(&extra_cdrom_params, "blank=fast ");
515 }
516 }
517 tmp = find_home_of_exe("cdrecord");
518 tmp1 = find_home_of_exe("dvdrecord");
519 if (tmp) {
520 mr_asprintf(&cdr_exe, "cdrecord");
521 } else if (tmp1) {
522 mr_asprintf(&cdr_exe, "dvdrecord");
523 } else {
524 fatal_error("Please install either cdrecord or dvdrecord.");
525 }
526 mr_free(tmp);
527 mr_free(tmp1);
528
529 if (bkpinfo->nonbootable_backup) {
530 mr_asprintf(&mondo_mkisofs_sz, "%s -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL_Version -V _CD#_", bkpinfo->mr_conf->mondo_iso_creation_cmd);
531 } else if
532#ifdef __FreeBSD__
533 (TRUE)
534#else
535 (bkpinfo->make_cd_use_lilo)
536#endif
537#ifdef __IA64__
538 {
539 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
540 }
541#else
542 {
543 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
544 }
545#endif
546 else
547 {
548 mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
549 }
550 if (bkpinfo->manual_cd_tray) {
551 if (bkpinfo->call_before_iso == NULL) {
552 mr_asprintf(&bkpinfo->call_before_iso,
553 "%s -o %s/temporary.iso . 2>> _ERR_",
554 mondo_mkisofs_sz, bkpinfo->tmpdir);
555 } else {
556 mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
557 mr_asprintf(&bkpinfo->call_before_iso,
558 "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )",
559 mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
560 mr_free(call_before_iso_user);
561 }
562 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
563 mr_asprintf(&bkpinfo->call_make_iso,
564 "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
565 cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
566 extra_cdrom_params, bkpinfo->media_device,
567 bkpinfo->cdrw_speed, bkpinfo->tmpdir);
568 } else {
569 mr_asprintf(&bkpinfo->call_make_iso,
570 "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
571 mondo_mkisofs_sz, cdr_exe,
572 (bkpinfo->please_dont_eject) ? " " : "-eject",
573 extra_cdrom_params, bkpinfo->media_device,
574 bkpinfo->cdrw_speed);
575 }
576 mr_free(mondo_mkisofs_sz);
577 mr_free(cdr_exe);
578 mr_free(extra_cdrom_params);
579 } // end of CD code
580
581 if (bkpinfo->backup_media_type == iso) {
582
583/* Patch by Conor Daly <conor.daly@met.ie>
584 * 23-june-2004
585 * Break up isodir into iso_mnt and iso_path
586 * These will be used along with iso-dev at restore time
587 * to locate the ISOs where ever they're mounted
588 */
589
590 log_it("isodir = %s", bkpinfo->isodir);
591 mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1",
592 bkpinfo->isodir);
593 log_it("command = %s", command);
594 tmp = call_program_and_get_last_line_of_output(command);
595 mr_free(command);
596 log_it("res of it = %s", tmp);
597 mr_asprintf(&tmp1, "%s/ISO-DEV", bkpinfo->tmpdir);
598 write_one_liner_data_file(tmp1, tmp);
599 mr_free(tmp1);
600
601 mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
602 tmp);
603 mr_free(tmp);
604 log_it("command = %s", command);
605 tmp = call_program_and_get_last_line_of_output(command);
606 mr_free(command);
607 log_it("res of it = %s", tmp);
608
609 mr_asprintf(&tmp1, "%s/ISO-MNT", bkpinfo->tmpdir);
610 write_one_liner_data_file(tmp1, tmp);
611 mr_free(tmp1);
612
613 log_it("isomnt: %s, %d", tmp, strlen(tmp));
614 if (strlen(bkpinfo->isodir) < strlen(tmp)) {
615 mr_asprintf(&iso_path, " ");
616 } else {
617 mr_asprintf(&iso_path, "%s", bkpinfo->isodir + strlen(tmp));
618 }
619 mr_free(tmp);
620
621 mr_asprintf(&tmp, "%s/ISODIR", bkpinfo->tmpdir);
622 write_one_liner_data_file(tmp, iso_path);
623 mr_free(tmp);
624 log_it("isodir: %s", iso_path);
625 mr_free(iso_path);
626 mr_asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
627 write_one_liner_data_file(tmp, bkpinfo->prefix);
628 log_it("iso-prefix: %s", bkpinfo->prefix);
629 mr_free(tmp);
630/* End patch */
631 } // end of iso code
632
633 if (bkpinfo->backup_media_type == nfs) {
634 mr_asprintf(&hostname, bkpinfo->nfs_mount);
635 colon = strchr(hostname, ':');
636 if (!colon) {
637 log_it("nfs mount doesn't have a colon in it");
638 retval++;
639 } else {
640 struct hostent *hent;
641
642 *colon = '\0';
643 hent = gethostbyname(hostname);
644 if (!hent) {
645 log_it("Can't resolve NFS mount (%s): %s", hostname,
646 hstrerror(h_errno));
647 retval++;
648 } else {
649 mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
650 *((struct in_addr
651 *) hent->
652 h_addr)),
653 strchr(bkpinfo->nfs_mount, ':'));
654 mr_allocstr(bkpinfo->nfs_mount, ip_address);
655 mr_free(ip_address);
656 }
657 }
658 store_nfs_config(bkpinfo);
659 mr_free(hostname);
660 }
661
662 log_it("Finished processing incoming params");
663 if (retval) {
664 fprintf(stderr, "Type 'man mondoarchive' for help.\n");
665 }
666 mr_asprintf(&tmp, "%s", MONDO_TMPISOS);
667 if (does_file_exist(tmp)) {
668 unlink(tmp);
669 }
670 mr_free(tmp);
671
672 if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
673 log_it("tmpdir or scratchdir are blank/missing");
674 retval++;
675 }
676 if (bkpinfo->include_paths == NULL) {
677 // fatal_error ("Why no backup path?");
678 mr_asprintf(&bkpinfo->include_paths, "/");
679 }
680 chmod(bkpinfo->scratchdir, 0700);
681 chmod(bkpinfo->tmpdir, 0700);
682 g_backup_media_type = bkpinfo->backup_media_type;
683 mr_allocstr(g_backup_media_string,bkpinfo->backup_media_string);
684 return (retval);
685}
686
687
688
689/**
690 * Do some miscellaneous setup tasks to be performed before filling @c bkpinfo.
691 * Seeds the random-number generator, loads important modules, checks the sanity
692 * of the user's Linux distribution, and deletes logfile.
693 * @param bkpinfo The backup information structure. Will be initialized.
694 * @return number of errors (0 for success)
695 */
696int pre_param_configuration(struct s_bkpinfo *bkpinfo)
697{
698 int res = 0;
699
700 make_hole_for_dir(MNT_CDROM);
701 assert(bkpinfo != NULL);
702 srandom((unsigned long) (time(NULL)));
703 insmod_crucial_modules();
704 reset_bkpinfo(bkpinfo); // also sets defaults ('/'=backup path, 3=compression level)
705 if (bkpinfo->disaster_recovery) {
706 if (!does_nonMS_partition_exist()) {
707 fatal_error
708 ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
709 }
710 }
711
712 unlink(MONDO_TRACEFILE);
713 run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
714 if ((g_mondo_home = find_and_store_mondoarchives_home()) == NULL) {
715 fprintf(stderr,
716 "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n");
717 res++;
718 return (res);
719 }
720 res += some_basic_system_sanity_checks();
721 if (res) {
722 log_it("Your distribution did not pass Mondo's sanity test.");
723 }
724 g_current_media_number = 1;
725 bkpinfo->postnuke_tarball = NULL;
726 mr_free(bkpinfo->nfs_mount);
727 return (res);
728}
729
730
731
732
733/**
734 * Reset all fields of the backup information structure to a sensible default.
735 * @param bkpinfo The @c bkpinfo to reset.
736 */
737void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
738{
739 int i = 0;
740
741 log_msg(1, "Hi");
742
743 assert(bkpinfo != NULL);
744 /* BERLIOS : Useless
745 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
746 */
747
748 bkpinfo->manual_cd_tray = FALSE;
749 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
750 bkpinfo->boot_loader = '\0';
751
752 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
753 bkpinfo->media_size[i] = -1;
754 }
755
756 mr_free(bkpinfo->media_device);
757 mr_free(bkpinfo->boot_device);
758 mr_free(bkpinfo->zip_exe);
759 mr_free(bkpinfo->zip_suffix);
760 mr_free(bkpinfo->restore_path);
761 bkpinfo->use_lzo = FALSE;
762 bkpinfo->use_gzip = FALSE;
763 bkpinfo->do_not_compress_these[0] = '\0';
764 bkpinfo->verify_data = FALSE;
765 bkpinfo->backup_data = FALSE;
766 bkpinfo->restore_data = FALSE;
767 bkpinfo->disaster_recovery =
768 (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
769 if (bkpinfo->disaster_recovery) {
770 mr_allocstr(bkpinfo->isodir, "/");
771 } else {
772 mr_allocstr(bkpinfo->isodir, "/var/cache/mondo/iso");
773 }
774 mr_allocstr(bkpinfo->prefix, STD_PREFIX);
775
776 mr_free(bkpinfo->scratchdir);
777 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
778 mr_free(bkpinfo->tmpdir);
779 mr_asprintf(&bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore
780 bkpinfo->optimal_set_size = 0;
781 bkpinfo->backup_media_type = none;
782 mr_free(bkpinfo->backup_media_string);
783 mr_allocstr(bkpinfo->include_paths, "/");
784 mr_free(bkpinfo->exclude_paths);
785 mr_free(bkpinfo->call_before_iso);
786 mr_free(bkpinfo->call_make_iso);
787 mr_free(bkpinfo->call_burn_iso);
788 mr_free(bkpinfo->call_after_iso);
789 mr_free(bkpinfo->image_devs);
790 mr_free(bkpinfo->postnuke_tarball);
791 mr_free(bkpinfo->kernel_path);
792 mr_free(bkpinfo->nfs_mount);
793 mr_free(bkpinfo->nfs_remote_dir);
794 bkpinfo->wipe_media_first = FALSE;
795 bkpinfo->differential = FALSE;
796 bkpinfo->cdrw_speed = 0;
797// patch by Herman Kuster
798 bkpinfo->differential = 0;
799// patch end
800 bkpinfo->compression_level = 3;
801}
802
803
804/**
805 * Get the remaining free space (in MB) on @p partition.
806 * @param partition The partition to check free space on (either a device or a mountpoint).
807 * @return The free space on @p partition, in MB.
808 */
809long free_space_on_given_partition(char *partition)
810{
811 char *command = NULL;
812 char *out_sz = NULL;
813 long res;
814
815 assert_string_is_neither_NULL_nor_zerolength(partition);
816
817 mr_asprintf(&command, "df -m -P %s &> /dev/null", partition);
818 if (system(command)) {
819 return (-1);
820 } // partition does not exist
821 mr_free(command);
822
823 mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
824 partition);
825 out_sz = call_program_and_get_last_line_of_output(command);
826 mr_free(command);
827 if (strlen(out_sz) == 0) {
828 return (-1);
829 } // error within df, probably
830 res = atol(out_sz);
831 mr_free(out_sz);
832 return (res);
833}
834
835
836
837/**
838 * Check the user's system for sanity. Checks performed:
839 * - make sure user has enough RAM (32mb required, 64mb recommended)
840 * - make sure user has enough free space in @c /
841 * - check kernel for ramdisk support
842 * - make sure afio, cdrecord, mkisofs, bzip2, awk, md5sum, strings, mindi, and buffer exist
843 * - make sure CD-ROM is unmounted
844 * - make sure /etc/modules.conf exists
845 * - make sure user's mountlist is OK by running <tt>mindi --makemountlist</tt>
846 *
847 * @return number of problems with the user's setup (0 for success)
848 */
849int some_basic_system_sanity_checks()
850{
851
852 /*@ buffers ************ */
853 char *tmp = NULL;
854
855 /*@ int's *************** */
856 int retval = 0;
857 long Lres;
858
859
860 mvaddstr_and_log_it(g_currentY, 0,
861 "Checking sanity of your Linux distribution");
862#ifndef __FreeBSD__
863 if (system("which mkfs.vfat &> /dev/null")
864 && !system("which mkfs.msdos &> /dev/null")) {
865 log_it
866 ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
867 run_program_and_log_output
868 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
869 }
870 tmp = call_program_and_get_last_line_of_output
871 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2");
872 if (atol(tmp) < 35000) {
873 retval++;
874 log_to_screen(_("You must have at least 32MB of RAM to use Mondo."));
875 }
876 if (atol(tmp) < 66000) {
877 log_to_screen
878 (_("WARNING! You have very little RAM. Please upgrade to 64MB or more."));
879 }
880 mr_free(tmp);
881#endif
882
883 Lres = free_space_on_given_partition("/var/cache");
884 log_it("Free space on given partition = %ld MB", Lres);
885
886 if (Lres < 50) {
887 fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner.");
888 }
889
890 if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
891 retval++;
892 log_to_screen
893 ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
894 fatal_error
895 ("Please use \"su -\", not \"su\" to become root. OK? ...and please don't e-mail the mailing list or me about this. Just read the message. :)");
896 }
897#ifndef __FreeBSD__
898 if (run_program_and_log_output
899 ("grep ramdisk /proc/devices", FALSE)) {
900 if (!ask_me_yes_or_no
901 (_("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?")))
902 {
903 // retval++;
904 log_to_screen
905 (_("It looks as if your kernel lacks ramdisk and initrd support."));
906 log_to_screen
907 (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken."));
908 }
909 }
910#endif
911 retval += whine_if_not_found(MKE2FS_OR_NEWFS);
912 retval += whine_if_not_found("mkisofs");
913 if (system("which dvdrecord > /dev/null 2> /dev/null")) {
914 retval += whine_if_not_found("cdrecord");
915 }
916 retval += whine_if_not_found("bzip2");
917 retval += whine_if_not_found("gzip");
918 retval += whine_if_not_found("awk");
919 retval += whine_if_not_found("md5sum");
920 retval += whine_if_not_found("strings");
921 retval += whine_if_not_found("mindi");
922 retval += whine_if_not_found("buffer");
923
924 // abort if Windows partition but no ms-sys and parted
925 if (!run_program_and_log_output
926 ("mount | grep -w vfat | grep -vE \"/dev/fd|nexdisk\"", 0)
927 ||
928 !run_program_and_log_output
929 ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
930 log_to_screen(_("I think you have a Windows 9x partition."));
931 retval += whine_if_not_found("parted");
932#ifndef __IA64__
933 /* IA64 always has one vfat partition for EFI even without Windows */
934 // retval +=
935 tmp = find_home_of_exe("ms-sys");
936 if (!tmp) {
937 log_to_screen(_("Please install ms-sys just in case."));
938 }
939 mr_free(tmp);
940#endif
941 }
942
943 tmp = find_home_of_exe("cmp");
944 if (!tmp) {
945 whine_if_not_found("cmp");
946 }
947 mr_free(tmp);
948
949 run_program_and_log_output
950 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
951 tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"");
952 if (strcmp("", tmp)) {
953 if (strstr(tmp, "autofs")) {
954 log_to_screen
955 (_("Your CD-ROM is mounted via autofs. I therefore cannot tell"));
956 log_to_screen
957 (_("if a CD actually is inserted. If a CD is inserted, please"));
958 log_to_screen(_("eject it. Thank you."));
959 log_it
960 ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
961 } else
962 if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
963 retval++;
964 fatal_error
965 ("Your CD-ROM drive is mounted. Please unmount it.");
966 }
967 }
968 mr_free(tmp);
969#ifndef __FreeBSD__
970 if (!does_file_exist("/etc/modules.conf")) {
971 if (does_file_exist("/etc/conf.modules")) {
972 log_it("Linking /etc/modules.conf to /etc/conf.modules");
973 run_program_and_log_output
974 ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
975 } else if (does_file_exist("/etc/modprobe.d")) {
976 log_it
977 ("Directory /etc/modprobe.d found. mindi will use its contents.");
978 } else if (does_file_exist("/etc/modprobe.conf")) {
979 log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
980 run_program_and_log_output
981 ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
982 } else {
983 retval++;
984 log_to_screen
985 (_("Please find out what happened to /etc/modules.conf"));
986 }
987 }
988#endif
989
990 run_program_and_log_output("cat /etc/fstab", 5);
991#ifdef __FreeBSD__
992 run_program_and_log_output("vinum printconfig", 5);
993#else
994 run_program_and_log_output("cat /etc/raidtab", 5);
995#endif
996
997 if (run_program_and_log_output("mindi -V", 1)) {
998 log_to_screen(_("Could not ascertain mindi's version number."));
999 log_to_screen
1000 (_("You have not installed Mondo and/or Mindi properly."));
1001 log_to_screen(_("Please uninstall and reinstall them both."));
1002 fatal_error("Please reinstall Mondo and Mindi.");
1003 }
1004 if (run_program_and_log_output
1005 ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
1006 log_to_screen
1007 (_("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason."));
1008 log_to_screen
1009 (_("Please run that command by hand and examine /var/log/mindi.log"));
1010 log_to_screen
1011 (_("for more information. Perhaps your /etc/fstab file is insane."));
1012 log_to_screen
1013 (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see."));
1014 retval++;
1015 }
1016
1017 if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1)
1018 && !does_file_exist("/etc/raidtab")) {
1019 log_to_screen
1020 (_("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat"));
1021 create_raidtab_from_mdstat("/etc/raidtab");
1022 }
1023
1024 if (retval) {
1025 mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
1026 } else {
1027 mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
1028 }
1029 return (retval);
1030}
1031
1032/**
1033 * Retrieve the line containing @p label from the config file.
1034 * @param config_file The file to read from, usually @c /tmp/mondo-restore.cfg.
1035 * @param label What to read from the file.
1036 * @param value Where to put it.
1037 * @return 0 for success, 1 for failure.
1038 */
1039int read_cfg_var(char *config_file, char *label, char *value)
1040{
1041 /*@ buffer ****************************************************** */
1042 char *command = NULL;
1043 char *tmp = NULL;
1044
1045 /*@ end vars *************************************************** */
1046
1047 assert_string_is_neither_NULL_nor_zerolength(config_file);
1048 assert_string_is_neither_NULL_nor_zerolength(label);
1049
1050 if (!does_file_exist(config_file)) {
1051 mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
1052 config_file);
1053 log_to_screen(tmp);
1054 mr_free(tmp);
1055 value = NULL;
1056 return (1);
1057 /* } BERLIOS: Useless:
1058 else if (strstr(value, "/dev/") && strstr(value, "t0")
1059 && !strcmp(label, "media-dev")) {
1060 log_msg(2, "FYI, I shan't read new value for %s - already got %s",
1061 label, value);
1062 return (0);
1063 */ } else {
1064 mr_asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",
1065 label, config_file);
1066 value = call_program_and_get_last_line_of_output(command);
1067 mr_free(command);
1068 if (strlen(value) == 0) {
1069 return (1);
1070 } else {
1071 return (0);
1072 }
1073 }
1074}
1075
1076
1077/**
1078 * Remount @c supermount if it was unmounted earlier.
1079 */
1080void remount_supermounts_if_necessary()
1081{
1082 if (g_remount_cdrom_at_end) {
1083 run_program_and_log_output("mount " MNT_CDROM, FALSE);
1084 }
1085 if (g_remount_floppy_at_end) {
1086 run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
1087 }
1088}
1089
1090/**
1091 * Unmount @c supermount if it's mounted.
1092 */
1093void unmount_supermounts_if_necessary()
1094{
1095 if (run_program_and_log_output
1096 ("mount | grep cdrom | grep super", FALSE) == 0) {
1097 g_remount_cdrom_at_end = TRUE;
1098 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1099 }
1100 if (run_program_and_log_output
1101 ("mount | grep floppy | grep super", FALSE) == 0) {
1102 g_remount_floppy_at_end = TRUE;
1103 run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
1104 }
1105}
1106
1107/**
1108 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
1109 */
1110void mount_boot_if_necessary()
1111{
1112 char *tmp;
1113 char *tmp1;
1114 char *command;
1115
1116 log_msg(1, "Started sub");
1117 log_msg(4, "Setting command to something");
1118 mr_asprintf(&command,
1119 "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
1120 log_msg(4, "Cool. Command = '%s'", command);
1121 tmp = call_program_and_get_last_line_of_output(command);
1122 mr_free(command);
1123
1124 log_msg(4, "tmp = '%s'", tmp);
1125 if (tmp) {
1126 log_it("/boot is at %s according to /etc/fstab", tmp);
1127 if (strstr(tmp, "LABEL=")) {
1128 if (!run_program_and_log_output("mount /boot", 5)) {
1129 mr_free(g_boot_mountpt);
1130 mr_asprintf(&g_boot_mountpt, "/boot");
1131 log_msg(1, "Mounted /boot");
1132 } else {
1133 log_it("...ignored cos it's a label :-)");
1134 }
1135 } else {
1136 mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
1137 log_msg(3, "command = %s", command);
1138 if (run_program_and_log_output(command, 5)) {
1139 mr_free(g_boot_mountpt);
1140 mr_asprintf(&g_boot_mountpt, tmp);
1141 mr_asprintf(&tmp1,
1142 "%s (your /boot partition) is not mounted. I'll mount it before backing up",
1143 g_boot_mountpt);
1144 log_it(tmp1);
1145 mr_free(tmp1);
1146
1147 mr_asprintf(&tmp1, "mount %s", g_boot_mountpt);
1148 if (run_program_and_log_output(tmp1, 5)) {
1149 /* BERLIOS: Useless ???
1150 mr_free(g_boot_mountpt);
1151 mr_asprintf(&g_boot_mountpt, " ");
1152 */
1153 log_msg(1, "Plan B");
1154 if (!run_program_and_log_output("mount /boot", 5)) {
1155 mr_free(g_boot_mountpt);
1156 mr_asprintf(&g_boot_mountpt, "/boot");
1157 log_msg(1, "Plan B worked");
1158 } else {
1159 log_msg(1,
1160 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
1161 }
1162 }
1163 mr_free(tmp1);
1164 }
1165 mr_free(command);
1166 }
1167 }
1168 mr_free(tmp);
1169 log_msg(1, "Ended sub");
1170}
1171
1172
1173/**
1174 * If we mounted /boot earlier, unmount it.
1175 */
1176void unmount_boot_if_necessary()
1177{
1178 char *tmp;
1179
1180 log_msg(3, "starting");
1181 if (g_boot_mountpt != NULL) {
1182 mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
1183 if (run_program_and_log_output(tmp, 5)) {
1184 log_it("WARNING - unable to unmount /boot");
1185 }
1186 mr_free(tmp);
1187 }
1188 log_msg(3, "leaving");
1189}
1190
1191
1192
1193/**
1194 * Write a line to a configuration file. Writes a line of the form,
1195 * @c label @c value.
1196 * @param config_file The file to write to. Usually @c mondo-restore.cfg.
1197 * @param label What to call this bit of data you're writing.
1198 * @param value The bit of data you're writing.
1199 * @return 0 for success, 1 for failure.
1200 */
1201int write_cfg_var(char *config_file, char *label, char *value)
1202{
1203 /*@ buffers ***************************************************** */
1204 char *command;
1205 char *tempfile;
1206 char *tmp;
1207
1208
1209 /*@ end vars *************************************************** */
1210 assert_string_is_neither_NULL_nor_zerolength(config_file);
1211 assert_string_is_neither_NULL_nor_zerolength(label);
1212 assert(value != NULL);
1213
1214 if (!does_file_exist(config_file)) {
1215 mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
1216 config_file);
1217 log_to_screen(tmp);
1218 mr_free(tmp);
1219 return (1);
1220 }
1221 tempfile = call_program_and_get_last_line_of_output
1222 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX");
1223 if (does_file_exist(config_file)) {
1224 mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s",
1225 label, config_file, tempfile);
1226 paranoid_system(command);
1227 mr_free(command);
1228 }
1229 mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
1230 paranoid_system(command);
1231 mr_free(command);
1232
1233 mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
1234 paranoid_system(command);
1235 mr_free(command);
1236 unlink(tempfile);
1237 mr_free(tempfile);
1238 return (0);
1239}
1240
1241/**
1242 * Allocate or free important globals, depending on @p mal.
1243 * @param mal If TRUE, malloc; if FALSE, free.
1244 */
1245void do_libmondo_global_strings_thing(int mal)
1246{
1247 if (mal) {
1248 /*
1249 iamhere("Malloc'ing globals");
1250 */
1251 g_erase_tmpdir_and_scratchdir = NULL;
1252 malloc_string(g_serial_string);
1253 } else {
1254 iamhere("Freeing globals");
1255 mr_free(g_boot_mountpt);
1256 mr_free(g_mondo_home);
1257 mr_free(g_tmpfs_mountpt);
1258 mr_free(g_erase_tmpdir_and_scratchdir);
1259 mr_free(g_serial_string);
1260 mr_free(g_magicdev_command);
1261 }
1262}
1263
1264/**
1265 * Allocate important globals.
1266 * @see do_libmondo_global_strings_thing
1267 */
1268void malloc_libmondo_global_strings(void)
1269{
1270 do_libmondo_global_strings_thing(1);
1271}
1272
1273/**
1274 * Free important globals.
1275 * @see do_libmondo_global_strings_thing
1276 */
1277void free_libmondo_global_strings(void)
1278{
1279 do_libmondo_global_strings_thing(0);
1280}
1281
1282
1283
1284/**
1285 * Stop @c magicdev if it's running.
1286 * The command used to start it is saved in @p g_magicdev_command.
1287 */
1288void stop_magicdev_if_necessary()
1289{
1290 g_magicdev_command = call_program_and_get_last_line_of_output
1291 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99");
1292 if (g_magicdev_command) {
1293 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
1294 paranoid_system("killall magicdev");
1295 }
1296}
1297
1298
1299/**
1300 * Restart magicdev if it was stopped.
1301 */
1302void restart_magicdev_if_necessary()
1303{
1304 char *tmp = NULL;
1305
1306 if (!g_magicdev_command) {
1307 mr_asprintf(&tmp, "%s &", g_magicdev_command);
1308 paranoid_system(tmp);
1309 mr_free(tmp);
1310 }
1311}
1312
1313/* @} - end of utilityGroup */
Note: See TracBrowser for help on using the repository browser.