source: trunk/mondo/mondo/common/libmondo-tools.c @ 687

Last change on this file since 687 was 687, checked in by bcornec, 13 years ago

merge -r671:686 $SVN_M/branches/stable

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