Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.05/mondo/mondo/common/libmondo-tools.c

    r126 r128  
    199199 * @{
    200200 */
    201 bool g_remount_cdrom_at_end, ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
    202     g_remount_floppy_at_end; ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
    203 bool g_cd_recovery; ///< TRUE if we're making an "autonuke" backup.
     201bool g_remount_cdrom_at_end,    ///< TRUE if we unmounted the CD-ROM and should remount it when done with the backup.
     202 g_remount_floppy_at_end;       ///< TRUE if we unmounted the floppy and should remount it when done with the backup.
     203bool g_cd_recovery;             ///< TRUE if we're making an "autonuke" backup.
    204204double g_kernel_version;
    205205
     
    207207 * The place where /boot is mounted.
    208208 */
    209 char *g_boot_mountpt=NULL;
     209char *g_boot_mountpt = NULL;
    210210
    211211/**
    212212 * The location of Mondo's home directory.
    213213 */
    214 char *g_mondo_home=NULL;
     214char *g_mondo_home = NULL;
    215215
    216216/**
    217217 * The serial string (used to differentiate between backups) of the current backup.
    218218 */
    219 char *g_serial_string=NULL;
     219char *g_serial_string = NULL;
    220220
    221221/**
    222222 * The location where tmpfs is mounted, or "" if it's not mounted.
    223223 */
    224 char *g_tmpfs_mountpt=NULL;
    225 char *g_magicdev_command=NULL;
     224char *g_tmpfs_mountpt = NULL;
     225char *g_magicdev_command = NULL;
    226226
    227227/**
    228228 * The default maximum level to log messages at or below.
    229229 */
    230 int g_loglevel=DEFAULT_DEBUG_LEVEL;
     230int g_loglevel = DEFAULT_DEBUG_LEVEL;
    231231
    232232/* @} - end of globalGroup */
     
    255255 * @param exp The expression that failed (as a string).
    256256 */
    257 void _mondo_assert_fail (const char *file,
    258              const char *function,
    259              int         line,
    260              const char *exp)
    261 {
    262     static int ignoring_assertions = 0;
    263     bool is_valid = TRUE;
    264 
    265     log_it ("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line, function);
    266     if (ignoring_assertions) {
    267     log_it ("Well, the user doesn't care...");
    268     return;
    269     }
    270 
     257void _mondo_assert_fail(const char *file,
     258                        const char *function, int line, const char *exp)
     259{
     260    static int ignoring_assertions = 0;
     261    bool is_valid = TRUE;
     262
     263    log_it("ASSERTION FAILED: `%s' at %s:%d in %s", exp, file, line,
     264           function);
     265    if (ignoring_assertions) {
     266        log_it("Well, the user doesn't care...");
     267        return;
     268    }
    271269#ifndef _XWIN
    272     if (!g_text_mode)
    273     newtSuspend();
    274 #endif
    275     printf ("ASSERTION FAILED: `%s'\n", exp);
    276     printf ("\tat %s:%d in %s\n\n", file, line, function);
    277     printf ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
    278     do {
    279     is_valid = TRUE;
    280     switch (toupper (getchar())) {
    281     case 'A': // ignore (A)ll
    282         ignoring_assertions = 1;
    283         break;
    284     case 'B': // a(B)ort
    285         signal (SIGABRT, SIG_DFL); /* prevent SIGABRT handler from running */
    286         raise (SIGABRT);
    287         break;          /* "can't get here" */
    288     case 'D': // (D)ebug, aka asm("int 3")
     270    if (!g_text_mode)
     271        newtSuspend();
     272#endif
     273    printf("ASSERTION FAILED: `%s'\n", exp);
     274    printf("\tat %s:%d in %s\n\n", file, line, function);
     275    printf("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     276    do {
     277        is_valid = TRUE;
     278        switch (toupper(getchar())) {
     279        case 'A':               // ignore (A)ll
     280            ignoring_assertions = 1;
     281            break;
     282        case 'B':               // a(B)ort
     283            signal(SIGABRT, SIG_DFL);   /* prevent SIGABRT handler from running */
     284            raise(SIGABRT);
     285            break;              /* "can't get here" */
     286        case 'D':               // (D)ebug, aka asm("int 3")
    289287#ifdef __IA32__
    290         __asm__ __volatile__ ("int $3"); // break to debugger
    291 #endif
    292         break;
    293     case 'E': // (E)xit
    294         fatal_error ("Failed assertion -- see above for details");
    295         break;          /* "can't get here" */
    296     case 'I': // (I)gnore
    297         break;
    298     /* These next two work as follows:
    299        the `default' catches the user's invalid choice and says so;
    300        the '\n' catches the newline on the end and prints the prompt again.
    301     */
    302     case '\n':
    303         printf ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
    304         break;
    305     default:
    306         is_valid = FALSE;
    307         printf ("Invalid choice.\n");
    308         break;
    309     }
    310     } while (!is_valid);
    311 
    312     if (ignoring_assertions) {
    313     log_it ("Ignoring ALL assertions from now on.");
    314     } else {
    315     log_it ("Ignoring assertion: %s", exp);
    316     }
    317 
    318     getchar(); // skip \n
     288            __asm__ __volatile__("int $3"); // break to debugger
     289#endif
     290            break;
     291        case 'E':               // (E)xit
     292            fatal_error("Failed assertion -- see above for details");
     293            break;              /* "can't get here" */
     294        case 'I':               // (I)gnore
     295            break;
     296            /* These next two work as follows:
     297               the `default' catches the user's invalid choice and says so;
     298               the '\n' catches the newline on the end and prints the prompt again.
     299             */
     300        case '\n':
     301            printf
     302                ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     303            break;
     304        default:
     305            is_valid = FALSE;
     306            printf("Invalid choice.\n");
     307            break;
     308        }
     309    } while (!is_valid);
     310
     311    if (ignoring_assertions) {
     312        log_it("Ignoring ALL assertions from now on.");
     313    } else {
     314        log_it("Ignoring assertion: %s", exp);
     315    }
     316
     317    getchar();                  // skip \n
    319318
    320319#ifndef _XWIN
    321     if (!g_text_mode)
    322     newtResume();
     320    if (!g_text_mode)
     321        newtResume();
    323322#endif
    324323}
     
    330329void clean_up_KDE_desktop_if_necessary(void)
    331330{
    332   char *tmp;
    333 
    334   malloc_string(tmp);
    335   strcpy(tmp, "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
     331    char *tmp;
     332
     333    malloc_string(tmp);
     334    strcpy(tmp,
     335           "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
    336336file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
    337337cat $file.old | awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
    338338else { print $0;};}' > $file ; fi ; done");
    339   run_program_and_log_output(tmp, 5);
    340   paranoid_free(tmp);
     339    run_program_and_log_output(tmp, 5);
     340    paranoid_free(tmp);
    341341}
    342342
     
    351351int find_and_store_mondoarchives_home(char *home_sz)
    352352{
    353   assert(home_sz!=NULL);
    354   strcpy (home_sz,
    355       call_program_and_get_last_line_of_output
    356       ("find /usr/lib/ /usr/local/ /usr/share/ /usr/local/share/ /opt/ /ramdisk/usr/share/ -type d -maxdepth 2 -name include -prune -o -type d -maxdepth 2 -path '*/mondo/restore-scripts' -printf '%h\n' 2> /dev/null"));
    357 
    358   if (home_sz[0] == '\0')
    359     {
    360       strcpy (home_sz,
    361           call_program_and_get_last_line_of_output
    362           ("find /usr -type d -path '*/mondo/restore-scripts' -follow -maxdepth 3 -printf '%h\n' 2> /dev/null"));
    363     }
    364   if (home_sz[0] == '\0')
    365     {
    366       return(1);
    367     }
    368   else
    369     {
    370       return(0);
    371     }
     353    assert(home_sz != NULL);
     354    strcpy(home_sz,
     355           call_program_and_get_last_line_of_output
     356           ("find /usr/lib/ /usr/local/ /usr/share/ /usr/local/share/ /opt/ /ramdisk/usr/share/ -type d -maxdepth 2 -name include -prune -o -type d -maxdepth 2 -path '*/mondo/restore-scripts' -printf '%h\n' 2> /dev/null"));
     357
     358    if (home_sz[0] == '\0') {
     359        strcpy(home_sz,
     360               call_program_and_get_last_line_of_output
     361               ("find /usr -type d -path '*/mondo/restore-scripts' -follow -maxdepth 3 -printf '%h\n' 2> /dev/null"));
     362    }
     363    if (home_sz[0] == '\0') {
     364        return (1);
     365    } else {
     366        return (0);
     367    }
    372368}
    373369
     
    376372{
    377373#ifdef __IA32__
    378     return("i386");
     374    return ("i386");
    379375#endif
    380376#ifdef __IA64__
    381     return("ia64");
    382 #endif
    383     return("unknown");
     377    return ("ia64");
     378#endif
     379    return ("unknown");
    384380}
    385381
     
    388384double get_kernel_version()
    389385{
    390   char *p, tmp[200];
    391   double d;
     386    char *p, tmp[200];
     387    double d;
    392388#ifdef __FreeBSD__
    393   // JOSH - FIXME :)
    394   d = 5.2; // :-)
     389    // JOSH - FIXME :)
     390    d = 5.2;                    // :-)
    395391#else
    396   strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
    397   p = strchr(tmp, '.');
    398   if (p)
    399     {
    400       p = strchr(++p, '.');
    401       if (p)
    402         {
    403       while(*p) { *p=*(p+1); p++; }
    404         }
    405     }
     392    strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));
     393    p = strchr(tmp, '.');
     394    if (p) {
     395        p = strchr(++p, '.');
     396        if (p) {
     397            while (*p) {
     398                *p = *(p + 1);
     399                p++;
     400            }
     401        }
     402    }
    406403//  log_msg(1, "tmp = '%s'", tmp);
    407   d = atof(tmp);
    408 #endif
    409   log_msg(1, "g_kernel_version = %f", d);
    410   return(d);
     404    d = atof(tmp);
     405#endif
     406    log_msg(1, "g_kernel_version = %f", d);
     407    return (d);
    411408}
    412409
     
    419416 * @return number of seconds since the epoch.
    420417 */
    421 long
    422 get_time ()
    423 {
    424   return (long) time ((void *) 0);
     418long get_time()
     419{
     420    return (long) time((void *) 0);
    425421}
    426422
     
    439435 */
    440436#ifdef __FreeBSD__
    441 void initialize_raidrec (struct vinum_volume *raidrec)
    442 {
    443   int i, j;
    444   raidrec->volname[0] = '\0';
    445   raidrec->plexes = 0;
    446   for (i = 0; i < 9; ++i) {
    447     raidrec->plex[i].raidlevel = -1;
    448     raidrec->plex[i].stripesize = 0;
    449     raidrec->plex[i].subdisks = 0;
    450     for (j = 0; j < 9; ++j) {
    451        strcpy (raidrec->plex[i].sd[j].which_device, "");
    452     }
    453   }
     437void initialize_raidrec(struct vinum_volume *raidrec)
     438{
     439    int i, j;
     440    raidrec->volname[0] = '\0';
     441    raidrec->plexes = 0;
     442    for (i = 0; i < 9; ++i) {
     443        raidrec->plex[i].raidlevel = -1;
     444        raidrec->plex[i].stripesize = 0;
     445        raidrec->plex[i].subdisks = 0;
     446        for (j = 0; j < 9; ++j) {
     447            strcpy(raidrec->plex[i].sd[j].which_device, "");
     448        }
     449    }
    454450}
    455451#else
    456 void initialize_raidrec (struct raid_device_record *raidrec)
    457 {
    458   assert(raidrec!=NULL);
    459   raidrec->raid_device[0] = '\0';
    460   raidrec->raid_level = 0;
    461   raidrec->chunk_size = 4;
    462   raidrec->persistent_superblock = 1;
    463   raidrec->data_disks.entries = 0;
    464   raidrec->spare_disks.entries = 0;
    465   raidrec->parity_disks.entries = 0;
    466   raidrec->failed_disks.entries = 0;
    467   raidrec->additional_vars.entries = 0;
     452void initialize_raidrec(struct raid_device_record *raidrec)
     453{
     454    assert(raidrec != NULL);
     455    raidrec->raid_device[0] = '\0';
     456    raidrec->raid_level = 0;
     457    raidrec->chunk_size = 4;
     458    raidrec->persistent_superblock = 1;
     459    raidrec->data_disks.entries = 0;
     460    raidrec->spare_disks.entries = 0;
     461    raidrec->parity_disks.entries = 0;
     462    raidrec->failed_disks.entries = 0;
     463    raidrec->additional_vars.entries = 0;
    468464}
    469465#endif
     
    480476{
    481477#ifdef __FreeBSD__
    482   system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
    483   system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
     478    system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
     479    system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
    484480#else
    485   system("modprobe dos &> /dev/null");
    486   system("modprobe fat &> /dev/null");
    487   system("modprobe vfat &> /dev/null");
    488   //  system("modprobe osst &> /dev/null");
     481    system("modprobe dos &> /dev/null");
     482    system("modprobe fat &> /dev/null");
     483    system("modprobe vfat &> /dev/null");
     484    //  system("modprobe osst &> /dev/null");
    489485#endif
    490486}
     
    495491 * @bug This function seems orphaned. Please remove.
    496492 */
    497 void
    498 log_trace (char *o)
    499 {
    500     /*@ pointers *****************************************************/
    501   FILE *fout;
    502 
    503     /*@ buffers ******************************************************/
    504   char output[MAX_STR_LEN];
    505 
    506     /*@ int    *******************************************************/
    507   int i;
    508 
    509     /*@ end vars ****************************************************/
    510 
    511   if (o[0] == '\0')
    512     {
    513       return;
    514     }
    515   strcpy (output, o);
    516   i = (int) strlen (output);
    517   if (i <= 0)
    518     {
    519       return;
    520     }
    521   if (output[i - 1] < 32)
    522     {
    523       output[i - 1] = '\0';
    524     }
    525   if (g_text_mode /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ )
    526     {
    527       printf ("%s\n", output);
    528     }
    529 
    530   fout = fopen (MONDO_TRACEFILE, "a");
    531   if (fout)
    532     {
    533       fprintf (fout, "%s\n", output);
    534       paranoid_fclose (fout);
    535     }
    536   else
    537     {
    538       log_OS_error( "Cannot write to tracefile" );
    539     }
     493void log_trace(char *o)
     494{
     495    /*@ pointers **************************************************** */
     496    FILE *fout;
     497
     498    /*@ buffers ***************************************************** */
     499    char output[MAX_STR_LEN];
     500
     501    /*@ int    ****************************************************** */
     502    int i;
     503
     504    /*@ end vars *************************************************** */
     505
     506    if (o[0] == '\0') {
     507        return;
     508    }
     509    strcpy(output, o);
     510    i = (int) strlen(output);
     511    if (i <= 0) {
     512        return;
     513    }
     514    if (output[i - 1] < 32) {
     515        output[i - 1] = '\0';
     516    }
     517    if (g_text_mode
     518        /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
     519        printf("%s\n", output);
     520    }
     521
     522    fout = fopen(MONDO_TRACEFILE, "a");
     523    if (fout) {
     524        fprintf(fout, "%s\n", output);
     525        paranoid_fclose(fout);
     526    } else {
     527        log_OS_error("Cannot write to tracefile");
     528    }
    540529}
    541530
     
    575564 * do not exist.
    576565 */
    577 int post_param_configuration (struct s_bkpinfo *bkpinfo)
    578 {
    579   char *extra_cdrom_params;
    580   char *mondo_mkisofs_sz;
    581   char *command;
    582   char *mtpt;
    583   char *hostname, *ip_address;
    584   int retval=0;
    585   long avm = 0;
    586   char *colon;
    587   char *cdr_exe;
    588   char *tmp;
    589   int rdsiz_MB;
    590       char *iso_dev;
    591       char *iso_mnt;
    592       char *iso_tmp;
    593       char *iso_path;
    594 
    595   assert(bkpinfo!=NULL);
    596   malloc_string(extra_cdrom_params);
    597   malloc_string(mondo_mkisofs_sz);
    598   malloc_string(command);
    599   malloc_string(mtpt);
    600   malloc_string(hostname);
    601   malloc_string(ip_address);
    602   malloc_string(cdr_exe);
    603   malloc_string(tmp);
    604       malloc_string(iso_dev);
    605       malloc_string(iso_mnt);
    606       malloc_string(iso_tmp);
    607       malloc_string(iso_path);
    608   bkpinfo->optimal_set_size = (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)?4:8) * 1024;
    609 
    610   log_msg(1, "Foo");
    611   if (bkpinfo->backup_media_type == tape)
    612     {
    613       log_msg(1, "Bar");
    614       sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    615       log_msg(1, "tmp = '%s'", tmp);
    616       if (run_program_and_log_output(tmp, 3))
    617         {
    618           fatal_error("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.");
    619     }
    620     }   
    621   make_hole_for_dir(bkpinfo->scratchdir);
    622   make_hole_for_dir(bkpinfo->tmpdir);
    623   if (bkpinfo->backup_media_type == iso)
    624       make_hole_for_dir(bkpinfo->isodir);
    625 
    626   run_program_and_log_output ("uname -a", 5);
    627   run_program_and_log_output ("cat /etc/*issue*", 5);
    628   sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
    629   sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
    630   paranoid_system(command);
    631   rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
     566int post_param_configuration(struct s_bkpinfo *bkpinfo)
     567{
     568    char *extra_cdrom_params;
     569    char *mondo_mkisofs_sz;
     570    char *command;
     571    char *mtpt;
     572    char *hostname, *ip_address;
     573    int retval = 0;
     574    long avm = 0;
     575    char *colon;
     576    char *cdr_exe;
     577    char *tmp;
     578    int rdsiz_MB;
     579    char *iso_dev;
     580    char *iso_mnt;
     581    char *iso_tmp;
     582    char *iso_path;
     583
     584    assert(bkpinfo != NULL);
     585    malloc_string(extra_cdrom_params);
     586    malloc_string(mondo_mkisofs_sz);
     587    malloc_string(command);
     588    malloc_string(mtpt);
     589    malloc_string(hostname);
     590    malloc_string(ip_address);
     591    malloc_string(cdr_exe);
     592    malloc_string(tmp);
     593    malloc_string(iso_dev);
     594    malloc_string(iso_mnt);
     595    malloc_string(iso_tmp);
     596    malloc_string(iso_path);
     597    bkpinfo->optimal_set_size =
     598        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 4 : 8) *
     599        1024;
     600
     601    log_msg(1, "Foo");
     602    if (bkpinfo->backup_media_type == tape) {
     603        log_msg(1, "Bar");
     604        sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
     605        log_msg(1, "tmp = '%s'", tmp);
     606        if (run_program_and_log_output(tmp, 3)) {
     607            fatal_error
     608                ("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.");
     609        }
     610    }
     611    make_hole_for_dir(bkpinfo->scratchdir);
     612    make_hole_for_dir(bkpinfo->tmpdir);
     613    if (bkpinfo->backup_media_type == iso)
     614        make_hole_for_dir(bkpinfo->isodir);
     615
     616    run_program_and_log_output("uname -a", 5);
     617    run_program_and_log_output("cat /etc/*issue*", 5);
     618    sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
     619    sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
     620    paranoid_system(command);
     621    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    632622#ifdef __FreeBSD__
    633   strcpy(tmp, call_program_and_get_last_line_of_output("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
    634   avm += atol (tmp);
    635   strcpy(tmp, call_program_and_get_last_line_of_output("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
    636   avm += atol (tmp);
    637   sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm', g_tmpfs_mountpt);
     623    strcpy(tmp,
     624           call_program_and_get_last_line_of_output
     625           ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
     626    avm += atol(tmp);
     627    strcpy(tmp,
     628           call_program_and_get_last_line_of_output
     629           ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
     630    avm += atol(tmp);
     631    sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
     632            g_tmpfs_mountpt);
    638633#else
    639   strcpy(tmp, call_program_and_get_last_line_of_output("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
    640   avm += atol (tmp);
    641   sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c", g_tmpfs_mountpt, rdsiz_MB, 'm');
    642   run_program_and_log_output ("cat /proc/cpuinfo", 5);
    643   run_program_and_log_output ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc", 5);
    644 #endif
    645   if (avm/1024 > rdsiz_MB*3)
    646     {
    647       if (run_program_and_log_output(command, 5))
     634    strcpy(tmp,
     635           call_program_and_get_last_line_of_output
     636           ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
     637    avm += atol(tmp);
     638    sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
     639            g_tmpfs_mountpt, rdsiz_MB, 'm');
     640    run_program_and_log_output("cat /proc/cpuinfo", 5);
     641    run_program_and_log_output
     642        ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
     643         5);
     644#endif
     645    if (avm / 1024 > rdsiz_MB * 3) {
     646        if (run_program_and_log_output(command, 5)) {
     647            g_tmpfs_mountpt[0] = '\0';
     648            log_it("Failed to mount tmpfs");
     649        } else {
     650            log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
     651        }
     652    } else {
     653        g_tmpfs_mountpt[0] = '\0';
     654        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
     655    }
     656
     657    if (bkpinfo->use_lzo) {
     658        strcpy(bkpinfo->zip_exe, "lzop");
     659        strcpy(bkpinfo->zip_suffix, "lzo");
     660    } else if (bkpinfo->compression_level != 0) {
     661        strcpy(bkpinfo->zip_exe, "bzip2");
     662        strcpy(bkpinfo->zip_suffix, "bz2");
     663    } else {
     664        bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     665    }
     666
     667// DVD
     668
     669    if (bkpinfo->backup_media_type == dvd) {
     670        extra_cdrom_params[0] = '\0';
     671        mondo_mkisofs_sz[0] = '\0';
     672        if (find_home_of_exe("growisofs")) {
     673            strcpy(cdr_exe, "growisofs");
     674        }                       // unlikely to be used
     675        else {
     676            fatal_error("Please install growisofs.");
     677        }
     678        if (bkpinfo->nonbootable_backup) {
     679            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     680        } else if
     681#ifdef __FreeBSD__
     682            (TRUE)
     683#else
     684            (bkpinfo->make_cd_use_lilo)
     685#endif
     686#ifdef __IA64__
    648687    {
    649       g_tmpfs_mountpt[0] = '\0';
    650       log_it("Failed to mount tmpfs");
    651     }
    652       else
     688        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     689    }
     690#else
    653691    {
    654       log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
    655     }
    656     }
    657   else
    658     {
    659       g_tmpfs_mountpt[0] = '\0';
    660       log_it ("It doesn't seem you have enough swap to use tmpfs. Fine.");
    661     }
    662 
    663   if (bkpinfo->use_lzo)
    664     {
    665       strcpy (bkpinfo->zip_exe, "lzop");
    666       strcpy (bkpinfo->zip_suffix, "lzo");
    667     }
    668   else if (bkpinfo->compression_level!=0)
    669     {
    670       strcpy (bkpinfo->zip_exe, "bzip2");
    671       strcpy (bkpinfo->zip_suffix, "bz2");
    672     }
    673   else
    674     {
    675       bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    676     }
    677 
    678 // DVD
    679 
    680   if (bkpinfo->backup_media_type == dvd)
    681       {
    682       extra_cdrom_params[0] = '\0';
    683       mondo_mkisofs_sz[0] = '\0';
    684       if (find_home_of_exe("growisofs"))
    685     { strcpy(cdr_exe, "growisofs"); } // unlikely to be used
    686       else
    687         { fatal_error("Please install growisofs."); }
    688       if (bkpinfo->nonbootable_backup)
    689         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); }
    690       else if
     692        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     693    }
     694#endif
     695        else
     696        {
     697            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     698        }
     699        if (bkpinfo->manual_cd_tray) {
     700            fatal_error("Manual CD tray + DVD not supported yet.");
     701            // -m isn't supported by growisofs, BTW...
     702        } else {
     703            sprintf(bkpinfo->call_make_iso,
     704                    "%s %s -Z %s . 2>> _ERR_",
     705                    mondo_mkisofs_sz,
     706                    extra_cdrom_params, bkpinfo->media_device);
     707        }
     708        log_msg(2, "call_make_iso (DVD res) is ... %s",
     709                bkpinfo->call_make_iso);
     710    }                           // end of DVD code
     711
     712// CD-R or CD-RW
     713    if (bkpinfo->backup_media_type == cdrw
     714        || bkpinfo->backup_media_type == cdr) {
     715        extra_cdrom_params[0] = '\0';
     716        if (!bkpinfo->manual_cd_tray) {
     717            strcat(extra_cdrom_params, "-waiti ");
     718        }
     719        if (bkpinfo->backup_media_type == cdrw) {
     720            strcat(extra_cdrom_params, "blank=fast ");
     721        }
     722        if (find_home_of_exe("cdrecord")) {
     723            strcpy(cdr_exe, "cdrecord");
     724        } else if (find_home_of_exe("dvdrecord")) {
     725            strcpy(cdr_exe, "dvdrecord");
     726        } else {
     727            fatal_error("Please install either cdrecord or dvdrecord.");
     728        }
     729        if (bkpinfo->nonbootable_backup) {
     730            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     731        } else if
    691732#ifdef __FreeBSD__
    692         (TRUE)
     733            (TRUE)
    693734#else
    694         (bkpinfo->make_cd_use_lilo)
     735            (bkpinfo->make_cd_use_lilo)
    695736#endif
    696737#ifdef __IA64__
    697         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); }
     738    {
     739        strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     740    }
    698741#else
    699         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); }
    700 #endif
    701       else
    702         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); }
    703       if (bkpinfo->manual_cd_tray)
    704742    {
    705       fatal_error("Manual CD tray + DVD not supported yet.");
    706       // -m isn't supported by growisofs, BTW...
    707     }
    708       else
    709     {
    710       sprintf (bkpinfo->call_make_iso,
    711            "%s %s -Z %s . 2>> _ERR_",
    712            mondo_mkisofs_sz,
    713            extra_cdrom_params,
    714            bkpinfo->media_device);
    715         }
    716       log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
    717     } // end of DVD code
    718 
    719 // CD-R or CD-RW
    720   if (bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr)
    721     {
    722       extra_cdrom_params[0] = '\0';
    723       if (!bkpinfo->manual_cd_tray)
    724     {
    725       strcat (extra_cdrom_params, "-waiti ");
    726     }
    727       if (bkpinfo->backup_media_type == cdrw)
    728     {
    729       strcat (extra_cdrom_params, "blank=fast ");
    730     }
    731       if (find_home_of_exe("cdrecord"))
    732     { strcpy(cdr_exe, "cdrecord"); }
    733       else if (find_home_of_exe("dvdrecord"))
    734     { strcpy(cdr_exe, "dvdrecord"); }
    735       else
    736         { fatal_error("Please install either cdrecord or dvdrecord."); }
    737       if (bkpinfo->nonbootable_backup)
    738         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT); }
    739       else if
    740 #ifdef __FreeBSD__
    741         (TRUE)
    742 #else
    743         (bkpinfo->make_cd_use_lilo)
    744 #endif
    745 #ifdef __IA64__
    746         { strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO); }
    747 #else
    748         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO); }
    749 #endif
    750       else
    751         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX); }
    752       if (bkpinfo->manual_cd_tray)
    753     {
    754       sprintf (bkpinfo->call_before_iso,
    755            "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz, bkpinfo->tmpdir);
    756       sprintf (bkpinfo->call_make_iso,
    757            "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
    758            cdr_exe,
    759            (bkpinfo->please_dont_eject)?" ":"-eject",
    760            extra_cdrom_params, bkpinfo->media_device,
    761            bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    762     }
    763       else
    764     {
    765       sprintf (bkpinfo->call_make_iso,
    766            "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    767            mondo_mkisofs_sz, cdr_exe,
    768            (bkpinfo->please_dont_eject)?" ":"-eject",
    769            extra_cdrom_params, bkpinfo->media_device,
    770            bkpinfo->cdrw_speed);
    771         }
    772     } // end of CD code
    773 
    774   /*
    775   if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
    776     {
    777       sprintf (tmp,
    778            "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
    779            bkpinfo->media_device, bkpinfo->internal_tape_block_size);
    780       if (system(tmp))
    781     {
    782       retval++;
    783       fprintf (stderr,
    784            "Cannot write to tape device. Is the tape set read-only?\n");
    785     }
    786     } // end of tape code
    787   */
    788 
    789 
    790   if (bkpinfo->backup_media_type == iso)
    791     {
     743        strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     744    }
     745#endif
     746        else
     747        {
     748            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     749        }
     750        if (bkpinfo->manual_cd_tray) {
     751            sprintf(bkpinfo->call_before_iso,
     752                    "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz,
     753                    bkpinfo->tmpdir);
     754            sprintf(bkpinfo->call_make_iso,
     755                    "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
     756                    cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
     757                    extra_cdrom_params, bkpinfo->media_device,
     758                    bkpinfo->cdrw_speed, bkpinfo->tmpdir);
     759        } else {
     760            sprintf(bkpinfo->call_make_iso,
     761                    "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
     762                    mondo_mkisofs_sz, cdr_exe,
     763                    (bkpinfo->please_dont_eject) ? " " : "-eject",
     764                    extra_cdrom_params, bkpinfo->media_device,
     765                    bkpinfo->cdrw_speed);
     766        }
     767    }                           // end of CD code
     768
     769    /*
     770       if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
     771       {
     772       sprintf (tmp,
     773       "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
     774       bkpinfo->media_device, bkpinfo->internal_tape_block_size);
     775       if (system(tmp))
     776       {
     777       retval++;
     778       fprintf (stderr,
     779       "Cannot write to tape device. Is the tape set read-only?\n");
     780       }
     781       } // end of tape code
     782     */
     783
     784
     785    if (bkpinfo->backup_media_type == iso) {
    792786
    793787/* Patch by Conor Daly <conor.daly@met.ie>
     
    798792 */
    799793
    800       log_it("isodir = %s", bkpinfo->isodir);
    801       sprintf(command, "df %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    802       log_it("command = %s", command);
    803       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    804       sprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
    805       sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    806       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    807 
    808       sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);
    809       log_it("command = %s", command);
    810       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    811       sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    812       sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    813       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    814 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    815       sprintf(iso_tmp, "%s", bkpinfo->isodir);
    816       if (strlen(iso_tmp) < strlen(iso_mnt))
    817         {
    818       iso_path[0] = '\0';
    819     }
    820       else
    821         {
    822           sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    823     }
    824       sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
    825       write_one_liner_data_file(tmp, iso_path);
    826 log_it("isodir: %s", iso_path);
     794        log_it("isodir = %s", bkpinfo->isodir);
     795        sprintf(command, "df %s | tail -n1 | cut -d' ' -f1",
     796                bkpinfo->isodir);
     797        log_it("command = %s", command);
     798        log_it("res of it = %s",
     799               call_program_and_get_last_line_of_output(command));
     800        sprintf(iso_dev, "%s",
     801                call_program_and_get_last_line_of_output(command));
     802        sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
     803        write_one_liner_data_file(tmp,
     804                                  call_program_and_get_last_line_of_output
     805                                  (command));
     806
     807        sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     808                iso_dev);
     809        log_it("command = %s", command);
     810        log_it("res of it = %s",
     811               call_program_and_get_last_line_of_output(command));
     812        sprintf(iso_mnt, "%s",
     813                call_program_and_get_last_line_of_output(command));
     814        sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
     815        write_one_liner_data_file(tmp,
     816                                  call_program_and_get_last_line_of_output
     817                                  (command));
     818        log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
     819        sprintf(iso_tmp, "%s", bkpinfo->isodir);
     820        if (strlen(iso_tmp) < strlen(iso_mnt)) {
     821            iso_path[0] = '\0';
     822        } else {
     823            sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
     824        }
     825        sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     826        write_one_liner_data_file(tmp, iso_path);
     827        log_it("isodir: %s", iso_path);
    827828
    828829/* End patch */
    829     } // end of iso code
    830 
    831   if (bkpinfo->backup_media_type == nfs) {
    832       strcpy (hostname, bkpinfo->nfs_mount);
    833       colon = strchr (hostname, ':');
    834       if (!colon) {
    835       log_it ("nfs mount doesn't have a colon in it");
    836       retval++;
    837       } else {
    838       struct hostent *hent;
    839 
    840       *colon = '\0';
    841       hent = gethostbyname (hostname);
    842       if (!hent) {
    843           log_it ("Can't resolve NFS mount (%s): %s", hostname, hstrerror (h_errno));
    844           retval++;
    845       } else {
    846           strcpy (ip_address, inet_ntoa
    847               ((struct in_addr)*((struct in_addr *)hent->h_addr)));
    848           strcat (ip_address, strchr (bkpinfo->nfs_mount, ':'));
    849           strcpy (bkpinfo->nfs_mount, ip_address);
    850       }
    851       }
    852       store_nfs_config (bkpinfo);
    853   }
    854 
    855   log_it("Finished processing incoming params");
    856   if (retval)
    857     {
    858       fprintf (stderr, "Type 'man mondoarchive' for help.\n");
    859     }
    860   sprintf (tmp, "%s", MONDO_TMPISOS);   /* added #define 22 apr 2002 */
    861   if (does_file_exist (tmp))
    862     {
    863       unlink (tmp);
    864     }
    865   if (strlen (bkpinfo->tmpdir) < 2 || strlen (bkpinfo->scratchdir) < 2)
    866     {
    867       log_it ("tmpdir or scratchdir are blank/missing");
    868       retval++;
    869     }
    870   if (bkpinfo->include_paths[0] == '\0')
    871     {
    872     //      fatal_error ("Why no backup path?");
    873     strcpy (bkpinfo->include_paths, "/");
    874     }
    875   chmod(bkpinfo->scratchdir, 0700);
    876   chmod(bkpinfo->tmpdir, 0700);
    877   g_backup_media_type = bkpinfo->backup_media_type;
    878   paranoid_free(mtpt);
    879   paranoid_free(extra_cdrom_params);
    880   paranoid_free(mondo_mkisofs_sz);
    881   paranoid_free(command);
    882   paranoid_free(hostname);
    883   paranoid_free(ip_address);
    884   paranoid_free(cdr_exe);
    885   paranoid_free(tmp);
    886   paranoid_free(iso_dev);
    887   paranoid_free(iso_mnt);
    888   paranoid_free(iso_tmp);
    889   paranoid_free(iso_path);
    890   return(retval);
     830    }                           // end of iso code
     831
     832    if (bkpinfo->backup_media_type == nfs) {
     833        strcpy(hostname, bkpinfo->nfs_mount);
     834        colon = strchr(hostname, ':');
     835        if (!colon) {
     836            log_it("nfs mount doesn't have a colon in it");
     837            retval++;
     838        } else {
     839            struct hostent *hent;
     840
     841            *colon = '\0';
     842            hent = gethostbyname(hostname);
     843            if (!hent) {
     844                log_it("Can't resolve NFS mount (%s): %s", hostname,
     845                       hstrerror(h_errno));
     846                retval++;
     847            } else {
     848                strcpy(ip_address, inet_ntoa
     849                       ((struct in_addr)
     850                        *((struct in_addr *) hent->h_addr)));
     851                strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     852                strcpy(bkpinfo->nfs_mount, ip_address);
     853            }
     854        }
     855        store_nfs_config(bkpinfo);
     856    }
     857
     858    log_it("Finished processing incoming params");
     859    if (retval) {
     860        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
     861    }
     862    sprintf(tmp, "%s", MONDO_TMPISOS);  /* added #define 22 apr 2002 */
     863    if (does_file_exist(tmp)) {
     864        unlink(tmp);
     865    }
     866    if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
     867        log_it("tmpdir or scratchdir are blank/missing");
     868        retval++;
     869    }
     870    if (bkpinfo->include_paths[0] == '\0') {
     871        //      fatal_error ("Why no backup path?");
     872        strcpy(bkpinfo->include_paths, "/");
     873    }
     874    chmod(bkpinfo->scratchdir, 0700);
     875    chmod(bkpinfo->tmpdir, 0700);
     876    g_backup_media_type = bkpinfo->backup_media_type;
     877    paranoid_free(mtpt);
     878    paranoid_free(extra_cdrom_params);
     879    paranoid_free(mondo_mkisofs_sz);
     880    paranoid_free(command);
     881    paranoid_free(hostname);
     882    paranoid_free(ip_address);
     883    paranoid_free(cdr_exe);
     884    paranoid_free(tmp);
     885    paranoid_free(iso_dev);
     886    paranoid_free(iso_mnt);
     887    paranoid_free(iso_tmp);
     888    paranoid_free(iso_path);
     889    return (retval);
    891890}
    892891
     
    902901int pre_param_configuration(struct s_bkpinfo *bkpinfo)
    903902{
    904   int res=0;
    905 
    906   make_hole_for_dir(MNT_CDROM);
    907   assert(bkpinfo!=NULL);
    908   srandom ((unsigned long)(time (NULL)));
    909   insmod_crucial_modules();
    910   reset_bkpinfo (bkpinfo); // also sets defaults ('/'=backup path, 3=compression level)
    911   if (bkpinfo->disaster_recovery) {
    912     if (!does_nonMS_partition_exist()) {
    913       fatal_error ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    914     }
    915   }
    916 
    917   unlink (MONDO_TRACEFILE);
    918   run_program_and_log_output( "rm -Rf /tmp/changed.files*", FALSE);
    919   if (find_and_store_mondoarchives_home(g_mondo_home))
    920     {
    921       fprintf (stderr,
    922            "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");
    923       res++;
    924       return(res);
    925     }
    926   res += some_basic_system_sanity_checks ();
    927   if (res)
    928     {
    929       log_it ("Your distribution did not pass Mondo's sanity test.");
    930     }
    931   g_current_media_number = 1;
    932   bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
    933   return(res);
     903    int res = 0;
     904
     905    make_hole_for_dir(MNT_CDROM);
     906    assert(bkpinfo != NULL);
     907    srandom((unsigned long) (time(NULL)));
     908    insmod_crucial_modules();
     909    reset_bkpinfo(bkpinfo);     // also sets defaults ('/'=backup path, 3=compression level)
     910    if (bkpinfo->disaster_recovery) {
     911        if (!does_nonMS_partition_exist()) {
     912            fatal_error
     913                ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     914        }
     915    }
     916
     917    unlink(MONDO_TRACEFILE);
     918    run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
     919    if (find_and_store_mondoarchives_home(g_mondo_home)) {
     920        fprintf(stderr,
     921                "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");
     922        res++;
     923        return (res);
     924    }
     925    res += some_basic_system_sanity_checks();
     926    if (res) {
     927        log_it("Your distribution did not pass Mondo's sanity test.");
     928    }
     929    g_current_media_number = 1;
     930    bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
     931    return (res);
    934932}
    935933
     
    941939 * @param bkpinfo The @c bkpinfo to reset.
    942940 */
    943 void
    944 reset_bkpinfo (struct s_bkpinfo *bkpinfo)
    945 {
    946   int i;
    947 
    948   log_msg(1, "Hi");
    949   assert(bkpinfo!=NULL);
    950   memset((void*)bkpinfo, 0, sizeof(struct s_bkpinfo));
    951   bkpinfo->manual_cd_tray = FALSE;
    952   bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    953   bkpinfo->media_device[0] = '\0';
    954   for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = -1; }
    955   bkpinfo->boot_loader = '\0';
    956   bkpinfo->boot_device[0] = '\0';
    957   bkpinfo->zip_exe[0] = '\0';
    958   bkpinfo->zip_suffix[0] = '\0';
    959   bkpinfo->restore_path[0] = '\0';
    960   bkpinfo->use_lzo = FALSE;
    961   bkpinfo->do_not_compress_these[0] = '\0';
    962   bkpinfo->verify_data = FALSE;
    963   bkpinfo->backup_data = FALSE;
    964   bkpinfo->restore_data = FALSE;
    965   bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()?TRUE:FALSE);
    966   if (bkpinfo->disaster_recovery)
    967     { strcpy(bkpinfo->isodir, "/"); }
    968   else
    969     { strcpy (bkpinfo->isodir, "/root/images/mondo"); }
    970   strcpy (bkpinfo->prefix, "mondorescue");
    971 
    972   bkpinfo->scratchdir[0] = '\0';
    973   bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
    974   sprintf( bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) ( random() %32768 ) ); // for mondorestore
    975   bkpinfo->optimal_set_size = 0;
    976   bkpinfo->backup_media_type = none;
    977   strcpy (bkpinfo->include_paths, "/");
    978   bkpinfo->exclude_paths[0] = '\0';
    979   bkpinfo->call_before_iso[0] = '\0';
    980   bkpinfo->call_make_iso[0] = '\0';
    981   bkpinfo->call_burn_iso[0] = '\0';
    982   bkpinfo->call_after_iso[0] = '\0';
    983   bkpinfo->image_devs[0] = '\0';
    984   bkpinfo->postnuke_tarball[0] = '\0';
    985   bkpinfo->kernel_path[0] = '\0';
    986   bkpinfo->nfs_mount[0] = '\0';
    987   bkpinfo->nfs_remote_dir[0] = '\0';
    988   bkpinfo->wipe_media_first = FALSE;
    989   bkpinfo->differential = FALSE;
    990   bkpinfo->cdrw_speed = 0;
     941void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
     942{
     943    int i;
     944
     945    log_msg(1, "Hi");
     946    assert(bkpinfo != NULL);
     947    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     948    bkpinfo->manual_cd_tray = FALSE;
     949    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     950    bkpinfo->media_device[0] = '\0';
     951    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     952        bkpinfo->media_size[i] = -1;
     953    }
     954    bkpinfo->boot_loader = '\0';
     955    bkpinfo->boot_device[0] = '\0';
     956    bkpinfo->zip_exe[0] = '\0';
     957    bkpinfo->zip_suffix[0] = '\0';
     958    bkpinfo->restore_path[0] = '\0';
     959    bkpinfo->use_lzo = FALSE;
     960    bkpinfo->do_not_compress_these[0] = '\0';
     961    bkpinfo->verify_data = FALSE;
     962    bkpinfo->backup_data = FALSE;
     963    bkpinfo->restore_data = FALSE;
     964    bkpinfo->disaster_recovery =
     965        (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     966    if (bkpinfo->disaster_recovery) {
     967        strcpy(bkpinfo->isodir, "/");
     968    } else {
     969        strcpy(bkpinfo->isodir, "/root/images/mondo");
     970    }
     971    strcpy(bkpinfo->prefix, "mondorescue");
     972
     973    bkpinfo->scratchdir[0] = '\0';
     974    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
     975    sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768));  // for mondorestore
     976    bkpinfo->optimal_set_size = 0;
     977    bkpinfo->backup_media_type = none;
     978    strcpy(bkpinfo->include_paths, "/");
     979    bkpinfo->exclude_paths[0] = '\0';
     980    bkpinfo->call_before_iso[0] = '\0';
     981    bkpinfo->call_make_iso[0] = '\0';
     982    bkpinfo->call_burn_iso[0] = '\0';
     983    bkpinfo->call_after_iso[0] = '\0';
     984    bkpinfo->image_devs[0] = '\0';
     985    bkpinfo->postnuke_tarball[0] = '\0';
     986    bkpinfo->kernel_path[0] = '\0';
     987    bkpinfo->nfs_mount[0] = '\0';
     988    bkpinfo->nfs_remote_dir[0] = '\0';
     989    bkpinfo->wipe_media_first = FALSE;
     990    bkpinfo->differential = FALSE;
     991    bkpinfo->cdrw_speed = 0;
    991992// patch by Herman Kuster 
    992   bkpinfo->differential = 0;
     993    bkpinfo->differential = 0;
    993994// patch end
    994   bkpinfo->compression_level = 3;
     995    bkpinfo->compression_level = 3;
    995996}
    996997
     
    10031004 * @return The free space on @p partition, in MB.
    10041005 */
    1005 long free_space_on_given_partition(char*partition)
    1006 {
    1007   char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
    1008   long res;
    1009 
    1010   assert_string_is_neither_NULL_nor_zerolength(partition);
    1011 
    1012   sprintf(command, "df -m %s &> /dev/null", partition);
    1013   if (system(command))
    1014     { return(-1); } // partition does not exist
    1015   sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    1016   strcpy(out_sz, call_program_and_get_last_line_of_output(command));
    1017   if (strlen(out_sz)==0)
    1018     { return(-1); } // error within df, probably
    1019   res = atol(out_sz);
    1020   return(res);
     1006long free_space_on_given_partition(char *partition)
     1007{
     1008    char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
     1009    long res;
     1010
     1011    assert_string_is_neither_NULL_nor_zerolength(partition);
     1012
     1013    sprintf(command, "df -m %s &> /dev/null", partition);
     1014    if (system(command)) {
     1015        return (-1);
     1016    }                           // partition does not exist
     1017    sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     1018            partition);
     1019    strcpy(out_sz, call_program_and_get_last_line_of_output(command));
     1020    if (strlen(out_sz) == 0) {
     1021        return (-1);
     1022    }                           // error within df, probably
     1023    res = atol(out_sz);
     1024    return (res);
    10211025}
    10221026
     
    10351039 * @return number of problems with the user's setup (0 for success)
    10361040 */
    1037 int
    1038 some_basic_system_sanity_checks ()
    1039 {
    1040 
    1041     /*@ buffers *************/
    1042   char tmp[MAX_STR_LEN];
    1043   //  char command[MAX_STR_LEN];
    1044 
    1045     /*@ int's ****************/
    1046   int retval = 0;
    1047   long Lres;
    1048 
    1049 
    1050   mvaddstr_and_log_it (g_currentY, 0,
    1051                "Checking sanity of your Linux distribution");
     1041int some_basic_system_sanity_checks()
     1042{
     1043
     1044    /*@ buffers ************ */
     1045    char tmp[MAX_STR_LEN];
     1046    //  char command[MAX_STR_LEN];
     1047
     1048    /*@ int's *************** */
     1049    int retval = 0;
     1050    long Lres;
     1051
     1052
     1053    mvaddstr_and_log_it(g_currentY, 0,
     1054                        "Checking sanity of your Linux distribution");
    10521055#ifndef __FreeBSD__
    1053   if (system("which mkfs.vfat &> /dev/null") && !system("which mkfs.msdos &> /dev/null"))
    1054     {
    1055       log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
    1056       run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    1057     }
    1058   strcpy (tmp,
    1059       call_program_and_get_last_line_of_output
    1060       ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    1061   if (atol (tmp) < 35000)
    1062     {
    1063       retval++;
    1064       log_to_screen ("You must have at least 32MB of RAM to use Mondo.");
    1065     }
    1066   if (atol (tmp) < 66000)
    1067     {
    1068       log_to_screen
    1069     ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    1070     }
    1071 #endif
    1072 
    1073   if ((Lres = free_space_on_given_partition("/root"))==-1)
    1074     { Lres = free_space_on_given_partition("/"); }
    1075   log_it("Free space on given partition = %ld MB", Lres);
    1076 
    1077   if (Lres < 50)
    1078     {
    1079       run_program_and_log_output("rm -Rf /root/images/mindi; mkdir -p /home/root/images/mindi; mkdir -p /root/images; ln -sf /home/root/images/mindi /root/images/mindi", 3);
    1080       //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
    1081     }
    1082 
    1083   if (system ("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null"))
    1084     {
    1085       retval++;
    1086       log_to_screen
    1087     ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
    1088       fatal_error
    1089         ("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. :)");
    1090     }
     1056    if (system("which mkfs.vfat &> /dev/null")
     1057        && !system("which mkfs.msdos &> /dev/null")) {
     1058        log_it
     1059            ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
     1060        run_program_and_log_output
     1061            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
     1062    }
     1063    strcpy(tmp,
     1064           call_program_and_get_last_line_of_output
     1065           ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     1066    if (atol(tmp) < 35000) {
     1067        retval++;
     1068        log_to_screen("You must have at least 32MB of RAM to use Mondo.");
     1069    }
     1070    if (atol(tmp) < 66000) {
     1071        log_to_screen
     1072            ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     1073    }
     1074#endif
     1075
     1076    if ((Lres = free_space_on_given_partition("/root")) == -1) {
     1077        Lres = free_space_on_given_partition("/");
     1078    }
     1079    log_it("Free space on given partition = %ld MB", Lres);
     1080
     1081    if (Lres < 50) {
     1082        run_program_and_log_output
     1083            ("rm -Rf /root/images/mindi; mkdir -p /home/root/images/mindi; mkdir -p /root/images; ln -sf /home/root/images/mindi /root/images/mindi",
     1084             3);
     1085        //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
     1086    }
     1087
     1088    if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
     1089        retval++;
     1090        log_to_screen
     1091            ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
     1092        fatal_error
     1093            ("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. :)");
     1094    }
    10911095#ifndef __FreeBSD__
    1092   if (run_program_and_log_output ("cat /proc/devices | grep ramdisk", FALSE))
    1093     {
    1094       if (!ask_me_yes_or_no("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?"))
    1095         {
    1096       //          retval++;
    1097           log_to_screen
    1098             ("It looks as if your kernel lacks ramdisk and initrd support.");
    1099       log_to_screen
    1100         ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
    1101         }
    1102     }
    1103 #endif
    1104   retval += whine_if_not_found (MKE2FS_OR_NEWFS);
    1105   retval += whine_if_not_found ("mkisofs");
    1106   if (system("which dvdrecord > /dev/null 2> /dev/null"))
    1107     { retval += whine_if_not_found ("cdrecord"); }
    1108   retval += whine_if_not_found ("bzip2");
    1109   retval += whine_if_not_found ("awk");
    1110   retval += whine_if_not_found ("md5sum");
    1111   retval += whine_if_not_found ("strings");
    1112   retval += whine_if_not_found ("mindi");
    1113   retval += whine_if_not_found ("buffer");
    1114 
    1115   // abort if Windows partition but no ms-sys and parted
    1116   if (!run_program_and_log_output("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0) ||
    1117       !run_program_and_log_output("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0))
    1118     {
    1119       log_to_screen("I think you have a Windows 9x partition.");
    1120       retval += whine_if_not_found ("parted");
     1096    if (run_program_and_log_output
     1097        ("cat /proc/devices | grep ramdisk", FALSE)) {
     1098        if (!ask_me_yes_or_no
     1099            ("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?"))
     1100        {
     1101            //          retval++;
     1102            log_to_screen
     1103                ("It looks as if your kernel lacks ramdisk and initrd support.");
     1104            log_to_screen
     1105                ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
     1106        }
     1107    }
     1108#endif
     1109    retval += whine_if_not_found(MKE2FS_OR_NEWFS);
     1110    retval += whine_if_not_found("mkisofs");
     1111    if (system("which dvdrecord > /dev/null 2> /dev/null")) {
     1112        retval += whine_if_not_found("cdrecord");
     1113    }
     1114    retval += whine_if_not_found("bzip2");
     1115    retval += whine_if_not_found("awk");
     1116    retval += whine_if_not_found("md5sum");
     1117    retval += whine_if_not_found("strings");
     1118    retval += whine_if_not_found("mindi");
     1119    retval += whine_if_not_found("buffer");
     1120
     1121    // abort if Windows partition but no ms-sys and parted
     1122    if (!run_program_and_log_output
     1123        ("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0)
     1124        ||
     1125        !run_program_and_log_output
     1126        ("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0)) {
     1127        log_to_screen("I think you have a Windows 9x partition.");
     1128        retval += whine_if_not_found("parted");
    11211129#ifndef __IA64__
    1122       /* IA64 always has one vfat partition for EFI even without Windows */
    1123       // retval +=
    1124       if (!find_home_of_exe("ms-sys"))
    1125         {
    1126       log_to_screen("Please install ms-sys just in case.");
    1127     }
    1128 #endif
    1129     }
    1130 
    1131   if (!find_home_of_exe("cmp"))
    1132     {
    1133       if (!find_home_of_exe("true"))
    1134         { whine_if_not_found ("cmp"); }
    1135       else
    1136         {
    1137           log_to_screen("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
    1138           if (run_program_and_log_output("cp -f `which true` /usr/bin/cmp", 0))
    1139             { fatal_error("Failed to create dummy 'cmp' file."); }
    1140         }
    1141     }
    1142   run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1143   strcpy (tmp,
    1144       call_program_and_get_last_line_of_output
    1145       ("mount | grep -E \"cdr(om|w)\""));
    1146   if (strcmp ("", tmp))
    1147     {
    1148     if (strstr (tmp, "autofs")) {
    1149         log_to_screen ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
    1150         log_to_screen ("if a CD actually is inserted. If a CD is inserted, please");
    1151         log_to_screen ("eject it. Thank you.");
    1152         log_it ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
    1153     } else if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
    1154         retval++;
    1155         fatal_error ("Your CD-ROM drive is mounted. Please unmount it.");
    1156     }
    1157     }
     1130        /* IA64 always has one vfat partition for EFI even without Windows */
     1131        // retval +=
     1132        if (!find_home_of_exe("ms-sys")) {
     1133            log_to_screen("Please install ms-sys just in case.");
     1134        }
     1135#endif
     1136    }
     1137
     1138    if (!find_home_of_exe("cmp")) {
     1139        if (!find_home_of_exe("true")) {
     1140            whine_if_not_found("cmp");
     1141        } else {
     1142            log_to_screen
     1143                ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
     1144            if (run_program_and_log_output
     1145                ("cp -f `which true` /usr/bin/cmp", 0)) {
     1146                fatal_error("Failed to create dummy 'cmp' file.");
     1147            }
     1148        }
     1149    }
     1150    run_program_and_log_output
     1151        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
     1152    strcpy(tmp,
     1153           call_program_and_get_last_line_of_output
     1154           ("mount | grep -E \"cdr(om|w)\""));
     1155    if (strcmp("", tmp)) {
     1156        if (strstr(tmp, "autofs")) {
     1157            log_to_screen
     1158                ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
     1159            log_to_screen
     1160                ("if a CD actually is inserted. If a CD is inserted, please");
     1161            log_to_screen("eject it. Thank you.");
     1162            log_it
     1163                ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
     1164        } else
     1165            if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
     1166            retval++;
     1167            fatal_error
     1168                ("Your CD-ROM drive is mounted. Please unmount it.");
     1169        }
     1170    }
    11581171#ifndef __FreeBSD__
    1159   if (!does_file_exist ("/etc/modules.conf"))
    1160     {
    1161       if (does_file_exist("/etc/conf.modules"))
    1162         {
    1163           log_it("Linking /etc/modules.conf to /etc/conf.modules");
    1164           run_program_and_log_output("ln -sf /etc/conf.modules /etc/modules.conf", 5);
    1165         }
    1166       else if (does_file_exist("/etc/modprobe.d"))
    1167     {
    1168       log_it("Directory /etc/modprobe.d found. mindi will use its contents.");
    1169     }
    1170       else if (does_file_exist("/etc/modprobe.conf"))
    1171         {
    1172           log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
    1173           run_program_and_log_output("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
    1174     }
    1175       else
    1176         {
    1177           retval++;
    1178           log_to_screen ("Please find out what happened to /etc/modules.conf");
    1179         }
    1180     }
    1181 #endif
    1182 
    1183   run_program_and_log_output("cat /etc/fstab", 5);
     1172    if (!does_file_exist("/etc/modules.conf")) {
     1173        if (does_file_exist("/etc/conf.modules")) {
     1174            log_it("Linking /etc/modules.conf to /etc/conf.modules");
     1175            run_program_and_log_output
     1176                ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
     1177        } else if (does_file_exist("/etc/modprobe.d")) {
     1178            log_it
     1179                ("Directory /etc/modprobe.d found. mindi will use its contents.");
     1180        } else if (does_file_exist("/etc/modprobe.conf")) {
     1181            log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
     1182            run_program_and_log_output
     1183                ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
     1184        } else {
     1185            retval++;
     1186            log_to_screen
     1187                ("Please find out what happened to /etc/modules.conf");
     1188        }
     1189    }
     1190#endif
     1191
     1192    run_program_and_log_output("cat /etc/fstab", 5);
    11841193#ifdef __FreeBSD__
    1185   run_program_and_log_output("vinum printconfig", 5);
     1194    run_program_and_log_output("vinum printconfig", 5);
    11861195#else
    1187   run_program_and_log_output("cat /etc/raidtab", 5);
    1188 #endif
    1189 
    1190   if (run_program_and_log_output("mindi -V", 1))
    1191     {
    1192       log_to_screen("Could not ascertain mindi's version number.");
    1193       log_to_screen("You have not installed Mondo and/or Mindi properly.");
    1194       log_to_screen("Please uninstall and reinstall them both.");
    1195       fatal_error("Please reinstall Mondo and Mindi.");
    1196     }
    1197   if (run_program_and_log_output("mindi --makemountlist /tmp/mountlist.txt.test", 5))
    1198     {
    1199       log_to_screen("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
    1200       log_to_screen("Please run that command by hand and examine /var/log/mindi.log");
    1201       log_to_screen("for more information. Perhaps your /etc/fstab file is insane.");
    1202       log_to_screen("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
    1203       retval++;
    1204     }
    1205 
    1206   if (!run_program_and_log_output("fdisk -l | grep -i raid", 1) && !does_file_exist("/etc/raidtab"))
    1207     {
    1208       log_to_screen("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
    1209       create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
    1210     }
    1211  
    1212   if (retval)
    1213     {
    1214       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1215     }
    1216   else
    1217     {
    1218       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1219     }
    1220   return (retval);
     1196    run_program_and_log_output("cat /etc/raidtab", 5);
     1197#endif
     1198
     1199    if (run_program_and_log_output("mindi -V", 1)) {
     1200        log_to_screen("Could not ascertain mindi's version number.");
     1201        log_to_screen
     1202            ("You have not installed Mondo and/or Mindi properly.");
     1203        log_to_screen("Please uninstall and reinstall them both.");
     1204        fatal_error("Please reinstall Mondo and Mindi.");
     1205    }
     1206    if (run_program_and_log_output
     1207        ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
     1208        log_to_screen
     1209            ("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
     1210        log_to_screen
     1211            ("Please run that command by hand and examine /var/log/mindi.log");
     1212        log_to_screen
     1213            ("for more information. Perhaps your /etc/fstab file is insane.");
     1214        log_to_screen
     1215            ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
     1216        retval++;
     1217    }
     1218
     1219    if (!run_program_and_log_output("fdisk -l | grep -i raid", 1)
     1220        && !does_file_exist("/etc/raidtab")) {
     1221        log_to_screen
     1222            ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
     1223        create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
     1224    }
     1225
     1226    if (retval) {
     1227        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1228    } else {
     1229        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1230    }
     1231    return (retval);
    12211232}
    12221233
     
    12281239 * @return 0 for success, 1 for failure.
    12291240 */
    1230 int
    1231 read_cfg_var (char *config_file, char *label, char *value)
    1232 {
    1233     /*@ buffer *******************************************************/
    1234   char command[MAX_STR_LEN*2];
    1235   char tmp[MAX_STR_LEN];
    1236 
    1237     /*@ end vars ****************************************************/
    1238 
    1239   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1240   assert_string_is_neither_NULL_nor_zerolength(label);
    1241   if (!does_file_exist (config_file))
    1242     {
    1243       sprintf (tmp, "(read_cfg_var) Cannot find %s config file", config_file);
    1244       log_to_screen (tmp);
    1245       value[0] = '\0';
    1246       return (1);
    1247     }
    1248   else if (strstr(value, "/dev/") && strstr(value, "t0") && !strcmp(label, "media-dev"))
    1249     {
    1250       log_msg (2, "FYI, I shan't read new value for %s - already got %s", label, value);
    1251       return(0);
    1252     }
    1253   else
    1254     {
    1255       sprintf (command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
    1256            config_file, label);
    1257       strcpy (value, call_program_and_get_last_line_of_output (command));
    1258       if (strlen (value) == 0)
    1259     {
    1260       return (1);
    1261     }
    1262       else
    1263     {
    1264       return (0);
    1265     }
    1266     }
     1241int read_cfg_var(char *config_file, char *label, char *value)
     1242{
     1243    /*@ buffer ****************************************************** */
     1244    char command[MAX_STR_LEN * 2];
     1245    char tmp[MAX_STR_LEN];
     1246
     1247    /*@ end vars *************************************************** */
     1248
     1249    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1250    assert_string_is_neither_NULL_nor_zerolength(label);
     1251    if (!does_file_exist(config_file)) {
     1252        sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
     1253                config_file);
     1254        log_to_screen(tmp);
     1255        value[0] = '\0';
     1256        return (1);
     1257    } else if (strstr(value, "/dev/") && strstr(value, "t0")
     1258               && !strcmp(label, "media-dev")) {
     1259        log_msg(2, "FYI, I shan't read new value for %s - already got %s",
     1260                label, value);
     1261        return (0);
     1262    } else {
     1263        sprintf(command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
     1264                config_file, label);
     1265        strcpy(value, call_program_and_get_last_line_of_output(command));
     1266        if (strlen(value) == 0) {
     1267            return (1);
     1268        } else {
     1269            return (0);
     1270        }
     1271    }
    12671272}
    12681273
     
    12741279void remount_supermounts_if_necessary()
    12751280{
    1276   if (g_remount_cdrom_at_end)
    1277     {
    1278       run_program_and_log_output ("mount "MNT_CDROM, FALSE);
    1279     }
    1280   if (g_remount_floppy_at_end)
    1281     {
    1282       run_program_and_log_output ("mount "MNT_FLOPPY, FALSE);
    1283     }
     1281    if (g_remount_cdrom_at_end) {
     1282        run_program_and_log_output("mount " MNT_CDROM, FALSE);
     1283    }
     1284    if (g_remount_floppy_at_end) {
     1285        run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
     1286    }
    12841287}
    12851288
     
    12891292void unmount_supermounts_if_necessary()
    12901293{
    1291   if (run_program_and_log_output ("mount | grep cdrom | grep super", FALSE) == 0)
    1292     {
    1293       g_remount_cdrom_at_end = TRUE;
    1294       run_program_and_log_output ("umount "MNT_CDROM, FALSE);
    1295     }
    1296   if (run_program_and_log_output ("mount | grep floppy | grep super", FALSE) == 0)
    1297     {
    1298       g_remount_floppy_at_end = TRUE;
    1299       run_program_and_log_output ("umount "MNT_FLOPPY, FALSE);
    1300     }
     1294    if (run_program_and_log_output
     1295        ("mount | grep cdrom | grep super", FALSE) == 0) {
     1296        g_remount_cdrom_at_end = TRUE;
     1297        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1298    }
     1299    if (run_program_and_log_output
     1300        ("mount | grep floppy | grep super", FALSE) == 0) {
     1301        g_remount_floppy_at_end = TRUE;
     1302        run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
     1303    }
    13011304}
    13021305
     
    13041307 * Whether we had to stop autofs (if so, restart it at end).
    13051308 */
    1306 bool g_autofs_stopped=FALSE;
     1309bool g_autofs_stopped = FALSE;
    13071310
    13081311/**
     
    13261329void stop_autofs_if_necessary()
    13271330{
    1328   char tmp[MAX_STR_LEN];
    1329  
    1330   g_autofs_exe[0] = '\0';
    1331   if (does_file_exist(XANDROS_AUTOFS_FNAME))
    1332     { strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME); } 
    1333   else if (does_file_exist(STOCK_AUTOFS_FNAME))
    1334     { strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME); }
    1335    
    1336   if (!g_autofs_exe[0]) { log_msg(3, "No autofs detected."); } 
    1337   else
    1338     {
    1339       log_msg(3, "%s --- autofs detected", g_autofs_exe);
     1331    char tmp[MAX_STR_LEN];
     1332
     1333    g_autofs_exe[0] = '\0';
     1334    if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
     1335        strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
     1336    } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
     1337        strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
     1338    }
     1339
     1340    if (!g_autofs_exe[0]) {
     1341        log_msg(3, "No autofs detected.");
     1342    } else {
     1343        log_msg(3, "%s --- autofs detected", g_autofs_exe);
    13401344// FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1341       sprintf(tmp, "%s stop", g_autofs_exe);
    1342       if (run_program_and_log_output(tmp, 2))
    1343         { log_it("Failed to stop autofs - I assume it wasn't running"); }
    1344       else
    1345         { g_autofs_stopped = TRUE; log_it("Stopped autofs OK"); }
    1346     }
     1345        sprintf(tmp, "%s stop", g_autofs_exe);
     1346        if (run_program_and_log_output(tmp, 2)) {
     1347            log_it("Failed to stop autofs - I assume it wasn't running");
     1348        } else {
     1349            g_autofs_stopped = TRUE;
     1350            log_it("Stopped autofs OK");
     1351        }
     1352    }
    13471353}
    13481354
     
    13521358void restart_autofs_if_necessary()
    13531359{
    1354   char tmp[MAX_STR_LEN];
    1355  
    1356   if (!g_autofs_stopped || !g_autofs_exe[0]) { log_msg(3, "No autofs detected."); return; } 
    1357   sprintf(tmp, "%s start", g_autofs_exe);
    1358   if (run_program_and_log_output(tmp, 2))
    1359     { log_it("Failed to start autofs"); }
    1360   else
    1361     { g_autofs_stopped = FALSE; log_it("Started autofs OK"); }
     1360    char tmp[MAX_STR_LEN];
     1361
     1362    if (!g_autofs_stopped || !g_autofs_exe[0]) {
     1363        log_msg(3, "No autofs detected.");
     1364        return;
     1365    }
     1366    sprintf(tmp, "%s start", g_autofs_exe);
     1367    if (run_program_and_log_output(tmp, 2)) {
     1368        log_it("Failed to start autofs");
     1369    } else {
     1370        g_autofs_stopped = FALSE;
     1371        log_it("Started autofs OK");
     1372    }
    13621373}
    13631374
     
    13681379void mount_boot_if_necessary()
    13691380{
    1370   char tmp[MAX_STR_LEN];
    1371   char command[MAX_STR_LEN];
    1372 
    1373   log_msg(1, "Started sub");
    1374   log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
    1375   g_boot_mountpt[0] = '\0';
    1376   log_msg(4, "Done. Great. Seeting command to something");
    1377   strcpy(command, "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    1378   log_msg(4, "Cool. Command = '%s'", command);
    1379   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1380   log_msg(4, "tmp = '%s'", tmp);
    1381   if (tmp[0])
    1382     {
    1383       log_it("/boot is at %s according to /etc/fstab", tmp);
    1384       if (strstr(tmp, "LABEL="))
    1385         {
    1386       if (!run_program_and_log_output("mount /boot", 5))
    1387         {
    1388           strcpy(g_boot_mountpt, "/boot");
    1389           log_msg(1, "Mounted /boot");
    1390         }
    1391       else
    1392         {
    1393           log_it("...ignored cos it's a label :-)");
    1394         }
    1395     }
    1396       else
    1397         {
    1398           sprintf(command, "mount | grep -w \"%s\"", tmp);
    1399           log_msg(3, "command = %s", command);
    1400           if (run_program_and_log_output(command, 5))
    1401             {
    1402           strcpy(g_boot_mountpt, tmp);
    1403               sprintf(tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
    1404           log_it(tmp);
    1405           sprintf(tmp, "mount %s", g_boot_mountpt);
    1406           if (run_program_and_log_output(tmp, 5))
    1407         {
    1408           g_boot_mountpt[0] = '\0';
    1409           log_msg(1, "Plan B");
    1410           if (!run_program_and_log_output("mount /boot", 5))
    1411             {
    1412               strcpy(g_boot_mountpt, "/boot");
    1413               log_msg(1, "Plan B worked");
    1414             }
    1415           else
    1416             {
    1417               log_msg(1, "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
    1418             }
    1419         }
    1420             }
    1421         }
    1422     }
    1423   log_msg(1, "Ended sub");
     1381    char tmp[MAX_STR_LEN];
     1382    char command[MAX_STR_LEN];
     1383
     1384    log_msg(1, "Started sub");
     1385    log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
     1386    g_boot_mountpt[0] = '\0';
     1387    log_msg(4, "Done. Great. Seeting command to something");
     1388    strcpy(command,
     1389           "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1390    log_msg(4, "Cool. Command = '%s'", command);
     1391    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1392    log_msg(4, "tmp = '%s'", tmp);
     1393    if (tmp[0]) {
     1394        log_it("/boot is at %s according to /etc/fstab", tmp);
     1395        if (strstr(tmp, "LABEL=")) {
     1396            if (!run_program_and_log_output("mount /boot", 5)) {
     1397                strcpy(g_boot_mountpt, "/boot");
     1398                log_msg(1, "Mounted /boot");
     1399            } else {
     1400                log_it("...ignored cos it's a label :-)");
     1401            }
     1402        } else {
     1403            sprintf(command, "mount | grep -w \"%s\"", tmp);
     1404            log_msg(3, "command = %s", command);
     1405            if (run_program_and_log_output(command, 5)) {
     1406                strcpy(g_boot_mountpt, tmp);
     1407                sprintf(tmp,
     1408                        "%s (your /boot partition) is not mounted. I'll mount it before backing up",
     1409                        g_boot_mountpt);
     1410                log_it(tmp);
     1411                sprintf(tmp, "mount %s", g_boot_mountpt);
     1412                if (run_program_and_log_output(tmp, 5)) {
     1413                    g_boot_mountpt[0] = '\0';
     1414                    log_msg(1, "Plan B");
     1415                    if (!run_program_and_log_output("mount /boot", 5)) {
     1416                        strcpy(g_boot_mountpt, "/boot");
     1417                        log_msg(1, "Plan B worked");
     1418                    } else {
     1419                        log_msg(1,
     1420                                "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1421                    }
     1422                }
     1423            }
     1424        }
     1425    }
     1426    log_msg(1, "Ended sub");
    14241427}
    14251428
     
    14301433void unmount_boot_if_necessary()
    14311434{
    1432   char tmp[MAX_STR_LEN];
    1433 
    1434   log_msg(3, "starting");
    1435   if (g_boot_mountpt[0])
    1436     {
    1437       sprintf(tmp, "umount %s", g_boot_mountpt);
    1438       if (run_program_and_log_output(tmp, 5))
    1439     { log_it("WARNING - unable to unmount /boot"); }
    1440     }
    1441    log_msg(3, "leaving");
     1435    char tmp[MAX_STR_LEN];
     1436
     1437    log_msg(3, "starting");
     1438    if (g_boot_mountpt[0]) {
     1439        sprintf(tmp, "umount %s", g_boot_mountpt);
     1440        if (run_program_and_log_output(tmp, 5)) {
     1441            log_it("WARNING - unable to unmount /boot");
     1442        }
     1443    }
     1444    log_msg(3, "leaving");
    14421445}
    14431446
     
    14521455 * @return 0 for success, 1 for failure.
    14531456 */
    1454 int
    1455 write_cfg_var (char *config_file, char *label, char *value)
    1456 {
    1457     /*@ buffers ******************************************************/
    1458   char command[MAX_STR_LEN*2];
    1459   char tempfile[MAX_STR_LEN];
    1460   char tmp[MAX_STR_LEN];
    1461 
    1462 
    1463     /*@ end vars ****************************************************/
    1464   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1465   assert_string_is_neither_NULL_nor_zerolength(label);
    1466   assert(value!=NULL);
    1467   if (!does_file_exist (config_file))
    1468     {
    1469       sprintf (tmp, "(write_cfg_file) Cannot find %s config file",
    1470            config_file);
    1471       log_to_screen (tmp);
    1472       return(1);
    1473     }
    1474   strcpy (tempfile,
    1475       call_program_and_get_last_line_of_output
    1476       ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
    1477   if (does_file_exist (config_file))
    1478     {
    1479       sprintf (command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
    1480            label, tempfile);
    1481       paranoid_system (command);
    1482     }
    1483   sprintf (command, "echo \"%s %s\" >> %s", label, value, tempfile);
    1484   paranoid_system (command);
    1485   sprintf (command, "mv -f %s %s", tempfile, config_file);
    1486   paranoid_system (command);
    1487   unlink (tempfile);
    1488   return (0);
     1457int write_cfg_var(char *config_file, char *label, char *value)
     1458{
     1459    /*@ buffers ***************************************************** */
     1460    char command[MAX_STR_LEN * 2];
     1461    char tempfile[MAX_STR_LEN];
     1462    char tmp[MAX_STR_LEN];
     1463
     1464
     1465    /*@ end vars *************************************************** */
     1466    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1467    assert_string_is_neither_NULL_nor_zerolength(label);
     1468    assert(value != NULL);
     1469    if (!does_file_exist(config_file)) {
     1470        sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
     1471                config_file);
     1472        log_to_screen(tmp);
     1473        return (1);
     1474    }
     1475    strcpy(tempfile,
     1476           call_program_and_get_last_line_of_output
     1477           ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
     1478    if (does_file_exist(config_file)) {
     1479        sprintf(command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
     1480                label, tempfile);
     1481        paranoid_system(command);
     1482    }
     1483    sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1484    paranoid_system(command);
     1485    sprintf(command, "mv -f %s %s", tempfile, config_file);
     1486    paranoid_system(command);
     1487    unlink(tempfile);
     1488    return (0);
    14891489}
    14901490
     
    14951495 */
    14961496void standard_log_debug_msg(int debug_level, const char *szFile,
    1497                 const char *szFunction, int nLine, const char *fmt, ...)
    1498 {
    1499   va_list args;
    1500   int i;
    1501   static int depth=0; 
    1502   char *tmp;
    1503   FILE*fout;
    1504 
    1505   if (depth>5) { depth--; return; }
    1506   depth++;
    1507 
    1508   malloc_string(tmp);
    1509 
    1510   if (debug_level <= g_loglevel)
    1511     {
    1512       va_start(args, fmt);
    1513       if (!(fout = fopen (MONDO_LOGFILE, "a")))
    1514     { return; } // fatal_error("Failed to openout to logfile - sheesh..."); }
    1515 
    1516       // add tabs to distinguish log levels
    1517       if (debug_level > 0)
    1518     {
    1519       for (i = 1; i < debug_level; i++)
    1520         fprintf(fout, "\t");
    1521       if (getpid() == g_main_pid)
    1522         fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
    1523       else if (getpid() == g_buffer_pid && g_buffer_pid>0)
    1524         fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction, nLine);
    1525       else
    1526         fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
    1527     }
    1528       vfprintf(fout, fmt, args);
    1529 
    1530     // do not slow down the progran if standard debug level
    1531     // must be enabled: if no flush, the log won't be up-to-date if there
    1532     // is a segfault
    1533     //if (g_dwDebugLevel != 1)
    1534 
    1535       va_end(args);
    1536       fprintf(fout, "\n");
    1537       paranoid_fclose(fout);
    1538     }
    1539   depth--;
    1540   paranoid_free(tmp);
     1497                            const char *szFunction, int nLine,
     1498                            const char *fmt, ...)
     1499{
     1500    va_list args;
     1501    int i;
     1502    static int depth = 0;
     1503    char *tmp;
     1504    FILE *fout;
     1505
     1506    if (depth > 5) {
     1507        depth--;
     1508        return;
     1509    }
     1510    depth++;
     1511
     1512    malloc_string(tmp);
     1513
     1514    if (debug_level <= g_loglevel) {
     1515        va_start(args, fmt);
     1516        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
     1517            return;
     1518        }                       // fatal_error("Failed to openout to logfile - sheesh..."); }
     1519
     1520        // add tabs to distinguish log levels
     1521        if (debug_level > 0) {
     1522            for (i = 1; i < debug_level; i++)
     1523                fprintf(fout, "\t");
     1524            if (getpid() == g_main_pid)
     1525                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
     1526                        nLine);
     1527            else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
     1528                fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
     1529                        nLine);
     1530            else
     1531                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
     1532                        szFunction, nLine);
     1533        }
     1534        vfprintf(fout, fmt, args);
     1535
     1536        // do not slow down the progran if standard debug level
     1537        // must be enabled: if no flush, the log won't be up-to-date if there
     1538        // is a segfault
     1539        //if (g_dwDebugLevel != 1)
     1540
     1541        va_end(args);
     1542        fprintf(fout, "\n");
     1543        paranoid_fclose(fout);
     1544    }
     1545    depth--;
     1546    paranoid_free(tmp);
    15411547}
    15421548
     
    15441550 * Function pointer to the @c log_debug_msg function to use. Points to standard_log_debug_msg() by default.
    15451551 */
    1546 void (*log_debug_msg) (int, const char *, const char *, int, const char *, ...) = standard_log_debug_msg;
     1552void (*log_debug_msg) (int, const char *, const char *, int, const char *,
     1553                       ...) = standard_log_debug_msg;
    15471554
    15481555
     
    15591566void do_libmondo_global_strings_thing(int mal)
    15601567{
    1561   if (mal)
    1562     {
    1563       iamhere("Malloc'ing globals");
    1564       malloc_string(g_boot_mountpt);
    1565       malloc_string(g_mondo_home);
    1566       malloc_string(g_tmpfs_mountpt);
    1567       malloc_string(g_erase_tmpdir_and_scratchdir);
    1568       malloc_string(g_serial_string);
    1569       malloc_string(g_magicdev_command);
    1570     }
    1571   else
    1572     {
    1573       iamhere("Freeing globals");
    1574       paranoid_free(g_boot_mountpt);
    1575       paranoid_free(g_mondo_home);
    1576       paranoid_free(g_tmpfs_mountpt);
    1577       paranoid_free(g_erase_tmpdir_and_scratchdir);
    1578       paranoid_free(g_serial_string);
    1579       paranoid_free(g_magicdev_command);
    1580     }
    1581 
    1582   /*
    1583   char**list_of_arrays[] = {
    1584     &g_boot_mountpt,
    1585     &g_mondo_home,
    1586     &g_tmpfs_mountpt,
    1587     &g_erase_tmpdir_and_scratchdir,
    1588     &g_serial_string,
    1589     &g_magicdev_command,
    1590     NULL};
    1591 
    1592   char**ppcurr;
    1593   int i;
    1594  
    1595   for(i=0;list_of_arrays[i];i++)
    1596     {
    1597       log_msg(5, "Allocating %d", i);
    1598       ppcurr = list_of_arrays[i];
    1599       if (mal)
    1600         { *ppcurr = malloc(MAX_STR_LEN); }
    1601       else
    1602         {
    1603       if (*ppcurr)
    1604         {
    1605           free(*ppcurr);
    1606         }
    1607     }
    1608     }
    1609   log_msg(5, "Returning");
    1610   */
     1568    if (mal) {
     1569        iamhere("Malloc'ing globals");
     1570        malloc_string(g_boot_mountpt);
     1571        malloc_string(g_mondo_home);
     1572        malloc_string(g_tmpfs_mountpt);
     1573        malloc_string(g_erase_tmpdir_and_scratchdir);
     1574        malloc_string(g_serial_string);
     1575        malloc_string(g_magicdev_command);
     1576    } else {
     1577        iamhere("Freeing globals");
     1578        paranoid_free(g_boot_mountpt);
     1579        paranoid_free(g_mondo_home);
     1580        paranoid_free(g_tmpfs_mountpt);
     1581        paranoid_free(g_erase_tmpdir_and_scratchdir);
     1582        paranoid_free(g_serial_string);
     1583        paranoid_free(g_magicdev_command);
     1584    }
     1585
     1586    /*
     1587       char**list_of_arrays[] = {
     1588       &g_boot_mountpt,
     1589       &g_mondo_home,
     1590       &g_tmpfs_mountpt,
     1591       &g_erase_tmpdir_and_scratchdir,
     1592       &g_serial_string,
     1593       &g_magicdev_command,
     1594       NULL};
     1595
     1596       char**ppcurr;
     1597       int i;
     1598
     1599       for(i=0;list_of_arrays[i];i++)
     1600       {
     1601       log_msg(5, "Allocating %d", i);
     1602       ppcurr = list_of_arrays[i];
     1603       if (mal)
     1604       { *ppcurr = malloc(MAX_STR_LEN); }
     1605       else
     1606       {
     1607       if (*ppcurr)
     1608       {
     1609       free(*ppcurr);
     1610       }
     1611       }
     1612       }
     1613       log_msg(5, "Returning");
     1614     */
    16111615}
    16121616
     
    16171621void malloc_libmondo_global_strings(void)
    16181622{
    1619   do_libmondo_global_strings_thing(1);
     1623    do_libmondo_global_strings_thing(1);
    16201624}
    16211625
     
    16261630void free_libmondo_global_strings(void)
    16271631{
    1628   do_libmondo_global_strings_thing(0);
     1632    do_libmondo_global_strings_thing(0);
    16291633}
    16301634
     
    16371641void stop_magicdev_if_necessary()
    16381642{
    1639   strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
    1640   if (g_magicdev_command[0])
    1641     {
    1642       log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
    1643       paranoid_system("killall magicdev");
    1644     }
     1643    strcpy(g_magicdev_command,
     1644           call_program_and_get_last_line_of_output
     1645           ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1646    if (g_magicdev_command[0]) {
     1647        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
     1648        paranoid_system("killall magicdev");
     1649    }
    16451650}
    16461651
     
    16511656void restart_magicdev_if_necessary()
    16521657{
    1653   char *tmp;
    1654  
    1655   malloc_string(tmp);
    1656   if (g_magicdev_command && g_magicdev_command[0])
    1657     {
    1658       sprintf(tmp, "%s &", g_magicdev_command);
    1659       paranoid_system(tmp);
    1660     }
    1661   paranoid_free(tmp);
     1658    char *tmp;
     1659
     1660    malloc_string(tmp);
     1661    if (g_magicdev_command && g_magicdev_command[0]) {
     1662        sprintf(tmp, "%s &", g_magicdev_command);
     1663        paranoid_system(tmp);
     1664    }
     1665    paranoid_free(tmp);
    16621666}
    16631667
Note: See TracChangeset for help on using the changeset viewer.