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

Last change on this file since 1106 was 1106, checked in by bruno, 12 years ago

merge -r1082:1105 $SVN_M/branches/stable

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