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

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

merge -r978:1042 $SVN_M/branches/stable

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