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

Last change on this file since 795 was 783, checked in by Bruno Cornec, 18 years ago
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

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