source: branches/stable/mondo/src/common/libmondo-tools.c @ 1903

Last change on this file since 1903 was 1903, checked in by bruno, 11 years ago

merge -r 1842:1889 2.2.5

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