Changeset 49 in MondoRescue for trunk


Ignore:
Timestamp:
Oct 7, 2005, 7:03:07 PM (19 years ago)
Author:
bcornec
Message:

some bugs corrected (size_t, & for getline, ...) + indent

Location:
trunk/mondo/mondo/common
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-archive.c

    r45 r49  
    995995    asprintf(&archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
    996996             bkpinfo->tmpdir, 0L);
    997     archiving_set_no = 0;
     997    archiving_set_no = 0L;
    998998    while (does_file_exist(archiving_filelist_fname)) {
    999999        paranoid_free(archiving_filelist_fname);
     
    19811981    int retval = 0;
    19821982    int res = 0;
    1983     int n = 0;
     1983    size_t n = 0;
    19841984    pid_t pid;
    19851985    FILE *ftmp = NULL;
     
    20152015        return (1);
    20162016    }
    2017     for (getline(&bigfile_fname, (size_t) & n, fin); !feof(fin);
    2018          getline(&bigfile_fname, (size_t) & n, fin),
     2017    for (getline(&bigfile_fname, &n, fin); !feof(fin);
     2018         getline(&bigfile_fname, &n, fin),
    20192019         biggie_file_number++) {
    20202020        use_partimagehack = FALSE;
     
    30463046
    30473047    /*@ buffers ************************************************** */
    3048     char *tmp, *checksum_line, *command;
     3048    char *tmp, *checksum_line = NULL, *command;
    30493049    char *tempblock;
    30503050    char *curr_slice_fname_uncompressed;
     
    30753075    int retval = 0;
    30763076    int res = 0;
    3077     int n = 0;
     3077    size_t n = 0;
    30783078
    30793079    /*@ structures ************************************************** */
     
    31153115        }
    31163116        paranoid_free(command);
    3117         (void) getline(&checksum_line, (size_t) & n, fin);
     3117        (void) getline(&checksum_line, &n, fin);
    31183118        pclose(fin);
    31193119    }
  • trunk/mondo/mondo/common/libmondo-filelist.c

    r30 r49  
    1 /* libmondo-filelist.c
    2    $Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $
    3 
    4 - for subroutines which manipulate the filelist
    5 
    6 
    7 01/11/2005
    8 - change  time_of_last_full_backup =  to st_mtime to allow manipulation of
    9 - /var/cache/mondo-archive/difflevel.0
    10 - Conor Daly <conor.daly@met.ie>
    11 
    12 10/01
    13 - don't try to sort non-existent file; return 0 instead
    14 
    15 09/14
    16 - dropped 'sort -o' (busybox doesn't support); use 'sort > ' instead
    17 
    18 08/02
    19 - add \ in front of [, ], ? or * when generating filelist subset
    20 
    21 07/27
    22 - sort filelists after creating them
    23 
    24 07/14
    25 - disabled ACL, xattr stuff; moved it to libmondo-archive.c
    26 - max sane size for a file is now 32MB
    27 
    28 07/10
    29 - added ACL and xattr support for afio users
    30 
    31 07/05
    32 - exclude /dev/shm from backup (Roberto Alsina)
    33 
    34 06/09
    35 - exclude /media/floppy or SuSE 9.1 freezes :(
    36 
    37 01/18/2004
    38 - exclude /sys as well as /proc
    39 
    40 10/18/2003
    41 - load_filelist() --- make sure you add the paths
    42   leading to the file, e.g. if you add /usr/lib/thingy.so
    43   then add /usr, /usr/lib first
    44 - rewritten load_filelist(), save_filelist(),
    45 - add_string_at_node(), find_string_at_node(),
    46 - save_filelist_entries_in_common()
    47 
    48 09/27
    49 - line 1269 had one too many '%s's
    50 
    51 09/26
    52 - fix newt* to be enclosed in #ifndef _XWIN
    53 - added superior progress display to mondo_makefilelist()
    54 
    55 09/18
    56 - call locate w/ 2> /dev/null at end of str
    57 
    58 09/16
    59 - replaced mondo-makefilelist with C subroutine
    60 
    61 06/06
    62 - fixed silly bug in load_filelist() which stopped
    63   funny German filenames from being handled properly
    64 
    65 05/19
    66 - misc clean-up (Steve Hindle)
    67 
    68 05/04
    69 - added Herman Kuster's multi-level bkp patch
    70 
    71 04/26
    72 - maximum max_set_size_for_a_file = maxsetsizeK*2
    73 - maximum is also 32MB
    74 
    75 04/24
    76 - added lots of assert()'s and log_OS_error()'s
    77 
    78 04/22
    79 - added lots of asserts() and log_OS_errors()'s
    80 
    81 04/07
    82 - cleaned up code a bit
    83 
    84 04/04
    85 - max_sane_size_for_a_file = maxsetsizeK*2 (was *8)
    86 
    87 01/02/2003
    88 - tell mondo-makefilelist that it's a custom catalog (if it is)
    89 
    90 10/01 - 10/31/2002
    91 - don't make large .bz2 or .tbz files into biggiefiles
    92 - max_sane_size_for_a_file = maxsetsizeK*8, or 64MB
    93   ...whichever is smaller
    94 
    95 08/01 - 08/31
    96 - if last filelist is <=2 bytes long then delete it
    97 - max_sane_size_for_a_file = maxsetsizeK
    98   (was SLICESIZE*4 or something)
    99 - cleaned up some log_it() calls
    100 
    101 07/26
    102 - started
     1/* $Id$
     2
     3for subroutines which manipulate the filelist
     4
    1035*/
    1046
     
    13537
    13638
    137 extern ssize_t getline(char **lineptr, size_t *n, FILE *stream);
    138 
    139 
    140 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    141     char*include_paths, char*excp, int differential, char *userdef_filelist);
     39int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     40                       char *include_paths, char *excp, int differential,
     41                       char *userdef_filelist);
    14242
    14343
    14444/*@unused@*/
    145 //static char cvsid[] = "$Id: libmondo-filelist.c,v 1.6 2004/06/10 15:29:12 hugo Exp $";
     45//static char cvsid[] = "$Id$";
    14646
    14747/**
     
    15656 * @ingroup globalGroup
    15757 */
    158 long g_noof_sets=0;
     58long g_noof_sets = 0;
    15959
    16060extern bool g_text_mode;
     
    18080 * @see chop_filelist
    18181 */
    182 int
    183 call_filelist_chopper (struct s_bkpinfo *bkpinfo)
    184 {
    185     /*@ buffers ************************/
    186   char *dev;
    187   char *filelist;
    188   char *tempfile;
    189   char *cksumlist;
    190   char *tmp;
    191   long noof_sets;
    192 
    193     /*@ pointers ***********************/
    194   char *ptr;
    195   FILE *fout;
    196 
    197     /*@ int ****************************/
    198   int i, retval=0;
    199 
    200   malloc_string(dev);
    201   malloc_string(filelist);
    202   malloc_string(tempfile);
    203   malloc_string(cksumlist);
    204   malloc_string(tmp);
    205   mvaddstr_and_log_it (g_currentY, 0, "Dividing filelist into sets");
    206 
    207   log_to_screen ("Dividing filelist into sets. Please wait.");
    208   i=0;
     82int call_filelist_chopper(struct s_bkpinfo *bkpinfo)
     83{
     84    /*@ buffers *********************** */
     85    char *dev;
     86    char *filelist;
     87    char *tempfile;
     88    char *cksumlist;
     89    char *tmp;
     90    long noof_sets;
     91
     92    /*@ pointers ********************** */
     93    char *ptr;
     94    FILE *fout;
     95
     96    /*@ int *************************** */
     97    int i, retval = 0;
     98
     99    malloc_string(dev);
     100    malloc_string(filelist);
     101    malloc_string(tempfile);
     102    malloc_string(cksumlist);
     103    malloc_string(tmp);
     104    mvaddstr_and_log_it(g_currentY, 0, "Dividing filelist into sets");
     105
     106    log_to_screen("Dividing filelist into sets. Please wait.");
     107    i = 0;
    209108/*
    210109  if (find_home_of_exe("getfattr"))
     
    215114    { i=0; log_to_screen ("This will take more time. Please be patient."); }
    216115*/
    217   sprintf (filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
    218   sprintf (cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
    219   if (!does_file_exist(filelist)) { log_it("filelist %s not found", filelist); fatal_error("call_filelist_chopper() -- filelist not found!"); }
    220 
    221   noof_sets = chop_filelist (filelist, bkpinfo->tmpdir, bkpinfo->optimal_set_size);
    222   estimate_noof_media_required (bkpinfo, noof_sets); // for cosmetic purposes
    223 
    224   sprintf (tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
    225   if (!(fout = fopen (tempfile, "a")))
    226     {
    227       log_OS_error("Cannot append to biggielist");
    228       retval++;
    229       goto end_of_func;
    230     }
    231   log_it (bkpinfo->image_devs);
    232 
    233   ptr = bkpinfo->image_devs;
    234 
    235   while (ptr && *ptr)
    236     {
    237       strcpy (dev, ptr);
    238       log_it ("Examining imagedev %s", dev);
    239       for (i = 0; i < (int) strlen (dev) && dev[i] != ' '; i++);
    240       dev[i] = '\0';
    241       if (!strlen (dev))
    242     {
    243       continue;
    244     }
    245       fprintf (fout, "%s\n", dev);
    246       log_it ("Adding '%s' to biggielist", dev);
    247       if ((ptr = strchr (ptr, ' ')))
    248     {
    249       ptr++;
    250     }
    251     }
    252   paranoid_fclose(fout);
    253   mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    254 
    255 end_of_func:
    256   paranoid_free(filelist);
    257   paranoid_free(tempfile);
    258   paranoid_free(cksumlist);
    259   paranoid_free(dev);
    260   paranoid_free(tmp);
    261   return(retval);
    262 }
    263 
    264 
    265 
    266 int sort_file(char*orig_fname)
    267 {
    268   char *tmp_fname;
    269   char *command;
    270   int retval=0;
    271 
    272   log_msg(1, "Sorting file %s", orig_fname);
    273   malloc_string(tmp_fname);
    274   malloc_string(command);
    275   sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int)(random()%32768), (int)(random()%32768), (int)(random()%32768));
    276  
    277   if (!does_file_exist(orig_fname))
    278     { return(0); } // no sense in trying to sort an empty file
    279 
    280   sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    281   retval = system(command);
    282   if (retval)
    283     {
    284       log_msg(2, "Failed to sort %s - oh dear", orig_fname);
    285     }
    286   else
    287     {
    288       log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now", orig_fname, tmp_fname, orig_fname);
    289       sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
    290       retval += run_program_and_log_output(command, 2);
    291       if (retval)
    292         {
    293       log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname, orig_fname);
    294     }
    295       else
    296         {
    297       log_msg(2, "%s was sorted OK.", orig_fname);
    298     }
    299     }
    300   paranoid_free(tmp_fname);
    301   paranoid_free(command);
    302   log_msg(1, "Finished sorting file %s", orig_fname);
    303   return(retval);
     116    sprintf(filelist, "%s/archives/filelist.full", bkpinfo->scratchdir);
     117    sprintf(cksumlist, "%s/cklist.full", bkpinfo->tmpdir);
     118    if (!does_file_exist(filelist)) {
     119        log_it("filelist %s not found", filelist);
     120        fatal_error("call_filelist_chopper() -- filelist not found!");
     121    }
     122
     123    noof_sets =
     124        chop_filelist(filelist, bkpinfo->tmpdir,
     125                      bkpinfo->optimal_set_size);
     126    estimate_noof_media_required(bkpinfo, noof_sets);   // for cosmetic purposes
     127
     128    sprintf(tempfile, "%s/biggielist.txt", bkpinfo->tmpdir);
     129    if (!(fout = fopen(tempfile, "a"))) {
     130        log_OS_error("Cannot append to biggielist");
     131        retval++;
     132        goto end_of_func;
     133    }
     134    log_it(bkpinfo->image_devs);
     135
     136    ptr = bkpinfo->image_devs;
     137
     138    while (ptr && *ptr) {
     139        strcpy(dev, ptr);
     140        log_it("Examining imagedev %s", dev);
     141        for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     142        dev[i] = '\0';
     143        if (!strlen(dev)) {
     144            continue;
     145        }
     146        fprintf(fout, "%s\n", dev);
     147        log_it("Adding '%s' to biggielist", dev);
     148        if ((ptr = strchr(ptr, ' '))) {
     149            ptr++;
     150        }
     151    }
     152    paranoid_fclose(fout);
     153    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     154
     155  end_of_func:
     156    paranoid_free(filelist);
     157    paranoid_free(tempfile);
     158    paranoid_free(cksumlist);
     159    paranoid_free(dev);
     160    paranoid_free(tmp);
     161    return (retval);
     162}
     163
     164
     165
     166int sort_file(char *orig_fname)
     167{
     168    char *tmp_fname;
     169    char *command;
     170    int retval = 0;
     171
     172    log_msg(1, "Sorting file %s", orig_fname);
     173    malloc_string(tmp_fname);
     174    malloc_string(command);
     175    sprintf(tmp_fname, "/tmp/sort.%d.%d.%d", (int) (random() % 32768),
     176            (int) (random() % 32768), (int) (random() % 32768));
     177
     178    if (!does_file_exist(orig_fname)) {
     179        return (0);
     180    }                           // no sense in trying to sort an empty file
     181
     182    sprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname,
     183            MONDO_LOGFILE);
     184    retval = system(command);
     185    if (retval) {
     186        log_msg(2, "Failed to sort %s - oh dear", orig_fname);
     187    } else {
     188        log_msg(2, "Sorted %s --> %s OK. Copying it back to %s now",
     189                orig_fname, tmp_fname, orig_fname);
     190        sprintf(command, "mv -f %s %s", tmp_fname, orig_fname);
     191        retval += run_program_and_log_output(command, 2);
     192        if (retval) {
     193            log_msg(2, "Failed to copy %s back to %s - oh dear", tmp_fname,
     194                    orig_fname);
     195        } else {
     196            log_msg(2, "%s was sorted OK.", orig_fname);
     197        }
     198    }
     199    paranoid_free(tmp_fname);
     200    paranoid_free(command);
     201    log_msg(1, "Finished sorting file %s", orig_fname);
     202    return (retval);
    304203}
    305204
     
    318217 * @return number of errors encountered (0 for success).
    319218 */
    320 int
    321 chop_filelist (char *filelist, char *outdir, long maxsetsizeK)
     219int chop_filelist(char *filelist, char *outdir, long maxsetsizeK)
    322220{
    323221/*@ long ****************************************/
    324   long lino = 0;
    325   long max_sane_size_for_a_file;
    326   long curr_set_size;
    327   long noof_lines;
    328   long siz;
    329 
    330     /*@ int *****************************************/
    331   int i;
    332   long curr_set_no;
    333 
    334     /*@ buffers **************************************/
    335   char *outfname;
    336   char *biggie_fname;
    337   char *incoming;
    338   char *tmp;
    339   char *acl_fname;
    340   char *xattr_fname;
    341 
    342     /*@ pointers ************************************/
    343   FILE *fin;
    344   FILE *fout;
    345   FILE *fbig;
    346 
    347     /*@ structures **********************************/
    348   struct stat buf;
    349   int err = 0;
    350 
    351   malloc_string(outfname);
    352   malloc_string(biggie_fname);
    353   incoming = malloc(MAX_STR_LEN*2);
    354   malloc_string(tmp);
    355   malloc_string(acl_fname);
    356   malloc_string(xattr_fname);
    357  
    358   assert_string_is_neither_NULL_nor_zerolength(filelist);
    359   assert_string_is_neither_NULL_nor_zerolength(outdir);
    360   assert( maxsetsizeK > 0);
    361 
    362   max_sane_size_for_a_file = 32L*1024L;
     222    long lino = 0;
     223    long max_sane_size_for_a_file;
     224    long curr_set_size;
     225    long noof_lines;
     226    long siz;
     227
     228    /*@ int **************************************** */
     229    int i;
     230    long curr_set_no;
     231
     232    /*@ buffers ************************************* */
     233    char *outfname;
     234    char *biggie_fname;
     235    char *incoming;
     236    char *tmp;
     237    char *acl_fname;
     238    char *xattr_fname;
     239
     240    /*@ pointers *********************************** */
     241    FILE *fin;
     242    FILE *fout;
     243    FILE *fbig;
     244
     245    /*@ structures ********************************* */
     246    struct stat buf;
     247    int err = 0;
     248
     249    malloc_string(outfname);
     250    malloc_string(biggie_fname);
     251    incoming = malloc(MAX_STR_LEN * 2);
     252    malloc_string(tmp);
     253    malloc_string(acl_fname);
     254    malloc_string(xattr_fname);
     255
     256    assert_string_is_neither_NULL_nor_zerolength(filelist);
     257    assert_string_is_neither_NULL_nor_zerolength(outdir);
     258    assert(maxsetsizeK > 0);
     259
     260    max_sane_size_for_a_file = 32L * 1024L;
    363261// max_sane_size_for_a_file = maxsetsizeK*2;
    364262//  if (max_sane_size_for_a_file > 32*1024)
    365263//    { max_sane_size_for_a_file = 32*1024; }
    366  
    367   log_it("filelist=%s;", filelist);
    368   open_evalcall_form ("Dividing filelist into sets");
    369   noof_lines = count_lines_in_file (filelist);
    370   if (!(fin = fopen (filelist, "r"))) { log_OS_error("Cannot openin filelist"); return(0); }
    371   curr_set_no = 0;
    372   curr_set_size = 0;
    373   sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    374   sprintf (biggie_fname, "%s/biggielist.txt", outdir);
    375   log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
    376   if (!(fbig = fopen (biggie_fname, "w"))) { log_OS_error("Cannot openout biggie_fname"); err++; goto end_of_func; }
    377   if (!(fout = fopen (outfname, "w"))) { log_OS_error("Cannot openout outfname"); err++; goto end_of_func; }
    378   (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    379   while (!feof (fin))
    380     {
    381       lino++;
    382       i = strlen (incoming) - 1;
    383       if (i < 0)
    384     {
    385       i = 0;
    386     }
    387       if (i > MAX_STR_LEN-1)
    388         {
    389       incoming[MAX_STR_LEN-30] = '\0';
    390       log_msg(1, "Warning - truncating file %s's name", incoming);
    391       err++;
    392     }
    393       if (incoming[i] < 32)
    394     {
    395       incoming[i] = '\0';
    396     }
    397       if (!strncmp (incoming, "/dev/", 5))
    398     {
    399       siz = 1;
    400     }
    401       else if (lstat (incoming, &buf) != 0)
    402     {
    403       siz = 0;
    404     }
    405       else
    406     {
    407       siz = (long) (buf.st_size >> 10);
    408     }
    409       if (siz > max_sane_size_for_a_file)
     264
     265    log_it("filelist=%s;", filelist);
     266    open_evalcall_form("Dividing filelist into sets");
     267    noof_lines = count_lines_in_file(filelist);
     268    if (!(fin = fopen(filelist, "r"))) {
     269        log_OS_error("Cannot openin filelist");
     270        return (0);
     271    }
     272    curr_set_no = 0;
     273    curr_set_size = 0;
     274    sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     275    sprintf(biggie_fname, "%s/biggielist.txt", outdir);
     276    log_it("outfname=%s; biggie_fname=%s", outfname, biggie_fname);
     277    if (!(fbig = fopen(biggie_fname, "w"))) {
     278        log_OS_error("Cannot openout biggie_fname");
     279        err++;
     280        goto end_of_func;
     281    }
     282    if (!(fout = fopen(outfname, "w"))) {
     283        log_OS_error("Cannot openout outfname");
     284        err++;
     285        goto end_of_func;
     286    }
     287    (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     288    while (!feof(fin)) {
     289        lino++;
     290        i = strlen(incoming) - 1;
     291        if (i < 0) {
     292            i = 0;
     293        }
     294        if (i > MAX_STR_LEN - 1) {
     295            incoming[MAX_STR_LEN - 30] = '\0';
     296            log_msg(1, "Warning - truncating file %s's name", incoming);
     297            err++;
     298        }
     299        if (incoming[i] < 32) {
     300            incoming[i] = '\0';
     301        }
     302        if (!strncmp(incoming, "/dev/", 5)) {
     303            siz = 1;
     304        } else if (lstat(incoming, &buf) != 0) {
     305            siz = 0;
     306        } else {
     307            siz = (long) (buf.st_size >> 10);
     308        }
     309        if (siz > max_sane_size_for_a_file)
    410310// && strcmp(incoming+strlen(incoming)-4, ".bz2") && strcmp(incoming+strlen(incoming)-4, ".tbz"))
    411     {
    412       fprintf (fbig, "%s\n", incoming);
    413     }
    414       else
    415     {
    416       curr_set_size += siz;
    417       fprintf (fout, "%s\n", incoming);
    418       if (curr_set_size > maxsetsizeK)
    419         {
    420           paranoid_fclose(fout);
    421           sort_file(outfname);
    422           curr_set_no++;
    423           curr_set_size = 0;
    424           sprintf (outfname, "%s/filelist.%ld", outdir, curr_set_no);
    425           if (!(fout = fopen (outfname, "w"))) { log_OS_error("Unable to openout outfname"); err++; goto end_of_func; }
    426           sprintf (tmp, "Fileset #%ld chopped ", curr_set_no - 1);
    427           update_evalcall_form ((int) (lino * 100 / noof_lines));
    428           /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
    429         }
    430     }
    431       (void) fgets (incoming, MAX_STR_LEN*2-1, fin);
    432     }
    433   paranoid_fclose (fin);
    434   paranoid_fclose (fout);
    435   paranoid_fclose (fbig);
    436 
    437   if (length_of_file(outfname) <= 2)
    438     {
    439       unlink(outfname);
    440       g_noof_sets --;
    441     }
    442   g_noof_sets = curr_set_no;
    443   sort_file(outfname);
    444   sort_file(biggie_fname);
    445   sprintf (outfname, "%s/LAST-FILELIST-NUMBER", outdir);
    446   sprintf (tmp, "%ld", curr_set_no);
    447   if (write_one_liner_data_file (outfname, tmp))
    448       { log_OS_error("Unable to echo write one-liner to LAST-FILELIST-NUMBER"); err = 1;}
    449   if (curr_set_no == 0)
    450     {
    451       sprintf (tmp, "Only one fileset. Fine.");
    452     }
    453   else
    454     {
    455       sprintf (tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    456     }
    457   log_msg(1, tmp);
    458   close_evalcall_form ();
    459   /* This is to work around an obscure bug in Newt; open a form, close it,
    460      carry on... I don't know why it works but it works. If you don't do this
    461      then update_progress_form() won't show the "time taken / time remaining"
    462      line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
     311        {
     312            fprintf(fbig, "%s\n", incoming);
     313        } else {
     314            curr_set_size += siz;
     315            fprintf(fout, "%s\n", incoming);
     316            if (curr_set_size > maxsetsizeK) {
     317                paranoid_fclose(fout);
     318                sort_file(outfname);
     319                curr_set_no++;
     320                curr_set_size = 0;
     321                sprintf(outfname, "%s/filelist.%ld", outdir, curr_set_no);
     322                if (!(fout = fopen(outfname, "w"))) {
     323                    log_OS_error("Unable to openout outfname");
     324                    err++;
     325                    goto end_of_func;
     326                }
     327                sprintf(tmp, "Fileset #%ld chopped ", curr_set_no - 1);
     328                update_evalcall_form((int) (lino * 100 / noof_lines));
     329                /*              if (!g_text_mode) {newtDrawRootText(0,22,tmp);newtRefresh();} else {log_it(tmp);} */
     330            }
     331        }
     332        (void) fgets(incoming, MAX_STR_LEN * 2 - 1, fin);
     333    }
     334    paranoid_fclose(fin);
     335    paranoid_fclose(fout);
     336    paranoid_fclose(fbig);
     337
     338    if (length_of_file(outfname) <= 2) {
     339        unlink(outfname);
     340        g_noof_sets--;
     341    }
     342    g_noof_sets = curr_set_no;
     343    sort_file(outfname);
     344    sort_file(biggie_fname);
     345    sprintf(outfname, "%s/LAST-FILELIST-NUMBER", outdir);
     346    sprintf(tmp, "%ld", curr_set_no);
     347    if (write_one_liner_data_file(outfname, tmp)) {
     348        log_OS_error
     349            ("Unable to echo write one-liner to LAST-FILELIST-NUMBER");
     350        err = 1;
     351    }
     352    if (curr_set_no == 0) {
     353        sprintf(tmp, "Only one fileset. Fine.");
     354    } else {
     355        sprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
     356    }
     357    log_msg(1, tmp);
     358    close_evalcall_form();
     359    /* This is to work around an obscure bug in Newt; open a form, close it,
     360       carry on... I don't know why it works but it works. If you don't do this
     361       then update_progress_form() won't show the "time taken / time remaining"
     362       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    463363#ifndef _XWIN
    464   if (!g_text_mode)
    465     {
    466       open_progress_form ("", "", "", "", 100);
    467       newtPopHelpLine ();
    468       newtFormDestroy (g_progressForm);
    469       newtPopWindow ();
    470     }
     364    if (!g_text_mode) {
     365        open_progress_form("", "", "", "", 100);
     366        newtPopHelpLine();
     367        newtFormDestroy(g_progressForm);
     368        newtPopWindow();
     369    }
    471370#endif
    472 end_of_func:
    473   paranoid_free(outfname);
    474   paranoid_free(biggie_fname);
    475   paranoid_free(incoming);
    476   paranoid_free(tmp);
    477   paranoid_free(acl_fname);
    478   paranoid_free(xattr_fname);
    479   return (err ? 0 : curr_set_no + 1);
     371  end_of_func:
     372    paranoid_free(outfname);
     373    paranoid_free(biggie_fname);
     374    paranoid_free(incoming);
     375    paranoid_free(tmp);
     376    paranoid_free(acl_fname);
     377    paranoid_free(xattr_fname);
     378    return (err ? 0 : curr_set_no + 1);
    480379}
    481380
     
    489388 * @param filelist The filelist to free.
    490389 */
    491 void
    492 free_filelist (struct s_node *filelist)
    493 {
    494     /*@ int's ********************************************************/
    495   static int depth = 0;
    496   int percentage;
    497 
    498     /*@ long's *******************************************************/
    499   static long i = 0;
    500 
    501     /*@ end vars *****************************************************/
    502 
    503   assert(filelist!=NULL);
    504   if (depth == 0)
    505     {
    506       open_evalcall_form ("Freeing memory");
    507       log_to_screen ("Freeing memory formerly occupied by filelist");
    508     }
    509   depth++;
    510 
    511   if (filelist->ch == '\0')
    512     {
    513       if (!(i++ % 1111))
    514     {
    515       percentage = (int) (i * 100 / g_original_noof_lines_in_filelist);
    516       update_evalcall_form (percentage);
    517 
    518     }
    519     }
    520 
    521   if (filelist->right)
    522     {
    523       free_filelist (filelist->right);
    524       filelist->right = NULL;
    525     }
    526   if (filelist->down)
    527     {
     390void free_filelist(struct s_node *filelist)
     391{
     392    /*@ int's ******************************************************* */
     393    static int depth = 0;
     394    int percentage;
     395
     396    /*@ long's ****************************************************** */
     397    static long i = 0;
     398
     399    /*@ end vars **************************************************** */
     400
     401    assert(filelist != NULL);
     402    if (depth == 0) {
     403        open_evalcall_form("Freeing memory");
     404        log_to_screen("Freeing memory formerly occupied by filelist");
     405    }
     406    depth++;
     407
     408    if (filelist->ch == '\0') {
     409        if (!(i++ % 1111)) {
     410            percentage =
     411                (int) (i * 100 / g_original_noof_lines_in_filelist);
     412            update_evalcall_form(percentage);
     413
     414        }
     415    }
     416
     417    if (filelist->right) {
     418        free_filelist(filelist->right);
     419        filelist->right = NULL;
     420    }
     421    if (filelist->down) {
    528422/*      if (!(i++ %39999)) { update_evalcall_form(0); } */
    529       free_filelist (filelist->down);
    530       filelist->down = NULL;
    531     }
    532   filelist->ch = '\0';
    533   paranoid_free (filelist);
    534   depth--;
    535   if (depth == 0)
    536     {
    537       close_evalcall_form ();
    538       log_it ("Finished freeing memory");
    539     }
    540 }
    541 
    542 
    543 int call_exe_and_pipe_output_to_fd(char*syscall, FILE*pout)
    544 {
    545   FILE *pattr;
    546   char *tmp;
    547       pattr = popen(syscall, "r");
    548       if (!pattr)
    549         {
    550       log_msg(1, "Failed to open fattr() %s", syscall);
    551       return(1);
    552         }
    553       if (feof(pattr))
    554         {
    555       log_msg(1, "Failed to call fattr() %s", syscall);
    556       paranoid_pclose(pattr);
    557       return(2); 
    558     }
    559       malloc_string(tmp);
    560       for (fgets (tmp, MAX_STR_LEN, pattr); !feof (pattr);
    561        fgets (tmp, MAX_STR_LEN, pattr))
    562         {
    563       fputs(tmp, pout);
    564     }
    565       paranoid_pclose(pattr);
    566       paranoid_free(tmp);
    567       return(0);
    568 }
    569 
    570 
    571 
    572 int gen_aux_list(char*filelist, char*syscall_sprintf, char*auxlist_fname)
    573 {
    574   FILE*fin;
    575   FILE*pout;
    576   char*pout_command;
    577   char*syscall;
    578   char*file_to_analyze;
    579   int i;
    580  
    581   if (!(fin=fopen(filelist, "r")))
    582     {
    583       log_msg(1, "Cannot openin filelist %s", filelist);
    584       return(1);
    585     }
    586   malloc_string(pout_command);
    587   sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
    588   if (!(pout=popen(pout_command, "w")))
    589     {
    590       log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
    591       fclose(fin);
    592       paranoid_free(pout_command);
    593       return(4);
    594     }
    595   malloc_string(syscall);
    596   malloc_string(file_to_analyze);
    597   for (fgets (file_to_analyze, MAX_STR_LEN, fin); !feof (fin);
    598        fgets (file_to_analyze, MAX_STR_LEN, fin))
    599     {
    600       i = strlen(file_to_analyze);
    601       if (i>0 && file_to_analyze[i-1]<32) { file_to_analyze[i-1]='\0'; }
    602       log_msg(8, "Analyzing %s", file_to_analyze);
    603       sprintf(syscall, syscall_sprintf, file_to_analyze);
    604       strcat(syscall, " 2>> /dev/null"); // " MONDO_LOGFILE);
    605       call_exe_and_pipe_output_to_fd(syscall, pout);
    606     }
    607   paranoid_fclose(fin);
    608   paranoid_pclose(pout);
    609   paranoid_free(file_to_analyze);
    610   paranoid_free(syscall);
    611   paranoid_free(pout_command);
    612   return(0);
    613 }
    614 
    615 
    616 int get_acl_list(char*filelist, char*facl_fname)
    617 {
    618   char*command;
    619   int retval=0;
    620  
    621   malloc_string(command);
    622   sprintf(command, "touch %s", facl_fname);
    623   run_program_and_log_output(command, 8);
    624   if (find_home_of_exe("getfacl"))
    625     {
     423        free_filelist(filelist->down);
     424        filelist->down = NULL;
     425    }
     426    filelist->ch = '\0';
     427    paranoid_free(filelist);
     428    depth--;
     429    if (depth == 0) {
     430        close_evalcall_form();
     431        log_it("Finished freeing memory");
     432    }
     433}
     434
     435
     436int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
     437{
     438    FILE *pattr;
     439    char *tmp;
     440    pattr = popen(syscall, "r");
     441    if (!pattr) {
     442        log_msg(1, "Failed to open fattr() %s", syscall);
     443        return (1);
     444    }
     445    if (feof(pattr)) {
     446        log_msg(1, "Failed to call fattr() %s", syscall);
     447        paranoid_pclose(pattr);
     448        return (2);
     449    }
     450    malloc_string(tmp);
     451    for (fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr);
     452         fgets(tmp, MAX_STR_LEN, pattr)) {
     453        fputs(tmp, pout);
     454    }
     455    paranoid_pclose(pattr);
     456    paranoid_free(tmp);
     457    return (0);
     458}
     459
     460
     461
     462int gen_aux_list(char *filelist, char *syscall_sprintf,
     463                 char *auxlist_fname)
     464{
     465    FILE *fin;
     466    FILE *pout;
     467    char *pout_command;
     468    char *syscall;
     469    char *file_to_analyze;
     470    int i;
     471
     472    if (!(fin = fopen(filelist, "r"))) {
     473        log_msg(1, "Cannot openin filelist %s", filelist);
     474        return (1);
     475    }
     476    malloc_string(pout_command);
     477    sprintf(pout_command, "gzip -c1 > %s", auxlist_fname);
     478    if (!(pout = popen(pout_command, "w"))) {
     479        log_msg(1, "Cannot openout auxlist_fname %s", auxlist_fname);
     480        fclose(fin);
     481        paranoid_free(pout_command);
     482        return (4);
     483    }
     484    malloc_string(syscall);
     485    malloc_string(file_to_analyze);
     486    for (fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin);
     487         fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     488        i = strlen(file_to_analyze);
     489        if (i > 0 && file_to_analyze[i - 1] < 32) {
     490            file_to_analyze[i - 1] = '\0';
     491        }
     492        log_msg(8, "Analyzing %s", file_to_analyze);
     493        sprintf(syscall, syscall_sprintf, file_to_analyze);
     494        strcat(syscall, " 2>> /dev/null");  // " MONDO_LOGFILE);
     495        call_exe_and_pipe_output_to_fd(syscall, pout);
     496    }
     497    paranoid_fclose(fin);
     498    paranoid_pclose(pout);
     499    paranoid_free(file_to_analyze);
     500    paranoid_free(syscall);
     501    paranoid_free(pout_command);
     502    return (0);
     503}
     504
     505
     506int get_acl_list(char *filelist, char *facl_fname)
     507{
     508    char *command;
     509    int retval = 0;
     510
     511    malloc_string(command);
     512    sprintf(command, "touch %s", facl_fname);
     513    run_program_and_log_output(command, 8);
     514    if (find_home_of_exe("getfacl")) {
    626515//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    627       sprintf(command, "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s", filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
    628       iamhere(command);
    629       retval = system(command);
    630     }
    631   paranoid_free(command);
    632   return(retval);
    633 }
    634 
    635 
    636 int get_fattr_list(char*filelist, char*fattr_fname)
    637 {
    638   char *command;
    639   int retval=0;
    640  
    641   malloc_string(command);
    642   sprintf(command, "touch %s", fattr_fname);
    643   run_program_and_log_output(command, 8);
    644   if (find_home_of_exe("getfattr"))
    645     {
     516        sprintf(command,
     517                "cat %s | getfacl --all-effective -P - 2>> %s | gzip -c1 > %s 2>> %s",
     518                filelist, MONDO_LOGFILE, facl_fname, MONDO_LOGFILE);
     519        iamhere(command);
     520        retval = system(command);
     521    }
     522    paranoid_free(command);
     523    return (retval);
     524}
     525
     526
     527int get_fattr_list(char *filelist, char *fattr_fname)
     528{
     529    char *command;
     530    int retval = 0;
     531
     532    malloc_string(command);
     533    sprintf(command, "touch %s", fattr_fname);
     534    run_program_and_log_output(command, 8);
     535    if (find_home_of_exe("getfattr")) {
    646536//      sort_file(filelist); // FIXME - filelist chopper sorts, so this isn't necessary
    647       retval = gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"", fattr_fname);
    648     }
    649   paranoid_free(command);
    650   return(retval);
     537        retval =
     538            gen_aux_list(filelist, "getfattr --en=hex -P -d \"%s\"",
     539                         fattr_fname);
     540    }
     541    paranoid_free(command);
     542    return (retval);
    651543}
    652544
     
    674566
    675567
    676 int set_EXAT_list(char*orig_msklist, char*original_exat_fname, char*executable)
    677 {
    678   const int my_depth=8;
    679   char*command, *syscall_pin, *syscall_pout, *incoming;
    680   char*current_subset_file, *current_master_file, *masklist;
    681   int retval=0;
    682   int i;
    683   char*p,*q;
    684   FILE*pin, *pout, *faclin;
    685 
    686   malloc_string(command);
    687   log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable); 
    688   if (!orig_msklist || !orig_msklist[0] || !does_file_exist(orig_msklist))
    689     {
    690       log_msg(1, "No masklist provided. I shall therefore set ALL attributes.");
    691       sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s", original_exat_fname, executable, MONDO_LOGFILE);
    692       log_msg(1, "command = %s", command);
    693       retval = system(command);
    694       paranoid_free(command);
    695       log_msg(1, "Returning w/ retval=%d", retval);
    696       return(retval);
    697     }
    698   if (length_of_file(original_exat_fname) <= 0)
    699     {
    700       log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname);
    701       paranoid_free(command);
    702       return(0);
    703     }
    704   malloc_string(incoming);
    705   malloc_string(masklist);
    706   malloc_string(current_subset_file);
    707   malloc_string(current_master_file);
    708   malloc_string(syscall_pin);
    709   malloc_string(syscall_pout);
    710   sprintf(masklist, "/tmp/%d.%d.mask", (int)(random()%32768), (int)(random()%32768));
    711   sprintf(command, "cp -f %s %s", orig_msklist, masklist);
    712   run_program_and_log_output(command, 1);
    713   sort_file(masklist);
    714   current_subset_file[0] = current_master_file[0] = '\0';
    715   sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
    716   sprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
    717 
    718   log_msg(1, "syscall_pin = %s", syscall_pin);
    719   log_msg(1, "syscall_pout = %s", syscall_pout);
    720   pout = popen(syscall_pout, "w");
    721   if (!pout)
    722     { iamhere("Unable to openout to syscall_pout"); return(1); }
    723   pin = popen(syscall_pin, "r");
    724   if (!pin)
    725     { pclose(pout); iamhere("Unable to openin from syscall"); return(1); }
    726   faclin = fopen(masklist, "r");
    727   if (!faclin)
    728     { pclose(pin); pclose(pout); iamhere("Unable to openin masklist"); return(1); }
    729 
     568int set_EXAT_list(char *orig_msklist, char *original_exat_fname,
     569                  char *executable)
     570{
     571    const int my_depth = 8;
     572    char *command, *syscall_pin, *syscall_pout, *incoming;
     573    char *current_subset_file, *current_master_file, *masklist;
     574    int retval = 0;
     575    int i;
     576    char *p, *q;
     577    FILE *pin, *pout, *faclin;
     578
     579    malloc_string(command);
     580    log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
     581            original_exat_fname, executable);
     582    if (!orig_msklist || !orig_msklist[0]
     583        || !does_file_exist(orig_msklist)) {
     584        log_msg(1,
     585                "No masklist provided. I shall therefore set ALL attributes.");
     586        sprintf(command, "cat %s | gzip -dc | %s --restore - 2>> %s",
     587                original_exat_fname, executable, MONDO_LOGFILE);
     588        log_msg(1, "command = %s", command);
     589        retval = system(command);
     590        paranoid_free(command);
     591        log_msg(1, "Returning w/ retval=%d", retval);
     592        return (retval);
     593    }
     594    if (length_of_file(original_exat_fname) <= 0) {
     595        log_msg(1,
     596                "original_exat_fname %s is empty or missing, so no need to set EXAT list",
     597                original_exat_fname);
     598        paranoid_free(command);
     599        return (0);
     600    }
     601    malloc_string(incoming);
     602    malloc_string(masklist);
     603    malloc_string(current_subset_file);
     604    malloc_string(current_master_file);
     605    malloc_string(syscall_pin);
     606    malloc_string(syscall_pout);
     607    sprintf(masklist, "/tmp/%d.%d.mask", (int) (random() % 32768),
     608            (int) (random() % 32768));
     609    sprintf(command, "cp -f %s %s", orig_msklist, masklist);
     610    run_program_and_log_output(command, 1);
     611    sort_file(masklist);
     612    current_subset_file[0] = current_master_file[0] = '\0';
     613    sprintf(syscall_pin, "cat %s | gzip -dc", original_exat_fname);
     614    sprintf(syscall_pout, "%s --restore - 2>> %s", executable,
     615            MONDO_LOGFILE);
     616
     617    log_msg(1, "syscall_pin = %s", syscall_pin);
     618    log_msg(1, "syscall_pout = %s", syscall_pout);
     619    pout = popen(syscall_pout, "w");
     620    if (!pout) {
     621        iamhere("Unable to openout to syscall_pout");
     622        return (1);
     623    }
     624    pin = popen(syscall_pin, "r");
     625    if (!pin) {
     626        pclose(pout);
     627        iamhere("Unable to openin from syscall");
     628        return (1);
     629    }
     630    faclin = fopen(masklist, "r");
     631    if (!faclin) {
     632        pclose(pin);
     633        pclose(pout);
     634        iamhere("Unable to openin masklist");
     635        return (1);
     636    }
    730637//  printf("Hi there. Starting the loop\n");
    731  
    732   fgets(current_subset_file, MAX_STR_LEN, faclin);
    733   fgets(incoming, MAX_STR_LEN, pin);
    734   while(!feof(pin) && !feof(faclin))
    735     {
     638
     639    fgets(current_subset_file, MAX_STR_LEN, faclin);
     640    fgets(incoming, MAX_STR_LEN, pin);
     641    while (!feof(pin) && !feof(faclin)) {
    736642//      printf("incoming = %s", incoming);
    737      
    738       strcpy(current_master_file, incoming+8);
    739      
    740       p = current_subset_file;
    741       if (*p=='/') {p++;}
    742       i = strlen(p);
    743       if (i>0 && p[i-1]<32) { p[i-1] = '\0'; }
    744 
    745            
    746       q = current_master_file;
    747       if (*q=='/') {q++;}
    748       i = strlen(q);
    749       if (i>0 && q[i-1]<32) { q[i-1] = '\0'; }
    750 
    751       i = strcmp(p,q);
    752       log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
    753      
     643
     644        strcpy(current_master_file, incoming + 8);
     645
     646        p = current_subset_file;
     647        if (*p == '/') {
     648            p++;
     649        }
     650        i = strlen(p);
     651        if (i > 0 && p[i - 1] < 32) {
     652            p[i - 1] = '\0';
     653        }
     654
     655
     656        q = current_master_file;
     657        if (*q == '/') {
     658            q++;
     659        }
     660        i = strlen(q);
     661        if (i > 0 && q[i - 1] < 32) {
     662            q[i - 1] = '\0';
     663        }
     664
     665        i = strcmp(p, q);
     666        log_msg(my_depth, "'%s' v '%s' --> %d\n", p, q, i);
     667
    754668//      printf("%s v %s --> %d\n", p, q, i);
    755      
    756       if (i<0)
    757         { // read another subset file in.
    758       log_msg(my_depth, "Reading next subset line in\n\n");
    759       fgets(current_subset_file, MAX_STR_LEN, faclin);
    760       continue;
    761     }
    762 
    763       if (!i) { fputs(incoming, pout); }
    764       fgets(incoming, MAX_STR_LEN, pin);
    765       if (!i) { log_msg(my_depth, "Copying master %s", q); }
    766      
     669
     670        if (i < 0) {            // read another subset file in.
     671            log_msg(my_depth, "Reading next subset line in\n\n");
     672            fgets(current_subset_file, MAX_STR_LEN, faclin);
     673            continue;
     674        }
     675
     676        if (!i) {
     677            fputs(incoming, pout);
     678        }
     679        fgets(incoming, MAX_STR_LEN, pin);
     680        if (!i) {
     681            log_msg(my_depth, "Copying master %s", q);
     682        }
    767683//      if (!i) { printf("Match --- %s\n", q); }
    768      
    769       while (!feof(pin) && strncmp(incoming, "# file: ", 8))
    770         {
    771           if (!i) {
    772      
    773 //    printf("%s", incoming);
    774      
    775       fputs(incoming, pout); }
    776           fgets(incoming, MAX_STR_LEN, pin);
    777         }
    778       if (!i) { fgets(current_subset_file, MAX_STR_LEN, faclin); }
    779     }
    780   while(!feof(pin)) { fgets (incoming, MAX_STR_LEN, pin); }
    781   fclose(faclin);
    782   pclose(pin);
    783   pclose(pout); 
    784  
     684
     685        while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
     686            if (!i) {
     687
     688//    printf("%s", incoming);
     689
     690                fputs(incoming, pout);
     691            }
     692            fgets(incoming, MAX_STR_LEN, pin);
     693        }
     694        if (!i) {
     695            fgets(current_subset_file, MAX_STR_LEN, faclin);
     696        }
     697    }
     698    while (!feof(pin)) {
     699        fgets(incoming, MAX_STR_LEN, pin);
     700    }
     701    fclose(faclin);
     702    pclose(pin);
     703    pclose(pout);
     704
    785705//  printf("OK, loop is done\n");
    786706
    787   unlink(masklist); 
    788   paranoid_free(current_subset_file);
    789   paranoid_free(current_master_file);
    790   paranoid_free(syscall_pout);
    791   paranoid_free(syscall_pin);
    792   paranoid_free(masklist);
    793   paranoid_free(incoming);
    794   paranoid_free(command);
    795   return(retval);
    796 } 
    797 
    798 
    799 int set_fattr_list(char*masklist, char*fattr_fname)
    800 {
    801   return(set_EXAT_list(masklist, fattr_fname, "setfattr"));
    802 }
    803 
    804 
    805 
    806 int set_acl_list(char*masklist, char*acl_fname)
    807 {
    808   return(set_EXAT_list(masklist, acl_fname, "setfacl"));
     707    unlink(masklist);
     708    paranoid_free(current_subset_file);
     709    paranoid_free(current_master_file);
     710    paranoid_free(syscall_pout);
     711    paranoid_free(syscall_pin);
     712    paranoid_free(masklist);
     713    paranoid_free(incoming);
     714    paranoid_free(command);
     715    return (retval);
     716}
     717
     718
     719int set_fattr_list(char *masklist, char *fattr_fname)
     720{
     721    return (set_EXAT_list(masklist, fattr_fname, "setfattr"));
     722}
     723
     724
     725
     726int set_acl_list(char *masklist, char *acl_fname)
     727{
     728    return (set_EXAT_list(masklist, acl_fname, "setfacl"));
    809729}
    810730
     
    833753 * @note This function should only be called at restore-time.
    834754 */
    835 int
    836 get_last_filelist_number (struct s_bkpinfo *bkpinfo)
    837 {
    838     /*@ buffers ******************************************************/
    839   char val_sz[MAX_STR_LEN];
    840   char cfg_fname[MAX_STR_LEN];
     755int get_last_filelist_number(struct s_bkpinfo *bkpinfo)
     756{
     757    /*@ buffers ***************************************************** */
     758    char val_sz[MAX_STR_LEN];
     759    char cfg_fname[MAX_STR_LEN];
    841760/*  char tmp[MAX_STR_LEN]; remove stan benoit apr 2002 */
    842761
    843     /*@ long *********************************************************/
    844   int val_i;
    845 
    846     /*@ end vars *****************************************************/
    847 
    848   assert(bkpinfo!=NULL);
    849 
    850   sprintf (cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
    851   read_cfg_var (cfg_fname, "last-filelist-number", val_sz);
    852   val_i = atoi (val_sz);
    853   if (val_i <= 0)
    854     {
    855       val_i = 500;
    856     }
    857   return (val_i);
     762    /*@ long ******************************************************** */
     763    int val_i;
     764
     765    /*@ end vars **************************************************** */
     766
     767    assert(bkpinfo != NULL);
     768
     769    sprintf(cfg_fname, "%s/mondo-restore.cfg", bkpinfo->tmpdir);
     770    read_cfg_var(cfg_fname, "last-filelist-number", val_sz);
     771    val_i = atoi(val_sz);
     772    if (val_i <= 0) {
     773        val_i = 500;
     774    }
     775    return (val_i);
    858776}
    859777
     
    866784 * @bug I don't understand this function. Would someone care to explain it?
    867785 */
    868 int
    869 add_string_at_node (struct s_node *startnode, char *string_to_add)
    870 {
    871 
    872 
    873     /*@ int *********************************************************/
    874   int noof_chars;
    875   int i;
    876   int res;
    877 
    878     /*@ sturctures **************************************************/
    879   struct s_node *node, *newnode;
    880 
    881     /*@ char  *******************************************************/
    882   char char_to_add;
    883 
    884     /*@ bools *******************************************************/
    885 
    886   const bool sosodef = FALSE;
    887 
    888   static int depth=0;
    889   static char original_string[MAX_STR_LEN];
    890 
    891   assert(startnode!=NULL);
    892   assert(string_to_add!=NULL);
    893 
    894   if (!depth) { strcpy(original_string, string_to_add); }
    895 
    896   noof_chars = strlen (string_to_add) + 1;  /* we include the '\0' */
     786int add_string_at_node(struct s_node *startnode, char *string_to_add)
     787{
     788
     789
     790    /*@ int ******************************************************** */
     791    int noof_chars;
     792    int i;
     793    int res;
     794
     795    /*@ sturctures ************************************************* */
     796    struct s_node *node, *newnode;
     797
     798    /*@ char  ****************************************************** */
     799    char char_to_add;
     800
     801    /*@ bools ****************************************************** */
     802
     803    const bool sosodef = FALSE;
     804
     805    static int depth = 0;
     806    static char original_string[MAX_STR_LEN];
     807
     808    assert(startnode != NULL);
     809    assert(string_to_add != NULL);
     810
     811    if (!depth) {
     812        strcpy(original_string, string_to_add);
     813    }
     814
     815    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    897816
    898817/* walk across tree if necessary */
    899   node = startnode;
    900   char_to_add = string_to_add[0];
    901   if (node->right != NULL && node->ch < char_to_add)
    902     {
    903       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_add, node->ch, (node->right)->ch);
    904       return (add_string_at_node (node->right, string_to_add));
    905     }
     818    node = startnode;
     819    char_to_add = string_to_add[0];
     820    if (node->right != NULL && node->ch < char_to_add) {
     821        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     822                char_to_add, node->ch, (node->right)->ch);
     823        return (add_string_at_node(node->right, string_to_add));
     824    }
    906825
    907826/* walk down tree if appropriate */
    908   if (node->down != NULL && node->ch == char_to_add)
    909     {
    910       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
    911       depth++;
    912       res = add_string_at_node (node->down, string_to_add + 1);
    913       depth--;
    914       return (res);
    915     }
    916 
    917   if (char_to_add == '\0' && node->ch =='\0')
    918     {
    919       log_msg(6, "%s already in tree", original_string);
    920       return(1);
    921     }
     827    if (node->down != NULL && node->ch == char_to_add) {
     828        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     829        depth++;
     830        res = add_string_at_node(node->down, string_to_add + 1);
     831        depth--;
     832        return (res);
     833    }
     834
     835    if (char_to_add == '\0' && node->ch == '\0') {
     836        log_msg(6, "%s already in tree", original_string);
     837        return (1);
     838    }
    922839
    923840/* add here */
    924   if (!(newnode = (struct s_node*)malloc (sizeof (struct s_node))))
    925             {
    926               log_to_screen ("failed to malloc");
    927               depth--;
    928               return (1);
    929             }
    930   if (char_to_add < node->ch) // add to the left of node
    931     {
    932       log_msg(7, "depth=%d char=%c --- adding (left)", depth, char_to_add);
    933       memcpy((void*)newnode, (void*)node, sizeof(struct s_node));
    934       node->right = newnode;
    935     }
    936   else if (char_to_add > node->ch) // add to the right of node
    937     {
    938       log_msg(7, "depth=%d char=%c --- adding (right)", depth, char_to_add);
    939       newnode->right = node->right; // newnode is to the RIGHT of node
    940       node->right = newnode;
    941       node = newnode;
    942     }
    943   // from now on, we're working on 'node'
    944   node->down = NULL;
    945   node->ch = char_to_add;
    946   node->expanded = node->selected = FALSE;
    947   if (char_to_add == '\0')
    948     {
    949       log_msg (6, "Added %s OK", original_string);
    950       return (0);
    951     }
    952 
     841    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
     842        log_to_screen("failed to malloc");
     843        depth--;
     844        return (1);
     845    }
     846    if (char_to_add < node->ch) // add to the left of node
     847    {
     848        log_msg(7, "depth=%d char=%c --- adding (left)", depth,
     849                char_to_add);
     850        memcpy((void *) newnode, (void *) node, sizeof(struct s_node));
     851        node->right = newnode;
     852    } else if (char_to_add > node->ch)  // add to the right of node
     853    {
     854        log_msg(7, "depth=%d char=%c --- adding (right)", depth,
     855                char_to_add);
     856        newnode->right = node->right;   // newnode is to the RIGHT of node
     857        node->right = newnode;
     858        node = newnode;
     859    }
     860    // from now on, we're working on 'node'
     861    node->down = NULL;
     862    node->ch = char_to_add;
     863    node->expanded = node->selected = FALSE;
     864    if (char_to_add == '\0') {
     865        log_msg(6, "Added %s OK", original_string);
     866        return (0);
     867    }
    953868// add the rest
    954   log_msg(6, "Adding remaining chars ('%s')", string_to_add+1);
    955   for (i = 1; i < noof_chars; i++)
    956     {
    957       if (!(node->down = (struct s_node*)malloc (sizeof (struct s_node))))
    958     {
    959       log_to_screen ("%s - failed to malloc", string_to_add);
    960       return (1);
    961     }
    962       node = node->down;
    963       char_to_add = string_to_add[i];
    964       log_msg(6, "Adding '%c'", char_to_add);
    965       node->ch = char_to_add;
    966       node->right = node->down = NULL;
    967       node->expanded = node->selected = FALSE;
    968       if (!node->ch) { node->selected = sosodef; }
    969     }
    970   log_msg (6, "Finally - added %s OK", original_string);
    971   return (0);
     869    log_msg(6, "Adding remaining chars ('%s')", string_to_add + 1);
     870    for (i = 1; i < noof_chars; i++) {
     871        if (!
     872            (node->down =
     873             (struct s_node *) malloc(sizeof(struct s_node)))) {
     874            log_to_screen("%s - failed to malloc", string_to_add);
     875            return (1);
     876        }
     877        node = node->down;
     878        char_to_add = string_to_add[i];
     879        log_msg(6, "Adding '%c'", char_to_add);
     880        node->ch = char_to_add;
     881        node->right = node->down = NULL;
     882        node->expanded = node->selected = FALSE;
     883        if (!node->ch) {
     884            node->selected = sosodef;
     885        }
     886    }
     887    log_msg(6, "Finally - added %s OK", original_string);
     888    return (0);
    972889}
    973890
     
    981898 * @return A filelist tree structure.
    982899 */
    983 struct s_node *
    984 load_filelist (char *filelist_fname)
    985 {
    986 
    987     /*@ structures **************************************************/
    988   struct s_node *filelist;
    989 
    990     /*@ pointers ****************************************************/
    991   FILE *pin;
    992 
    993     /*@ buffers *****************************************************/
    994   char command_to_open_fname[MAX_STR_LEN];
    995   char fname[MAX_STR_LEN];
    996   char tmp[MAX_STR_LEN];
    997   int pos_in_fname;
    998     /*@ int *********************************************************/
    999   int percentage;
    1000 
    1001     /*@ long ********************************************************/
    1002   long lines_in_filelist;
    1003   long lino = 0;
    1004     /*@ end vars ****************************************************/
    1005 
    1006   assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
    1007 
    1008   if (!does_file_exist(filelist_fname))
    1009     { fatal_error("filelist does not exist -- cannot load it"); }
    1010   log_to_screen ("Loading filelist");
    1011   sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
    1012   sprintf(tmp, "zcat %s | wc -l", filelist_fname);
    1013   log_msg(6, "tmp = %s", tmp);
    1014   lines_in_filelist = atol(call_program_and_get_last_line_of_output(tmp));
    1015   if (lines_in_filelist < 3) { log_to_screen("Warning - surprisingly short filelist."); }
    1016   g_original_noof_lines_in_filelist = lines_in_filelist;
    1017   if (!(filelist = (struct s_node*)malloc (sizeof (struct s_node))))
    1018     {
    1019       return (NULL);
    1020     }
    1021   filelist->ch = '/';
    1022   filelist->right = NULL;
    1023   filelist->down = malloc(sizeof(struct s_node));
    1024   filelist->expanded = filelist->selected = FALSE;
    1025   (filelist->down)->ch = '\0';
    1026   (filelist->down)->right = (filelist->down)->down = FALSE;
    1027   (filelist->down)->expanded = (filelist->down)->selected = FALSE;
    1028   if (!(pin = popen (command_to_open_fname, "r")))
    1029     {
    1030       log_OS_error("Unable to openin filelist_fname");
    1031       return (NULL);
    1032     }
    1033   open_evalcall_form ("Loading filelist from disk");
    1034   for (fgets (fname, MAX_STR_LEN, pin); !feof (pin);
    1035        fgets (fname, MAX_STR_LEN, pin))
    1036     {
    1037       if ((fname[strlen(fname)-1]==13 || fname[strlen(fname)-1]==10) && strlen(fname)>0)
    1038         { fname[strlen(fname)-1] = '\0'; }
     900struct s_node *load_filelist(char *filelist_fname)
     901{
     902
     903    /*@ structures ************************************************* */
     904    struct s_node *filelist;
     905
     906    /*@ pointers *************************************************** */
     907    FILE *pin;
     908
     909    /*@ buffers **************************************************** */
     910    char command_to_open_fname[MAX_STR_LEN];
     911    char fname[MAX_STR_LEN];
     912    char tmp[MAX_STR_LEN];
     913    int pos_in_fname;
     914    /*@ int ******************************************************** */
     915    int percentage;
     916
     917    /*@ long ******************************************************* */
     918    long lines_in_filelist;
     919    long lino = 0;
     920    /*@ end vars *************************************************** */
     921
     922    assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
     923
     924    if (!does_file_exist(filelist_fname)) {
     925        fatal_error("filelist does not exist -- cannot load it");
     926    }
     927    log_to_screen("Loading filelist");
     928    sprintf(command_to_open_fname, "gzip -dc %s", filelist_fname);
     929    sprintf(tmp, "zcat %s | wc -l", filelist_fname);
     930    log_msg(6, "tmp = %s", tmp);
     931    lines_in_filelist =
     932        atol(call_program_and_get_last_line_of_output(tmp));
     933    if (lines_in_filelist < 3) {
     934        log_to_screen("Warning - surprisingly short filelist.");
     935    }
     936    g_original_noof_lines_in_filelist = lines_in_filelist;
     937    if (!(filelist = (struct s_node *) malloc(sizeof(struct s_node)))) {
     938        return (NULL);
     939    }
     940    filelist->ch = '/';
     941    filelist->right = NULL;
     942    filelist->down = malloc(sizeof(struct s_node));
     943    filelist->expanded = filelist->selected = FALSE;
     944    (filelist->down)->ch = '\0';
     945    (filelist->down)->right = (filelist->down)->down = FALSE;
     946    (filelist->down)->expanded = (filelist->down)->selected = FALSE;
     947    if (!(pin = popen(command_to_open_fname, "r"))) {
     948        log_OS_error("Unable to openin filelist_fname");
     949        return (NULL);
     950    }
     951    open_evalcall_form("Loading filelist from disk");
     952    for (fgets(fname, MAX_STR_LEN, pin); !feof(pin);
     953         fgets(fname, MAX_STR_LEN, pin)) {
     954        if ((fname[strlen(fname) - 1] == 13
     955             || fname[strlen(fname) - 1] == 10) && strlen(fname) > 0) {
     956            fname[strlen(fname) - 1] = '\0';
     957        }
    1039958//      strip_spaces (fname);
    1040       if (!strlen (fname))
    1041     {
    1042       continue;
    1043     }
    1044       for(pos_in_fname=0; fname[pos_in_fname]!='\0'; pos_in_fname++)
    1045         {
    1046       if (fname[pos_in_fname]!='/') { continue; }
    1047       strcpy(tmp, fname);
    1048       tmp[pos_in_fname] = '\0';
    1049       if (strlen(tmp))
    1050         { add_string_at_node (filelist, tmp); }
    1051     }
    1052       add_string_at_node (filelist, fname);
    1053       if (!(++lino % 1111))
    1054     {
    1055       percentage = (int) (lino * 100 / lines_in_filelist);
    1056       update_evalcall_form (percentage);
    1057     }
    1058     }
    1059   paranoid_pclose(pin);
    1060   close_evalcall_form ();
    1061   log_it ("Finished loading filelist");
    1062   return (filelist);
     959        if (!strlen(fname)) {
     960            continue;
     961        }
     962        for (pos_in_fname = 0; fname[pos_in_fname] != '\0'; pos_in_fname++) {
     963            if (fname[pos_in_fname] != '/') {
     964                continue;
     965            }
     966            strcpy(tmp, fname);
     967            tmp[pos_in_fname] = '\0';
     968            if (strlen(tmp)) {
     969                add_string_at_node(filelist, tmp);
     970            }
     971        }
     972        add_string_at_node(filelist, fname);
     973        if (!(++lino % 1111)) {
     974            percentage = (int) (lino * 100 / lines_in_filelist);
     975            update_evalcall_form(percentage);
     976        }
     977    }
     978    paranoid_pclose(pin);
     979    close_evalcall_form();
     980    log_it("Finished loading filelist");
     981    return (filelist);
    1063982}
    1064983
     
    1068987 * @param node The toplevel node to use.
    1069988 */
    1070 void
    1071 show_filelist (struct s_node *node)
    1072 {
    1073   static int depth=0;
    1074   static char current_string[200];
    1075 
    1076   if (depth==0)
    1077     { log_msg(0, "----------------show filelist--------------"); }
    1078   current_string[depth] = node->ch;
    1079 
    1080   log_msg(3, "depth=%d", depth);
    1081   if (node->down)
    1082     {
    1083       log_msg(3, "moving down");
    1084       depth++;
    1085       show_filelist(node->down);
    1086       depth--;
    1087     }
    1088 
    1089   if (!node->ch)
    1090     {
    1091       log_msg(0, "%s\n", current_string);
    1092     }
    1093 
    1094   if (node->right)
    1095     {
    1096       log_msg(3, "moving right");
    1097       show_filelist(node->right);
    1098     }
    1099   if (depth==0)
    1100     { log_msg(0, "----------------show filelist--------------"); }
    1101   return;
     989void show_filelist(struct s_node *node)
     990{
     991    static int depth = 0;
     992    static char current_string[200];
     993
     994    if (depth == 0) {
     995        log_msg(0, "----------------show filelist--------------");
     996    }
     997    current_string[depth] = node->ch;
     998
     999    log_msg(3, "depth=%d", depth);
     1000    if (node->down) {
     1001        log_msg(3, "moving down");
     1002        depth++;
     1003        show_filelist(node->down);
     1004        depth--;
     1005    }
     1006
     1007    if (!node->ch) {
     1008        log_msg(0, "%s\n", current_string);
     1009    }
     1010
     1011    if (node->right) {
     1012        log_msg(3, "moving right");
     1013        show_filelist(node->right);
     1014    }
     1015    if (depth == 0) {
     1016        log_msg(0, "----------------show filelist--------------");
     1017    }
     1018    return;
    11021019}
    11031020
     
    11101027 * @param filelist The filelist tree structure.
    11111028 */
    1112 void
    1113 reload_filelist (struct s_node *filelist)
    1114 {
    1115   assert(filelist!=NULL);
    1116   toggle_node_selection (filelist, FALSE);
    1117   toggle_path_expandability (filelist, "/", FALSE);
    1118   toggle_all_root_dirs_on (filelist);
     1029void reload_filelist(struct s_node *filelist)
     1030{
     1031    assert(filelist != NULL);
     1032    toggle_node_selection(filelist, FALSE);
     1033    toggle_path_expandability(filelist, "/", FALSE);
     1034    toggle_all_root_dirs_on(filelist);
    11191035}
    11201036
     
    11261042 * @param outfname Where to save it.
    11271043 */
    1128 void
    1129 save_filelist (struct s_node *filelist, char *outfname)
    1130 {
    1131     /*@ int **********************************************************/
    1132   static int percentage;
    1133   static int depth = 0;
    1134 
    1135     /*@ buffers ******************************************************/
    1136   static char str[MAX_STR_LEN];
    1137 
    1138     /*@ structures ***************************************************/
    1139   struct s_node *node;
    1140 
    1141     /*@ pointers *****************************************************/
    1142   static FILE *fout = NULL;
    1143 
    1144     /*@ long *********************************************************/
    1145   static long lines_in_filelist = 0;
    1146   static long lino = 0;
    1147 
    1148     /*@ end vars ****************************************************/
    1149 
    1150   assert(filelist!=NULL);
    1151   assert(outfname!=NULL); // will be zerolength if save_filelist() is called by itself
    1152   if (depth == 0)
    1153     {
    1154       log_to_screen ("Saving filelist");
    1155       if (!(fout = fopen (outfname, "w"))) { fatal_error("Cannot openout/save filelist"); }
    1156       lines_in_filelist = g_original_noof_lines_in_filelist;    /* set by load_filelist() */
    1157       open_evalcall_form ("Saving selection to disk");
    1158     }
    1159   for (node = filelist; node != NULL; node = node->right)
    1160     {
    1161       str[depth] = node->ch;
    1162       log_msg(5, "depth=%d ch=%c", depth, node->ch);
    1163       if (!node->ch)
    1164     {
    1165 //    if (node->selected)
    1166 //      {
    1167           fprintf (fout, "%s\n", str);
    1168 //      }
    1169       if (!(++lino % 1111))
    1170         {
    1171           percentage = (int) (lino * 100 / lines_in_filelist);
    1172           update_evalcall_form (percentage);
    1173         }
    1174     }
    1175       if (node->down)
    1176     {
    1177       depth++;
    1178       save_filelist (node->down, "");
    1179       depth--;
    1180     }
    1181     }
    1182   if (depth == 0)
    1183     {
    1184       paranoid_fclose (fout);
    1185       close_evalcall_form ();
    1186       log_it ("Finished saving filelist");
    1187     }
     1044void save_filelist(struct s_node *filelist, char *outfname)
     1045{
     1046    /*@ int ********************************************************* */
     1047    static int percentage;
     1048    static int depth = 0;
     1049
     1050    /*@ buffers ***************************************************** */
     1051    static char str[MAX_STR_LEN];
     1052
     1053    /*@ structures ************************************************** */
     1054    struct s_node *node;
     1055
     1056    /*@ pointers **************************************************** */
     1057    static FILE *fout = NULL;
     1058
     1059    /*@ long ******************************************************** */
     1060    static long lines_in_filelist = 0;
     1061    static long lino = 0;
     1062
     1063    /*@ end vars *************************************************** */
     1064
     1065    assert(filelist != NULL);
     1066    assert(outfname != NULL);   // will be zerolength if save_filelist() is called by itself
     1067    if (depth == 0) {
     1068        log_to_screen("Saving filelist");
     1069        if (!(fout = fopen(outfname, "w"))) {
     1070            fatal_error("Cannot openout/save filelist");
     1071        }
     1072        lines_in_filelist = g_original_noof_lines_in_filelist;  /* set by load_filelist() */
     1073        open_evalcall_form("Saving selection to disk");
     1074    }
     1075    for (node = filelist; node != NULL; node = node->right) {
     1076        str[depth] = node->ch;
     1077        log_msg(5, "depth=%d ch=%c", depth, node->ch);
     1078        if (!node->ch) {
     1079//    if (node->selected)
     1080//      {
     1081            fprintf(fout, "%s\n", str);
     1082//      }
     1083            if (!(++lino % 1111)) {
     1084                percentage = (int) (lino * 100 / lines_in_filelist);
     1085                update_evalcall_form(percentage);
     1086            }
     1087        }
     1088        if (node->down) {
     1089            depth++;
     1090            save_filelist(node->down, "");
     1091            depth--;
     1092        }
     1093    }
     1094    if (depth == 0) {
     1095        paranoid_fclose(fout);
     1096        close_evalcall_form();
     1097        log_it("Finished saving filelist");
     1098    }
    11881099}
    11891100
     
    11951106 * @bug I don't understand this function. Would someone care to explain it?
    11961107 */
    1197 void
    1198 toggle_all_root_dirs_on (struct s_node *filelist)
    1199 {
    1200     /*@ structures ***************************************************/
    1201   struct s_node *node;
    1202 
    1203     /*@ int **********************************************************/
    1204   static int depth = 0;
    1205   static int root_dirs_expanded;
    1206 
    1207     /*@ buffers ******************************************************/
    1208   static char filename[MAX_STR_LEN];
    1209 
    1210     /*@ end vars ****************************************************/
    1211 
    1212   assert(filelist!=NULL);
    1213   if (depth == 0)
    1214     {
    1215       log_it ("Toggling all root dirs ON");
    1216       root_dirs_expanded = 0;
    1217     }
    1218   for (node = filelist; node != NULL; node = node->right)
    1219     {
    1220       filename[depth] = node->ch;
    1221       if (node->ch == '\0' && strlen (filename) > 1
    1222       && (!strchr (filename + 1, '/')))
    1223     {
    1224       node->selected = FALSE;
    1225       node->expanded = TRUE;
    1226 //    log_it (filename);
    1227       root_dirs_expanded++;
    1228     }
    1229       if (node->down)
    1230     {
    1231       depth++;
    1232       toggle_all_root_dirs_on (node->down);
    1233       depth--;
    1234     }
    1235     }
    1236   if (depth == 0)
    1237     {
    1238       log_it ("Finished toggling all root dirs ON");
    1239     }
     1108void toggle_all_root_dirs_on(struct s_node *filelist)
     1109{
     1110    /*@ structures ************************************************** */
     1111    struct s_node *node;
     1112
     1113    /*@ int ********************************************************* */
     1114    static int depth = 0;
     1115    static int root_dirs_expanded;
     1116
     1117    /*@ buffers ***************************************************** */
     1118    static char filename[MAX_STR_LEN];
     1119
     1120    /*@ end vars *************************************************** */
     1121
     1122    assert(filelist != NULL);
     1123    if (depth == 0) {
     1124        log_it("Toggling all root dirs ON");
     1125        root_dirs_expanded = 0;
     1126    }
     1127    for (node = filelist; node != NULL; node = node->right) {
     1128        filename[depth] = node->ch;
     1129        if (node->ch == '\0' && strlen(filename) > 1
     1130            && (!strchr(filename + 1, '/'))) {
     1131            node->selected = FALSE;
     1132            node->expanded = TRUE;
     1133//    log_it (filename);
     1134            root_dirs_expanded++;
     1135        }
     1136        if (node->down) {
     1137            depth++;
     1138            toggle_all_root_dirs_on(node->down);
     1139            depth--;
     1140        }
     1141    }
     1142    if (depth == 0) {
     1143        log_it("Finished toggling all root dirs ON");
     1144    }
    12401145}
    12411146
     
    12491154 */
    12501155void
    1251 toggle_path_expandability (struct s_node *filelist, char *pathname,
    1252                bool on_or_off)
    1253 {
    1254 
    1255     /*@ int *********************************************************/
    1256   static int depth = 0;
    1257   static int total_expanded;
    1258   static int root_depth;
    1259   int j;
    1260     /*@ structures **************************************************/
    1261   struct s_node *node;
    1262 
    1263     /*@ buffers *****************************************************/
    1264   static char current_filename[MAX_STR_LEN];
     1156toggle_path_expandability(struct s_node *filelist, char *pathname,
     1157                          bool on_or_off)
     1158{
     1159
     1160    /*@ int ******************************************************** */
     1161    static int depth = 0;
     1162    static int total_expanded;
     1163    static int root_depth;
     1164    int j;
     1165    /*@ structures ************************************************* */
     1166    struct s_node *node;
     1167
     1168    /*@ buffers **************************************************** */
     1169    static char current_filename[MAX_STR_LEN];
    12651170
    12661171/*  char tmp[MAX_STR_LEN+2]; */
    12671172
    1268     /*@ end vars ****************************************************/
    1269 
    1270   assert(filelist!=NULL);
    1271   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1272   if (depth == 0)
    1273     {
    1274       total_expanded = 0;
     1173    /*@ end vars *************************************************** */
     1174
     1175    assert(filelist != NULL);
     1176    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1177    if (depth == 0) {
     1178        total_expanded = 0;
    12751179//      log_it ("Toggling path's expandability");
    1276       for (root_depth = (int) strlen (pathname);
    1277        root_depth > 0 && pathname[root_depth - 1] != '/'; root_depth--);
    1278       if (root_depth < 2)
    1279     {
    1280       root_depth = (int) strlen (pathname);
    1281     }
    1282     }
    1283   for (node = filelist; node != NULL; node = node->right)
    1284     {
    1285       current_filename[depth] = node->ch;
    1286       if (node->down)
    1287     {
    1288       depth++;
    1289       toggle_path_expandability (node->down, pathname, on_or_off);
    1290       depth--;
    1291     }
    1292       if (node->ch == '\0')
    1293     {
    1294       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1295         {
    1296           for (j = root_depth;
    1297            current_filename[j] != '/' && current_filename[j] != '\0';
    1298            j++);
    1299           if (current_filename[j] != '\0')
    1300         {
    1301           for (j++;
    1302                current_filename[j] != '/'
    1303                && current_filename[j] != '\0'; j++);
    1304         }
    1305           if (current_filename[j] == '\0')
    1306         {
    1307           node->expanded =
    1308             (!strcmp (pathname, current_filename) ? TRUE : on_or_off);
    1309         }
    1310         }
    1311     }
    1312       if (node->expanded)
    1313     {
    1314       if (total_expanded < ARBITRARY_MAXIMUM - 32
    1315           || !strrchr (current_filename + strlen (pathname), '/'))
    1316         {
    1317           total_expanded++;
    1318         }
    1319       else
    1320         {
    1321           node->expanded = FALSE;
    1322         }
    1323     }
    1324     }
    1325   if (depth == 0)
    1326     {
     1180        for (root_depth = (int) strlen(pathname);
     1181             root_depth > 0 && pathname[root_depth - 1] != '/';
     1182             root_depth--);
     1183        if (root_depth < 2) {
     1184            root_depth = (int) strlen(pathname);
     1185        }
     1186    }
     1187    for (node = filelist; node != NULL; node = node->right) {
     1188        current_filename[depth] = node->ch;
     1189        if (node->down) {
     1190            depth++;
     1191            toggle_path_expandability(node->down, pathname, on_or_off);
     1192            depth--;
     1193        }
     1194        if (node->ch == '\0') {
     1195            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1196                for (j = root_depth;
     1197                     current_filename[j] != '/'
     1198                     && current_filename[j] != '\0'; j++);
     1199                if (current_filename[j] != '\0') {
     1200                    for (j++;
     1201                         current_filename[j] != '/'
     1202                         && current_filename[j] != '\0'; j++);
     1203                }
     1204                if (current_filename[j] == '\0') {
     1205                    node->expanded =
     1206                        (!strcmp(pathname, current_filename) ? TRUE :
     1207                         on_or_off);
     1208                }
     1209            }
     1210        }
     1211        if (node->expanded) {
     1212            if (total_expanded < ARBITRARY_MAXIMUM - 32
     1213                || !strrchr(current_filename + strlen(pathname), '/')) {
     1214                total_expanded++;
     1215            } else {
     1216                node->expanded = FALSE;
     1217            }
     1218        }
     1219    }
     1220    if (depth == 0) {
    13271221//      log_it ("Finished toggling expandability");
    1328     }
     1222    }
    13291223}
    13301224
     
    13371231 */
    13381232void
    1339 toggle_path_selection (struct s_node *filelist, char *pathname,
    1340                bool on_or_off)
    1341 {
    1342     /*@ int **********************************************************/
    1343   static int depth = 0;
    1344   int j;
    1345 
    1346     /*@ structures ***************************************************/
    1347   struct s_node *node;
    1348 
    1349     /*@ buffers ******************************************************/
    1350   static char current_filename[MAX_STR_LEN];
    1351   char tmp[MAX_STR_LEN + 2];
    1352 
    1353     /*@ end vars ****************************************************/
    1354   assert(filelist!=NULL);
    1355   assert_string_is_neither_NULL_nor_zerolength(pathname);
    1356   if (depth == 0)
    1357     {
    1358       log_it ("Toggling path's selection");
    1359     }
    1360   for (node = filelist; node != NULL; node = node->right)
    1361     {
    1362       current_filename[depth] = node->ch;
    1363       if (node->down)
    1364     {
    1365       depth++;
    1366       toggle_path_selection (node->down, pathname, on_or_off);
    1367       depth--;
    1368     }
    1369       if (node->ch == '\0')
    1370     {
    1371       if (!strncmp (pathname, current_filename, strlen (pathname)))
    1372         {
    1373           for (j = 0;
    1374            pathname[j] != '\0' && pathname[j] == current_filename[j];
    1375            j++);
    1376           if (current_filename[j] == '/' || current_filename[j] == '\0')
    1377         {
    1378           node->selected = on_or_off;
    1379           sprintf (tmp, "%s is now %s\n", current_filename,
    1380                (on_or_off ? "ON" : "OFF"));
    1381         }
    1382         }
    1383     }
    1384     }
    1385   if (depth == 0)
    1386     {
    1387       log_it ("Finished toggling selection");
    1388     }
     1233toggle_path_selection(struct s_node *filelist, char *pathname,
     1234                      bool on_or_off)
     1235{
     1236    /*@ int ********************************************************* */
     1237    static int depth = 0;
     1238    int j;
     1239
     1240    /*@ structures ************************************************** */
     1241    struct s_node *node;
     1242
     1243    /*@ buffers ***************************************************** */
     1244    static char current_filename[MAX_STR_LEN];
     1245    char tmp[MAX_STR_LEN + 2];
     1246
     1247    /*@ end vars *************************************************** */
     1248    assert(filelist != NULL);
     1249    assert_string_is_neither_NULL_nor_zerolength(pathname);
     1250    if (depth == 0) {
     1251        log_it("Toggling path's selection");
     1252    }
     1253    for (node = filelist; node != NULL; node = node->right) {
     1254        current_filename[depth] = node->ch;
     1255        if (node->down) {
     1256            depth++;
     1257            toggle_path_selection(node->down, pathname, on_or_off);
     1258            depth--;
     1259        }
     1260        if (node->ch == '\0') {
     1261            if (!strncmp(pathname, current_filename, strlen(pathname))) {
     1262                for (j = 0;
     1263                     pathname[j] != '\0'
     1264                     && pathname[j] == current_filename[j]; j++);
     1265                if (current_filename[j] == '/'
     1266                    || current_filename[j] == '\0') {
     1267                    node->selected = on_or_off;
     1268                    sprintf(tmp, "%s is now %s\n", current_filename,
     1269                            (on_or_off ? "ON" : "OFF"));
     1270                }
     1271            }
     1272        }
     1273    }
     1274    if (depth == 0) {
     1275        log_it("Finished toggling selection");
     1276    }
    13891277}
    13901278
     
    13961284 * @bug I don't understand this function. Would someone care to explain it?
    13971285 */
    1398 void
    1399 toggle_node_selection (struct s_node *filelist, bool on_or_off)
    1400 {
    1401     /*@ structure ***************************************************/
    1402   struct s_node *node;
    1403 
    1404     /*@ end vars ****************************************************/
    1405   assert(filelist!=NULL);
    1406   for (node = filelist; node != NULL; node = node->right)
    1407     {
    1408       if (node->ch == '/')
    1409     {
    1410       continue;
    1411     }           /* don't go deep */
    1412       if (node->ch == '\0')
    1413     {
    1414       node->selected = on_or_off;
    1415     }
    1416       if (node->down)
    1417     {
    1418       toggle_node_selection (node->down, on_or_off);
    1419     }
    1420     }
     1286void toggle_node_selection(struct s_node *filelist, bool on_or_off)
     1287{
     1288    /*@ structure ************************************************** */
     1289    struct s_node *node;
     1290
     1291    /*@ end vars *************************************************** */
     1292    assert(filelist != NULL);
     1293    for (node = filelist; node != NULL; node = node->right) {
     1294        if (node->ch == '/') {
     1295            continue;
     1296        }                       /* don't go deep */
     1297        if (node->ch == '\0') {
     1298            node->selected = on_or_off;
     1299        }
     1300        if (node->down) {
     1301            toggle_node_selection(node->down, on_or_off);
     1302        }
     1303    }
    14211304}
    14221305
     
    14301313 * The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
    14311314 */
    1432 char *g_skeleton_filelist=NULL;
     1315char *g_skeleton_filelist = NULL;
    14331316
    14341317/**
    14351318 * Number of entries in the skeleton filelist.
    14361319 */
    1437 long g_skeleton_entries=0;
     1320long g_skeleton_entries = 0;
    14381321
    14391322/**
     
    14491332 * @see mondo_makefilelist
    14501333 */
    1451 int
    1452 prepare_filelist (struct s_bkpinfo *bkpinfo)
    1453 {
    1454 
    1455     /*@ int *****************************************************/
    1456   int res = 0;
     1334int prepare_filelist(struct s_bkpinfo *bkpinfo)
     1335{
     1336
     1337    /*@ int **************************************************** */
     1338    int res = 0;
    14571339// patch by Herman Kuster
    14581340// end patch
    1459   int *p_res = &res;
    1460 
    1461     /*@ buffers *************************************************/
     1341    int *p_res = &res;
     1342
     1343    /*@ buffers ************************************************ */
    14621344//  char command[MAX_STR_LEN*2];
    14631345
    1464     /*@ i don't have any idea ***********************************/
    1465 
    1466   assert(bkpinfo!=NULL);
    1467   log_it ("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
    1468        bkpinfo->scratchdir);
    1469   if (bkpinfo->make_filelist)
    1470     {
    1471       mvaddstr_and_log_it (g_currentY, 0,
    1472                "Making catalog of files to be backed up");
    1473     }
    1474   else
    1475     {
    1476       mvaddstr_and_log_it (g_currentY, 0,
    1477                "Using supplied catalog of files to be backed up");
    1478     }
    1479 
    1480   if (bkpinfo->make_filelist)
    1481     {
    1482       res = mondo_makefilelist(
    1483        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1484        bkpinfo->include_paths,
    1485        bkpinfo->exclude_paths,
    1486        bkpinfo->differential,
    1487        NULL);
    1488     }
    1489   else
    1490     {
    1491       res = mondo_makefilelist(
    1492        MONDO_LOGFILE, bkpinfo->tmpdir, bkpinfo->scratchdir,
    1493        NULL,
    1494        bkpinfo->exclude_paths,
    1495        bkpinfo->differential,
    1496        bkpinfo->include_paths);
    1497     }
    1498 
    1499   if (res)
    1500     {
    1501       log_OS_error("Call to mondo-makefilelist failed");
    1502       *p_res ++;
    1503       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1504     }
    1505   else
    1506     {
    1507       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1508     }
    1509   return (res);
     1346    /*@ i don't have any idea ********************************** */
     1347
     1348    assert(bkpinfo != NULL);
     1349    log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
     1350           bkpinfo->scratchdir);
     1351    if (bkpinfo->make_filelist) {
     1352        mvaddstr_and_log_it(g_currentY, 0,
     1353                            "Making catalog of files to be backed up");
     1354    } else {
     1355        mvaddstr_and_log_it(g_currentY, 0,
     1356                            "Using supplied catalog of files to be backed up");
     1357    }
     1358
     1359    if (bkpinfo->make_filelist) {
     1360        res =
     1361            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1362                               bkpinfo->scratchdir, bkpinfo->include_paths,
     1363                               bkpinfo->exclude_paths,
     1364                               bkpinfo->differential, NULL);
     1365    } else {
     1366        res =
     1367            mondo_makefilelist(MONDO_LOGFILE, bkpinfo->tmpdir,
     1368                               bkpinfo->scratchdir, NULL,
     1369                               bkpinfo->exclude_paths,
     1370                               bkpinfo->differential,
     1371                               bkpinfo->include_paths);
     1372    }
     1373
     1374    if (res) {
     1375        log_OS_error("Call to mondo-makefilelist failed");
     1376        *p_res++;
     1377        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1378    } else {
     1379        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1380    }
     1381    return (res);
    15101382}
    15111383
     
    15201392 * @bug Return value should be @c void.
    15211393 */
    1522 int open_and_list_dir(char*dir, char*sth, FILE*fout, time_t time_of_last_full_backup)
    1523 {
    1524   DIR             *dip;
    1525   struct dirent   *dit;
    1526   struct stat statbuf;
    1527   char new[MAX_STR_LEN];
    1528   char *tmp;
    1529   char *sth_B;
    1530   static int percentage=0;
    1531   char *ith_B;
    1532   char *skip_these;
    1533   char *new_with_spaces;
    1534   static char *name_of_evalcall_form;
    1535   int i;
    1536   static int depth=0;
    1537   char *p;
    1538   static int counter=0;
    1539   static int uberctr=0;
    1540   static char *find_skeleton_marker;
    1541   static long skeleton_lino=0;
    1542   static time_t last_time=0;
    1543   time_t this_time;
    1544  
    1545   malloc_string(tmp);
    1546   malloc_string(sth_B);
    1547   malloc_string(ith_B);
    1548   malloc_string(new_with_spaces);
    1549   p = strrchr(dir, '/');
    1550   if (p)
    1551     {
    1552       if (!strcmp(p, "/.") || !strcmp(p, "/.."))
    1553         {
    1554           return(0);
    1555         }
    1556     }
    1557 
    1558   if (!depth)
    1559     {
    1560       malloc_string(name_of_evalcall_form);
    1561       malloc_string(find_skeleton_marker);
     1394int open_and_list_dir(char *dir, char *sth, FILE * fout,
     1395                      time_t time_of_last_full_backup)
     1396{
     1397    DIR *dip;
     1398    struct dirent *dit;
     1399    struct stat statbuf;
     1400    char new[MAX_STR_LEN];
     1401    char *tmp;
     1402    char *sth_B;
     1403    static int percentage = 0;
     1404    char *ith_B;
     1405    char *skip_these;
     1406    char *new_with_spaces;
     1407    static char *name_of_evalcall_form;
     1408    int i;
     1409    static int depth = 0;
     1410    char *p;
     1411    static int counter = 0;
     1412    static int uberctr = 0;
     1413    static char *find_skeleton_marker;
     1414    static long skeleton_lino = 0;
     1415    static time_t last_time = 0;
     1416    time_t this_time;
     1417
     1418    malloc_string(tmp);
     1419    malloc_string(sth_B);
     1420    malloc_string(ith_B);
     1421    malloc_string(new_with_spaces);
     1422    p = strrchr(dir, '/');
     1423    if (p) {
     1424        if (!strcmp(p, "/.") || !strcmp(p, "/..")) {
     1425            return (0);
     1426        }
     1427    }
     1428
     1429    if (!depth) {
     1430        malloc_string(name_of_evalcall_form);
     1431        malloc_string(find_skeleton_marker);
    15621432#if linux
    1563       // 2.6 has /sys as a proc-type thing -- must be excluded
    1564       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1433        // 2.6 has /sys as a proc-type thing -- must be excluded
     1434        sprintf(tmp,
     1435                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -path /sys -prune -o -path /dev/shm -prune -o -path /media/floppy -prune -o -type d -a -print > %s 2> /dev/null",
     1436                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15651437#else
    1566       // On BSD, for example, /sys is the kernel sources -- don't exclude
    1567       sprintf(tmp, "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
     1438        // On BSD, for example, /sys is the kernel sources -- don't exclude
     1439        sprintf(tmp,
     1440                "find %s -maxdepth %d -path /proc -prune -o -path /tmp -prune -o -type d -a -print > %s 2> /dev/null",
     1441                dir, MAX_SKEL_DEPTH, g_skeleton_filelist);
    15681442#endif
    1569       system(tmp);
    1570       sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    1571       g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp));
    1572       sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
    1573       open_evalcall_form (name_of_evalcall_form);
    1574       find_skeleton_marker[0] = '\0';
    1575       skeleton_lino=1;
    1576       log_msg(5, "entries = %ld", g_skeleton_entries);
    1577       percentage=0;
    1578     }
    1579   else if (depth<=MAX_SKEL_DEPTH) // update evalcall form if appropriate
    1580         {
    1581       sprintf(find_skeleton_marker, "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist);
    1582 //    log_msg(0, "fsm = %s", find_skeleton_marker);
    1583       if (!system(find_skeleton_marker))
    1584         {
    1585           percentage = (int)(skeleton_lino*100/g_skeleton_entries);
    1586           skeleton_lino++;
    1587 //        log_msg(5, "Found %s", dir);
    1588 //        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
    1589           sprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist);
    1590 //        log_msg(6, "fsm = %s", find_skeleton_marker);
    1591           run_program_and_log_output(find_skeleton_marker, 8);
    1592           time(&this_time);
    1593           if (this_time != last_time)
    1594             {
    1595             last_time = this_time;
     1443        system(tmp);
     1444        sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1445        g_skeleton_entries =
     1446            1 + atol(call_program_and_get_last_line_of_output(tmp));
     1447        sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
     1448        open_evalcall_form(name_of_evalcall_form);
     1449        find_skeleton_marker[0] = '\0';
     1450        skeleton_lino = 1;
     1451        log_msg(5, "entries = %ld", g_skeleton_entries);
     1452        percentage = 0;
     1453    } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
     1454    {
     1455        sprintf(find_skeleton_marker,
     1456                "fgrep -v \"%s\" %s > %s.new 2> /dev/null", dir,
     1457                g_skeleton_filelist, g_skeleton_filelist);
     1458//    log_msg(0, "fsm = %s", find_skeleton_marker);
     1459        if (!system(find_skeleton_marker)) {
     1460            percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
     1461            skeleton_lino++;
     1462//        log_msg(5, "Found %s", dir);
     1463//        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
     1464            sprintf(find_skeleton_marker, "mv -f %s.new %s",
     1465                    g_skeleton_filelist, g_skeleton_filelist);
     1466//        log_msg(6, "fsm = %s", find_skeleton_marker);
     1467            run_program_and_log_output(find_skeleton_marker, 8);
     1468            time(&this_time);
     1469            if (this_time != last_time) {
     1470                last_time = this_time;
    15961471#ifndef _XWIN
    1597                   if (!g_text_mode)
    1598                 {
    1599               sprintf(tmp, "Reading %-68s", dir);
    1600                   newtDrawRootText (0, g_noof_rows - 3, tmp);
    1601             }
     1472                if (!g_text_mode) {
     1473                    sprintf(tmp, "Reading %-68s", dir);
     1474                    newtDrawRootText(0, g_noof_rows - 3, tmp);
     1475                }
    16021476#endif
    1603           update_evalcall_form(percentage);
    1604         }
    1605         }
    1606         }
    1607 
    1608   depth++;
     1477                update_evalcall_form(percentage);
     1478            }
     1479        }
     1480    }
     1481
     1482    depth++;
    16091483
    16101484//  log_msg(0, "Cataloguing %s", dir);
    1611   if (sth[0]==' ') { skip_these = sth; }
    1612   else
    1613     {
    1614       skip_these = sth_B;
    1615       sprintf(skip_these, " %s ", sth);
    1616     }
    1617   sprintf(new_with_spaces, " %s ", dir);
    1618   if ((dip = opendir(dir)) == NULL)
    1619     {
    1620       log_OS_error("opendir");
    1621     }
    1622   else if (strstr(skip_these, new_with_spaces))
    1623     {
    1624       fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
    1625     }
    1626   else
    1627     {
    1628       fprintf(fout, "%s\n", dir);
    1629       while ((dit = readdir(dip)) != NULL)
    1630        {
    1631     i++;
    1632         strcpy(new, dir);
    1633         if (strcmp(dir, "/")) { strcat(new, "/"); }
    1634         strcat(new, dit->d_name);
    1635     new_with_spaces[0] = ' ';
    1636           strcpy(new_with_spaces+1, new);
    1637           strcat(new_with_spaces, " ");
    1638     if (strstr(skip_these, new_with_spaces))
    1639       {
    1640         fprintf(fout, "%s\n", new);
    1641       }
    1642     else
    1643       {
    1644         if (!lstat(new, &statbuf))
    1645           {
    1646         if (!S_ISLNK(statbuf.st_mode) && S_ISDIR(statbuf.st_mode)) {
    1647           open_and_list_dir(new, skip_these, fout, time_of_last_full_backup);
    1648         }
    1649         else {
    1650           if (time_of_last_full_backup==0 || time_of_last_full_backup<statbuf.st_ctime)
    1651             {
    1652               fprintf(fout, "%s\n", new);
    1653               if ((counter++)>128)
    1654                 {
    1655                   counter=0;
    1656               uberctr++;
    1657                   sprintf(tmp, " %c ", special_dot_char(uberctr));
     1485    if (sth[0] == ' ') {
     1486        skip_these = sth;
     1487    } else {
     1488        skip_these = sth_B;
     1489        sprintf(skip_these, " %s ", sth);
     1490    }
     1491    sprintf(new_with_spaces, " %s ", dir);
     1492    if ((dip = opendir(dir)) == NULL) {
     1493        log_OS_error("opendir");
     1494    } else if (strstr(skip_these, new_with_spaces)) {
     1495        fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
     1496    } else {
     1497        fprintf(fout, "%s\n", dir);
     1498        while ((dit = readdir(dip)) != NULL) {
     1499            i++;
     1500            strcpy(new, dir);
     1501            if (strcmp(dir, "/")) {
     1502                strcat(new, "/");
     1503            }
     1504            strcat(new, dit->d_name);
     1505            new_with_spaces[0] = ' ';
     1506            strcpy(new_with_spaces + 1, new);
     1507            strcat(new_with_spaces, " ");
     1508            if (strstr(skip_these, new_with_spaces)) {
     1509                fprintf(fout, "%s\n", new);
     1510            } else {
     1511                if (!lstat(new, &statbuf)) {
     1512                    if (!S_ISLNK(statbuf.st_mode)
     1513                        && S_ISDIR(statbuf.st_mode)) {
     1514                        open_and_list_dir(new, skip_these, fout,
     1515                                          time_of_last_full_backup);
     1516                    } else {
     1517                        if (time_of_last_full_backup == 0
     1518                            || time_of_last_full_backup <
     1519                            statbuf.st_ctime) {
     1520                            fprintf(fout, "%s\n", new);
     1521                            if ((counter++) > 128) {
     1522                                counter = 0;
     1523                                uberctr++;
     1524                                sprintf(tmp, " %c ",
     1525                                        special_dot_char(uberctr));
    16581526#ifndef _XWIN
    1659               if (!g_text_mode) {
    1660                   newtDrawRootText (77, g_noof_rows - 3, tmp);
    1661                   newtRefresh();
    1662               }
     1527                                if (!g_text_mode) {
     1528                                    newtDrawRootText(77, g_noof_rows - 3,
     1529                                                     tmp);
     1530                                    newtRefresh();
     1531                                }
    16631532#endif
    1664                         }
    1665             }
    1666         }
    1667           }
    1668       }
    1669        }
    1670     }
    1671   if (dip)
    1672     {
    1673       if (closedir(dip) == -1)
    1674         {
    1675       log_OS_error("closedir");
    1676         }
    1677     }
    1678   depth--;
    1679   if (!depth)
    1680     {
    1681       close_evalcall_form ();
    1682       paranoid_free (name_of_evalcall_form);
    1683       paranoid_free(find_skeleton_marker);
    1684       unlink(g_skeleton_filelist);
    1685       log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
    1686     }
    1687   paranoid_free(tmp);
    1688   paranoid_free(sth_B);
    1689   paranoid_free(ith_B);
    1690   paranoid_free(new_with_spaces);
    1691   return(0);
     1533                            }
     1534                        }
     1535                    }
     1536                }
     1537            }
     1538        }
     1539    }
     1540    if (dip) {
     1541        if (closedir(dip) == -1) {
     1542            log_OS_error("closedir");
     1543        }
     1544    }
     1545    depth--;
     1546    if (!depth) {
     1547        close_evalcall_form();
     1548        paranoid_free(name_of_evalcall_form);
     1549        paranoid_free(find_skeleton_marker);
     1550        unlink(g_skeleton_filelist);
     1551        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
     1552    }
     1553    paranoid_free(tmp);
     1554    paranoid_free(sth_B);
     1555    paranoid_free(ith_B);
     1556    paranoid_free(new_with_spaces);
     1557    return (0);
    16921558}
    16931559
     
    17021568 * @note The returned string points to static data that will be overwritten with each call.
    17031569 */
    1704 char *next_entry(char*incoming)
    1705 {
    1706   static char sz_res[MAX_STR_LEN];
    1707   char *p;
    1708   bool in_quotes=FALSE;
    1709 
    1710   strcpy(sz_res, incoming);
    1711   p = sz_res;
    1712   while((*p!=' ' || in_quotes) && *p!='\0')
    1713     {
    1714       if (*p=='\"') { in_quotes = !in_quotes; }
    1715       p++;
    1716     }
    1717   *p = '\0';
    1718   return(sz_res);
     1570char *next_entry(char *incoming)
     1571{
     1572    static char sz_res[MAX_STR_LEN];
     1573    char *p;
     1574    bool in_quotes = FALSE;
     1575
     1576    strcpy(sz_res, incoming);
     1577    p = sz_res;
     1578    while ((*p != ' ' || in_quotes) && *p != '\0') {
     1579        if (*p == '\"') {
     1580            in_quotes = !in_quotes;
     1581        }
     1582        p++;
     1583    }
     1584    *p = '\0';
     1585    return (sz_res);
    17191586}
    17201587
     
    17341601 * @bug Return value is meaningless.
    17351602 */
    1736 int mondo_makefilelist(char*logfile, char*tmpdir, char*scratchdir,
    1737     char*include_paths, char*excp, int differential, char *userdef_filelist)
     1603int mondo_makefilelist(char *logfile, char *tmpdir, char *scratchdir,
     1604                       char *include_paths, char *excp, int differential,
     1605                       char *userdef_filelist)
    17381606{
    17391607    char sz_datefile_wildcard[] = "/var/cache/mondo-archive/difflevel.%d";
     
    17421610    char *sz_filelist, *exclude_paths, *tmp;
    17431611    int i;
    1744     FILE*fout;
     1612    FILE *fout;
    17451613    char *command;
    1746         time_t time_of_last_full_backup=0;
     1614    time_t time_of_last_full_backup = 0;
    17471615    struct stat statbuf;
    17481616
    1749   malloc_string(command);
    1750   malloc_string(tmp);
    1751   malloc_string(sz_filelist);
    1752   malloc_string(g_skeleton_filelist);
    1753   if (!(exclude_paths = malloc(1000))) { fatal_error("Cannot malloc exclude_paths"); }
    1754   log_msg(3, "Trying to write test string to exclude_paths");
    1755   strcpy(exclude_paths, "/blah /froo");
    1756   log_msg(3, "...Success!");
    1757   sprintf(sz_datefile, sz_datefile_wildcard, 0);
    1758   if (!include_paths && !userdef_filelist)
    1759     { fatal_error("Please supply either include_paths or userdef_filelist"); }
    1760 
     1617    malloc_string(command);
     1618    malloc_string(tmp);
     1619    malloc_string(sz_filelist);
     1620    malloc_string(g_skeleton_filelist);
     1621    if (!(exclude_paths = malloc(1000))) {
     1622        fatal_error("Cannot malloc exclude_paths");
     1623    }
     1624    log_msg(3, "Trying to write test string to exclude_paths");
     1625    strcpy(exclude_paths, "/blah /froo");
     1626    log_msg(3, "...Success!");
     1627    sprintf(sz_datefile, sz_datefile_wildcard, 0);
     1628    if (!include_paths && !userdef_filelist) {
     1629        fatal_error
     1630            ("Please supply either include_paths or userdef_filelist");
     1631    }
    17611632// make hole for filelist
    1762   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1763   paranoid_system(command);
    1764   sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    1765   make_hole_for_file(sz_filelist);
    1766 
    1767   if (differential==0)
    1768     {
    1769   // restore last good datefile if it exists
    1770       sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
    1771       run_program_and_log_output(command, 3);
    1772   // backup last known good datefile just in case :)
    1773       if (does_file_exist(sz_datefile))
    1774         {
    1775           sprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    1776           paranoid_system(command);
    1777         }
    1778       make_hole_for_file(sz_datefile);
    1779       write_one_liner_data_file(sz_datefile, call_program_and_get_last_line_of_output("date +%s"));
    1780     }
    1781   else if (lstat(sz_datefile, &statbuf))
    1782     {
    1783       log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    1784       differential = 0;
    1785       time_of_last_full_backup = 0;
    1786     }
    1787   else
    1788     {
    1789       time_of_last_full_backup = statbuf.st_mtime;
    1790       log_msg(2, "Differential backup. Yay.");
    1791     }
     1633    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1634    paranoid_system(command);
     1635    sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1636    make_hole_for_file(sz_filelist);
     1637
     1638    if (differential == 0) {
     1639        // restore last good datefile if it exists
     1640        sprintf(command, "cp -f %s.aborted %s", sz_datefile, sz_datefile);
     1641        run_program_and_log_output(command, 3);
     1642        // backup last known good datefile just in case :)
     1643        if (does_file_exist(sz_datefile)) {
     1644            sprintf(command, "mv -f %s %s.aborted", sz_datefile,
     1645                    sz_datefile);
     1646            paranoid_system(command);
     1647        }
     1648        make_hole_for_file(sz_datefile);
     1649        write_one_liner_data_file(sz_datefile,
     1650                                  call_program_and_get_last_line_of_output
     1651                                  ("date +%s"));
     1652    } else if (lstat(sz_datefile, &statbuf)) {
     1653        log_msg(2,
     1654                "Warning - unable to find date of previous backup. Full backup instead.");
     1655        differential = 0;
     1656        time_of_last_full_backup = 0;
     1657    } else {
     1658        time_of_last_full_backup = statbuf.st_mtime;
     1659        log_msg(2, "Differential backup. Yay.");
     1660    }
    17921661
    17931662// use user-specified filelist (if specified)
    1794   if (userdef_filelist)
    1795     {
    1796       log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    1797       sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    1798       if (run_program_and_log_output(command, 3))
    1799         { fatal_error("Failed to copy user-specified filelist"); }
    1800     }
    1801   else
    1802     {
    1803       log_msg(2, "include_paths = '%s'", include_paths);
    1804       log_msg(1, "Calculating filelist");
    1805       sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
    1806 "MNT_CDROM" "MNT_FLOPPY" /media/cdrom /media/cdrecorder \
    1807 /proc /sys /tmp /root/images/mondo /root/images/mindi ",
    1808         excp,
    1809         call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"),
    1810         call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"),
    1811         call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"),
    1812         (tmpdir[0]=='/' && tmpdir[1]=='/')?(tmpdir+1):tmpdir,
    1813         (scratchdir[0]=='/' && scratchdir[1]=='/')?(scratchdir+1):scratchdir
    1814                         );
    1815 
    1816     log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1817     log_msg(2, "Generating skeleton filelist so that we can track our progress");
    1818     sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
    1819     make_hole_for_file(g_skeleton_filelist);
    1820     log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    1821     log_msg(2, "Opening out filelist to %s", sz_filelist);
    1822     if (!(fout = fopen(sz_filelist, "w"))) { fatal_error("Cannot openout to sz_filelist"); }
    1823     i = 0;
    1824     if (strlen(include_paths)==0)
    1825         {
    1826           log_msg(1, "Including only '/' in %s", sz_filelist);
    1827         open_and_list_dir("/", exclude_paths, fout, time_of_last_full_backup);
    1828         }
    1829     else
    1830         {
    1831         p = include_paths;
    1832         while(*p)
    1833             {
    1834             q = next_entry(p);
    1835             log_msg(1, "Including %s in filelist %s", q, sz_filelist);
    1836             open_and_list_dir(q, exclude_paths, fout, time_of_last_full_backup);
    1837             p += strlen(q);
    1838             while(*p==' ') { p++; }
     1663    if (userdef_filelist) {
     1664        log_msg(1,
     1665                "Using the user-specified filelist - %s - instead of calculating one",
     1666                userdef_filelist);
     1667        sprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
     1668        if (run_program_and_log_output(command, 3)) {
     1669            fatal_error("Failed to copy user-specified filelist");
     1670        }
     1671    } else {
     1672        log_msg(2, "include_paths = '%s'", include_paths);
     1673        log_msg(1, "Calculating filelist");
     1674        sprintf(exclude_paths, " %s %s %s %s %s %s . .. \
     1675" MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \
     1676/proc /sys /tmp /root/images/mondo /root/images/mindi ", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1677
     1678        log_msg(2, "Excluding paths = '%s'", exclude_paths);
     1679        log_msg(2,
     1680                "Generating skeleton filelist so that we can track our progress");
     1681        sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
     1682        make_hole_for_file(g_skeleton_filelist);
     1683        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
     1684        log_msg(2, "Opening out filelist to %s", sz_filelist);
     1685        if (!(fout = fopen(sz_filelist, "w"))) {
     1686            fatal_error("Cannot openout to sz_filelist");
     1687        }
     1688        i = 0;
     1689        if (strlen(include_paths) == 0) {
     1690            log_msg(1, "Including only '/' in %s", sz_filelist);
     1691            open_and_list_dir("/", exclude_paths, fout,
     1692                              time_of_last_full_backup);
     1693        } else {
     1694            p = include_paths;
     1695            while (*p) {
     1696                q = next_entry(p);
     1697                log_msg(1, "Including %s in filelist %s", q, sz_filelist);
     1698                open_and_list_dir(q, exclude_paths, fout,
     1699                                  time_of_last_full_backup);
     1700                p += strlen(q);
     1701                while (*p == ' ') {
     1702                    p++;
     1703                }
    18391704            }
    18401705        }
    1841     paranoid_fclose(fout);
    1842     }
    1843   log_msg(2, "Copying new filelist to scratchdir");
    1844   sprintf(command, "mkdir -p %s/archives", scratchdir);
    1845   paranoid_system(command);
    1846   sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
    1847   paranoid_system(command);
    1848   sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
    1849   paranoid_system(command);
    1850   log_msg(2, "Freeing variables");
    1851   paranoid_free(sz_filelist);
    1852   paranoid_free(command);
    1853   paranoid_free(exclude_paths);
    1854   paranoid_free(tmp);
    1855   paranoid_free(g_skeleton_filelist);
    1856   log_msg(2, "Exiting");
    1857   return(0);
     1706        paranoid_fclose(fout);
     1707    }
     1708    log_msg(2, "Copying new filelist to scratchdir");
     1709    sprintf(command, "mkdir -p %s/archives", scratchdir);
     1710    paranoid_system(command);
     1711    sprintf(command, "cp -f %s %s/archives/", sz_filelist, scratchdir);
     1712    paranoid_system(command);
     1713    sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
     1714    paranoid_system(command);
     1715    log_msg(2, "Freeing variables");
     1716    paranoid_free(sz_filelist);
     1717    paranoid_free(command);
     1718    paranoid_free(exclude_paths);
     1719    paranoid_free(tmp);
     1720    paranoid_free(g_skeleton_filelist);
     1721    log_msg(2, "Exiting");
     1722    return (0);
    18581723}
    18591724
     
    18681733 * it was not found.
    18691734 */
    1870 struct s_node *find_string_at_node (struct s_node *startnode, char *string_to_find)
    1871 {
    1872     /*@ int *********************************************************/
    1873   int noof_chars;
    1874   static int depth=0;
    1875   static char original_string[MAX_STR_LEN];
    1876 
    1877     /*@ sturctures **************************************************/
    1878   struct s_node *node;
    1879 
    1880     /*@ char  *******************************************************/
    1881   char char_to_find;
    1882 
    1883     /*@ bools *******************************************************/
    1884 
    1885   if (!depth) { strcpy(original_string, string_to_find); }
    1886 
    1887   assert(startnode!=NULL);
    1888   assert(string_to_find!=NULL);
    1889 
    1890   noof_chars = strlen (string_to_find) + 1; /* we include the '\0' */
    1891 
    1892   log_msg(7, "starting --- str=%s", string_to_find);
     1735struct s_node *find_string_at_node(struct s_node *startnode,
     1736                                   char *string_to_find)
     1737{
     1738    /*@ int ******************************************************** */
     1739    int noof_chars;
     1740    static int depth = 0;
     1741    static char original_string[MAX_STR_LEN];
     1742
     1743    /*@ sturctures ************************************************* */
     1744    struct s_node *node;
     1745
     1746    /*@ char  ****************************************************** */
     1747    char char_to_find;
     1748
     1749    /*@ bools ****************************************************** */
     1750
     1751    if (!depth) {
     1752        strcpy(original_string, string_to_find);
     1753    }
     1754
     1755    assert(startnode != NULL);
     1756    assert(string_to_find != NULL);
     1757
     1758    noof_chars = strlen(string_to_find) + 1;    /* we include the '\0' */
     1759
     1760    log_msg(7, "starting --- str=%s", string_to_find);
    18931761
    18941762/* walk across tree if necessary */
    1895   node = startnode;
    1896   char_to_find = string_to_find[0];
    1897   if (node->right != NULL && node->ch < char_to_find)
    1898     {
    1899       log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth, char_to_find, node->ch, (node->right)->ch);
    1900       return (find_string_at_node (node->right, string_to_find));
    1901     }
     1763    node = startnode;
     1764    char_to_find = string_to_find[0];
     1765    if (node->right != NULL && node->ch < char_to_find) {
     1766        log_msg(7, "depth=%d --- going RIGHT ... %c-->%c", depth,
     1767                char_to_find, node->ch, (node->right)->ch);
     1768        return (find_string_at_node(node->right, string_to_find));
     1769    }
    19021770
    19031771/* walk down tree if appropriate */
    1904   if (node->down != NULL && node->ch == char_to_find)
    1905     {
    1906       log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
    1907       depth++;
    1908       node = find_string_at_node (node->down, string_to_find + 1);
    1909       depth--;
    1910       return (node);
    1911     }
    1912 
    1913   if (char_to_find == '\0' && node->ch =='\0')
    1914     {
    1915       log_msg(7, "%s is in tree", original_string);
    1916       return(node);
    1917     }
    1918   else
    1919     {
    1920       log_msg(7, "%s is NOT in tree", original_string);
    1921       return(NULL);
    1922     }
     1772    if (node->down != NULL && node->ch == char_to_find) {
     1773        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_find);
     1774        depth++;
     1775        node = find_string_at_node(node->down, string_to_find + 1);
     1776        depth--;
     1777        return (node);
     1778    }
     1779
     1780    if (char_to_find == '\0' && node->ch == '\0') {
     1781        log_msg(7, "%s is in tree", original_string);
     1782        return (node);
     1783    } else {
     1784        log_msg(7, "%s is NOT in tree", original_string);
     1785        return (NULL);
     1786    }
    19231787}
    19241788
     
    19331797 * @return The number of matches found.
    19341798 */
    1935 long save_filelist_entries_in_common(
    1936             char*needles_list_fname,
    1937             struct s_node *filelist,
    1938             char*matches_list_fname, bool use_star)
    1939 {
    1940   int retval=0;
    1941   struct s_node *found_node;
    1942   FILE*fin;
    1943   FILE*fout;
    1944   char *fname;
    1945   char *tmp;
    1946   size_t len = 0; // Scrub's patch doesn't work without that
     1799long save_filelist_entries_in_common(char *needles_list_fname,
     1800                                     struct s_node *filelist,
     1801                                     char *matches_list_fname,
     1802                                    bool use_star)
     1803{
     1804    int retval = 0;
     1805    struct s_node *found_node;
     1806    FILE *fin;
     1807    FILE *fout;
     1808    char *fname = NULL;
     1809    char *tmp;
     1810    size_t len = 0;             // Scrub's patch doesn't work without that
    19471811
    19481812//  log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1949   malloc_string(fname);
    1950   malloc_string(tmp);
    1951   log_msg(5, "starting");
    1952   log_msg(5, "needles_list_fname = %s", needles_list_fname);
    1953   log_msg(5, "matches_list_fname = %s", matches_list_fname);
    1954   if (!(fin = fopen(needles_list_fname, "r"))) { fatal_error("Cannot openin needles_list_fname"); }
    1955   if (!(fout= fopen(matches_list_fname, "w"))) { fatal_error("Cannot openout matches_list_fname"); }
    1956   while(!feof(fin))
    1957     {
    1958 //      fscanf(fin, "%s\n", fname);
    1959       len = MAX_STR_LEN-1;
    1960       getline(& fname, & len, fin); // patch by Scrub
    1961       if (!use_star)
    1962         {
    1963       if (fname[0]=='/')
    1964         { strcpy(tmp, fname); }
    1965       else
    1966         {
    1967           tmp[0]='/';
    1968           strcpy(tmp+1, fname);
    1969         }
    1970       strcpy(fname, tmp);
    1971         }
    1972       while (strlen(fname)>0 && fname[strlen(fname)-1]<32) { fname[strlen(fname)-1] = '\0'; }
     1813    log_msg(5, "starting");
     1814    log_msg(5, "needles_list_fname = %s", needles_list_fname);
     1815    log_msg(5, "matches_list_fname = %s", matches_list_fname);
     1816    if (!(fin = fopen(needles_list_fname, "r"))) {
     1817        fatal_error("Cannot openin needles_list_fname");
     1818    }
     1819    if (!(fout = fopen(matches_list_fname, "w"))) {
     1820        fatal_error("Cannot openout matches_list_fname");
     1821    }
     1822    while (!feof(fin)) {
     1823        getline(&fname, &len, fin);
     1824        if (!use_star) {
     1825            if (fname[0] == '/') {
     1826                asprintf(&tmp, fname);
     1827            } else {
     1828                asprintf(&tmp, "/%s", fname);
     1829            }
     1830            paranoid_free(fname);
     1831            asprintf(&fname, tmp);
     1832            paranoid_free(tmp);
     1833        }
     1834        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
     1835            fname[strlen(fname) - 1] = '\0';
     1836        }
    19731837
    19741838/*
     
    19771841      sprintf(temporary_string, "echo \"Looking for '%s'\" >> /tmp/looking.txt", fname);
    19781842      system(temporary_string);
    1979 */     
    1980      
    1981       log_msg(5, "Looking for '%s'", fname);
    1982       found_node = find_string_at_node(filelist, fname);
    1983       if (found_node)
    1984         {
    1985       if (found_node->selected)
    1986         {
    1987 //              if (use_star)
    1988               if (fname[0]=='/')
    1989             {
    1990           strcpy(tmp, fname+1);
    1991           strcpy(fname, tmp);
    1992         }
    1993           log_msg(5, "Found '%s'", fname);
    1994           turn_wildcard_chars_into_literal_chars(tmp, fname);
    1995           fprintf(fout, "%s\n", tmp);
    1996           retval++;
    1997         }
    1998     }
    1999     }
    2000   paranoid_fclose(fout);
    2001   paranoid_fclose(fin);
    2002   paranoid_free(fname);
    2003   paranoid_free(tmp);
    2004   return(retval);
     1843*/
     1844
     1845        log_msg(5, "Looking for '%s'", fname);
     1846        found_node = find_string_at_node(filelist, fname);
     1847        if (found_node) {
     1848            if (found_node->selected) {
     1849                if (fname[0] == '/') {
     1850                    asprintf(&tmp, fname + 1);
     1851                    paranoid_free(fname);
     1852                    asprintf(&fname, tmp);
     1853                    paranoid_free(tmp);
     1854                }
     1855                log_msg(5, "Found '%s'", fname);
     1856                turn_wildcard_chars_into_literal_chars(tmp, fname);
     1857                fprintf(fout, "%s\n", tmp);
     1858                retval++;
     1859            }
     1860        }
     1861    paranoid_free(fname);
     1862    }
     1863    paranoid_fclose(fout);
     1864    paranoid_fclose(fin);
     1865    return (retval);
    20051866}
    20061867
     
    20181879 * @return 0 for success, nonzero for failure.
    20191880 */
    2020 int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em)
    2021 {
    2022   FILE*fin;
    2023   char*tmp;
    2024   struct s_node *nod;
    2025 
    2026   malloc_string(tmp);
    2027   log_msg(3, "Adding %s to filelist", list_of_files_fname);
    2028   if (!(fin=fopen(list_of_files_fname,"r"))) { iamhere(list_of_files_fname); return(1); }
    2029   for (fgets (tmp, MAX_STR_LEN, fin); !feof(fin);
    2030        fgets (tmp, MAX_STR_LEN, fin))
    2031     {
    2032       if (!tmp[0]) { continue; }
    2033       if ((tmp[strlen(tmp)-1]==13 || tmp[strlen(tmp)-1]==10) && strlen(tmp)>0)
    2034         { tmp[strlen(tmp)-1] = '\0'; }
    2035       log_msg(2, "tmp = '%s'", tmp);
    2036       if (!tmp[0]) { continue; }
    2037       if ((nod = find_string_at_node (filelist, tmp)))
    2038         {
    2039       log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
    2040         }
    2041       else
    2042         {
    2043       add_string_at_node (filelist, tmp);
    2044           nod = find_string_at_node (filelist, tmp);
    2045         }
    2046 
    2047       if (nod && flag_em)
    2048         {
    2049       toggle_path_selection(filelist, tmp, TRUE);
    2050       log_msg (5, "Flagged '%s'", tmp);
    2051     }
    2052     }
    2053   paranoid_fclose(fin);
    2054   paranoid_free(tmp);
    2055   return(0);
     1881int add_list_of_files_to_filelist(struct s_node *filelist,
     1882                                  char *list_of_files_fname, bool flag_em)
     1883{
     1884    FILE *fin;
     1885    char *tmp;
     1886    struct s_node *nod;
     1887
     1888    malloc_string(tmp);
     1889    log_msg(3, "Adding %s to filelist", list_of_files_fname);
     1890    if (!(fin = fopen(list_of_files_fname, "r"))) {
     1891        iamhere(list_of_files_fname);
     1892        return (1);
     1893    }
     1894    for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     1895         fgets(tmp, MAX_STR_LEN, fin)) {
     1896        if (!tmp[0]) {
     1897            continue;
     1898        }
     1899        if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
     1900            && strlen(tmp) > 0) {
     1901            tmp[strlen(tmp) - 1] = '\0';
     1902        }
     1903        log_msg(2, "tmp = '%s'", tmp);
     1904        if (!tmp[0]) {
     1905            continue;
     1906        }
     1907        if ((nod = find_string_at_node(filelist, tmp))) {
     1908            log_msg(5, "Found '%s' in filelist already. Cool.", tmp);
     1909        } else {
     1910            add_string_at_node(filelist, tmp);
     1911            nod = find_string_at_node(filelist, tmp);
     1912        }
     1913
     1914        if (nod && flag_em) {
     1915            toggle_path_selection(filelist, tmp, TRUE);
     1916            log_msg(5, "Flagged '%s'", tmp);
     1917        }
     1918    }
     1919    paranoid_fclose(fin);
     1920    paranoid_free(tmp);
     1921    return (0);
    20561922}
    20571923
  • trunk/mondo/mondo/common/libmondo-mountlist.c

    r48 r49  
    914914    int items;
    915915    int j;
    916     int n = 0;
     916    size_t n = 0;
    917917
    918918    assert(mountlist != NULL);
  • trunk/mondo/mondo/common/libmondo-string.c

    r45 r49  
    128128    assert(input != NULL);
    129129
    130     asprintf(tmp, "%s", input);
     130    asprintf(&tmp, "%s", input);
    131131    if (strlen(tmp) > 6) {
    132132        asprintf(&pos_w_commas, "%s", tmp);
     
    250250    assert(width > 2);
    251251
    252     asprintf(output, "%s", incoming);
     252    asprintf(&output, "%s", incoming);
    253253    for (i = (int) strlen(output); i < width; i++) {
    254254        output[i] = ' ';
  • trunk/mondo/mondo/common/libmondo-tools.c

    r30 r49  
    11/* libmondo-tools.c                                  misc tools
    2    $Id: libmondo-tools.c,v 1.14 2004/06/19 01:36:07 hugo Exp $
     2   $Id$
    33.
    44
     
    186186
    187187/*@unused@*/
    188 //static char cvsid[] = "$Id: libmondo-tools.c,v 1.14 2004/06/19 01:36:07 hugo Exp $";
     188//static char cvsid[] = "$Id$";
    189189
    190190extern int g_tape_buffer_size_MB;
     
    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 ()
     418long get_time()
    423419{
    424420
    425421#if 0
    426422
    427     /*@ pointers *****************************************************/
    428   FILE *fin;
    429 
    430     /*@ buffers ******************************************************/
    431   char incoming[MAX_STR_LEN];
    432 
    433     /*@ end vars *****************************************************/
    434 
    435   if (!(fin = popen ("date +%s", "r"))) { log_OS_error("Cannot popen date"); return(0); }
    436   fgets (incoming, MAX_STR_LEN - 1, fin);
    437   paranoid_pclose (fin);
    438   return (atol (incoming));
     423    /*@ pointers **************************************************** */
     424    FILE *fin;
     425
     426    /*@ buffers ***************************************************** */
     427    char incoming[MAX_STR_LEN];
     428
     429    /*@ end vars **************************************************** */
     430
     431    if (!(fin = popen("date +%s", "r"))) {
     432        log_OS_error("Cannot popen date");
     433        return (0);
     434    }
     435    fgets(incoming, MAX_STR_LEN - 1, fin);
     436    paranoid_pclose(fin);
     437    return (atol(incoming));
    439438#else
    440   return (long) time ((void *) 0);
     439    return (long) time((void *) 0);
    441440#endif
    442441}
     
    456455 */
    457456#ifdef __FreeBSD__
    458 void initialize_raidrec (struct vinum_volume *raidrec)
    459 {
    460   int i, j;
    461   raidrec->volname[0] = '\0';
    462   raidrec->plexes = 0;
    463   for (i = 0; i < 9; ++i) {
    464     raidrec->plex[i].raidlevel = -1;
    465     raidrec->plex[i].stripesize = 0;
    466     raidrec->plex[i].subdisks = 0;
    467     for (j = 0; j < 9; ++j) {
    468        strcpy (raidrec->plex[i].sd[j].which_device, "");
    469     }
    470   }
     457void initialize_raidrec(struct vinum_volume *raidrec)
     458{
     459    int i, j;
     460    raidrec->volname[0] = '\0';
     461    raidrec->plexes = 0;
     462    for (i = 0; i < 9; ++i) {
     463        raidrec->plex[i].raidlevel = -1;
     464        raidrec->plex[i].stripesize = 0;
     465        raidrec->plex[i].subdisks = 0;
     466        for (j = 0; j < 9; ++j) {
     467            strcpy(raidrec->plex[i].sd[j].which_device, "");
     468        }
     469    }
    471470}
    472471#else
    473 void initialize_raidrec (struct raid_device_record *raidrec)
    474 {
    475   assert(raidrec!=NULL);
    476   raidrec->raid_device[0] = '\0';
    477   raidrec->raid_level = 0;
    478   raidrec->chunk_size = 4;
    479   raidrec->persistent_superblock = 1;
    480   raidrec->data_disks.entries = 0;
    481   raidrec->spare_disks.entries = 0;
    482   raidrec->parity_disks.entries = 0;
    483   raidrec->failed_disks.entries = 0;
    484   raidrec->additional_vars.entries = 0;
     472void initialize_raidrec(struct raid_device_record *raidrec)
     473{
     474    assert(raidrec != NULL);
     475    raidrec->raid_device[0] = '\0';
     476    raidrec->raid_level = 0;
     477    raidrec->chunk_size = 4;
     478    raidrec->persistent_superblock = 1;
     479    raidrec->data_disks.entries = 0;
     480    raidrec->spare_disks.entries = 0;
     481    raidrec->parity_disks.entries = 0;
     482    raidrec->failed_disks.entries = 0;
     483    raidrec->additional_vars.entries = 0;
    485484}
    486485#endif
     
    497496{
    498497#ifdef __FreeBSD__
    499   system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
    500   system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
     498    system("kldstat | grep msdosfs || kldload msdosfs 2> /dev/null");
     499    system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
    501500#else
    502   system("modprobe dos &> /dev/null");
    503   system("modprobe fat &> /dev/null");
    504   system("modprobe vfat &> /dev/null");
    505   //  system("modprobe osst &> /dev/null");
     501    system("modprobe dos &> /dev/null");
     502    system("modprobe fat &> /dev/null");
     503    system("modprobe vfat &> /dev/null");
     504    //  system("modprobe osst &> /dev/null");
    506505#endif
    507506}
     
    512511 * @bug This function seems orphaned. Please remove.
    513512 */
    514 void
    515 log_trace (char *o)
    516 {
    517     /*@ pointers *****************************************************/
    518   FILE *fout;
    519 
    520     /*@ buffers ******************************************************/
    521   char output[MAX_STR_LEN];
    522 
    523     /*@ int    *******************************************************/
    524   int i;
    525 
    526     /*@ end vars ****************************************************/
    527 
    528   if (o[0] == '\0')
    529     {
    530       return;
    531     }
    532   strcpy (output, o);
    533   i = (int) strlen (output);
    534   if (i <= 0)
    535     {
    536       return;
    537     }
    538   if (output[i - 1] < 32)
    539     {
    540       output[i - 1] = '\0';
    541     }
    542   if (g_text_mode /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ )
    543     {
    544       printf ("%s\n", output);
    545     }
    546 
    547   fout = fopen (MONDO_TRACEFILE, "a");
    548   if (fout)
    549     {
    550       fprintf (fout, "%s\n", output);
    551       paranoid_fclose (fout);
    552     }
    553   else
    554     {
    555       log_OS_error( "Cannot write to tracefile" );
    556     }
     513void log_trace(char *o)
     514{
     515    /*@ pointers **************************************************** */
     516    FILE *fout;
     517
     518    /*@ buffers ***************************************************** */
     519    char output[MAX_STR_LEN];
     520
     521    /*@ int    ****************************************************** */
     522    int i;
     523
     524    /*@ end vars *************************************************** */
     525
     526    if (o[0] == '\0') {
     527        return;
     528    }
     529    strcpy(output, o);
     530    i = (int) strlen(output);
     531    if (i <= 0) {
     532        return;
     533    }
     534    if (output[i - 1] < 32) {
     535        output[i - 1] = '\0';
     536    }
     537    if (g_text_mode
     538        /* && !strstr(last_line_of_file(MONDO_LOGFILE),output) */ ) {
     539        printf("%s\n", output);
     540    }
     541
     542    fout = fopen(MONDO_TRACEFILE, "a");
     543    if (fout) {
     544        fprintf(fout, "%s\n", output);
     545        paranoid_fclose(fout);
     546    } else {
     547        log_OS_error("Cannot write to tracefile");
     548    }
    557549}
    558550
     
    592584 * do not exist.
    593585 */
    594 int post_param_configuration (struct s_bkpinfo *bkpinfo)
    595 {
    596   char *extra_cdrom_params;
    597   char *mondo_mkisofs_sz;
    598   char *command;
    599   char *mtpt;
    600   char *hostname, *ip_address;
    601   int retval=0;
    602   long avm = 0;
    603   char *colon;
    604   char *cdr_exe;
    605   char *tmp;
    606   int rdsiz_MB;
    607       char *iso_dev;
    608       char *iso_mnt;
    609       char *iso_tmp;
    610       char *iso_path;
    611 
    612   assert(bkpinfo!=NULL);
    613   malloc_string(extra_cdrom_params);
    614   malloc_string(mondo_mkisofs_sz);
    615   malloc_string(command);
    616   malloc_string(mtpt);
    617   malloc_string(hostname);
    618   malloc_string(ip_address);
    619   malloc_string(cdr_exe);
    620   malloc_string(tmp);
    621       malloc_string(iso_dev);
    622       malloc_string(iso_mnt);
    623       malloc_string(iso_tmp);
    624       malloc_string(iso_path);
    625   bkpinfo->optimal_set_size = (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)?4:8) * 1024;
    626 
    627   log_msg(1, "Foo");
    628   if (bkpinfo->backup_media_type == tape)
    629     {
    630       log_msg(1, "Bar");
    631       sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    632       log_msg(1, "tmp = '%s'", tmp);
    633       if (run_program_and_log_output(tmp, 3))
    634         {
    635           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.");
    636     }
    637     }   
    638   make_hole_for_dir(bkpinfo->scratchdir);
    639   make_hole_for_dir(bkpinfo->tmpdir);
    640   if (bkpinfo->backup_media_type == iso)
    641       make_hole_for_dir(bkpinfo->isodir);
    642 
    643   run_program_and_log_output ("uname -a", 5);
    644   run_program_and_log_output ("cat /etc/*issue*", 5);
    645   sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
    646   sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
    647   paranoid_system(command);
    648   rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
     586int post_param_configuration(struct s_bkpinfo *bkpinfo)
     587{
     588    char *extra_cdrom_params;
     589    char *mondo_mkisofs_sz;
     590    char *command;
     591    char *mtpt;
     592    char *hostname, *ip_address;
     593    int retval = 0;
     594    long avm = 0;
     595    char *colon;
     596    char *cdr_exe;
     597    char *tmp;
     598    int rdsiz_MB;
     599    char *iso_dev;
     600    char *iso_mnt;
     601    char *iso_tmp;
     602    char *iso_path;
     603
     604    assert(bkpinfo != NULL);
     605    malloc_string(extra_cdrom_params);
     606    malloc_string(mondo_mkisofs_sz);
     607    malloc_string(command);
     608    malloc_string(mtpt);
     609    malloc_string(hostname);
     610    malloc_string(ip_address);
     611    malloc_string(cdr_exe);
     612    malloc_string(tmp);
     613    malloc_string(iso_dev);
     614    malloc_string(iso_mnt);
     615    malloc_string(iso_tmp);
     616    malloc_string(iso_path);
     617    bkpinfo->optimal_set_size =
     618        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 4 : 8) *
     619        1024;
     620
     621    log_msg(1, "Foo");
     622    if (bkpinfo->backup_media_type == tape) {
     623        log_msg(1, "Bar");
     624        sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
     625        log_msg(1, "tmp = '%s'", tmp);
     626        if (run_program_and_log_output(tmp, 3)) {
     627            fatal_error
     628                ("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.");
     629        }
     630    }
     631    make_hole_for_dir(bkpinfo->scratchdir);
     632    make_hole_for_dir(bkpinfo->tmpdir);
     633    if (bkpinfo->backup_media_type == iso)
     634        make_hole_for_dir(bkpinfo->isodir);
     635
     636    run_program_and_log_output("uname -a", 5);
     637    run_program_and_log_output("cat /etc/*issue*", 5);
     638    sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
     639    sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
     640    paranoid_system(command);
     641    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    649642#ifdef __FreeBSD__
    650   strcpy(tmp, call_program_and_get_last_line_of_output("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
    651   avm += atol (tmp);
    652   strcpy(tmp, call_program_and_get_last_line_of_output("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
    653   avm += atol (tmp);
    654   sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm', g_tmpfs_mountpt);
     643    strcpy(tmp,
     644           call_program_and_get_last_line_of_output
     645           ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
     646    avm += atol(tmp);
     647    strcpy(tmp,
     648           call_program_and_get_last_line_of_output
     649           ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
     650    avm += atol(tmp);
     651    sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
     652            g_tmpfs_mountpt);
    655653#else
    656   strcpy(tmp, call_program_and_get_last_line_of_output("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
    657   avm += atol (tmp);
    658   sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c", g_tmpfs_mountpt, rdsiz_MB, 'm');
    659   run_program_and_log_output ("cat /proc/cpuinfo", 5);
    660   run_program_and_log_output ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc", 5);
    661 #endif
    662   if (avm/1024 > rdsiz_MB*3)
    663     {
    664       if (run_program_and_log_output(command, 5))
     654    strcpy(tmp,
     655           call_program_and_get_last_line_of_output
     656           ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
     657    avm += atol(tmp);
     658    sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
     659            g_tmpfs_mountpt, rdsiz_MB, 'm');
     660    run_program_and_log_output("cat /proc/cpuinfo", 5);
     661    run_program_and_log_output
     662        ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
     663         5);
     664#endif
     665    if (avm / 1024 > rdsiz_MB * 3) {
     666        if (run_program_and_log_output(command, 5)) {
     667            g_tmpfs_mountpt[0] = '\0';
     668            log_it("Failed to mount tmpfs");
     669        } else {
     670            log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
     671        }
     672    } else {
     673        g_tmpfs_mountpt[0] = '\0';
     674        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
     675    }
     676
     677    if (bkpinfo->use_lzo) {
     678        strcpy(bkpinfo->zip_exe, "lzop");
     679        strcpy(bkpinfo->zip_suffix, "lzo");
     680    } else if (bkpinfo->compression_level != 0) {
     681        strcpy(bkpinfo->zip_exe, "bzip2");
     682        strcpy(bkpinfo->zip_suffix, "bz2");
     683    } else {
     684        bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
     685    }
     686
     687// DVD
     688
     689    if (bkpinfo->backup_media_type == dvd) {
     690        extra_cdrom_params[0] = '\0';
     691        mondo_mkisofs_sz[0] = '\0';
     692        if (find_home_of_exe("growisofs")) {
     693            strcpy(cdr_exe, "growisofs");
     694        }                       // unlikely to be used
     695        else {
     696            fatal_error("Please install growisofs.");
     697        }
     698        if (bkpinfo->nonbootable_backup) {
     699            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     700        } else if
     701#ifdef __FreeBSD__
     702            (TRUE)
     703#else
     704            (bkpinfo->make_cd_use_lilo)
     705#endif
     706#ifdef __IA64__
    665707    {
    666       g_tmpfs_mountpt[0] = '\0';
    667       log_it("Failed to mount tmpfs");
    668     }
    669       else
     708        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     709    }
     710#else
    670711    {
    671       log_it("Tmpfs mounted OK - %d MB", rdsiz_MB);
    672     }
    673     }
    674   else
    675     {
    676       g_tmpfs_mountpt[0] = '\0';
    677       log_it ("It doesn't seem you have enough swap to use tmpfs. Fine.");
    678     }
    679 
    680   if (bkpinfo->use_lzo)
    681     {
    682       strcpy (bkpinfo->zip_exe, "lzop");
    683       strcpy (bkpinfo->zip_suffix, "lzo");
    684     }
    685   else if (bkpinfo->compression_level!=0)
    686     {
    687       strcpy (bkpinfo->zip_exe, "bzip2");
    688       strcpy (bkpinfo->zip_suffix, "bz2");
    689     }
    690   else
    691     {
    692       bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
    693     }
    694 
    695 // DVD
    696 
    697   if (bkpinfo->backup_media_type == dvd)
    698       {
    699       extra_cdrom_params[0] = '\0';
    700       mondo_mkisofs_sz[0] = '\0';
    701       if (find_home_of_exe("growisofs"))
    702     { strcpy(cdr_exe, "growisofs"); } // unlikely to be used
    703       else
    704         { fatal_error("Please install growisofs."); }
    705       if (bkpinfo->nonbootable_backup)
    706         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); }
    707       else if
     712        strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     713    }
     714#endif
     715        else
     716        {
     717            strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     718        }
     719        if (bkpinfo->manual_cd_tray) {
     720            fatal_error("Manual CD tray + DVD not supported yet.");
     721            // -m isn't supported by growisofs, BTW...
     722        } else {
     723            sprintf(bkpinfo->call_make_iso,
     724                    "%s %s -Z %s . 2>> _ERR_",
     725                    mondo_mkisofs_sz,
     726                    extra_cdrom_params, bkpinfo->media_device);
     727        }
     728        log_msg(2, "call_make_iso (DVD res) is ... %s",
     729                bkpinfo->call_make_iso);
     730    }                           // end of DVD code
     731
     732// CD-R or CD-RW
     733    if (bkpinfo->backup_media_type == cdrw
     734        || bkpinfo->backup_media_type == cdr) {
     735        extra_cdrom_params[0] = '\0';
     736        if (!bkpinfo->manual_cd_tray) {
     737            strcat(extra_cdrom_params, "-waiti ");
     738        }
     739        if (bkpinfo->backup_media_type == cdrw) {
     740            strcat(extra_cdrom_params, "blank=fast ");
     741        }
     742        if (find_home_of_exe("cdrecord")) {
     743            strcpy(cdr_exe, "cdrecord");
     744        } else if (find_home_of_exe("dvdrecord")) {
     745            strcpy(cdr_exe, "dvdrecord");
     746        } else {
     747            fatal_error("Please install either cdrecord or dvdrecord.");
     748        }
     749        if (bkpinfo->nonbootable_backup) {
     750            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     751        } else if
    708752#ifdef __FreeBSD__
    709         (TRUE)
     753            (TRUE)
    710754#else
    711         (bkpinfo->make_cd_use_lilo)
     755            (bkpinfo->make_cd_use_lilo)
    712756#endif
    713757#ifdef __IA64__
    714         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); }
     758    {
     759        strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     760    }
    715761#else
    716         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); }
    717 #endif
    718       else
    719         { strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); }
    720       if (bkpinfo->manual_cd_tray)
    721762    {
    722       fatal_error("Manual CD tray + DVD not supported yet.");
    723       // -m isn't supported by growisofs, BTW...
    724     }
    725       else
    726     {
    727       sprintf (bkpinfo->call_make_iso,
    728            "%s %s -Z %s . 2>> _ERR_",
    729            mondo_mkisofs_sz,
    730            extra_cdrom_params,
    731            bkpinfo->media_device);
    732         }
    733       log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso);
    734     } // end of DVD code
    735 
    736 // CD-R or CD-RW
    737   if (bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr)
    738     {
    739       extra_cdrom_params[0] = '\0';
    740       if (!bkpinfo->manual_cd_tray)
    741     {
    742       strcat (extra_cdrom_params, "-waiti ");
    743     }
    744       if (bkpinfo->backup_media_type == cdrw)
    745     {
    746       strcat (extra_cdrom_params, "blank=fast ");
    747     }
    748       if (find_home_of_exe("cdrecord"))
    749     { strcpy(cdr_exe, "cdrecord"); }
    750       else if (find_home_of_exe("dvdrecord"))
    751     { strcpy(cdr_exe, "dvdrecord"); }
    752       else
    753         { fatal_error("Please install either cdrecord or dvdrecord."); }
    754       if (bkpinfo->nonbootable_backup)
    755         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT); }
    756       else if
    757 #ifdef __FreeBSD__
    758         (TRUE)
    759 #else
    760         (bkpinfo->make_cd_use_lilo)
    761 #endif
    762 #ifdef __IA64__
    763         { strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO); }
    764 #else
    765         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO); }
    766 #endif
    767       else
    768         { strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX); }
    769       if (bkpinfo->manual_cd_tray)
    770     {
    771       sprintf (bkpinfo->call_before_iso,
    772            "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz, bkpinfo->tmpdir);
    773       sprintf (bkpinfo->call_make_iso,
    774            "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
    775            cdr_exe,
    776            (bkpinfo->please_dont_eject)?" ":"-eject",
    777            extra_cdrom_params, bkpinfo->media_device,
    778            bkpinfo->cdrw_speed, bkpinfo->tmpdir);
    779     }
    780       else
    781     {
    782       sprintf (bkpinfo->call_make_iso,
    783            "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
    784            mondo_mkisofs_sz, cdr_exe,
    785            (bkpinfo->please_dont_eject)?" ":"-eject",
    786            extra_cdrom_params, bkpinfo->media_device,
    787            bkpinfo->cdrw_speed);
    788         }
    789     } // end of CD code
    790 
    791   /*
    792   if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
    793     {
    794       sprintf (tmp,
    795            "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
    796            bkpinfo->media_device, bkpinfo->internal_tape_block_size);
    797       if (system(tmp))
    798     {
    799       retval++;
    800       fprintf (stderr,
    801            "Cannot write to tape device. Is the tape set read-only?\n");
    802     }
    803     } // end of tape code
    804   */
    805 
    806 
    807   if (bkpinfo->backup_media_type == iso)
    808     {
     763        strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     764    }
     765#endif
     766        else
     767        {
     768            strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     769        }
     770        if (bkpinfo->manual_cd_tray) {
     771            sprintf(bkpinfo->call_before_iso,
     772                    "%s -o %s/temporary.iso . 2>> _ERR_", mondo_mkisofs_sz,
     773                    bkpinfo->tmpdir);
     774            sprintf(bkpinfo->call_make_iso,
     775                    "%s %s -v %s fs=4m dev=%s speed=%d %s/temporary.iso",
     776                    cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject",
     777                    extra_cdrom_params, bkpinfo->media_device,
     778                    bkpinfo->cdrw_speed, bkpinfo->tmpdir);
     779        } else {
     780            sprintf(bkpinfo->call_make_iso,
     781                    "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -",
     782                    mondo_mkisofs_sz, cdr_exe,
     783                    (bkpinfo->please_dont_eject) ? " " : "-eject",
     784                    extra_cdrom_params, bkpinfo->media_device,
     785                    bkpinfo->cdrw_speed);
     786        }
     787    }                           // end of CD code
     788
     789    /*
     790       if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
     791       {
     792       sprintf (tmp,
     793       "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
     794       bkpinfo->media_device, bkpinfo->internal_tape_block_size);
     795       if (system(tmp))
     796       {
     797       retval++;
     798       fprintf (stderr,
     799       "Cannot write to tape device. Is the tape set read-only?\n");
     800       }
     801       } // end of tape code
     802     */
     803
     804
     805    if (bkpinfo->backup_media_type == iso) {
    809806
    810807/* Patch by Conor Daly <conor.daly@met.ie>
     
    815812 */
    816813
    817       log_it("isodir = %s", bkpinfo->isodir);
    818       sprintf(command, "df %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);
    819       log_it("command = %s", command);
    820       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    821       sprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command));
    822       sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
    823       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    824 
    825       sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);
    826       log_it("command = %s", command);
    827       log_it("res of it = %s", call_program_and_get_last_line_of_output(command));
    828       sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command));
    829       sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
    830       write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));
    831 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    832       sprintf(iso_tmp, "%s", bkpinfo->isodir);
    833       if (strlen(iso_tmp) < strlen(iso_mnt))
    834         {
    835       iso_path[0] = '\0';
    836     }
    837       else
    838         {
    839           sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    840     }
    841       sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
    842       write_one_liner_data_file(tmp, iso_path);
    843 log_it("isodir: %s", iso_path);
     814        log_it("isodir = %s", bkpinfo->isodir);
     815        sprintf(command, "df %s | tail -n1 | cut -d' ' -f1",
     816                bkpinfo->isodir);
     817        log_it("command = %s", command);
     818        log_it("res of it = %s",
     819               call_program_and_get_last_line_of_output(command));
     820        sprintf(iso_dev, "%s",
     821                call_program_and_get_last_line_of_output(command));
     822        sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir);
     823        write_one_liner_data_file(tmp,
     824                                  call_program_and_get_last_line_of_output
     825                                  (command));
     826
     827        sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     828                iso_dev);
     829        log_it("command = %s", command);
     830        log_it("res of it = %s",
     831               call_program_and_get_last_line_of_output(command));
     832        sprintf(iso_mnt, "%s",
     833                call_program_and_get_last_line_of_output(command));
     834        sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir);
     835        write_one_liner_data_file(tmp,
     836                                  call_program_and_get_last_line_of_output
     837                                  (command));
     838        log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
     839        sprintf(iso_tmp, "%s", bkpinfo->isodir);
     840        if (strlen(iso_tmp) < strlen(iso_mnt)) {
     841            iso_path[0] = '\0';
     842        } else {
     843            sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
     844        }
     845        sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir);
     846        write_one_liner_data_file(tmp, iso_path);
     847        log_it("isodir: %s", iso_path);
    844848
    845849/* End patch */
    846     } // end of iso code
    847 
    848   if (bkpinfo->backup_media_type == nfs) {
    849       strcpy (hostname, bkpinfo->nfs_mount);
    850       colon = strchr (hostname, ':');
    851       if (!colon) {
    852       log_it ("nfs mount doesn't have a colon in it");
    853       retval++;
    854       } else {
    855       struct hostent *hent;
    856 
    857       *colon = '\0';
    858       hent = gethostbyname (hostname);
    859       if (!hent) {
    860           log_it ("Can't resolve NFS mount (%s): %s", hostname, hstrerror (h_errno));
    861           retval++;
    862       } else {
    863           strcpy (ip_address, inet_ntoa
    864               ((struct in_addr)*((struct in_addr *)hent->h_addr)));
    865           strcat (ip_address, strchr (bkpinfo->nfs_mount, ':'));
    866           strcpy (bkpinfo->nfs_mount, ip_address);
    867       }
    868       }
    869   }
    870 
    871   log_it("Finished processing incoming params");
    872   if (retval)
    873     {
    874       fprintf (stderr, "Type 'man mondoarchive' for help.\n");
    875     }
    876   sprintf (tmp, "%s", MONDO_TMPISOS);   /* added #define 22 apr 2002 */
    877   if (does_file_exist (tmp))
    878     {
    879       unlink (tmp);
    880     }
    881   if (strlen (bkpinfo->tmpdir) < 2 || strlen (bkpinfo->scratchdir) < 2)
    882     {
    883       log_it ("tmpdir or scratchdir are blank/missing");
    884       retval++;
    885     }
    886   if (bkpinfo->include_paths[0] == '\0')
    887     {
    888     //      fatal_error ("Why no backup path?");
    889     strcpy (bkpinfo->include_paths, "/");
    890     }
    891   chmod(bkpinfo->scratchdir, 0700);
    892   chmod(bkpinfo->tmpdir, 0700);
    893   g_backup_media_type = bkpinfo->backup_media_type;
    894   paranoid_free(mtpt);
    895   paranoid_free(extra_cdrom_params);
    896   paranoid_free(mondo_mkisofs_sz);
    897   paranoid_free(command);
    898   paranoid_free(hostname);
    899   paranoid_free(ip_address);
    900   paranoid_free(cdr_exe);
    901   paranoid_free(tmp);
    902   paranoid_free(iso_dev);
    903   paranoid_free(iso_mnt);
    904   paranoid_free(iso_tmp);
    905   paranoid_free(iso_path);
    906   return(retval);
     850    }                           // end of iso code
     851
     852    if (bkpinfo->backup_media_type == nfs) {
     853        strcpy(hostname, bkpinfo->nfs_mount);
     854        colon = strchr(hostname, ':');
     855        if (!colon) {
     856            log_it("nfs mount doesn't have a colon in it");
     857            retval++;
     858        } else {
     859            struct hostent *hent;
     860
     861            *colon = '\0';
     862            hent = gethostbyname(hostname);
     863            if (!hent) {
     864                log_it("Can't resolve NFS mount (%s): %s", hostname,
     865                       hstrerror(h_errno));
     866                retval++;
     867            } else {
     868                strcpy(ip_address, inet_ntoa
     869                       ((struct in_addr)
     870                        *((struct in_addr *) hent->h_addr)));
     871                strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     872                strcpy(bkpinfo->nfs_mount, ip_address);
     873            }
     874        }
     875    }
     876
     877    log_it("Finished processing incoming params");
     878    if (retval) {
     879        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
     880    }
     881    sprintf(tmp, "%s", MONDO_TMPISOS);  /* added #define 22 apr 2002 */
     882    if (does_file_exist(tmp)) {
     883        unlink(tmp);
     884    }
     885    if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
     886        log_it("tmpdir or scratchdir are blank/missing");
     887        retval++;
     888    }
     889    if (bkpinfo->include_paths[0] == '\0') {
     890        //      fatal_error ("Why no backup path?");
     891        strcpy(bkpinfo->include_paths, "/");
     892    }
     893    chmod(bkpinfo->scratchdir, 0700);
     894    chmod(bkpinfo->tmpdir, 0700);
     895    g_backup_media_type = bkpinfo->backup_media_type;
     896    paranoid_free(mtpt);
     897    paranoid_free(extra_cdrom_params);
     898    paranoid_free(mondo_mkisofs_sz);
     899    paranoid_free(command);
     900    paranoid_free(hostname);
     901    paranoid_free(ip_address);
     902    paranoid_free(cdr_exe);
     903    paranoid_free(tmp);
     904    paranoid_free(iso_dev);
     905    paranoid_free(iso_mnt);
     906    paranoid_free(iso_tmp);
     907    paranoid_free(iso_path);
     908    return (retval);
    907909}
    908910
     
    918920int pre_param_configuration(struct s_bkpinfo *bkpinfo)
    919921{
    920   int res=0;
    921 
    922   make_hole_for_dir(MNT_CDROM);
    923   assert(bkpinfo!=NULL);
    924   srandom ((unsigned long)(time (NULL)));
    925   insmod_crucial_modules();
    926   reset_bkpinfo (bkpinfo); // also sets defaults ('/'=backup path, 3=compression level)
    927   if (bkpinfo->disaster_recovery) {
    928     if (!does_nonMS_partition_exist()) {
    929       fatal_error ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
    930     }
    931   }
    932 
    933   unlink (MONDO_TRACEFILE);
    934   run_program_and_log_output( "rm -Rf /tmp/changed.files*", FALSE);
    935   if (find_and_store_mondoarchives_home(g_mondo_home))
    936     {
    937       fprintf (stderr,
    938            "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");
    939       res++;
    940       return(res);
    941     }
    942   res += some_basic_system_sanity_checks ();
    943   if (res)
    944     {
    945       log_it ("Your distribution did not pass Mondo's sanity test.");
    946     }
    947   g_current_media_number = 1;
    948   bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
    949   return(res);
     922    int res = 0;
     923
     924    make_hole_for_dir(MNT_CDROM);
     925    assert(bkpinfo != NULL);
     926    srandom((unsigned long) (time(NULL)));
     927    insmod_crucial_modules();
     928    reset_bkpinfo(bkpinfo);     // also sets defaults ('/'=backup path, 3=compression level)
     929    if (bkpinfo->disaster_recovery) {
     930        if (!does_nonMS_partition_exist()) {
     931            fatal_error
     932                ("I am in disaster recovery mode\nPlease don't run mondoarchive.");
     933        }
     934    }
     935
     936    unlink(MONDO_TRACEFILE);
     937    run_program_and_log_output("rm -Rf /tmp/changed.files*", FALSE);
     938    if (find_and_store_mondoarchives_home(g_mondo_home)) {
     939        fprintf(stderr,
     940                "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");
     941        res++;
     942        return (res);
     943    }
     944    res += some_basic_system_sanity_checks();
     945    if (res) {
     946        log_it("Your distribution did not pass Mondo's sanity test.");
     947    }
     948    g_current_media_number = 1;
     949    bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
     950    return (res);
    950951}
    951952
     
    957958 * @param bkpinfo The @c bkpinfo to reset.
    958959 */
    959 void
    960 reset_bkpinfo (struct s_bkpinfo *bkpinfo)
    961 {
    962   int i;
    963 
    964   log_msg(1, "Hi");
    965   assert(bkpinfo!=NULL);
    966   memset((void*)bkpinfo, 0, sizeof(struct s_bkpinfo));
    967   bkpinfo->manual_cd_tray = FALSE;
    968   bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    969   bkpinfo->media_device[0] = '\0';
    970   for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = -1; }
    971   bkpinfo->boot_loader = '\0';
    972   bkpinfo->boot_device[0] = '\0';
    973   bkpinfo->zip_exe[0] = '\0';
    974   bkpinfo->zip_suffix[0] = '\0';
    975   bkpinfo->restore_path[0] = '\0';
    976   bkpinfo->use_lzo = FALSE;
    977   bkpinfo->do_not_compress_these[0] = '\0';
    978   bkpinfo->verify_data = FALSE;
    979   bkpinfo->backup_data = FALSE;
    980   bkpinfo->restore_data = FALSE;
    981   bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()?TRUE:FALSE);
    982   if (bkpinfo->disaster_recovery)
    983     { strcpy(bkpinfo->isodir, "/"); }
    984   else
    985     { strcpy (bkpinfo->isodir, "/root/images/mondo"); }
    986   strcpy (bkpinfo->prefix, "mondorescue");
    987 
    988   bkpinfo->scratchdir[0] = '\0';
    989   bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive
    990   sprintf( bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) ( random() %32768 ) ); // for mondorestore
    991   bkpinfo->optimal_set_size = 0;
    992   bkpinfo->backup_media_type = none;
    993   strcpy (bkpinfo->include_paths, "/");
    994   bkpinfo->exclude_paths[0] = '\0';
    995   bkpinfo->call_before_iso[0] = '\0';
    996   bkpinfo->call_make_iso[0] = '\0';
    997   bkpinfo->call_burn_iso[0] = '\0';
    998   bkpinfo->call_after_iso[0] = '\0';
    999   bkpinfo->image_devs[0] = '\0';
    1000   bkpinfo->postnuke_tarball[0] = '\0';
    1001   bkpinfo->kernel_path[0] = '\0';
    1002   bkpinfo->nfs_mount[0] = '\0';
    1003   bkpinfo->nfs_remote_dir[0] = '\0';
    1004   bkpinfo->wipe_media_first = FALSE;
    1005   bkpinfo->differential = FALSE;
    1006   bkpinfo->cdrw_speed = 0;
     960void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
     961{
     962    int i;
     963
     964    log_msg(1, "Hi");
     965    assert(bkpinfo != NULL);
     966    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     967    bkpinfo->manual_cd_tray = FALSE;
     968    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     969    bkpinfo->media_device[0] = '\0';
     970    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     971        bkpinfo->media_size[i] = -1;
     972    }
     973    bkpinfo->boot_loader = '\0';
     974    bkpinfo->boot_device[0] = '\0';
     975    bkpinfo->zip_exe[0] = '\0';
     976    bkpinfo->zip_suffix[0] = '\0';
     977    bkpinfo->restore_path[0] = '\0';
     978    bkpinfo->use_lzo = FALSE;
     979    bkpinfo->do_not_compress_these[0] = '\0';
     980    bkpinfo->verify_data = FALSE;
     981    bkpinfo->backup_data = FALSE;
     982    bkpinfo->restore_data = FALSE;
     983    bkpinfo->disaster_recovery =
     984        (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     985    if (bkpinfo->disaster_recovery) {
     986        strcpy(bkpinfo->isodir, "/");
     987    } else {
     988        strcpy(bkpinfo->isodir, "/root/images/mondo");
     989    }
     990    strcpy(bkpinfo->prefix, "mondorescue");
     991
     992    bkpinfo->scratchdir[0] = '\0';
     993    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
     994    sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768));  // for mondorestore
     995    bkpinfo->optimal_set_size = 0;
     996    bkpinfo->backup_media_type = none;
     997    strcpy(bkpinfo->include_paths, "/");
     998    bkpinfo->exclude_paths[0] = '\0';
     999    bkpinfo->call_before_iso[0] = '\0';
     1000    bkpinfo->call_make_iso[0] = '\0';
     1001    bkpinfo->call_burn_iso[0] = '\0';
     1002    bkpinfo->call_after_iso[0] = '\0';
     1003    bkpinfo->image_devs[0] = '\0';
     1004    bkpinfo->postnuke_tarball[0] = '\0';
     1005    bkpinfo->kernel_path[0] = '\0';
     1006    bkpinfo->nfs_mount[0] = '\0';
     1007    bkpinfo->nfs_remote_dir[0] = '\0';
     1008    bkpinfo->wipe_media_first = FALSE;
     1009    bkpinfo->differential = FALSE;
     1010    bkpinfo->cdrw_speed = 0;
    10071011// patch by Herman Kuster 
    1008   bkpinfo->differential = 0;
     1012    bkpinfo->differential = 0;
    10091013// patch end
    1010   bkpinfo->compression_level = 3;
     1014    bkpinfo->compression_level = 3;
    10111015}
    10121016
     
    10191023 * @return The free space on @p partition, in MB.
    10201024 */
    1021 long free_space_on_given_partition(char*partition)
    1022 {
    1023   char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
    1024   long res;
    1025 
    1026   assert_string_is_neither_NULL_nor_zerolength(partition);
    1027 
    1028   sprintf(command, "df -m %s &> /dev/null", partition);
    1029   if (system(command))
    1030     { return(-1); } // partition does not exist
    1031   sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition);
    1032   strcpy(out_sz, call_program_and_get_last_line_of_output(command));
    1033   if (strlen(out_sz)==0)
    1034     { return(-1); } // error within df, probably
    1035   res = atol(out_sz);
    1036   return(res);
     1025long free_space_on_given_partition(char *partition)
     1026{
     1027    char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
     1028    long res;
     1029
     1030    assert_string_is_neither_NULL_nor_zerolength(partition);
     1031
     1032    sprintf(command, "df -m %s &> /dev/null", partition);
     1033    if (system(command)) {
     1034        return (-1);
     1035    }                           // partition does not exist
     1036    sprintf(command, "df -m %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     1037            partition);
     1038    strcpy(out_sz, call_program_and_get_last_line_of_output(command));
     1039    if (strlen(out_sz) == 0) {
     1040        return (-1);
     1041    }                           // error within df, probably
     1042    res = atol(out_sz);
     1043    return (res);
    10371044}
    10381045
     
    10511058 * @return number of problems with the user's setup (0 for success)
    10521059 */
    1053 int
    1054 some_basic_system_sanity_checks ()
    1055 {
    1056 
    1057     /*@ buffers *************/
    1058   char tmp[MAX_STR_LEN];
    1059   //  char command[MAX_STR_LEN];
    1060 
    1061     /*@ int's ****************/
    1062   int retval = 0;
    1063   long Lres;
    1064 
    1065 
    1066   mvaddstr_and_log_it (g_currentY, 0,
    1067                "Checking sanity of your Linux distribution");
     1060int some_basic_system_sanity_checks()
     1061{
     1062
     1063    /*@ buffers ************ */
     1064    char tmp[MAX_STR_LEN];
     1065    //  char command[MAX_STR_LEN];
     1066
     1067    /*@ int's *************** */
     1068    int retval = 0;
     1069    long Lres;
     1070
     1071
     1072    mvaddstr_and_log_it(g_currentY, 0,
     1073                        "Checking sanity of your Linux distribution");
    10681074#ifndef __FreeBSD__
    1069   if (system("which mkfs.vfat &> /dev/null") && !system("which mkfs.msdos &> /dev/null"))
    1070     {
    1071       log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
    1072       run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    1073     }
    1074   strcpy (tmp,
    1075       call_program_and_get_last_line_of_output
    1076       ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    1077   if (atol (tmp) < 35000)
    1078     {
    1079       retval++;
    1080       log_to_screen ("You must have at least 32MB of RAM to use Mondo.");
    1081     }
    1082   if (atol (tmp) < 66000)
    1083     {
    1084       log_to_screen
    1085     ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    1086     }
    1087 #endif
    1088 
    1089   if ((Lres = free_space_on_given_partition("/root"))==-1)
    1090     { Lres = free_space_on_given_partition("/"); }
    1091   log_it("Free space on given partition = %ld MB", Lres);
    1092 
    1093   if (Lres < 50)
    1094     {
    1095       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);
    1096       //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
    1097     }
    1098 
    1099   if (system ("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null"))
    1100     {
    1101       retval++;
    1102       log_to_screen
    1103     ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
    1104       fatal_error
    1105         ("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. :)");
    1106     }
     1075    if (system("which mkfs.vfat &> /dev/null")
     1076        && !system("which mkfs.msdos &> /dev/null")) {
     1077        log_it
     1078            ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand...");
     1079        run_program_and_log_output
     1080            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
     1081    }
     1082    strcpy(tmp,
     1083           call_program_and_get_last_line_of_output
     1084           ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     1085    if (atol(tmp) < 35000) {
     1086        retval++;
     1087        log_to_screen("You must have at least 32MB of RAM to use Mondo.");
     1088    }
     1089    if (atol(tmp) < 66000) {
     1090        log_to_screen
     1091            ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
     1092    }
     1093#endif
     1094
     1095    if ((Lres = free_space_on_given_partition("/root")) == -1) {
     1096        Lres = free_space_on_given_partition("/");
     1097    }
     1098    log_it("Free space on given partition = %ld MB", Lres);
     1099
     1100    if (Lres < 50) {
     1101        run_program_and_log_output
     1102            ("rm -Rf /root/images/mindi; mkdir -p /home/root/images/mindi; mkdir -p /root/images; ln -sf /home/root/images/mindi /root/images/mindi",
     1103             3);
     1104        //      fatal_error("Your / (or /root) partition has <50MB free. Please adjust your partition table to something saner.");
     1105    }
     1106
     1107    if (system("which " MKE2FS_OR_NEWFS " > /dev/null 2> /dev/null")) {
     1108        retval++;
     1109        log_to_screen
     1110            ("Unable to find " MKE2FS_OR_NEWFS " in system path.");
     1111        fatal_error
     1112            ("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. :)");
     1113    }
    11071114#ifndef __FreeBSD__
    1108   if (run_program_and_log_output ("cat /proc/devices | grep ramdisk", FALSE))
    1109     {
    1110       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?"))
    1111         {
    1112       //          retval++;
    1113           log_to_screen
    1114             ("It looks as if your kernel lacks ramdisk and initrd support.");
    1115       log_to_screen
    1116         ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
    1117         }
    1118     }
    1119 #endif
    1120   retval += whine_if_not_found (MKE2FS_OR_NEWFS);
    1121   retval += whine_if_not_found ("mkisofs");
    1122   if (system("which dvdrecord > /dev/null 2> /dev/null"))
    1123     { retval += whine_if_not_found ("cdrecord"); }
    1124   retval += whine_if_not_found ("bzip2");
    1125   retval += whine_if_not_found ("awk");
    1126   retval += whine_if_not_found ("md5sum");
    1127   retval += whine_if_not_found ("strings");
    1128   retval += whine_if_not_found ("mindi");
    1129   retval += whine_if_not_found ("buffer");
    1130 
    1131   // abort if Windows partition but no ms-sys and parted
    1132   if (!run_program_and_log_output("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0) ||
    1133       !run_program_and_log_output("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0))
    1134     {
    1135       log_to_screen("I think you have a Windows 9x partition.");
    1136       retval += whine_if_not_found ("parted");
     1115    if (run_program_and_log_output
     1116        ("cat /proc/devices | grep ramdisk", FALSE)) {
     1117        if (!ask_me_yes_or_no
     1118            ("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?"))
     1119        {
     1120            //          retval++;
     1121            log_to_screen
     1122                ("It looks as if your kernel lacks ramdisk and initrd support.");
     1123            log_to_screen
     1124                ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
     1125        }
     1126    }
     1127#endif
     1128    retval += whine_if_not_found(MKE2FS_OR_NEWFS);
     1129    retval += whine_if_not_found("mkisofs");
     1130    if (system("which dvdrecord > /dev/null 2> /dev/null")) {
     1131        retval += whine_if_not_found("cdrecord");
     1132    }
     1133    retval += whine_if_not_found("bzip2");
     1134    retval += whine_if_not_found("awk");
     1135    retval += whine_if_not_found("md5sum");
     1136    retval += whine_if_not_found("strings");
     1137    retval += whine_if_not_found("mindi");
     1138    retval += whine_if_not_found("buffer");
     1139
     1140    // abort if Windows partition but no ms-sys and parted
     1141    if (!run_program_and_log_output
     1142        ("mount | grep -w vfat | grep -v /dev/fd | grep -v nexdisk", 0)
     1143        ||
     1144        !run_program_and_log_output
     1145        ("mount | grep -w dos | grep -v /dev/fd | grep -v nexdisk", 0)) {
     1146        log_to_screen("I think you have a Windows 9x partition.");
     1147        retval += whine_if_not_found("parted");
    11371148#ifndef __IA64__
    1138       /* IA64 always has one vfat partition for EFI even without Windows */
    1139       // retval +=
    1140       if (!find_home_of_exe("ms-sys"))
    1141         {
    1142       log_to_screen("Please install ms-sys just in case.");
    1143     }
    1144 #endif
    1145     }
    1146 
    1147   if (!find_home_of_exe("cmp"))
    1148     {
    1149       if (!find_home_of_exe("true"))
    1150         { whine_if_not_found ("cmp"); }
    1151       else
    1152         {
    1153           log_to_screen("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
    1154           if (run_program_and_log_output("cp -f `which true` /usr/bin/cmp", 0))
    1155             { fatal_error("Failed to create dummy 'cmp' file."); }
    1156         }
    1157     }
    1158   run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    1159   strcpy (tmp,
    1160       call_program_and_get_last_line_of_output
    1161       ("mount | grep -E \"cdr(om|w)\""));
    1162   if (strcmp ("", tmp))
    1163     {
    1164     if (strstr (tmp, "autofs")) {
    1165         log_to_screen ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
    1166         log_to_screen ("if a CD actually is inserted. If a CD is inserted, please");
    1167         log_to_screen ("eject it. Thank you.");
    1168         log_it ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
    1169     } else if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
    1170         retval++;
    1171         fatal_error ("Your CD-ROM drive is mounted. Please unmount it.");
    1172     }
    1173     }
     1149        /* IA64 always has one vfat partition for EFI even without Windows */
     1150        // retval +=
     1151        if (!find_home_of_exe("ms-sys")) {
     1152            log_to_screen("Please install ms-sys just in case.");
     1153        }
     1154#endif
     1155    }
     1156
     1157    if (!find_home_of_exe("cmp")) {
     1158        if (!find_home_of_exe("true")) {
     1159            whine_if_not_found("cmp");
     1160        } else {
     1161            log_to_screen
     1162                ("Your system lacks the 'cmp' binary. I'll create a dummy cmp for you.");
     1163            if (run_program_and_log_output
     1164                ("cp -f `which true` /usr/bin/cmp", 0)) {
     1165                fatal_error("Failed to create dummy 'cmp' file.");
     1166            }
     1167        }
     1168    }
     1169    run_program_and_log_output
     1170        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
     1171    strcpy(tmp,
     1172           call_program_and_get_last_line_of_output
     1173           ("mount | grep -E \"cdr(om|w)\""));
     1174    if (strcmp("", tmp)) {
     1175        if (strstr(tmp, "autofs")) {
     1176            log_to_screen
     1177                ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
     1178            log_to_screen
     1179                ("if a CD actually is inserted. If a CD is inserted, please");
     1180            log_to_screen("eject it. Thank you.");
     1181            log_it
     1182                ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
     1183        } else
     1184            if (run_program_and_log_output("uname -a | grep Knoppix", 5)) {
     1185            retval++;
     1186            fatal_error
     1187                ("Your CD-ROM drive is mounted. Please unmount it.");
     1188        }
     1189    }
    11741190#ifndef __FreeBSD__
    1175   if (!does_file_exist ("/etc/modules.conf"))
    1176     {
    1177       if (does_file_exist("/etc/conf.modules"))
    1178         {
    1179           log_it("Linking /etc/modules.conf to /etc/conf.modules");
    1180           run_program_and_log_output("ln -sf /etc/conf.modules /etc/modules.conf", 5);
    1181         }
    1182       else if (does_file_exist("/etc/modprobe.d"))
    1183     {
    1184       log_it("Directory /etc/modprobe.d found. mindi will use its contents.");
    1185     }
    1186       else if (does_file_exist("/etc/modprobe.conf"))
    1187         {
    1188           log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
    1189           run_program_and_log_output("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
    1190     }
    1191       else
    1192         {
    1193           retval++;
    1194           log_to_screen ("Please find out what happened to /etc/modules.conf");
    1195         }
    1196     }
    1197 #endif
    1198 
    1199   run_program_and_log_output("cat /etc/fstab", 5);
     1191    if (!does_file_exist("/etc/modules.conf")) {
     1192        if (does_file_exist("/etc/conf.modules")) {
     1193            log_it("Linking /etc/modules.conf to /etc/conf.modules");
     1194            run_program_and_log_output
     1195                ("ln -sf /etc/conf.modules /etc/modules.conf", 5);
     1196        } else if (does_file_exist("/etc/modprobe.d")) {
     1197            log_it
     1198                ("Directory /etc/modprobe.d found. mindi will use its contents.");
     1199        } else if (does_file_exist("/etc/modprobe.conf")) {
     1200            log_it("Linking /etc/modules.conf to /etc/modprobe.conf");
     1201            run_program_and_log_output
     1202                ("ln -sf /etc/modprobe.conf /etc/modules.conf", 5);
     1203        } else {
     1204            retval++;
     1205            log_to_screen
     1206                ("Please find out what happened to /etc/modules.conf");
     1207        }
     1208    }
     1209#endif
     1210
     1211    run_program_and_log_output("cat /etc/fstab", 5);
    12001212#ifdef __FreeBSD__
    1201   run_program_and_log_output("vinum printconfig", 5);
     1213    run_program_and_log_output("vinum printconfig", 5);
    12021214#else
    1203   run_program_and_log_output("cat /etc/raidtab", 5);
    1204 #endif
    1205 
    1206   if (run_program_and_log_output("mindi -V", 1))
    1207     {
    1208       log_to_screen("Could not ascertain mindi's version number.");
    1209       log_to_screen("You have not installed Mondo and/or Mindi properly.");
    1210       log_to_screen("Please uninstall and reinstall them both.");
    1211       fatal_error("Please reinstall Mondo and Mindi.");
    1212     }
    1213   if (run_program_and_log_output("mindi --makemountlist /tmp/mountlist.txt.test", 5))
    1214     {
    1215       log_to_screen("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
    1216       log_to_screen("Please run that command by hand and examine /var/log/mindi.log");
    1217       log_to_screen("for more information. Perhaps your /etc/fstab file is insane.");
    1218       log_to_screen("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
    1219       retval++;
    1220     }
    1221 
    1222   if (!run_program_and_log_output("fdisk -l | grep -i raid", 1) && !does_file_exist("/etc/raidtab"))
    1223     {
    1224       log_to_screen("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
    1225       create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
    1226     }
    1227  
    1228   if (retval)
    1229     {
    1230       mvaddstr_and_log_it (g_currentY++, 74, "Failed.");
    1231     }
    1232   else
    1233     {
    1234       mvaddstr_and_log_it (g_currentY++, 74, "Done.");
    1235     }
    1236   return (retval);
     1215    run_program_and_log_output("cat /etc/raidtab", 5);
     1216#endif
     1217
     1218    if (run_program_and_log_output("mindi -V", 1)) {
     1219        log_to_screen("Could not ascertain mindi's version number.");
     1220        log_to_screen
     1221            ("You have not installed Mondo and/or Mindi properly.");
     1222        log_to_screen("Please uninstall and reinstall them both.");
     1223        fatal_error("Please reinstall Mondo and Mindi.");
     1224    }
     1225    if (run_program_and_log_output
     1226        ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
     1227        log_to_screen
     1228            ("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
     1229        log_to_screen
     1230            ("Please run that command by hand and examine /var/log/mindi.log");
     1231        log_to_screen
     1232            ("for more information. Perhaps your /etc/fstab file is insane.");
     1233        log_to_screen
     1234            ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
     1235        retval++;
     1236    }
     1237
     1238    if (!run_program_and_log_output("fdisk -l | grep -i raid", 1)
     1239        && !does_file_exist("/etc/raidtab")) {
     1240        log_to_screen
     1241            ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
     1242        create_raidtab_from_mdstat("/etc/raidtab", "/proc/mdstat");
     1243    }
     1244
     1245    if (retval) {
     1246        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1247    } else {
     1248        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1249    }
     1250    return (retval);
    12371251}
    12381252
     
    12441258 * @return 0 for success, 1 for failure.
    12451259 */
    1246 int
    1247 read_cfg_var (char *config_file, char *label, char *value)
    1248 {
    1249     /*@ buffer *******************************************************/
    1250   char command[MAX_STR_LEN*2];
    1251   char tmp[MAX_STR_LEN];
    1252 
    1253     /*@ end vars ****************************************************/
    1254 
    1255   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1256   assert_string_is_neither_NULL_nor_zerolength(label);
    1257   if (!does_file_exist (config_file))
    1258     {
    1259       sprintf (tmp, "(read_cfg_var) Cannot find %s config file", config_file);
    1260       log_to_screen (tmp);
    1261       value[0] = '\0';
    1262       return (1);
    1263     }
    1264   else if (strstr(value, "/dev/") && strstr(value, "t0") && !strcmp(label, "media-dev"))
    1265     {
    1266       log_msg (2, "FYI, I shan't read new value for %s - already got %s", label, value);
    1267       return(0);
    1268     }
    1269   else
    1270     {
    1271       sprintf (command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
    1272            config_file, label);
    1273       strcpy (value, call_program_and_get_last_line_of_output (command));
    1274       if (strlen (value) == 0)
    1275     {
    1276       return (1);
    1277     }
    1278       else
    1279     {
    1280       return (0);
    1281     }
    1282     }
     1260int read_cfg_var(char *config_file, char *label, char *value)
     1261{
     1262    /*@ buffer ****************************************************** */
     1263    char command[MAX_STR_LEN * 2];
     1264    char tmp[MAX_STR_LEN];
     1265
     1266    /*@ end vars *************************************************** */
     1267
     1268    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1269    assert_string_is_neither_NULL_nor_zerolength(label);
     1270    if (!does_file_exist(config_file)) {
     1271        sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
     1272                config_file);
     1273        log_to_screen(tmp);
     1274        value[0] = '\0';
     1275        return (1);
     1276    } else if (strstr(value, "/dev/") && strstr(value, "t0")
     1277               && !strcmp(label, "media-dev")) {
     1278        log_msg(2, "FYI, I shan't read new value for %s - already got %s",
     1279                label, value);
     1280        return (0);
     1281    } else {
     1282        sprintf(command, "cat %s | grep \"%s .*\" | cut -d' ' -f2,3,4,5",
     1283                config_file, label);
     1284        strcpy(value, call_program_and_get_last_line_of_output(command));
     1285        if (strlen(value) == 0) {
     1286            return (1);
     1287        } else {
     1288            return (0);
     1289        }
     1290    }
    12831291}
    12841292
     
    12901298void remount_supermounts_if_necessary()
    12911299{
    1292   if (g_remount_cdrom_at_end)
    1293     {
    1294       run_program_and_log_output ("mount "MNT_CDROM, FALSE);
    1295     }
    1296   if (g_remount_floppy_at_end)
    1297     {
    1298       run_program_and_log_output ("mount "MNT_FLOPPY, FALSE);
    1299     }
     1300    if (g_remount_cdrom_at_end) {
     1301        run_program_and_log_output("mount " MNT_CDROM, FALSE);
     1302    }
     1303    if (g_remount_floppy_at_end) {
     1304        run_program_and_log_output("mount " MNT_FLOPPY, FALSE);
     1305    }
    13001306}
    13011307
     
    13051311void unmount_supermounts_if_necessary()
    13061312{
    1307   if (run_program_and_log_output ("mount | grep cdrom | grep super", FALSE) == 0)
    1308     {
    1309       g_remount_cdrom_at_end = TRUE;
    1310       run_program_and_log_output ("umount "MNT_CDROM, FALSE);
    1311     }
    1312   if (run_program_and_log_output ("mount | grep floppy | grep super", FALSE) == 0)
    1313     {
    1314       g_remount_floppy_at_end = TRUE;
    1315       run_program_and_log_output ("umount "MNT_FLOPPY, FALSE);
    1316     }
     1313    if (run_program_and_log_output
     1314        ("mount | grep cdrom | grep super", FALSE) == 0) {
     1315        g_remount_cdrom_at_end = TRUE;
     1316        run_program_and_log_output("umount " MNT_CDROM, FALSE);
     1317    }
     1318    if (run_program_and_log_output
     1319        ("mount | grep floppy | grep super", FALSE) == 0) {
     1320        g_remount_floppy_at_end = TRUE;
     1321        run_program_and_log_output("umount " MNT_FLOPPY, FALSE);
     1322    }
    13171323}
    13181324
     
    13201326 * Whether we had to stop autofs (if so, restart it at end).
    13211327 */
    1322 bool g_autofs_stopped=FALSE;
     1328bool g_autofs_stopped = FALSE;
    13231329
    13241330/**
     
    13421348void stop_autofs_if_necessary()
    13431349{
    1344   char tmp[MAX_STR_LEN];
    1345  
    1346   g_autofs_exe[0] = '\0';
    1347   if (does_file_exist(XANDROS_AUTOFS_FNAME))
    1348     { strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME); } 
    1349   else if (does_file_exist(STOCK_AUTOFS_FNAME))
    1350     { strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME); }
    1351    
    1352   if (!g_autofs_exe[0]) { log_msg(3, "No autofs detected."); } 
    1353   else
    1354     {
    1355       log_msg(3, "%s --- autofs detected", g_autofs_exe);
     1350    char tmp[MAX_STR_LEN];
     1351
     1352    g_autofs_exe[0] = '\0';
     1353    if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
     1354        strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
     1355    } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
     1356        strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
     1357    }
     1358
     1359    if (!g_autofs_exe[0]) {
     1360        log_msg(3, "No autofs detected.");
     1361    } else {
     1362        log_msg(3, "%s --- autofs detected", g_autofs_exe);
    13561363// FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1357       sprintf(tmp, "%s stop", g_autofs_exe);
    1358       if (run_program_and_log_output(tmp, 2))
    1359         { log_it("Failed to stop autofs - I assume it wasn't running"); }
    1360       else
    1361         { g_autofs_stopped = TRUE; log_it("Stopped autofs OK"); }
    1362     }
     1364        sprintf(tmp, "%s stop", g_autofs_exe);
     1365        if (run_program_and_log_output(tmp, 2)) {
     1366            log_it("Failed to stop autofs - I assume it wasn't running");
     1367        } else {
     1368            g_autofs_stopped = TRUE;
     1369            log_it("Stopped autofs OK");
     1370        }
     1371    }
    13631372}
    13641373
     
    13681377void restart_autofs_if_necessary()
    13691378{
    1370   char tmp[MAX_STR_LEN];
    1371  
    1372   if (!g_autofs_stopped || !g_autofs_exe[0]) { log_msg(3, "No autofs detected."); return; } 
    1373   sprintf(tmp, "%s start", g_autofs_exe);
    1374   if (run_program_and_log_output(tmp, 2))
    1375     { log_it("Failed to start autofs"); }
    1376   else
    1377     { g_autofs_stopped = FALSE; log_it("Started autofs OK"); }
     1379    char tmp[MAX_STR_LEN];
     1380
     1381    if (!g_autofs_stopped || !g_autofs_exe[0]) {
     1382        log_msg(3, "No autofs detected.");
     1383        return;
     1384    }
     1385    sprintf(tmp, "%s start", g_autofs_exe);
     1386    if (run_program_and_log_output(tmp, 2)) {
     1387        log_it("Failed to start autofs");
     1388    } else {
     1389        g_autofs_stopped = FALSE;
     1390        log_it("Started autofs OK");
     1391    }
    13781392}
    13791393
     
    13841398void mount_boot_if_necessary()
    13851399{
    1386   char tmp[MAX_STR_LEN];
    1387   char command[MAX_STR_LEN];
    1388 
    1389   log_msg(1, "Started sub");
    1390   log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
    1391   g_boot_mountpt[0] = '\0';
    1392   log_msg(4, "Done. Great. Seeting command to something");
    1393   strcpy(command, "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    1394   log_msg(4, "Cool. Command = '%s'", command);
    1395   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    1396   log_msg(4, "tmp = '%s'", tmp);
    1397   if (tmp[0])
    1398     {
    1399       log_it("/boot is at %s according to /etc/fstab", tmp);
    1400       if (strstr(tmp, "LABEL="))
    1401         {
    1402       if (!run_program_and_log_output("mount /boot", 5))
    1403         {
    1404           strcpy(g_boot_mountpt, "/boot");
    1405           log_msg(1, "Mounted /boot");
    1406         }
    1407       else
    1408         {
    1409           log_it("...ignored cos it's a label :-)");
    1410         }
    1411     }
    1412       else
    1413         {
    1414           sprintf(command, "mount | grep -w \"%s\"", tmp);
    1415           log_msg(3, "command = %s", command);
    1416           if (run_program_and_log_output(command, 5))
    1417             {
    1418           strcpy(g_boot_mountpt, tmp);
    1419               sprintf(tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);
    1420           log_it(tmp);
    1421           sprintf(tmp, "mount %s", g_boot_mountpt);
    1422           if (run_program_and_log_output(tmp, 5))
    1423         {
    1424           g_boot_mountpt[0] = '\0';
    1425           log_msg(1, "Plan B");
    1426           if (!run_program_and_log_output("mount /boot", 5))
    1427             {
    1428               strcpy(g_boot_mountpt, "/boot");
    1429               log_msg(1, "Plan B worked");
    1430             }
    1431           else
    1432             {
    1433               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.");
    1434             }
    1435         }
    1436             }
    1437         }
    1438     }
    1439   log_msg(1, "Ended sub");
     1400    char tmp[MAX_STR_LEN];
     1401    char command[MAX_STR_LEN];
     1402
     1403    log_msg(1, "Started sub");
     1404    log_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
     1405    g_boot_mountpt[0] = '\0';
     1406    log_msg(4, "Done. Great. Seeting command to something");
     1407    strcpy(command,
     1408           "cat /etc/fstab | grep -v \":\" | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1409    log_msg(4, "Cool. Command = '%s'", command);
     1410    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1411    log_msg(4, "tmp = '%s'", tmp);
     1412    if (tmp[0]) {
     1413        log_it("/boot is at %s according to /etc/fstab", tmp);
     1414        if (strstr(tmp, "LABEL=")) {
     1415            if (!run_program_and_log_output("mount /boot", 5)) {
     1416                strcpy(g_boot_mountpt, "/boot");
     1417                log_msg(1, "Mounted /boot");
     1418            } else {
     1419                log_it("...ignored cos it's a label :-)");
     1420            }
     1421        } else {
     1422            sprintf(command, "mount | grep -w \"%s\"", tmp);
     1423            log_msg(3, "command = %s", command);
     1424            if (run_program_and_log_output(command, 5)) {
     1425                strcpy(g_boot_mountpt, tmp);
     1426                sprintf(tmp,
     1427                        "%s (your /boot partition) is not mounted. I'll mount it before backing up",
     1428                        g_boot_mountpt);
     1429                log_it(tmp);
     1430                sprintf(tmp, "mount %s", g_boot_mountpt);
     1431                if (run_program_and_log_output(tmp, 5)) {
     1432                    g_boot_mountpt[0] = '\0';
     1433                    log_msg(1, "Plan B");
     1434                    if (!run_program_and_log_output("mount /boot", 5)) {
     1435                        strcpy(g_boot_mountpt, "/boot");
     1436                        log_msg(1, "Plan B worked");
     1437                    } else {
     1438                        log_msg(1,
     1439                                "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");
     1440                    }
     1441                }
     1442            }
     1443        }
     1444    }
     1445    log_msg(1, "Ended sub");
    14401446}
    14411447
     
    14461452void unmount_boot_if_necessary()
    14471453{
    1448   char tmp[MAX_STR_LEN];
    1449 
    1450   log_msg(3, "starting");
    1451   if (g_boot_mountpt[0])
    1452     {
    1453       sprintf(tmp, "umount %s", g_boot_mountpt);
    1454       if (run_program_and_log_output(tmp, 5))
    1455     { log_it("WARNING - unable to unmount /boot"); }
    1456     }
    1457    log_msg(3, "leaving");
     1454    char tmp[MAX_STR_LEN];
     1455
     1456    log_msg(3, "starting");
     1457    if (g_boot_mountpt[0]) {
     1458        sprintf(tmp, "umount %s", g_boot_mountpt);
     1459        if (run_program_and_log_output(tmp, 5)) {
     1460            log_it("WARNING - unable to unmount /boot");
     1461        }
     1462    }
     1463    log_msg(3, "leaving");
    14581464}
    14591465
     
    14681474 * @return 0 for success, 1 for failure.
    14691475 */
    1470 int
    1471 write_cfg_var (char *config_file, char *label, char *value)
    1472 {
    1473     /*@ buffers ******************************************************/
    1474   char command[MAX_STR_LEN*2];
    1475   char tempfile[MAX_STR_LEN];
    1476   char tmp[MAX_STR_LEN];
    1477 
    1478 
    1479     /*@ end vars ****************************************************/
    1480   assert_string_is_neither_NULL_nor_zerolength(config_file);
    1481   assert_string_is_neither_NULL_nor_zerolength(label);
    1482   assert(value!=NULL);
    1483   if (!does_file_exist (config_file))
    1484     {
    1485       sprintf (tmp, "(write_cfg_file) Cannot find %s config file",
    1486            config_file);
    1487       log_to_screen (tmp);
    1488       return(1);
    1489     }
    1490   strcpy (tempfile,
    1491       call_program_and_get_last_line_of_output
    1492       ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
    1493   if (does_file_exist (config_file))
    1494     {
    1495       sprintf (command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
    1496            label, tempfile);
    1497       paranoid_system (command);
    1498     }
    1499   sprintf (command, "echo \"%s %s\" >> %s", label, value, tempfile);
    1500   paranoid_system (command);
    1501   sprintf (command, "mv -f %s %s", tempfile, config_file);
    1502   paranoid_system (command);
    1503   unlink (tempfile);
    1504   return (0);
     1476int write_cfg_var(char *config_file, char *label, char *value)
     1477{
     1478    /*@ buffers ***************************************************** */
     1479    char command[MAX_STR_LEN * 2];
     1480    char tempfile[MAX_STR_LEN];
     1481    char tmp[MAX_STR_LEN];
     1482
     1483
     1484    /*@ end vars *************************************************** */
     1485    assert_string_is_neither_NULL_nor_zerolength(config_file);
     1486    assert_string_is_neither_NULL_nor_zerolength(label);
     1487    assert(value != NULL);
     1488    if (!does_file_exist(config_file)) {
     1489        sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
     1490                config_file);
     1491        log_to_screen(tmp);
     1492        return (1);
     1493    }
     1494    strcpy(tempfile,
     1495           call_program_and_get_last_line_of_output
     1496           ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
     1497    if (does_file_exist(config_file)) {
     1498        sprintf(command, "cat %s | grep -vx \"%s .*\" > %s", config_file,
     1499                label, tempfile);
     1500        paranoid_system(command);
     1501    }
     1502    sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1503    paranoid_system(command);
     1504    sprintf(command, "mv -f %s %s", tempfile, config_file);
     1505    paranoid_system(command);
     1506    unlink(tempfile);
     1507    return (0);
    15051508}
    15061509
     
    15111514 */
    15121515void standard_log_debug_msg(int debug_level, const char *szFile,
    1513                 const char *szFunction, int nLine, const char *fmt, ...)
    1514 {
    1515   va_list args;
    1516   int i;
    1517   static int depth=0; 
    1518   char *tmp;
    1519   FILE*fout;
    1520 
    1521   if (depth>5) { depth--; return; }
    1522   depth++;
    1523 
    1524   malloc_string(tmp);
    1525 
    1526   if (debug_level <= g_loglevel)
    1527     {
    1528       va_start(args, fmt);
    1529       if (!(fout = fopen (MONDO_LOGFILE, "a")))
    1530     { return; } // fatal_error("Failed to openout to logfile - sheesh..."); }
    1531 
    1532       // add tabs to distinguish log levels
    1533       if (debug_level > 0)
    1534     {
    1535       for (i = 1; i < debug_level; i++)
    1536         fprintf(fout, "\t");
    1537       if (getpid() == g_main_pid)
    1538         fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine);
    1539       else if (getpid() == g_buffer_pid && g_buffer_pid>0)
    1540         fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction, nLine);
    1541       else
    1542         fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine);
    1543     }
    1544       vfprintf(fout, fmt, args);
    1545 
    1546     // do not slow down the progran if standard debug level
    1547     // must be enabled: if no flush, the log won't be up-to-date if there
    1548     // is a segfault
    1549     //if (g_dwDebugLevel != 1)
    1550 
    1551       va_end(args);
    1552       fprintf(fout, "\n");
    1553       paranoid_fclose(fout);
    1554     }
    1555   depth--;
    1556   paranoid_free(tmp);
     1516                            const char *szFunction, int nLine,
     1517                            const char *fmt, ...)
     1518{
     1519    va_list args;
     1520    int i;
     1521    static int depth = 0;
     1522    char *tmp;
     1523    FILE *fout;
     1524
     1525    if (depth > 5) {
     1526        depth--;
     1527        return;
     1528    }
     1529    depth++;
     1530
     1531    malloc_string(tmp);
     1532
     1533    if (debug_level <= g_loglevel) {
     1534        va_start(args, fmt);
     1535        if (!(fout = fopen(MONDO_LOGFILE, "a"))) {
     1536            return;
     1537        }                       // fatal_error("Failed to openout to logfile - sheesh..."); }
     1538
     1539        // add tabs to distinguish log levels
     1540        if (debug_level > 0) {
     1541            for (i = 1; i < debug_level; i++)
     1542                fprintf(fout, "\t");
     1543            if (getpid() == g_main_pid)
     1544                fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction,
     1545                        nLine);
     1546            else if (getpid() == g_buffer_pid && g_buffer_pid > 0)
     1547                fprintf(fout, "[Buff] %s->%s#%d: ", szFile, szFunction,
     1548                        nLine);
     1549            else
     1550                fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile,
     1551                        szFunction, nLine);
     1552        }
     1553        vfprintf(fout, fmt, args);
     1554
     1555        // do not slow down the progran if standard debug level
     1556        // must be enabled: if no flush, the log won't be up-to-date if there
     1557        // is a segfault
     1558        //if (g_dwDebugLevel != 1)
     1559
     1560        va_end(args);
     1561        fprintf(fout, "\n");
     1562        paranoid_fclose(fout);
     1563    }
     1564    depth--;
     1565    paranoid_free(tmp);
    15571566}
    15581567
     
    15601569 * Function pointer to the @c log_debug_msg function to use. Points to standard_log_debug_msg() by default.
    15611570 */
    1562 void (*log_debug_msg) (int, const char *, const char *, int, const char *, ...) = standard_log_debug_msg;
     1571void (*log_debug_msg) (int, const char *, const char *, int, const char *,
     1572                       ...) = standard_log_debug_msg;
    15631573
    15641574
     
    15751585void do_libmondo_global_strings_thing(int mal)
    15761586{
    1577   if (mal)
    1578     {
    1579       iamhere("Malloc'ing globals");
    1580       malloc_string(g_boot_mountpt);
    1581       malloc_string(g_mondo_home);
    1582       malloc_string(g_tmpfs_mountpt);
    1583       malloc_string(g_erase_tmpdir_and_scratchdir);
    1584       malloc_string(g_serial_string);
    1585       malloc_string(g_magicdev_command);
    1586     }
    1587   else
    1588     {
    1589       iamhere("Freeing globals");
    1590       paranoid_free(g_boot_mountpt);
    1591       paranoid_free(g_mondo_home);
    1592       paranoid_free(g_tmpfs_mountpt);
    1593       paranoid_free(g_erase_tmpdir_and_scratchdir);
    1594       paranoid_free(g_serial_string);
    1595       paranoid_free(g_magicdev_command);
    1596     }
    1597 
    1598   /*
    1599   char**list_of_arrays[] = {
    1600     &g_boot_mountpt,
    1601     &g_mondo_home,
    1602     &g_tmpfs_mountpt,
    1603     &g_erase_tmpdir_and_scratchdir,
    1604     &g_serial_string,
    1605     &g_magicdev_command,
    1606     NULL};
    1607 
    1608   char**ppcurr;
    1609   int i;
    1610  
    1611   for(i=0;list_of_arrays[i];i++)
    1612     {
    1613       log_msg(5, "Allocating %d", i);
    1614       ppcurr = list_of_arrays[i];
    1615       if (mal)
    1616         { *ppcurr = malloc(MAX_STR_LEN); }
    1617       else
    1618         {
    1619       if (*ppcurr)
    1620         {
    1621           free(*ppcurr);
    1622         }
    1623     }
    1624     }
    1625   log_msg(5, "Returning");
    1626   */
     1587    if (mal) {
     1588        iamhere("Malloc'ing globals");
     1589        malloc_string(g_boot_mountpt);
     1590        malloc_string(g_mondo_home);
     1591        malloc_string(g_tmpfs_mountpt);
     1592        malloc_string(g_erase_tmpdir_and_scratchdir);
     1593        malloc_string(g_serial_string);
     1594        malloc_string(g_magicdev_command);
     1595    } else {
     1596        iamhere("Freeing globals");
     1597        paranoid_free(g_boot_mountpt);
     1598        paranoid_free(g_mondo_home);
     1599        paranoid_free(g_tmpfs_mountpt);
     1600        paranoid_free(g_erase_tmpdir_and_scratchdir);
     1601        paranoid_free(g_serial_string);
     1602        paranoid_free(g_magicdev_command);
     1603    }
     1604
     1605    /*
     1606       char**list_of_arrays[] = {
     1607       &g_boot_mountpt,
     1608       &g_mondo_home,
     1609       &g_tmpfs_mountpt,
     1610       &g_erase_tmpdir_and_scratchdir,
     1611       &g_serial_string,
     1612       &g_magicdev_command,
     1613       NULL};
     1614
     1615       char**ppcurr;
     1616       int i;
     1617
     1618       for(i=0;list_of_arrays[i];i++)
     1619       {
     1620       log_msg(5, "Allocating %d", i);
     1621       ppcurr = list_of_arrays[i];
     1622       if (mal)
     1623       { *ppcurr = malloc(MAX_STR_LEN); }
     1624       else
     1625       {
     1626       if (*ppcurr)
     1627       {
     1628       free(*ppcurr);
     1629       }
     1630       }
     1631       }
     1632       log_msg(5, "Returning");
     1633     */
    16271634}
    16281635
     
    16331640void malloc_libmondo_global_strings(void)
    16341641{
    1635   do_libmondo_global_strings_thing(1);
     1642    do_libmondo_global_strings_thing(1);
    16361643}
    16371644
     
    16421649void free_libmondo_global_strings(void)
    16431650{
    1644   do_libmondo_global_strings_thing(0);
     1651    do_libmondo_global_strings_thing(0);
    16451652}
    16461653
     
    16531660void stop_magicdev_if_necessary()
    16541661{
    1655   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"));
    1656   if (g_magicdev_command[0])
    1657     {
    1658       log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
    1659       paranoid_system("killall magicdev");
    1660     }
     1662    strcpy(g_magicdev_command,
     1663           call_program_and_get_last_line_of_output
     1664           ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
     1665    if (g_magicdev_command[0]) {
     1666        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
     1667        paranoid_system("killall magicdev");
     1668    }
    16611669}
    16621670
     
    16671675void restart_magicdev_if_necessary()
    16681676{
    1669   char *tmp;
    1670  
    1671   malloc_string(tmp);
    1672   if (g_magicdev_command && g_magicdev_command[0])
    1673     {
    1674       sprintf(tmp, "%s &", g_magicdev_command);
    1675       paranoid_system(tmp);
    1676     }
    1677   paranoid_free(tmp);
     1677    char *tmp;
     1678
     1679    malloc_string(tmp);
     1680    if (g_magicdev_command && g_magicdev_command[0]) {
     1681        sprintf(tmp, "%s &", g_magicdev_command);
     1682        paranoid_system(tmp);
     1683    }
     1684    paranoid_free(tmp);
    16781685}
    16791686
  • trunk/mondo/mondo/common/libmondo-verify.c

    r48 r49  
    403403    FILE *pin;
    404404
    405     int n = 0;
     405    size_t n = 0;
    406406
    407407    /*@ long *********************************************************** */
     
    458458        if (pin) {
    459459            for (getline(&tmp, &n, pin); !feof(pin);
    460                  fgets(&tmp, &n, pin)) {
     460                 getline(&tmp, &n, pin)) {
    461461                if (bkpinfo->use_star) {
    462462                    if (!strstr(tmp, "diffopts=")) {
Note: See TracChangeset for help on using the changeset viewer.